Built motion from commit 47436d59.|2.6.7
[motion2.git] / server / api / faxAccount / faxAccount.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 _0x71bb=['catch','show','find','body','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','autoAssociation','UserProfileResource','create','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','describe','FaxAccountId','Disposition','getDispositions','findAll','removeDispositions','ids','addAnswer','CannedAnswer','findOne','pick','removeAnswers','addInteraction','omit','FaxInteraction','Contact','Owner','fullname','internal','Tag','Tags','color','tag','addApplications','sequelize','transaction','Transaction','ISOLATION_LEVELS','READ_COMMITTED','FaxApplication','bulkCreate','priority','stack','finally','getApplications','context','from-voip-provider','localstationid','app','system','Fax\x20Extension','push','Answer','CDR(type)=inbound-fax','Set','ecm','faxdetect','headerinfo','maxrate','minrate','modem','t38timeout','FAXOPT(','ReceiveFax','addAccountApplications','VoiceExtension','updateAccountApplications','tech','key','createdAt','updatedAt','TrunkId','ListId','findById','$gte','split','format','YYYY-MM-DD\x20HH:mm:ss','FaxMessage','CmList','List','CmContact','Contacts','DESC','attachments','join','root','server/files/attachments','basename','CheckAfterSend','isNil','path','from','\x22%s\x22\x20<%s>','fax','defaults','List\x20not\x20found','Send\x20Fax\x20failed','user','out','Contact\x20not\x20found','spread','ContactId','dataValues','Messages','SendFax','SendFaxRpc,\x20%s','addAgents','emit','userFaxAccount:save','removeAgents','isArray','userFaxAccount:remove','getAgents','eml-format','rimraf','fast-json-patch','moment','mustache','util','to-csv','fs-extra','lodash','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','socket.io-emitter','./faxAccount.socket','register','jayson/promise','client','http','request','info','request\x20sent','FaxAccount,\x20%s,\x20%s,\x20%s','error','code','FaxAccount,\x20%s,\x20%s','message','result','sendStatus','status','json','undefined','count','offset','limit','set','Content-Range','reject','update','then','destroy','end','name','send','index','Pause','mandatoryDispositionPause','map','FaxAccount','rawAttributes','type','model','query','keys','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','filter','merge','where','VIRTUAL','options','includeAll','include','rows'];(function(_0x2064e5,_0x4f6fa2){var _0x21a233=function(_0x1b2491){while(--_0x1b2491){_0x2064e5['push'](_0x2064e5['shift']());}};_0x21a233(++_0x4f6fa2);}(_0x71bb,0x74));var _0xb71b=function(_0x4dcab1,_0x27df89){_0x4dcab1=_0x4dcab1-0x0;var _0x28dd76=_0x71bb[_0x4dcab1];return _0x28dd76;};'use strict';var emlformat=require(_0xb71b('0x0'));var rimraf=require(_0xb71b('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xb71b('0x2'));var rp=require('request-promise');var moment=require(_0xb71b('0x3'));var BPromise=require('bluebird');var Mustache=require(_0xb71b('0x4'));var util=require(_0xb71b('0x5'));var path=require('path');var sox=require('sox');var csv=require(_0xb71b('0x6'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xb71b('0x7'));var _=require(_0xb71b('0x8'));var squel=require(_0xb71b('0x9'));var crypto=require(_0xb71b('0xa'));var jsforce=require(_0xb71b('0xb'));var deskjs=require(_0xb71b('0xc'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0xb71b('0xd'));var Redis=require(_0xb71b('0xe'));var authService=require(_0xb71b('0xf'));var qs=require(_0xb71b('0x10'));var as=require(_0xb71b('0x11'));var hardwareService=require(_0xb71b('0x12'));var logger=require('../../config/logger')(_0xb71b('0x13'));var utils=require(_0xb71b('0x14'));var config=require(_0xb71b('0x15'));var licenseUtil=require(_0xb71b('0x16'));var db=require(_0xb71b('0x17'))['db'];config['redis']=_['defaults'](config[_0xb71b('0x18')],{'host':'localhost','port':0x18eb});var socket=require(_0xb71b('0x19'))(new Redis(config['redis']));require(_0xb71b('0x1a'))[_0xb71b('0x1b')](socket);var jayson=require(_0xb71b('0x1c'));var client=jayson[_0xb71b('0x1d')][_0xb71b('0x1e')]({'port':0x232c});var client9002=jayson['client'][_0xb71b('0x1e')]({'port':0x232a});function respondWithRpcPromise(_0x14cbb5,_0x167b8c,_0x58b675,_0x28bd83){return new BPromise(function(_0x23f6ed,_0x2732b1){var _0x50b058=_0x28bd83||client;return _0x50b058[_0xb71b('0x1f')](_0x14cbb5,_0x58b675)['then'](function(_0x458bf8){logger[_0xb71b('0x20')]('FaxAccount,\x20%s,\x20%s',_0x167b8c,_0xb71b('0x21'));logger['debug'](_0xb71b('0x22'),_0x167b8c,_0xb71b('0x21'),JSON['stringify'](_0x458bf8));if(_0x458bf8[_0xb71b('0x23')]){if(_0x458bf8[_0xb71b('0x23')][_0xb71b('0x24')]===0x1f4){logger[_0xb71b('0x23')](_0xb71b('0x25'),_0x167b8c,_0x458bf8[_0xb71b('0x23')][_0xb71b('0x26')]);return _0x2732b1(_0x458bf8['error']['message']);}logger[_0xb71b('0x23')](_0xb71b('0x25'),_0x167b8c,_0x458bf8[_0xb71b('0x23')][_0xb71b('0x26')]);return _0x23f6ed(_0x458bf8[_0xb71b('0x23')][_0xb71b('0x26')]);}else{logger[_0xb71b('0x20')](_0xb71b('0x25'),_0x167b8c,_0xb71b('0x21'));_0x23f6ed(_0x458bf8[_0xb71b('0x27')][_0xb71b('0x26')]);}})['catch'](function(_0x1563cb){logger[_0xb71b('0x23')](_0xb71b('0x25'),_0x167b8c,_0x1563cb);_0x2732b1(_0x1563cb);});});}function respondWithStatusCode(_0x555788,_0x2221d4){_0x2221d4=_0x2221d4||0xcc;return function(_0x18eadb){if(_0x18eadb){return _0x555788[_0xb71b('0x28')](_0x2221d4);}return _0x555788[_0xb71b('0x29')](_0x2221d4)['end']();};}function respondWithResult(_0x26cbcf,_0x23aad8){_0x23aad8=_0x23aad8||0xc8;return function(_0x11e466){if(_0x11e466){return _0x26cbcf[_0xb71b('0x29')](_0x23aad8)[_0xb71b('0x2a')](_0x11e466);}};}function respondWithFilteredResult(_0x1c48d0,_0x3a03f7){return function(_0x585090){if(_0x585090){var _0x2855e3=typeof _0x3a03f7['offset']===_0xb71b('0x2b')&&typeof _0x3a03f7['limit']===_0xb71b('0x2b');var _0x75e0ef=_0x585090[_0xb71b('0x2c')];var _0x481673=_0x2855e3?0x0:_0x3a03f7[_0xb71b('0x2d')];var _0x4ba754=_0x2855e3?_0x585090['count']:_0x3a03f7[_0xb71b('0x2d')]+_0x3a03f7[_0xb71b('0x2e')];var _0x1258be;if(_0x4ba754>=_0x75e0ef){_0x4ba754=_0x75e0ef;_0x1258be=0xc8;}else{_0x1258be=0xce;}_0x1c48d0[_0xb71b('0x29')](_0x1258be);return _0x1c48d0[_0xb71b('0x2f')](_0xb71b('0x30'),_0x481673+'-'+_0x4ba754+'/'+_0x75e0ef)[_0xb71b('0x2a')](_0x585090);}return null;};}function patchUpdates(_0x40e20e){return function(_0xc13de4){try{jsonpatch['apply'](_0xc13de4,_0x40e20e,!![]);}catch(_0x2bc3d4){return BPromise[_0xb71b('0x31')](_0x2bc3d4);}return _0xc13de4['save']();};}function saveUpdates(_0xb6fd81,_0x2f7a58){return function(_0x501f30){if(_0x501f30){return _0x501f30[_0xb71b('0x32')](_0xb6fd81)[_0xb71b('0x33')](function(_0x51a129){return _0x51a129;});}return null;};}function removeEntity(_0x2eefee,_0x4e3a39){return function(_0x5e4e9a){if(_0x5e4e9a){return _0x5e4e9a[_0xb71b('0x34')]()[_0xb71b('0x33')](function(){var _0x2d31d1=_0x5e4e9a['get']({'plain':!![]});var _0x5b2c58='FaxAccounts';return db['UserProfileResource'][_0xb71b('0x34')]({'where':{'type':_0x5b2c58,'resourceId':_0x2d31d1['id']}})[_0xb71b('0x33')](function(){return _0x5e4e9a;});})[_0xb71b('0x33')](function(){_0x2eefee[_0xb71b('0x29')](0xcc)[_0xb71b('0x35')]();});}};}function handleEntityNotFound(_0x5cc4a8,_0xe488b5){return function(_0x5d6bca){if(!_0x5d6bca){_0x5cc4a8[_0xb71b('0x28')](0x194);}return _0x5d6bca;};}function handleError(_0x43450c,_0x154357){_0x154357=_0x154357||0x1f4;return function(_0x59235d){logger['error'](_0x59235d['stack']);if(_0x59235d['name']){delete _0x59235d[_0xb71b('0x36')];}_0x43450c[_0xb71b('0x29')](_0x154357)[_0xb71b('0x37')](_0x59235d);};}exports[_0xb71b('0x38')]=function(_0x2e2155,_0x338b16){var _0x440a8e={'include':[{'model':db[_0xb71b('0x39')],'as':_0xb71b('0x3a')}]},_0x47868f={},_0x4578a3={'count':0x0,'rows':[]};var _0x267d06=_[_0xb71b('0x3b')](db[_0xb71b('0x3c')][_0xb71b('0x3d')],function(_0x23783d){return{'name':_0x23783d['fieldName'],'type':_0x23783d[_0xb71b('0x3e')]['key']};});_0x47868f[_0xb71b('0x3f')]=_[_0xb71b('0x3b')](_0x267d06,_0xb71b('0x36'));_0x47868f[_0xb71b('0x40')]=_[_0xb71b('0x41')](_0x2e2155[_0xb71b('0x40')]);_0x47868f[_0xb71b('0x42')]=_['intersection'](_0x47868f[_0xb71b('0x3f')],_0x47868f['query']);_0x440a8e[_0xb71b('0x43')]=_[_0xb71b('0x44')](_0x47868f['model'],qs[_0xb71b('0x45')](_0x2e2155[_0xb71b('0x40')]['fields']));_0x440a8e[_0xb71b('0x43')]=_0x440a8e[_0xb71b('0x43')][_0xb71b('0x46')]?_0x440a8e[_0xb71b('0x43')]:_0x47868f['model'];if(!_0x2e2155[_0xb71b('0x40')][_0xb71b('0x47')](_0xb71b('0x48'))){_0x440a8e[_0xb71b('0x2e')]=qs[_0xb71b('0x2e')](_0x2e2155[_0xb71b('0x40')]['limit']);_0x440a8e[_0xb71b('0x2d')]=qs[_0xb71b('0x2d')](_0x2e2155[_0xb71b('0x40')][_0xb71b('0x2d')]);}_0x440a8e[_0xb71b('0x49')]=qs[_0xb71b('0x4a')](_0x2e2155[_0xb71b('0x40')]['sort']);_0x440a8e['where']=qs[_0xb71b('0x42')](_['pick'](_0x2e2155[_0xb71b('0x40')],_0x47868f[_0xb71b('0x42')]),_0x267d06);if(_0x2e2155[_0xb71b('0x40')][_0xb71b('0x4b')]){_0x440a8e['where']=_[_0xb71b('0x4c')](_0x440a8e[_0xb71b('0x4d')],{'$or':_['map'](_0x267d06,function(_0x5b20f5){if(_0x5b20f5[_0xb71b('0x3e')]!==_0xb71b('0x4e')){var _0x58b804={};_0x58b804[_0x5b20f5[_0xb71b('0x36')]]={'$like':'%'+_0x2e2155[_0xb71b('0x40')][_0xb71b('0x4b')]+'%'};return _0x58b804;}})});}_0x440a8e=_['merge']({},_0x440a8e,_0x2e2155[_0xb71b('0x4f')]);var _0x2b5327={'where':_0x440a8e['where']};return db['FaxAccount']['count'](_0x2b5327)[_0xb71b('0x33')](function(_0xefa000){_0x4578a3[_0xb71b('0x2c')]=_0xefa000;if(_0x2e2155[_0xb71b('0x40')][_0xb71b('0x50')]){_0x440a8e[_0xb71b('0x51')]=[{'all':!![]}];}return db['FaxAccount']['findAll'](_0x440a8e);})[_0xb71b('0x33')](function(_0x54415a){_0x4578a3[_0xb71b('0x52')]=_0x54415a;return _0x4578a3;})['then'](respondWithFilteredResult(_0x338b16,_0x440a8e))[_0xb71b('0x53')](handleError(_0x338b16,null));};exports[_0xb71b('0x54')]=function(_0x514bf9,_0x46eb23){var _0x489f94={'raw':![],'where':{'id':_0x514bf9['params']['id']},'include':[{'model':db[_0xb71b('0x39')],'as':'mandatoryDispositionPause'}]},_0x486a77={};_0x486a77[_0xb71b('0x3f')]=_[_0xb71b('0x41')](db[_0xb71b('0x3c')][_0xb71b('0x3d')]);_0x486a77[_0xb71b('0x40')]=_[_0xb71b('0x41')](_0x514bf9['query']);_0x486a77[_0xb71b('0x42')]=_['intersection'](_0x486a77['model'],_0x486a77[_0xb71b('0x40')]);_0x489f94[_0xb71b('0x43')]=_['intersection'](_0x486a77[_0xb71b('0x3f')],qs[_0xb71b('0x45')](_0x514bf9[_0xb71b('0x40')]['fields']));_0x489f94[_0xb71b('0x43')]=_0x489f94['attributes'][_0xb71b('0x46')]?_0x489f94['attributes']:_0x486a77[_0xb71b('0x3f')];if(_0x514bf9[_0xb71b('0x40')]['includeAll']){_0x489f94[_0xb71b('0x51')]=[{'all':!![]}];}_0x489f94=_[_0xb71b('0x4c')]({},_0x489f94,_0x514bf9[_0xb71b('0x4f')]);return db[_0xb71b('0x3c')][_0xb71b('0x55')](_0x489f94)[_0xb71b('0x33')](handleEntityNotFound(_0x46eb23,null))[_0xb71b('0x33')](respondWithResult(_0x46eb23,null))['catch'](handleError(_0x46eb23,null));};exports['create']=function(_0x5da0e6,_0x40a998){return db['FaxAccount']['create'](_0x5da0e6[_0xb71b('0x56')],{})[_0xb71b('0x33')](function(_0x1e743e){var _0x44d043=_0x5da0e6['user'][_0xb71b('0x57')]({'plain':!![]});if(!_0x44d043)throw new Error(_0xb71b('0x58'));if(_0x44d043['role']==='user'){var _0x1800ca=_0x1e743e[_0xb71b('0x57')]({'plain':!![]});var _0x13b595='FaxAccounts';return db[_0xb71b('0x59')][_0xb71b('0x55')]({'where':{'name':_0x13b595,'userProfileId':_0x44d043['userProfileId']},'raw':!![]})[_0xb71b('0x33')](function(_0x4176f5){if(_0x4176f5&&_0x4176f5[_0xb71b('0x5a')]===0x0){return db[_0xb71b('0x5b')][_0xb71b('0x5c')]({'name':_0x1800ca[_0xb71b('0x36')],'resourceId':_0x1800ca['id'],'type':_0x4176f5[_0xb71b('0x36')],'sectionId':_0x4176f5['id']},{})[_0xb71b('0x33')](function(){return _0x1e743e;});}else{return _0x1e743e;}})[_0xb71b('0x53')](function(_0x4b58a8){logger[_0xb71b('0x23')](_0xb71b('0x5d'),_0x4b58a8);throw _0x4b58a8;});}return _0x1e743e;})[_0xb71b('0x33')](respondWithResult(_0x40a998,0xc9))[_0xb71b('0x53')](handleError(_0x40a998,null));};exports[_0xb71b('0x32')]=function(_0x59e7d9,_0x3aa79e){if(_0x59e7d9[_0xb71b('0x56')]['id']){delete _0x59e7d9['body']['id'];}return db[_0xb71b('0x3c')][_0xb71b('0x55')]({'where':{'id':_0x59e7d9['params']['id']},'include':[{'model':db[_0xb71b('0x39')],'as':_0xb71b('0x3a')}]})[_0xb71b('0x33')](handleEntityNotFound(_0x3aa79e,null))['then'](saveUpdates(_0x59e7d9[_0xb71b('0x56')],null))[_0xb71b('0x33')](respondWithResult(_0x3aa79e,null))[_0xb71b('0x53')](handleError(_0x3aa79e,null));};exports[_0xb71b('0x34')]=function(_0x30e4c8,_0x30b130){return db[_0xb71b('0x3c')][_0xb71b('0x55')]({'where':{'id':_0x30e4c8[_0xb71b('0x5e')]['id']}})[_0xb71b('0x33')](handleEntityNotFound(_0x30b130,null))[_0xb71b('0x33')](removeEntity(_0x30b130,null))[_0xb71b('0x53')](handleError(_0x30b130,null));};exports[_0xb71b('0x5f')]=function(_0xfe3d41,_0x56515b){return db[_0xb71b('0x3c')]['describe']()['then'](respondWithResult(_0x56515b,null))[_0xb71b('0x53')](handleError(_0x56515b,null));};exports['addDisposition']=function(_0x3746d6,_0x2c880c,_0xd19906){if(_0x3746d6[_0xb71b('0x56')]['id']){delete _0x3746d6['body']['id'];}return db[_0xb71b('0x3c')][_0xb71b('0x55')]({'where':{'id':_0x3746d6[_0xb71b('0x5e')]['id']}})[_0xb71b('0x33')](handleEntityNotFound(_0x2c880c,null))[_0xb71b('0x33')](function(_0x19853c){if(_0x19853c){_0x3746d6['body'][_0xb71b('0x60')]=_0x19853c['id'];return db[_0xb71b('0x61')]['create'](_0x3746d6[_0xb71b('0x56')]);}})[_0xb71b('0x33')](respondWithResult(_0x2c880c,null))[_0xb71b('0x53')](handleError(_0x2c880c,null));};exports[_0xb71b('0x62')]=function(_0x4d22d5,_0x27a60f,_0x10e154){var _0x4e81b2={'raw':![],'where':{}};var _0x912697={};var _0x1cf205={'count':0x0,'rows':[]};return db[_0xb71b('0x3c')]['findOne']({'where':{'id':_0x4d22d5[_0xb71b('0x5e')]['id']}})[_0xb71b('0x33')](handleEntityNotFound(_0x27a60f,null))[_0xb71b('0x33')](function(_0x301fab){if(_0x301fab){_0x912697[_0xb71b('0x3f')]=_['keys'](db[_0xb71b('0x61')][_0xb71b('0x3d')]);_0x912697[_0xb71b('0x40')]=_['keys'](_0x4d22d5[_0xb71b('0x40')]);_0x912697['filters']=_[_0xb71b('0x44')](_0x912697[_0xb71b('0x3f')],_0x912697[_0xb71b('0x40')]);_0x4e81b2[_0xb71b('0x43')]=_['intersection'](_0x912697[_0xb71b('0x3f')],qs['fields'](_0x4d22d5[_0xb71b('0x40')][_0xb71b('0x45')]));_0x4e81b2[_0xb71b('0x43')]=_0x4e81b2[_0xb71b('0x43')][_0xb71b('0x46')]?_0x4e81b2[_0xb71b('0x43')]:_0x912697[_0xb71b('0x3f')];if(!_0x4d22d5['query'][_0xb71b('0x47')](_0xb71b('0x48'))){_0x4e81b2[_0xb71b('0x2e')]=qs[_0xb71b('0x2e')](_0x4d22d5[_0xb71b('0x40')]['limit']);_0x4e81b2[_0xb71b('0x2d')]=qs[_0xb71b('0x2d')](_0x4d22d5[_0xb71b('0x40')][_0xb71b('0x2d')]);}_0x4e81b2[_0xb71b('0x49')]=qs[_0xb71b('0x4a')](_0x4d22d5['query'][_0xb71b('0x4a')]);_0x4e81b2[_0xb71b('0x4d')]=qs['filters'](_['pick'](_0x4d22d5[_0xb71b('0x40')],_0x912697[_0xb71b('0x42')]));_0x4e81b2[_0xb71b('0x4d')][_0xb71b('0x60')]=_0x301fab['id'];if(_0x4d22d5[_0xb71b('0x40')]['filter']){_0x4e81b2[_0xb71b('0x4d')]=_['merge'](_0x4e81b2[_0xb71b('0x4d')],{'$or':_[_0xb71b('0x3b')](_0x4e81b2[_0xb71b('0x43')],function(_0x5e0c0b){var _0x490538={};_0x490538[_0x5e0c0b]={'$like':'%'+_0x4d22d5[_0xb71b('0x40')]['filter']+'%'};return _0x490538;})});}_0x4e81b2=_[_0xb71b('0x4c')]({},_0x4e81b2,_0x4d22d5[_0xb71b('0x4f')]);return db['Disposition'][_0xb71b('0x2c')]({'where':_0x4e81b2[_0xb71b('0x4d')]})[_0xb71b('0x33')](function(_0x3af106){_0x1cf205[_0xb71b('0x2c')]=_0x3af106;if(_0x4d22d5[_0xb71b('0x40')][_0xb71b('0x50')]){_0x4e81b2['include']=[{'all':!![]}];}return db[_0xb71b('0x61')][_0xb71b('0x63')](_0x4e81b2);})[_0xb71b('0x33')](function(_0x2059e1){_0x1cf205[_0xb71b('0x52')]=_0x2059e1;return _0x1cf205;});}})[_0xb71b('0x33')](respondWithFilteredResult(_0x27a60f,_0x4e81b2))[_0xb71b('0x53')](handleError(_0x27a60f,null));};exports[_0xb71b('0x64')]=function(_0x1f3b68,_0x4ee520,_0x5cc7a6){return db[_0xb71b('0x3c')]['find']({'where':{'id':_0x1f3b68[_0xb71b('0x5e')]['id']}})[_0xb71b('0x33')](handleEntityNotFound(_0x4ee520,null))[_0xb71b('0x33')](function(_0x2ac052){if(_0x2ac052){return _0x2ac052[_0xb71b('0x64')](_0x1f3b68[_0xb71b('0x40')][_0xb71b('0x65')]);}})['then'](respondWithStatusCode(_0x4ee520,null))[_0xb71b('0x53')](handleError(_0x4ee520,null));};exports[_0xb71b('0x66')]=function(_0x255a9c,_0x113422,_0x2ad961){if(_0x255a9c['body']['id']){delete _0x255a9c[_0xb71b('0x56')]['id'];}return db['FaxAccount'][_0xb71b('0x55')]({'where':{'id':_0x255a9c[_0xb71b('0x5e')]['id']}})['then'](handleEntityNotFound(_0x113422,null))[_0xb71b('0x33')](function(_0x2b2b64){if(_0x2b2b64){_0x255a9c[_0xb71b('0x56')][_0xb71b('0x60')]=_0x2b2b64['id'];return db[_0xb71b('0x67')]['create'](_0x255a9c[_0xb71b('0x56')]);}})[_0xb71b('0x33')](respondWithResult(_0x113422,null))['catch'](handleError(_0x113422,null));};exports['getAnswers']=function(_0x5933c6,_0x32cc39,_0x58630d){var _0x1d0927={'raw':![],'where':{}};var _0x8f11ca={};var _0x3b9200={'count':0x0,'rows':[]};return db[_0xb71b('0x3c')][_0xb71b('0x68')]({'where':{'id':_0x5933c6[_0xb71b('0x5e')]['id']}})[_0xb71b('0x33')](handleEntityNotFound(_0x32cc39,null))[_0xb71b('0x33')](function(_0x2b94dd){if(_0x2b94dd){_0x8f11ca[_0xb71b('0x3f')]=_[_0xb71b('0x41')](db[_0xb71b('0x67')][_0xb71b('0x3d')]);_0x8f11ca[_0xb71b('0x40')]=_[_0xb71b('0x41')](_0x5933c6['query']);_0x8f11ca[_0xb71b('0x42')]=_[_0xb71b('0x44')](_0x8f11ca[_0xb71b('0x3f')],_0x8f11ca[_0xb71b('0x40')]);_0x1d0927[_0xb71b('0x43')]=_[_0xb71b('0x44')](_0x8f11ca['model'],qs[_0xb71b('0x45')](_0x5933c6[_0xb71b('0x40')]['fields']));_0x1d0927[_0xb71b('0x43')]=_0x1d0927[_0xb71b('0x43')][_0xb71b('0x46')]?_0x1d0927[_0xb71b('0x43')]:_0x8f11ca[_0xb71b('0x3f')];if(!_0x5933c6[_0xb71b('0x40')][_0xb71b('0x47')]('nolimit')){_0x1d0927[_0xb71b('0x2e')]=qs[_0xb71b('0x2e')](_0x5933c6['query'][_0xb71b('0x2e')]);_0x1d0927[_0xb71b('0x2d')]=qs[_0xb71b('0x2d')](_0x5933c6[_0xb71b('0x40')][_0xb71b('0x2d')]);}_0x1d0927[_0xb71b('0x49')]=qs[_0xb71b('0x4a')](_0x5933c6['query'][_0xb71b('0x4a')]);_0x1d0927[_0xb71b('0x4d')]=qs[_0xb71b('0x42')](_[_0xb71b('0x69')](_0x5933c6[_0xb71b('0x40')],_0x8f11ca[_0xb71b('0x42')]));_0x1d0927['where'][_0xb71b('0x60')]=_0x2b94dd['id'];if(_0x5933c6[_0xb71b('0x40')][_0xb71b('0x4b')]){_0x1d0927['where']=_[_0xb71b('0x4c')](_0x1d0927[_0xb71b('0x4d')],{'$or':_[_0xb71b('0x3b')](_0x1d0927['attributes'],function(_0xb1d01f){var _0x4ce66e={};_0x4ce66e[_0xb1d01f]={'$like':'%'+_0x5933c6[_0xb71b('0x40')][_0xb71b('0x4b')]+'%'};return _0x4ce66e;})});}_0x1d0927=_['merge']({},_0x1d0927,_0x5933c6[_0xb71b('0x4f')]);return db['CannedAnswer'][_0xb71b('0x2c')]({'where':_0x1d0927[_0xb71b('0x4d')]})[_0xb71b('0x33')](function(_0x4b0770){_0x3b9200[_0xb71b('0x2c')]=_0x4b0770;if(_0x5933c6[_0xb71b('0x40')][_0xb71b('0x50')]){_0x1d0927[_0xb71b('0x51')]=[{'all':!![]}];}return db[_0xb71b('0x67')][_0xb71b('0x63')](_0x1d0927);})[_0xb71b('0x33')](function(_0x30c7ef){_0x3b9200[_0xb71b('0x52')]=_0x30c7ef;return _0x3b9200;});}})[_0xb71b('0x33')](respondWithFilteredResult(_0x32cc39,_0x1d0927))[_0xb71b('0x53')](handleError(_0x32cc39,null));};exports['removeAnswers']=function(_0x19ab48,_0x41a82a,_0x1ae64e){return db[_0xb71b('0x3c')][_0xb71b('0x55')]({'where':{'id':_0x19ab48[_0xb71b('0x5e')]['id']}})[_0xb71b('0x33')](handleEntityNotFound(_0x41a82a,null))['then'](function(_0x3ce25a){if(_0x3ce25a){return _0x3ce25a[_0xb71b('0x6a')](_0x19ab48['query'][_0xb71b('0x65')]);}})['then'](respondWithStatusCode(_0x41a82a,null))[_0xb71b('0x53')](handleError(_0x41a82a,null));};exports['addInteraction']=function(_0xce0100,_0x8268ea,_0x73b700){return db['FaxInteraction']['find']({'where':{'id':_0xce0100['params']['id']}})[_0xb71b('0x33')](handleEntityNotFound(_0x8268ea,null))[_0xb71b('0x33')](function(_0x3cff0f){if(_0x3cff0f){return _0x3cff0f[_0xb71b('0x6b')](_0xce0100['body'][_0xb71b('0x65')],_[_0xb71b('0x6c')](_0xce0100[_0xb71b('0x56')],[_0xb71b('0x65'),'id'])||{});}})[_0xb71b('0x33')](respondWithResult(_0x8268ea,null))['catch'](handleError(_0x8268ea,null));};exports['getInteractions']=function(_0x5e7c3b,_0x483234,_0x222ef6){var _0x1b223d={'raw':![],'where':{}};var _0x1997f3={};var _0x1bc595={'count':0x0,'rows':[]};return db[_0xb71b('0x3c')][_0xb71b('0x68')]({'where':{'id':_0x5e7c3b[_0xb71b('0x5e')]['id']}})['then'](handleEntityNotFound(_0x483234,null))[_0xb71b('0x33')](function(_0x1fdad0){if(_0x1fdad0){_0x1997f3[_0xb71b('0x3f')]=_[_0xb71b('0x41')](db['FaxInteraction']['rawAttributes']);_0x1997f3[_0xb71b('0x40')]=_[_0xb71b('0x41')](_0x5e7c3b[_0xb71b('0x40')]);_0x1997f3[_0xb71b('0x42')]=_[_0xb71b('0x44')](_0x1997f3[_0xb71b('0x3f')],_0x1997f3[_0xb71b('0x40')]);_0x1b223d[_0xb71b('0x43')]=_[_0xb71b('0x44')](_0x1997f3['model'],qs[_0xb71b('0x45')](_0x5e7c3b[_0xb71b('0x40')][_0xb71b('0x45')]));_0x1b223d[_0xb71b('0x43')]=_0x1b223d[_0xb71b('0x43')][_0xb71b('0x46')]?_0x1b223d[_0xb71b('0x43')]:_0x1997f3[_0xb71b('0x3f')];if(!_0x5e7c3b['query'][_0xb71b('0x47')]('nolimit')){_0x1b223d[_0xb71b('0x2e')]=qs['limit'](_0x5e7c3b['query'][_0xb71b('0x2e')]);_0x1b223d[_0xb71b('0x2d')]=qs[_0xb71b('0x2d')](_0x5e7c3b[_0xb71b('0x40')][_0xb71b('0x2d')]);}_0x1b223d[_0xb71b('0x49')]=qs[_0xb71b('0x4a')](_0x5e7c3b[_0xb71b('0x40')][_0xb71b('0x4a')]);_0x1b223d[_0xb71b('0x4d')]=qs['filters'](_[_0xb71b('0x69')](_0x5e7c3b[_0xb71b('0x40')],_0x1997f3[_0xb71b('0x42')]));_0x1b223d[_0xb71b('0x4d')][_0xb71b('0x60')]=_0x1fdad0['id'];if(_0x5e7c3b['query']['filter']){_0x1b223d[_0xb71b('0x4d')]=_[_0xb71b('0x4c')](_0x1b223d['where'],{'$or':_[_0xb71b('0x3b')](_0x1b223d['attributes'],function(_0xbaf27d){var _0x1e05d2={};_0x1e05d2[_0xbaf27d]={'$like':'%'+_0x5e7c3b[_0xb71b('0x40')][_0xb71b('0x4b')]+'%'};return _0x1e05d2;})});}_0x1b223d=_[_0xb71b('0x4c')]({},_0x1b223d,_0x5e7c3b['options']);return db[_0xb71b('0x6d')][_0xb71b('0x2c')]({'where':_0x1b223d[_0xb71b('0x4d')]})['then'](function(_0x318f8f){_0x1bc595[_0xb71b('0x2c')]=_0x318f8f;if(_0x5e7c3b[_0xb71b('0x40')][_0xb71b('0x50')]){_0x1b223d[_0xb71b('0x51')]=[{'model':db['CmContact'],'as':_0xb71b('0x6e'),'required':![]},{'model':db['User'],'as':_0xb71b('0x6f'),'attributes':[_0xb71b('0x36'),_0xb71b('0x70'),_0xb71b('0x71')],'required':![]},{'model':db[_0xb71b('0x72')],'as':_0xb71b('0x73'),'attributes':['id',_0xb71b('0x36'),_0xb71b('0x74')],'where':_0x5e7c3b[_0xb71b('0x40')][_0xb71b('0x75')]?{'id':_0x5e7c3b[_0xb71b('0x40')][_0xb71b('0x75')]}:undefined,'required':_0x5e7c3b[_0xb71b('0x40')][_0xb71b('0x75')]?!![]:![]}];}return db[_0xb71b('0x6d')][_0xb71b('0x63')](_0x1b223d);})[_0xb71b('0x33')](function(_0xe987c4){_0x1bc595['rows']=_0xe987c4;return _0x1bc595;});}})[_0xb71b('0x33')](respondWithFilteredResult(_0x483234,_0x1b223d))['catch'](handleError(_0x483234,null));};exports[_0xb71b('0x76')]=function(_0x15ecc4,_0x383005){var _0x59dc57=_0x15ecc4[_0xb71b('0x5e')]['id'];var _0x14e1a2=_0x15ecc4[_0xb71b('0x56')];var _0x5482c9=0xc8;var _0x1af28a=null;return db[_0xb71b('0x77')][_0xb71b('0x78')]({'isolationLevel':db[_0xb71b('0x77')][_0xb71b('0x79')][_0xb71b('0x7a')][_0xb71b('0x7b')]},function(_0x1ee165){return db[_0xb71b('0x3c')]['findOne']({'where':{'id':_0x59dc57},'transaction':_0x1ee165})['then'](function(_0x214143){if(_0x214143){return db[_0xb71b('0x7c')]['destroy']({'where':{'FaxAccountId':_0x59dc57},'transaction':_0x1ee165})[_0xb71b('0x33')](function(){var _0x4d2040=_[_0xb71b('0x3b')](_0x14e1a2,function(_0x264103){_0x264103[_0xb71b('0x60')]=_0x59dc57;return _0x264103;});return db[_0xb71b('0x7c')][_0xb71b('0x7d')](_0x4d2040,{'transaction':_0x1ee165});});}else{_0x5482c9=0x194;_0x1af28a=[];}});})[_0xb71b('0x33')](function(){if(_0x5482c9!==0x194){return db['FaxApplication']['findAndCountAll']({'where':{'FaxAccountId':_0x59dc57},'order':_0xb71b('0x7e')})[_0xb71b('0x33')](function(_0xe60e69){_0x1af28a=_0xe60e69;});}})['catch'](function(_0x5064b8){_0x5482c9=0x1f4;logger[_0xb71b('0x23')](_0x5064b8[_0xb71b('0x7f')]);if(_0x5064b8[_0xb71b('0x36')]){delete _0x5064b8[_0xb71b('0x36')];}_0x1af28a=_0x5064b8;})[_0xb71b('0x80')](function(){if(_0x1af28a===null){_0x383005[_0xb71b('0x28')](_0x5482c9);}else{if(_0x5482c9===0x1f4){_0x383005['status'](_0x5482c9)[_0xb71b('0x37')](_0x1af28a);}else{_0x383005[_0xb71b('0x29')](_0x5482c9)[_0xb71b('0x2a')](_0x1af28a);}}});};exports[_0xb71b('0x81')]=function(_0x16e8b9,_0x23ee22,_0x171cb9){var _0x55d3ac={};var _0x333aae={};var _0x425a0a;var _0x28c807;return db[_0xb71b('0x3c')]['findOne']({'where':{'id':_0x16e8b9[_0xb71b('0x5e')]['id']}})['then'](handleEntityNotFound(_0x23ee22,null))['then'](function(_0x4e299a){if(_0x4e299a){_0x425a0a=_0x4e299a;_0x333aae['model']=_[_0xb71b('0x41')](db['FaxApplication'][_0xb71b('0x3d')]);_0x333aae[_0xb71b('0x40')]=_[_0xb71b('0x41')](_0x16e8b9[_0xb71b('0x40')]);_0x333aae[_0xb71b('0x42')]=_[_0xb71b('0x44')](_0x333aae['model'],_0x333aae['query']);_0x55d3ac[_0xb71b('0x43')]=_[_0xb71b('0x44')](_0x333aae['model'],qs[_0xb71b('0x45')](_0x16e8b9['query'][_0xb71b('0x45')]));_0x55d3ac['attributes']=_0x55d3ac[_0xb71b('0x43')][_0xb71b('0x46')]?_0x55d3ac['attributes']:_0x333aae[_0xb71b('0x3f')];_0x55d3ac[_0xb71b('0x49')]=qs['sort'](_0x16e8b9['query'][_0xb71b('0x4a')]);_0x55d3ac[_0xb71b('0x4d')]=qs[_0xb71b('0x42')](_[_0xb71b('0x69')](_0x16e8b9[_0xb71b('0x40')],_0x333aae[_0xb71b('0x42')]));if(_0x16e8b9['query'][_0xb71b('0x4b')]){_0x55d3ac[_0xb71b('0x4d')]=_[_0xb71b('0x4c')](_0x55d3ac[_0xb71b('0x4d')],{'$or':_['map'](_0x55d3ac[_0xb71b('0x43')],function(_0x2c77f3){var _0x278e74={};_0x278e74[_0x2c77f3]={'$like':'%'+_0x16e8b9[_0xb71b('0x40')]['filter']+'%'};return _0x278e74;})});}_0x55d3ac=_[_0xb71b('0x4c')]({},_0x55d3ac,_0x16e8b9[_0xb71b('0x4f')]);return _0x425a0a[_0xb71b('0x81')](_0x55d3ac);}})[_0xb71b('0x33')](function(_0x268d47){if(_0x268d47){_0x28c807=_0x268d47[_0xb71b('0x46')];if(!_0x16e8b9[_0xb71b('0x40')][_0xb71b('0x47')](_0xb71b('0x48'))){_0x55d3ac['limit']=qs['limit'](_0x16e8b9['query'][_0xb71b('0x2e')]);_0x55d3ac[_0xb71b('0x2d')]=qs['offset'](_0x16e8b9[_0xb71b('0x40')][_0xb71b('0x2d')]);}return _0x425a0a[_0xb71b('0x81')](_0x55d3ac);}})[_0xb71b('0x33')](function(_0x57e392){if(_0x57e392){return _0x57e392?{'count':_0x28c807,'rows':_0x57e392}:null;}})[_0xb71b('0x33')](respondWithResult(_0x23ee22,null))[_0xb71b('0x53')](handleError(_0x23ee22,null));};function Extension(_0x33d021,_0x3d876d,_0x5cca87,_0x8b479d){this[_0xb71b('0x82')]=_0xb71b('0x83');this['exten']=_0x33d021[_0xb71b('0x84')];this[_0xb71b('0x85')]=_0x8b479d;this['type']=_0xb71b('0x86');this['description']=_0xb71b('0x87');this['FaxAccountId']=_0x33d021['id'];this[_0xb71b('0x7e')]=_0x3d876d;this['appdata']=_0x5cca87;}function createExtensionsReciveFax(_0x1d496b){var _0x431b96=0x1;var _0x227a1e=[];_0x227a1e[_0xb71b('0x88')](new Extension(_0x1d496b,_0x431b96,'',_0xb71b('0x89')));_0x431b96+=0x1;_0x227a1e[_0xb71b('0x88')](new Extension(_0x1d496b,_0x431b96,_0xb71b('0x8a'),_0xb71b('0x8b')));_0x431b96+=0x1;for(var _0x3613c7 in _0x1d496b){if(_0x1d496b[_0xb71b('0x47')](_0x3613c7)&&(_0x3613c7===_0xb71b('0x8c')||_0x3613c7===_0xb71b('0x84')||_0x3613c7==='gateway'||_0x3613c7===_0xb71b('0x8d')||_0x3613c7===_0xb71b('0x8e')||_0x3613c7===_0xb71b('0x8f')||_0x3613c7===_0xb71b('0x90')||_0x3613c7===_0xb71b('0x91')||_0x3613c7===_0xb71b('0x92'))){_0x227a1e['push'](new Extension(_0x1d496b,_0x431b96,_0xb71b('0x93')+_0x3613c7+')='+_0x1d496b[_0x3613c7],'Set'));_0x431b96+=0x1;}}_0x227a1e[_0xb71b('0x88')](new Extension(_0x1d496b,_0x431b96,'6','Wait'));_0x431b96+=0x1;_0x227a1e['push'](new Extension(_0x1d496b,_0x431b96,'/var/opt/motion2/server/files/attachments/fax-${CALLERID(num)}-${CUT(UNIQUEID,.,1)}-${CUT(UNIQUEID,.,2)}-${STRFTIME(,,%C%y%m%d%H%M%S)}-rx.tif,d',_0xb71b('0x94')));_0x431b96=0x0;return _0x227a1e;}exports[_0xb71b('0x95')]=function(_0x18b4bf,_0x54a748,_0x28f1ce){var _0xa4299c;return db['sequelize']['transaction'](function(_0x2e048e){return db['FaxAccount'][_0xb71b('0x5c')](_0x18b4bf[_0xb71b('0x56')],{'transaction':_0x2e048e})['then'](function(_0x372c94){_0xa4299c=_0x372c94[_0xb71b('0x57')]({'plain':!![]});return db[_0xb71b('0x96')]['bulkCreate'](createExtensionsReciveFax(_0xa4299c),{'transaction':_0x2e048e});});})['then'](function(){return _0xa4299c;})[_0xb71b('0x33')](respondWithResult(_0x54a748,null))[_0xb71b('0x53')](handleError(_0x54a748,null));};exports[_0xb71b('0x97')]=function(_0x4d4756,_0x4b24b7,_0x40e25a){var _0x4e1dd8;return db[_0xb71b('0x77')][_0xb71b('0x78')](function(_0x3c2848){return db[_0xb71b('0x3c')][_0xb71b('0x32')](_0x4d4756[_0xb71b('0x56')],{'where':{'id':_0x4d4756[_0xb71b('0x56')]['id']},'transaction':_0x3c2848})[_0xb71b('0x33')](function(_0x1923be){return db[_0xb71b('0x96')][_0xb71b('0x34')]({'where':{'FaxAccountId':_0x4d4756[_0xb71b('0x56')]['id']},'transaction':_0x3c2848})[_0xb71b('0x33')](function(_0x4da20c){return db['VoiceExtension']['bulkCreate'](createExtensionsReciveFax(_[_0xb71b('0x6c')](_0x4d4756[_0xb71b('0x56')],[_0xb71b('0x98'),_0xb71b('0x99'),_0xb71b('0x9a'),_0xb71b('0x9b'),_0xb71b('0x9c'),_0xb71b('0x9d')])),{'transaction':_0x3c2848});});});})[_0xb71b('0x33')](function(){return db[_0xb71b('0x3c')][_0xb71b('0x9e')](_0x4d4756[_0xb71b('0x56')]['id']);})['then'](respondWithResult(_0x4b24b7,null))[_0xb71b('0x53')](handleError(_0x4b24b7,null));};exports['getMessages']=function(_0x3e109b,_0x4980f9,_0x439f73){var _0x598401={'raw':!![],'where':{}};var _0x669b3e={};var _0x1c49c0={'count':0x0,'rows':[]};return db['FaxAccount']['findOne']({'where':{'id':_0x3e109b['params']['id']}})[_0xb71b('0x33')](handleEntityNotFound(_0x4980f9,null))[_0xb71b('0x33')](function(_0x359f67){if(_0x359f67){_0x669b3e[_0xb71b('0x3f')]=_['keys'](db['FaxMessage'][_0xb71b('0x3d')]);_0x669b3e[_0xb71b('0x40')]=_['keys'](_0x3e109b[_0xb71b('0x40')]);_0x669b3e[_0xb71b('0x42')]=_['intersection'](_0x669b3e[_0xb71b('0x3f')],_0x669b3e['query']);_0x598401[_0xb71b('0x43')]=_[_0xb71b('0x44')](_0x669b3e[_0xb71b('0x3f')],qs[_0xb71b('0x45')](_0x3e109b['query'][_0xb71b('0x45')]));_0x598401['attributes']=_0x598401['attributes']['length']?_0x598401[_0xb71b('0x43')]:_0x669b3e[_0xb71b('0x3f')];if(!_0x3e109b[_0xb71b('0x40')][_0xb71b('0x47')](_0xb71b('0x48'))){_0x598401[_0xb71b('0x2e')]=qs[_0xb71b('0x2e')](_0x3e109b[_0xb71b('0x40')]['limit']);_0x598401[_0xb71b('0x2d')]=qs[_0xb71b('0x2d')](_0x3e109b['query'][_0xb71b('0x2d')]);}_0x598401['order']=qs[_0xb71b('0x4a')](_0x3e109b[_0xb71b('0x40')]['sort']);_0x598401['where']=qs[_0xb71b('0x42')](_[_0xb71b('0x69')](_0x3e109b[_0xb71b('0x40')],_0x669b3e[_0xb71b('0x42')]));_0x598401[_0xb71b('0x4d')]['FaxAccountId']=_0x359f67['id'];if(_0x3e109b[_0xb71b('0x40')][_0xb71b('0x4b')]){_0x598401[_0xb71b('0x4d')]=_[_0xb71b('0x4c')](_0x598401[_0xb71b('0x4d')],{'$or':_['map'](_0x598401['attributes'],function(_0x11dd5a){var _0x42b6ad={};_0x42b6ad[_0x11dd5a]={'$like':'%'+_0x3e109b['query'][_0xb71b('0x4b')]+'%'};return _0x42b6ad;})});}if(_0x3e109b[_0xb71b('0x40')][_0xb71b('0x9f')]){var _0x6618f=_0x3e109b[_0xb71b('0x40')][_0xb71b('0x9f')][_0xb71b('0xa0')](',');var _0xb8a8d2={};_0xb8a8d2[_0x6618f[0x0]]={'$gte':moment(_0x6618f[0x1])[_0xb71b('0xa1')](_0xb71b('0xa2'))};_0x598401[_0xb71b('0x4d')]=_['merge'](_0x598401[_0xb71b('0x4d')],_0xb8a8d2);}_0x598401=_['merge']({},_0x598401,_0x3e109b[_0xb71b('0x4f')]);return db[_0xb71b('0xa3')][_0xb71b('0x2c')]({'where':_0x598401[_0xb71b('0x4d')]})['then'](function(_0x6aefb2){_0x1c49c0['count']=_0x6aefb2;if(_0x3e109b[_0xb71b('0x40')][_0xb71b('0x50')]){_0x598401[_0xb71b('0x51')]=[{'all':!![]}];}return db[_0xb71b('0xa3')]['findAll'](_0x598401);})[_0xb71b('0x33')](function(_0x4570d6){_0x1c49c0['rows']=_0x4570d6;return _0x1c49c0;});}})[_0xb71b('0x33')](respondWithFilteredResult(_0x4980f9,_0x598401))[_0xb71b('0x53')](handleError(_0x4980f9,null));};exports['send']=function(_0x30943e,_0x302c19,_0x4797cc){var _0x2cfae0,_0xc7d0b9={},_0xd964f5;if(_0x30943e[_0xb71b('0x56')]['to']){_0xd964f5=_0x30943e[_0xb71b('0x56')]['to'][0x0];}return db[_0xb71b('0x3c')][_0xb71b('0x55')]({'where':{'id':_0x30943e[_0xb71b('0x5e')]['id']},'include':[{'model':db[_0xb71b('0xa4')],'as':_0xb71b('0xa5'),'include':[{'model':db[_0xb71b('0xa6')],'as':_0xb71b('0xa7'),'where':{'fax':_0xd964f5},'limit':0x1,'order':[[_0xb71b('0x9b'),_0xb71b('0xa8')]]}]}]})[_0xb71b('0x33')](handleEntityNotFound(_0x302c19,null))[_0xb71b('0x33')](function(_0x32a226){_0x2cfae0=_0x32a226;if(_0x30943e[_0xb71b('0x56')][_0xb71b('0xa9')]&&_0x30943e['body'][_0xb71b('0xa9')][_0xb71b('0x46')]){for(var _0x2829bf=0x0;_0x2829bf<_0x30943e['body'][_0xb71b('0xa9')]['length'];_0x2829bf+=0x1){_0x30943e[_0xb71b('0x56')]['attachments'][_0x2829bf]={'filename':_0x30943e['body'][_0xb71b('0xa9')][_0x2829bf][_0xb71b('0x36')],'id':_0x30943e[_0xb71b('0x56')][_0xb71b('0xa9')][_0x2829bf]['id'],'path':path[_0xb71b('0xaa')](config[_0xb71b('0xab')],_0xb71b('0xac'),_0x30943e[_0xb71b('0x56')][_0xb71b('0xa9')][_0x2829bf][_0xb71b('0xad')])};}}return respondWithRpcPromise(_0xb71b('0xae'),_0xb71b('0xae'),{'FaxAccountId':_[_0xb71b('0xaf')](_0x30943e['params']['id'])?undefined:_0x30943e[_0xb71b('0x5e')]['id'],'path':_[_0xb71b('0xaf')](_0x30943e[_0xb71b('0x56')]['attachments'][0x0][_0xb71b('0xb0')])?undefined:_0x30943e[_0xb71b('0x56')]['attachments'][0x0][_0xb71b('0xb0')],'fax':_[_0xb71b('0xaf')](_0x30943e[_0xb71b('0x56')]['to'][0x0])?undefined:_0x30943e[_0xb71b('0x56')]['to'][0x0]},client9002);})['then'](function(){if(_0x2cfae0){if(_[_0xb71b('0xaf')](_0x30943e[_0xb71b('0x56')][_0xb71b('0xb1')])){_0x30943e[_0xb71b('0x56')][_0xb71b('0xb1')]=util[_0xb71b('0xa1')](_0xb71b('0xb2'),_0x2cfae0[_0xb71b('0x36')],_0x2cfae0[_0xb71b('0xb3')]);}if(_0x2cfae0[_0xb71b('0xa5')]){if(_0x2cfae0[_0xb71b('0xa5')][_0xb71b('0xa7')][_0xb71b('0x46')]){return _0x2cfae0[_0xb71b('0xa5')][_0xb71b('0xa7')][0x0];}else{return db[_0xb71b('0xa6')][_0xb71b('0x5c')](_[_0xb71b('0xb4')](_0x30943e[_0xb71b('0x56')],{'firstName':_0x30943e['body']['to'][0x0],'phone':_0x30943e['body']['to'][0x0],'fax':_0x30943e[_0xb71b('0x56')]['to'][0x0],'ListId':_0x2cfae0[_0xb71b('0x9d')]}));}}else{throw new Error(_0xb71b('0xb5'));}}else{throw new Error(_0xb71b('0xb6'));}})[_0xb71b('0x33')](function(_0x3d3182){if(_0x3d3182){return db[_0xb71b('0x6d')][_0xb71b('0x55')]({'where':{'ContactId':_0x3d3182['id'],'closed':![],'FaxAccountId':_0x2cfae0['id']}})[_0xb71b('0x33')](function(_0xa31962){if(_0xa31962){return[_0xa31962,![]];}return db[_0xb71b('0x6d')][_0xb71b('0x5c')]({'UserId':_0x30943e[_0xb71b('0xb7')]['id'],'ContactId':_0x3d3182['id'],'FaxAccountId':_0x2cfae0['id'],'fax':_0x30943e[_0xb71b('0x56')]['to'][0x0],'firstMsgDirection':_0xb71b('0xb8'),'Messages':[_[_0xb71b('0x4c')](_0x30943e['body'],{'read':![],'body':_0x30943e[_0xb71b('0x56')][_0xb71b('0xa9')][0x0]['filename'],'FaxAccountId':_0x2cfae0['id'],'UserId':_0x30943e[_0xb71b('0xb7')]['id'],'ContactId':_0x3d3182['id'],'AttachmentId':_0x30943e['body'][_0xb71b('0xa9')][0x0]['id']})]},{'include':[{'model':db[_0xb71b('0xa3')],'as':'Messages'}]})['then'](function(_0xf5f7f3){return[_0xf5f7f3,!![]];});});}else{throw new Error(_0xb71b('0xb9'));}})[_0xb71b('0xba')](function(_0x411b77,_0x4d68f6){if(_0x4d68f6){return _0x411b77;}return db[_0xb71b('0xa3')][_0xb71b('0x5c')]({'direction':_0xb71b('0xb8'),'read':![],'body':_0x30943e[_0xb71b('0x56')]['attachments'][0x0]['filename'],'FaxAccountId':_0x2cfae0['id'],'FaxInteractionId':_0x411b77['id'],'UserId':_0x30943e[_0xb71b('0xb7')]['id'],'ContactId':_0x411b77[_0xb71b('0xbb')],'AttachmentId':_0x30943e[_0xb71b('0x56')][_0xb71b('0xa9')][0x0]['id']})[_0xb71b('0x33')](function(_0x5c2cc0){_0x411b77[_0xb71b('0xbc')][_0xb71b('0xbd')]=[];_0x411b77['dataValues']['Messages'][_0xb71b('0x88')](_0x5c2cc0['dataValues']);return _0x411b77;});})['then'](function(_0x1d9eda){respondWithRpcPromise('SendFax',_0xb71b('0xbe'),{'FaxAccountId':_[_0xb71b('0xaf')](_0x30943e['params']['id'])?undefined:_0x30943e[_0xb71b('0x5e')]['id'],'path':_['isNil'](_0x30943e['body'][_0xb71b('0xa9')][0x0][_0xb71b('0xb0')])?undefined:_0x30943e[_0xb71b('0x56')]['attachments'][0x0][_0xb71b('0xb0')],'fax':_['isNil'](_0x30943e['body']['to'][0x0])?undefined:_0x30943e[_0xb71b('0x56')]['to'][0x0],'AttachmentId':_0x30943e['body'][_0xb71b('0xa9')][0x0]['id']},client9002)[_0xb71b('0x33')](function(_0x47392d){logger['info']('SendFaxRpc,\x20%s',_0x47392d);})['catch'](function(_0x2e56ef){logger[_0xb71b('0x20')](_0xb71b('0xbf'),_0x2e56ef);});return _0x1d9eda;})[_0xb71b('0x33')](respondWithResult(_0x302c19,null))['catch'](handleError(_0x302c19,null));};exports[_0xb71b('0xc0')]=function(_0x236aab,_0x594004,_0x8b37b1){return db['FaxAccount'][_0xb71b('0x55')]({'where':{'id':_0x236aab[_0xb71b('0x5e')]['id']}})[_0xb71b('0x33')](handleEntityNotFound(_0x594004,null))[_0xb71b('0x33')](function(_0xde494){if(_0xde494){return _0xde494[_0xb71b('0xc0')](_0x236aab[_0xb71b('0x56')][_0xb71b('0x65')],_[_0xb71b('0x6c')](_0x236aab[_0xb71b('0x56')],[_0xb71b('0x65'),'id'])||{})[_0xb71b('0xba')](function(_0x1da3c7){for(var _0x258d56=0x0;_0x258d56<_0x236aab[_0xb71b('0x56')][_0xb71b('0x65')][_0xb71b('0x46')];_0x258d56+=0x1){socket[_0xb71b('0xc1')](_0xb71b('0xc2'),{'UserId':Number(_0x236aab['body']['ids'][_0x258d56]),'FaxAccountId':Number(_0x236aab['params']['id'])});}return _0x1da3c7;});}})[_0xb71b('0x33')](respondWithResult(_0x594004,null))['catch'](handleError(_0x594004,null));};exports['removeAgents']=function(_0x1dc658,_0x554509,_0x31eadb){return db[_0xb71b('0x3c')]['find']({'where':{'id':_0x1dc658[_0xb71b('0x5e')]['id']}})[_0xb71b('0x33')](handleEntityNotFound(_0x554509,null))[_0xb71b('0x33')](function(_0x2d39b2){if(_0x2d39b2){return _0x2d39b2[_0xb71b('0xc3')](_0x1dc658[_0xb71b('0x40')][_0xb71b('0x65')])[_0xb71b('0x33')](function(){if(_[_0xb71b('0xc4')](_0x1dc658[_0xb71b('0x40')][_0xb71b('0x65')])){for(var _0x5b5ae4=0x0;_0x5b5ae4<_0x1dc658[_0xb71b('0x40')][_0xb71b('0x65')][_0xb71b('0x46')];_0x5b5ae4+=0x1){socket[_0xb71b('0xc1')](_0xb71b('0xc5'),{'UserId':Number(_0x1dc658['query'][_0xb71b('0x65')][_0x5b5ae4]),'FaxAccountId':Number(_0x1dc658[_0xb71b('0x5e')]['id'])});}}else{socket[_0xb71b('0xc1')](_0xb71b('0xc5'),{'UserId':Number(_0x1dc658[_0xb71b('0x40')][_0xb71b('0x65')]),'FaxAccountId':Number(_0x1dc658[_0xb71b('0x5e')]['id'])});}});}})[_0xb71b('0x33')](respondWithStatusCode(_0x554509,null))['catch'](handleError(_0x554509,null));};exports[_0xb71b('0xc6')]=function(_0x5b9f0e,_0x484b29,_0x3fba84){var _0x2fcbdb={};var _0x2391e4={};var _0x16e831;var _0x29b3b8;return db[_0xb71b('0x3c')][_0xb71b('0x68')]({'where':{'id':_0x5b9f0e[_0xb71b('0x5e')]['id']}})['then'](handleEntityNotFound(_0x484b29,null))[_0xb71b('0x33')](function(_0x128b4c){if(_0x128b4c){_0x16e831=_0x128b4c;_0x2391e4[_0xb71b('0x3f')]=_[_0xb71b('0x41')](db['User']['rawAttributes']);_0x2391e4[_0xb71b('0x40')]=_[_0xb71b('0x41')](_0x5b9f0e[_0xb71b('0x40')]);_0x2391e4[_0xb71b('0x42')]=_[_0xb71b('0x44')](_0x2391e4[_0xb71b('0x3f')],_0x2391e4[_0xb71b('0x40')]);_0x2fcbdb[_0xb71b('0x43')]=_[_0xb71b('0x44')](_0x2391e4['model'],qs[_0xb71b('0x45')](_0x5b9f0e[_0xb71b('0x40')][_0xb71b('0x45')]));_0x2fcbdb[_0xb71b('0x43')]=_0x2fcbdb[_0xb71b('0x43')][_0xb71b('0x46')]?_0x2fcbdb[_0xb71b('0x43')]:_0x2391e4['model'];_0x2fcbdb[_0xb71b('0x49')]=qs[_0xb71b('0x4a')](_0x5b9f0e['query'][_0xb71b('0x4a')]);_0x2fcbdb[_0xb71b('0x4d')]=qs[_0xb71b('0x42')](_[_0xb71b('0x69')](_0x5b9f0e[_0xb71b('0x40')],_0x2391e4[_0xb71b('0x42')]));if(_0x5b9f0e[_0xb71b('0x40')][_0xb71b('0x4b')]){_0x2fcbdb['where']=_[_0xb71b('0x4c')](_0x2fcbdb[_0xb71b('0x4d')],{'$or':_[_0xb71b('0x3b')](_0x2fcbdb[_0xb71b('0x43')],function(_0x246d6a){var _0xce4716={};_0xce4716[_0x246d6a]={'$like':'%'+_0x5b9f0e[_0xb71b('0x40')][_0xb71b('0x4b')]+'%'};return _0xce4716;})});}_0x2fcbdb=_[_0xb71b('0x4c')]({},_0x2fcbdb,_0x5b9f0e[_0xb71b('0x4f')]);return _0x16e831[_0xb71b('0xc6')](_0x2fcbdb);}})[_0xb71b('0x33')](function(_0x29bb14){if(_0x29bb14){_0x29b3b8=_0x29bb14[_0xb71b('0x46')];if(!_0x5b9f0e[_0xb71b('0x40')][_0xb71b('0x47')](_0xb71b('0x48'))){_0x2fcbdb[_0xb71b('0x2e')]=qs[_0xb71b('0x2e')](_0x5b9f0e[_0xb71b('0x40')][_0xb71b('0x2e')]);_0x2fcbdb[_0xb71b('0x2d')]=qs[_0xb71b('0x2d')](_0x5b9f0e[_0xb71b('0x40')][_0xb71b('0x2d')]);}return _0x16e831[_0xb71b('0xc6')](_0x2fcbdb);}})[_0xb71b('0x33')](function(_0x2b14d1){if(_0x2b14d1){return _0x2b14d1?{'count':_0x29b3b8,'rows':_0x2b14d1}:null;}})[_0xb71b('0x33')](respondWithResult(_0x484b29,null))[_0xb71b('0x53')](handleError(_0x484b29,null));};