Built motion from commit 9e1399f3.|2.5.37
[motion2.git] / server / api / smsAccount / smsAccount.controller.js
index 3283d25..030bdc0 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x2a84=['bluebird','util','path','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','defaults','redis','localhost','socket.io-emitter','register','jayson/promise','http','request','info','SmsAccount,\x20%s,\x20%s','request\x20sent','debug','SmsAccount,\x20%s,\x20%s,\x20%s','stringify','error','message','result','catch','sendStatus','end','json','count','offset','status','Content-Range','apply','save','update','then','destroy','get','SmsAccounts','UserProfileResource','name','send','index','mandatoryDispositionPause','map','SmsAccount','rawAttributes','fieldName','key','model','query','keys','filters','attributes','intersection','fields','length','limit','order','sort','where','pick','filter','merge','type','VIRTUAL','options','includeAll','include','findAll','rows','show','params','Pause','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','addDisposition','SmsAccountId','Disposition','getDispositions','findOne','nolimit','removeDispositions','ids','getAnswers','CannedAnswer','hasOwnProperty','removeAnswers','notify','sms','Applications','account','applications','asc','CmContact','Sequelize','difference','createdAt','updatedAt','CompanyId','ListId','mobile','twilio','from','Body','MessageSid','skebby','sender','clicksend','messageId','message_id','plivo','From','infobip','results','text','csc','originatingAddress','segmentedMessage','clickatell','fromNumber','replyMessageId','intelepeer','refid','isNil','ValidationError','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','Contacts','DESC','list','omit','contact','SmsInteraction','spread','interaction','created','push','close','unmanaged','*,*,*,*','SmsMessage','ContactId','AttachmentId','UserId','User','unshift','agent','Start','startRouting','entity\x20found','set','Content-Type','addApplications','sequelize','transaction','SmsApplication','bulkCreate','findAndCountAll','priority','getApplications','getInteractions','Contact','Owner','fullname','internal','Tag','Tags','color','tag','body\x20is\x20mandatory\x20and\x20not\x20empty','to\x20is\x20mandatory','List','out','Messages','dataValues','log','endpoint\x20/status\x20POST\x20/','received\x20delivery\x20report\x20from','inspect','skebby_dispatch_id','connectel','requestid','statusInt','status_code','DELIVERED','groupName','redif','error_code','DELIVERED_TO_GATEWAY','RECEIVED_BY_RECIPIENT','DELIVRD','ACCEPTD','statusGet','message-id','state','addAgents','emit','userSmsAccount:save','removeAgents','userSmsAccount:remove','getAgents','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment'];(function(_0x321bb2,_0x202794){var _0x9c12ed=function(_0x263dd3){while(--_0x263dd3){_0x321bb2['push'](_0x321bb2['shift']());}};_0x9c12ed(++_0x202794);}(_0x2a84,0xdf));var _0x42a8=function(_0x14add3,_0x13ce8d){_0x14add3=_0x14add3-0x0;var _0x4a174f=_0x2a84[_0x14add3];return _0x4a174f;};'use strict';var pdf=require(_0x42a8('0x0'));var emlformat=require(_0x42a8('0x1'));var rimraf=require(_0x42a8('0x2'));var zipdir=require(_0x42a8('0x3'));var jsonpatch=require(_0x42a8('0x4'));var rp=require(_0x42a8('0x5'));var moment=require(_0x42a8('0x6'));var BPromise=require(_0x42a8('0x7'));var Mustache=require('mustache');var util=require(_0x42a8('0x8'));var path=require(_0x42a8('0x9'));var sox=require('sox');var csv=require(_0x42a8('0xa'));var ejs=require(_0x42a8('0xb'));var fs=require('fs');var _=require(_0x42a8('0xc'));var squel=require(_0x42a8('0xd'));var crypto=require(_0x42a8('0xe'));var jsforce=require(_0x42a8('0xf'));var deskjs=require(_0x42a8('0x10'));var toCsv=require(_0x42a8('0xa'));var querystring=require('querystring');var Papa=require(_0x42a8('0x11'));var Redis=require(_0x42a8('0x12'));var authService=require('../../components/auth/service');var qs=require(_0x42a8('0x13'));var as=require(_0x42a8('0x14'));var hardwareService=require(_0x42a8('0x15'));var logger=require(_0x42a8('0x16'))(_0x42a8('0x17'));var utils=require(_0x42a8('0x18'));var config=require('../../config/environment');var licenseUtil=require(_0x42a8('0x19'));var db=require(_0x42a8('0x1a'))['db'];config['redis']=_[_0x42a8('0x1b')](config[_0x42a8('0x1c')],{'host':_0x42a8('0x1d'),'port':0x18eb});var socket=require(_0x42a8('0x1e'))(new Redis(config[_0x42a8('0x1c')]));require('./smsAccount.socket')[_0x42a8('0x1f')](socket);var jayson=require(_0x42a8('0x20'));var client=jayson['client'][_0x42a8('0x21')]({'port':0x232c});function respondWithRpcPromise(_0x29a5dc,_0x4c99ce,_0x15858b,_0x2509fe){return new BPromise(function(_0x5592ab,_0x5c6c24){var _0x42d863=_0x2509fe||client;return _0x42d863[_0x42a8('0x22')](_0x29a5dc,_0x15858b)['then'](function(_0x4dbf66){logger[_0x42a8('0x23')](_0x42a8('0x24'),_0x4c99ce,_0x42a8('0x25'));logger[_0x42a8('0x26')](_0x42a8('0x27'),_0x4c99ce,_0x42a8('0x25'),JSON[_0x42a8('0x28')](_0x4dbf66));if(_0x4dbf66['error']){if(_0x4dbf66['error']['code']===0x1f4){logger[_0x42a8('0x29')](_0x42a8('0x24'),_0x4c99ce,_0x4dbf66[_0x42a8('0x29')][_0x42a8('0x2a')]);return _0x5c6c24(_0x4dbf66[_0x42a8('0x29')]['message']);}logger[_0x42a8('0x29')](_0x42a8('0x24'),_0x4c99ce,_0x4dbf66[_0x42a8('0x29')][_0x42a8('0x2a')]);return _0x5592ab(_0x4dbf66[_0x42a8('0x29')][_0x42a8('0x2a')]);}else{logger[_0x42a8('0x23')](_0x42a8('0x24'),_0x4c99ce,_0x42a8('0x25'));_0x5592ab(_0x4dbf66[_0x42a8('0x2b')][_0x42a8('0x2a')]);}})[_0x42a8('0x2c')](function(_0x145d74){logger[_0x42a8('0x29')](_0x42a8('0x24'),_0x4c99ce,_0x145d74);_0x5c6c24(_0x145d74);});});}function respondWithStatusCode(_0x261711,_0x25f36e){_0x25f36e=_0x25f36e||0xcc;return function(_0x51e248){if(_0x51e248){return _0x261711[_0x42a8('0x2d')](_0x25f36e);}return _0x261711['status'](_0x25f36e)[_0x42a8('0x2e')]();};}function respondWithResult(_0x1e1591,_0x4f5a1f){_0x4f5a1f=_0x4f5a1f||0xc8;return function(_0x4bd93a){if(_0x4bd93a){return _0x1e1591['status'](_0x4f5a1f)[_0x42a8('0x2f')](_0x4bd93a);}};}function respondWithFilteredResult(_0x2359ae,_0x417123){return function(_0xc0c19f){if(_0xc0c19f){var _0x3e937d=_0xc0c19f[_0x42a8('0x30')],_0x1e1cfb=_0x417123[_0x42a8('0x31')],_0x1ed8cc=_0x417123[_0x42a8('0x31')]+_0x417123['limit'],_0x4aae8f;if(_0x1ed8cc>=_0x3e937d){_0x1ed8cc=_0x3e937d;_0x4aae8f=0xc8;}else{_0x4aae8f=0xce;}_0x2359ae[_0x42a8('0x32')](_0x4aae8f);return _0x2359ae['set'](_0x42a8('0x33'),_0x1e1cfb+'-'+_0x1ed8cc+'/'+_0x3e937d)[_0x42a8('0x2f')](_0xc0c19f);}return null;};}function patchUpdates(_0x3d2a56){return function(_0x15eb91){try{jsonpatch[_0x42a8('0x34')](_0x15eb91,_0x3d2a56,!![]);}catch(_0x1e3279){return BPromise['reject'](_0x1e3279);}return _0x15eb91[_0x42a8('0x35')]();};}function saveUpdates(_0x239db4,_0x1dee27){return function(_0x36eda2){if(_0x36eda2){return _0x36eda2[_0x42a8('0x36')](_0x239db4)[_0x42a8('0x37')](function(_0x430cc9){return _0x430cc9;});}return null;};}function removeEntity(_0x4ef116,_0x2c0b9c){return function(_0x4385a4){if(_0x4385a4){return _0x4385a4[_0x42a8('0x38')]()['then'](function(){var _0x82dce=_0x4385a4[_0x42a8('0x39')]({'plain':!![]});var _0x55eaa5=_0x42a8('0x3a');return db[_0x42a8('0x3b')]['destroy']({'where':{'type':_0x55eaa5,'resourceId':_0x82dce['id']}})['then'](function(){return _0x4385a4;});})['then'](function(){_0x4ef116[_0x42a8('0x32')](0xcc)[_0x42a8('0x2e')]();});}};}function handleEntityNotFound(_0x302f89,_0x26a4da){return function(_0x5745c5){if(!_0x5745c5){_0x302f89[_0x42a8('0x2d')](0x194);}return _0x5745c5;};}function handleError(_0x5d639d,_0x5b40c5){_0x5b40c5=_0x5b40c5||0x1f4;return function(_0x303881){logger[_0x42a8('0x29')](_0x303881['stack']);if(_0x303881[_0x42a8('0x3c')]){delete _0x303881[_0x42a8('0x3c')];}_0x5d639d[_0x42a8('0x32')](_0x5b40c5)[_0x42a8('0x3d')](_0x303881);};}exports[_0x42a8('0x3e')]=function(_0x54f7b9,_0x593232){var _0xfb62c5={'include':[{'model':db['Pause'],'as':_0x42a8('0x3f')}]},_0x1407fd={},_0x47c8f3={'count':0x0,'rows':[]};var _0x512ba5=_[_0x42a8('0x40')](db[_0x42a8('0x41')][_0x42a8('0x42')],function(_0x44d054){return{'name':_0x44d054[_0x42a8('0x43')],'type':_0x44d054['type'][_0x42a8('0x44')]};});_0x1407fd[_0x42a8('0x45')]=_[_0x42a8('0x40')](_0x512ba5,'name');_0x1407fd[_0x42a8('0x46')]=_[_0x42a8('0x47')](_0x54f7b9['query']);_0x1407fd[_0x42a8('0x48')]=_['intersection'](_0x1407fd[_0x42a8('0x45')],_0x1407fd[_0x42a8('0x46')]);_0xfb62c5[_0x42a8('0x49')]=_[_0x42a8('0x4a')](_0x1407fd[_0x42a8('0x45')],qs[_0x42a8('0x4b')](_0x54f7b9[_0x42a8('0x46')][_0x42a8('0x4b')]));_0xfb62c5['attributes']=_0xfb62c5['attributes'][_0x42a8('0x4c')]?_0xfb62c5[_0x42a8('0x49')]:_0x1407fd['model'];if(!_0x54f7b9['query']['hasOwnProperty']('nolimit')){_0xfb62c5[_0x42a8('0x4d')]=qs[_0x42a8('0x4d')](_0x54f7b9[_0x42a8('0x46')][_0x42a8('0x4d')]);_0xfb62c5['offset']=qs[_0x42a8('0x31')](_0x54f7b9[_0x42a8('0x46')][_0x42a8('0x31')]);}_0xfb62c5[_0x42a8('0x4e')]=qs[_0x42a8('0x4f')](_0x54f7b9[_0x42a8('0x46')][_0x42a8('0x4f')]);_0xfb62c5[_0x42a8('0x50')]=qs[_0x42a8('0x48')](_[_0x42a8('0x51')](_0x54f7b9[_0x42a8('0x46')],_0x1407fd[_0x42a8('0x48')]),_0x512ba5);if(_0x54f7b9['query'][_0x42a8('0x52')]){_0xfb62c5[_0x42a8('0x50')]=_[_0x42a8('0x53')](_0xfb62c5[_0x42a8('0x50')],{'$or':_['map'](_0x512ba5,function(_0x544853){if(_0x544853[_0x42a8('0x54')]!==_0x42a8('0x55')){var _0x1e4948={};_0x1e4948[_0x544853[_0x42a8('0x3c')]]={'$like':'%'+_0x54f7b9[_0x42a8('0x46')]['filter']+'%'};return _0x1e4948;}})});}_0xfb62c5=_['merge']({},_0xfb62c5,_0x54f7b9[_0x42a8('0x56')]);var _0x27ccf0={'where':_0xfb62c5[_0x42a8('0x50')]};return db['SmsAccount'][_0x42a8('0x30')](_0x27ccf0)[_0x42a8('0x37')](function(_0x160ef3){_0x47c8f3['count']=_0x160ef3;if(_0x54f7b9[_0x42a8('0x46')][_0x42a8('0x57')]){_0xfb62c5[_0x42a8('0x58')]=[{'all':!![]}];}return db['SmsAccount'][_0x42a8('0x59')](_0xfb62c5);})[_0x42a8('0x37')](function(_0x16ca6e){_0x47c8f3[_0x42a8('0x5a')]=_0x16ca6e;return _0x47c8f3;})[_0x42a8('0x37')](respondWithFilteredResult(_0x593232,_0xfb62c5))['catch'](handleError(_0x593232,null));};exports[_0x42a8('0x5b')]=function(_0x6bff9,_0x32841d){var _0x59cc69={'raw':![],'where':{'id':_0x6bff9[_0x42a8('0x5c')]['id']},'include':[{'model':db[_0x42a8('0x5d')],'as':_0x42a8('0x3f')}]},_0x5718cd={};_0x5718cd['model']=_[_0x42a8('0x47')](db[_0x42a8('0x41')][_0x42a8('0x42')]);_0x5718cd[_0x42a8('0x46')]=_[_0x42a8('0x47')](_0x6bff9[_0x42a8('0x46')]);_0x5718cd['filters']=_[_0x42a8('0x4a')](_0x5718cd[_0x42a8('0x45')],_0x5718cd[_0x42a8('0x46')]);_0x59cc69[_0x42a8('0x49')]=_[_0x42a8('0x4a')](_0x5718cd[_0x42a8('0x45')],qs[_0x42a8('0x4b')](_0x6bff9[_0x42a8('0x46')][_0x42a8('0x4b')]));_0x59cc69[_0x42a8('0x49')]=_0x59cc69[_0x42a8('0x49')][_0x42a8('0x4c')]?_0x59cc69[_0x42a8('0x49')]:_0x5718cd[_0x42a8('0x45')];if(_0x6bff9[_0x42a8('0x46')][_0x42a8('0x57')]){_0x59cc69[_0x42a8('0x58')]=[{'all':!![]}];}_0x59cc69=_[_0x42a8('0x53')]({},_0x59cc69,_0x6bff9[_0x42a8('0x56')]);return db['SmsAccount'][_0x42a8('0x5e')](_0x59cc69)[_0x42a8('0x37')](handleEntityNotFound(_0x32841d,null))[_0x42a8('0x37')](respondWithResult(_0x32841d,null))[_0x42a8('0x2c')](handleError(_0x32841d,null));};exports[_0x42a8('0x5f')]=function(_0x597322,_0x2ad616){return db[_0x42a8('0x41')][_0x42a8('0x5f')](_0x597322[_0x42a8('0x60')],{})[_0x42a8('0x37')](function(_0x29b48e){var _0x1c2ef5=_0x597322[_0x42a8('0x61')][_0x42a8('0x39')]({'plain':!![]});if(!_0x1c2ef5)throw new Error(_0x42a8('0x62'));if(_0x1c2ef5['role']==='user'){var _0x585429=_0x29b48e[_0x42a8('0x39')]({'plain':!![]});var _0x4fe651=_0x42a8('0x3a');return db[_0x42a8('0x63')][_0x42a8('0x5e')]({'where':{'name':_0x4fe651,'userProfileId':_0x1c2ef5['userProfileId']},'raw':!![]})[_0x42a8('0x37')](function(_0x52f4c7){if(_0x52f4c7&&_0x52f4c7['autoAssociation']===0x0){return db[_0x42a8('0x3b')][_0x42a8('0x5f')]({'name':_0x585429[_0x42a8('0x3c')],'resourceId':_0x585429['id'],'type':_0x52f4c7[_0x42a8('0x3c')],'sectionId':_0x52f4c7['id']},{})['then'](function(){return _0x29b48e;});}else{return _0x29b48e;}})[_0x42a8('0x2c')](function(_0x376e5b){logger[_0x42a8('0x29')](_0x42a8('0x64'),_0x376e5b);throw _0x376e5b;});}return _0x29b48e;})[_0x42a8('0x37')](respondWithResult(_0x2ad616,0xc9))['catch'](handleError(_0x2ad616,null));};exports[_0x42a8('0x36')]=function(_0x156186,_0x490dee){if(_0x156186[_0x42a8('0x60')]['id']){delete _0x156186[_0x42a8('0x60')]['id'];}return db['SmsAccount'][_0x42a8('0x5e')]({'where':{'id':_0x156186[_0x42a8('0x5c')]['id']},'include':[{'model':db[_0x42a8('0x5d')],'as':_0x42a8('0x3f')}]})['then'](handleEntityNotFound(_0x490dee,null))[_0x42a8('0x37')](saveUpdates(_0x156186[_0x42a8('0x60')],null))[_0x42a8('0x37')](respondWithResult(_0x490dee,null))[_0x42a8('0x2c')](handleError(_0x490dee,null));};exports[_0x42a8('0x38')]=function(_0x53244c,_0x3d180d){return db[_0x42a8('0x41')][_0x42a8('0x5e')]({'where':{'id':_0x53244c[_0x42a8('0x5c')]['id']}})[_0x42a8('0x37')](handleEntityNotFound(_0x3d180d,null))['then'](removeEntity(_0x3d180d,null))[_0x42a8('0x2c')](handleError(_0x3d180d,null));};exports[_0x42a8('0x65')]=function(_0x4f3d41,_0x479369){return db['SmsAccount'][_0x42a8('0x65')]()[_0x42a8('0x37')](respondWithResult(_0x479369,null))[_0x42a8('0x2c')](handleError(_0x479369,null));};exports[_0x42a8('0x66')]=function(_0x250628,_0x5453e0,_0x435c64){if(_0x250628[_0x42a8('0x60')]['id']){delete _0x250628['body']['id'];}return db['SmsAccount']['find']({'where':{'id':_0x250628[_0x42a8('0x5c')]['id']}})[_0x42a8('0x37')](handleEntityNotFound(_0x5453e0,null))[_0x42a8('0x37')](function(_0xc5927d){if(_0xc5927d){_0x250628[_0x42a8('0x60')][_0x42a8('0x67')]=_0xc5927d['id'];return db[_0x42a8('0x68')]['create'](_0x250628[_0x42a8('0x60')]);}})['then'](respondWithResult(_0x5453e0,null))['catch'](handleError(_0x5453e0,null));};exports[_0x42a8('0x69')]=function(_0x5471b6,_0x468c18,_0x301eaa){var _0x2010b0={'raw':![],'where':{}};var _0x43b3be={};var _0x172453={'count':0x0,'rows':[]};return db[_0x42a8('0x41')][_0x42a8('0x6a')]({'where':{'id':_0x5471b6[_0x42a8('0x5c')]['id']}})[_0x42a8('0x37')](handleEntityNotFound(_0x468c18,null))[_0x42a8('0x37')](function(_0x53eb2a){if(_0x53eb2a){_0x43b3be[_0x42a8('0x45')]=_[_0x42a8('0x47')](db[_0x42a8('0x68')]['rawAttributes']);_0x43b3be[_0x42a8('0x46')]=_[_0x42a8('0x47')](_0x5471b6[_0x42a8('0x46')]);_0x43b3be[_0x42a8('0x48')]=_[_0x42a8('0x4a')](_0x43b3be[_0x42a8('0x45')],_0x43b3be['query']);_0x2010b0['attributes']=_[_0x42a8('0x4a')](_0x43b3be[_0x42a8('0x45')],qs[_0x42a8('0x4b')](_0x5471b6[_0x42a8('0x46')]['fields']));_0x2010b0[_0x42a8('0x49')]=_0x2010b0[_0x42a8('0x49')][_0x42a8('0x4c')]?_0x2010b0[_0x42a8('0x49')]:_0x43b3be[_0x42a8('0x45')];if(!_0x5471b6[_0x42a8('0x46')]['hasOwnProperty'](_0x42a8('0x6b'))){_0x2010b0[_0x42a8('0x4d')]=qs[_0x42a8('0x4d')](_0x5471b6[_0x42a8('0x46')]['limit']);_0x2010b0[_0x42a8('0x31')]=qs[_0x42a8('0x31')](_0x5471b6[_0x42a8('0x46')][_0x42a8('0x31')]);}_0x2010b0['order']=qs[_0x42a8('0x4f')](_0x5471b6[_0x42a8('0x46')][_0x42a8('0x4f')]);_0x2010b0[_0x42a8('0x50')]=qs[_0x42a8('0x48')](_[_0x42a8('0x51')](_0x5471b6[_0x42a8('0x46')],_0x43b3be[_0x42a8('0x48')]));_0x2010b0[_0x42a8('0x50')]['SmsAccountId']=_0x53eb2a['id'];if(_0x5471b6[_0x42a8('0x46')][_0x42a8('0x52')]){_0x2010b0[_0x42a8('0x50')]=_[_0x42a8('0x53')](_0x2010b0['where'],{'$or':_[_0x42a8('0x40')](_0x2010b0['attributes'],function(_0x2a2c12){var _0x254baf={};_0x254baf[_0x2a2c12]={'$like':'%'+_0x5471b6['query'][_0x42a8('0x52')]+'%'};return _0x254baf;})});}_0x2010b0=_[_0x42a8('0x53')]({},_0x2010b0,_0x5471b6[_0x42a8('0x56')]);return db[_0x42a8('0x68')][_0x42a8('0x30')]({'where':_0x2010b0[_0x42a8('0x50')]})[_0x42a8('0x37')](function(_0x3356b6){_0x172453[_0x42a8('0x30')]=_0x3356b6;if(_0x5471b6[_0x42a8('0x46')]['includeAll']){_0x2010b0[_0x42a8('0x58')]=[{'all':!![]}];}return db[_0x42a8('0x68')][_0x42a8('0x59')](_0x2010b0);})['then'](function(_0x218728){_0x172453['rows']=_0x218728;return _0x172453;});}})[_0x42a8('0x37')](respondWithFilteredResult(_0x468c18,_0x2010b0))['catch'](handleError(_0x468c18,null));};exports[_0x42a8('0x6c')]=function(_0x5c7116,_0x35c2f5,_0x3a8a31){return db[_0x42a8('0x41')]['find']({'where':{'id':_0x5c7116[_0x42a8('0x5c')]['id']}})['then'](handleEntityNotFound(_0x35c2f5,null))[_0x42a8('0x37')](function(_0x528fba){if(_0x528fba){return _0x528fba[_0x42a8('0x6c')](_0x5c7116[_0x42a8('0x46')][_0x42a8('0x6d')]);}})[_0x42a8('0x37')](respondWithStatusCode(_0x35c2f5,null))[_0x42a8('0x2c')](handleError(_0x35c2f5,null));};exports['addAnswer']=function(_0x3a06ff,_0x28a862,_0x93a76a){if(_0x3a06ff['body']['id']){delete _0x3a06ff[_0x42a8('0x60')]['id'];}return db[_0x42a8('0x41')][_0x42a8('0x5e')]({'where':{'id':_0x3a06ff[_0x42a8('0x5c')]['id']}})[_0x42a8('0x37')](handleEntityNotFound(_0x28a862,null))[_0x42a8('0x37')](function(_0x3aea48){if(_0x3aea48){_0x3a06ff['body'][_0x42a8('0x67')]=_0x3aea48['id'];return db['CannedAnswer'][_0x42a8('0x5f')](_0x3a06ff[_0x42a8('0x60')]);}})[_0x42a8('0x37')](respondWithResult(_0x28a862,null))[_0x42a8('0x2c')](handleError(_0x28a862,null));};exports[_0x42a8('0x6e')]=function(_0x3fbb26,_0x2a501f,_0x55040d){var _0xfed600={'raw':![],'where':{}};var _0xf80801={};var _0x3ce7cb={'count':0x0,'rows':[]};return db[_0x42a8('0x41')][_0x42a8('0x6a')]({'where':{'id':_0x3fbb26[_0x42a8('0x5c')]['id']}})[_0x42a8('0x37')](handleEntityNotFound(_0x2a501f,null))[_0x42a8('0x37')](function(_0x3cc72d){if(_0x3cc72d){_0xf80801['model']=_['keys'](db[_0x42a8('0x6f')]['rawAttributes']);_0xf80801[_0x42a8('0x46')]=_['keys'](_0x3fbb26[_0x42a8('0x46')]);_0xf80801[_0x42a8('0x48')]=_[_0x42a8('0x4a')](_0xf80801[_0x42a8('0x45')],_0xf80801[_0x42a8('0x46')]);_0xfed600[_0x42a8('0x49')]=_[_0x42a8('0x4a')](_0xf80801['model'],qs[_0x42a8('0x4b')](_0x3fbb26[_0x42a8('0x46')]['fields']));_0xfed600[_0x42a8('0x49')]=_0xfed600[_0x42a8('0x49')][_0x42a8('0x4c')]?_0xfed600[_0x42a8('0x49')]:_0xf80801['model'];if(!_0x3fbb26[_0x42a8('0x46')][_0x42a8('0x70')](_0x42a8('0x6b'))){_0xfed600[_0x42a8('0x4d')]=qs[_0x42a8('0x4d')](_0x3fbb26['query'][_0x42a8('0x4d')]);_0xfed600[_0x42a8('0x31')]=qs[_0x42a8('0x31')](_0x3fbb26[_0x42a8('0x46')]['offset']);}_0xfed600[_0x42a8('0x4e')]=qs[_0x42a8('0x4f')](_0x3fbb26[_0x42a8('0x46')]['sort']);_0xfed600[_0x42a8('0x50')]=qs[_0x42a8('0x48')](_[_0x42a8('0x51')](_0x3fbb26['query'],_0xf80801[_0x42a8('0x48')]));_0xfed600[_0x42a8('0x50')][_0x42a8('0x67')]=_0x3cc72d['id'];if(_0x3fbb26[_0x42a8('0x46')][_0x42a8('0x52')]){_0xfed600[_0x42a8('0x50')]=_['merge'](_0xfed600['where'],{'$or':_['map'](_0xfed600[_0x42a8('0x49')],function(_0x3cd380){var _0x15f2f6={};_0x15f2f6[_0x3cd380]={'$like':'%'+_0x3fbb26[_0x42a8('0x46')]['filter']+'%'};return _0x15f2f6;})});}_0xfed600=_[_0x42a8('0x53')]({},_0xfed600,_0x3fbb26[_0x42a8('0x56')]);return db['CannedAnswer'][_0x42a8('0x30')]({'where':_0xfed600[_0x42a8('0x50')]})[_0x42a8('0x37')](function(_0x1bebf4){_0x3ce7cb[_0x42a8('0x30')]=_0x1bebf4;if(_0x3fbb26[_0x42a8('0x46')][_0x42a8('0x57')]){_0xfed600[_0x42a8('0x58')]=[{'all':!![]}];}return db[_0x42a8('0x6f')][_0x42a8('0x59')](_0xfed600);})[_0x42a8('0x37')](function(_0x45c8c2){_0x3ce7cb[_0x42a8('0x5a')]=_0x45c8c2;return _0x3ce7cb;});}})[_0x42a8('0x37')](respondWithFilteredResult(_0x2a501f,_0xfed600))['catch'](handleError(_0x2a501f,null));};exports['removeAnswers']=function(_0x42f73f,_0x540416,_0x5be882){return db['SmsAccount'][_0x42a8('0x5e')]({'where':{'id':_0x42f73f[_0x42a8('0x5c')]['id']}})[_0x42a8('0x37')](handleEntityNotFound(_0x540416,null))[_0x42a8('0x37')](function(_0x93a375){if(_0x93a375){return _0x93a375[_0x42a8('0x71')](_0x42f73f[_0x42a8('0x46')][_0x42a8('0x6d')]);}})[_0x42a8('0x37')](respondWithStatusCode(_0x540416,null))[_0x42a8('0x2c')](handleError(_0x540416,null));};exports[_0x42a8('0x72')]=function(_0x1566b5,_0x1a8c6e,_0x42fbb4){var _0xac0d95={'channel':_0x42a8('0x73')};var _0x20258f=[];var _0x5baeaf=[];var _0x367746={};return db['SmsAccount']['find']({'where':{'id':_0x1566b5[_0x42a8('0x5c')]['id']},'include':[{'model':db['SmsApplication'],'as':_0x42a8('0x74')}]})['then'](handleEntityNotFound(_0x1a8c6e,null))[_0x42a8('0x37')](function(_0x36f7c1){_0xac0d95[_0x42a8('0x75')]=_0x36f7c1;_0xac0d95[_0x42a8('0x76')]=_['orderBy'](_0x36f7c1['Applications'],['priority'],[_0x42a8('0x77')]);if(_0xac0d95[_0x42a8('0x75')][_0x42a8('0x74')]){delete _0xac0d95[_0x42a8('0x75')][_0x42a8('0x74')];}return db[_0x42a8('0x78')][_0x42a8('0x65')]();})[_0x42a8('0x37')](function(_0x59703a){if(!_0x59703a){throw new db[(_0x42a8('0x79'))]['ValidationError']('no\x20available\x20attributes');}_0x20258f=_[_0x42a8('0x7a')](_[_0x42a8('0x47')](_0x59703a),[_0x42a8('0x7b'),_0x42a8('0x7c')]);_0x5baeaf=_[_0x42a8('0x7a')](_['keys'](_0x59703a),['createdAt',_0x42a8('0x7c'),_0x42a8('0x7d'),_0x42a8('0x7e')]);_0xac0d95[_0x42a8('0x60')]={'mapKey':_0x42a8('0x7f')};if(_0xac0d95['account'][_0x42a8('0x54')]){switch(_0xac0d95['account'][_0x42a8('0x54')]){case _0x42a8('0x80'):_0xac0d95[_0x42a8('0x60')][_0x42a8('0x81')]=_0x1566b5[_0x42a8('0x60')]['From'];_0xac0d95[_0x42a8('0x60')]['body']=_0x1566b5['body'][_0x42a8('0x82')];_0xac0d95[_0x42a8('0x60')]['messageId']=_0x1566b5['body'][_0x42a8('0x83')];break;case _0x42a8('0x84'):_0xac0d95['body'][_0x42a8('0x81')]='+'+_0x1566b5[_0x42a8('0x60')][_0x42a8('0x85')];_0xac0d95[_0x42a8('0x60')][_0x42a8('0x60')]=_0x1566b5[_0x42a8('0x60')]['text'];break;case'connectel':_0xac0d95['body'][_0x42a8('0x81')]=_0x1566b5['body']['from'];_0xac0d95[_0x42a8('0x60')][_0x42a8('0x60')]=_0x1566b5[_0x42a8('0x60')][_0x42a8('0x2a')];break;case _0x42a8('0x86'):_0xac0d95['body']['from']=_0x1566b5[_0x42a8('0x60')][_0x42a8('0x81')];_0xac0d95['body']['body']=_0x1566b5[_0x42a8('0x60')][_0x42a8('0x60')];_0xac0d95[_0x42a8('0x60')][_0x42a8('0x87')]=_0x1566b5['body'][_0x42a8('0x88')];break;case _0x42a8('0x89'):_0xac0d95[_0x42a8('0x60')][_0x42a8('0x81')]=_0x1566b5[_0x42a8('0x60')][_0x42a8('0x8a')];_0xac0d95[_0x42a8('0x60')][_0x42a8('0x60')]=_0x1566b5[_0x42a8('0x60')]['Text'];_0xac0d95['body'][_0x42a8('0x87')]=_0x1566b5[_0x42a8('0x60')]['MessageUUID'];break;case _0x42a8('0x8b'):_0xac0d95[_0x42a8('0x60')][_0x42a8('0x81')]='+'+_0x1566b5[_0x42a8('0x60')]['results'][0x0]['from'];_0xac0d95[_0x42a8('0x60')][_0x42a8('0x60')]=_0x1566b5[_0x42a8('0x60')][_0x42a8('0x8c')][0x0][_0x42a8('0x8d')];_0xac0d95[_0x42a8('0x60')][_0x42a8('0x87')]=_0x1566b5[_0x42a8('0x60')][_0x42a8('0x8c')][0x0]['messageId'];break;case _0x42a8('0x8e'):_0xac0d95[_0x42a8('0x60')][_0x42a8('0x81')]=_0x1566b5[_0x42a8('0x60')][_0x42a8('0x8f')];_0xac0d95[_0x42a8('0x60')][_0x42a8('0x60')]=_0x1566b5[_0x42a8('0x60')][_0x42a8('0x90')][_0x42a8('0x2a')];break;case _0x42a8('0x91'):_0xac0d95[_0x42a8('0x60')]['from']=_0x1566b5['body'][_0x42a8('0x92')];_0xac0d95[_0x42a8('0x60')][_0x42a8('0x60')]=_0x1566b5[_0x42a8('0x60')]['text'];_0xac0d95[_0x42a8('0x60')][_0x42a8('0x87')]=_0x1566b5[_0x42a8('0x60')][_0x42a8('0x93')];break;case _0x42a8('0x94'):_0xac0d95[_0x42a8('0x60')]['from']=_0x1566b5[_0x42a8('0x60')][_0x42a8('0x81')];_0xac0d95[_0x42a8('0x60')][_0x42a8('0x60')]=_0x1566b5['body']['message'];_0xac0d95['body'][_0x42a8('0x87')]=_0x1566b5[_0x42a8('0x60')][_0x42a8('0x95')];break;}}if(_0xac0d95[_0x42a8('0x60')]['id']){delete _0xac0d95[_0x42a8('0x60')]['id'];}if(_[_0x42a8('0x96')](_0xac0d95[_0x42a8('0x60')][_0x42a8('0x81')])){throw new db[(_0x42a8('0x79'))][(_0x42a8('0x97'))]('from\x20is\x20mandatory');}if(_[_0x42a8('0x96')](_0xac0d95['body'][_0x42a8('0x60')])||_0xac0d95[_0x42a8('0x60')][_0x42a8('0x60')]===''){throw new db[(_0x42a8('0x79'))][(_0x42a8('0x97'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_['isNil'](_0xac0d95[_0x42a8('0x60')][_0x42a8('0x98')])){throw new db[(_0x42a8('0x79'))][(_0x42a8('0x97'))](_0x42a8('0x99')+_0x5baeaf);}if(!_['includes'](_0x5baeaf,_0xac0d95['body']['mapKey'])){throw new db['Sequelize']['ValidationError'](_0x42a8('0x9a')+_0x5baeaf);}_0x367746[_0xac0d95['body'][_0x42a8('0x98')]]=_0xac0d95[_0x42a8('0x60')]['from'];return db[_0x42a8('0x9b')][_0x42a8('0x5e')]({'where':{'id':_0xac0d95[_0x42a8('0x75')][_0x42a8('0x7e')]},'include':[{'model':db[_0x42a8('0x78')],'as':_0x42a8('0x9c'),'where':_0x367746,'limit':0x1,'order':[[_0x42a8('0x7c'),_0x42a8('0x9d')]]}]});})['then'](handleEntityNotFound(_0x1a8c6e,null))[_0x42a8('0x37')](function(_0x49440e){if(_0x49440e){_0xac0d95[_0x42a8('0x9e')]=_[_0x42a8('0x9f')](_0x49440e,['Contacts']);if(_0x49440e[_0x42a8('0x9c')]['length']){return _0x49440e[_0x42a8('0x9c')][0x0];}var _0x47535d=_['defaults'](_0xac0d95['body'],{'firstName':_0xac0d95['body'][_0x42a8('0x81')],'ListId':_0x49440e['id']});_0x47535d[_0xac0d95[_0x42a8('0x60')]['mapKey']]=_0xac0d95[_0x42a8('0x60')][_0x42a8('0x81')];return db['CmContact']['create'](_0x47535d,{'fields':_0x20258f,'raw':!![]});}})[_0x42a8('0x37')](handleEntityNotFound(_0x1a8c6e,null))[_0x42a8('0x37')](function(_0x1bd706){if(_0x1bd706){_0xac0d95[_0x42a8('0xa0')]=_0x1bd706;var _0x5f0f8e={'ContactId':_0x1bd706['id'],'phone':_0xac0d95[_0x42a8('0x60')][_0x42a8('0x81')],'SmsAccountId':_0x1566b5[_0x42a8('0x5c')]['id']};var _0x5d6e5e={'ContactId':_0x1bd706['id'],'SmsAccountId':_0x1566b5[_0x42a8('0x5c')]['id'],'closed':![]};return db['SmsInteraction']['find']({'where':_0x5d6e5e})[_0x42a8('0x37')](function(_0x5a7f87){if(_0x5a7f87){return[_0x5a7f87,![]];}return db[_0x42a8('0xa1')][_0x42a8('0x5f')](_0x5f0f8e)[_0x42a8('0x37')](function(_0x5eb57e){return[_0x5eb57e,!![]];});});}})[_0x42a8('0xa2')](function(_0x4fbc27,_0x2e25c8){_0xac0d95['interaction']=_0x4fbc27[_0x42a8('0x39')]({'plain':!![]});_0xac0d95[_0x42a8('0xa3')][_0x42a8('0xa4')]=![];if(_0x2e25c8){if(_0xac0d95[_0x42a8('0x75')]['autoclose']){_0xac0d95[_0x42a8('0x76')][_0x42a8('0xa5')]({'id':0x0,'priority':_0xac0d95['applications']['length']+0x1,'app':_0x42a8('0xa6'),'appdata':_0x42a8('0xa7'),'interval':_0x42a8('0xa8')});}_0xac0d95[_0x42a8('0xa3')][_0x42a8('0xa4')]=!![];}return db[_0x42a8('0xa9')][_0x42a8('0x5f')]({'phone':_0xac0d95[_0x42a8('0x60')][_0x42a8('0x81')],'messageId':_0xac0d95[_0x42a8('0x60')]['messageId'],'body':_0xac0d95[_0x42a8('0x60')][_0x42a8('0x60')],'SmsAccountId':_0x1566b5['params']['id'],'SmsInteractionId':_0x4fbc27['id'],'direction':'in','ContactId':_0x4fbc27[_0x42a8('0xaa')],'AttachmentId':_0xac0d95[_0x42a8('0x60')][_0x42a8('0xab')]});})[_0x42a8('0x37')](function(_0x593c0e){_0xac0d95[_0x42a8('0x2a')]=_0x593c0e;if(_0xac0d95[_0x42a8('0xa3')][_0x42a8('0xac')]){return db[_0x42a8('0xad')]['find']({'attributes':['id',_0x42a8('0x3c')],'where':{'id':_0xac0d95[_0x42a8('0xa3')][_0x42a8('0xac')]}})['then'](function(_0xf0290){if(_0xf0290){_0xac0d95['applications'][_0x42a8('0xae')]({'id':0x0,'priority':0x0,'app':_0x42a8('0xaf'),'appdata':_0xf0290[_0x42a8('0x3c')]+','+(_0xac0d95[_0x42a8('0x75')]['waitForTheAssignedAgent']||0xa),'interval':'*,*,*,*'});}return respondWithRpcPromise(_0x42a8('0xb0'),_0x42a8('0xb1'),_0xac0d95);});}return respondWithRpcPromise(_0x42a8('0xb0'),_0x42a8('0xb1'),_0xac0d95);})[_0x42a8('0x37')](function(_0x4ee86a){if(_0x4ee86a){var _0x5cfe7f=0xc8;var _0x2936da='receiveMessage';logger[_0x42a8('0x23')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x2936da,_0x5cfe7f,_0x42a8('0xb2'));logger[_0x42a8('0x26')]('SmsAccount,\x20%s,\x20%s,\x20%s,\x20%s',_0x2936da,_0x5cfe7f,_0x42a8('0xb2'),JSON[_0x42a8('0x28')](_0x4ee86a));if(_0xac0d95[_0x42a8('0x75')][_0x42a8('0x54')]===_0x42a8('0x80')){return _0x1a8c6e[_0x42a8('0x32')](_0x5cfe7f)[_0x42a8('0xb3')](_0x42a8('0xb4'),'text/xml')[_0x42a8('0x3d')]('<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>');}else{return _0x1a8c6e['status'](_0x5cfe7f)['json'](_0x4ee86a);}}})[_0x42a8('0x2c')](handleError(_0x1a8c6e,null));};exports[_0x42a8('0xb5')]=function(_0x523408,_0x3744d5,_0x9acf65){return db[_0x42a8('0x41')][_0x42a8('0x6a')]({'where':{'id':_0x523408['params']['id']}})['then'](handleEntityNotFound(_0x3744d5,null))[_0x42a8('0x37')](function(_0x2f8b81){if(_0x2f8b81){return db[_0x42a8('0xb6')][_0x42a8('0xb7')](function(_0x2ebac9){return db[_0x42a8('0xb8')]['destroy']({'where':{'SmsAccountId':_0x523408[_0x42a8('0x5c')]['id']},'transaction':_0x2ebac9})[_0x42a8('0x37')](function(_0x2c741c){var _0x5356ea=_[_0x42a8('0x40')](_0x523408['body'],function(_0x1d4e2d){_0x1d4e2d['SmsAccountId']=_0x523408['params']['id'];return _0x1d4e2d;});return db[_0x42a8('0xb8')][_0x42a8('0xb9')](_0x5356ea,{'transaction':_0x2ebac9});});})[_0x42a8('0x37')](function(){return db[_0x42a8('0xb8')][_0x42a8('0xba')]({'where':{'SmsAccountId':_0x523408[_0x42a8('0x5c')]['id']},'order':_0x42a8('0xbb')});});}})[_0x42a8('0x37')](respondWithResult(_0x3744d5,null))[_0x42a8('0x2c')](handleError(_0x3744d5,null));};exports[_0x42a8('0xbc')]=function(_0x46c46f,_0x1acd86,_0x59084b){var _0x3b2f9e={};var _0x43bf21={};var _0x215d6b;var _0x4309b4;return db[_0x42a8('0x41')][_0x42a8('0x6a')]({'where':{'id':_0x46c46f['params']['id']}})[_0x42a8('0x37')](handleEntityNotFound(_0x1acd86,null))[_0x42a8('0x37')](function(_0x29740c){if(_0x29740c){_0x215d6b=_0x29740c;_0x43bf21[_0x42a8('0x45')]=_[_0x42a8('0x47')](db[_0x42a8('0xb8')][_0x42a8('0x42')]);_0x43bf21[_0x42a8('0x46')]=_[_0x42a8('0x47')](_0x46c46f['query']);_0x43bf21[_0x42a8('0x48')]=_[_0x42a8('0x4a')](_0x43bf21[_0x42a8('0x45')],_0x43bf21[_0x42a8('0x46')]);_0x3b2f9e[_0x42a8('0x49')]=_[_0x42a8('0x4a')](_0x43bf21[_0x42a8('0x45')],qs['fields'](_0x46c46f[_0x42a8('0x46')][_0x42a8('0x4b')]));_0x3b2f9e['attributes']=_0x3b2f9e[_0x42a8('0x49')]['length']?_0x3b2f9e[_0x42a8('0x49')]:_0x43bf21['model'];_0x3b2f9e[_0x42a8('0x4e')]=qs['sort'](_0x46c46f[_0x42a8('0x46')]['sort']);_0x3b2f9e[_0x42a8('0x50')]=qs[_0x42a8('0x48')](_[_0x42a8('0x51')](_0x46c46f[_0x42a8('0x46')],_0x43bf21[_0x42a8('0x48')]));if(_0x46c46f[_0x42a8('0x46')][_0x42a8('0x52')]){_0x3b2f9e[_0x42a8('0x50')]=_[_0x42a8('0x53')](_0x3b2f9e[_0x42a8('0x50')],{'$or':_[_0x42a8('0x40')](_0x3b2f9e[_0x42a8('0x49')],function(_0x5c8360){var _0x50bc04={};_0x50bc04[_0x5c8360]={'$like':'%'+_0x46c46f[_0x42a8('0x46')][_0x42a8('0x52')]+'%'};return _0x50bc04;})});}_0x3b2f9e=_['merge']({},_0x3b2f9e,_0x46c46f[_0x42a8('0x56')]);return _0x215d6b[_0x42a8('0xbc')](_0x3b2f9e);}})[_0x42a8('0x37')](function(_0x2464c3){if(_0x2464c3){_0x4309b4=_0x2464c3['length'];if(!_0x46c46f[_0x42a8('0x46')][_0x42a8('0x70')](_0x42a8('0x6b'))){_0x3b2f9e[_0x42a8('0x4d')]=qs[_0x42a8('0x4d')](_0x46c46f['query']['limit']);_0x3b2f9e[_0x42a8('0x31')]=qs[_0x42a8('0x31')](_0x46c46f[_0x42a8('0x46')]['offset']);}return _0x215d6b[_0x42a8('0xbc')](_0x3b2f9e);}})['then'](function(_0x323d38){if(_0x323d38){return _0x323d38?{'count':_0x4309b4,'rows':_0x323d38}:null;}})['then'](respondWithResult(_0x1acd86,null))[_0x42a8('0x2c')](handleError(_0x1acd86,null));};exports[_0x42a8('0xbd')]=function(_0x2e289e,_0x5bafc8,_0x40262e){var _0x20c5a3={'raw':![],'where':{}};var _0x2e7f2d={};var _0xf497e={'count':0x0,'rows':[]};return db['SmsAccount'][_0x42a8('0x6a')]({'where':{'id':_0x2e289e[_0x42a8('0x5c')]['id']}})[_0x42a8('0x37')](handleEntityNotFound(_0x5bafc8,null))['then'](function(_0x5ec189){if(_0x5ec189){_0x2e7f2d[_0x42a8('0x45')]=_['keys'](db[_0x42a8('0xa1')]['rawAttributes']);_0x2e7f2d[_0x42a8('0x46')]=_['keys'](_0x2e289e[_0x42a8('0x46')]);_0x2e7f2d[_0x42a8('0x48')]=_['intersection'](_0x2e7f2d['model'],_0x2e7f2d[_0x42a8('0x46')]);_0x20c5a3[_0x42a8('0x49')]=_[_0x42a8('0x4a')](_0x2e7f2d[_0x42a8('0x45')],qs[_0x42a8('0x4b')](_0x2e289e[_0x42a8('0x46')][_0x42a8('0x4b')]));_0x20c5a3[_0x42a8('0x49')]=_0x20c5a3['attributes']['length']?_0x20c5a3[_0x42a8('0x49')]:_0x2e7f2d['model'];if(!_0x2e289e[_0x42a8('0x46')][_0x42a8('0x70')](_0x42a8('0x6b'))){_0x20c5a3['limit']=qs[_0x42a8('0x4d')](_0x2e289e[_0x42a8('0x46')][_0x42a8('0x4d')]);_0x20c5a3[_0x42a8('0x31')]=qs[_0x42a8('0x31')](_0x2e289e['query'][_0x42a8('0x31')]);}_0x20c5a3[_0x42a8('0x4e')]=qs[_0x42a8('0x4f')](_0x2e289e[_0x42a8('0x46')]['sort']);_0x20c5a3['where']=qs[_0x42a8('0x48')](_['pick'](_0x2e289e['query'],_0x2e7f2d['filters']));_0x20c5a3[_0x42a8('0x50')][_0x42a8('0x67')]=_0x5ec189['id'];if(_0x2e289e[_0x42a8('0x46')]['filter']){_0x20c5a3[_0x42a8('0x50')]=_[_0x42a8('0x53')](_0x20c5a3[_0x42a8('0x50')],{'$or':_['map'](_0x20c5a3[_0x42a8('0x49')],function(_0x591577){var _0x4507dc={};_0x4507dc[_0x591577]={'$like':'%'+_0x2e289e[_0x42a8('0x46')][_0x42a8('0x52')]+'%'};return _0x4507dc;})});}_0x20c5a3=_[_0x42a8('0x53')]({},_0x20c5a3,_0x2e289e['options']);return db[_0x42a8('0xa1')][_0x42a8('0x30')]({'where':_0x20c5a3[_0x42a8('0x50')]})[_0x42a8('0x37')](function(_0x5b6862){_0xf497e[_0x42a8('0x30')]=_0x5b6862;if(_0x2e289e['query']['includeAll']){_0x20c5a3['include']=[{'model':db[_0x42a8('0x78')],'as':_0x42a8('0xbe'),'required':![]},{'model':db[_0x42a8('0xad')],'as':_0x42a8('0xbf'),'attributes':[_0x42a8('0x3c'),_0x42a8('0xc0'),_0x42a8('0xc1')],'required':![]},{'model':db[_0x42a8('0xc2')],'as':_0x42a8('0xc3'),'attributes':['id',_0x42a8('0x3c'),_0x42a8('0xc4')],'where':_0x2e289e[_0x42a8('0x46')][_0x42a8('0xc5')]?{'id':_0x2e289e[_0x42a8('0x46')][_0x42a8('0xc5')]}:undefined,'required':_0x2e289e[_0x42a8('0x46')][_0x42a8('0xc5')]?!![]:![]}];}return db[_0x42a8('0xa1')][_0x42a8('0x59')](_0x20c5a3);})[_0x42a8('0x37')](function(_0xd7b20b){_0xf497e[_0x42a8('0x5a')]=_0xd7b20b;return _0xf497e;});}})['then'](respondWithFilteredResult(_0x5bafc8,_0x20c5a3))['catch'](handleError(_0x5bafc8,null));};exports[_0x42a8('0x3d')]=function(_0x3d9873,_0x24614b,_0x36f5c6){var _0x44744e,_0x3430fa,_0x247ca8;if(_[_0x42a8('0x96')](_0x3d9873[_0x42a8('0x60')][_0x42a8('0x60')])||_0x3d9873[_0x42a8('0x60')][_0x42a8('0x60')]===''){throw new db[(_0x42a8('0x79'))]['ValidationError'](_0x42a8('0xc6'));}if(_[_0x42a8('0x96')](_0x3d9873['body']['to'])){throw new db[(_0x42a8('0x79'))][(_0x42a8('0x97'))](_0x42a8('0xc7'));}_0x44744e=_0x3d9873['body']['to'];return db[_0x42a8('0x41')][_0x42a8('0x5e')]({'where':{'id':_0x3d9873['params']['id']},'include':[{'model':db['CmList'],'as':_0x42a8('0xc8'),'include':[{'model':db['CmContact'],'as':_0x42a8('0x9c'),'where':{'mobile':_0x44744e},'limit':0x1,'order':[[_0x42a8('0x7c'),_0x42a8('0x9d')]]}]}]})[_0x42a8('0x37')](handleEntityNotFound(_0x24614b,null))[_0x42a8('0x37')](function(_0xb0ab89){if(_0xb0ab89&&_0xb0ab89[_0x42a8('0xc8')]){_0x3430fa=_0xb0ab89[_0x42a8('0x39')]({'plain':!![]});if(_0x3430fa[_0x42a8('0xc8')]&&_0x3430fa[_0x42a8('0xc8')][_0x42a8('0x9c')][_0x42a8('0x4c')]){return _0x3430fa[_0x42a8('0xc8')][_0x42a8('0x9c')][0x0];}return db['CmContact'][_0x42a8('0x5f')](_[_0x42a8('0x1b')](_0x3d9873[_0x42a8('0x60')],{'firstName':_0x44744e,'mobile':_0x44744e,'phone':_0x44744e,'ListId':_0x3430fa['ListId']}));}})[_0x42a8('0x37')](handleEntityNotFound(_0x24614b,null))[_0x42a8('0x37')](function(_0x28a13a){if(_0x28a13a){_0x247ca8=_0x28a13a;return db[_0x42a8('0xa1')][_0x42a8('0x5e')]({'where':{'ContactId':_0x247ca8['id'],'closed':![],'SmsAccountId':_0x3430fa['id']}})['then'](function(_0x1093ee){if(_0x1093ee){return[_0x1093ee,![]];}return db[_0x42a8('0xa1')][_0x42a8('0x5f')]({'UserId':_0x3d9873[_0x42a8('0x61')]['id'],'ContactId':_0x247ca8['id'],'SmsAccountId':_0x3430fa['id'],'phone':_0x44744e,'firstMsgDirection':_0x42a8('0xc9'),'Messages':[_[_0x42a8('0x53')](_0x3d9873[_0x42a8('0x60')],{'read':![],'body':_0x3d9873[_0x42a8('0x60')][_0x42a8('0x60')],'phone':_0x44744e,'SmsAccountId':_0x3430fa['id'],'UserId':_0x3d9873[_0x42a8('0x61')]['id'],'ContactId':_0x247ca8['id']})]},{'include':[{'model':db[_0x42a8('0xa9')],'as':_0x42a8('0xca')}]})[_0x42a8('0x37')](function(_0xb40727){return[_0xb40727,!![]];});});}})['spread'](function(_0x46e52f,_0x9141e8){if(_0x9141e8){return _0x46e52f;}return db[_0x42a8('0xa9')][_0x42a8('0x5f')](_[_0x42a8('0x53')](_0x3d9873[_0x42a8('0x60')],{'read':![],'body':_0x3d9873[_0x42a8('0x60')][_0x42a8('0x60')],'phone':_0x44744e,'SmsAccountId':_0x3430fa['id'],'SmsInteractionId':_0x46e52f['id'],'UserId':_0x3d9873[_0x42a8('0x61')]['id'],'ContactId':_0x247ca8['id']}))['then'](function(_0x22fc78){_0x46e52f[_0x42a8('0xcb')][_0x42a8('0xca')]=[];_0x46e52f['dataValues'][_0x42a8('0xca')]['push'](_0x22fc78[_0x42a8('0xcb')]);return _0x46e52f;});})[_0x42a8('0x37')](respondWithResult(_0x24614b,null))['catch'](handleError(_0x24614b,null));};exports[_0x42a8('0x32')]=function(_0x3b1c7f,_0x54223b,_0x403c46){if(_0x3b1c7f[_0x42a8('0x60')]['id']){delete _0x3b1c7f['body']['id'];}console[_0x42a8('0xcc')](_0x42a8('0xcd'),_0x3b1c7f['body']);var _0x40827f,_0x32cf7a,_0x45ec0f;return db['SmsAccount'][_0x42a8('0x5e')]({'where':{'id':_0x3b1c7f['params']['id']}})[_0x42a8('0x37')](handleEntityNotFound(_0x54223b,null))[_0x42a8('0x37')](function(_0x4b829b){if(_0x4b829b){_0x45ec0f=_0x4b829b;logger['debug'](_0x42a8('0x27'),_0x42a8('0x32'),_0x42a8('0xce'),_0x4b829b[_0x42a8('0x54')],util[_0x42a8('0xcf')](_0x3b1c7f[_0x42a8('0x60')],{'showHidden':![],'depth':null}));switch(_0x4b829b[_0x42a8('0x54')]){case _0x42a8('0x84'):if(_0x3b1c7f[_0x42a8('0x60')][_0x42a8('0xd0')]&&_0x3b1c7f['body']['status']){_0x32cf7a=_0x3b1c7f[_0x42a8('0x60')]['status'];return db[_0x42a8('0xa9')][_0x42a8('0x5e')]({'where':{'messageId':_0x3b1c7f[_0x42a8('0x60')]['skebby_dispatch_id']}});}break;case _0x42a8('0xd1'):if(_0x3b1c7f['body'][_0x42a8('0xd2')]&&_0x3b1c7f[_0x42a8('0x60')][_0x42a8('0xd3')]){_0x32cf7a=_0x3b1c7f[_0x42a8('0x60')][_0x42a8('0xd3')];return db[_0x42a8('0xa9')][_0x42a8('0x5e')]({'where':{'messageId':_0x3b1c7f[_0x42a8('0x60')][_0x42a8('0xd2')]}});}break;case'clicksend':if(_0x3b1c7f[_0x42a8('0x60')][_0x42a8('0x88')]&&_0x3b1c7f['body'][_0x42a8('0xd4')]){_0x32cf7a=_0x3b1c7f[_0x42a8('0x60')]['status_code'];return db['SmsMessage'][_0x42a8('0x5e')]({'where':{'messageId':_0x3b1c7f[_0x42a8('0x60')][_0x42a8('0x88')]}});}break;case _0x42a8('0x8b'):var _0xb3f184=_0x3b1c7f[_0x42a8('0x60')][_0x42a8('0x8c')][0x0];if(_0xb3f184[_0x42a8('0x87')]&&_0xb3f184[_0x42a8('0x32')]['groupName']===_0x42a8('0xd5')){_0x32cf7a=_0xb3f184[_0x42a8('0x32')][_0x42a8('0xd6')];return db[_0x42a8('0xa9')]['find']({'where':{'messageId':_0xb3f184[_0x42a8('0x87')]}});}break;case _0x42a8('0x91'):if(_0x3b1c7f['body'][_0x42a8('0x87')]&&_0x3b1c7f[_0x42a8('0x60')][_0x42a8('0x32')]){_0x32cf7a=_0x3b1c7f[_0x42a8('0x60')][_0x42a8('0x32')];return db[_0x42a8('0xa9')][_0x42a8('0x5e')]({'where':{'messageId':_0x3b1c7f[_0x42a8('0x60')][_0x42a8('0x87')]}});}break;case _0x42a8('0x94'):if(_0x3b1c7f[_0x42a8('0x60')][_0x42a8('0xd7')]&&_0x3b1c7f['body']['status']){_0x32cf7a=_0x3b1c7f['body'][_0x42a8('0x32')];return db['SmsMessage'][_0x42a8('0x5e')]({'where':{'messageId':_0x3b1c7f[_0x42a8('0x60')][_0x42a8('0xd7')]}});}break;}}})[_0x42a8('0x37')](handleEntityNotFound(_0x54223b,null))['then'](function(_0x39c65e){if(_0x39c65e){_0x40827f=_0x39c65e;switch(_0x45ec0f['type']){case'skebby':if(_0x32cf7a===_0x42a8('0xd5')){return _0x40827f['update']({'read':!![]});}else{logger[_0x42a8('0x29')](_0x42a8('0x27'),_0x42a8('0x32'),_0x42a8('0x84'),util[_0x42a8('0xcf')](_0x3b1c7f['body'],{'showHidden':![],'depth':null}));}break;case'connectel':if(_0x32cf7a==='1'){return _0x40827f['update']({'read':!![]});}else{logger[_0x42a8('0x29')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x42a8('0x32'),_0x42a8('0x84'),util[_0x42a8('0xcf')](_0x3b1c7f['body'],{'showHidden':![],'depth':null}));}break;case _0x42a8('0x86'):if(!_0x3b1c7f[_0x42a8('0x60')][_0x42a8('0xd8')]&&_0x32cf7a>=0xc8&&_0x32cf7a<=0xce){return _0x40827f['update']({'read':!![]});}else{logger['error'](_0x42a8('0x27'),_0x42a8('0x32'),'clicksend',util[_0x42a8('0xcf')](_0x3b1c7f[_0x42a8('0x60')],{'showHidden':![],'depth':null}));}break;case _0x42a8('0x8b'):var _0x7901ff=_0x3b1c7f['body'][_0x42a8('0x8c')][0x0];if(_0x7901ff[_0x42a8('0x32')][_0x42a8('0xd6')]===_0x42a8('0xd5')){return _0x40827f[_0x42a8('0x36')]({'read':!![]});}else{logger['error'](_0x42a8('0x27'),_0x42a8('0x32'),'infobip',util[_0x42a8('0xcf')](_0x3b1c7f[_0x42a8('0x60')],{'showHidden':![],'depth':null}));}break;case _0x42a8('0x91'):if(_0x32cf7a==_0x42a8('0xd9')||_0x32cf7a==_0x42a8('0xda')){return _0x40827f[_0x42a8('0x36')]({'read':!![]});}else{logger['error'](_0x42a8('0x27'),_0x42a8('0x32'),_0x42a8('0x91'),util['inspect'](_0x3b1c7f[_0x42a8('0x60')],{'showHidden':![],'depth':null}));}break;case'intelepeer':if(_0x32cf7a===_0x42a8('0xdb')||_0x32cf7a===_0x42a8('0xdc')){return _0x40827f[_0x42a8('0x36')]({'read':!![]});}else{logger[_0x42a8('0x29')]('SmsAccount,\x20%s,\x20%s,\x20%s','status','intelepeer',util[_0x42a8('0xcf')](_0x3b1c7f[_0x42a8('0x60')],{'showHidden':![],'depth':null}));}break;}return _0x40827f;}})[_0x42a8('0x37')](respondWithResult(_0x54223b,null))['catch'](handleError(_0x54223b,null));};exports[_0x42a8('0xdd')]=function(_0x2795c3,_0x2b7091,_0x2ec476){var _0x372e58,_0x4cbf16,_0x55c77d;return db[_0x42a8('0x41')]['find']({'where':{'id':_0x2795c3[_0x42a8('0x5c')]['id']}})['then'](handleEntityNotFound(_0x2b7091,null))[_0x42a8('0x37')](function(_0x408559){if(_0x408559){_0x55c77d=_0x408559;logger[_0x42a8('0x26')](_0x42a8('0x27'),_0x42a8('0x32'),_0x42a8('0xce'),_0x408559[_0x42a8('0x54')],util['inspect'](_0x2795c3[_0x42a8('0x46')],{'showHidden':![],'depth':null}));switch(_0x408559[_0x42a8('0x54')]){case _0x42a8('0x8e'):if(_0x2795c3['query'][_0x42a8('0xde')]&&_0x2795c3[_0x42a8('0x46')][_0x42a8('0xdf')]){_0x4cbf16=_0x2795c3[_0x42a8('0x46')][_0x42a8('0xdf')];return db['SmsMessage']['find']({'where':{'messageId':_0x2795c3[_0x42a8('0x46')][_0x42a8('0xde')]}});}break;}}})['then'](handleEntityNotFound(_0x2b7091,null))['then'](function(_0x1221a9){if(_0x1221a9){_0x372e58=_0x1221a9;switch(_0x55c77d[_0x42a8('0x54')]){case'csc':if(_0x4cbf16==='2'||_0x4cbf16==='6'){return _0x372e58['update']({'read':!![]});}else{logger[_0x42a8('0x29')](_0x42a8('0x27'),_0x42a8('0x32'),'csc',util[_0x42a8('0xcf')](_0x2795c3[_0x42a8('0x46')],{'showHidden':![],'depth':null}));};break;}return _0x372e58;}})['then'](respondWithResult(_0x2b7091,null))[_0x42a8('0x2c')](handleError(_0x2b7091,null));};exports[_0x42a8('0xe0')]=function(_0xfea099,_0x64046b,_0x47ab1e){return db[_0x42a8('0x41')][_0x42a8('0x5e')]({'where':{'id':_0xfea099['params']['id']}})[_0x42a8('0x37')](handleEntityNotFound(_0x64046b,null))[_0x42a8('0x37')](function(_0xc32ca5){if(_0xc32ca5){return _0xc32ca5['addAgents'](_0xfea099['body']['ids'],_[_0x42a8('0x9f')](_0xfea099[_0x42a8('0x60')],[_0x42a8('0x6d'),'id'])||{})[_0x42a8('0xa2')](function(_0x415cde){for(var _0x1674ba=0x0;_0x1674ba<_0xfea099[_0x42a8('0x60')]['ids'][_0x42a8('0x4c')];_0x1674ba+=0x1){socket[_0x42a8('0xe1')](_0x42a8('0xe2'),{'UserId':_0xfea099['body'][_0x42a8('0x6d')][_0x1674ba],'SmsAccountId':_0xfea099[_0x42a8('0x5c')]['id']});}return _0x415cde;});}})[_0x42a8('0x37')](respondWithResult(_0x64046b,null))[_0x42a8('0x2c')](handleError(_0x64046b,null));};exports[_0x42a8('0xe3')]=function(_0x20b86c,_0x428ff2,_0x389704){return db[_0x42a8('0x41')][_0x42a8('0x5e')]({'where':{'id':_0x20b86c[_0x42a8('0x5c')]['id']}})[_0x42a8('0x37')](handleEntityNotFound(_0x428ff2,null))[_0x42a8('0x37')](function(_0x3615e8){if(_0x3615e8){return _0x3615e8[_0x42a8('0xe3')](_0x20b86c[_0x42a8('0x46')]['ids'])[_0x42a8('0x37')](function(){if(_['isArray'](_0x20b86c[_0x42a8('0x46')][_0x42a8('0x6d')])){for(var _0x6fa2bd=0x0;_0x6fa2bd<_0x20b86c[_0x42a8('0x46')]['ids'][_0x42a8('0x4c')];_0x6fa2bd+=0x1){socket['emit'](_0x42a8('0xe4'),{'UserId':Number(_0x20b86c['query'][_0x42a8('0x6d')][_0x6fa2bd]),'SmsAccountId':Number(_0x20b86c[_0x42a8('0x5c')]['id'])});}}else{socket[_0x42a8('0xe1')](_0x42a8('0xe4'),{'UserId':Number(_0x20b86c[_0x42a8('0x46')][_0x42a8('0x6d')]),'SmsAccountId':Number(_0x20b86c[_0x42a8('0x5c')]['id'])});}});}})[_0x42a8('0x37')](respondWithStatusCode(_0x428ff2,null))[_0x42a8('0x2c')](handleError(_0x428ff2,null));};exports[_0x42a8('0xe5')]=function(_0x46b784,_0xe50a61,_0x1da122){var _0x40bcb8={};var _0x275776={};var _0x2702b1;var _0x5bd5c3;return db['SmsAccount'][_0x42a8('0x6a')]({'where':{'id':_0x46b784['params']['id']}})[_0x42a8('0x37')](handleEntityNotFound(_0xe50a61,null))[_0x42a8('0x37')](function(_0x232bdf){if(_0x232bdf){_0x2702b1=_0x232bdf;_0x275776[_0x42a8('0x45')]=_[_0x42a8('0x47')](db[_0x42a8('0xad')][_0x42a8('0x42')]);_0x275776[_0x42a8('0x46')]=_[_0x42a8('0x47')](_0x46b784[_0x42a8('0x46')]);_0x275776[_0x42a8('0x48')]=_[_0x42a8('0x4a')](_0x275776[_0x42a8('0x45')],_0x275776[_0x42a8('0x46')]);_0x40bcb8[_0x42a8('0x49')]=_[_0x42a8('0x4a')](_0x275776['model'],qs[_0x42a8('0x4b')](_0x46b784['query'][_0x42a8('0x4b')]));_0x40bcb8[_0x42a8('0x49')]=_0x40bcb8[_0x42a8('0x49')][_0x42a8('0x4c')]?_0x40bcb8[_0x42a8('0x49')]:_0x275776[_0x42a8('0x45')];_0x40bcb8[_0x42a8('0x4e')]=qs['sort'](_0x46b784[_0x42a8('0x46')][_0x42a8('0x4f')]);_0x40bcb8[_0x42a8('0x50')]=qs[_0x42a8('0x48')](_[_0x42a8('0x51')](_0x46b784['query'],_0x275776[_0x42a8('0x48')]));if(_0x46b784[_0x42a8('0x46')]['filter']){_0x40bcb8[_0x42a8('0x50')]=_[_0x42a8('0x53')](_0x40bcb8[_0x42a8('0x50')],{'$or':_[_0x42a8('0x40')](_0x40bcb8[_0x42a8('0x49')],function(_0x2d4ed1){var _0x244e3d={};_0x244e3d[_0x2d4ed1]={'$like':'%'+_0x46b784[_0x42a8('0x46')][_0x42a8('0x52')]+'%'};return _0x244e3d;})});}_0x40bcb8=_[_0x42a8('0x53')]({},_0x40bcb8,_0x46b784[_0x42a8('0x56')]);return _0x2702b1['getAgents'](_0x40bcb8);}})[_0x42a8('0x37')](function(_0x430375){if(_0x430375){_0x5bd5c3=_0x430375['length'];if(!_0x46b784[_0x42a8('0x46')][_0x42a8('0x70')](_0x42a8('0x6b'))){_0x40bcb8[_0x42a8('0x4d')]=qs[_0x42a8('0x4d')](_0x46b784[_0x42a8('0x46')][_0x42a8('0x4d')]);_0x40bcb8[_0x42a8('0x31')]=qs[_0x42a8('0x31')](_0x46b784[_0x42a8('0x46')]['offset']);}return _0x2702b1[_0x42a8('0xe5')](_0x40bcb8);}})[_0x42a8('0x37')](function(_0xe34b9f){if(_0xe34b9f){return _0xe34b9f?{'count':_0x5bd5c3,'rows':_0xe34b9f}:null;}})[_0x42a8('0x37')](respondWithResult(_0xe50a61,null))[_0x42a8('0x2c')](handleError(_0xe50a61,null));};
\ No newline at end of file
+var _0xdfc3=['List','out','SmsMessage','Messages','dataValues','debug','received\x20delivery\x20report\x20from','inspect','skebby_dispatch_id','requestid','statusInt','status_code','groupName','DELIVERED','redif','update','error_code','DELIVERED_TO_GATEWAY','RECEIVED_BY_RECIPIENT','message-delivered','DELIVRD','ACCEPTD','statusGet','csc','message-id','state','addAgents','emit','userSmsAccount:save','removeAgents','getAgents','zip-dir','fast-json-patch','moment','bluebird','mustache','to-csv','lodash','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','redis','defaults','localhost','socket.io-emitter','./smsAccount.socket','register','jayson/promise','http','request','then','info','request\x20sent','stringify','error','code','SmsAccount,\x20%s,\x20%s','message','result','catch','sendStatus','status','end','offset','undefined','limit','count','set','Content-Range','json','reject','save','get','SmsAccounts','UserProfileResource','destroy','stack','name','send','mandatoryDispositionPause','SmsAccount','rawAttributes','type','key','model','map','query','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','include','findAll','rows','Pause','keys','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','describe','addDisposition','SmsAccountId','Disposition','getDispositions','includeAll','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','findOne','options','removeAnswers','notify','sms','SmsApplication','account','orderBy','priority','Applications','Sequelize','ValidationError','createdAt','updatedAt','difference','CompanyId','ListId','mobile','twilio','From','Body','messageId','MessageSid','skebby','from','sender','text','connectel','clicksend','message_id','plivo','Text','infobip','results','originatingAddress','clickatell','fromNumber','replyMessageId','bandwidth','intelepeer','refid','isNil','from\x20is\x20mandatory','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','mapKey','CmList','Contacts','DESC','list','omit','CmContact','SmsInteraction','spread','interaction','push','applications','close','unmanaged','created','AttachmentId','User','UserId','unshift','agent','*,*,*,*','Start','startRouting','receiveMessage','SmsAccount,\x20%s,\x20%s,\x20%s','entity\x20found','SmsAccount,\x20%s,\x20%s,\x20%s,\x20%s','<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>','addApplications','sequelize','ISOLATION_LEVELS','findAndCountAll','finally','getApplications','getInteractions','Contact','Owner','fullname','internal','Tags','tag','body\x20is\x20mandatory\x20and\x20not\x20empty'];(function(_0x54bac5,_0x8d3a16){var _0xc15971=function(_0x254653){while(--_0x254653){_0x54bac5['push'](_0x54bac5['shift']());}};_0xc15971(++_0x8d3a16);}(_0xdfc3,0x1e1));var _0x3dfc=function(_0x1589dd,_0x2b9d22){_0x1589dd=_0x1589dd-0x0;var _0x1bddd1=_0xdfc3[_0x1589dd];return _0x1bddd1;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0x3dfc('0x0'));var jsonpatch=require(_0x3dfc('0x1'));var rp=require('request-promise');var moment=require(_0x3dfc('0x2'));var BPromise=require(_0x3dfc('0x3'));var Mustache=require(_0x3dfc('0x4'));var util=require('util');var path=require('path');var sox=require('sox');var csv=require(_0x3dfc('0x5'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x3dfc('0x6'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x3dfc('0x7'));var deskjs=require(_0x3dfc('0x8'));var toCsv=require(_0x3dfc('0x5'));var querystring=require(_0x3dfc('0x9'));var Papa=require(_0x3dfc('0xa'));var Redis=require(_0x3dfc('0xb'));var authService=require('../../components/auth/service');var qs=require(_0x3dfc('0xc'));var as=require(_0x3dfc('0xd'));var hardwareService=require(_0x3dfc('0xe'));var logger=require(_0x3dfc('0xf'))(_0x3dfc('0x10'));var utils=require(_0x3dfc('0x11'));var config=require(_0x3dfc('0x12'));var licenseUtil=require(_0x3dfc('0x13'));var db=require('../../mysqldb')['db'];config[_0x3dfc('0x14')]=_[_0x3dfc('0x15')](config[_0x3dfc('0x14')],{'host':_0x3dfc('0x16'),'port':0x18eb});var socket=require(_0x3dfc('0x17'))(new Redis(config['redis']));require(_0x3dfc('0x18'))[_0x3dfc('0x19')](socket);var jayson=require(_0x3dfc('0x1a'));var client=jayson['client'][_0x3dfc('0x1b')]({'port':0x232c});function respondWithRpcPromise(_0x368822,_0xbd7337,_0x3065a5,_0x5a0183){return new BPromise(function(_0x533f7e,_0x71e2df){var _0x1685c4=_0x5a0183||client;return _0x1685c4[_0x3dfc('0x1c')](_0x368822,_0x3065a5)[_0x3dfc('0x1d')](function(_0x55f52b){logger[_0x3dfc('0x1e')]('SmsAccount,\x20%s,\x20%s',_0xbd7337,_0x3dfc('0x1f'));logger['debug']('SmsAccount,\x20%s,\x20%s,\x20%s',_0xbd7337,_0x3dfc('0x1f'),JSON[_0x3dfc('0x20')](_0x55f52b));if(_0x55f52b[_0x3dfc('0x21')]){if(_0x55f52b[_0x3dfc('0x21')][_0x3dfc('0x22')]===0x1f4){logger[_0x3dfc('0x21')](_0x3dfc('0x23'),_0xbd7337,_0x55f52b[_0x3dfc('0x21')][_0x3dfc('0x24')]);return _0x71e2df(_0x55f52b[_0x3dfc('0x21')][_0x3dfc('0x24')]);}logger[_0x3dfc('0x21')](_0x3dfc('0x23'),_0xbd7337,_0x55f52b[_0x3dfc('0x21')][_0x3dfc('0x24')]);return _0x533f7e(_0x55f52b['error'][_0x3dfc('0x24')]);}else{logger[_0x3dfc('0x1e')](_0x3dfc('0x23'),_0xbd7337,_0x3dfc('0x1f'));_0x533f7e(_0x55f52b[_0x3dfc('0x25')][_0x3dfc('0x24')]);}})[_0x3dfc('0x26')](function(_0x19ef52){logger['error'](_0x3dfc('0x23'),_0xbd7337,_0x19ef52);_0x71e2df(_0x19ef52);});});}function respondWithStatusCode(_0xab2681,_0x29fa3b){_0x29fa3b=_0x29fa3b||0xcc;return function(_0x144053){if(_0x144053){return _0xab2681[_0x3dfc('0x27')](_0x29fa3b);}return _0xab2681[_0x3dfc('0x28')](_0x29fa3b)[_0x3dfc('0x29')]();};}function respondWithResult(_0x403560,_0x3cb1f6){_0x3cb1f6=_0x3cb1f6||0xc8;return function(_0x59e98a){if(_0x59e98a){return _0x403560[_0x3dfc('0x28')](_0x3cb1f6)['json'](_0x59e98a);}};}function respondWithFilteredResult(_0x385f20,_0xad5d72){return function(_0x1584c6){if(_0x1584c6){var _0x530038=typeof _0xad5d72[_0x3dfc('0x2a')]===_0x3dfc('0x2b')&&typeof _0xad5d72[_0x3dfc('0x2c')]==='undefined';var _0x3d82e4=_0x1584c6[_0x3dfc('0x2d')];var _0x1ccc8c=_0x530038?0x0:_0xad5d72[_0x3dfc('0x2a')];var _0x5389c1=_0x530038?_0x1584c6[_0x3dfc('0x2d')]:_0xad5d72[_0x3dfc('0x2a')]+_0xad5d72['limit'];var _0x2f1f14;if(_0x5389c1>=_0x3d82e4){_0x5389c1=_0x3d82e4;_0x2f1f14=0xc8;}else{_0x2f1f14=0xce;}_0x385f20[_0x3dfc('0x28')](_0x2f1f14);return _0x385f20[_0x3dfc('0x2e')](_0x3dfc('0x2f'),_0x1ccc8c+'-'+_0x5389c1+'/'+_0x3d82e4)[_0x3dfc('0x30')](_0x1584c6);}return null;};}function patchUpdates(_0x116b8a){return function(_0x2fad0c){try{jsonpatch['apply'](_0x2fad0c,_0x116b8a,!![]);}catch(_0x17fcb2){return BPromise[_0x3dfc('0x31')](_0x17fcb2);}return _0x2fad0c[_0x3dfc('0x32')]();};}function saveUpdates(_0xc1c43c,_0x1d5d5f){return function(_0xc9b728){if(_0xc9b728){return _0xc9b728['update'](_0xc1c43c)['then'](function(_0x467ddf){return _0x467ddf;});}return null;};}function removeEntity(_0xa51a7e,_0x55bf65){return function(_0x4b0794){if(_0x4b0794){return _0x4b0794['destroy']()[_0x3dfc('0x1d')](function(){var _0x25c23a=_0x4b0794[_0x3dfc('0x33')]({'plain':!![]});var _0x16abbd=_0x3dfc('0x34');return db[_0x3dfc('0x35')][_0x3dfc('0x36')]({'where':{'type':_0x16abbd,'resourceId':_0x25c23a['id']}})['then'](function(){return _0x4b0794;});})[_0x3dfc('0x1d')](function(){_0xa51a7e[_0x3dfc('0x28')](0xcc)['end']();});}};}function handleEntityNotFound(_0x25ec68,_0x2933e2){return function(_0xaaee5d){if(!_0xaaee5d){_0x25ec68[_0x3dfc('0x27')](0x194);}return _0xaaee5d;};}function handleError(_0x34fbeb,_0x3cca8d){_0x3cca8d=_0x3cca8d||0x1f4;return function(_0xce85c6){logger[_0x3dfc('0x21')](_0xce85c6[_0x3dfc('0x37')]);if(_0xce85c6[_0x3dfc('0x38')]){delete _0xce85c6[_0x3dfc('0x38')];}_0x34fbeb[_0x3dfc('0x28')](_0x3cca8d)[_0x3dfc('0x39')](_0xce85c6);};}exports['index']=function(_0x1f7ec6,_0x49f600){var _0x499d48={'include':[{'model':db['Pause'],'as':_0x3dfc('0x3a')}]},_0x1c3aa3={},_0x38850f={'count':0x0,'rows':[]};var _0x2eb7e5=_['map'](db[_0x3dfc('0x3b')][_0x3dfc('0x3c')],function(_0x35cb1c){return{'name':_0x35cb1c['fieldName'],'type':_0x35cb1c[_0x3dfc('0x3d')][_0x3dfc('0x3e')]};});_0x1c3aa3[_0x3dfc('0x3f')]=_[_0x3dfc('0x40')](_0x2eb7e5,_0x3dfc('0x38'));_0x1c3aa3['query']=_['keys'](_0x1f7ec6[_0x3dfc('0x41')]);_0x1c3aa3[_0x3dfc('0x42')]=_['intersection'](_0x1c3aa3[_0x3dfc('0x3f')],_0x1c3aa3['query']);_0x499d48[_0x3dfc('0x43')]=_[_0x3dfc('0x44')](_0x1c3aa3[_0x3dfc('0x3f')],qs[_0x3dfc('0x45')](_0x1f7ec6['query'][_0x3dfc('0x45')]));_0x499d48[_0x3dfc('0x43')]=_0x499d48['attributes'][_0x3dfc('0x46')]?_0x499d48[_0x3dfc('0x43')]:_0x1c3aa3['model'];if(!_0x1f7ec6[_0x3dfc('0x41')][_0x3dfc('0x47')](_0x3dfc('0x48'))){_0x499d48[_0x3dfc('0x2c')]=qs[_0x3dfc('0x2c')](_0x1f7ec6[_0x3dfc('0x41')][_0x3dfc('0x2c')]);_0x499d48['offset']=qs[_0x3dfc('0x2a')](_0x1f7ec6['query'][_0x3dfc('0x2a')]);}_0x499d48[_0x3dfc('0x49')]=qs['sort'](_0x1f7ec6[_0x3dfc('0x41')][_0x3dfc('0x4a')]);_0x499d48[_0x3dfc('0x4b')]=qs[_0x3dfc('0x42')](_[_0x3dfc('0x4c')](_0x1f7ec6[_0x3dfc('0x41')],_0x1c3aa3[_0x3dfc('0x42')]),_0x2eb7e5);if(_0x1f7ec6[_0x3dfc('0x41')][_0x3dfc('0x4d')]){_0x499d48[_0x3dfc('0x4b')]=_[_0x3dfc('0x4e')](_0x499d48[_0x3dfc('0x4b')],{'$or':_['map'](_0x2eb7e5,function(_0x573906){if(_0x573906[_0x3dfc('0x3d')]!==_0x3dfc('0x4f')){var _0x24d9bc={};_0x24d9bc[_0x573906[_0x3dfc('0x38')]]={'$like':'%'+_0x1f7ec6[_0x3dfc('0x41')][_0x3dfc('0x4d')]+'%'};return _0x24d9bc;}})});}_0x499d48=_['merge']({},_0x499d48,_0x1f7ec6['options']);var _0x3111e7={'where':_0x499d48[_0x3dfc('0x4b')]};return db[_0x3dfc('0x3b')][_0x3dfc('0x2d')](_0x3111e7)['then'](function(_0x338fb9){_0x38850f[_0x3dfc('0x2d')]=_0x338fb9;if(_0x1f7ec6[_0x3dfc('0x41')]['includeAll']){_0x499d48[_0x3dfc('0x50')]=[{'all':!![]}];}return db['SmsAccount'][_0x3dfc('0x51')](_0x499d48);})[_0x3dfc('0x1d')](function(_0x4b92f4){_0x38850f[_0x3dfc('0x52')]=_0x4b92f4;return _0x38850f;})[_0x3dfc('0x1d')](respondWithFilteredResult(_0x49f600,_0x499d48))[_0x3dfc('0x26')](handleError(_0x49f600,null));};exports['show']=function(_0x21c4d8,_0x121313){var _0x27ab0c={'raw':![],'where':{'id':_0x21c4d8['params']['id']},'include':[{'model':db[_0x3dfc('0x53')],'as':_0x3dfc('0x3a')}]},_0x39b2cf={};_0x39b2cf[_0x3dfc('0x3f')]=_[_0x3dfc('0x54')](db[_0x3dfc('0x3b')][_0x3dfc('0x3c')]);_0x39b2cf[_0x3dfc('0x41')]=_[_0x3dfc('0x54')](_0x21c4d8[_0x3dfc('0x41')]);_0x39b2cf[_0x3dfc('0x42')]=_[_0x3dfc('0x44')](_0x39b2cf[_0x3dfc('0x3f')],_0x39b2cf['query']);_0x27ab0c[_0x3dfc('0x43')]=_[_0x3dfc('0x44')](_0x39b2cf[_0x3dfc('0x3f')],qs[_0x3dfc('0x45')](_0x21c4d8[_0x3dfc('0x41')][_0x3dfc('0x45')]));_0x27ab0c[_0x3dfc('0x43')]=_0x27ab0c['attributes'][_0x3dfc('0x46')]?_0x27ab0c['attributes']:_0x39b2cf[_0x3dfc('0x3f')];if(_0x21c4d8['query']['includeAll']){_0x27ab0c[_0x3dfc('0x50')]=[{'all':!![]}];}_0x27ab0c=_[_0x3dfc('0x4e')]({},_0x27ab0c,_0x21c4d8['options']);return db[_0x3dfc('0x3b')][_0x3dfc('0x55')](_0x27ab0c)[_0x3dfc('0x1d')](handleEntityNotFound(_0x121313,null))['then'](respondWithResult(_0x121313,null))[_0x3dfc('0x26')](handleError(_0x121313,null));};exports[_0x3dfc('0x56')]=function(_0x44d12,_0x2a53bd){return db[_0x3dfc('0x3b')]['create'](_0x44d12[_0x3dfc('0x57')],{})[_0x3dfc('0x1d')](function(_0x357328){var _0x3ee2f7=_0x44d12[_0x3dfc('0x58')]['get']({'plain':!![]});if(!_0x3ee2f7)throw new Error(_0x3dfc('0x59'));if(_0x3ee2f7[_0x3dfc('0x5a')]==='user'){var _0x59f628=_0x357328[_0x3dfc('0x33')]({'plain':!![]});var _0x11658a=_0x3dfc('0x34');return db[_0x3dfc('0x5b')]['find']({'where':{'name':_0x11658a,'userProfileId':_0x3ee2f7[_0x3dfc('0x5c')]},'raw':!![]})[_0x3dfc('0x1d')](function(_0x5add15){if(_0x5add15&&_0x5add15[_0x3dfc('0x5d')]===0x0){return db['UserProfileResource'][_0x3dfc('0x56')]({'name':_0x59f628['name'],'resourceId':_0x59f628['id'],'type':_0x5add15['name'],'sectionId':_0x5add15['id']},{})[_0x3dfc('0x1d')](function(){return _0x357328;});}else{return _0x357328;}})['catch'](function(_0x1bd225){logger['error'](_0x3dfc('0x5e'),_0x1bd225);throw _0x1bd225;});}return _0x357328;})['then'](respondWithResult(_0x2a53bd,0xc9))['catch'](handleError(_0x2a53bd,null));};exports['update']=function(_0x56b3b5,_0x22e549){if(_0x56b3b5[_0x3dfc('0x57')]['id']){delete _0x56b3b5[_0x3dfc('0x57')]['id'];}return db[_0x3dfc('0x3b')][_0x3dfc('0x55')]({'where':{'id':_0x56b3b5[_0x3dfc('0x5f')]['id']},'include':[{'model':db['Pause'],'as':_0x3dfc('0x3a')}]})[_0x3dfc('0x1d')](handleEntityNotFound(_0x22e549,null))['then'](saveUpdates(_0x56b3b5[_0x3dfc('0x57')],null))[_0x3dfc('0x1d')](respondWithResult(_0x22e549,null))[_0x3dfc('0x26')](handleError(_0x22e549,null));};exports[_0x3dfc('0x36')]=function(_0x3182dd,_0x3ee93c){return db[_0x3dfc('0x3b')]['find']({'where':{'id':_0x3182dd['params']['id']}})['then'](handleEntityNotFound(_0x3ee93c,null))[_0x3dfc('0x1d')](removeEntity(_0x3ee93c,null))[_0x3dfc('0x26')](handleError(_0x3ee93c,null));};exports[_0x3dfc('0x60')]=function(_0x1afe37,_0x456f86){return db[_0x3dfc('0x3b')]['describe']()[_0x3dfc('0x1d')](respondWithResult(_0x456f86,null))[_0x3dfc('0x26')](handleError(_0x456f86,null));};exports[_0x3dfc('0x61')]=function(_0x4ad794,_0x26d6a6,_0x454f57){if(_0x4ad794[_0x3dfc('0x57')]['id']){delete _0x4ad794['body']['id'];}return db[_0x3dfc('0x3b')][_0x3dfc('0x55')]({'where':{'id':_0x4ad794['params']['id']}})[_0x3dfc('0x1d')](handleEntityNotFound(_0x26d6a6,null))[_0x3dfc('0x1d')](function(_0x16f918){if(_0x16f918){_0x4ad794['body'][_0x3dfc('0x62')]=_0x16f918['id'];return db[_0x3dfc('0x63')][_0x3dfc('0x56')](_0x4ad794[_0x3dfc('0x57')]);}})['then'](respondWithResult(_0x26d6a6,null))[_0x3dfc('0x26')](handleError(_0x26d6a6,null));};exports[_0x3dfc('0x64')]=function(_0x544fd0,_0x161274,_0x115585){var _0x1759bd={'raw':![],'where':{}};var _0x44bb7f={};var _0xafd328={'count':0x0,'rows':[]};return db[_0x3dfc('0x3b')]['findOne']({'where':{'id':_0x544fd0['params']['id']}})[_0x3dfc('0x1d')](handleEntityNotFound(_0x161274,null))[_0x3dfc('0x1d')](function(_0x37e427){if(_0x37e427){_0x44bb7f[_0x3dfc('0x3f')]=_['keys'](db[_0x3dfc('0x63')]['rawAttributes']);_0x44bb7f[_0x3dfc('0x41')]=_[_0x3dfc('0x54')](_0x544fd0[_0x3dfc('0x41')]);_0x44bb7f['filters']=_['intersection'](_0x44bb7f[_0x3dfc('0x3f')],_0x44bb7f['query']);_0x1759bd[_0x3dfc('0x43')]=_[_0x3dfc('0x44')](_0x44bb7f[_0x3dfc('0x3f')],qs[_0x3dfc('0x45')](_0x544fd0[_0x3dfc('0x41')]['fields']));_0x1759bd[_0x3dfc('0x43')]=_0x1759bd[_0x3dfc('0x43')][_0x3dfc('0x46')]?_0x1759bd[_0x3dfc('0x43')]:_0x44bb7f[_0x3dfc('0x3f')];if(!_0x544fd0['query'][_0x3dfc('0x47')](_0x3dfc('0x48'))){_0x1759bd['limit']=qs['limit'](_0x544fd0[_0x3dfc('0x41')][_0x3dfc('0x2c')]);_0x1759bd[_0x3dfc('0x2a')]=qs['offset'](_0x544fd0[_0x3dfc('0x41')][_0x3dfc('0x2a')]);}_0x1759bd[_0x3dfc('0x49')]=qs[_0x3dfc('0x4a')](_0x544fd0[_0x3dfc('0x41')]['sort']);_0x1759bd['where']=qs['filters'](_[_0x3dfc('0x4c')](_0x544fd0[_0x3dfc('0x41')],_0x44bb7f['filters']));_0x1759bd[_0x3dfc('0x4b')]['SmsAccountId']=_0x37e427['id'];if(_0x544fd0['query']['filter']){_0x1759bd[_0x3dfc('0x4b')]=_[_0x3dfc('0x4e')](_0x1759bd[_0x3dfc('0x4b')],{'$or':_[_0x3dfc('0x40')](_0x1759bd['attributes'],function(_0x892eb9){var _0x4fb67a={};_0x4fb67a[_0x892eb9]={'$like':'%'+_0x544fd0[_0x3dfc('0x41')]['filter']+'%'};return _0x4fb67a;})});}_0x1759bd=_['merge']({},_0x1759bd,_0x544fd0['options']);return db[_0x3dfc('0x63')][_0x3dfc('0x2d')]({'where':_0x1759bd[_0x3dfc('0x4b')]})[_0x3dfc('0x1d')](function(_0x4d9da9){_0xafd328[_0x3dfc('0x2d')]=_0x4d9da9;if(_0x544fd0[_0x3dfc('0x41')][_0x3dfc('0x65')]){_0x1759bd['include']=[{'all':!![]}];}return db[_0x3dfc('0x63')][_0x3dfc('0x51')](_0x1759bd);})['then'](function(_0x4f98c1){_0xafd328['rows']=_0x4f98c1;return _0xafd328;});}})['then'](respondWithFilteredResult(_0x161274,_0x1759bd))[_0x3dfc('0x26')](handleError(_0x161274,null));};exports[_0x3dfc('0x66')]=function(_0x1eaa5e,_0x4d3620,_0x4ad1f9){return db[_0x3dfc('0x3b')][_0x3dfc('0x55')]({'where':{'id':_0x1eaa5e[_0x3dfc('0x5f')]['id']}})[_0x3dfc('0x1d')](handleEntityNotFound(_0x4d3620,null))[_0x3dfc('0x1d')](function(_0xc4fd6f){if(_0xc4fd6f){return _0xc4fd6f[_0x3dfc('0x66')](_0x1eaa5e[_0x3dfc('0x41')][_0x3dfc('0x67')]);}})[_0x3dfc('0x1d')](respondWithStatusCode(_0x4d3620,null))[_0x3dfc('0x26')](handleError(_0x4d3620,null));};exports[_0x3dfc('0x68')]=function(_0x47036e,_0x5333e8,_0x41c96d){if(_0x47036e[_0x3dfc('0x57')]['id']){delete _0x47036e[_0x3dfc('0x57')]['id'];}return db['SmsAccount']['find']({'where':{'id':_0x47036e[_0x3dfc('0x5f')]['id']}})[_0x3dfc('0x1d')](handleEntityNotFound(_0x5333e8,null))['then'](function(_0x12f84e){if(_0x12f84e){_0x47036e[_0x3dfc('0x57')]['SmsAccountId']=_0x12f84e['id'];return db[_0x3dfc('0x69')]['create'](_0x47036e[_0x3dfc('0x57')]);}})['then'](respondWithResult(_0x5333e8,null))[_0x3dfc('0x26')](handleError(_0x5333e8,null));};exports[_0x3dfc('0x6a')]=function(_0x1e573f,_0x461697,_0x56686a){var _0x2328d4={'raw':![],'where':{}};var _0xf8618c={};var _0x2adadf={'count':0x0,'rows':[]};return db[_0x3dfc('0x3b')][_0x3dfc('0x6b')]({'where':{'id':_0x1e573f['params']['id']}})[_0x3dfc('0x1d')](handleEntityNotFound(_0x461697,null))[_0x3dfc('0x1d')](function(_0x4b5af7){if(_0x4b5af7){_0xf8618c[_0x3dfc('0x3f')]=_[_0x3dfc('0x54')](db['CannedAnswer'][_0x3dfc('0x3c')]);_0xf8618c['query']=_[_0x3dfc('0x54')](_0x1e573f['query']);_0xf8618c[_0x3dfc('0x42')]=_[_0x3dfc('0x44')](_0xf8618c[_0x3dfc('0x3f')],_0xf8618c['query']);_0x2328d4[_0x3dfc('0x43')]=_[_0x3dfc('0x44')](_0xf8618c[_0x3dfc('0x3f')],qs[_0x3dfc('0x45')](_0x1e573f[_0x3dfc('0x41')][_0x3dfc('0x45')]));_0x2328d4[_0x3dfc('0x43')]=_0x2328d4[_0x3dfc('0x43')][_0x3dfc('0x46')]?_0x2328d4['attributes']:_0xf8618c[_0x3dfc('0x3f')];if(!_0x1e573f['query']['hasOwnProperty'](_0x3dfc('0x48'))){_0x2328d4[_0x3dfc('0x2c')]=qs[_0x3dfc('0x2c')](_0x1e573f[_0x3dfc('0x41')]['limit']);_0x2328d4[_0x3dfc('0x2a')]=qs[_0x3dfc('0x2a')](_0x1e573f[_0x3dfc('0x41')][_0x3dfc('0x2a')]);}_0x2328d4[_0x3dfc('0x49')]=qs[_0x3dfc('0x4a')](_0x1e573f[_0x3dfc('0x41')][_0x3dfc('0x4a')]);_0x2328d4[_0x3dfc('0x4b')]=qs['filters'](_['pick'](_0x1e573f[_0x3dfc('0x41')],_0xf8618c[_0x3dfc('0x42')]));_0x2328d4[_0x3dfc('0x4b')][_0x3dfc('0x62')]=_0x4b5af7['id'];if(_0x1e573f[_0x3dfc('0x41')][_0x3dfc('0x4d')]){_0x2328d4[_0x3dfc('0x4b')]=_[_0x3dfc('0x4e')](_0x2328d4[_0x3dfc('0x4b')],{'$or':_[_0x3dfc('0x40')](_0x2328d4['attributes'],function(_0x432047){var _0x5857d4={};_0x5857d4[_0x432047]={'$like':'%'+_0x1e573f['query']['filter']+'%'};return _0x5857d4;})});}_0x2328d4=_[_0x3dfc('0x4e')]({},_0x2328d4,_0x1e573f[_0x3dfc('0x6c')]);return db[_0x3dfc('0x69')][_0x3dfc('0x2d')]({'where':_0x2328d4['where']})[_0x3dfc('0x1d')](function(_0x48b616){_0x2adadf[_0x3dfc('0x2d')]=_0x48b616;if(_0x1e573f[_0x3dfc('0x41')][_0x3dfc('0x65')]){_0x2328d4[_0x3dfc('0x50')]=[{'all':!![]}];}return db[_0x3dfc('0x69')][_0x3dfc('0x51')](_0x2328d4);})[_0x3dfc('0x1d')](function(_0x4172c5){_0x2adadf[_0x3dfc('0x52')]=_0x4172c5;return _0x2adadf;});}})[_0x3dfc('0x1d')](respondWithFilteredResult(_0x461697,_0x2328d4))['catch'](handleError(_0x461697,null));};exports[_0x3dfc('0x6d')]=function(_0x63f04e,_0x4eaff2,_0x578091){return db['SmsAccount']['find']({'where':{'id':_0x63f04e['params']['id']}})[_0x3dfc('0x1d')](handleEntityNotFound(_0x4eaff2,null))[_0x3dfc('0x1d')](function(_0x2d095f){if(_0x2d095f){return _0x2d095f[_0x3dfc('0x6d')](_0x63f04e[_0x3dfc('0x41')]['ids']);}})[_0x3dfc('0x1d')](respondWithStatusCode(_0x4eaff2,null))[_0x3dfc('0x26')](handleError(_0x4eaff2,null));};exports[_0x3dfc('0x6e')]=function(_0x5de9da,_0x2a16a8,_0x4532f4){var _0x4388d4={'channel':_0x3dfc('0x6f')};var _0x53d426=[];var _0x2111c2=[];var _0x5b5af6={};return db[_0x3dfc('0x3b')]['find']({'where':{'id':_0x5de9da[_0x3dfc('0x5f')]['id']},'include':[{'model':db[_0x3dfc('0x70')],'as':'Applications'}]})[_0x3dfc('0x1d')](handleEntityNotFound(_0x2a16a8,null))['then'](function(_0x4a56c4){_0x4388d4[_0x3dfc('0x71')]=_0x4a56c4;_0x4388d4['applications']=_[_0x3dfc('0x72')](_0x4a56c4['Applications'],[_0x3dfc('0x73')],['asc']);if(_0x4388d4[_0x3dfc('0x71')][_0x3dfc('0x74')]){delete _0x4388d4[_0x3dfc('0x71')]['Applications'];}return db['CmContact'][_0x3dfc('0x60')]();})[_0x3dfc('0x1d')](function(_0x398dd4){if(!_0x398dd4){throw new db[(_0x3dfc('0x75'))][(_0x3dfc('0x76'))]('no\x20available\x20attributes');}_0x53d426=_['difference'](_[_0x3dfc('0x54')](_0x398dd4),[_0x3dfc('0x77'),_0x3dfc('0x78')]);_0x2111c2=_[_0x3dfc('0x79')](_[_0x3dfc('0x54')](_0x398dd4),['createdAt',_0x3dfc('0x78'),_0x3dfc('0x7a'),_0x3dfc('0x7b')]);_0x4388d4['body']={'mapKey':_0x3dfc('0x7c')};if(_0x4388d4['account'][_0x3dfc('0x3d')]){switch(_0x4388d4[_0x3dfc('0x71')][_0x3dfc('0x3d')]){case _0x3dfc('0x7d'):_0x4388d4['body']['from']=_0x5de9da[_0x3dfc('0x57')][_0x3dfc('0x7e')];_0x4388d4[_0x3dfc('0x57')][_0x3dfc('0x57')]=_0x5de9da['body'][_0x3dfc('0x7f')];_0x4388d4[_0x3dfc('0x57')][_0x3dfc('0x80')]=_0x5de9da['body'][_0x3dfc('0x81')];break;case _0x3dfc('0x82'):_0x4388d4[_0x3dfc('0x57')][_0x3dfc('0x83')]='+'+_0x5de9da[_0x3dfc('0x57')][_0x3dfc('0x84')];_0x4388d4['body'][_0x3dfc('0x57')]=_0x5de9da['body'][_0x3dfc('0x85')];break;case _0x3dfc('0x86'):_0x4388d4[_0x3dfc('0x57')][_0x3dfc('0x83')]=_0x5de9da['body'][_0x3dfc('0x83')];_0x4388d4[_0x3dfc('0x57')][_0x3dfc('0x57')]=_0x5de9da[_0x3dfc('0x57')]['message'];break;case _0x3dfc('0x87'):_0x4388d4[_0x3dfc('0x57')]['from']=_0x5de9da[_0x3dfc('0x57')][_0x3dfc('0x83')];_0x4388d4[_0x3dfc('0x57')]['body']=_0x5de9da['body'][_0x3dfc('0x57')];_0x4388d4[_0x3dfc('0x57')][_0x3dfc('0x80')]=_0x5de9da[_0x3dfc('0x57')][_0x3dfc('0x88')];break;case _0x3dfc('0x89'):_0x4388d4[_0x3dfc('0x57')]['from']=_0x5de9da[_0x3dfc('0x57')][_0x3dfc('0x7e')];_0x4388d4['body']['body']=_0x5de9da[_0x3dfc('0x57')][_0x3dfc('0x8a')];_0x4388d4[_0x3dfc('0x57')][_0x3dfc('0x80')]=_0x5de9da[_0x3dfc('0x57')]['MessageUUID'];break;case _0x3dfc('0x8b'):_0x4388d4['body'][_0x3dfc('0x83')]='+'+_0x5de9da[_0x3dfc('0x57')][_0x3dfc('0x8c')][0x0][_0x3dfc('0x83')];_0x4388d4[_0x3dfc('0x57')][_0x3dfc('0x57')]=_0x5de9da[_0x3dfc('0x57')][_0x3dfc('0x8c')][0x0][_0x3dfc('0x85')];_0x4388d4[_0x3dfc('0x57')]['messageId']=_0x5de9da['body']['results'][0x0]['messageId'];break;case'csc':_0x4388d4[_0x3dfc('0x57')]['from']=_0x5de9da['body'][_0x3dfc('0x8d')];_0x4388d4[_0x3dfc('0x57')][_0x3dfc('0x57')]=_0x5de9da[_0x3dfc('0x57')]['segmentedMessage'][_0x3dfc('0x24')];break;case _0x3dfc('0x8e'):_0x4388d4[_0x3dfc('0x57')]['from']=_0x5de9da[_0x3dfc('0x57')][_0x3dfc('0x8f')];_0x4388d4[_0x3dfc('0x57')]['body']=_0x5de9da[_0x3dfc('0x57')][_0x3dfc('0x85')];_0x4388d4[_0x3dfc('0x57')][_0x3dfc('0x80')]=_0x5de9da[_0x3dfc('0x57')][_0x3dfc('0x90')];break;case _0x3dfc('0x91'):_0x4388d4[_0x3dfc('0x57')][_0x3dfc('0x80')]=_0x5de9da['body'][0x0][_0x3dfc('0x24')]['id'];_0x4388d4['body'][_0x3dfc('0x83')]=_0x5de9da['body'][0x0][_0x3dfc('0x24')][_0x3dfc('0x83')];_0x4388d4['body']['body']=_0x5de9da[_0x3dfc('0x57')][0x0][_0x3dfc('0x24')][_0x3dfc('0x85')];break;case _0x3dfc('0x92'):_0x4388d4['body']['from']=_0x5de9da['body'][_0x3dfc('0x83')];_0x4388d4[_0x3dfc('0x57')][_0x3dfc('0x57')]=_0x5de9da['body'][_0x3dfc('0x24')];_0x4388d4[_0x3dfc('0x57')][_0x3dfc('0x80')]=_0x5de9da['body'][_0x3dfc('0x93')];break;}}if(_0x4388d4[_0x3dfc('0x57')]['id']){delete _0x4388d4[_0x3dfc('0x57')]['id'];}if(_[_0x3dfc('0x94')](_0x4388d4[_0x3dfc('0x57')][_0x3dfc('0x83')])){throw new db[(_0x3dfc('0x75'))][(_0x3dfc('0x76'))](_0x3dfc('0x95'));}if(_[_0x3dfc('0x94')](_0x4388d4[_0x3dfc('0x57')][_0x3dfc('0x57')])||_0x4388d4[_0x3dfc('0x57')][_0x3dfc('0x57')]===''){throw new db[(_0x3dfc('0x75'))]['ValidationError']('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0x3dfc('0x94')](_0x4388d4[_0x3dfc('0x57')]['mapKey'])){throw new db[(_0x3dfc('0x75'))]['ValidationError'](_0x3dfc('0x96')+_0x2111c2);}if(!_[_0x3dfc('0x97')](_0x2111c2,_0x4388d4['body'][_0x3dfc('0x98')])){throw new db[(_0x3dfc('0x75'))][(_0x3dfc('0x76'))]('mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x2111c2);}_0x5b5af6[_0x4388d4['body'][_0x3dfc('0x98')]]=_0x4388d4['body'][_0x3dfc('0x83')];return db[_0x3dfc('0x99')][_0x3dfc('0x55')]({'where':{'id':_0x4388d4[_0x3dfc('0x71')]['ListId']},'include':[{'model':db['CmContact'],'as':_0x3dfc('0x9a'),'where':_0x5b5af6,'limit':0x1,'order':[['updatedAt',_0x3dfc('0x9b')]]}]});})['then'](handleEntityNotFound(_0x2a16a8,null))[_0x3dfc('0x1d')](function(_0x38f980){if(_0x38f980){_0x4388d4[_0x3dfc('0x9c')]=_[_0x3dfc('0x9d')](_0x38f980,['Contacts']);if(_0x38f980['Contacts'][_0x3dfc('0x46')]){return _0x38f980['Contacts'][0x0];}var _0x4c4060=_[_0x3dfc('0x15')](_0x4388d4[_0x3dfc('0x57')],{'firstName':_0x4388d4['body'][_0x3dfc('0x83')],'ListId':_0x38f980['id']});_0x4c4060[_0x4388d4['body'][_0x3dfc('0x98')]]=_0x4388d4[_0x3dfc('0x57')]['from'];return db[_0x3dfc('0x9e')][_0x3dfc('0x56')](_0x4c4060,{'fields':_0x53d426,'raw':!![]});}})[_0x3dfc('0x1d')](handleEntityNotFound(_0x2a16a8,null))[_0x3dfc('0x1d')](function(_0x4d1721){if(_0x4d1721){_0x4388d4['contact']=_0x4d1721;var _0x2dffe5={'ContactId':_0x4d1721['id'],'phone':_0x4388d4[_0x3dfc('0x57')][_0x3dfc('0x83')],'SmsAccountId':_0x5de9da[_0x3dfc('0x5f')]['id']};var _0x20d179={'ContactId':_0x4d1721['id'],'SmsAccountId':_0x5de9da[_0x3dfc('0x5f')]['id'],'closed':![]};return db[_0x3dfc('0x9f')][_0x3dfc('0x55')]({'where':_0x20d179})['then'](function(_0x4a0147){if(_0x4a0147){return[_0x4a0147,![]];}return db[_0x3dfc('0x9f')][_0x3dfc('0x56')](_0x2dffe5)[_0x3dfc('0x1d')](function(_0x1f0314){return[_0x1f0314,!![]];});});}})[_0x3dfc('0xa0')](function(_0x2adc93,_0x2d3fa7){_0x4388d4['interaction']=_0x2adc93[_0x3dfc('0x33')]({'plain':!![]});_0x4388d4[_0x3dfc('0xa1')]['created']=![];if(_0x2d3fa7){if(_0x4388d4[_0x3dfc('0x71')]['autoclose']){_0x4388d4['applications'][_0x3dfc('0xa2')]({'id':0x0,'priority':_0x4388d4[_0x3dfc('0xa3')][_0x3dfc('0x46')]+0x1,'app':_0x3dfc('0xa4'),'appdata':_0x3dfc('0xa5'),'interval':'*,*,*,*'});}_0x4388d4['interaction'][_0x3dfc('0xa6')]=!![];}return db['SmsMessage']['create']({'phone':_0x4388d4['body']['from'],'messageId':_0x4388d4[_0x3dfc('0x57')][_0x3dfc('0x80')],'body':_0x4388d4[_0x3dfc('0x57')]['body'],'SmsAccountId':_0x5de9da['params']['id'],'SmsInteractionId':_0x2adc93['id'],'direction':'in','ContactId':_0x2adc93['ContactId'],'AttachmentId':_0x4388d4[_0x3dfc('0x57')][_0x3dfc('0xa7')]});})['then'](function(_0x5f7bb){_0x4388d4[_0x3dfc('0x24')]=_0x5f7bb;if(_0x4388d4[_0x3dfc('0xa1')]['UserId']){return db[_0x3dfc('0xa8')][_0x3dfc('0x55')]({'attributes':['id',_0x3dfc('0x38')],'where':{'id':_0x4388d4[_0x3dfc('0xa1')][_0x3dfc('0xa9')]}})[_0x3dfc('0x1d')](function(_0x4a239d){if(_0x4a239d){_0x4388d4[_0x3dfc('0xa3')][_0x3dfc('0xaa')]({'id':0x0,'priority':0x0,'app':_0x3dfc('0xab'),'appdata':_0x4a239d['name']+','+(_0x4388d4[_0x3dfc('0x71')]['waitForTheAssignedAgent']||0xa),'interval':_0x3dfc('0xac')});}return respondWithRpcPromise(_0x3dfc('0xad'),_0x3dfc('0xae'),_0x4388d4);});}return respondWithRpcPromise(_0x3dfc('0xad'),_0x3dfc('0xae'),_0x4388d4);})[_0x3dfc('0x1d')](function(_0x3528cd){if(_0x3528cd){var _0x215047=0xc8;var _0x2ab700=_0x3dfc('0xaf');logger[_0x3dfc('0x1e')](_0x3dfc('0xb0'),_0x2ab700,_0x215047,_0x3dfc('0xb1'));logger['debug'](_0x3dfc('0xb2'),_0x2ab700,_0x215047,_0x3dfc('0xb1'),JSON[_0x3dfc('0x20')](_0x3528cd));if(_0x4388d4[_0x3dfc('0x71')][_0x3dfc('0x3d')]===_0x3dfc('0x7d')){return _0x2a16a8[_0x3dfc('0x28')](_0x215047)['set']('Content-Type','text/xml')[_0x3dfc('0x39')](_0x3dfc('0xb3'));}else{return _0x2a16a8['status'](_0x215047)[_0x3dfc('0x30')](_0x3528cd);}}})['catch'](handleError(_0x2a16a8,null));};exports[_0x3dfc('0xb4')]=function(_0x13d350,_0x57ae9b){var _0x4be679=_0x13d350[_0x3dfc('0x5f')]['id'];var _0x93e316=_0x13d350[_0x3dfc('0x57')];var _0x3d1a3c=0xc8;var _0x28d340=null;return db[_0x3dfc('0xb5')]['transaction']({'isolationLevel':db[_0x3dfc('0xb5')]['Transaction'][_0x3dfc('0xb6')]['READ_COMMITTED']},function(_0x2887cf){return db[_0x3dfc('0x3b')][_0x3dfc('0x6b')]({'where':{'id':_0x4be679},'transaction':_0x2887cf})[_0x3dfc('0x1d')](function(_0x27ab2e){if(_0x27ab2e){return db[_0x3dfc('0x70')][_0x3dfc('0x36')]({'where':{'SmsAccountId':_0x4be679},'transaction':_0x2887cf})['then'](function(){var _0x52ef0c=_['map'](_0x93e316,function(_0x13230d){_0x13230d[_0x3dfc('0x62')]=_0x4be679;return _0x13230d;});return db[_0x3dfc('0x70')]['bulkCreate'](_0x52ef0c,{'transaction':_0x2887cf});});}else{_0x3d1a3c=0x194;_0x28d340=[];}});})[_0x3dfc('0x1d')](function(){if(_0x3d1a3c!==0x194){return db[_0x3dfc('0x70')][_0x3dfc('0xb7')]({'where':{'SmsAccountId':_0x4be679},'order':_0x3dfc('0x73')})['then'](function(_0x55b222){_0x28d340=_0x55b222;});}})[_0x3dfc('0x26')](function(_0x3e946d){_0x3d1a3c=0x1f4;logger[_0x3dfc('0x21')](_0x3e946d[_0x3dfc('0x37')]);if(_0x3e946d[_0x3dfc('0x38')]){delete _0x3e946d[_0x3dfc('0x38')];}_0x28d340=_0x3e946d;})[_0x3dfc('0xb8')](function(){if(_0x28d340===null){_0x57ae9b['sendStatus'](_0x3d1a3c);}else{if(_0x3d1a3c===0x1f4){_0x57ae9b[_0x3dfc('0x28')](_0x3d1a3c)[_0x3dfc('0x39')](_0x28d340);}else{_0x57ae9b['status'](_0x3d1a3c)[_0x3dfc('0x30')](_0x28d340);}}});};exports[_0x3dfc('0xb9')]=function(_0x5d852d,_0x297924,_0x37e1d7){var _0x21fb9a={};var _0x3a49c6={};var _0x4b1c8f;var _0x730690;return db[_0x3dfc('0x3b')]['findOne']({'where':{'id':_0x5d852d[_0x3dfc('0x5f')]['id']}})[_0x3dfc('0x1d')](handleEntityNotFound(_0x297924,null))[_0x3dfc('0x1d')](function(_0x2587d1){if(_0x2587d1){_0x4b1c8f=_0x2587d1;_0x3a49c6[_0x3dfc('0x3f')]=_[_0x3dfc('0x54')](db[_0x3dfc('0x70')][_0x3dfc('0x3c')]);_0x3a49c6[_0x3dfc('0x41')]=_['keys'](_0x5d852d[_0x3dfc('0x41')]);_0x3a49c6[_0x3dfc('0x42')]=_[_0x3dfc('0x44')](_0x3a49c6['model'],_0x3a49c6[_0x3dfc('0x41')]);_0x21fb9a['attributes']=_[_0x3dfc('0x44')](_0x3a49c6[_0x3dfc('0x3f')],qs[_0x3dfc('0x45')](_0x5d852d[_0x3dfc('0x41')][_0x3dfc('0x45')]));_0x21fb9a[_0x3dfc('0x43')]=_0x21fb9a[_0x3dfc('0x43')]['length']?_0x21fb9a['attributes']:_0x3a49c6[_0x3dfc('0x3f')];_0x21fb9a[_0x3dfc('0x49')]=qs['sort'](_0x5d852d[_0x3dfc('0x41')]['sort']);_0x21fb9a[_0x3dfc('0x4b')]=qs[_0x3dfc('0x42')](_[_0x3dfc('0x4c')](_0x5d852d[_0x3dfc('0x41')],_0x3a49c6[_0x3dfc('0x42')]));if(_0x5d852d[_0x3dfc('0x41')][_0x3dfc('0x4d')]){_0x21fb9a['where']=_[_0x3dfc('0x4e')](_0x21fb9a[_0x3dfc('0x4b')],{'$or':_[_0x3dfc('0x40')](_0x21fb9a[_0x3dfc('0x43')],function(_0x408ddb){var _0x2cf1db={};_0x2cf1db[_0x408ddb]={'$like':'%'+_0x5d852d[_0x3dfc('0x41')][_0x3dfc('0x4d')]+'%'};return _0x2cf1db;})});}_0x21fb9a=_[_0x3dfc('0x4e')]({},_0x21fb9a,_0x5d852d[_0x3dfc('0x6c')]);return _0x4b1c8f[_0x3dfc('0xb9')](_0x21fb9a);}})[_0x3dfc('0x1d')](function(_0x385a99){if(_0x385a99){_0x730690=_0x385a99['length'];if(!_0x5d852d[_0x3dfc('0x41')][_0x3dfc('0x47')](_0x3dfc('0x48'))){_0x21fb9a[_0x3dfc('0x2c')]=qs[_0x3dfc('0x2c')](_0x5d852d[_0x3dfc('0x41')]['limit']);_0x21fb9a[_0x3dfc('0x2a')]=qs['offset'](_0x5d852d[_0x3dfc('0x41')][_0x3dfc('0x2a')]);}return _0x4b1c8f[_0x3dfc('0xb9')](_0x21fb9a);}})[_0x3dfc('0x1d')](function(_0x4f1378){if(_0x4f1378){return _0x4f1378?{'count':_0x730690,'rows':_0x4f1378}:null;}})[_0x3dfc('0x1d')](respondWithResult(_0x297924,null))[_0x3dfc('0x26')](handleError(_0x297924,null));};exports[_0x3dfc('0xba')]=function(_0x256d4a,_0x116b1e,_0x5a69b5){var _0x217c7d={'raw':![],'where':{}};var _0x482dbe={};var _0x27205b={'count':0x0,'rows':[]};return db[_0x3dfc('0x3b')][_0x3dfc('0x6b')]({'where':{'id':_0x256d4a[_0x3dfc('0x5f')]['id']}})[_0x3dfc('0x1d')](handleEntityNotFound(_0x116b1e,null))[_0x3dfc('0x1d')](function(_0x5253f5){if(_0x5253f5){_0x482dbe['model']=_[_0x3dfc('0x54')](db[_0x3dfc('0x9f')][_0x3dfc('0x3c')]);_0x482dbe[_0x3dfc('0x41')]=_['keys'](_0x256d4a[_0x3dfc('0x41')]);_0x482dbe[_0x3dfc('0x42')]=_[_0x3dfc('0x44')](_0x482dbe[_0x3dfc('0x3f')],_0x482dbe['query']);_0x217c7d[_0x3dfc('0x43')]=_['intersection'](_0x482dbe[_0x3dfc('0x3f')],qs[_0x3dfc('0x45')](_0x256d4a[_0x3dfc('0x41')][_0x3dfc('0x45')]));_0x217c7d['attributes']=_0x217c7d['attributes'][_0x3dfc('0x46')]?_0x217c7d['attributes']:_0x482dbe[_0x3dfc('0x3f')];if(!_0x256d4a['query']['hasOwnProperty']('nolimit')){_0x217c7d[_0x3dfc('0x2c')]=qs[_0x3dfc('0x2c')](_0x256d4a[_0x3dfc('0x41')][_0x3dfc('0x2c')]);_0x217c7d['offset']=qs[_0x3dfc('0x2a')](_0x256d4a[_0x3dfc('0x41')][_0x3dfc('0x2a')]);}_0x217c7d['order']=qs[_0x3dfc('0x4a')](_0x256d4a[_0x3dfc('0x41')][_0x3dfc('0x4a')]);_0x217c7d[_0x3dfc('0x4b')]=qs[_0x3dfc('0x42')](_[_0x3dfc('0x4c')](_0x256d4a[_0x3dfc('0x41')],_0x482dbe[_0x3dfc('0x42')]));_0x217c7d[_0x3dfc('0x4b')]['SmsAccountId']=_0x5253f5['id'];if(_0x256d4a['query'][_0x3dfc('0x4d')]){_0x217c7d[_0x3dfc('0x4b')]=_[_0x3dfc('0x4e')](_0x217c7d[_0x3dfc('0x4b')],{'$or':_[_0x3dfc('0x40')](_0x217c7d[_0x3dfc('0x43')],function(_0x3da2fa){var _0xe7a6d8={};_0xe7a6d8[_0x3da2fa]={'$like':'%'+_0x256d4a[_0x3dfc('0x41')]['filter']+'%'};return _0xe7a6d8;})});}_0x217c7d=_['merge']({},_0x217c7d,_0x256d4a[_0x3dfc('0x6c')]);return db[_0x3dfc('0x9f')][_0x3dfc('0x2d')]({'where':_0x217c7d['where']})['then'](function(_0x21286c){_0x27205b['count']=_0x21286c;if(_0x256d4a[_0x3dfc('0x41')][_0x3dfc('0x65')]){_0x217c7d[_0x3dfc('0x50')]=[{'model':db[_0x3dfc('0x9e')],'as':_0x3dfc('0xbb'),'required':![]},{'model':db[_0x3dfc('0xa8')],'as':_0x3dfc('0xbc'),'attributes':[_0x3dfc('0x38'),_0x3dfc('0xbd'),_0x3dfc('0xbe')],'required':![]},{'model':db['Tag'],'as':_0x3dfc('0xbf'),'attributes':['id',_0x3dfc('0x38'),'color'],'where':_0x256d4a['query'][_0x3dfc('0xc0')]?{'id':_0x256d4a[_0x3dfc('0x41')][_0x3dfc('0xc0')]}:undefined,'required':_0x256d4a[_0x3dfc('0x41')][_0x3dfc('0xc0')]?!![]:![]}];}return db[_0x3dfc('0x9f')]['findAll'](_0x217c7d);})[_0x3dfc('0x1d')](function(_0x32ec7d){_0x27205b['rows']=_0x32ec7d;return _0x27205b;});}})[_0x3dfc('0x1d')](respondWithFilteredResult(_0x116b1e,_0x217c7d))['catch'](handleError(_0x116b1e,null));};exports[_0x3dfc('0x39')]=function(_0x136692,_0xbc3495,_0x3d34cc){var _0x59e193,_0xf23d62,_0x115a7b;if(_[_0x3dfc('0x94')](_0x136692['body']['body'])||_0x136692[_0x3dfc('0x57')][_0x3dfc('0x57')]===''){throw new db[(_0x3dfc('0x75'))][(_0x3dfc('0x76'))](_0x3dfc('0xc1'));}if(_[_0x3dfc('0x94')](_0x136692[_0x3dfc('0x57')]['to'])){throw new db['Sequelize'][(_0x3dfc('0x76'))]('to\x20is\x20mandatory');}_0x59e193=_0x136692[_0x3dfc('0x57')]['to'];return db[_0x3dfc('0x3b')][_0x3dfc('0x55')]({'where':{'id':_0x136692[_0x3dfc('0x5f')]['id']},'include':[{'model':db[_0x3dfc('0x99')],'as':'List','include':[{'model':db[_0x3dfc('0x9e')],'as':_0x3dfc('0x9a'),'where':{'mobile':_0x59e193},'limit':0x1,'order':[[_0x3dfc('0x78'),'DESC']]}]}]})['then'](handleEntityNotFound(_0xbc3495,null))[_0x3dfc('0x1d')](function(_0x513f80){if(_0x513f80&&_0x513f80[_0x3dfc('0xc2')]){_0xf23d62=_0x513f80['get']({'plain':!![]});if(_0xf23d62[_0x3dfc('0xc2')]&&_0xf23d62[_0x3dfc('0xc2')][_0x3dfc('0x9a')]['length']){return _0xf23d62[_0x3dfc('0xc2')][_0x3dfc('0x9a')][0x0];}return db[_0x3dfc('0x9e')][_0x3dfc('0x56')](_[_0x3dfc('0x15')](_0x136692[_0x3dfc('0x57')],{'firstName':_0x59e193,'mobile':_0x59e193,'phone':_0x59e193,'ListId':_0xf23d62[_0x3dfc('0x7b')]}));}})[_0x3dfc('0x1d')](handleEntityNotFound(_0xbc3495,null))['then'](function(_0x3abf74){if(_0x3abf74){_0x115a7b=_0x3abf74;return db[_0x3dfc('0x9f')][_0x3dfc('0x55')]({'where':{'ContactId':_0x115a7b['id'],'closed':![],'SmsAccountId':_0xf23d62['id']}})[_0x3dfc('0x1d')](function(_0x4499f3){if(_0x4499f3){return[_0x4499f3,![]];}return db[_0x3dfc('0x9f')][_0x3dfc('0x56')]({'UserId':_0x136692['user']['id'],'ContactId':_0x115a7b['id'],'SmsAccountId':_0xf23d62['id'],'phone':_0x59e193,'firstMsgDirection':_0x3dfc('0xc3'),'Messages':[_[_0x3dfc('0x4e')](_0x136692[_0x3dfc('0x57')],{'read':![],'body':_0x136692['body'][_0x3dfc('0x57')],'phone':_0x59e193,'SmsAccountId':_0xf23d62['id'],'UserId':_0x136692[_0x3dfc('0x58')]['id'],'ContactId':_0x115a7b['id']})]},{'include':[{'model':db[_0x3dfc('0xc4')],'as':_0x3dfc('0xc5')}]})[_0x3dfc('0x1d')](function(_0xfcecf0){return[_0xfcecf0,!![]];});});}})[_0x3dfc('0xa0')](function(_0x1a3950,_0xc21d13){if(_0xc21d13){return _0x1a3950;}return db['SmsMessage']['create'](_[_0x3dfc('0x4e')](_0x136692['body'],{'read':![],'body':_0x136692[_0x3dfc('0x57')][_0x3dfc('0x57')],'phone':_0x59e193,'SmsAccountId':_0xf23d62['id'],'SmsInteractionId':_0x1a3950['id'],'UserId':_0x136692['user']['id'],'ContactId':_0x115a7b['id']}))['then'](function(_0x140012){_0x1a3950['dataValues'][_0x3dfc('0xc5')]=[];_0x1a3950[_0x3dfc('0xc6')]['Messages']['push'](_0x140012[_0x3dfc('0xc6')]);return _0x1a3950;});})[_0x3dfc('0x1d')](respondWithResult(_0xbc3495,null))[_0x3dfc('0x26')](handleError(_0xbc3495,null));};exports[_0x3dfc('0x28')]=function(_0x218cfb,_0x56fa46,_0x12712d){if(_0x218cfb[_0x3dfc('0x57')]['id']){delete _0x218cfb[_0x3dfc('0x57')]['id'];}var _0x3f1716,_0x9bc9d,_0x55da79;return db[_0x3dfc('0x3b')][_0x3dfc('0x55')]({'where':{'id':_0x218cfb[_0x3dfc('0x5f')]['id']}})['then'](handleEntityNotFound(_0x56fa46,null))[_0x3dfc('0x1d')](function(_0x25afee){if(_0x25afee){_0x55da79=_0x25afee;logger[_0x3dfc('0xc7')](_0x3dfc('0xb0'),_0x3dfc('0x28'),_0x3dfc('0xc8'),_0x25afee[_0x3dfc('0x3d')],util[_0x3dfc('0xc9')](_0x218cfb[_0x3dfc('0x57')],{'showHidden':![],'depth':null}));switch(_0x25afee[_0x3dfc('0x3d')]){case _0x3dfc('0x82'):if(_0x218cfb['body'][_0x3dfc('0xca')]&&_0x218cfb[_0x3dfc('0x57')][_0x3dfc('0x28')]){_0x9bc9d=_0x218cfb[_0x3dfc('0x57')][_0x3dfc('0x28')];return db[_0x3dfc('0xc4')][_0x3dfc('0x55')]({'where':{'messageId':_0x218cfb[_0x3dfc('0x57')][_0x3dfc('0xca')]}});}break;case'connectel':if(_0x218cfb[_0x3dfc('0x57')][_0x3dfc('0xcb')]&&_0x218cfb[_0x3dfc('0x57')][_0x3dfc('0xcc')]){_0x9bc9d=_0x218cfb['body'][_0x3dfc('0xcc')];return db[_0x3dfc('0xc4')][_0x3dfc('0x55')]({'where':{'messageId':_0x218cfb[_0x3dfc('0x57')][_0x3dfc('0xcb')]}});}break;case _0x3dfc('0x87'):if(_0x218cfb[_0x3dfc('0x57')][_0x3dfc('0x88')]&&_0x218cfb[_0x3dfc('0x57')][_0x3dfc('0xcd')]){_0x9bc9d=_0x218cfb[_0x3dfc('0x57')][_0x3dfc('0xcd')];return db[_0x3dfc('0xc4')]['find']({'where':{'messageId':_0x218cfb[_0x3dfc('0x57')][_0x3dfc('0x88')]}});}break;case _0x3dfc('0x8b'):var _0x7eede=_0x218cfb[_0x3dfc('0x57')][_0x3dfc('0x8c')][0x0];if(_0x7eede[_0x3dfc('0x80')]&&_0x7eede[_0x3dfc('0x28')][_0x3dfc('0xce')]===_0x3dfc('0xcf')){_0x9bc9d=_0x7eede[_0x3dfc('0x28')]['groupName'];return db['SmsMessage'][_0x3dfc('0x55')]({'where':{'messageId':_0x7eede[_0x3dfc('0x80')]}});}break;case _0x3dfc('0x8e'):if(_0x218cfb[_0x3dfc('0x57')][_0x3dfc('0x80')]&&_0x218cfb[_0x3dfc('0x57')]['status']){_0x9bc9d=_0x218cfb[_0x3dfc('0x57')][_0x3dfc('0x28')];return db['SmsMessage'][_0x3dfc('0x55')]({'where':{'messageId':_0x218cfb[_0x3dfc('0x57')][_0x3dfc('0x80')]}});}break;case _0x3dfc('0x91'):if(_0x218cfb[_0x3dfc('0x57')][0x0][_0x3dfc('0x24')]['id']){_0x9bc9d=_0x218cfb[_0x3dfc('0x57')][0x0]['type'];return db[_0x3dfc('0xc4')][_0x3dfc('0x55')]({'where':{'messageId':_0x218cfb[_0x3dfc('0x57')][0x0][_0x3dfc('0x24')]['id']}});}break;case _0x3dfc('0x92'):if(_0x218cfb[_0x3dfc('0x57')]['redif']&&_0x218cfb['body'][_0x3dfc('0x28')]){_0x9bc9d=_0x218cfb['body']['status'];return db[_0x3dfc('0xc4')][_0x3dfc('0x55')]({'where':{'messageId':_0x218cfb['body'][_0x3dfc('0xd0')]}});}break;}}})[_0x3dfc('0x1d')](handleEntityNotFound(_0x56fa46,null))[_0x3dfc('0x1d')](function(_0x3a189b){if(_0x3a189b){_0x3f1716=_0x3a189b;switch(_0x55da79[_0x3dfc('0x3d')]){case'skebby':if(_0x9bc9d==='DELIVERED'){return _0x3f1716[_0x3dfc('0xd1')]({'read':!![]});}else{logger[_0x3dfc('0x21')](_0x3dfc('0xb0'),_0x3dfc('0x28'),_0x3dfc('0x82'),util[_0x3dfc('0xc9')](_0x218cfb['body'],{'showHidden':![],'depth':null}));}break;case'connectel':if(_0x9bc9d==='1'){return _0x3f1716[_0x3dfc('0xd1')]({'read':!![]});}else{logger['error'](_0x3dfc('0xb0'),'status',_0x3dfc('0x82'),util[_0x3dfc('0xc9')](_0x218cfb[_0x3dfc('0x57')],{'showHidden':![],'depth':null}));}break;case _0x3dfc('0x87'):if(!_0x218cfb[_0x3dfc('0x57')][_0x3dfc('0xd2')]&&_0x9bc9d>=0xc8&&_0x9bc9d<=0xce){return _0x3f1716[_0x3dfc('0xd1')]({'read':!![]});}else{logger[_0x3dfc('0x21')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x3dfc('0x28'),_0x3dfc('0x87'),util[_0x3dfc('0xc9')](_0x218cfb[_0x3dfc('0x57')],{'showHidden':![],'depth':null}));}break;case _0x3dfc('0x8b'):var _0x1621f2=_0x218cfb[_0x3dfc('0x57')][_0x3dfc('0x8c')][0x0];if(_0x1621f2[_0x3dfc('0x28')]['groupName']===_0x3dfc('0xcf')){return _0x3f1716[_0x3dfc('0xd1')]({'read':!![]});}else{logger[_0x3dfc('0x21')](_0x3dfc('0xb0'),_0x3dfc('0x28'),_0x3dfc('0x8b'),util[_0x3dfc('0xc9')](_0x218cfb[_0x3dfc('0x57')],{'showHidden':![],'depth':null}));}break;case _0x3dfc('0x8e'):if(_0x9bc9d==_0x3dfc('0xd3')||_0x9bc9d==_0x3dfc('0xd4')){return _0x3f1716[_0x3dfc('0xd1')]({'read':!![]});}else{logger[_0x3dfc('0x21')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x3dfc('0x28'),_0x3dfc('0x8e'),util['inspect'](_0x218cfb[_0x3dfc('0x57')],{'showHidden':![],'depth':null}));}break;case'bandwidth':if(_0x9bc9d==_0x3dfc('0xd5')){return _0x3f1716['update']({'read':!![]});}else{logger[_0x3dfc('0x21')](_0x3dfc('0xb0'),_0x3dfc('0x28'),_0x3dfc('0x91'),util['inspect'](_0x218cfb[_0x3dfc('0x57')],{'showHidden':![],'depth':null}));}break;case _0x3dfc('0x92'):if(_0x9bc9d===_0x3dfc('0xd6')||_0x9bc9d===_0x3dfc('0xd7')){return _0x3f1716['update']({'read':!![]});}else{logger[_0x3dfc('0x21')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x3dfc('0x28'),'intelepeer',util['inspect'](_0x218cfb[_0x3dfc('0x57')],{'showHidden':![],'depth':null}));}break;}return _0x3f1716;}})[_0x3dfc('0x1d')](respondWithResult(_0x56fa46,null))['catch'](handleError(_0x56fa46,null));};exports[_0x3dfc('0xd8')]=function(_0x258c63,_0x12918f,_0x53fca1){var _0x21e64b,_0x509012,_0x5f2719;return db[_0x3dfc('0x3b')][_0x3dfc('0x55')]({'where':{'id':_0x258c63[_0x3dfc('0x5f')]['id']}})[_0x3dfc('0x1d')](handleEntityNotFound(_0x12918f,null))['then'](function(_0x453d0e){if(_0x453d0e){_0x5f2719=_0x453d0e;logger['debug'](_0x3dfc('0xb0'),'status',_0x3dfc('0xc8'),_0x453d0e[_0x3dfc('0x3d')],util[_0x3dfc('0xc9')](_0x258c63[_0x3dfc('0x41')],{'showHidden':![],'depth':null}));switch(_0x453d0e['type']){case _0x3dfc('0xd9'):if(_0x258c63['query'][_0x3dfc('0xda')]&&_0x258c63[_0x3dfc('0x41')][_0x3dfc('0xdb')]){_0x509012=_0x258c63[_0x3dfc('0x41')]['state'];return db['SmsMessage'][_0x3dfc('0x55')]({'where':{'messageId':_0x258c63['query']['message-id']}});}break;}}})[_0x3dfc('0x1d')](handleEntityNotFound(_0x12918f,null))[_0x3dfc('0x1d')](function(_0xe2b1f3){if(_0xe2b1f3){_0x21e64b=_0xe2b1f3;switch(_0x5f2719[_0x3dfc('0x3d')]){case _0x3dfc('0xd9'):if(_0x509012==='2'||_0x509012==='6'){return _0x21e64b[_0x3dfc('0xd1')]({'read':!![]});}else{logger[_0x3dfc('0x21')](_0x3dfc('0xb0'),_0x3dfc('0x28'),_0x3dfc('0xd9'),util[_0x3dfc('0xc9')](_0x258c63[_0x3dfc('0x41')],{'showHidden':![],'depth':null}));};break;}return _0x21e64b;}})[_0x3dfc('0x1d')](respondWithResult(_0x12918f,null))[_0x3dfc('0x26')](handleError(_0x12918f,null));};exports[_0x3dfc('0xdc')]=function(_0x3c5f98,_0x5456a8,_0x5e4107){return db[_0x3dfc('0x3b')][_0x3dfc('0x55')]({'where':{'id':_0x3c5f98[_0x3dfc('0x5f')]['id']}})[_0x3dfc('0x1d')](handleEntityNotFound(_0x5456a8,null))['then'](function(_0x3f802a){if(_0x3f802a){return _0x3f802a[_0x3dfc('0xdc')](_0x3c5f98[_0x3dfc('0x57')][_0x3dfc('0x67')],_['omit'](_0x3c5f98[_0x3dfc('0x57')],[_0x3dfc('0x67'),'id'])||{})[_0x3dfc('0xa0')](function(_0xbfbb7a){for(var _0x4c62b8=0x0;_0x4c62b8<_0x3c5f98[_0x3dfc('0x57')][_0x3dfc('0x67')][_0x3dfc('0x46')];_0x4c62b8+=0x1){socket[_0x3dfc('0xdd')](_0x3dfc('0xde'),{'UserId':Number(_0x3c5f98[_0x3dfc('0x57')][_0x3dfc('0x67')][_0x4c62b8]),'SmsAccountId':Number(_0x3c5f98[_0x3dfc('0x5f')]['id'])});}return _0xbfbb7a;});}})['then'](respondWithResult(_0x5456a8,null))[_0x3dfc('0x26')](handleError(_0x5456a8,null));};exports[_0x3dfc('0xdf')]=function(_0x4cc0b9,_0x553183,_0x3d68f3){return db[_0x3dfc('0x3b')][_0x3dfc('0x55')]({'where':{'id':_0x4cc0b9[_0x3dfc('0x5f')]['id']}})['then'](handleEntityNotFound(_0x553183,null))[_0x3dfc('0x1d')](function(_0x352811){if(_0x352811){return _0x352811[_0x3dfc('0xdf')](_0x4cc0b9['query'][_0x3dfc('0x67')])['then'](function(){if(_['isArray'](_0x4cc0b9[_0x3dfc('0x41')][_0x3dfc('0x67')])){for(var _0x3c3edb=0x0;_0x3c3edb<_0x4cc0b9[_0x3dfc('0x41')][_0x3dfc('0x67')]['length'];_0x3c3edb+=0x1){socket[_0x3dfc('0xdd')]('userSmsAccount:remove',{'UserId':Number(_0x4cc0b9[_0x3dfc('0x41')][_0x3dfc('0x67')][_0x3c3edb]),'SmsAccountId':Number(_0x4cc0b9[_0x3dfc('0x5f')]['id'])});}}else{socket[_0x3dfc('0xdd')]('userSmsAccount:remove',{'UserId':Number(_0x4cc0b9[_0x3dfc('0x41')][_0x3dfc('0x67')]),'SmsAccountId':Number(_0x4cc0b9[_0x3dfc('0x5f')]['id'])});}});}})[_0x3dfc('0x1d')](respondWithStatusCode(_0x553183,null))['catch'](handleError(_0x553183,null));};exports[_0x3dfc('0xe0')]=function(_0x2f8205,_0x166f28,_0x5d42db){var _0x34eed0={};var _0x5848f4={};var _0x37aee5;var _0x198093;return db[_0x3dfc('0x3b')][_0x3dfc('0x6b')]({'where':{'id':_0x2f8205[_0x3dfc('0x5f')]['id']}})[_0x3dfc('0x1d')](handleEntityNotFound(_0x166f28,null))[_0x3dfc('0x1d')](function(_0x162603){if(_0x162603){_0x37aee5=_0x162603;_0x5848f4[_0x3dfc('0x3f')]=_['keys'](db[_0x3dfc('0xa8')][_0x3dfc('0x3c')]);_0x5848f4[_0x3dfc('0x41')]=_['keys'](_0x2f8205[_0x3dfc('0x41')]);_0x5848f4[_0x3dfc('0x42')]=_[_0x3dfc('0x44')](_0x5848f4[_0x3dfc('0x3f')],_0x5848f4[_0x3dfc('0x41')]);_0x34eed0['attributes']=_[_0x3dfc('0x44')](_0x5848f4[_0x3dfc('0x3f')],qs[_0x3dfc('0x45')](_0x2f8205[_0x3dfc('0x41')]['fields']));_0x34eed0[_0x3dfc('0x43')]=_0x34eed0['attributes'][_0x3dfc('0x46')]?_0x34eed0['attributes']:_0x5848f4[_0x3dfc('0x3f')];_0x34eed0[_0x3dfc('0x49')]=qs[_0x3dfc('0x4a')](_0x2f8205[_0x3dfc('0x41')][_0x3dfc('0x4a')]);_0x34eed0['where']=qs[_0x3dfc('0x42')](_[_0x3dfc('0x4c')](_0x2f8205[_0x3dfc('0x41')],_0x5848f4[_0x3dfc('0x42')]));if(_0x2f8205[_0x3dfc('0x41')]['filter']){_0x34eed0[_0x3dfc('0x4b')]=_['merge'](_0x34eed0['where'],{'$or':_['map'](_0x34eed0['attributes'],function(_0x5c9e39){var _0x11767d={};_0x11767d[_0x5c9e39]={'$like':'%'+_0x2f8205[_0x3dfc('0x41')][_0x3dfc('0x4d')]+'%'};return _0x11767d;})});}_0x34eed0=_[_0x3dfc('0x4e')]({},_0x34eed0,_0x2f8205[_0x3dfc('0x6c')]);return _0x37aee5[_0x3dfc('0xe0')](_0x34eed0);}})[_0x3dfc('0x1d')](function(_0x4a5124){if(_0x4a5124){_0x198093=_0x4a5124[_0x3dfc('0x46')];if(!_0x2f8205[_0x3dfc('0x41')][_0x3dfc('0x47')](_0x3dfc('0x48'))){_0x34eed0[_0x3dfc('0x2c')]=qs[_0x3dfc('0x2c')](_0x2f8205[_0x3dfc('0x41')]['limit']);_0x34eed0['offset']=qs[_0x3dfc('0x2a')](_0x2f8205[_0x3dfc('0x41')][_0x3dfc('0x2a')]);}return _0x37aee5[_0x3dfc('0xe0')](_0x34eed0);}})[_0x3dfc('0x1d')](function(_0x427a86){if(_0x427a86){return _0x427a86?{'count':_0x198093,'rows':_0x427a86}:null;}})[_0x3dfc('0x1d')](respondWithResult(_0x166f28,null))[_0x3dfc('0x26')](handleError(_0x166f28,null));};
\ No newline at end of file