Built motion from commit 1fa89557.|2.6.10
[motion2.git] / server / api / smsAccount / smsAccount.controller.js
index 99626aa..e204c39 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xaf9e=['statusGet','message-id','state','addAgents','omit','emit','userSmsAccount:save','removeAgents','isArray','userSmsAccount:remove','getAgents','eml-format','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./smsAccount.socket','register','jayson/promise','request','then','info','request\x20sent','debug','stringify','error','code','SmsAccount,\x20%s,\x20%s','message','result','catch','sendStatus','status','end','undefined','count','offset','set','json','apply','reject','update','destroy','SmsAccounts','UserProfileResource','stack','name','send','index','mandatoryDispositionPause','map','type','key','query','keys','filters','intersection','attributes','fields','length','model','hasOwnProperty','nolimit','limit','order','pick','where','merge','filter','options','SmsAccount','includeAll','include','rows','show','params','Pause','find','create','user','get','role','UserProfileSection','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','describe','addDisposition','SmsAccountId','getDispositions','findOne','Disposition','rawAttributes','sort','findAll','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','removeAnswers','notify','sms','Applications','orderBy','asc','account','CmContact','Sequelize','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','ListId','twilio','From','Body','messageId','MessageSid','skebby','from','sender','connectel','message_id','plivo','Text','MessageUUID','infobip','results','text','csc','originatingAddress','segmentedMessage','fromNumber','replyMessageId','bandwidth','refid','isNil','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','CmList','Contacts','DESC','list','contact','SmsInteraction','spread','interaction','autoclose','push','applications','close','unmanaged','*,*,*,*','SmsMessage','ContactId','UserId','User','unshift','agent','startRouting','SmsAccount,\x20%s,\x20%s,\x20%s','entity\x20found','SmsAccount,\x20%s,\x20%s,\x20%s,\x20%s','Content-Type','text/xml','<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>','transaction','Transaction','ISOLATION_LEVELS','READ_COMMITTED','SmsApplication','findAndCountAll','priority','finally','getApplications','getInteractions','Contact','Owner','fullname','internal','Tags','color','tag','body\x20is\x20mandatory\x20and\x20not\x20empty','to\x20is\x20mandatory','List','out','Messages','dataValues','received\x20delivery\x20report\x20from','inspect','skebby_dispatch_id','requestid','statusInt','clicksend','status_code','groupName','DELIVERED','clickatell','intelepeer','redif','error_code','DELIVERED_TO_GATEWAY','RECEIVED_BY_RECIPIENT','message-delivered','DELIVRD','ACCEPTD'];(function(_0x3e44fa,_0x75ed2a){var _0x2a0aba=function(_0x1db6a7){while(--_0x1db6a7){_0x3e44fa['push'](_0x3e44fa['shift']());}};_0x2a0aba(++_0x75ed2a);}(_0xaf9e,0xf6));var _0xeaf9=function(_0x16f9be,_0x533f56){_0x16f9be=_0x16f9be-0x0;var _0x53706f=_0xaf9e[_0x16f9be];return _0x53706f;};'use strict';var emlformat=require(_0xeaf9('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0xeaf9('0x1'));var rp=require(_0xeaf9('0x2'));var moment=require(_0xeaf9('0x3'));var BPromise=require(_0xeaf9('0x4'));var Mustache=require(_0xeaf9('0x5'));var util=require(_0xeaf9('0x6'));var path=require(_0xeaf9('0x7'));var sox=require(_0xeaf9('0x8'));var csv=require(_0xeaf9('0x9'));var ejs=require(_0xeaf9('0xa'));var fs=require('fs');var fs_extra=require(_0xeaf9('0xb'));var _=require(_0xeaf9('0xc'));var squel=require('squel');var crypto=require(_0xeaf9('0xd'));var jsforce=require(_0xeaf9('0xe'));var deskjs=require('desk.js');var toCsv=require(_0xeaf9('0x9'));var querystring=require('querystring');var Papa=require(_0xeaf9('0xf'));var Redis=require(_0xeaf9('0x10'));var authService=require(_0xeaf9('0x11'));var qs=require(_0xeaf9('0x12'));var as=require(_0xeaf9('0x13'));var hardwareService=require(_0xeaf9('0x14'));var logger=require('../../config/logger')(_0xeaf9('0x15'));var utils=require(_0xeaf9('0x16'));var config=require(_0xeaf9('0x17'));var licenseUtil=require(_0xeaf9('0x18'));var db=require(_0xeaf9('0x19'))['db'];config[_0xeaf9('0x1a')]=_[_0xeaf9('0x1b')](config[_0xeaf9('0x1a')],{'host':_0xeaf9('0x1c'),'port':0x18eb});var socket=require(_0xeaf9('0x1d'))(new Redis(config['redis']));require(_0xeaf9('0x1e'))[_0xeaf9('0x1f')](socket);var jayson=require(_0xeaf9('0x20'));var client=jayson['client']['http']({'port':0x232c});function respondWithRpcPromise(_0x1cd1e2,_0x2369a3,_0x26e8c8,_0x45e811){return new BPromise(function(_0xd46ad9,_0x50c16c){var _0xcaa6da=_0x45e811||client;return _0xcaa6da[_0xeaf9('0x21')](_0x1cd1e2,_0x26e8c8)[_0xeaf9('0x22')](function(_0x3fad38){logger[_0xeaf9('0x23')]('SmsAccount,\x20%s,\x20%s',_0x2369a3,_0xeaf9('0x24'));logger[_0xeaf9('0x25')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x2369a3,_0xeaf9('0x24'),JSON[_0xeaf9('0x26')](_0x3fad38));if(_0x3fad38[_0xeaf9('0x27')]){if(_0x3fad38[_0xeaf9('0x27')][_0xeaf9('0x28')]===0x1f4){logger[_0xeaf9('0x27')](_0xeaf9('0x29'),_0x2369a3,_0x3fad38[_0xeaf9('0x27')][_0xeaf9('0x2a')]);return _0x50c16c(_0x3fad38['error']['message']);}logger['error'](_0xeaf9('0x29'),_0x2369a3,_0x3fad38[_0xeaf9('0x27')][_0xeaf9('0x2a')]);return _0xd46ad9(_0x3fad38[_0xeaf9('0x27')][_0xeaf9('0x2a')]);}else{logger['info'](_0xeaf9('0x29'),_0x2369a3,_0xeaf9('0x24'));_0xd46ad9(_0x3fad38[_0xeaf9('0x2b')][_0xeaf9('0x2a')]);}})[_0xeaf9('0x2c')](function(_0x426132){logger[_0xeaf9('0x27')](_0xeaf9('0x29'),_0x2369a3,_0x426132);_0x50c16c(_0x426132);});});}function respondWithStatusCode(_0xe20d4c,_0x2faae7){_0x2faae7=_0x2faae7||0xcc;return function(_0x39a4a4){if(_0x39a4a4){return _0xe20d4c[_0xeaf9('0x2d')](_0x2faae7);}return _0xe20d4c[_0xeaf9('0x2e')](_0x2faae7)[_0xeaf9('0x2f')]();};}function respondWithResult(_0x5115cd,_0x59e574){_0x59e574=_0x59e574||0xc8;return function(_0xcc159a){if(_0xcc159a){return _0x5115cd[_0xeaf9('0x2e')](_0x59e574)['json'](_0xcc159a);}};}function respondWithFilteredResult(_0x5d4fc7,_0xc64d8b){return function(_0x35da7f){if(_0x35da7f){var _0x425080=typeof _0xc64d8b['offset']===_0xeaf9('0x30')&&typeof _0xc64d8b['limit']===_0xeaf9('0x30');var _0xd38e35=_0x35da7f[_0xeaf9('0x31')];var _0x56fcc5=_0x425080?0x0:_0xc64d8b[_0xeaf9('0x32')];var _0x9b27c1=_0x425080?_0x35da7f[_0xeaf9('0x31')]:_0xc64d8b[_0xeaf9('0x32')]+_0xc64d8b['limit'];var _0xb5d6f6;if(_0x9b27c1>=_0xd38e35){_0x9b27c1=_0xd38e35;_0xb5d6f6=0xc8;}else{_0xb5d6f6=0xce;}_0x5d4fc7[_0xeaf9('0x2e')](_0xb5d6f6);return _0x5d4fc7[_0xeaf9('0x33')]('Content-Range',_0x56fcc5+'-'+_0x9b27c1+'/'+_0xd38e35)[_0xeaf9('0x34')](_0x35da7f);}return null;};}function patchUpdates(_0x2f8acf){return function(_0x14ed71){try{jsonpatch[_0xeaf9('0x35')](_0x14ed71,_0x2f8acf,!![]);}catch(_0xf71c22){return BPromise[_0xeaf9('0x36')](_0xf71c22);}return _0x14ed71['save']();};}function saveUpdates(_0x3fa079,_0x1de3a2){return function(_0x529364){if(_0x529364){return _0x529364[_0xeaf9('0x37')](_0x3fa079)[_0xeaf9('0x22')](function(_0x488fa8){return _0x488fa8;});}return null;};}function removeEntity(_0x4b14e4,_0x1c3459){return function(_0x2341fb){if(_0x2341fb){return _0x2341fb[_0xeaf9('0x38')]()['then'](function(){var _0x579c9b=_0x2341fb['get']({'plain':!![]});var _0x2f6a0b=_0xeaf9('0x39');return db[_0xeaf9('0x3a')][_0xeaf9('0x38')]({'where':{'type':_0x2f6a0b,'resourceId':_0x579c9b['id']}})[_0xeaf9('0x22')](function(){return _0x2341fb;});})[_0xeaf9('0x22')](function(){_0x4b14e4[_0xeaf9('0x2e')](0xcc)[_0xeaf9('0x2f')]();});}};}function handleEntityNotFound(_0xe74081,_0x21a55c){return function(_0x23bcae){if(!_0x23bcae){_0xe74081[_0xeaf9('0x2d')](0x194);}return _0x23bcae;};}function handleError(_0x270c7c,_0x430e87){_0x430e87=_0x430e87||0x1f4;return function(_0x5206ab){logger[_0xeaf9('0x27')](_0x5206ab[_0xeaf9('0x3b')]);if(_0x5206ab['name']){delete _0x5206ab[_0xeaf9('0x3c')];}_0x270c7c['status'](_0x430e87)[_0xeaf9('0x3d')](_0x5206ab);};}exports[_0xeaf9('0x3e')]=function(_0x4d36cc,_0x54771f){var _0x281a67={'include':[{'model':db['Pause'],'as':_0xeaf9('0x3f')}]},_0x2c0204={},_0x4bdcfd={'count':0x0,'rows':[]};var _0x3e430c=_[_0xeaf9('0x40')](db['SmsAccount']['rawAttributes'],function(_0x2237c8){return{'name':_0x2237c8['fieldName'],'type':_0x2237c8[_0xeaf9('0x41')][_0xeaf9('0x42')]};});_0x2c0204['model']=_['map'](_0x3e430c,'name');_0x2c0204[_0xeaf9('0x43')]=_[_0xeaf9('0x44')](_0x4d36cc[_0xeaf9('0x43')]);_0x2c0204[_0xeaf9('0x45')]=_[_0xeaf9('0x46')](_0x2c0204['model'],_0x2c0204[_0xeaf9('0x43')]);_0x281a67[_0xeaf9('0x47')]=_['intersection'](_0x2c0204['model'],qs[_0xeaf9('0x48')](_0x4d36cc[_0xeaf9('0x43')]['fields']));_0x281a67['attributes']=_0x281a67['attributes'][_0xeaf9('0x49')]?_0x281a67['attributes']:_0x2c0204[_0xeaf9('0x4a')];if(!_0x4d36cc[_0xeaf9('0x43')][_0xeaf9('0x4b')](_0xeaf9('0x4c'))){_0x281a67[_0xeaf9('0x4d')]=qs[_0xeaf9('0x4d')](_0x4d36cc['query'][_0xeaf9('0x4d')]);_0x281a67[_0xeaf9('0x32')]=qs['offset'](_0x4d36cc[_0xeaf9('0x43')][_0xeaf9('0x32')]);}_0x281a67[_0xeaf9('0x4e')]=qs['sort'](_0x4d36cc[_0xeaf9('0x43')]['sort']);_0x281a67['where']=qs[_0xeaf9('0x45')](_[_0xeaf9('0x4f')](_0x4d36cc[_0xeaf9('0x43')],_0x2c0204['filters']),_0x3e430c);if(_0x4d36cc[_0xeaf9('0x43')]['filter']){_0x281a67[_0xeaf9('0x50')]=_[_0xeaf9('0x51')](_0x281a67['where'],{'$or':_[_0xeaf9('0x40')](_0x3e430c,function(_0x4d9932){if(_0x4d9932[_0xeaf9('0x41')]!=='VIRTUAL'){var _0x1637fd={};_0x1637fd[_0x4d9932[_0xeaf9('0x3c')]]={'$like':'%'+_0x4d36cc[_0xeaf9('0x43')][_0xeaf9('0x52')]+'%'};return _0x1637fd;}})});}_0x281a67=_['merge']({},_0x281a67,_0x4d36cc[_0xeaf9('0x53')]);var _0x10ad12={'where':_0x281a67['where']};return db[_0xeaf9('0x54')]['count'](_0x10ad12)['then'](function(_0x1e4f10){_0x4bdcfd[_0xeaf9('0x31')]=_0x1e4f10;if(_0x4d36cc['query'][_0xeaf9('0x55')]){_0x281a67[_0xeaf9('0x56')]=[{'all':!![]}];}return db[_0xeaf9('0x54')]['findAll'](_0x281a67);})[_0xeaf9('0x22')](function(_0x44ed98){_0x4bdcfd[_0xeaf9('0x57')]=_0x44ed98;return _0x4bdcfd;})[_0xeaf9('0x22')](respondWithFilteredResult(_0x54771f,_0x281a67))[_0xeaf9('0x2c')](handleError(_0x54771f,null));};exports[_0xeaf9('0x58')]=function(_0x2a2265,_0x296ad2){var _0x4d9cde={'raw':![],'where':{'id':_0x2a2265[_0xeaf9('0x59')]['id']},'include':[{'model':db[_0xeaf9('0x5a')],'as':'mandatoryDispositionPause'}]},_0x57509c={};_0x57509c[_0xeaf9('0x4a')]=_[_0xeaf9('0x44')](db[_0xeaf9('0x54')]['rawAttributes']);_0x57509c['query']=_[_0xeaf9('0x44')](_0x2a2265[_0xeaf9('0x43')]);_0x57509c[_0xeaf9('0x45')]=_[_0xeaf9('0x46')](_0x57509c[_0xeaf9('0x4a')],_0x57509c[_0xeaf9('0x43')]);_0x4d9cde[_0xeaf9('0x47')]=_['intersection'](_0x57509c['model'],qs[_0xeaf9('0x48')](_0x2a2265[_0xeaf9('0x43')]['fields']));_0x4d9cde[_0xeaf9('0x47')]=_0x4d9cde['attributes']['length']?_0x4d9cde[_0xeaf9('0x47')]:_0x57509c['model'];if(_0x2a2265['query']['includeAll']){_0x4d9cde[_0xeaf9('0x56')]=[{'all':!![]}];}_0x4d9cde=_[_0xeaf9('0x51')]({},_0x4d9cde,_0x2a2265[_0xeaf9('0x53')]);return db['SmsAccount'][_0xeaf9('0x5b')](_0x4d9cde)[_0xeaf9('0x22')](handleEntityNotFound(_0x296ad2,null))[_0xeaf9('0x22')](respondWithResult(_0x296ad2,null))[_0xeaf9('0x2c')](handleError(_0x296ad2,null));};exports[_0xeaf9('0x5c')]=function(_0x524a50,_0xcf9b82){return db[_0xeaf9('0x54')][_0xeaf9('0x5c')](_0x524a50['body'],{})[_0xeaf9('0x22')](function(_0x11613c){var _0x2220d2=_0x524a50[_0xeaf9('0x5d')][_0xeaf9('0x5e')]({'plain':!![]});if(!_0x2220d2)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x2220d2[_0xeaf9('0x5f')]===_0xeaf9('0x5d')){var _0x2b6ec5=_0x11613c[_0xeaf9('0x5e')]({'plain':!![]});var _0x249794='SmsAccounts';return db[_0xeaf9('0x60')][_0xeaf9('0x5b')]({'where':{'name':_0x249794,'userProfileId':_0x2220d2['userProfileId']},'raw':!![]})['then'](function(_0x3efec5){if(_0x3efec5&&_0x3efec5[_0xeaf9('0x61')]===0x0){return db[_0xeaf9('0x3a')]['create']({'name':_0x2b6ec5[_0xeaf9('0x3c')],'resourceId':_0x2b6ec5['id'],'type':_0x3efec5['name'],'sectionId':_0x3efec5['id']},{})['then'](function(){return _0x11613c;});}else{return _0x11613c;}})[_0xeaf9('0x2c')](function(_0xfaaf04){logger['error'](_0xeaf9('0x62'),_0xfaaf04);throw _0xfaaf04;});}return _0x11613c;})['then'](respondWithResult(_0xcf9b82,0xc9))['catch'](handleError(_0xcf9b82,null));};exports[_0xeaf9('0x37')]=function(_0x5e1192,_0x1dfb28){if(_0x5e1192['body']['id']){delete _0x5e1192[_0xeaf9('0x63')]['id'];}return db['SmsAccount'][_0xeaf9('0x5b')]({'where':{'id':_0x5e1192['params']['id']},'include':[{'model':db['Pause'],'as':'mandatoryDispositionPause'}]})[_0xeaf9('0x22')](handleEntityNotFound(_0x1dfb28,null))[_0xeaf9('0x22')](saveUpdates(_0x5e1192['body'],null))[_0xeaf9('0x22')](respondWithResult(_0x1dfb28,null))[_0xeaf9('0x2c')](handleError(_0x1dfb28,null));};exports['destroy']=function(_0x55bbbf,_0x1e7a66){return db['SmsAccount'][_0xeaf9('0x5b')]({'where':{'id':_0x55bbbf[_0xeaf9('0x59')]['id']}})[_0xeaf9('0x22')](handleEntityNotFound(_0x1e7a66,null))['then'](removeEntity(_0x1e7a66,null))[_0xeaf9('0x2c')](handleError(_0x1e7a66,null));};exports['describe']=function(_0xf6755d,_0x3104f6){return db[_0xeaf9('0x54')][_0xeaf9('0x64')]()[_0xeaf9('0x22')](respondWithResult(_0x3104f6,null))[_0xeaf9('0x2c')](handleError(_0x3104f6,null));};exports[_0xeaf9('0x65')]=function(_0x21c62d,_0x19378f,_0x255afb){if(_0x21c62d[_0xeaf9('0x63')]['id']){delete _0x21c62d[_0xeaf9('0x63')]['id'];}return db['SmsAccount'][_0xeaf9('0x5b')]({'where':{'id':_0x21c62d[_0xeaf9('0x59')]['id']}})['then'](handleEntityNotFound(_0x19378f,null))[_0xeaf9('0x22')](function(_0x5b965b){if(_0x5b965b){_0x21c62d[_0xeaf9('0x63')][_0xeaf9('0x66')]=_0x5b965b['id'];return db['Disposition'][_0xeaf9('0x5c')](_0x21c62d[_0xeaf9('0x63')]);}})[_0xeaf9('0x22')](respondWithResult(_0x19378f,null))[_0xeaf9('0x2c')](handleError(_0x19378f,null));};exports[_0xeaf9('0x67')]=function(_0x1f2586,_0x1c80a7,_0x2287c6){var _0x5df70d={'raw':![],'where':{}};var _0x1e662a={};var _0x590e3e={'count':0x0,'rows':[]};return db[_0xeaf9('0x54')][_0xeaf9('0x68')]({'where':{'id':_0x1f2586[_0xeaf9('0x59')]['id']}})[_0xeaf9('0x22')](handleEntityNotFound(_0x1c80a7,null))[_0xeaf9('0x22')](function(_0x354eb1){if(_0x354eb1){_0x1e662a[_0xeaf9('0x4a')]=_['keys'](db[_0xeaf9('0x69')][_0xeaf9('0x6a')]);_0x1e662a[_0xeaf9('0x43')]=_[_0xeaf9('0x44')](_0x1f2586['query']);_0x1e662a['filters']=_[_0xeaf9('0x46')](_0x1e662a['model'],_0x1e662a['query']);_0x5df70d[_0xeaf9('0x47')]=_[_0xeaf9('0x46')](_0x1e662a[_0xeaf9('0x4a')],qs['fields'](_0x1f2586[_0xeaf9('0x43')]['fields']));_0x5df70d[_0xeaf9('0x47')]=_0x5df70d[_0xeaf9('0x47')][_0xeaf9('0x49')]?_0x5df70d[_0xeaf9('0x47')]:_0x1e662a['model'];if(!_0x1f2586[_0xeaf9('0x43')][_0xeaf9('0x4b')]('nolimit')){_0x5df70d['limit']=qs[_0xeaf9('0x4d')](_0x1f2586[_0xeaf9('0x43')][_0xeaf9('0x4d')]);_0x5df70d[_0xeaf9('0x32')]=qs[_0xeaf9('0x32')](_0x1f2586['query'][_0xeaf9('0x32')]);}_0x5df70d['order']=qs['sort'](_0x1f2586[_0xeaf9('0x43')][_0xeaf9('0x6b')]);_0x5df70d[_0xeaf9('0x50')]=qs[_0xeaf9('0x45')](_[_0xeaf9('0x4f')](_0x1f2586['query'],_0x1e662a[_0xeaf9('0x45')]));_0x5df70d[_0xeaf9('0x50')]['SmsAccountId']=_0x354eb1['id'];if(_0x1f2586[_0xeaf9('0x43')][_0xeaf9('0x52')]){_0x5df70d[_0xeaf9('0x50')]=_[_0xeaf9('0x51')](_0x5df70d[_0xeaf9('0x50')],{'$or':_['map'](_0x5df70d[_0xeaf9('0x47')],function(_0x1dd9b1){var _0x541f91={};_0x541f91[_0x1dd9b1]={'$like':'%'+_0x1f2586[_0xeaf9('0x43')][_0xeaf9('0x52')]+'%'};return _0x541f91;})});}_0x5df70d=_[_0xeaf9('0x51')]({},_0x5df70d,_0x1f2586['options']);return db[_0xeaf9('0x69')][_0xeaf9('0x31')]({'where':_0x5df70d[_0xeaf9('0x50')]})[_0xeaf9('0x22')](function(_0x5aa746){_0x590e3e[_0xeaf9('0x31')]=_0x5aa746;if(_0x1f2586[_0xeaf9('0x43')]['includeAll']){_0x5df70d[_0xeaf9('0x56')]=[{'all':!![]}];}return db[_0xeaf9('0x69')][_0xeaf9('0x6c')](_0x5df70d);})[_0xeaf9('0x22')](function(_0x2fa565){_0x590e3e[_0xeaf9('0x57')]=_0x2fa565;return _0x590e3e;});}})['then'](respondWithFilteredResult(_0x1c80a7,_0x5df70d))[_0xeaf9('0x2c')](handleError(_0x1c80a7,null));};exports[_0xeaf9('0x6d')]=function(_0x11fd9d,_0x55d84f,_0x2a1e90){return db['SmsAccount'][_0xeaf9('0x5b')]({'where':{'id':_0x11fd9d[_0xeaf9('0x59')]['id']}})[_0xeaf9('0x22')](handleEntityNotFound(_0x55d84f,null))[_0xeaf9('0x22')](function(_0x4f6fea){if(_0x4f6fea){return _0x4f6fea[_0xeaf9('0x6d')](_0x11fd9d[_0xeaf9('0x43')][_0xeaf9('0x6e')]);}})[_0xeaf9('0x22')](respondWithStatusCode(_0x55d84f,null))['catch'](handleError(_0x55d84f,null));};exports[_0xeaf9('0x6f')]=function(_0x2f5d18,_0x1ad516,_0x372f2b){if(_0x2f5d18[_0xeaf9('0x63')]['id']){delete _0x2f5d18[_0xeaf9('0x63')]['id'];}return db['SmsAccount'][_0xeaf9('0x5b')]({'where':{'id':_0x2f5d18[_0xeaf9('0x59')]['id']}})['then'](handleEntityNotFound(_0x1ad516,null))['then'](function(_0x2e6ec6){if(_0x2e6ec6){_0x2f5d18['body']['SmsAccountId']=_0x2e6ec6['id'];return db[_0xeaf9('0x70')]['create'](_0x2f5d18[_0xeaf9('0x63')]);}})[_0xeaf9('0x22')](respondWithResult(_0x1ad516,null))['catch'](handleError(_0x1ad516,null));};exports[_0xeaf9('0x71')]=function(_0x15f8e3,_0xce72b1,_0x45e8ea){var _0x4bf03f={'raw':![],'where':{}};var _0x49b162={};var _0x11a1b7={'count':0x0,'rows':[]};return db['SmsAccount'][_0xeaf9('0x68')]({'where':{'id':_0x15f8e3[_0xeaf9('0x59')]['id']}})[_0xeaf9('0x22')](handleEntityNotFound(_0xce72b1,null))[_0xeaf9('0x22')](function(_0x16bdd5){if(_0x16bdd5){_0x49b162['model']=_[_0xeaf9('0x44')](db['CannedAnswer'][_0xeaf9('0x6a')]);_0x49b162['query']=_['keys'](_0x15f8e3['query']);_0x49b162[_0xeaf9('0x45')]=_[_0xeaf9('0x46')](_0x49b162['model'],_0x49b162[_0xeaf9('0x43')]);_0x4bf03f['attributes']=_[_0xeaf9('0x46')](_0x49b162[_0xeaf9('0x4a')],qs[_0xeaf9('0x48')](_0x15f8e3[_0xeaf9('0x43')]['fields']));_0x4bf03f['attributes']=_0x4bf03f['attributes'][_0xeaf9('0x49')]?_0x4bf03f[_0xeaf9('0x47')]:_0x49b162[_0xeaf9('0x4a')];if(!_0x15f8e3[_0xeaf9('0x43')][_0xeaf9('0x4b')](_0xeaf9('0x4c'))){_0x4bf03f[_0xeaf9('0x4d')]=qs['limit'](_0x15f8e3[_0xeaf9('0x43')][_0xeaf9('0x4d')]);_0x4bf03f['offset']=qs['offset'](_0x15f8e3[_0xeaf9('0x43')][_0xeaf9('0x32')]);}_0x4bf03f[_0xeaf9('0x4e')]=qs['sort'](_0x15f8e3[_0xeaf9('0x43')][_0xeaf9('0x6b')]);_0x4bf03f[_0xeaf9('0x50')]=qs[_0xeaf9('0x45')](_[_0xeaf9('0x4f')](_0x15f8e3[_0xeaf9('0x43')],_0x49b162[_0xeaf9('0x45')]));_0x4bf03f[_0xeaf9('0x50')]['SmsAccountId']=_0x16bdd5['id'];if(_0x15f8e3['query']['filter']){_0x4bf03f['where']=_['merge'](_0x4bf03f[_0xeaf9('0x50')],{'$or':_[_0xeaf9('0x40')](_0x4bf03f[_0xeaf9('0x47')],function(_0x530c47){var _0x5808aa={};_0x5808aa[_0x530c47]={'$like':'%'+_0x15f8e3[_0xeaf9('0x43')][_0xeaf9('0x52')]+'%'};return _0x5808aa;})});}_0x4bf03f=_[_0xeaf9('0x51')]({},_0x4bf03f,_0x15f8e3[_0xeaf9('0x53')]);return db['CannedAnswer'][_0xeaf9('0x31')]({'where':_0x4bf03f[_0xeaf9('0x50')]})[_0xeaf9('0x22')](function(_0x3cd485){_0x11a1b7[_0xeaf9('0x31')]=_0x3cd485;if(_0x15f8e3[_0xeaf9('0x43')][_0xeaf9('0x55')]){_0x4bf03f[_0xeaf9('0x56')]=[{'all':!![]}];}return db[_0xeaf9('0x70')][_0xeaf9('0x6c')](_0x4bf03f);})[_0xeaf9('0x22')](function(_0x20125c){_0x11a1b7['rows']=_0x20125c;return _0x11a1b7;});}})[_0xeaf9('0x22')](respondWithFilteredResult(_0xce72b1,_0x4bf03f))[_0xeaf9('0x2c')](handleError(_0xce72b1,null));};exports[_0xeaf9('0x72')]=function(_0x4d5340,_0x389e10,_0x510893){return db['SmsAccount'][_0xeaf9('0x5b')]({'where':{'id':_0x4d5340['params']['id']}})[_0xeaf9('0x22')](handleEntityNotFound(_0x389e10,null))[_0xeaf9('0x22')](function(_0x47ce3c){if(_0x47ce3c){return _0x47ce3c[_0xeaf9('0x72')](_0x4d5340[_0xeaf9('0x43')]['ids']);}})['then'](respondWithStatusCode(_0x389e10,null))[_0xeaf9('0x2c')](handleError(_0x389e10,null));};exports[_0xeaf9('0x73')]=function(_0x45272a,_0x48f789,_0x1dc012){var _0x54a4ec={'channel':_0xeaf9('0x74')};var _0xbab89f=[];var _0x1595fd=[];var _0x501ab4={};return db['SmsAccount']['find']({'where':{'id':_0x45272a[_0xeaf9('0x59')]['id']},'include':[{'model':db['SmsApplication'],'as':_0xeaf9('0x75')}]})[_0xeaf9('0x22')](handleEntityNotFound(_0x48f789,null))[_0xeaf9('0x22')](function(_0x1959d4){_0x54a4ec['account']=_0x1959d4;_0x54a4ec['applications']=_[_0xeaf9('0x76')](_0x1959d4[_0xeaf9('0x75')],['priority'],[_0xeaf9('0x77')]);if(_0x54a4ec[_0xeaf9('0x78')][_0xeaf9('0x75')]){delete _0x54a4ec[_0xeaf9('0x78')][_0xeaf9('0x75')];}return db[_0xeaf9('0x79')]['describe']();})[_0xeaf9('0x22')](function(_0x43d822){if(!_0x43d822){throw new db[(_0xeaf9('0x7a'))][(_0xeaf9('0x7b'))](_0xeaf9('0x7c'));}_0xbab89f=_[_0xeaf9('0x7d')](_[_0xeaf9('0x44')](_0x43d822),[_0xeaf9('0x7e'),_0xeaf9('0x7f')]);_0x1595fd=_[_0xeaf9('0x7d')](_[_0xeaf9('0x44')](_0x43d822),['createdAt','updatedAt','CompanyId',_0xeaf9('0x80')]);_0x54a4ec[_0xeaf9('0x63')]={'mapKey':'mobile'};if(_0x54a4ec[_0xeaf9('0x78')]['type']){switch(_0x54a4ec[_0xeaf9('0x78')][_0xeaf9('0x41')]){case _0xeaf9('0x81'):_0x54a4ec[_0xeaf9('0x63')]['from']=_0x45272a[_0xeaf9('0x63')][_0xeaf9('0x82')];_0x54a4ec['body'][_0xeaf9('0x63')]=_0x45272a[_0xeaf9('0x63')][_0xeaf9('0x83')];_0x54a4ec['body'][_0xeaf9('0x84')]=_0x45272a[_0xeaf9('0x63')][_0xeaf9('0x85')];break;case _0xeaf9('0x86'):_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x87')]='+'+_0x45272a[_0xeaf9('0x63')][_0xeaf9('0x88')];_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x63')]=_0x45272a[_0xeaf9('0x63')]['text'];break;case _0xeaf9('0x89'):_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x87')]=_0x45272a['body'][_0xeaf9('0x87')];_0x54a4ec[_0xeaf9('0x63')]['body']=_0x45272a[_0xeaf9('0x63')][_0xeaf9('0x2a')];break;case'clicksend':_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x87')]=_0x45272a['body']['from'];_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x63')]=_0x45272a[_0xeaf9('0x63')][_0xeaf9('0x63')];_0x54a4ec[_0xeaf9('0x63')]['messageId']=_0x45272a[_0xeaf9('0x63')][_0xeaf9('0x8a')];break;case _0xeaf9('0x8b'):_0x54a4ec['body'][_0xeaf9('0x87')]=_0x45272a['body'][_0xeaf9('0x82')];_0x54a4ec['body'][_0xeaf9('0x63')]=_0x45272a[_0xeaf9('0x63')][_0xeaf9('0x8c')];_0x54a4ec[_0xeaf9('0x63')]['messageId']=_0x45272a[_0xeaf9('0x63')][_0xeaf9('0x8d')];break;case _0xeaf9('0x8e'):_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x87')]='+'+_0x45272a[_0xeaf9('0x63')][_0xeaf9('0x8f')][0x0][_0xeaf9('0x87')];_0x54a4ec[_0xeaf9('0x63')]['body']=_0x45272a[_0xeaf9('0x63')][_0xeaf9('0x8f')][0x0][_0xeaf9('0x90')];_0x54a4ec['body'][_0xeaf9('0x84')]=_0x45272a['body'][_0xeaf9('0x8f')][0x0][_0xeaf9('0x84')];break;case _0xeaf9('0x91'):_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x87')]=_0x45272a['body'][_0xeaf9('0x92')];_0x54a4ec['body'][_0xeaf9('0x63')]=_0x45272a['body'][_0xeaf9('0x93')]['message'];break;case'clickatell':_0x54a4ec[_0xeaf9('0x63')]['from']=_0x45272a[_0xeaf9('0x63')][_0xeaf9('0x94')];_0x54a4ec['body'][_0xeaf9('0x63')]=_0x45272a[_0xeaf9('0x63')]['text'];_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x84')]=_0x45272a['body'][_0xeaf9('0x95')];break;case _0xeaf9('0x96'):_0x54a4ec[_0xeaf9('0x63')]['messageId']=_0x45272a['body'][0x0][_0xeaf9('0x2a')]['id'];_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x87')]=_0x45272a['body'][0x0][_0xeaf9('0x2a')][_0xeaf9('0x87')];_0x54a4ec['body']['body']=_0x45272a[_0xeaf9('0x63')][0x0][_0xeaf9('0x2a')][_0xeaf9('0x90')];break;case'intelepeer':_0x54a4ec[_0xeaf9('0x63')]['from']=_0x45272a['body']['from'];_0x54a4ec[_0xeaf9('0x63')]['body']=_0x45272a[_0xeaf9('0x63')]['message'];_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x84')]=_0x45272a['body'][_0xeaf9('0x97')];break;}}if(_0x54a4ec[_0xeaf9('0x63')]['id']){delete _0x54a4ec[_0xeaf9('0x63')]['id'];}if(_[_0xeaf9('0x98')](_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x87')])){throw new db[(_0xeaf9('0x7a'))]['ValidationError']('from\x20is\x20mandatory');}if(_[_0xeaf9('0x98')](_0x54a4ec['body'][_0xeaf9('0x63')])||_0x54a4ec[_0xeaf9('0x63')]['body']===''){throw new db[(_0xeaf9('0x7a'))]['ValidationError']('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0xeaf9('0x98')](_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x99')])){throw new db[(_0xeaf9('0x7a'))][(_0xeaf9('0x7b'))](_0xeaf9('0x9a')+_0x1595fd);}if(!_[_0xeaf9('0x9b')](_0x1595fd,_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x99')])){throw new db[(_0xeaf9('0x7a'))][(_0xeaf9('0x7b'))]('mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x1595fd);}_0x501ab4[_0x54a4ec[_0xeaf9('0x63')]['mapKey']]=_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x87')];return db[_0xeaf9('0x9c')]['find']({'where':{'id':_0x54a4ec[_0xeaf9('0x78')][_0xeaf9('0x80')]},'include':[{'model':db[_0xeaf9('0x79')],'as':_0xeaf9('0x9d'),'where':_0x501ab4,'limit':0x1,'order':[[_0xeaf9('0x7f'),_0xeaf9('0x9e')]]}]});})[_0xeaf9('0x22')](handleEntityNotFound(_0x48f789,null))[_0xeaf9('0x22')](function(_0x1d49df){if(_0x1d49df){_0x54a4ec[_0xeaf9('0x9f')]=_['omit'](_0x1d49df,['Contacts']);if(_0x1d49df['Contacts'][_0xeaf9('0x49')]){return _0x1d49df[_0xeaf9('0x9d')][0x0];}var _0x3f3c79=_[_0xeaf9('0x1b')](_0x54a4ec[_0xeaf9('0x63')],{'firstName':_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x87')],'ListId':_0x1d49df['id']});_0x3f3c79[_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x99')]]=_0x54a4ec[_0xeaf9('0x63')]['from'];return db[_0xeaf9('0x79')][_0xeaf9('0x5c')](_0x3f3c79,{'fields':_0xbab89f,'raw':!![]});}})[_0xeaf9('0x22')](handleEntityNotFound(_0x48f789,null))[_0xeaf9('0x22')](function(_0x56c854){if(_0x56c854){_0x54a4ec[_0xeaf9('0xa0')]=_0x56c854;var _0x25637e={'ContactId':_0x56c854['id'],'phone':_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x87')],'SmsAccountId':_0x45272a['params']['id']};var _0x79ef0a={'ContactId':_0x56c854['id'],'SmsAccountId':_0x45272a[_0xeaf9('0x59')]['id'],'closed':![]};return db[_0xeaf9('0xa1')]['find']({'where':_0x79ef0a})['then'](function(_0x4bfe01){if(_0x4bfe01){return[_0x4bfe01,![]];}return db['SmsInteraction'][_0xeaf9('0x5c')](_0x25637e)['then'](function(_0x59ca51){return[_0x59ca51,!![]];});});}})[_0xeaf9('0xa2')](function(_0x4527ce,_0x71ad6e){_0x54a4ec[_0xeaf9('0xa3')]=_0x4527ce[_0xeaf9('0x5e')]({'plain':!![]});_0x54a4ec['interaction']['created']=![];if(_0x71ad6e){if(_0x54a4ec['account'][_0xeaf9('0xa4')]){_0x54a4ec['applications'][_0xeaf9('0xa5')]({'id':0x0,'priority':_0x54a4ec[_0xeaf9('0xa6')][_0xeaf9('0x49')]+0x1,'app':_0xeaf9('0xa7'),'appdata':_0xeaf9('0xa8'),'interval':_0xeaf9('0xa9')});}_0x54a4ec[_0xeaf9('0xa3')]['created']=!![];}return db[_0xeaf9('0xaa')][_0xeaf9('0x5c')]({'phone':_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x87')],'messageId':_0x54a4ec['body'][_0xeaf9('0x84')],'body':_0x54a4ec['body'][_0xeaf9('0x63')],'SmsAccountId':_0x45272a['params']['id'],'SmsInteractionId':_0x4527ce['id'],'direction':'in','ContactId':_0x4527ce[_0xeaf9('0xab')],'AttachmentId':_0x54a4ec['body']['AttachmentId']});})['then'](function(_0x56fca0){_0x54a4ec[_0xeaf9('0x2a')]=_0x56fca0;if(_0x54a4ec[_0xeaf9('0xa3')][_0xeaf9('0xac')]){return db[_0xeaf9('0xad')][_0xeaf9('0x5b')]({'attributes':['id',_0xeaf9('0x3c')],'where':{'id':_0x54a4ec[_0xeaf9('0xa3')][_0xeaf9('0xac')]}})[_0xeaf9('0x22')](function(_0x2dd97e){if(_0x2dd97e){_0x54a4ec['applications'][_0xeaf9('0xae')]({'id':0x0,'priority':0x0,'app':_0xeaf9('0xaf'),'appdata':_0x2dd97e['name']+','+(_0x54a4ec[_0xeaf9('0x78')]['waitForTheAssignedAgent']||0xa),'interval':_0xeaf9('0xa9')});}return respondWithRpcPromise('Start','startRouting',_0x54a4ec);});}return respondWithRpcPromise('Start',_0xeaf9('0xb0'),_0x54a4ec);})[_0xeaf9('0x22')](function(_0x4de8a0){if(_0x4de8a0){var _0x396706=0xc8;var _0x52a698='receiveMessage';logger[_0xeaf9('0x23')](_0xeaf9('0xb1'),_0x52a698,_0x396706,_0xeaf9('0xb2'));logger['debug'](_0xeaf9('0xb3'),_0x52a698,_0x396706,_0xeaf9('0xb2'),JSON[_0xeaf9('0x26')](_0x4de8a0));if(_0x54a4ec['account'][_0xeaf9('0x41')]===_0xeaf9('0x81')){return _0x48f789[_0xeaf9('0x2e')](_0x396706)[_0xeaf9('0x33')](_0xeaf9('0xb4'),_0xeaf9('0xb5'))[_0xeaf9('0x3d')](_0xeaf9('0xb6'));}else{return _0x48f789['status'](_0x396706)[_0xeaf9('0x34')](_0x4de8a0);}}})[_0xeaf9('0x2c')](handleError(_0x48f789,null));};exports['addApplications']=function(_0x4e7271,_0x24e165){var _0x74c094=_0x4e7271[_0xeaf9('0x59')]['id'];var _0x33fd6a=_0x4e7271[_0xeaf9('0x63')];var _0x3c0b8f=0xc8;var _0x4a6347=null;return db['sequelize'][_0xeaf9('0xb7')]({'isolationLevel':db['sequelize'][_0xeaf9('0xb8')][_0xeaf9('0xb9')][_0xeaf9('0xba')]},function(_0x120b10){return db[_0xeaf9('0x54')][_0xeaf9('0x68')]({'where':{'id':_0x74c094},'transaction':_0x120b10})[_0xeaf9('0x22')](function(_0x2050d7){if(_0x2050d7){return db[_0xeaf9('0xbb')][_0xeaf9('0x38')]({'where':{'SmsAccountId':_0x74c094},'transaction':_0x120b10})[_0xeaf9('0x22')](function(){var _0x4001ac=_[_0xeaf9('0x40')](_0x33fd6a,function(_0x26275d){_0x26275d[_0xeaf9('0x66')]=_0x74c094;return _0x26275d;});return db[_0xeaf9('0xbb')]['bulkCreate'](_0x4001ac,{'transaction':_0x120b10});});}else{_0x3c0b8f=0x194;_0x4a6347=[];}});})[_0xeaf9('0x22')](function(){if(_0x3c0b8f!==0x194){return db['SmsApplication'][_0xeaf9('0xbc')]({'where':{'SmsAccountId':_0x74c094},'order':_0xeaf9('0xbd')})[_0xeaf9('0x22')](function(_0x4d350d){_0x4a6347=_0x4d350d;});}})['catch'](function(_0x1b41f9){_0x3c0b8f=0x1f4;logger[_0xeaf9('0x27')](_0x1b41f9[_0xeaf9('0x3b')]);if(_0x1b41f9[_0xeaf9('0x3c')]){delete _0x1b41f9[_0xeaf9('0x3c')];}_0x4a6347=_0x1b41f9;})[_0xeaf9('0xbe')](function(){if(_0x4a6347===null){_0x24e165['sendStatus'](_0x3c0b8f);}else{if(_0x3c0b8f===0x1f4){_0x24e165[_0xeaf9('0x2e')](_0x3c0b8f)[_0xeaf9('0x3d')](_0x4a6347);}else{_0x24e165[_0xeaf9('0x2e')](_0x3c0b8f)[_0xeaf9('0x34')](_0x4a6347);}}});};exports['getApplications']=function(_0x44af0f,_0x1b2097,_0xe48055){var _0xc69d84={};var _0x41d6fe={};var _0x4be25a;var _0x2fad53;return db[_0xeaf9('0x54')][_0xeaf9('0x68')]({'where':{'id':_0x44af0f[_0xeaf9('0x59')]['id']}})[_0xeaf9('0x22')](handleEntityNotFound(_0x1b2097,null))[_0xeaf9('0x22')](function(_0x4d757f){if(_0x4d757f){_0x4be25a=_0x4d757f;_0x41d6fe[_0xeaf9('0x4a')]=_['keys'](db[_0xeaf9('0xbb')]['rawAttributes']);_0x41d6fe[_0xeaf9('0x43')]=_[_0xeaf9('0x44')](_0x44af0f[_0xeaf9('0x43')]);_0x41d6fe[_0xeaf9('0x45')]=_['intersection'](_0x41d6fe[_0xeaf9('0x4a')],_0x41d6fe[_0xeaf9('0x43')]);_0xc69d84[_0xeaf9('0x47')]=_['intersection'](_0x41d6fe[_0xeaf9('0x4a')],qs['fields'](_0x44af0f['query'][_0xeaf9('0x48')]));_0xc69d84['attributes']=_0xc69d84[_0xeaf9('0x47')][_0xeaf9('0x49')]?_0xc69d84[_0xeaf9('0x47')]:_0x41d6fe[_0xeaf9('0x4a')];_0xc69d84['order']=qs[_0xeaf9('0x6b')](_0x44af0f[_0xeaf9('0x43')]['sort']);_0xc69d84['where']=qs['filters'](_['pick'](_0x44af0f[_0xeaf9('0x43')],_0x41d6fe[_0xeaf9('0x45')]));if(_0x44af0f[_0xeaf9('0x43')]['filter']){_0xc69d84[_0xeaf9('0x50')]=_['merge'](_0xc69d84[_0xeaf9('0x50')],{'$or':_['map'](_0xc69d84[_0xeaf9('0x47')],function(_0x1c4a0e){var _0x385a93={};_0x385a93[_0x1c4a0e]={'$like':'%'+_0x44af0f['query'][_0xeaf9('0x52')]+'%'};return _0x385a93;})});}_0xc69d84=_[_0xeaf9('0x51')]({},_0xc69d84,_0x44af0f[_0xeaf9('0x53')]);return _0x4be25a['getApplications'](_0xc69d84);}})[_0xeaf9('0x22')](function(_0x509ccb){if(_0x509ccb){_0x2fad53=_0x509ccb[_0xeaf9('0x49')];if(!_0x44af0f[_0xeaf9('0x43')][_0xeaf9('0x4b')](_0xeaf9('0x4c'))){_0xc69d84['limit']=qs[_0xeaf9('0x4d')](_0x44af0f[_0xeaf9('0x43')]['limit']);_0xc69d84[_0xeaf9('0x32')]=qs[_0xeaf9('0x32')](_0x44af0f[_0xeaf9('0x43')][_0xeaf9('0x32')]);}return _0x4be25a[_0xeaf9('0xbf')](_0xc69d84);}})[_0xeaf9('0x22')](function(_0x4f890b){if(_0x4f890b){return _0x4f890b?{'count':_0x2fad53,'rows':_0x4f890b}:null;}})[_0xeaf9('0x22')](respondWithResult(_0x1b2097,null))[_0xeaf9('0x2c')](handleError(_0x1b2097,null));};exports[_0xeaf9('0xc0')]=function(_0x43de75,_0x54ca87,_0x38c8a0){var _0x2c0dfe={'raw':![],'where':{}};var _0x25617c={};var _0x33a97a={'count':0x0,'rows':[]};return db[_0xeaf9('0x54')][_0xeaf9('0x68')]({'where':{'id':_0x43de75[_0xeaf9('0x59')]['id']}})[_0xeaf9('0x22')](handleEntityNotFound(_0x54ca87,null))[_0xeaf9('0x22')](function(_0x37ae4d){if(_0x37ae4d){_0x25617c[_0xeaf9('0x4a')]=_[_0xeaf9('0x44')](db['SmsInteraction']['rawAttributes']);_0x25617c[_0xeaf9('0x43')]=_[_0xeaf9('0x44')](_0x43de75[_0xeaf9('0x43')]);_0x25617c['filters']=_[_0xeaf9('0x46')](_0x25617c[_0xeaf9('0x4a')],_0x25617c[_0xeaf9('0x43')]);_0x2c0dfe[_0xeaf9('0x47')]=_[_0xeaf9('0x46')](_0x25617c[_0xeaf9('0x4a')],qs[_0xeaf9('0x48')](_0x43de75[_0xeaf9('0x43')][_0xeaf9('0x48')]));_0x2c0dfe[_0xeaf9('0x47')]=_0x2c0dfe['attributes'][_0xeaf9('0x49')]?_0x2c0dfe[_0xeaf9('0x47')]:_0x25617c[_0xeaf9('0x4a')];if(!_0x43de75['query']['hasOwnProperty'](_0xeaf9('0x4c'))){_0x2c0dfe['limit']=qs[_0xeaf9('0x4d')](_0x43de75[_0xeaf9('0x43')][_0xeaf9('0x4d')]);_0x2c0dfe[_0xeaf9('0x32')]=qs[_0xeaf9('0x32')](_0x43de75[_0xeaf9('0x43')]['offset']);}_0x2c0dfe[_0xeaf9('0x4e')]=qs[_0xeaf9('0x6b')](_0x43de75[_0xeaf9('0x43')][_0xeaf9('0x6b')]);_0x2c0dfe[_0xeaf9('0x50')]=qs[_0xeaf9('0x45')](_[_0xeaf9('0x4f')](_0x43de75[_0xeaf9('0x43')],_0x25617c[_0xeaf9('0x45')]));_0x2c0dfe['where'][_0xeaf9('0x66')]=_0x37ae4d['id'];if(_0x43de75[_0xeaf9('0x43')]['filter']){_0x2c0dfe[_0xeaf9('0x50')]=_['merge'](_0x2c0dfe[_0xeaf9('0x50')],{'$or':_['map'](_0x2c0dfe['attributes'],function(_0x1b99b9){var _0x292d2a={};_0x292d2a[_0x1b99b9]={'$like':'%'+_0x43de75[_0xeaf9('0x43')][_0xeaf9('0x52')]+'%'};return _0x292d2a;})});}_0x2c0dfe=_[_0xeaf9('0x51')]({},_0x2c0dfe,_0x43de75['options']);return db[_0xeaf9('0xa1')]['count']({'where':_0x2c0dfe[_0xeaf9('0x50')]})[_0xeaf9('0x22')](function(_0x1aea70){_0x33a97a[_0xeaf9('0x31')]=_0x1aea70;if(_0x43de75[_0xeaf9('0x43')][_0xeaf9('0x55')]){_0x2c0dfe[_0xeaf9('0x56')]=[{'model':db['CmContact'],'as':_0xeaf9('0xc1'),'required':![]},{'model':db[_0xeaf9('0xad')],'as':_0xeaf9('0xc2'),'attributes':[_0xeaf9('0x3c'),_0xeaf9('0xc3'),_0xeaf9('0xc4')],'required':![]},{'model':db['Tag'],'as':_0xeaf9('0xc5'),'attributes':['id','name',_0xeaf9('0xc6')],'where':_0x43de75[_0xeaf9('0x43')][_0xeaf9('0xc7')]?{'id':_0x43de75[_0xeaf9('0x43')]['tag']}:undefined,'required':_0x43de75[_0xeaf9('0x43')][_0xeaf9('0xc7')]?!![]:![]}];}return db[_0xeaf9('0xa1')]['findAll'](_0x2c0dfe);})[_0xeaf9('0x22')](function(_0x3417ed){_0x33a97a['rows']=_0x3417ed;return _0x33a97a;});}})['then'](respondWithFilteredResult(_0x54ca87,_0x2c0dfe))[_0xeaf9('0x2c')](handleError(_0x54ca87,null));};exports[_0xeaf9('0x3d')]=function(_0x59f650,_0x312e79,_0x387805){var _0x1392cc,_0x16b026,_0x9d1728;if(_[_0xeaf9('0x98')](_0x59f650[_0xeaf9('0x63')][_0xeaf9('0x63')])||_0x59f650[_0xeaf9('0x63')][_0xeaf9('0x63')]===''){throw new db[(_0xeaf9('0x7a'))][(_0xeaf9('0x7b'))](_0xeaf9('0xc8'));}if(_['isNil'](_0x59f650[_0xeaf9('0x63')]['to'])){throw new db['Sequelize'][(_0xeaf9('0x7b'))](_0xeaf9('0xc9'));}_0x1392cc=_0x59f650[_0xeaf9('0x63')]['to'];return db[_0xeaf9('0x54')][_0xeaf9('0x5b')]({'where':{'id':_0x59f650['params']['id']},'include':[{'model':db[_0xeaf9('0x9c')],'as':_0xeaf9('0xca'),'include':[{'model':db[_0xeaf9('0x79')],'as':'Contacts','where':{'mobile':_0x1392cc},'limit':0x1,'order':[[_0xeaf9('0x7f'),_0xeaf9('0x9e')]]}]}]})[_0xeaf9('0x22')](handleEntityNotFound(_0x312e79,null))['then'](function(_0x853f87){if(_0x853f87&&_0x853f87[_0xeaf9('0xca')]){_0x16b026=_0x853f87['get']({'plain':!![]});if(_0x16b026['List']&&_0x16b026[_0xeaf9('0xca')][_0xeaf9('0x9d')][_0xeaf9('0x49')]){return _0x16b026[_0xeaf9('0xca')][_0xeaf9('0x9d')][0x0];}return db[_0xeaf9('0x79')][_0xeaf9('0x5c')](_[_0xeaf9('0x1b')](_0x59f650['body'],{'firstName':_0x1392cc,'mobile':_0x1392cc,'phone':_0x1392cc,'ListId':_0x16b026[_0xeaf9('0x80')]}));}})[_0xeaf9('0x22')](handleEntityNotFound(_0x312e79,null))['then'](function(_0x144b20){if(_0x144b20){_0x9d1728=_0x144b20;return db[_0xeaf9('0xa1')][_0xeaf9('0x5b')]({'where':{'ContactId':_0x9d1728['id'],'closed':![],'SmsAccountId':_0x16b026['id']}})['then'](function(_0x153ef2){if(_0x153ef2){return[_0x153ef2,![]];}return db[_0xeaf9('0xa1')][_0xeaf9('0x5c')]({'UserId':_0x59f650[_0xeaf9('0x5d')]['id'],'ContactId':_0x9d1728['id'],'SmsAccountId':_0x16b026['id'],'phone':_0x1392cc,'firstMsgDirection':_0xeaf9('0xcb'),'Messages':[_['merge'](_0x59f650[_0xeaf9('0x63')],{'read':![],'body':_0x59f650[_0xeaf9('0x63')][_0xeaf9('0x63')],'phone':_0x1392cc,'SmsAccountId':_0x16b026['id'],'UserId':_0x59f650[_0xeaf9('0x5d')]['id'],'ContactId':_0x9d1728['id']})]},{'include':[{'model':db[_0xeaf9('0xaa')],'as':_0xeaf9('0xcc')}]})['then'](function(_0x544193){return[_0x544193,!![]];});});}})[_0xeaf9('0xa2')](function(_0x2f7896,_0x2bd188){if(_0x2bd188){return _0x2f7896;}return db[_0xeaf9('0xaa')]['create'](_[_0xeaf9('0x51')](_0x59f650[_0xeaf9('0x63')],{'read':![],'body':_0x59f650['body'][_0xeaf9('0x63')],'phone':_0x1392cc,'SmsAccountId':_0x16b026['id'],'SmsInteractionId':_0x2f7896['id'],'UserId':_0x59f650['user']['id'],'ContactId':_0x9d1728['id']}))[_0xeaf9('0x22')](function(_0x9a03b3){_0x2f7896['dataValues'][_0xeaf9('0xcc')]=[];_0x2f7896[_0xeaf9('0xcd')][_0xeaf9('0xcc')][_0xeaf9('0xa5')](_0x9a03b3[_0xeaf9('0xcd')]);return _0x2f7896;});})[_0xeaf9('0x22')](respondWithResult(_0x312e79,null))[_0xeaf9('0x2c')](handleError(_0x312e79,null));};exports['status']=function(_0x15bc03,_0x1fe7a9,_0x1f521c){if(_0x15bc03['body']['id']){delete _0x15bc03['body']['id'];}var _0x54cd85,_0x5d7754,_0x61f3da;return db[_0xeaf9('0x54')][_0xeaf9('0x5b')]({'where':{'id':_0x15bc03[_0xeaf9('0x59')]['id']}})[_0xeaf9('0x22')](handleEntityNotFound(_0x1fe7a9,null))[_0xeaf9('0x22')](function(_0x370782){if(_0x370782){_0x61f3da=_0x370782;logger['debug'](_0xeaf9('0xb1'),'status',_0xeaf9('0xce'),_0x370782['type'],util[_0xeaf9('0xcf')](_0x15bc03[_0xeaf9('0x63')],{'showHidden':![],'depth':null}));switch(_0x370782[_0xeaf9('0x41')]){case _0xeaf9('0x86'):if(_0x15bc03['body']['skebby_dispatch_id']&&_0x15bc03[_0xeaf9('0x63')][_0xeaf9('0x2e')]){_0x5d7754=_0x15bc03[_0xeaf9('0x63')][_0xeaf9('0x2e')];return db[_0xeaf9('0xaa')][_0xeaf9('0x5b')]({'where':{'messageId':_0x15bc03[_0xeaf9('0x63')][_0xeaf9('0xd0')]}});}break;case _0xeaf9('0x89'):if(_0x15bc03['body'][_0xeaf9('0xd1')]&&_0x15bc03[_0xeaf9('0x63')][_0xeaf9('0xd2')]){_0x5d7754=_0x15bc03[_0xeaf9('0x63')][_0xeaf9('0xd2')];return db[_0xeaf9('0xaa')]['find']({'where':{'messageId':_0x15bc03['body'][_0xeaf9('0xd1')]}});}break;case _0xeaf9('0xd3'):if(_0x15bc03[_0xeaf9('0x63')][_0xeaf9('0x8a')]&&_0x15bc03[_0xeaf9('0x63')]['status_code']){_0x5d7754=_0x15bc03['body'][_0xeaf9('0xd4')];return db['SmsMessage'][_0xeaf9('0x5b')]({'where':{'messageId':_0x15bc03[_0xeaf9('0x63')]['message_id']}});}break;case _0xeaf9('0x8e'):var _0x22d058=_0x15bc03[_0xeaf9('0x63')][_0xeaf9('0x8f')][0x0];if(_0x22d058['messageId']&&_0x22d058[_0xeaf9('0x2e')][_0xeaf9('0xd5')]===_0xeaf9('0xd6')){_0x5d7754=_0x22d058[_0xeaf9('0x2e')]['groupName'];return db['SmsMessage'][_0xeaf9('0x5b')]({'where':{'messageId':_0x22d058[_0xeaf9('0x84')]}});}break;case _0xeaf9('0xd7'):if(_0x15bc03[_0xeaf9('0x63')]['messageId']&&_0x15bc03[_0xeaf9('0x63')][_0xeaf9('0x2e')]){_0x5d7754=_0x15bc03['body'][_0xeaf9('0x2e')];return db[_0xeaf9('0xaa')][_0xeaf9('0x5b')]({'where':{'messageId':_0x15bc03['body']['messageId']}});}break;case _0xeaf9('0x96'):if(_0x15bc03['body'][0x0][_0xeaf9('0x2a')]['id']){_0x5d7754=_0x15bc03['body'][0x0]['type'];return db[_0xeaf9('0xaa')][_0xeaf9('0x5b')]({'where':{'messageId':_0x15bc03['body'][0x0][_0xeaf9('0x2a')]['id']}});}break;case _0xeaf9('0xd8'):if(_0x15bc03['body'][_0xeaf9('0xd9')]&&_0x15bc03[_0xeaf9('0x63')]['status']){_0x5d7754=_0x15bc03['body'][_0xeaf9('0x2e')];return db[_0xeaf9('0xaa')][_0xeaf9('0x5b')]({'where':{'messageId':_0x15bc03['body'][_0xeaf9('0xd9')]}});}break;}}})['then'](handleEntityNotFound(_0x1fe7a9,null))['then'](function(_0x3667f0){if(_0x3667f0){_0x54cd85=_0x3667f0;switch(_0x61f3da[_0xeaf9('0x41')]){case _0xeaf9('0x86'):if(_0x5d7754===_0xeaf9('0xd6')){return _0x54cd85[_0xeaf9('0x37')]({'read':!![]});}else{logger[_0xeaf9('0x27')](_0xeaf9('0xb1'),_0xeaf9('0x2e'),_0xeaf9('0x86'),util[_0xeaf9('0xcf')](_0x15bc03[_0xeaf9('0x63')],{'showHidden':![],'depth':null}));}break;case _0xeaf9('0x89'):if(_0x5d7754==='1'){return _0x54cd85[_0xeaf9('0x37')]({'read':!![]});}else{logger[_0xeaf9('0x27')]('SmsAccount,\x20%s,\x20%s,\x20%s','status',_0xeaf9('0x86'),util[_0xeaf9('0xcf')](_0x15bc03[_0xeaf9('0x63')],{'showHidden':![],'depth':null}));}break;case'clicksend':if(!_0x15bc03[_0xeaf9('0x63')][_0xeaf9('0xda')]&&_0x5d7754>=0xc8&&_0x5d7754<=0xce){return _0x54cd85[_0xeaf9('0x37')]({'read':!![]});}else{logger[_0xeaf9('0x27')]('SmsAccount,\x20%s,\x20%s,\x20%s','status',_0xeaf9('0xd3'),util[_0xeaf9('0xcf')](_0x15bc03[_0xeaf9('0x63')],{'showHidden':![],'depth':null}));}break;case'infobip':var _0xdf4729=_0x15bc03[_0xeaf9('0x63')][_0xeaf9('0x8f')][0x0];if(_0xdf4729[_0xeaf9('0x2e')]['groupName']===_0xeaf9('0xd6')){return _0x54cd85['update']({'read':!![]});}else{logger['error'](_0xeaf9('0xb1'),_0xeaf9('0x2e'),_0xeaf9('0x8e'),util[_0xeaf9('0xcf')](_0x15bc03[_0xeaf9('0x63')],{'showHidden':![],'depth':null}));}break;case _0xeaf9('0xd7'):if(_0x5d7754==_0xeaf9('0xdb')||_0x5d7754==_0xeaf9('0xdc')){return _0x54cd85['update']({'read':!![]});}else{logger[_0xeaf9('0x27')](_0xeaf9('0xb1'),_0xeaf9('0x2e'),'clickatell',util[_0xeaf9('0xcf')](_0x15bc03[_0xeaf9('0x63')],{'showHidden':![],'depth':null}));}break;case _0xeaf9('0x96'):if(_0x5d7754==_0xeaf9('0xdd')){return _0x54cd85[_0xeaf9('0x37')]({'read':!![]});}else{logger['error'](_0xeaf9('0xb1'),'status',_0xeaf9('0x96'),util[_0xeaf9('0xcf')](_0x15bc03[_0xeaf9('0x63')],{'showHidden':![],'depth':null}));}break;case _0xeaf9('0xd8'):if(_0x5d7754===_0xeaf9('0xde')||_0x5d7754===_0xeaf9('0xdf')){return _0x54cd85[_0xeaf9('0x37')]({'read':!![]});}else{logger[_0xeaf9('0x27')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0xeaf9('0x2e'),_0xeaf9('0xd8'),util[_0xeaf9('0xcf')](_0x15bc03['body'],{'showHidden':![],'depth':null}));}break;}return _0x54cd85;}})[_0xeaf9('0x22')](respondWithResult(_0x1fe7a9,null))['catch'](handleError(_0x1fe7a9,null));};exports[_0xeaf9('0xe0')]=function(_0x5577a2,_0x44d700,_0xb1d4e1){var _0x177baa,_0x366784,_0x58e9f4;return db[_0xeaf9('0x54')][_0xeaf9('0x5b')]({'where':{'id':_0x5577a2[_0xeaf9('0x59')]['id']}})[_0xeaf9('0x22')](handleEntityNotFound(_0x44d700,null))[_0xeaf9('0x22')](function(_0x1c8fb7){if(_0x1c8fb7){_0x58e9f4=_0x1c8fb7;logger[_0xeaf9('0x25')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0xeaf9('0x2e'),_0xeaf9('0xce'),_0x1c8fb7[_0xeaf9('0x41')],util[_0xeaf9('0xcf')](_0x5577a2[_0xeaf9('0x43')],{'showHidden':![],'depth':null}));switch(_0x1c8fb7[_0xeaf9('0x41')]){case _0xeaf9('0x91'):if(_0x5577a2[_0xeaf9('0x43')][_0xeaf9('0xe1')]&&_0x5577a2['query'][_0xeaf9('0xe2')]){_0x366784=_0x5577a2['query'][_0xeaf9('0xe2')];return db[_0xeaf9('0xaa')][_0xeaf9('0x5b')]({'where':{'messageId':_0x5577a2[_0xeaf9('0x43')][_0xeaf9('0xe1')]}});}break;}}})[_0xeaf9('0x22')](handleEntityNotFound(_0x44d700,null))['then'](function(_0x251dda){if(_0x251dda){_0x177baa=_0x251dda;switch(_0x58e9f4['type']){case _0xeaf9('0x91'):if(_0x366784==='2'||_0x366784==='6'){return _0x177baa[_0xeaf9('0x37')]({'read':!![]});}else{logger[_0xeaf9('0x27')](_0xeaf9('0xb1'),_0xeaf9('0x2e'),'csc',util[_0xeaf9('0xcf')](_0x5577a2[_0xeaf9('0x43')],{'showHidden':![],'depth':null}));};break;}return _0x177baa;}})[_0xeaf9('0x22')](respondWithResult(_0x44d700,null))[_0xeaf9('0x2c')](handleError(_0x44d700,null));};exports['addAgents']=function(_0x5a6cb7,_0x2e5a29,_0x212143){return db[_0xeaf9('0x54')][_0xeaf9('0x5b')]({'where':{'id':_0x5a6cb7[_0xeaf9('0x59')]['id']}})[_0xeaf9('0x22')](handleEntityNotFound(_0x2e5a29,null))['then'](function(_0x50ee91){if(_0x50ee91){return _0x50ee91[_0xeaf9('0xe3')](_0x5a6cb7[_0xeaf9('0x63')]['ids'],_[_0xeaf9('0xe4')](_0x5a6cb7[_0xeaf9('0x63')],['ids','id'])||{})[_0xeaf9('0xa2')](function(_0x326176){for(var _0x1e2da6=0x0;_0x1e2da6<_0x5a6cb7[_0xeaf9('0x63')][_0xeaf9('0x6e')][_0xeaf9('0x49')];_0x1e2da6+=0x1){socket[_0xeaf9('0xe5')](_0xeaf9('0xe6'),{'UserId':Number(_0x5a6cb7[_0xeaf9('0x63')][_0xeaf9('0x6e')][_0x1e2da6]),'SmsAccountId':Number(_0x5a6cb7[_0xeaf9('0x59')]['id'])});}return _0x326176;});}})[_0xeaf9('0x22')](respondWithResult(_0x2e5a29,null))[_0xeaf9('0x2c')](handleError(_0x2e5a29,null));};exports[_0xeaf9('0xe7')]=function(_0x29b118,_0x4ec05c,_0x49454c){return db[_0xeaf9('0x54')]['find']({'where':{'id':_0x29b118['params']['id']}})[_0xeaf9('0x22')](handleEntityNotFound(_0x4ec05c,null))[_0xeaf9('0x22')](function(_0x2de83d){if(_0x2de83d){return _0x2de83d[_0xeaf9('0xe7')](_0x29b118['query']['ids'])[_0xeaf9('0x22')](function(){if(_[_0xeaf9('0xe8')](_0x29b118[_0xeaf9('0x43')][_0xeaf9('0x6e')])){for(var _0x54bf7d=0x0;_0x54bf7d<_0x29b118['query']['ids'][_0xeaf9('0x49')];_0x54bf7d+=0x1){socket[_0xeaf9('0xe5')](_0xeaf9('0xe9'),{'UserId':Number(_0x29b118[_0xeaf9('0x43')][_0xeaf9('0x6e')][_0x54bf7d]),'SmsAccountId':Number(_0x29b118['params']['id'])});}}else{socket[_0xeaf9('0xe5')]('userSmsAccount:remove',{'UserId':Number(_0x29b118[_0xeaf9('0x43')][_0xeaf9('0x6e')]),'SmsAccountId':Number(_0x29b118[_0xeaf9('0x59')]['id'])});}});}})[_0xeaf9('0x22')](respondWithStatusCode(_0x4ec05c,null))['catch'](handleError(_0x4ec05c,null));};exports[_0xeaf9('0xea')]=function(_0x22af22,_0x4a9fad,_0x4a8a24){var _0x2759fb={};var _0x5050ff={};var _0x224caa;var _0x4eaaf0;return db['SmsAccount'][_0xeaf9('0x68')]({'where':{'id':_0x22af22[_0xeaf9('0x59')]['id']}})[_0xeaf9('0x22')](handleEntityNotFound(_0x4a9fad,null))['then'](function(_0x50136c){if(_0x50136c){_0x224caa=_0x50136c;_0x5050ff[_0xeaf9('0x4a')]=_[_0xeaf9('0x44')](db['User'][_0xeaf9('0x6a')]);_0x5050ff[_0xeaf9('0x43')]=_[_0xeaf9('0x44')](_0x22af22[_0xeaf9('0x43')]);_0x5050ff['filters']=_[_0xeaf9('0x46')](_0x5050ff[_0xeaf9('0x4a')],_0x5050ff['query']);_0x2759fb[_0xeaf9('0x47')]=_[_0xeaf9('0x46')](_0x5050ff[_0xeaf9('0x4a')],qs['fields'](_0x22af22[_0xeaf9('0x43')][_0xeaf9('0x48')]));_0x2759fb[_0xeaf9('0x47')]=_0x2759fb[_0xeaf9('0x47')]['length']?_0x2759fb['attributes']:_0x5050ff['model'];_0x2759fb[_0xeaf9('0x4e')]=qs[_0xeaf9('0x6b')](_0x22af22[_0xeaf9('0x43')][_0xeaf9('0x6b')]);_0x2759fb[_0xeaf9('0x50')]=qs[_0xeaf9('0x45')](_[_0xeaf9('0x4f')](_0x22af22['query'],_0x5050ff[_0xeaf9('0x45')]));if(_0x22af22[_0xeaf9('0x43')]['filter']){_0x2759fb[_0xeaf9('0x50')]=_[_0xeaf9('0x51')](_0x2759fb['where'],{'$or':_[_0xeaf9('0x40')](_0x2759fb[_0xeaf9('0x47')],function(_0x368af7){var _0x484d78={};_0x484d78[_0x368af7]={'$like':'%'+_0x22af22[_0xeaf9('0x43')]['filter']+'%'};return _0x484d78;})});}_0x2759fb=_['merge']({},_0x2759fb,_0x22af22[_0xeaf9('0x53')]);return _0x224caa['getAgents'](_0x2759fb);}})[_0xeaf9('0x22')](function(_0x488a0a){if(_0x488a0a){_0x4eaaf0=_0x488a0a[_0xeaf9('0x49')];if(!_0x22af22[_0xeaf9('0x43')][_0xeaf9('0x4b')](_0xeaf9('0x4c'))){_0x2759fb[_0xeaf9('0x4d')]=qs[_0xeaf9('0x4d')](_0x22af22[_0xeaf9('0x43')][_0xeaf9('0x4d')]);_0x2759fb['offset']=qs[_0xeaf9('0x32')](_0x22af22[_0xeaf9('0x43')][_0xeaf9('0x32')]);}return _0x224caa[_0xeaf9('0xea')](_0x2759fb);}})[_0xeaf9('0x22')](function(_0x1d02f1){if(_0x1d02f1){return _0x1d02f1?{'count':_0x4eaaf0,'rows':_0x1d02f1}:null;}})['then'](respondWithResult(_0x4a9fad,null))[_0xeaf9('0x2c')](handleError(_0x4a9fad,null));};
\ No newline at end of file
+var _0xe077=['limit','offset','set','apply','save','update','destroy','get','name','index','Pause','map','SmsAccount','rawAttributes','type','key','model','query','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','filters','pick','filter','where','merge','VIRTUAL','options','count','include','findAll','rows','catch','show','mandatoryDispositionPause','keys','create','user','role','SmsAccounts','UserProfileSection','userProfileId','autoAssociation','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','find','params','describe','addDisposition','SmsAccountId','Disposition','includeAll','removeDispositions','addAnswer','findOne','CannedAnswer','removeAnswers','notify','SmsApplication','applications','orderBy','Applications','priority','asc','account','Sequelize','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','CompanyId','ListId','mobile','twilio','From','Body','messageId','MessageSid','skebby','from','sender','connectel','message_id','plivo','Text','MessageUUID','infobip','results','text','csc','originatingAddress','segmentedMessage','clickatell','fromNumber','replyMessageId','intelepeer','refid','isNil','from\x20is\x20mandatory','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','CmContact','Contacts','DESC','list','mapKey','contact','SmsInteraction','spread','interaction','created','autoclose','push','close','unmanaged','*,*,*,*','SmsMessage','ContactId','AttachmentId','UserId','waitForTheAssignedAgent','Start','startRouting','receiveMessage','SmsAccount,\x20%s,\x20%s,\x20%s','entity\x20found','SmsAccount,\x20%s,\x20%s,\x20%s,\x20%s','Content-Type','text/xml','<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>','addApplications','sequelize','transaction','Transaction','READ_COMMITTED','bulkCreate','stack','finally','send','getApplications','getInteractions','Contact','User','Owner','fullname','Tag','Tags','color','tag','body\x20is\x20mandatory\x20and\x20not\x20empty','to\x20is\x20mandatory','List','out','dataValues','Messages','skebby_dispatch_id','requestid','statusInt','clicksend','status_code','groupName','DELIVERED','bandwidth','redif','inspect','error_code','DELIVERED_TO_GATEWAY','RECEIVED_BY_RECIPIENT','message-delivered','DELIVRD','ACCEPTD','received\x20delivery\x20report\x20from','message-id','state','addAgents','ids','omit','emit','isArray','userSmsAccount:remove','getAgents','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','api','../../config/environment','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./smsAccount.socket','register','jayson/promise','client','http','request','then','info','request\x20sent','debug','stringify','error','code','SmsAccount,\x20%s,\x20%s','message','result','sendStatus','status','end','json','undefined'];(function(_0x30cc1a,_0x162bbc){var _0xb3f18f=function(_0x26bdfe){while(--_0x26bdfe){_0x30cc1a['push'](_0x30cc1a['shift']());}};_0xb3f18f(++_0x162bbc);}(_0xe077,0x1ae));var _0x7e07=function(_0x19de20,_0x4e6684){_0x19de20=_0x19de20-0x0;var _0x55d051=_0xe077[_0x19de20];return _0x55d051;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x7e07('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0x7e07('0x1'));var rp=require(_0x7e07('0x2'));var moment=require(_0x7e07('0x3'));var BPromise=require(_0x7e07('0x4'));var Mustache=require(_0x7e07('0x5'));var util=require(_0x7e07('0x6'));var path=require(_0x7e07('0x7'));var sox=require('sox');var csv=require(_0x7e07('0x8'));var ejs=require(_0x7e07('0x9'));var fs=require('fs');var fs_extra=require(_0x7e07('0xa'));var _=require(_0x7e07('0xb'));var squel=require(_0x7e07('0xc'));var crypto=require(_0x7e07('0xd'));var jsforce=require(_0x7e07('0xe'));var deskjs=require(_0x7e07('0xf'));var toCsv=require(_0x7e07('0x8'));var querystring=require(_0x7e07('0x10'));var Papa=require(_0x7e07('0x11'));var Redis=require(_0x7e07('0x12'));var authService=require(_0x7e07('0x13'));var qs=require(_0x7e07('0x14'));var as=require(_0x7e07('0x15'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x7e07('0x16'));var utils=require('../../config/utils');var config=require(_0x7e07('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0x7e07('0x18'))['db'];config[_0x7e07('0x19')]=_[_0x7e07('0x1a')](config['redis'],{'host':_0x7e07('0x1b'),'port':0x18eb});var socket=require(_0x7e07('0x1c'))(new Redis(config['redis']));require(_0x7e07('0x1d'))[_0x7e07('0x1e')](socket);var jayson=require(_0x7e07('0x1f'));var client=jayson[_0x7e07('0x20')][_0x7e07('0x21')]({'port':0x232c});function respondWithRpcPromise(_0x1797a2,_0x5c22c8,_0x241fc0,_0x57dd48){return new BPromise(function(_0x5b2c68,_0x4d0b11){var _0x21cf5d=_0x57dd48||client;return _0x21cf5d[_0x7e07('0x22')](_0x1797a2,_0x241fc0)[_0x7e07('0x23')](function(_0x2f0133){logger[_0x7e07('0x24')]('SmsAccount,\x20%s,\x20%s',_0x5c22c8,_0x7e07('0x25'));logger[_0x7e07('0x26')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x5c22c8,_0x7e07('0x25'),JSON[_0x7e07('0x27')](_0x2f0133));if(_0x2f0133[_0x7e07('0x28')]){if(_0x2f0133[_0x7e07('0x28')][_0x7e07('0x29')]===0x1f4){logger[_0x7e07('0x28')](_0x7e07('0x2a'),_0x5c22c8,_0x2f0133[_0x7e07('0x28')]['message']);return _0x4d0b11(_0x2f0133['error']['message']);}logger[_0x7e07('0x28')](_0x7e07('0x2a'),_0x5c22c8,_0x2f0133[_0x7e07('0x28')][_0x7e07('0x2b')]);return _0x5b2c68(_0x2f0133[_0x7e07('0x28')][_0x7e07('0x2b')]);}else{logger[_0x7e07('0x24')]('SmsAccount,\x20%s,\x20%s',_0x5c22c8,_0x7e07('0x25'));_0x5b2c68(_0x2f0133[_0x7e07('0x2c')][_0x7e07('0x2b')]);}})['catch'](function(_0x3a27fb){logger[_0x7e07('0x28')](_0x7e07('0x2a'),_0x5c22c8,_0x3a27fb);_0x4d0b11(_0x3a27fb);});});}function respondWithStatusCode(_0x5bb011,_0x2b8054){_0x2b8054=_0x2b8054||0xcc;return function(_0x1a4522){if(_0x1a4522){return _0x5bb011[_0x7e07('0x2d')](_0x2b8054);}return _0x5bb011[_0x7e07('0x2e')](_0x2b8054)[_0x7e07('0x2f')]();};}function respondWithResult(_0x33f838,_0x18fa16){_0x18fa16=_0x18fa16||0xc8;return function(_0x151d23){if(_0x151d23){return _0x33f838[_0x7e07('0x2e')](_0x18fa16)[_0x7e07('0x30')](_0x151d23);}};}function respondWithFilteredResult(_0x5840fa,_0x4e98da){return function(_0x21f44e){if(_0x21f44e){var _0x988f44=typeof _0x4e98da['offset']===_0x7e07('0x31')&&typeof _0x4e98da[_0x7e07('0x32')]===_0x7e07('0x31');var _0x4d6f3c=_0x21f44e['count'];var _0x2d56bf=_0x988f44?0x0:_0x4e98da[_0x7e07('0x33')];var _0x234e73=_0x988f44?_0x21f44e['count']:_0x4e98da[_0x7e07('0x33')]+_0x4e98da['limit'];var _0x26ff6c;if(_0x234e73>=_0x4d6f3c){_0x234e73=_0x4d6f3c;_0x26ff6c=0xc8;}else{_0x26ff6c=0xce;}_0x5840fa[_0x7e07('0x2e')](_0x26ff6c);return _0x5840fa[_0x7e07('0x34')]('Content-Range',_0x2d56bf+'-'+_0x234e73+'/'+_0x4d6f3c)[_0x7e07('0x30')](_0x21f44e);}return null;};}function patchUpdates(_0x2a84cd){return function(_0x31c543){try{jsonpatch[_0x7e07('0x35')](_0x31c543,_0x2a84cd,!![]);}catch(_0x4a1254){return BPromise['reject'](_0x4a1254);}return _0x31c543[_0x7e07('0x36')]();};}function saveUpdates(_0x5b2f4d,_0x48ddd1){return function(_0x473585){if(_0x473585){return _0x473585[_0x7e07('0x37')](_0x5b2f4d)[_0x7e07('0x23')](function(_0x43b1a8){return _0x43b1a8;});}return null;};}function removeEntity(_0x468465,_0x4e6512){return function(_0x19e4e3){if(_0x19e4e3){return _0x19e4e3[_0x7e07('0x38')]()[_0x7e07('0x23')](function(){var _0x23de9e=_0x19e4e3[_0x7e07('0x39')]({'plain':!![]});var _0x11f04f='SmsAccounts';return db['UserProfileResource'][_0x7e07('0x38')]({'where':{'type':_0x11f04f,'resourceId':_0x23de9e['id']}})[_0x7e07('0x23')](function(){return _0x19e4e3;});})[_0x7e07('0x23')](function(){_0x468465[_0x7e07('0x2e')](0xcc)[_0x7e07('0x2f')]();});}};}function handleEntityNotFound(_0x21c930,_0x7d3a78){return function(_0x125967){if(!_0x125967){_0x21c930[_0x7e07('0x2d')](0x194);}return _0x125967;};}function handleError(_0x47c964,_0x1efdbd){_0x1efdbd=_0x1efdbd||0x1f4;return function(_0x3e07e5){logger[_0x7e07('0x28')](_0x3e07e5['stack']);if(_0x3e07e5[_0x7e07('0x3a')]){delete _0x3e07e5[_0x7e07('0x3a')];}_0x47c964[_0x7e07('0x2e')](_0x1efdbd)['send'](_0x3e07e5);};}exports[_0x7e07('0x3b')]=function(_0x1b7ba8,_0x509bc8){var _0x37850f={'include':[{'model':db[_0x7e07('0x3c')],'as':'mandatoryDispositionPause'}]},_0x20e264={},_0x499aed={'count':0x0,'rows':[]};var _0x2cfd70=_[_0x7e07('0x3d')](db[_0x7e07('0x3e')][_0x7e07('0x3f')],function(_0x13db97){return{'name':_0x13db97['fieldName'],'type':_0x13db97[_0x7e07('0x40')][_0x7e07('0x41')]};});_0x20e264[_0x7e07('0x42')]=_[_0x7e07('0x3d')](_0x2cfd70,_0x7e07('0x3a'));_0x20e264[_0x7e07('0x43')]=_['keys'](_0x1b7ba8[_0x7e07('0x43')]);_0x20e264['filters']=_[_0x7e07('0x44')](_0x20e264[_0x7e07('0x42')],_0x20e264[_0x7e07('0x43')]);_0x37850f[_0x7e07('0x45')]=_[_0x7e07('0x44')](_0x20e264[_0x7e07('0x42')],qs['fields'](_0x1b7ba8[_0x7e07('0x43')][_0x7e07('0x46')]));_0x37850f[_0x7e07('0x45')]=_0x37850f[_0x7e07('0x45')][_0x7e07('0x47')]?_0x37850f[_0x7e07('0x45')]:_0x20e264[_0x7e07('0x42')];if(!_0x1b7ba8[_0x7e07('0x43')][_0x7e07('0x48')](_0x7e07('0x49'))){_0x37850f[_0x7e07('0x32')]=qs[_0x7e07('0x32')](_0x1b7ba8[_0x7e07('0x43')]['limit']);_0x37850f[_0x7e07('0x33')]=qs[_0x7e07('0x33')](_0x1b7ba8['query'][_0x7e07('0x33')]);}_0x37850f[_0x7e07('0x4a')]=qs[_0x7e07('0x4b')](_0x1b7ba8[_0x7e07('0x43')][_0x7e07('0x4b')]);_0x37850f['where']=qs[_0x7e07('0x4c')](_[_0x7e07('0x4d')](_0x1b7ba8['query'],_0x20e264[_0x7e07('0x4c')]),_0x2cfd70);if(_0x1b7ba8[_0x7e07('0x43')][_0x7e07('0x4e')]){_0x37850f[_0x7e07('0x4f')]=_[_0x7e07('0x50')](_0x37850f[_0x7e07('0x4f')],{'$or':_['map'](_0x2cfd70,function(_0x2d58ad){if(_0x2d58ad[_0x7e07('0x40')]!==_0x7e07('0x51')){var _0x2d3b1c={};_0x2d3b1c[_0x2d58ad[_0x7e07('0x3a')]]={'$like':'%'+_0x1b7ba8[_0x7e07('0x43')][_0x7e07('0x4e')]+'%'};return _0x2d3b1c;}})});}_0x37850f=_[_0x7e07('0x50')]({},_0x37850f,_0x1b7ba8[_0x7e07('0x52')]);var _0x5865a7={'where':_0x37850f[_0x7e07('0x4f')]};return db[_0x7e07('0x3e')][_0x7e07('0x53')](_0x5865a7)[_0x7e07('0x23')](function(_0x1ae376){_0x499aed[_0x7e07('0x53')]=_0x1ae376;if(_0x1b7ba8['query']['includeAll']){_0x37850f[_0x7e07('0x54')]=[{'all':!![]}];}return db[_0x7e07('0x3e')][_0x7e07('0x55')](_0x37850f);})[_0x7e07('0x23')](function(_0x9c85ed){_0x499aed[_0x7e07('0x56')]=_0x9c85ed;return _0x499aed;})[_0x7e07('0x23')](respondWithFilteredResult(_0x509bc8,_0x37850f))[_0x7e07('0x57')](handleError(_0x509bc8,null));};exports[_0x7e07('0x58')]=function(_0xf8c7af,_0x42e004){var _0x3f9cae={'raw':![],'where':{'id':_0xf8c7af['params']['id']},'include':[{'model':db[_0x7e07('0x3c')],'as':_0x7e07('0x59')}]},_0x2ceeeb={};_0x2ceeeb[_0x7e07('0x42')]=_[_0x7e07('0x5a')](db[_0x7e07('0x3e')]['rawAttributes']);_0x2ceeeb['query']=_[_0x7e07('0x5a')](_0xf8c7af[_0x7e07('0x43')]);_0x2ceeeb['filters']=_[_0x7e07('0x44')](_0x2ceeeb[_0x7e07('0x42')],_0x2ceeeb[_0x7e07('0x43')]);_0x3f9cae['attributes']=_[_0x7e07('0x44')](_0x2ceeeb[_0x7e07('0x42')],qs['fields'](_0xf8c7af['query']['fields']));_0x3f9cae['attributes']=_0x3f9cae[_0x7e07('0x45')][_0x7e07('0x47')]?_0x3f9cae[_0x7e07('0x45')]:_0x2ceeeb['model'];if(_0xf8c7af[_0x7e07('0x43')]['includeAll']){_0x3f9cae['include']=[{'all':!![]}];}_0x3f9cae=_[_0x7e07('0x50')]({},_0x3f9cae,_0xf8c7af[_0x7e07('0x52')]);return db['SmsAccount']['find'](_0x3f9cae)[_0x7e07('0x23')](handleEntityNotFound(_0x42e004,null))[_0x7e07('0x23')](respondWithResult(_0x42e004,null))[_0x7e07('0x57')](handleError(_0x42e004,null));};exports[_0x7e07('0x5b')]=function(_0x52afd3,_0x50e9d5){return db['SmsAccount']['create'](_0x52afd3['body'],{})[_0x7e07('0x23')](function(_0x34eb8d){var _0x35ea2d=_0x52afd3[_0x7e07('0x5c')]['get']({'plain':!![]});if(!_0x35ea2d)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x35ea2d[_0x7e07('0x5d')]===_0x7e07('0x5c')){var _0x2377c4=_0x34eb8d[_0x7e07('0x39')]({'plain':!![]});var _0x3ac1de=_0x7e07('0x5e');return db[_0x7e07('0x5f')]['find']({'where':{'name':_0x3ac1de,'userProfileId':_0x35ea2d[_0x7e07('0x60')]},'raw':!![]})[_0x7e07('0x23')](function(_0x334ec1){if(_0x334ec1&&_0x334ec1[_0x7e07('0x61')]===0x0){return db[_0x7e07('0x62')]['create']({'name':_0x2377c4['name'],'resourceId':_0x2377c4['id'],'type':_0x334ec1['name'],'sectionId':_0x334ec1['id']},{})['then'](function(){return _0x34eb8d;});}else{return _0x34eb8d;}})['catch'](function(_0x13de9f){logger[_0x7e07('0x28')](_0x7e07('0x63'),_0x13de9f);throw _0x13de9f;});}return _0x34eb8d;})[_0x7e07('0x23')](respondWithResult(_0x50e9d5,0xc9))[_0x7e07('0x57')](handleError(_0x50e9d5,null));};exports[_0x7e07('0x37')]=function(_0x38104e,_0x32f09e){if(_0x38104e[_0x7e07('0x64')]['id']){delete _0x38104e['body']['id'];}return db[_0x7e07('0x3e')][_0x7e07('0x65')]({'where':{'id':_0x38104e[_0x7e07('0x66')]['id']},'include':[{'model':db[_0x7e07('0x3c')],'as':_0x7e07('0x59')}]})['then'](handleEntityNotFound(_0x32f09e,null))['then'](saveUpdates(_0x38104e[_0x7e07('0x64')],null))[_0x7e07('0x23')](respondWithResult(_0x32f09e,null))[_0x7e07('0x57')](handleError(_0x32f09e,null));};exports[_0x7e07('0x38')]=function(_0xb7413d,_0x1071b8){return db[_0x7e07('0x3e')][_0x7e07('0x65')]({'where':{'id':_0xb7413d[_0x7e07('0x66')]['id']}})[_0x7e07('0x23')](handleEntityNotFound(_0x1071b8,null))[_0x7e07('0x23')](removeEntity(_0x1071b8,null))[_0x7e07('0x57')](handleError(_0x1071b8,null));};exports[_0x7e07('0x67')]=function(_0x186435,_0x8cc1b0){return db[_0x7e07('0x3e')][_0x7e07('0x67')]()[_0x7e07('0x23')](respondWithResult(_0x8cc1b0,null))[_0x7e07('0x57')](handleError(_0x8cc1b0,null));};exports[_0x7e07('0x68')]=function(_0x370e2b,_0x433958,_0x1d75ff){if(_0x370e2b[_0x7e07('0x64')]['id']){delete _0x370e2b[_0x7e07('0x64')]['id'];}return db['SmsAccount'][_0x7e07('0x65')]({'where':{'id':_0x370e2b['params']['id']}})['then'](handleEntityNotFound(_0x433958,null))[_0x7e07('0x23')](function(_0x595165){if(_0x595165){_0x370e2b[_0x7e07('0x64')][_0x7e07('0x69')]=_0x595165['id'];return db[_0x7e07('0x6a')][_0x7e07('0x5b')](_0x370e2b[_0x7e07('0x64')]);}})[_0x7e07('0x23')](respondWithResult(_0x433958,null))['catch'](handleError(_0x433958,null));};exports['getDispositions']=function(_0x4d5b71,_0x482455,_0x44edf5){var _0x84642f={'raw':![],'where':{}};var _0x59692e={};var _0x2334d9={'count':0x0,'rows':[]};return db['SmsAccount']['findOne']({'where':{'id':_0x4d5b71[_0x7e07('0x66')]['id']}})[_0x7e07('0x23')](handleEntityNotFound(_0x482455,null))[_0x7e07('0x23')](function(_0x242d3e){if(_0x242d3e){_0x59692e['model']=_['keys'](db[_0x7e07('0x6a')][_0x7e07('0x3f')]);_0x59692e[_0x7e07('0x43')]=_['keys'](_0x4d5b71[_0x7e07('0x43')]);_0x59692e[_0x7e07('0x4c')]=_[_0x7e07('0x44')](_0x59692e[_0x7e07('0x42')],_0x59692e[_0x7e07('0x43')]);_0x84642f['attributes']=_[_0x7e07('0x44')](_0x59692e['model'],qs[_0x7e07('0x46')](_0x4d5b71['query'][_0x7e07('0x46')]));_0x84642f[_0x7e07('0x45')]=_0x84642f[_0x7e07('0x45')]['length']?_0x84642f['attributes']:_0x59692e[_0x7e07('0x42')];if(!_0x4d5b71[_0x7e07('0x43')][_0x7e07('0x48')](_0x7e07('0x49'))){_0x84642f[_0x7e07('0x32')]=qs[_0x7e07('0x32')](_0x4d5b71[_0x7e07('0x43')][_0x7e07('0x32')]);_0x84642f[_0x7e07('0x33')]=qs['offset'](_0x4d5b71['query'][_0x7e07('0x33')]);}_0x84642f[_0x7e07('0x4a')]=qs[_0x7e07('0x4b')](_0x4d5b71['query']['sort']);_0x84642f[_0x7e07('0x4f')]=qs['filters'](_[_0x7e07('0x4d')](_0x4d5b71[_0x7e07('0x43')],_0x59692e[_0x7e07('0x4c')]));_0x84642f[_0x7e07('0x4f')]['SmsAccountId']=_0x242d3e['id'];if(_0x4d5b71[_0x7e07('0x43')][_0x7e07('0x4e')]){_0x84642f['where']=_[_0x7e07('0x50')](_0x84642f[_0x7e07('0x4f')],{'$or':_[_0x7e07('0x3d')](_0x84642f[_0x7e07('0x45')],function(_0x58a7b3){var _0x1c3dc5={};_0x1c3dc5[_0x58a7b3]={'$like':'%'+_0x4d5b71[_0x7e07('0x43')][_0x7e07('0x4e')]+'%'};return _0x1c3dc5;})});}_0x84642f=_[_0x7e07('0x50')]({},_0x84642f,_0x4d5b71[_0x7e07('0x52')]);return db[_0x7e07('0x6a')][_0x7e07('0x53')]({'where':_0x84642f[_0x7e07('0x4f')]})['then'](function(_0x188548){_0x2334d9['count']=_0x188548;if(_0x4d5b71[_0x7e07('0x43')][_0x7e07('0x6b')]){_0x84642f[_0x7e07('0x54')]=[{'all':!![]}];}return db[_0x7e07('0x6a')][_0x7e07('0x55')](_0x84642f);})['then'](function(_0x1c11c9){_0x2334d9['rows']=_0x1c11c9;return _0x2334d9;});}})[_0x7e07('0x23')](respondWithFilteredResult(_0x482455,_0x84642f))['catch'](handleError(_0x482455,null));};exports[_0x7e07('0x6c')]=function(_0x305680,_0x546142,_0x5fd9c7){return db[_0x7e07('0x3e')][_0x7e07('0x65')]({'where':{'id':_0x305680[_0x7e07('0x66')]['id']}})[_0x7e07('0x23')](handleEntityNotFound(_0x546142,null))[_0x7e07('0x23')](function(_0x588279){if(_0x588279){return _0x588279[_0x7e07('0x6c')](_0x305680[_0x7e07('0x43')]['ids']);}})[_0x7e07('0x23')](respondWithStatusCode(_0x546142,null))[_0x7e07('0x57')](handleError(_0x546142,null));};exports[_0x7e07('0x6d')]=function(_0x187e51,_0x356f53,_0x44aa06){if(_0x187e51['body']['id']){delete _0x187e51[_0x7e07('0x64')]['id'];}return db[_0x7e07('0x3e')]['find']({'where':{'id':_0x187e51['params']['id']}})['then'](handleEntityNotFound(_0x356f53,null))['then'](function(_0x46db3a){if(_0x46db3a){_0x187e51[_0x7e07('0x64')][_0x7e07('0x69')]=_0x46db3a['id'];return db['CannedAnswer'][_0x7e07('0x5b')](_0x187e51[_0x7e07('0x64')]);}})[_0x7e07('0x23')](respondWithResult(_0x356f53,null))[_0x7e07('0x57')](handleError(_0x356f53,null));};exports['getAnswers']=function(_0x2266c0,_0x5ccc7e,_0x547baa){var _0x1e1484={'raw':![],'where':{}};var _0x2c3e4d={};var _0x1fa243={'count':0x0,'rows':[]};return db[_0x7e07('0x3e')][_0x7e07('0x6e')]({'where':{'id':_0x2266c0[_0x7e07('0x66')]['id']}})['then'](handleEntityNotFound(_0x5ccc7e,null))[_0x7e07('0x23')](function(_0x5f057f){if(_0x5f057f){_0x2c3e4d[_0x7e07('0x42')]=_[_0x7e07('0x5a')](db[_0x7e07('0x6f')]['rawAttributes']);_0x2c3e4d['query']=_[_0x7e07('0x5a')](_0x2266c0[_0x7e07('0x43')]);_0x2c3e4d[_0x7e07('0x4c')]=_['intersection'](_0x2c3e4d['model'],_0x2c3e4d[_0x7e07('0x43')]);_0x1e1484[_0x7e07('0x45')]=_[_0x7e07('0x44')](_0x2c3e4d[_0x7e07('0x42')],qs[_0x7e07('0x46')](_0x2266c0[_0x7e07('0x43')][_0x7e07('0x46')]));_0x1e1484['attributes']=_0x1e1484[_0x7e07('0x45')]['length']?_0x1e1484['attributes']:_0x2c3e4d['model'];if(!_0x2266c0[_0x7e07('0x43')][_0x7e07('0x48')](_0x7e07('0x49'))){_0x1e1484[_0x7e07('0x32')]=qs['limit'](_0x2266c0['query'][_0x7e07('0x32')]);_0x1e1484[_0x7e07('0x33')]=qs[_0x7e07('0x33')](_0x2266c0[_0x7e07('0x43')][_0x7e07('0x33')]);}_0x1e1484[_0x7e07('0x4a')]=qs[_0x7e07('0x4b')](_0x2266c0['query'][_0x7e07('0x4b')]);_0x1e1484['where']=qs[_0x7e07('0x4c')](_[_0x7e07('0x4d')](_0x2266c0[_0x7e07('0x43')],_0x2c3e4d[_0x7e07('0x4c')]));_0x1e1484['where'][_0x7e07('0x69')]=_0x5f057f['id'];if(_0x2266c0[_0x7e07('0x43')]['filter']){_0x1e1484['where']=_[_0x7e07('0x50')](_0x1e1484[_0x7e07('0x4f')],{'$or':_[_0x7e07('0x3d')](_0x1e1484[_0x7e07('0x45')],function(_0x2c728d){var _0x443447={};_0x443447[_0x2c728d]={'$like':'%'+_0x2266c0[_0x7e07('0x43')][_0x7e07('0x4e')]+'%'};return _0x443447;})});}_0x1e1484=_[_0x7e07('0x50')]({},_0x1e1484,_0x2266c0[_0x7e07('0x52')]);return db[_0x7e07('0x6f')]['count']({'where':_0x1e1484[_0x7e07('0x4f')]})[_0x7e07('0x23')](function(_0x1430f5){_0x1fa243[_0x7e07('0x53')]=_0x1430f5;if(_0x2266c0[_0x7e07('0x43')][_0x7e07('0x6b')]){_0x1e1484['include']=[{'all':!![]}];}return db[_0x7e07('0x6f')][_0x7e07('0x55')](_0x1e1484);})[_0x7e07('0x23')](function(_0x2e5b8d){_0x1fa243[_0x7e07('0x56')]=_0x2e5b8d;return _0x1fa243;});}})[_0x7e07('0x23')](respondWithFilteredResult(_0x5ccc7e,_0x1e1484))[_0x7e07('0x57')](handleError(_0x5ccc7e,null));};exports[_0x7e07('0x70')]=function(_0x348e13,_0x358ee7,_0x21ded9){return db[_0x7e07('0x3e')][_0x7e07('0x65')]({'where':{'id':_0x348e13[_0x7e07('0x66')]['id']}})['then'](handleEntityNotFound(_0x358ee7,null))['then'](function(_0x5bfb7b){if(_0x5bfb7b){return _0x5bfb7b['removeAnswers'](_0x348e13[_0x7e07('0x43')]['ids']);}})[_0x7e07('0x23')](respondWithStatusCode(_0x358ee7,null))['catch'](handleError(_0x358ee7,null));};exports[_0x7e07('0x71')]=function(_0x81fbc2,_0x54c3d9,_0x117058){var _0x2f5b10={'channel':'sms'};var _0x2fdd4e=[];var _0x367735=[];var _0x35204d={};return db[_0x7e07('0x3e')][_0x7e07('0x65')]({'where':{'id':_0x81fbc2[_0x7e07('0x66')]['id']},'include':[{'model':db[_0x7e07('0x72')],'as':'Applications'}]})['then'](handleEntityNotFound(_0x54c3d9,null))[_0x7e07('0x23')](function(_0x31d153){_0x2f5b10['account']=_0x31d153;_0x2f5b10[_0x7e07('0x73')]=_[_0x7e07('0x74')](_0x31d153[_0x7e07('0x75')],[_0x7e07('0x76')],[_0x7e07('0x77')]);if(_0x2f5b10[_0x7e07('0x78')][_0x7e07('0x75')]){delete _0x2f5b10[_0x7e07('0x78')][_0x7e07('0x75')];}return db['CmContact'][_0x7e07('0x67')]();})['then'](function(_0x57b467){if(!_0x57b467){throw new db[(_0x7e07('0x79'))][(_0x7e07('0x7a'))](_0x7e07('0x7b'));}_0x2fdd4e=_[_0x7e07('0x7c')](_[_0x7e07('0x5a')](_0x57b467),[_0x7e07('0x7d'),_0x7e07('0x7e')]);_0x367735=_[_0x7e07('0x7c')](_[_0x7e07('0x5a')](_0x57b467),[_0x7e07('0x7d'),_0x7e07('0x7e'),_0x7e07('0x7f'),_0x7e07('0x80')]);_0x2f5b10['body']={'mapKey':_0x7e07('0x81')};if(_0x2f5b10[_0x7e07('0x78')][_0x7e07('0x40')]){switch(_0x2f5b10[_0x7e07('0x78')][_0x7e07('0x40')]){case _0x7e07('0x82'):_0x2f5b10[_0x7e07('0x64')]['from']=_0x81fbc2[_0x7e07('0x64')][_0x7e07('0x83')];_0x2f5b10[_0x7e07('0x64')]['body']=_0x81fbc2[_0x7e07('0x64')][_0x7e07('0x84')];_0x2f5b10[_0x7e07('0x64')][_0x7e07('0x85')]=_0x81fbc2[_0x7e07('0x64')][_0x7e07('0x86')];break;case _0x7e07('0x87'):_0x2f5b10[_0x7e07('0x64')][_0x7e07('0x88')]='+'+_0x81fbc2[_0x7e07('0x64')][_0x7e07('0x89')];_0x2f5b10[_0x7e07('0x64')]['body']=_0x81fbc2[_0x7e07('0x64')]['text'];break;case _0x7e07('0x8a'):_0x2f5b10['body'][_0x7e07('0x88')]=_0x81fbc2[_0x7e07('0x64')]['from'];_0x2f5b10[_0x7e07('0x64')][_0x7e07('0x64')]=_0x81fbc2['body'][_0x7e07('0x2b')];break;case'clicksend':_0x2f5b10[_0x7e07('0x64')][_0x7e07('0x88')]=_0x81fbc2[_0x7e07('0x64')][_0x7e07('0x88')];_0x2f5b10[_0x7e07('0x64')][_0x7e07('0x64')]=_0x81fbc2[_0x7e07('0x64')]['body'];_0x2f5b10[_0x7e07('0x64')][_0x7e07('0x85')]=_0x81fbc2[_0x7e07('0x64')][_0x7e07('0x8b')];break;case _0x7e07('0x8c'):_0x2f5b10[_0x7e07('0x64')][_0x7e07('0x88')]=_0x81fbc2[_0x7e07('0x64')][_0x7e07('0x83')];_0x2f5b10['body'][_0x7e07('0x64')]=_0x81fbc2['body'][_0x7e07('0x8d')];_0x2f5b10[_0x7e07('0x64')][_0x7e07('0x85')]=_0x81fbc2[_0x7e07('0x64')][_0x7e07('0x8e')];break;case _0x7e07('0x8f'):_0x2f5b10[_0x7e07('0x64')]['from']='+'+_0x81fbc2[_0x7e07('0x64')][_0x7e07('0x90')][0x0][_0x7e07('0x88')];_0x2f5b10[_0x7e07('0x64')][_0x7e07('0x64')]=_0x81fbc2[_0x7e07('0x64')][_0x7e07('0x90')][0x0][_0x7e07('0x91')];_0x2f5b10[_0x7e07('0x64')]['messageId']=_0x81fbc2['body'][_0x7e07('0x90')][0x0][_0x7e07('0x85')];break;case _0x7e07('0x92'):_0x2f5b10[_0x7e07('0x64')][_0x7e07('0x88')]=_0x81fbc2['body'][_0x7e07('0x93')];_0x2f5b10[_0x7e07('0x64')][_0x7e07('0x64')]=_0x81fbc2[_0x7e07('0x64')][_0x7e07('0x94')][_0x7e07('0x2b')];break;case _0x7e07('0x95'):_0x2f5b10[_0x7e07('0x64')][_0x7e07('0x88')]=_0x81fbc2[_0x7e07('0x64')][_0x7e07('0x96')];_0x2f5b10[_0x7e07('0x64')][_0x7e07('0x64')]=_0x81fbc2[_0x7e07('0x64')][_0x7e07('0x91')];_0x2f5b10[_0x7e07('0x64')][_0x7e07('0x85')]=_0x81fbc2[_0x7e07('0x64')][_0x7e07('0x97')];break;case'bandwidth':_0x2f5b10['body'][_0x7e07('0x85')]=_0x81fbc2[_0x7e07('0x64')][0x0][_0x7e07('0x2b')]['id'];_0x2f5b10[_0x7e07('0x64')][_0x7e07('0x88')]=_0x81fbc2[_0x7e07('0x64')][0x0][_0x7e07('0x2b')]['from'];_0x2f5b10['body']['body']=_0x81fbc2['body'][0x0][_0x7e07('0x2b')][_0x7e07('0x91')];break;case _0x7e07('0x98'):_0x2f5b10[_0x7e07('0x64')][_0x7e07('0x88')]=_0x81fbc2[_0x7e07('0x64')]['from'];_0x2f5b10[_0x7e07('0x64')]['body']=_0x81fbc2[_0x7e07('0x64')]['message'];_0x2f5b10[_0x7e07('0x64')][_0x7e07('0x85')]=_0x81fbc2[_0x7e07('0x64')][_0x7e07('0x99')];break;}}if(_0x2f5b10[_0x7e07('0x64')]['id']){delete _0x2f5b10[_0x7e07('0x64')]['id'];}if(_[_0x7e07('0x9a')](_0x2f5b10[_0x7e07('0x64')]['from'])){throw new db[(_0x7e07('0x79'))][(_0x7e07('0x7a'))](_0x7e07('0x9b'));}if(_[_0x7e07('0x9a')](_0x2f5b10['body']['body'])||_0x2f5b10[_0x7e07('0x64')][_0x7e07('0x64')]===''){throw new db[(_0x7e07('0x79'))][(_0x7e07('0x7a'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0x7e07('0x9a')](_0x2f5b10[_0x7e07('0x64')]['mapKey'])){throw new db[(_0x7e07('0x79'))][(_0x7e07('0x7a'))](_0x7e07('0x9c')+_0x367735);}if(!_[_0x7e07('0x9d')](_0x367735,_0x2f5b10['body']['mapKey'])){throw new db['Sequelize'][(_0x7e07('0x7a'))](_0x7e07('0x9e')+_0x367735);}_0x35204d[_0x2f5b10['body']['mapKey']]=_0x2f5b10[_0x7e07('0x64')][_0x7e07('0x88')];return db[_0x7e07('0x9f')]['find']({'where':{'id':_0x2f5b10[_0x7e07('0x78')]['ListId']},'include':[{'model':db[_0x7e07('0xa0')],'as':_0x7e07('0xa1'),'where':_0x35204d,'limit':0x1,'order':[[_0x7e07('0x7e'),_0x7e07('0xa2')]]}]});})['then'](handleEntityNotFound(_0x54c3d9,null))['then'](function(_0x21af7e){if(_0x21af7e){_0x2f5b10[_0x7e07('0xa3')]=_['omit'](_0x21af7e,[_0x7e07('0xa1')]);if(_0x21af7e[_0x7e07('0xa1')]['length']){return _0x21af7e[_0x7e07('0xa1')][0x0];}var _0x20922b=_[_0x7e07('0x1a')](_0x2f5b10['body'],{'firstName':_0x2f5b10[_0x7e07('0x64')][_0x7e07('0x88')],'ListId':_0x21af7e['id']});_0x20922b[_0x2f5b10[_0x7e07('0x64')][_0x7e07('0xa4')]]=_0x2f5b10['body']['from'];return db[_0x7e07('0xa0')][_0x7e07('0x5b')](_0x20922b,{'fields':_0x2fdd4e,'raw':!![]});}})[_0x7e07('0x23')](handleEntityNotFound(_0x54c3d9,null))[_0x7e07('0x23')](function(_0x712e12){if(_0x712e12){_0x2f5b10[_0x7e07('0xa5')]=_0x712e12;var _0x2b5aa9={'ContactId':_0x712e12['id'],'phone':_0x2f5b10[_0x7e07('0x64')][_0x7e07('0x88')],'SmsAccountId':_0x81fbc2['params']['id']};var _0x48f3f1={'ContactId':_0x712e12['id'],'SmsAccountId':_0x81fbc2[_0x7e07('0x66')]['id'],'closed':![]};return db[_0x7e07('0xa6')]['find']({'where':_0x48f3f1})[_0x7e07('0x23')](function(_0x2e460c){if(_0x2e460c){return[_0x2e460c,![]];}return db[_0x7e07('0xa6')]['create'](_0x2b5aa9)[_0x7e07('0x23')](function(_0x2d75fe){return[_0x2d75fe,!![]];});});}})[_0x7e07('0xa7')](function(_0x42b730,_0x1ab23f){_0x2f5b10[_0x7e07('0xa8')]=_0x42b730['get']({'plain':!![]});_0x2f5b10[_0x7e07('0xa8')][_0x7e07('0xa9')]=![];if(_0x1ab23f){if(_0x2f5b10[_0x7e07('0x78')][_0x7e07('0xaa')]){_0x2f5b10[_0x7e07('0x73')][_0x7e07('0xab')]({'id':0x0,'priority':_0x2f5b10[_0x7e07('0x73')][_0x7e07('0x47')]+0x1,'app':_0x7e07('0xac'),'appdata':_0x7e07('0xad'),'interval':_0x7e07('0xae')});}_0x2f5b10[_0x7e07('0xa8')][_0x7e07('0xa9')]=!![];}return db[_0x7e07('0xaf')][_0x7e07('0x5b')]({'phone':_0x2f5b10[_0x7e07('0x64')]['from'],'messageId':_0x2f5b10['body'][_0x7e07('0x85')],'body':_0x2f5b10[_0x7e07('0x64')][_0x7e07('0x64')],'SmsAccountId':_0x81fbc2[_0x7e07('0x66')]['id'],'SmsInteractionId':_0x42b730['id'],'direction':'in','ContactId':_0x42b730[_0x7e07('0xb0')],'AttachmentId':_0x2f5b10[_0x7e07('0x64')][_0x7e07('0xb1')]});})[_0x7e07('0x23')](function(_0x52efa4){_0x2f5b10[_0x7e07('0x2b')]=_0x52efa4;if(_0x2f5b10[_0x7e07('0xa8')][_0x7e07('0xb2')]){return db['User'][_0x7e07('0x65')]({'attributes':['id','name'],'where':{'id':_0x2f5b10[_0x7e07('0xa8')]['UserId']}})[_0x7e07('0x23')](function(_0x59687e){if(_0x59687e){_0x2f5b10['applications']['unshift']({'id':0x0,'priority':0x0,'app':'agent','appdata':_0x59687e[_0x7e07('0x3a')]+','+(_0x2f5b10['account'][_0x7e07('0xb3')]||0xa),'interval':_0x7e07('0xae')});}return respondWithRpcPromise(_0x7e07('0xb4'),'startRouting',_0x2f5b10);});}return respondWithRpcPromise('Start',_0x7e07('0xb5'),_0x2f5b10);})[_0x7e07('0x23')](function(_0x3717ff){if(_0x3717ff){var _0x341e0f=0xc8;var _0x11408a=_0x7e07('0xb6');logger[_0x7e07('0x24')](_0x7e07('0xb7'),_0x11408a,_0x341e0f,_0x7e07('0xb8'));logger['debug'](_0x7e07('0xb9'),_0x11408a,_0x341e0f,_0x7e07('0xb8'),JSON[_0x7e07('0x27')](_0x3717ff));if(_0x2f5b10[_0x7e07('0x78')]['type']==='twilio'){return _0x54c3d9[_0x7e07('0x2e')](_0x341e0f)[_0x7e07('0x34')](_0x7e07('0xba'),_0x7e07('0xbb'))['send'](_0x7e07('0xbc'));}else{return _0x54c3d9[_0x7e07('0x2e')](_0x341e0f)[_0x7e07('0x30')](_0x3717ff);}}})[_0x7e07('0x57')](handleError(_0x54c3d9,null));};exports[_0x7e07('0xbd')]=function(_0x277052,_0x3b3fa6){var _0x25a1b2=_0x277052[_0x7e07('0x66')]['id'];var _0xa668b4=_0x277052['body'];var _0x2e229b=0xc8;var _0x5aed41=null;return db[_0x7e07('0xbe')][_0x7e07('0xbf')]({'isolationLevel':db[_0x7e07('0xbe')][_0x7e07('0xc0')]['ISOLATION_LEVELS'][_0x7e07('0xc1')]},function(_0xa72581){return db[_0x7e07('0x3e')]['findOne']({'where':{'id':_0x25a1b2},'transaction':_0xa72581})['then'](function(_0x145753){if(_0x145753){return db[_0x7e07('0x72')]['destroy']({'where':{'SmsAccountId':_0x25a1b2},'transaction':_0xa72581})[_0x7e07('0x23')](function(){var _0x536146=_[_0x7e07('0x3d')](_0xa668b4,function(_0x5efdf8){_0x5efdf8['SmsAccountId']=_0x25a1b2;return _0x5efdf8;});return db[_0x7e07('0x72')][_0x7e07('0xc2')](_0x536146,{'transaction':_0xa72581});});}else{_0x2e229b=0x194;_0x5aed41=[];}});})[_0x7e07('0x23')](function(){if(_0x2e229b!==0x194){return db[_0x7e07('0x72')]['findAndCountAll']({'where':{'SmsAccountId':_0x25a1b2},'order':_0x7e07('0x76')})[_0x7e07('0x23')](function(_0x3683d1){_0x5aed41=_0x3683d1;});}})[_0x7e07('0x57')](function(_0x11d3ab){_0x2e229b=0x1f4;logger[_0x7e07('0x28')](_0x11d3ab[_0x7e07('0xc3')]);if(_0x11d3ab[_0x7e07('0x3a')]){delete _0x11d3ab[_0x7e07('0x3a')];}_0x5aed41=_0x11d3ab;})[_0x7e07('0xc4')](function(){if(_0x5aed41===null){_0x3b3fa6[_0x7e07('0x2d')](_0x2e229b);}else{if(_0x2e229b===0x1f4){_0x3b3fa6['status'](_0x2e229b)[_0x7e07('0xc5')](_0x5aed41);}else{_0x3b3fa6[_0x7e07('0x2e')](_0x2e229b)[_0x7e07('0x30')](_0x5aed41);}}});};exports['getApplications']=function(_0x17764d,_0x24f98f,_0x85d571){var _0x5e6642={};var _0x3c2225={};var _0x3ca5ca;var _0x53ae2c;return db[_0x7e07('0x3e')][_0x7e07('0x6e')]({'where':{'id':_0x17764d[_0x7e07('0x66')]['id']}})[_0x7e07('0x23')](handleEntityNotFound(_0x24f98f,null))[_0x7e07('0x23')](function(_0x3888a8){if(_0x3888a8){_0x3ca5ca=_0x3888a8;_0x3c2225['model']=_[_0x7e07('0x5a')](db[_0x7e07('0x72')][_0x7e07('0x3f')]);_0x3c2225[_0x7e07('0x43')]=_['keys'](_0x17764d[_0x7e07('0x43')]);_0x3c2225['filters']=_[_0x7e07('0x44')](_0x3c2225[_0x7e07('0x42')],_0x3c2225['query']);_0x5e6642[_0x7e07('0x45')]=_[_0x7e07('0x44')](_0x3c2225[_0x7e07('0x42')],qs[_0x7e07('0x46')](_0x17764d[_0x7e07('0x43')]['fields']));_0x5e6642[_0x7e07('0x45')]=_0x5e6642[_0x7e07('0x45')][_0x7e07('0x47')]?_0x5e6642[_0x7e07('0x45')]:_0x3c2225[_0x7e07('0x42')];_0x5e6642[_0x7e07('0x4a')]=qs[_0x7e07('0x4b')](_0x17764d[_0x7e07('0x43')]['sort']);_0x5e6642[_0x7e07('0x4f')]=qs['filters'](_[_0x7e07('0x4d')](_0x17764d[_0x7e07('0x43')],_0x3c2225['filters']));if(_0x17764d['query'][_0x7e07('0x4e')]){_0x5e6642[_0x7e07('0x4f')]=_['merge'](_0x5e6642[_0x7e07('0x4f')],{'$or':_[_0x7e07('0x3d')](_0x5e6642[_0x7e07('0x45')],function(_0x441ebc){var _0x2c8335={};_0x2c8335[_0x441ebc]={'$like':'%'+_0x17764d[_0x7e07('0x43')][_0x7e07('0x4e')]+'%'};return _0x2c8335;})});}_0x5e6642=_[_0x7e07('0x50')]({},_0x5e6642,_0x17764d[_0x7e07('0x52')]);return _0x3ca5ca[_0x7e07('0xc6')](_0x5e6642);}})['then'](function(_0x551b64){if(_0x551b64){_0x53ae2c=_0x551b64[_0x7e07('0x47')];if(!_0x17764d[_0x7e07('0x43')]['hasOwnProperty'](_0x7e07('0x49'))){_0x5e6642[_0x7e07('0x32')]=qs[_0x7e07('0x32')](_0x17764d[_0x7e07('0x43')][_0x7e07('0x32')]);_0x5e6642['offset']=qs[_0x7e07('0x33')](_0x17764d['query']['offset']);}return _0x3ca5ca[_0x7e07('0xc6')](_0x5e6642);}})[_0x7e07('0x23')](function(_0x53bba4){if(_0x53bba4){return _0x53bba4?{'count':_0x53ae2c,'rows':_0x53bba4}:null;}})['then'](respondWithResult(_0x24f98f,null))[_0x7e07('0x57')](handleError(_0x24f98f,null));};exports[_0x7e07('0xc7')]=function(_0x1e187e,_0x3cd966,_0x467649){var _0x35964b={'raw':![],'where':{}};var _0x4da31={};var _0xa7986d={'count':0x0,'rows':[]};return db[_0x7e07('0x3e')]['findOne']({'where':{'id':_0x1e187e['params']['id']}})[_0x7e07('0x23')](handleEntityNotFound(_0x3cd966,null))[_0x7e07('0x23')](function(_0x3161fc){if(_0x3161fc){_0x4da31['model']=_['keys'](db[_0x7e07('0xa6')][_0x7e07('0x3f')]);_0x4da31[_0x7e07('0x43')]=_['keys'](_0x1e187e['query']);_0x4da31[_0x7e07('0x4c')]=_[_0x7e07('0x44')](_0x4da31[_0x7e07('0x42')],_0x4da31[_0x7e07('0x43')]);_0x35964b[_0x7e07('0x45')]=_[_0x7e07('0x44')](_0x4da31['model'],qs[_0x7e07('0x46')](_0x1e187e[_0x7e07('0x43')][_0x7e07('0x46')]));_0x35964b[_0x7e07('0x45')]=_0x35964b[_0x7e07('0x45')]['length']?_0x35964b['attributes']:_0x4da31[_0x7e07('0x42')];if(!_0x1e187e[_0x7e07('0x43')][_0x7e07('0x48')](_0x7e07('0x49'))){_0x35964b[_0x7e07('0x32')]=qs[_0x7e07('0x32')](_0x1e187e[_0x7e07('0x43')][_0x7e07('0x32')]);_0x35964b['offset']=qs[_0x7e07('0x33')](_0x1e187e[_0x7e07('0x43')][_0x7e07('0x33')]);}_0x35964b[_0x7e07('0x4a')]=qs[_0x7e07('0x4b')](_0x1e187e['query']['sort']);_0x35964b[_0x7e07('0x4f')]=qs[_0x7e07('0x4c')](_[_0x7e07('0x4d')](_0x1e187e[_0x7e07('0x43')],_0x4da31[_0x7e07('0x4c')]));_0x35964b['where'][_0x7e07('0x69')]=_0x3161fc['id'];if(_0x1e187e[_0x7e07('0x43')][_0x7e07('0x4e')]){_0x35964b[_0x7e07('0x4f')]=_['merge'](_0x35964b[_0x7e07('0x4f')],{'$or':_['map'](_0x35964b[_0x7e07('0x45')],function(_0x10b87b){var _0x2ba7c3={};_0x2ba7c3[_0x10b87b]={'$like':'%'+_0x1e187e[_0x7e07('0x43')][_0x7e07('0x4e')]+'%'};return _0x2ba7c3;})});}_0x35964b=_['merge']({},_0x35964b,_0x1e187e[_0x7e07('0x52')]);return db[_0x7e07('0xa6')][_0x7e07('0x53')]({'where':_0x35964b[_0x7e07('0x4f')]})[_0x7e07('0x23')](function(_0x5decf3){_0xa7986d[_0x7e07('0x53')]=_0x5decf3;if(_0x1e187e[_0x7e07('0x43')][_0x7e07('0x6b')]){_0x35964b[_0x7e07('0x54')]=[{'model':db[_0x7e07('0xa0')],'as':_0x7e07('0xc8'),'required':![]},{'model':db[_0x7e07('0xc9')],'as':_0x7e07('0xca'),'attributes':[_0x7e07('0x3a'),_0x7e07('0xcb'),'internal'],'required':![]},{'model':db[_0x7e07('0xcc')],'as':_0x7e07('0xcd'),'attributes':['id',_0x7e07('0x3a'),_0x7e07('0xce')],'where':_0x1e187e[_0x7e07('0x43')][_0x7e07('0xcf')]?{'id':_0x1e187e['query'][_0x7e07('0xcf')]}:undefined,'required':_0x1e187e['query'][_0x7e07('0xcf')]?!![]:![]}];}return db[_0x7e07('0xa6')][_0x7e07('0x55')](_0x35964b);})[_0x7e07('0x23')](function(_0x29d59a){_0xa7986d['rows']=_0x29d59a;return _0xa7986d;});}})[_0x7e07('0x23')](respondWithFilteredResult(_0x3cd966,_0x35964b))[_0x7e07('0x57')](handleError(_0x3cd966,null));};exports[_0x7e07('0xc5')]=function(_0x4cd4a9,_0x472173,_0x17833d){var _0x2398a9,_0x4ad46e,_0x4e2fed;if(_['isNil'](_0x4cd4a9['body'][_0x7e07('0x64')])||_0x4cd4a9[_0x7e07('0x64')]['body']===''){throw new db[(_0x7e07('0x79'))]['ValidationError'](_0x7e07('0xd0'));}if(_['isNil'](_0x4cd4a9[_0x7e07('0x64')]['to'])){throw new db[(_0x7e07('0x79'))][(_0x7e07('0x7a'))](_0x7e07('0xd1'));}_0x2398a9=_0x4cd4a9[_0x7e07('0x64')]['to'];return db['SmsAccount']['find']({'where':{'id':_0x4cd4a9['params']['id']},'include':[{'model':db[_0x7e07('0x9f')],'as':_0x7e07('0xd2'),'include':[{'model':db[_0x7e07('0xa0')],'as':'Contacts','where':{'mobile':_0x2398a9},'limit':0x1,'order':[['updatedAt','DESC']]}]}]})['then'](handleEntityNotFound(_0x472173,null))['then'](function(_0x1d2746){if(_0x1d2746&&_0x1d2746[_0x7e07('0xd2')]){_0x4ad46e=_0x1d2746[_0x7e07('0x39')]({'plain':!![]});if(_0x4ad46e[_0x7e07('0xd2')]&&_0x4ad46e[_0x7e07('0xd2')]['Contacts'][_0x7e07('0x47')]){return _0x4ad46e[_0x7e07('0xd2')]['Contacts'][0x0];}return db[_0x7e07('0xa0')]['create'](_[_0x7e07('0x1a')](_0x4cd4a9[_0x7e07('0x64')],{'firstName':_0x2398a9,'mobile':_0x2398a9,'phone':_0x2398a9,'ListId':_0x4ad46e['ListId']}));}})['then'](handleEntityNotFound(_0x472173,null))[_0x7e07('0x23')](function(_0x2aae04){if(_0x2aae04){_0x4e2fed=_0x2aae04;return db['SmsInteraction'][_0x7e07('0x65')]({'where':{'ContactId':_0x4e2fed['id'],'closed':![],'SmsAccountId':_0x4ad46e['id']}})[_0x7e07('0x23')](function(_0x4ecfce){if(_0x4ecfce){return[_0x4ecfce,![]];}return db[_0x7e07('0xa6')]['create']({'UserId':_0x4cd4a9[_0x7e07('0x5c')]['id'],'ContactId':_0x4e2fed['id'],'SmsAccountId':_0x4ad46e['id'],'phone':_0x2398a9,'firstMsgDirection':_0x7e07('0xd3'),'Messages':[_[_0x7e07('0x50')](_0x4cd4a9['body'],{'read':![],'body':_0x4cd4a9[_0x7e07('0x64')][_0x7e07('0x64')],'phone':_0x2398a9,'SmsAccountId':_0x4ad46e['id'],'UserId':_0x4cd4a9['user']['id'],'ContactId':_0x4e2fed['id']})]},{'include':[{'model':db[_0x7e07('0xaf')],'as':'Messages'}]})[_0x7e07('0x23')](function(_0x2b35ce){return[_0x2b35ce,!![]];});});}})[_0x7e07('0xa7')](function(_0x19fe48,_0x1aaab5){if(_0x1aaab5){return _0x19fe48;}return db[_0x7e07('0xaf')]['create'](_[_0x7e07('0x50')](_0x4cd4a9[_0x7e07('0x64')],{'read':![],'body':_0x4cd4a9['body']['body'],'phone':_0x2398a9,'SmsAccountId':_0x4ad46e['id'],'SmsInteractionId':_0x19fe48['id'],'UserId':_0x4cd4a9[_0x7e07('0x5c')]['id'],'ContactId':_0x4e2fed['id']}))[_0x7e07('0x23')](function(_0x3440e9){_0x19fe48[_0x7e07('0xd4')][_0x7e07('0xd5')]=[];_0x19fe48['dataValues'][_0x7e07('0xd5')][_0x7e07('0xab')](_0x3440e9[_0x7e07('0xd4')]);return _0x19fe48;});})['then'](respondWithResult(_0x472173,null))['catch'](handleError(_0x472173,null));};exports[_0x7e07('0x2e')]=function(_0x3e5631,_0x28a9ca,_0x414788){if(_0x3e5631[_0x7e07('0x64')]['id']){delete _0x3e5631[_0x7e07('0x64')]['id'];}var _0x1019d0,_0x3f94ae,_0x6f2262;return db[_0x7e07('0x3e')]['find']({'where':{'id':_0x3e5631[_0x7e07('0x66')]['id']}})['then'](handleEntityNotFound(_0x28a9ca,null))[_0x7e07('0x23')](function(_0x104a9e){if(_0x104a9e){_0x6f2262=_0x104a9e;logger['debug'](_0x7e07('0xb7'),_0x7e07('0x2e'),'received\x20delivery\x20report\x20from',_0x104a9e['type'],util['inspect'](_0x3e5631[_0x7e07('0x64')],{'showHidden':![],'depth':null}));switch(_0x104a9e[_0x7e07('0x40')]){case'skebby':if(_0x3e5631['body']['skebby_dispatch_id']&&_0x3e5631[_0x7e07('0x64')][_0x7e07('0x2e')]){_0x3f94ae=_0x3e5631['body'][_0x7e07('0x2e')];return db['SmsMessage']['find']({'where':{'messageId':_0x3e5631[_0x7e07('0x64')][_0x7e07('0xd6')]}});}break;case'connectel':if(_0x3e5631[_0x7e07('0x64')][_0x7e07('0xd7')]&&_0x3e5631[_0x7e07('0x64')][_0x7e07('0xd8')]){_0x3f94ae=_0x3e5631[_0x7e07('0x64')][_0x7e07('0xd8')];return db[_0x7e07('0xaf')]['find']({'where':{'messageId':_0x3e5631[_0x7e07('0x64')][_0x7e07('0xd7')]}});}break;case _0x7e07('0xd9'):if(_0x3e5631[_0x7e07('0x64')][_0x7e07('0x8b')]&&_0x3e5631[_0x7e07('0x64')][_0x7e07('0xda')]){_0x3f94ae=_0x3e5631[_0x7e07('0x64')][_0x7e07('0xda')];return db[_0x7e07('0xaf')][_0x7e07('0x65')]({'where':{'messageId':_0x3e5631[_0x7e07('0x64')]['message_id']}});}break;case _0x7e07('0x8f'):var _0x1f81f8=_0x3e5631[_0x7e07('0x64')][_0x7e07('0x90')][0x0];if(_0x1f81f8['messageId']&&_0x1f81f8['status'][_0x7e07('0xdb')]===_0x7e07('0xdc')){_0x3f94ae=_0x1f81f8[_0x7e07('0x2e')][_0x7e07('0xdb')];return db[_0x7e07('0xaf')]['find']({'where':{'messageId':_0x1f81f8[_0x7e07('0x85')]}});}break;case _0x7e07('0x95'):if(_0x3e5631[_0x7e07('0x64')][_0x7e07('0x85')]&&_0x3e5631[_0x7e07('0x64')][_0x7e07('0x2e')]){_0x3f94ae=_0x3e5631[_0x7e07('0x64')]['status'];return db[_0x7e07('0xaf')][_0x7e07('0x65')]({'where':{'messageId':_0x3e5631['body']['messageId']}});}break;case _0x7e07('0xdd'):if(_0x3e5631[_0x7e07('0x64')][0x0][_0x7e07('0x2b')]['id']){_0x3f94ae=_0x3e5631[_0x7e07('0x64')][0x0][_0x7e07('0x40')];return db[_0x7e07('0xaf')]['find']({'where':{'messageId':_0x3e5631[_0x7e07('0x64')][0x0][_0x7e07('0x2b')]['id']}});}break;case _0x7e07('0x98'):if(_0x3e5631[_0x7e07('0x64')][_0x7e07('0xde')]&&_0x3e5631['body'][_0x7e07('0x2e')]){_0x3f94ae=_0x3e5631[_0x7e07('0x64')]['status'];return db[_0x7e07('0xaf')][_0x7e07('0x65')]({'where':{'messageId':_0x3e5631[_0x7e07('0x64')][_0x7e07('0xde')]}});}break;}}})[_0x7e07('0x23')](handleEntityNotFound(_0x28a9ca,null))['then'](function(_0x1125d5){if(_0x1125d5){_0x1019d0=_0x1125d5;switch(_0x6f2262[_0x7e07('0x40')]){case _0x7e07('0x87'):if(_0x3f94ae===_0x7e07('0xdc')){return _0x1019d0['update']({'read':!![]});}else{logger[_0x7e07('0x28')](_0x7e07('0xb7'),_0x7e07('0x2e'),_0x7e07('0x87'),util[_0x7e07('0xdf')](_0x3e5631[_0x7e07('0x64')],{'showHidden':![],'depth':null}));}break;case'connectel':if(_0x3f94ae==='1'){return _0x1019d0[_0x7e07('0x37')]({'read':!![]});}else{logger[_0x7e07('0x28')](_0x7e07('0xb7'),_0x7e07('0x2e'),'skebby',util['inspect'](_0x3e5631[_0x7e07('0x64')],{'showHidden':![],'depth':null}));}break;case _0x7e07('0xd9'):if(!_0x3e5631[_0x7e07('0x64')][_0x7e07('0xe0')]&&_0x3f94ae>=0xc8&&_0x3f94ae<=0xce){return _0x1019d0[_0x7e07('0x37')]({'read':!![]});}else{logger[_0x7e07('0x28')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x7e07('0x2e'),_0x7e07('0xd9'),util[_0x7e07('0xdf')](_0x3e5631[_0x7e07('0x64')],{'showHidden':![],'depth':null}));}break;case _0x7e07('0x8f'):var _0x5824fb=_0x3e5631[_0x7e07('0x64')]['results'][0x0];if(_0x5824fb[_0x7e07('0x2e')]['groupName']===_0x7e07('0xdc')){return _0x1019d0['update']({'read':!![]});}else{logger['error'](_0x7e07('0xb7'),_0x7e07('0x2e'),'infobip',util[_0x7e07('0xdf')](_0x3e5631['body'],{'showHidden':![],'depth':null}));}break;case _0x7e07('0x95'):if(_0x3f94ae==_0x7e07('0xe1')||_0x3f94ae==_0x7e07('0xe2')){return _0x1019d0[_0x7e07('0x37')]({'read':!![]});}else{logger[_0x7e07('0x28')](_0x7e07('0xb7'),_0x7e07('0x2e'),_0x7e07('0x95'),util[_0x7e07('0xdf')](_0x3e5631[_0x7e07('0x64')],{'showHidden':![],'depth':null}));}break;case _0x7e07('0xdd'):if(_0x3f94ae==_0x7e07('0xe3')){return _0x1019d0['update']({'read':!![]});}else{logger['error'](_0x7e07('0xb7'),_0x7e07('0x2e'),_0x7e07('0xdd'),util['inspect'](_0x3e5631[_0x7e07('0x64')],{'showHidden':![],'depth':null}));}break;case _0x7e07('0x98'):if(_0x3f94ae===_0x7e07('0xe4')||_0x3f94ae===_0x7e07('0xe5')){return _0x1019d0[_0x7e07('0x37')]({'read':!![]});}else{logger[_0x7e07('0x28')](_0x7e07('0xb7'),_0x7e07('0x2e'),'intelepeer',util[_0x7e07('0xdf')](_0x3e5631[_0x7e07('0x64')],{'showHidden':![],'depth':null}));}break;}return _0x1019d0;}})[_0x7e07('0x23')](respondWithResult(_0x28a9ca,null))[_0x7e07('0x57')](handleError(_0x28a9ca,null));};exports['statusGet']=function(_0x576e43,_0x34947b,_0x1fe63b){var _0x3a848b,_0x3f5775,_0x496d46;return db[_0x7e07('0x3e')]['find']({'where':{'id':_0x576e43[_0x7e07('0x66')]['id']}})['then'](handleEntityNotFound(_0x34947b,null))[_0x7e07('0x23')](function(_0x572976){if(_0x572976){_0x496d46=_0x572976;logger[_0x7e07('0x26')](_0x7e07('0xb7'),_0x7e07('0x2e'),_0x7e07('0xe6'),_0x572976[_0x7e07('0x40')],util['inspect'](_0x576e43[_0x7e07('0x43')],{'showHidden':![],'depth':null}));switch(_0x572976[_0x7e07('0x40')]){case _0x7e07('0x92'):if(_0x576e43['query'][_0x7e07('0xe7')]&&_0x576e43['query'][_0x7e07('0xe8')]){_0x3f5775=_0x576e43['query'][_0x7e07('0xe8')];return db[_0x7e07('0xaf')]['find']({'where':{'messageId':_0x576e43[_0x7e07('0x43')][_0x7e07('0xe7')]}});}break;}}})[_0x7e07('0x23')](handleEntityNotFound(_0x34947b,null))[_0x7e07('0x23')](function(_0x1b8f87){if(_0x1b8f87){_0x3a848b=_0x1b8f87;switch(_0x496d46[_0x7e07('0x40')]){case _0x7e07('0x92'):if(_0x3f5775==='2'||_0x3f5775==='6'){return _0x3a848b[_0x7e07('0x37')]({'read':!![]});}else{logger[_0x7e07('0x28')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x7e07('0x2e'),_0x7e07('0x92'),util[_0x7e07('0xdf')](_0x576e43[_0x7e07('0x43')],{'showHidden':![],'depth':null}));};break;}return _0x3a848b;}})[_0x7e07('0x23')](respondWithResult(_0x34947b,null))['catch'](handleError(_0x34947b,null));};exports[_0x7e07('0xe9')]=function(_0x460b4a,_0x214ec2,_0x5eb107){return db[_0x7e07('0x3e')]['find']({'where':{'id':_0x460b4a[_0x7e07('0x66')]['id']}})[_0x7e07('0x23')](handleEntityNotFound(_0x214ec2,null))[_0x7e07('0x23')](function(_0xa853b4){if(_0xa853b4){return _0xa853b4[_0x7e07('0xe9')](_0x460b4a[_0x7e07('0x64')][_0x7e07('0xea')],_[_0x7e07('0xeb')](_0x460b4a[_0x7e07('0x64')],[_0x7e07('0xea'),'id'])||{})[_0x7e07('0xa7')](function(_0x3f3e3a){for(var _0xfa7143=0x0;_0xfa7143<_0x460b4a[_0x7e07('0x64')]['ids']['length'];_0xfa7143+=0x1){socket[_0x7e07('0xec')]('userSmsAccount:save',{'UserId':Number(_0x460b4a[_0x7e07('0x64')][_0x7e07('0xea')][_0xfa7143]),'SmsAccountId':Number(_0x460b4a[_0x7e07('0x66')]['id'])});}return _0x3f3e3a;});}})[_0x7e07('0x23')](respondWithResult(_0x214ec2,null))[_0x7e07('0x57')](handleError(_0x214ec2,null));};exports['removeAgents']=function(_0x411c9f,_0x4ba545,_0x4ca7e3){return db[_0x7e07('0x3e')][_0x7e07('0x65')]({'where':{'id':_0x411c9f[_0x7e07('0x66')]['id']}})[_0x7e07('0x23')](handleEntityNotFound(_0x4ba545,null))[_0x7e07('0x23')](function(_0x3e558c){if(_0x3e558c){return _0x3e558c['removeAgents'](_0x411c9f['query']['ids'])[_0x7e07('0x23')](function(){if(_[_0x7e07('0xed')](_0x411c9f[_0x7e07('0x43')]['ids'])){for(var _0x31642e=0x0;_0x31642e<_0x411c9f[_0x7e07('0x43')][_0x7e07('0xea')][_0x7e07('0x47')];_0x31642e+=0x1){socket[_0x7e07('0xec')](_0x7e07('0xee'),{'UserId':Number(_0x411c9f[_0x7e07('0x43')][_0x7e07('0xea')][_0x31642e]),'SmsAccountId':Number(_0x411c9f[_0x7e07('0x66')]['id'])});}}else{socket['emit']('userSmsAccount:remove',{'UserId':Number(_0x411c9f[_0x7e07('0x43')][_0x7e07('0xea')]),'SmsAccountId':Number(_0x411c9f['params']['id'])});}});}})['then'](respondWithStatusCode(_0x4ba545,null))[_0x7e07('0x57')](handleError(_0x4ba545,null));};exports[_0x7e07('0xef')]=function(_0x434002,_0x414c49,_0x2b6a67){var _0x179a92={};var _0x43187a={};var _0x5a5ece;var _0x189aae;return db[_0x7e07('0x3e')][_0x7e07('0x6e')]({'where':{'id':_0x434002[_0x7e07('0x66')]['id']}})[_0x7e07('0x23')](handleEntityNotFound(_0x414c49,null))[_0x7e07('0x23')](function(_0xdf2154){if(_0xdf2154){_0x5a5ece=_0xdf2154;_0x43187a[_0x7e07('0x42')]=_[_0x7e07('0x5a')](db['User'][_0x7e07('0x3f')]);_0x43187a[_0x7e07('0x43')]=_['keys'](_0x434002[_0x7e07('0x43')]);_0x43187a[_0x7e07('0x4c')]=_[_0x7e07('0x44')](_0x43187a[_0x7e07('0x42')],_0x43187a[_0x7e07('0x43')]);_0x179a92[_0x7e07('0x45')]=_['intersection'](_0x43187a[_0x7e07('0x42')],qs[_0x7e07('0x46')](_0x434002[_0x7e07('0x43')][_0x7e07('0x46')]));_0x179a92[_0x7e07('0x45')]=_0x179a92[_0x7e07('0x45')]['length']?_0x179a92[_0x7e07('0x45')]:_0x43187a[_0x7e07('0x42')];_0x179a92[_0x7e07('0x4a')]=qs[_0x7e07('0x4b')](_0x434002[_0x7e07('0x43')]['sort']);_0x179a92['where']=qs[_0x7e07('0x4c')](_[_0x7e07('0x4d')](_0x434002[_0x7e07('0x43')],_0x43187a[_0x7e07('0x4c')]));if(_0x434002[_0x7e07('0x43')][_0x7e07('0x4e')]){_0x179a92[_0x7e07('0x4f')]=_[_0x7e07('0x50')](_0x179a92['where'],{'$or':_['map'](_0x179a92['attributes'],function(_0x28ad48){var _0x2bc6bb={};_0x2bc6bb[_0x28ad48]={'$like':'%'+_0x434002[_0x7e07('0x43')][_0x7e07('0x4e')]+'%'};return _0x2bc6bb;})});}_0x179a92=_['merge']({},_0x179a92,_0x434002[_0x7e07('0x52')]);return _0x5a5ece[_0x7e07('0xef')](_0x179a92);}})[_0x7e07('0x23')](function(_0x3f6b1a){if(_0x3f6b1a){_0x189aae=_0x3f6b1a['length'];if(!_0x434002[_0x7e07('0x43')][_0x7e07('0x48')](_0x7e07('0x49'))){_0x179a92['limit']=qs[_0x7e07('0x32')](_0x434002[_0x7e07('0x43')]['limit']);_0x179a92[_0x7e07('0x33')]=qs[_0x7e07('0x33')](_0x434002[_0x7e07('0x43')]['offset']);}return _0x5a5ece['getAgents'](_0x179a92);}})[_0x7e07('0x23')](function(_0x29ee65){if(_0x29ee65){return _0x29ee65?{'count':_0x189aae,'rows':_0x29ee65}:null;}})[_0x7e07('0x23')](respondWithResult(_0x414c49,null))[_0x7e07('0x57')](handleError(_0x414c49,null));};
\ No newline at end of file