3 var _ = require('lodash');
4 var util = require('util');
6 var FaxMessage = require('../../models').FaxMessage;
7 var Trunk = require('../../models').User;
9 exports.register = function(ami) {
11 FaxMessage.afterCreate(function(doc) {
12 console.log('FaxMessage afterCreate');
17 function onSave(ami, doc, cb) {
18 if (doc.status === 'NOT SENT' && !doc.actionid) {
19 // I have to send the fax with the Originate
20 var faxBody = JSON.parse(doc.body);
21 console.log('faxBody', faxBody);
24 .findById(faxBody.trunk.id)
25 .then(function(trunk) {
28 CallerID: faxBody.from,
29 Channel: util.format('%s/%s@%s', faxBody.technology, faxBody.to, trunk.name),
30 Context: 'outbound-fax',
35 MAXRATE: faxBody.maxrate,
36 MINRATE: faxBody.minrate,
37 ECM: faxBody.ecm ? 'yes' : 'no',
38 LOCALID: faxBody.fax_localid,
39 FAXFILE: faxBody.fax_file,
40 // 'FAXFILE': 'test.tiff', // Scommentare se si fanno prove in locale!
41 FAXHEADER: faxBody.fax_header,
46 ami.action(action, function(err, res) {
48 doc.updateAttributes({
52 if (res.response && res.actionid) {
53 doc.updateAttributes({
54 actionid: res.actionid
60 .catch(function(err) {