Built motion from commit bab6f49e.|2.6.17
[motion2.git] / server / api / faxMessage / faxMessage.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xf9cf=['EventManager','rejectmessage','create','findOne','ContactId','Attachment','AttachmentId','SendFax','FaxAccountId','/var/opt/motion2/server/files/attachments/%s','download','join','root','files','basename','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','lodash','squel','crypto','jsforce','querystring','papaparse','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','localhost','socket.io-emitter','./faxMessage.socket','register','jayson/promise','client','http','request','then','info','request\x20sent','debug','stringify','code','error','FaxMessage,\x20%s,\x20%s','message','result','catch','sendStatus','status','end','offset','undefined','count','limit','json','reject','update','destroy','stack','name','index','map','FaxMessage','rawAttributes','type','model','query','keys','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','rows','show','params','include','find','body','describe','fax-interactions','accept','fax','read','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','user','agent','get','FaxInteractionId','isNil','read1stAt','[FAXMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','interaction','null','AcceptMessage','acceptMessage','sequelize','SELECT','contact','User','fullname','email','internal','manual','SIP/%s','channel','motionChannel','FaxInteraction','[FAXMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','Sequelize','QueryTypes','interface'];(function(_0x59aa93,_0x46ff65){var _0x3d2428=function(_0x201c56){while(--_0x201c56){_0x59aa93['push'](_0x59aa93['shift']());}};_0x3d2428(++_0x46ff65);}(_0xf9cf,0x1b9));var _0xff9c=function(_0xf47ff3,_0x2439eb){_0xf47ff3=_0xf47ff3-0x0;var _0x476dde=_0xf9cf[_0xf47ff3];return _0x476dde;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xff9c('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0xff9c('0x1'));var rp=require(_0xff9c('0x2'));var moment=require(_0xff9c('0x3'));var BPromise=require(_0xff9c('0x4'));var Mustache=require(_0xff9c('0x5'));var util=require(_0xff9c('0x6'));var path=require('path');var sox=require(_0xff9c('0x7'));var csv=require(_0xff9c('0x8'));var ejs=require(_0xff9c('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xff9c('0xa'));var squel=require(_0xff9c('0xb'));var crypto=require(_0xff9c('0xc'));var jsforce=require(_0xff9c('0xd'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0xff9c('0xe'));var Papa=require(_0xff9c('0xf'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0xff9c('0x10'));var hardwareService=require(_0xff9c('0x11'));var logger=require(_0xff9c('0x12'))(_0xff9c('0x13'));var utils=require(_0xff9c('0x14'));var config=require(_0xff9c('0x15'));var licenseUtil=require(_0xff9c('0x16'));var db=require(_0xff9c('0x17'))['db'];config[_0xff9c('0x18')]=_['defaults'](config[_0xff9c('0x18')],{'host':_0xff9c('0x19'),'port':0x18eb});var socket=require(_0xff9c('0x1a'))(new Redis(config[_0xff9c('0x18')]));require(_0xff9c('0x1b'))[_0xff9c('0x1c')](socket);var jayson=require(_0xff9c('0x1d'));var client=jayson['client']['http']({'port':0x232c});var client9002=jayson[_0xff9c('0x1e')][_0xff9c('0x1f')]({'port':0x232a});function respondWithRpcPromise(_0x2af068,_0x189484,_0x3b0ea3,_0xd19ba4){return new BPromise(function(_0x254a22,_0x2144ab){var _0x4ab37f=_0xd19ba4||client;return _0x4ab37f[_0xff9c('0x20')](_0x2af068,_0x3b0ea3)[_0xff9c('0x21')](function(_0x497425){logger[_0xff9c('0x22')]('FaxMessage,\x20%s,\x20%s',_0x189484,_0xff9c('0x23'));logger[_0xff9c('0x24')]('FaxMessage,\x20%s,\x20%s,\x20%s',_0x189484,'request\x20sent',JSON[_0xff9c('0x25')](_0x497425));if(_0x497425['error']){if(_0x497425['error'][_0xff9c('0x26')]===0x1f4){logger[_0xff9c('0x27')](_0xff9c('0x28'),_0x189484,_0x497425[_0xff9c('0x27')]['message']);return _0x2144ab(_0x497425[_0xff9c('0x27')]['message']);}logger[_0xff9c('0x27')]('FaxMessage,\x20%s,\x20%s',_0x189484,_0x497425[_0xff9c('0x27')]['message']);return _0x254a22(_0x497425['error'][_0xff9c('0x29')]);}else{logger[_0xff9c('0x22')]('FaxMessage,\x20%s,\x20%s',_0x189484,'request\x20sent');_0x254a22(_0x497425[_0xff9c('0x2a')][_0xff9c('0x29')]);}})[_0xff9c('0x2b')](function(_0x221495){logger[_0xff9c('0x27')]('FaxMessage,\x20%s,\x20%s',_0x189484,_0x221495);_0x2144ab(_0x221495);});});}function respondWithStatusCode(_0x23bc4a,_0x46c9cc){_0x46c9cc=_0x46c9cc||0xcc;return function(_0x4cf078){if(_0x4cf078){return _0x23bc4a[_0xff9c('0x2c')](_0x46c9cc);}return _0x23bc4a[_0xff9c('0x2d')](_0x46c9cc)[_0xff9c('0x2e')]();};}function respondWithResult(_0x272a8b,_0x2854df){_0x2854df=_0x2854df||0xc8;return function(_0xbfb2d6){if(_0xbfb2d6){return _0x272a8b[_0xff9c('0x2d')](_0x2854df)['json'](_0xbfb2d6);}};}function respondWithFilteredResult(_0x527305,_0x2b4dcb){return function(_0x160922){if(_0x160922){var _0x6ac171=typeof _0x2b4dcb[_0xff9c('0x2f')]===_0xff9c('0x30')&&typeof _0x2b4dcb['limit']==='undefined';var _0x28bf6e=_0x160922['count'];var _0x1b140d=_0x6ac171?0x0:_0x2b4dcb['offset'];var _0x2e10c9=_0x6ac171?_0x160922[_0xff9c('0x31')]:_0x2b4dcb['offset']+_0x2b4dcb[_0xff9c('0x32')];var _0x1d6627;if(_0x2e10c9>=_0x28bf6e){_0x2e10c9=_0x28bf6e;_0x1d6627=0xc8;}else{_0x1d6627=0xce;}_0x527305['status'](_0x1d6627);return _0x527305['set']('Content-Range',_0x1b140d+'-'+_0x2e10c9+'/'+_0x28bf6e)[_0xff9c('0x33')](_0x160922);}return null;};}function patchUpdates(_0x3b05e0){return function(_0x1338b7){try{jsonpatch['apply'](_0x1338b7,_0x3b05e0,!![]);}catch(_0x177e62){return BPromise[_0xff9c('0x34')](_0x177e62);}return _0x1338b7['save']();};}function saveUpdates(_0x35e904,_0x5c1602){return function(_0x4204e3){if(_0x4204e3){return _0x4204e3[_0xff9c('0x35')](_0x35e904)[_0xff9c('0x21')](function(_0x3ec2d2){return _0x3ec2d2;});}return null;};}function removeEntity(_0x161d4e,_0x206f3b){return function(_0x2c451a){if(_0x2c451a){return _0x2c451a[_0xff9c('0x36')]()['then'](function(){_0x161d4e[_0xff9c('0x2d')](0xcc)['end']();});}};}function handleEntityNotFound(_0x3099d3,_0x437b67){return function(_0x451b93){if(!_0x451b93){_0x3099d3[_0xff9c('0x2c')](0x194);}return _0x451b93;};}function handleError(_0x41dee9,_0x308080){_0x308080=_0x308080||0x1f4;return function(_0x3a0a5e){logger[_0xff9c('0x27')](_0x3a0a5e[_0xff9c('0x37')]);if(_0x3a0a5e[_0xff9c('0x38')]){delete _0x3a0a5e[_0xff9c('0x38')];}_0x41dee9[_0xff9c('0x2d')](_0x308080)['send'](_0x3a0a5e);};}exports[_0xff9c('0x39')]=function(_0x27714c,_0x32e466){var _0x3613ad={},_0x3a9433={},_0x29ce4f={'count':0x0,'rows':[]};var _0x5f35ee=_[_0xff9c('0x3a')](db[_0xff9c('0x3b')][_0xff9c('0x3c')],function(_0x452b7b){return{'name':_0x452b7b['fieldName'],'type':_0x452b7b[_0xff9c('0x3d')]['key']};});_0x3a9433[_0xff9c('0x3e')]=_[_0xff9c('0x3a')](_0x5f35ee,'name');_0x3a9433[_0xff9c('0x3f')]=_[_0xff9c('0x40')](_0x27714c[_0xff9c('0x3f')]);_0x3a9433[_0xff9c('0x41')]=_['intersection'](_0x3a9433[_0xff9c('0x3e')],_0x3a9433[_0xff9c('0x3f')]);_0x3613ad[_0xff9c('0x42')]=_[_0xff9c('0x43')](_0x3a9433[_0xff9c('0x3e')],qs[_0xff9c('0x44')](_0x27714c[_0xff9c('0x3f')]['fields']));_0x3613ad['attributes']=_0x3613ad['attributes'][_0xff9c('0x45')]?_0x3613ad[_0xff9c('0x42')]:_0x3a9433[_0xff9c('0x3e')];if(!_0x27714c['query'][_0xff9c('0x46')](_0xff9c('0x47'))){_0x3613ad['limit']=qs[_0xff9c('0x32')](_0x27714c['query']['limit']);_0x3613ad[_0xff9c('0x2f')]=qs[_0xff9c('0x2f')](_0x27714c[_0xff9c('0x3f')][_0xff9c('0x2f')]);}_0x3613ad[_0xff9c('0x48')]=qs['sort'](_0x27714c[_0xff9c('0x3f')][_0xff9c('0x49')]);_0x3613ad[_0xff9c('0x4a')]=qs[_0xff9c('0x41')](_[_0xff9c('0x4b')](_0x27714c['query'],_0x3a9433['filters']),_0x5f35ee);if(_0x27714c[_0xff9c('0x3f')][_0xff9c('0x4c')]){_0x3613ad[_0xff9c('0x4a')]=_[_0xff9c('0x4d')](_0x3613ad[_0xff9c('0x4a')],{'$or':_['map'](_0x5f35ee,function(_0x1a5e12){if(_0x1a5e12['type']!==_0xff9c('0x4e')){var _0x51cd63={};_0x51cd63[_0x1a5e12[_0xff9c('0x38')]]={'$like':'%'+_0x27714c[_0xff9c('0x3f')][_0xff9c('0x4c')]+'%'};return _0x51cd63;}})});}_0x3613ad=_['merge']({},_0x3613ad,_0x27714c[_0xff9c('0x4f')]);var _0x551766={'where':_0x3613ad[_0xff9c('0x4a')]};return db[_0xff9c('0x3b')]['count'](_0x551766)[_0xff9c('0x21')](function(_0x493a75){_0x29ce4f[_0xff9c('0x31')]=_0x493a75;if(_0x27714c[_0xff9c('0x3f')][_0xff9c('0x50')]){_0x3613ad['include']=[{'all':!![]}];}return db[_0xff9c('0x3b')]['findAll'](_0x3613ad);})['then'](function(_0x3806da){_0x29ce4f[_0xff9c('0x51')]=_0x3806da;return _0x29ce4f;})[_0xff9c('0x21')](respondWithFilteredResult(_0x32e466,_0x3613ad))[_0xff9c('0x2b')](handleError(_0x32e466,null));};exports[_0xff9c('0x52')]=function(_0x1d8cb9,_0x45fabf){var _0x1901f9={'raw':!![],'where':{'id':_0x1d8cb9[_0xff9c('0x53')]['id']}},_0x53d43c={};_0x53d43c[_0xff9c('0x3e')]=_[_0xff9c('0x40')](db[_0xff9c('0x3b')][_0xff9c('0x3c')]);_0x53d43c['query']=_[_0xff9c('0x40')](_0x1d8cb9[_0xff9c('0x3f')]);_0x53d43c[_0xff9c('0x41')]=_[_0xff9c('0x43')](_0x53d43c[_0xff9c('0x3e')],_0x53d43c[_0xff9c('0x3f')]);_0x1901f9[_0xff9c('0x42')]=_[_0xff9c('0x43')](_0x53d43c[_0xff9c('0x3e')],qs['fields'](_0x1d8cb9[_0xff9c('0x3f')]['fields']));_0x1901f9[_0xff9c('0x42')]=_0x1901f9['attributes'][_0xff9c('0x45')]?_0x1901f9[_0xff9c('0x42')]:_0x53d43c[_0xff9c('0x3e')];if(_0x1d8cb9[_0xff9c('0x3f')][_0xff9c('0x50')]){_0x1901f9[_0xff9c('0x54')]=[{'all':!![]}];}_0x1901f9=_[_0xff9c('0x4d')]({},_0x1901f9,_0x1d8cb9['options']);return db[_0xff9c('0x3b')][_0xff9c('0x55')](_0x1901f9)[_0xff9c('0x21')](handleEntityNotFound(_0x45fabf,null))['then'](respondWithResult(_0x45fabf,null))[_0xff9c('0x2b')](handleError(_0x45fabf,null));};exports[_0xff9c('0x35')]=function(_0x12dd03,_0x1be112){if(_0x12dd03[_0xff9c('0x56')]['id']){delete _0x12dd03['body']['id'];}return db[_0xff9c('0x3b')][_0xff9c('0x55')]({'where':{'id':_0x12dd03[_0xff9c('0x53')]['id']}})[_0xff9c('0x21')](handleEntityNotFound(_0x1be112,null))[_0xff9c('0x21')](saveUpdates(_0x12dd03[_0xff9c('0x56')],null))[_0xff9c('0x21')](respondWithResult(_0x1be112,null))[_0xff9c('0x2b')](handleError(_0x1be112,null));};exports['destroy']=function(_0x2857b5,_0x7c8637){return db['FaxMessage']['find']({'where':{'id':_0x2857b5[_0xff9c('0x53')]['id']}})[_0xff9c('0x21')](handleEntityNotFound(_0x7c8637,null))[_0xff9c('0x21')](removeEntity(_0x7c8637,null))[_0xff9c('0x2b')](handleError(_0x7c8637,null));};exports[_0xff9c('0x57')]=function(_0x6cc6d0,_0x1b3bc0){return db[_0xff9c('0x3b')][_0xff9c('0x57')]()[_0xff9c('0x21')](respondWithResult(_0x1b3bc0,null))[_0xff9c('0x2b')](handleError(_0x1b3bc0,null));};var interaction_log=require(_0xff9c('0x12'))(_0xff9c('0x58'));exports[_0xff9c('0x59')]=function(_0x406c84,_0x58e281,_0x2e9850){var _0x174661={'agent':{},'channel':_0xff9c('0x5a')};if(_0x406c84[_0xff9c('0x56')]['id']){delete _0x406c84[_0xff9c('0x56')]['id'];}_0x406c84[_0xff9c('0x56')][_0xff9c('0x5b')]=!![];_0x406c84[_0xff9c('0x56')][_0xff9c('0x5c')]=moment()[_0xff9c('0x5d')](_0xff9c('0x5e'));_0x406c84[_0xff9c('0x56')][_0xff9c('0x5f')]=_0x406c84[_0xff9c('0x56')][_0xff9c('0x5f')]||_0x406c84[_0xff9c('0x60')]['id'];_0x174661[_0xff9c('0x61')]['id']=_0x406c84[_0xff9c('0x56')][_0xff9c('0x5f')];return db['FaxMessage'][_0xff9c('0x55')]({'where':{'id':_0x406c84[_0xff9c('0x53')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0x58e281,null))[_0xff9c('0x21')](saveUpdates(_0x406c84[_0xff9c('0x56')],null))['then'](function(_0x40d45a){if(_0x40d45a){_0x174661['message']=_0x40d45a[_0xff9c('0x62')]({'plain':!![]});return db['FaxInteraction']['find']({'where':{'id':_0x40d45a[_0xff9c('0x63')]}});}return null;})[_0xff9c('0x21')](handleEntityNotFound(_0x58e281,null))['then'](function(_0xe00aa9){if(_0xe00aa9){return _0xe00aa9['update']({'UserId':_0x406c84[_0xff9c('0x56')][_0xff9c('0x5f')],'read1stAt':_[_0xff9c('0x64')](_0xe00aa9[_0xff9c('0x65')])?moment()[_0xff9c('0x5d')](_0xff9c('0x5e')):undefined});}return null;})[_0xff9c('0x21')](function(_0xa2d9b){if(_0xa2d9b){_0x174661['interaction']=_0xa2d9b[_0xff9c('0x62')]({'plain':!![]});interaction_log[_0xff9c('0x22')](_0xff9c('0x66'),_0x406c84[_0xff9c('0x60')]['id'],_0x406c84[_0xff9c('0x60')][_0xff9c('0x38')],_0x406c84[_0xff9c('0x60')][_0xff9c('0x67')],_0x174661[_0xff9c('0x68')]['id'],_0x406c84[_0xff9c('0x56')]?JSON[_0xff9c('0x25')](_0x406c84[_0xff9c('0x56')]):_0xff9c('0x69'));return respondWithRpcPromise(_0xff9c('0x6a'),_0xff9c('0x6b'),_0x174661);}return null;})[_0xff9c('0x21')](function(_0x1d1244){var _0x1afca1='SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20'+_0x1d1244[_0xff9c('0x29')]['ContactId'];return db[_0xff9c('0x6c')][_0xff9c('0x3f')](_0x1afca1,{'type':db['Sequelize']['QueryTypes'][_0xff9c('0x6d')],'raw':!![]})[_0xff9c('0x21')](function(_0x4613e2){return _0x4613e2;});})[_0xff9c('0x21')](function(_0x4baf5b){if(_0x4baf5b){_0x174661['message'][_0xff9c('0x6e')]=_0x4baf5b[0x0];if(!_0x406c84['body'][_0xff9c('0x5f')])return;return db[_0xff9c('0x6f')]['find']({'where':{'id':_0x406c84['body']['UserId'],'role':'agent'},'attributes':['id',_0xff9c('0x38'),_0xff9c('0x70'),_0xff9c('0x71'),_0xff9c('0x72')],'raw':!![]});}return null;})[_0xff9c('0x21')](function(_0x3f498c){if(!_0x3f498c)return null;_0x174661[_0xff9c('0x29')][_0xff9c('0x61')]=_0x3f498c;return _0x174661;})[_0xff9c('0x21')](function(_0x4117ee){if(_0x4117ee){if(_0x406c84[_0xff9c('0x56')][_0xff9c('0x73')]){_0x174661[_0xff9c('0x29')]['interface']=util[_0xff9c('0x5d')](_0xff9c('0x74'),_0x406c84[_0xff9c('0x60')][_0xff9c('0x38')]);_0x174661['message']['channel']=_0x174661[_0xff9c('0x75')];_0x174661[_0xff9c('0x29')][_0xff9c('0x76')]=_0x174661['channel'];_0x174661[_0xff9c('0x29')]['event']=_0xff9c('0x59');return respondWithRpcPromise('EventManager','EventManager',{'event':'acceptmessage','message':_0x174661[_0xff9c('0x29')]},client9002)['then'](function(){return _0x174661;});}return _0x174661;}return null;})[_0xff9c('0x21')](respondWithResult(_0x58e281,null))['catch'](handleError(_0x58e281,null));};var interaction_log=require(_0xff9c('0x12'))(_0xff9c('0x58'));exports[_0xff9c('0x34')]=function(_0x44b68a,_0x327e0e,_0x1dac92){var _0x39cb9a={'agent':{},'channel':_0xff9c('0x5a')};if(_0x44b68a['body']['id']){delete _0x44b68a[_0xff9c('0x56')]['id'];}_0x44b68a['body'][_0xff9c('0x5f')]=_0x44b68a['body'][_0xff9c('0x5f')]||_0x44b68a['user']['id'];_0x39cb9a['agent']['id']=_0x44b68a['body'][_0xff9c('0x5f')];return db[_0xff9c('0x3b')][_0xff9c('0x55')]({'where':{'id':_0x44b68a[_0xff9c('0x53')]['id'],'UserId':null}})[_0xff9c('0x21')](handleEntityNotFound(_0x327e0e,null))[_0xff9c('0x21')](function(_0x427323){if(_0x427323){_0x39cb9a[_0xff9c('0x29')]=_0x427323[_0xff9c('0x62')]({'plain':!![]});return db[_0xff9c('0x77')]['find']({'where':{'id':_0x427323[_0xff9c('0x63')]}});}return null;})[_0xff9c('0x21')](handleEntityNotFound(_0x327e0e,null))[_0xff9c('0x21')](function(_0x3dfe01){if(_0x3dfe01){_0x39cb9a[_0xff9c('0x68')]=_0x3dfe01[_0xff9c('0x62')]({'plain':!![]});interaction_log[_0xff9c('0x22')](_0xff9c('0x78'),_0x44b68a[_0xff9c('0x60')]['id'],_0x44b68a[_0xff9c('0x60')][_0xff9c('0x38')],_0x44b68a[_0xff9c('0x60')][_0xff9c('0x67')],_0x39cb9a['interaction']['id'],_0x44b68a[_0xff9c('0x56')]?JSON[_0xff9c('0x25')](_0x44b68a[_0xff9c('0x56')]):_0xff9c('0x69'));return respondWithRpcPromise(_0xff9c('0x79'),_0xff9c('0x7a'),_0x39cb9a);}return null;})['then'](function(_0x324e57){var _0x2eff3a=_0xff9c('0x7b')+_0x324e57[_0xff9c('0x29')]['ContactId'];return db['sequelize']['query'](_0x2eff3a,{'type':db[_0xff9c('0x7c')][_0xff9c('0x7d')][_0xff9c('0x6d')],'raw':!![]})['then'](function(_0x26d6de){return _0x26d6de;});})[_0xff9c('0x21')](function(_0x4bf0a9){if(_0x4bf0a9){_0x39cb9a[_0xff9c('0x29')][_0xff9c('0x6e')]=_0x4bf0a9[0x0];if(!_0x44b68a['body']['UserId'])return;return db[_0xff9c('0x6f')][_0xff9c('0x55')]({'where':{'id':_0x44b68a[_0xff9c('0x56')][_0xff9c('0x5f')],'role':_0xff9c('0x61')},'attributes':['id','name','fullname','email',_0xff9c('0x72')],'raw':!![]});}return null;})['then'](function(_0x80046d){if(!_0x80046d)return null;_0x39cb9a[_0xff9c('0x29')][_0xff9c('0x61')]=_0x80046d;return _0x39cb9a;})[_0xff9c('0x21')](function(_0x385ef8){if(_0x385ef8){_0x385ef8[_0xff9c('0x29')][_0xff9c('0x7e')]=util[_0xff9c('0x5d')](_0xff9c('0x74'),_0x44b68a[_0xff9c('0x60')][_0xff9c('0x38')]);_0x385ef8['message']['channel']=_0x39cb9a[_0xff9c('0x75')];_0x385ef8['message']['motionChannel']=_0x39cb9a[_0xff9c('0x75')];_0x385ef8['message']['event']=_0xff9c('0x34');respondWithRpcPromise(_0xff9c('0x7f'),_0xff9c('0x7f'),{'event':_0xff9c('0x80'),'message':_0x385ef8['message']},client9002);return _0x39cb9a;}return null;})[_0xff9c('0x21')](respondWithResult(_0x327e0e,null))['catch'](handleError(_0x327e0e,null));};exports[_0xff9c('0x81')]=function(_0x5ea8ca,_0x4345bd){var _0x36fa9a;return db[_0xff9c('0x3b')]['create'](_0x5ea8ca[_0xff9c('0x56')],{})[_0xff9c('0x21')](function(_0x5604fc){_0x36fa9a=_0x5604fc;return db['CmContact'][_0xff9c('0x82')]({'where':{'id':_0x36fa9a[_0xff9c('0x83')]}});})['then'](function(_0x169de9){if(_[_0xff9c('0x64')](_0x169de9)){return;}else{_0x36fa9a['fax']=_0x169de9['fax'];return db[_0xff9c('0x84')][_0xff9c('0x82')]({'where':{'id':_0x36fa9a[_0xff9c('0x85')]}});}})['then'](function(_0x2e447f){return respondWithRpcPromise(_0xff9c('0x86'),_0xff9c('0x86'),{'FaxAccountId':_['isNil'](_0x5ea8ca[_0xff9c('0x56')])?undefined:_0x5ea8ca[_0xff9c('0x56')][_0xff9c('0x87')],'path':_[_0xff9c('0x64')](_0x2e447f)?undefined:util['format'](_0xff9c('0x88'),_0x2e447f['basename']),'fax':_['isNil'](_0x36fa9a[_0xff9c('0x5a')])?undefined:_0x36fa9a[_0xff9c('0x5a')],'AttachmentId':_0x36fa9a[_0xff9c('0x85')]},client9002);})[_0xff9c('0x21')](respondWithResult(_0x4345bd,0xc9))[_0xff9c('0x2b')](handleError(_0x4345bd,null));};exports[_0xff9c('0x89')]=function(_0x343c2d,_0x1c7908){var _0x9ec879=path[_0xff9c('0x8a')](config[_0xff9c('0x8b')],'server',_0xff9c('0x8c'),'attachments');return db['FaxMessage']['find']({'where':{'id':_0x343c2d[_0xff9c('0x53')]['id']},'include':[{'model':db[_0xff9c('0x84')],'as':_0xff9c('0x84')}]})['then'](handleEntityNotFound(_0x1c7908,null))['then'](function(_0xe800fe){if(_0xe800fe){return _0x1c7908['download'](path[_0xff9c('0x8a')](_0x9ec879,_0xe800fe[_0xff9c('0x84')][_0xff9c('0x8d')]));}})[_0xff9c('0x2b')](handleError(_0x1c7908,null));};