Built motion from commit f861bcb808219e66da88ba48b61bddb35224a65e. Version 3.0.0...
[motion-next.git] / server / api / smsAccount / smsAccount.controller.js
1 'use strict';const a642_0x1b22=['role','CannedAnswer','account','keys','index','emit','stringify','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','undefined','connectel','count','Applications','51AdJtfC','omit','Body','key','status_code','1517ewbhWQ','Content-Type','message-id','DELIVRD','unmanaged','addDisposition','bandwidth','@rediscache','<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>','242950zWtpPk','fields','Contacts','SmsAccount','find','refid','SmsApplication','mobile','http','User','findAll','DESC','userProfileId','result','updatedAt','sort','type','SmsAccount,\x20%s,\x20%s,\x20%s','client','end','includeAll','get','intersection','text','Disposition','@components/parsers/qs','agent','appdata','include','create','json','addAnswer','col','to\x20is\x20mandatory','skebby','userSmsAccount:remove','Unable\x20to\x20retrieve\x20the\x20current\x20user','waitForTheAssignedAgent','UserProfileResource','getDispositions','clicksend','DELIVERED','update','plivo','merge','addAgents','debug','intelepeer','1ypenKJ','destroy','startRouting','removeAnswers','14iwgOyt','mandatoryDispositionPause','SmsAccount,\x20%s,\x20%s,\x20%s,\x20%s','fieldName','tag','offset','inspect','userSmsAccount:save','received\x20delivery\x20report\x20from','transaction','error','ListId','catch','then','messageId','code','status','mapKey','getAgents','37467DngWbP','*,*,*,*','@utils/filter-attributes','from\x20is\x20mandatory','contact','request\x20sent','infobip','created','dataValues','user','notify','SmsInteraction','Pause','set','internal','UserProfileSection','List','segmentedMessage','101076KBJZhg','UserId','interaction','filters','jayson/promise','ids','rawAttributes','@config/logger','removeAgents','From','length','unshift','getInteractions','autoAssociation','addApplications','rpcRoutingPort','state','sequelize','getApplications','./smsAccount.socket','Start','text/xml','stack','SmsMessage','query','DELIVERED_TO_GATEWAY','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','request','createdAt','@config/get-config','csc','10zWwxoH','SmsAccounts','limit','model','lodash','Tag','filter','message','message_id','ContactId','redif','where','params','rows','Messages','clickatell','attributes','Content-Range','CmContact','body','fromNumber','includes','groupName','results','sendStatus','applications','Owner','CompanyId','entity\x20found','from','Contact','59545LKLozv','name','push','AttachmentId','info','api','SmsAccountId','nolimit','autoclose','map','describe','1543MlsrvW','close','CmList','SmsAccount,\x20%s,\x20%s','removeDispositions','options','findOne','asc','statusInt','Text','defaults','MessageUUID','RECEIVED_BY_RECIPIENT','priority','findAndCountAll','skebby_dispatch_id','send','510787FDwFmq','Tags','order','isNil','statusGet','fullname','pick'];const a642_0x1094=function(_0x25df86,_0x2ecb4a){_0x25df86=_0x25df86-0x19c;let _0x1b22c7=a642_0x1b22[_0x25df86];return _0x1b22c7;};const a642_0x577217=a642_0x1094;(function(_0x422772,_0x48cc1a){const _0x2bc0b7=a642_0x1094;while(!![]){try{const _0x1abdc2=parseInt(_0x2bc0b7(0x1cc))*parseInt(_0x2bc0b7(0x232))+-parseInt(_0x2bc0b7(0x1c1))*-parseInt(_0x2bc0b7(0x22e))+parseInt(_0x2bc0b7(0x1f0))*-parseInt(_0x2bc0b7(0x1f5))+parseInt(_0x2bc0b7(0x1a2))*-parseInt(_0x2bc0b7(0x245))+parseInt(_0x2bc0b7(0x1dd))+-parseInt(_0x2bc0b7(0x257))+parseInt(_0x2bc0b7(0x1fe));if(_0x1abdc2===_0x48cc1a)break;else _0x422772['push'](_0x422772['shift']());}catch(_0x18a5ce){_0x422772['push'](_0x422772['shift']());}}}(a642_0x1b22,0x44cab));const util=require('util'),_=require(a642_0x577217(0x1a6)),qs=require(a642_0x577217(0x217)),logger=require(a642_0x577217(0x25e))(a642_0x577217(0x1c6)),{getSocket}=require(a642_0x577217(0x1fc)),socket=getSocket(),{db}=require('@mysqldb'),{ValidationError}=require('sequelize'),{filterAttributes}=require(a642_0x577217(0x247));require(a642_0x577217(0x26a))['register'](socket);const jayson=require(a642_0x577217(0x25b)),{getConfig}=require(a642_0x577217(0x1a0)),config=getConfig(),rpcRoutingClient=jayson[a642_0x577217(0x210)][a642_0x577217(0x206)]({'host':config['rpcRoutingIp'],'port':config[a642_0x577217(0x266)]});function respondWithRpcPromise(_0x3f2cfd,_0xd06c50,_0x197745,_0x1dc41b){return new Promise(function(_0x192ff1,_0x3acfb3){const _0x37df8e=a642_0x1094,_0x5da1ec=_0x1dc41b||rpcRoutingClient;return _0x5da1ec[_0x37df8e(0x19e)](_0x3f2cfd,_0x197745)[_0x37df8e(0x23f)](function(_0x556ac1){const _0x1669e8=_0x37df8e;logger[_0x1669e8(0x1c5)]('SmsAccount,\x20%s,\x20%s',_0xd06c50,'request\x20sent'),logger[_0x1669e8(0x22c)](_0x1669e8(0x20f),_0xd06c50,_0x1669e8(0x24a),JSON[_0x1669e8(0x1ea)](_0x556ac1));if(_0x556ac1[_0x1669e8(0x23c)]){if(_0x556ac1[_0x1669e8(0x23c)][_0x1669e8(0x241)]===0x1f4)return logger[_0x1669e8(0x23c)](_0x1669e8(0x1cf),_0xd06c50,_0x556ac1[_0x1669e8(0x23c)][_0x1669e8(0x1a9)]),_0x3acfb3(_0x556ac1[_0x1669e8(0x23c)][_0x1669e8(0x1a9)]);return logger[_0x1669e8(0x23c)](_0x1669e8(0x1cf),_0xd06c50,_0x556ac1[_0x1669e8(0x23c)][_0x1669e8(0x1a9)]),_0x192ff1(_0x556ac1['error'][_0x1669e8(0x1a9)]);}else logger['info'](_0x1669e8(0x1cf),_0xd06c50,'request\x20sent'),_0x192ff1(_0x556ac1[_0x1669e8(0x20b)][_0x1669e8(0x1a9)]);})[_0x37df8e(0x23e)](function(_0x2a52ce){const _0x33e462=_0x37df8e;logger[_0x33e462(0x23c)]('SmsAccount,\x20%s,\x20%s',_0xd06c50,_0x2a52ce),_0x3acfb3(_0x2a52ce);});});}function respondWithStatusCode(_0x32ff36,_0xe5f618){return _0xe5f618=_0xe5f618||0xcc,function(_0x32ea86){const _0x4f1dcd=a642_0x1094;if(_0x32ea86)return _0x32ff36[_0x4f1dcd(0x1ba)](_0xe5f618);return _0x32ff36[_0x4f1dcd(0x242)](_0xe5f618)[_0x4f1dcd(0x211)]();};}function respondWithResult(_0x158149,_0x21a8a3){return _0x21a8a3=_0x21a8a3||0xc8,function(_0x176bf1){const _0x2b23fa=a642_0x1094;if(_0x176bf1)return _0x158149[_0x2b23fa(0x242)](_0x21a8a3)['json'](_0x176bf1);};}function respondWithFilteredResult(_0x138a35,_0x282a32){return function(_0x19ee15){const _0x3b1476=a642_0x1094;if(_0x19ee15){const _0x54f0e8=_0x19ee15[_0x3b1476(0x1ee)],_0x5165e4=_0x282a32[_0x3b1476(0x237)];let _0x3d9918=_0x282a32[_0x3b1476(0x237)]+_0x282a32[_0x3b1476(0x1a4)],_0x5d2dec;return _0x3d9918>=_0x54f0e8?(_0x3d9918=_0x54f0e8,_0x5d2dec=0xc8):_0x5d2dec=0xce,_0x138a35[_0x3b1476(0x242)](_0x5d2dec),_0x138a35[_0x3b1476(0x252)](_0x3b1476(0x1b3),_0x5165e4+'-'+_0x3d9918+'/'+_0x54f0e8)[_0x3b1476(0x21c)](_0x19ee15);}return null;};}function saveUpdates(_0x18dbe7){return function(_0x296af0){const _0x25242b=a642_0x1094;if(_0x296af0)return _0x296af0[_0x25242b(0x228)](_0x18dbe7)['then'](function(_0x248c47){return _0x248c47;});return null;};}function removeEntity(_0x346609){return function(_0x1b78fc){const _0x461fda=a642_0x1094;if(_0x1b78fc)return _0x1b78fc[_0x461fda(0x22f)]()[_0x461fda(0x23f)](function(){const _0x1f7960=_0x461fda,_0x16a4b5=_0x1b78fc[_0x1f7960(0x213)]({'plain':!![]}),_0x842fef=_0x1f7960(0x1a3);return db['UserProfileResource']['destroy']({'where':{'type':_0x842fef,'resourceId':_0x16a4b5['id']}})[_0x1f7960(0x23f)](function(){return _0x1b78fc;});})[_0x461fda(0x23f)](function(){const _0x766368=_0x461fda;_0x346609['status'](0xcc)[_0x766368(0x211)]();});};}function handleEntityNotFound(_0x3081be){return function(_0x49d6e9){return!_0x49d6e9&&_0x3081be['sendStatus'](0x194),_0x49d6e9;};}function handleError(_0x145b8a,_0x366b1a){return _0x366b1a=_0x366b1a||0x1f4,function(_0x299334){const _0x355e65=a642_0x1094;logger[_0x355e65(0x23c)](_0x299334[_0x355e65(0x26d)]),_0x299334[_0x355e65(0x1c2)]&&delete _0x299334[_0x355e65(0x1c2)],_0x145b8a['status'](_0x366b1a)[_0x355e65(0x1dc)](_0x299334);};}exports[a642_0x577217(0x1e8)]=function(_0x321a79,_0x16c32b){const _0x4e7b59=a642_0x577217;let _0x1e908a={'include':[{'model':db['Pause'],'as':_0x4e7b59(0x233)}]};const _0x327364={},_0x444e66={'count':0x0,'rows':[]},_0x5d6fc4=_[_0x4e7b59(0x1ca)](db[_0x4e7b59(0x201)][_0x4e7b59(0x25d)],function(_0x21807f){const _0x5e63d9=_0x4e7b59;return{'name':_0x21807f[_0x5e63d9(0x235)],'type':_0x21807f[_0x5e63d9(0x20e)][_0x5e63d9(0x1f3)]};});_0x327364[_0x4e7b59(0x1a5)]=_[_0x4e7b59(0x1ca)](_0x5d6fc4,'name'),_0x327364['query']=_[_0x4e7b59(0x1e7)](_0x321a79[_0x4e7b59(0x26f)]),_0x327364[_0x4e7b59(0x25a)]=_['intersection'](_0x327364[_0x4e7b59(0x1a5)],_0x327364['query']),_0x1e908a[_0x4e7b59(0x1b2)]=_[_0x4e7b59(0x214)](_0x327364['model'],qs[_0x4e7b59(0x1ff)](_0x321a79[_0x4e7b59(0x26f)][_0x4e7b59(0x1ff)])),_0x1e908a[_0x4e7b59(0x1b2)]=_0x1e908a[_0x4e7b59(0x1b2)][_0x4e7b59(0x261)]?_0x1e908a[_0x4e7b59(0x1b2)]:_0x327364[_0x4e7b59(0x1a5)];typeof _0x321a79[_0x4e7b59(0x26f)][_0x4e7b59(0x1c8)]===_0x4e7b59(0x1ec)&&(_0x1e908a[_0x4e7b59(0x1a4)]=qs[_0x4e7b59(0x1a4)](_0x321a79['query']['limit']),_0x1e908a[_0x4e7b59(0x237)]=qs[_0x4e7b59(0x237)](_0x321a79[_0x4e7b59(0x26f)][_0x4e7b59(0x237)]));_0x1e908a[_0x4e7b59(0x1df)]=qs['sort'](_0x321a79[_0x4e7b59(0x26f)]['sort']),_0x1e908a[_0x4e7b59(0x1ad)]=qs[_0x4e7b59(0x25a)](_[_0x4e7b59(0x1e3)](_0x321a79[_0x4e7b59(0x26f)],_0x327364['filters']),_0x5d6fc4),_0x1e908a=filterAttributes(_0x1e908a,_0x321a79[_0x4e7b59(0x26f)][_0x4e7b59(0x1a8)],_0x5d6fc4,_0x321a79[_0x4e7b59(0x1d1)]);const _0x46001a={'where':_0x1e908a[_0x4e7b59(0x1ad)]};return db[_0x4e7b59(0x201)]['count'](_0x46001a)[_0x4e7b59(0x23f)](function(_0x28b4e1){const _0x503365=_0x4e7b59;return _0x444e66['count']=_0x28b4e1,_0x321a79[_0x503365(0x26f)][_0x503365(0x212)]&&(_0x1e908a[_0x503365(0x21a)]=[{'all':!![]}]),db[_0x503365(0x201)][_0x503365(0x208)](_0x1e908a);})[_0x4e7b59(0x23f)](function(_0x59606a){return _0x444e66['rows']=_0x59606a,_0x444e66;})['then'](respondWithFilteredResult(_0x16c32b,_0x1e908a))[_0x4e7b59(0x23e)](handleError(_0x16c32b,null));},exports['show']=function(_0x57ca3c,_0x3269dd){const _0x307cbb=a642_0x577217;let _0x308205={'raw':![],'where':{'id':_0x57ca3c[_0x307cbb(0x1ae)]['id']},'include':[{'model':db[_0x307cbb(0x251)],'as':_0x307cbb(0x233)}]};const _0x2fc79e={};return _0x2fc79e['model']=_[_0x307cbb(0x1e7)](db[_0x307cbb(0x201)][_0x307cbb(0x25d)]),_0x2fc79e[_0x307cbb(0x26f)]=_[_0x307cbb(0x1e7)](_0x57ca3c[_0x307cbb(0x26f)]),_0x2fc79e[_0x307cbb(0x25a)]=_[_0x307cbb(0x214)](_0x2fc79e[_0x307cbb(0x1a5)],_0x2fc79e[_0x307cbb(0x26f)]),_0x308205[_0x307cbb(0x1b2)]=_[_0x307cbb(0x214)](_0x2fc79e[_0x307cbb(0x1a5)],qs[_0x307cbb(0x1ff)](_0x57ca3c[_0x307cbb(0x26f)]['fields'])),_0x308205[_0x307cbb(0x1b2)]=_0x308205[_0x307cbb(0x1b2)][_0x307cbb(0x261)]?_0x308205[_0x307cbb(0x1b2)]:_0x2fc79e[_0x307cbb(0x1a5)],_0x57ca3c[_0x307cbb(0x26f)][_0x307cbb(0x212)]&&(_0x308205[_0x307cbb(0x21a)]=[{'all':!![]}]),_0x308205=_[_0x307cbb(0x22a)]({},_0x308205,_0x57ca3c['options']),db[_0x307cbb(0x201)][_0x307cbb(0x1d2)](_0x308205)[_0x307cbb(0x23f)](handleEntityNotFound(_0x3269dd,null))[_0x307cbb(0x23f)](respondWithResult(_0x3269dd,null))['catch'](handleError(_0x3269dd,null));},exports['create']=function(_0x29cbb2,_0x5224b0){const _0x1a3602=a642_0x577217;return db[_0x1a3602(0x201)][_0x1a3602(0x21b)](_0x29cbb2[_0x1a3602(0x1b5)],{})['then'](function(_0x36f6e8){const _0x4fc965=_0x1a3602,_0x15ab55=_0x29cbb2[_0x4fc965(0x24e)]['get']({'plain':!![]});if(!_0x15ab55)throw new Error(_0x4fc965(0x222));if(_0x15ab55[_0x4fc965(0x1e4)]===_0x4fc965(0x24e)){const _0x20d681=_0x36f6e8['get']({'plain':!![]}),_0x245685=_0x4fc965(0x1a3);return db[_0x4fc965(0x254)][_0x4fc965(0x1d2)]({'where':{'name':_0x245685,'userProfileId':_0x15ab55[_0x4fc965(0x20a)]},'raw':!![]})['then'](function(_0x8401e){const _0x5037c3=_0x4fc965;return _0x8401e&&_0x8401e[_0x5037c3(0x264)]===0x0?db[_0x5037c3(0x224)][_0x5037c3(0x21b)]({'name':_0x20d681[_0x5037c3(0x1c2)],'resourceId':_0x20d681['id'],'type':_0x8401e['name'],'sectionId':_0x8401e['id']},{})[_0x5037c3(0x23f)](function(){return _0x36f6e8;}):_0x36f6e8;})[_0x4fc965(0x23e)](function(_0xa076df){logger['error']('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0xa076df);throw _0xa076df;});}return _0x36f6e8;})[_0x1a3602(0x23f)](respondWithResult(_0x5224b0,0xc9))[_0x1a3602(0x23e)](handleError(_0x5224b0,null));},exports['update']=function(_0x512735,_0x46f49a){const _0x2d004c=a642_0x577217;return _0x512735[_0x2d004c(0x1b5)]['id']&&delete _0x512735[_0x2d004c(0x1b5)]['id'],db['SmsAccount']['findOne']({'where':{'id':_0x512735[_0x2d004c(0x1ae)]['id']},'include':[{'model':db[_0x2d004c(0x251)],'as':_0x2d004c(0x233)}]})[_0x2d004c(0x23f)](handleEntityNotFound(_0x46f49a,null))[_0x2d004c(0x23f)](saveUpdates(_0x512735[_0x2d004c(0x1b5)],null))['then'](respondWithResult(_0x46f49a,null))[_0x2d004c(0x23e)](handleError(_0x46f49a,null));},exports[a642_0x577217(0x22f)]=function(_0x2d7124,_0x14fdfe){const _0x531e85=a642_0x577217;return db[_0x531e85(0x201)][_0x531e85(0x1d2)]({'where':{'id':_0x2d7124[_0x531e85(0x1ae)]['id']}})[_0x531e85(0x23f)](handleEntityNotFound(_0x14fdfe,null))[_0x531e85(0x23f)](removeEntity(_0x14fdfe,null))[_0x531e85(0x23e)](handleError(_0x14fdfe,null));},exports['describe']=function(_0x167ca3,_0x5e87a6){const _0x4d5cdd=a642_0x577217;return db[_0x4d5cdd(0x201)]['describe']()[_0x4d5cdd(0x23f)](respondWithResult(_0x5e87a6,null))[_0x4d5cdd(0x23e)](handleError(_0x5e87a6,null));},exports[a642_0x577217(0x1fa)]=function(_0x249dab,_0x217a76){const _0x2f848f=a642_0x577217;return _0x249dab[_0x2f848f(0x1b5)]['id']&&delete _0x249dab['body']['id'],db[_0x2f848f(0x201)][_0x2f848f(0x1d2)]({'where':{'id':_0x249dab[_0x2f848f(0x1ae)]['id']}})['then'](handleEntityNotFound(_0x217a76,null))['then'](function(_0x38ca1f){const _0x23a1c9=_0x2f848f;if(_0x38ca1f)return _0x249dab[_0x23a1c9(0x1b5)]['SmsAccountId']=_0x38ca1f['id'],db[_0x23a1c9(0x216)][_0x23a1c9(0x21b)](_0x249dab[_0x23a1c9(0x1b5)]);})[_0x2f848f(0x23f)](respondWithResult(_0x217a76,null))['catch'](handleError(_0x217a76,null));},exports[a642_0x577217(0x225)]=function(_0x5cedac,_0x29b7df){const _0x4d20a2=a642_0x577217;let _0xc577d8={'raw':![],'where':{}};const _0x32dc0d={},_0x2196ec={'count':0x0,'rows':[]};return db[_0x4d20a2(0x201)][_0x4d20a2(0x1d2)]({'where':{'id':_0x5cedac[_0x4d20a2(0x1ae)]['id']}})[_0x4d20a2(0x23f)](handleEntityNotFound(_0x29b7df,null))[_0x4d20a2(0x23f)](function(_0x12c2a5){const _0x328c6a=_0x4d20a2;if(_0x12c2a5)return _0x32dc0d[_0x328c6a(0x1a5)]=_['keys'](db[_0x328c6a(0x216)]['rawAttributes']),_0x32dc0d[_0x328c6a(0x26f)]=_[_0x328c6a(0x1e7)](_0x5cedac[_0x328c6a(0x26f)]),_0x32dc0d[_0x328c6a(0x25a)]=_[_0x328c6a(0x214)](_0x32dc0d[_0x328c6a(0x1a5)],_0x32dc0d['query']),_0xc577d8[_0x328c6a(0x1b2)]=_[_0x328c6a(0x214)](_0x32dc0d[_0x328c6a(0x1a5)],qs['fields'](_0x5cedac[_0x328c6a(0x26f)][_0x328c6a(0x1ff)])),_0xc577d8[_0x328c6a(0x1b2)]=_0xc577d8[_0x328c6a(0x1b2)][_0x328c6a(0x261)]?_0xc577d8['attributes']:_0x32dc0d[_0x328c6a(0x1a5)],typeof _0x5cedac[_0x328c6a(0x26f)]['nolimit']===_0x328c6a(0x1ec)&&(_0xc577d8['limit']=qs[_0x328c6a(0x1a4)](_0x5cedac[_0x328c6a(0x26f)][_0x328c6a(0x1a4)]),_0xc577d8['offset']=qs[_0x328c6a(0x237)](_0x5cedac[_0x328c6a(0x26f)]['offset'])),_0xc577d8[_0x328c6a(0x1df)]=qs[_0x328c6a(0x20d)](_0x5cedac[_0x328c6a(0x26f)]['sort']),_0xc577d8[_0x328c6a(0x1ad)]=qs[_0x328c6a(0x25a)](_['pick'](_0x5cedac['query'],_0x32dc0d['filters'])),_0xc577d8[_0x328c6a(0x1ad)][_0x328c6a(0x1c7)]=_0x12c2a5['id'],_0xc577d8=filterAttributes(_0xc577d8,_0x5cedac[_0x328c6a(0x26f)][_0x328c6a(0x1a8)],_0xc577d8[_0x328c6a(0x1b2)],_0x5cedac[_0x328c6a(0x1d1)],![]),db[_0x328c6a(0x216)][_0x328c6a(0x1ee)]({'where':_0xc577d8[_0x328c6a(0x1ad)]})[_0x328c6a(0x23f)](function(_0x437f79){const _0x4aba84=_0x328c6a;return _0x2196ec[_0x4aba84(0x1ee)]=_0x437f79,_0x5cedac['query']['includeAll']&&(_0xc577d8['include']=[{'all':!![]}]),db[_0x4aba84(0x216)][_0x4aba84(0x208)](_0xc577d8);})[_0x328c6a(0x23f)](function(_0x46ba4f){const _0x500225=_0x328c6a;return _0x2196ec[_0x500225(0x1af)]=_0x46ba4f,_0x2196ec;});})[_0x4d20a2(0x23f)](respondWithFilteredResult(_0x29b7df,_0xc577d8))[_0x4d20a2(0x23e)](handleError(_0x29b7df,null));},exports[a642_0x577217(0x1d0)]=function(_0x53652a,_0x3c72af){const _0x572c8e=a642_0x577217;return db[_0x572c8e(0x201)][_0x572c8e(0x1d2)]({'where':{'id':_0x53652a[_0x572c8e(0x1ae)]['id']}})['then'](handleEntityNotFound(_0x3c72af,null))['then'](function(_0x56b4c6){const _0x3b2a2e=_0x572c8e;if(_0x56b4c6)return _0x56b4c6[_0x3b2a2e(0x1d0)](_0x53652a['query']['ids']);})[_0x572c8e(0x23f)](respondWithStatusCode(_0x3c72af,null))[_0x572c8e(0x23e)](handleError(_0x3c72af,null));},exports[a642_0x577217(0x21d)]=function(_0x2f9361,_0x3665cc){const _0x491248=a642_0x577217;return _0x2f9361[_0x491248(0x1b5)]['id']&&delete _0x2f9361[_0x491248(0x1b5)]['id'],db['SmsAccount'][_0x491248(0x1d2)]({'where':{'id':_0x2f9361[_0x491248(0x1ae)]['id']}})[_0x491248(0x23f)](handleEntityNotFound(_0x3665cc,null))[_0x491248(0x23f)](function(_0x213849){const _0x148bf7=_0x491248;if(_0x213849)return _0x2f9361[_0x148bf7(0x1b5)][_0x148bf7(0x1c7)]=_0x213849['id'],db[_0x148bf7(0x1e5)][_0x148bf7(0x21b)](_0x2f9361[_0x148bf7(0x1b5)]);})[_0x491248(0x23f)](respondWithResult(_0x3665cc,null))[_0x491248(0x23e)](handleError(_0x3665cc,null));},exports['getAnswers']=function(_0x38ed72,_0x16717a){const _0x1d9868=a642_0x577217;let _0x8f650e={'raw':![],'where':{}};const _0x5465b3={},_0x5acff3={'count':0x0,'rows':[]};return db[_0x1d9868(0x201)][_0x1d9868(0x1d2)]({'where':{'id':_0x38ed72[_0x1d9868(0x1ae)]['id']}})[_0x1d9868(0x23f)](handleEntityNotFound(_0x16717a,null))['then'](function(_0x42da7d){const _0x13d77f=_0x1d9868;if(_0x42da7d)return _0x5465b3['model']=_[_0x13d77f(0x1e7)](db['CannedAnswer'][_0x13d77f(0x25d)]),_0x5465b3['query']=_[_0x13d77f(0x1e7)](_0x38ed72['query']),_0x5465b3[_0x13d77f(0x25a)]=_[_0x13d77f(0x214)](_0x5465b3[_0x13d77f(0x1a5)],_0x5465b3[_0x13d77f(0x26f)]),_0x8f650e['attributes']=_[_0x13d77f(0x214)](_0x5465b3[_0x13d77f(0x1a5)],qs['fields'](_0x38ed72['query'][_0x13d77f(0x1ff)])),_0x8f650e['attributes']=_0x8f650e[_0x13d77f(0x1b2)][_0x13d77f(0x261)]?_0x8f650e[_0x13d77f(0x1b2)]:_0x5465b3[_0x13d77f(0x1a5)],typeof _0x38ed72[_0x13d77f(0x26f)][_0x13d77f(0x1c8)]==='undefined'&&(_0x8f650e['limit']=qs['limit'](_0x38ed72[_0x13d77f(0x26f)][_0x13d77f(0x1a4)]),_0x8f650e[_0x13d77f(0x237)]=qs[_0x13d77f(0x237)](_0x38ed72[_0x13d77f(0x26f)][_0x13d77f(0x237)])),_0x8f650e[_0x13d77f(0x1df)]=qs[_0x13d77f(0x20d)](_0x38ed72[_0x13d77f(0x26f)][_0x13d77f(0x20d)]),_0x8f650e[_0x13d77f(0x1ad)]=qs[_0x13d77f(0x25a)](_[_0x13d77f(0x1e3)](_0x38ed72[_0x13d77f(0x26f)],_0x5465b3[_0x13d77f(0x25a)])),_0x8f650e['where']['SmsAccountId']=_0x42da7d['id'],_0x8f650e=filterAttributes(_0x8f650e,_0x38ed72['query'][_0x13d77f(0x1a8)],_0x8f650e[_0x13d77f(0x1b2)],_0x38ed72[_0x13d77f(0x1d1)],![]),db[_0x13d77f(0x1e5)][_0x13d77f(0x1ee)]({'where':_0x8f650e[_0x13d77f(0x1ad)]})[_0x13d77f(0x23f)](function(_0x5a6bae){const _0x357ad9=_0x13d77f;return _0x5acff3[_0x357ad9(0x1ee)]=_0x5a6bae,_0x38ed72[_0x357ad9(0x26f)][_0x357ad9(0x212)]&&(_0x8f650e[_0x357ad9(0x21a)]=[{'all':!![]}]),db['CannedAnswer']['findAll'](_0x8f650e);})['then'](function(_0x53b846){const _0x221c45=_0x13d77f;return _0x5acff3[_0x221c45(0x1af)]=_0x53b846,_0x5acff3;});})[_0x1d9868(0x23f)](respondWithFilteredResult(_0x16717a,_0x8f650e))[_0x1d9868(0x23e)](handleError(_0x16717a,null));},exports[a642_0x577217(0x231)]=function(_0x43d2d8,_0x3e58fe){const _0x1e59dc=a642_0x577217;return db[_0x1e59dc(0x201)][_0x1e59dc(0x1d2)]({'where':{'id':_0x43d2d8[_0x1e59dc(0x1ae)]['id']}})[_0x1e59dc(0x23f)](handleEntityNotFound(_0x3e58fe,null))[_0x1e59dc(0x23f)](function(_0x1e7c7d){const _0x287d6c=_0x1e59dc;if(_0x1e7c7d)return _0x1e7c7d[_0x287d6c(0x231)](_0x43d2d8['query'][_0x287d6c(0x25c)]);})['then'](respondWithStatusCode(_0x3e58fe,null))[_0x1e59dc(0x23e)](handleError(_0x3e58fe,null));},exports[a642_0x577217(0x24f)]=function(_0x36f922,_0x12ac4b){const _0x550446=a642_0x577217,_0x4794e4={'channel':'sms'};let _0xb76c19=[],_0x8c27f2=[];const _0x26f4ae={};return db[_0x550446(0x201)][_0x550446(0x1d2)]({'where':{'id':_0x36f922[_0x550446(0x1ae)]['id']},'include':[{'model':db[_0x550446(0x204)],'as':'Applications'}]})[_0x550446(0x23f)](handleEntityNotFound(_0x12ac4b,null))[_0x550446(0x23f)](function(_0x1d3413){const _0x356a08=_0x550446;return _0x4794e4[_0x356a08(0x1e6)]=_0x1d3413,_0x4794e4[_0x356a08(0x1bb)]=_['orderBy'](_0x1d3413[_0x356a08(0x1ef)],[_0x356a08(0x1d9)],[_0x356a08(0x1d3)]),_0x4794e4[_0x356a08(0x1e6)]['Applications']&&delete _0x4794e4[_0x356a08(0x1e6)]['Applications'],db[_0x356a08(0x1b4)][_0x356a08(0x1cb)]();})['then'](function(_0x198131){const _0x2a2ce5=_0x550446;if(!_0x198131)throw new ValidationError('no\x20available\x20attributes');_0xb76c19=_['difference'](_[_0x2a2ce5(0x1e7)](_0x198131),[_0x2a2ce5(0x19f),_0x2a2ce5(0x20c)]),_0x8c27f2=_['difference'](_['keys'](_0x198131),[_0x2a2ce5(0x19f),_0x2a2ce5(0x20c),_0x2a2ce5(0x1bd),_0x2a2ce5(0x23d)]),_0x4794e4['body']={'mapKey':_0x2a2ce5(0x205)};if(_0x4794e4[_0x2a2ce5(0x1e6)][_0x2a2ce5(0x20e)])switch(_0x4794e4[_0x2a2ce5(0x1e6)][_0x2a2ce5(0x20e)]){case'twilio':_0x4794e4['body'][_0x2a2ce5(0x1bf)]=_0x36f922[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x260)],_0x4794e4['body'][_0x2a2ce5(0x1b5)]=_0x36f922[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x1f2)],_0x4794e4['body']['messageId']=_0x36f922['body']['MessageSid'];break;case _0x2a2ce5(0x220):_0x4794e4[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x1bf)]='+'+_0x36f922['body']['sender'],_0x4794e4[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x1b5)]=_0x36f922[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x215)];break;case _0x2a2ce5(0x1ed):_0x4794e4['body']['from']=_0x36f922[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x1bf)],_0x4794e4[_0x2a2ce5(0x1b5)]['body']=_0x36f922[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x1a9)];break;case _0x2a2ce5(0x226):_0x4794e4[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x1bf)]=_0x36f922[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x1bf)],_0x4794e4[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x1b5)]=_0x36f922[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x1b5)],_0x4794e4[_0x2a2ce5(0x1b5)]['messageId']=_0x36f922['body'][_0x2a2ce5(0x1aa)];break;case _0x2a2ce5(0x229):_0x4794e4[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x1bf)]=_0x36f922[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x260)],_0x4794e4[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x1b5)]=_0x36f922[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x1d5)],_0x4794e4[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x240)]=_0x36f922[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x1d7)];break;case _0x2a2ce5(0x24b):_0x4794e4['body']['from']='+'+_0x36f922[_0x2a2ce5(0x1b5)]['results'][0x0][_0x2a2ce5(0x1bf)],_0x4794e4[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x1b5)]=_0x36f922[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x1b9)][0x0][_0x2a2ce5(0x215)],_0x4794e4[_0x2a2ce5(0x1b5)]['messageId']=_0x36f922[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x1b9)][0x0][_0x2a2ce5(0x240)];break;case'csc':_0x4794e4['body']['from']=_0x36f922['body']['originatingAddress'],_0x4794e4[_0x2a2ce5(0x1b5)]['body']=_0x36f922['body'][_0x2a2ce5(0x256)][_0x2a2ce5(0x1a9)];break;case _0x2a2ce5(0x1b1):_0x4794e4['body']['from']=_0x36f922[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x1b6)],_0x4794e4[_0x2a2ce5(0x1b5)]['body']=_0x36f922[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x215)],_0x4794e4['body'][_0x2a2ce5(0x240)]=_0x36f922[_0x2a2ce5(0x1b5)]['replyMessageId'];break;case _0x2a2ce5(0x1fb):_0x4794e4[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x240)]=_0x36f922[_0x2a2ce5(0x1b5)][0x0][_0x2a2ce5(0x1a9)]['id'],_0x4794e4[_0x2a2ce5(0x1b5)]['from']=_0x36f922['body'][0x0]['message'][_0x2a2ce5(0x1bf)],_0x4794e4[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x1b5)]=_0x36f922[_0x2a2ce5(0x1b5)][0x0][_0x2a2ce5(0x1a9)][_0x2a2ce5(0x215)];break;case'intelepeer':_0x4794e4[_0x2a2ce5(0x1b5)]['from']=_0x36f922[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x1bf)],_0x4794e4[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x1b5)]=_0x36f922[_0x2a2ce5(0x1b5)]['message'],_0x4794e4[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x240)]=_0x36f922[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x203)];break;}_0x4794e4[_0x2a2ce5(0x1b5)]['id']&&delete _0x4794e4['body']['id'];if(_[_0x2a2ce5(0x1e0)](_0x4794e4[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x1bf)]))throw new ValidationError(_0x2a2ce5(0x248));if(_[_0x2a2ce5(0x1e0)](_0x4794e4['body'][_0x2a2ce5(0x1b5)])||_0x4794e4[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x1b5)]==='')throw new ValidationError('body\x20is\x20mandatory\x20and\x20not\x20empty');if(_[_0x2a2ce5(0x1e0)](_0x4794e4[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x243)]))throw new ValidationError(_0x2a2ce5(0x1eb)+_0x8c27f2);if(!_[_0x2a2ce5(0x1b7)](_0x8c27f2,_0x4794e4['body'][_0x2a2ce5(0x243)]))throw new ValidationError(_0x2a2ce5(0x19d)+_0x8c27f2);return _0x26f4ae[_0x4794e4[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x243)]]=_0x4794e4[_0x2a2ce5(0x1b5)][_0x2a2ce5(0x1bf)],db[_0x2a2ce5(0x1ce)]['findOne']({'where':{'id':_0x4794e4[_0x2a2ce5(0x1e6)][_0x2a2ce5(0x23d)]},'include':[{'model':db[_0x2a2ce5(0x1b4)],'as':'Contacts','where':_0x26f4ae,'limit':0x1,'order':[[_0x2a2ce5(0x20c),_0x2a2ce5(0x209)]]}]});})[_0x550446(0x23f)](handleEntityNotFound(_0x12ac4b,null))[_0x550446(0x23f)](function(_0x2e9efd){const _0x1c6d83=_0x550446;if(_0x2e9efd){_0x4794e4['list']=_[_0x1c6d83(0x1f1)](_0x2e9efd,[_0x1c6d83(0x200)]);if(_0x2e9efd[_0x1c6d83(0x200)][_0x1c6d83(0x261)])return _0x2e9efd['Contacts'][0x0];const _0x4a985e=_[_0x1c6d83(0x1d6)](_0x4794e4[_0x1c6d83(0x1b5)],{'firstName':_0x4794e4[_0x1c6d83(0x1b5)][_0x1c6d83(0x1bf)],'ListId':_0x2e9efd['id']});return _0x4a985e[_0x4794e4['body'][_0x1c6d83(0x243)]]=_0x4794e4['body'][_0x1c6d83(0x1bf)],db[_0x1c6d83(0x1b4)][_0x1c6d83(0x21b)](_0x4a985e,{'fields':_0xb76c19,'raw':!![]});}})['then'](handleEntityNotFound(_0x12ac4b,null))['then'](function(_0x3d31d6){const _0x4af327=_0x550446;if(_0x3d31d6){_0x4794e4[_0x4af327(0x249)]=_0x3d31d6;const _0x4454f7={'ContactId':_0x3d31d6['id'],'phone':_0x4794e4[_0x4af327(0x1b5)][_0x4af327(0x1bf)],'SmsAccountId':_0x36f922[_0x4af327(0x1ae)]['id']},_0x292f66={'ContactId':_0x3d31d6['id'],'SmsAccountId':_0x36f922['params']['id'],'closed':![]};return db[_0x4af327(0x250)]['findOne']({'where':_0x292f66})[_0x4af327(0x23f)](function(_0x239a18){const _0x47c8d2=_0x4af327;if(_0x239a18)return[_0x239a18,![]];return db[_0x47c8d2(0x250)]['create'](_0x4454f7)[_0x47c8d2(0x23f)](function(_0x5413f9){return[_0x5413f9,!![]];});});}})[_0x550446(0x23f)](function([_0x4a360d,_0x5b4256]){const _0x41f3ce=_0x550446;return _0x4794e4[_0x41f3ce(0x259)]=_0x4a360d['get']({'plain':!![]}),_0x4794e4[_0x41f3ce(0x259)][_0x41f3ce(0x24c)]=![],_0x5b4256&&(_0x4794e4[_0x41f3ce(0x1e6)][_0x41f3ce(0x1c9)]&&_0x4794e4[_0x41f3ce(0x1bb)][_0x41f3ce(0x1c3)]({'id':0x0,'priority':_0x4794e4[_0x41f3ce(0x1bb)][_0x41f3ce(0x261)]+0x1,'app':_0x41f3ce(0x1cd),'appdata':_0x41f3ce(0x1f9),'interval':_0x41f3ce(0x246)}),_0x4794e4[_0x41f3ce(0x259)][_0x41f3ce(0x24c)]=!![]),db[_0x41f3ce(0x26e)]['create']({'phone':_0x4794e4[_0x41f3ce(0x1b5)][_0x41f3ce(0x1bf)],'messageId':_0x4794e4['body'][_0x41f3ce(0x240)],'body':_0x4794e4[_0x41f3ce(0x1b5)][_0x41f3ce(0x1b5)],'SmsAccountId':_0x36f922[_0x41f3ce(0x1ae)]['id'],'SmsInteractionId':_0x4a360d['id'],'direction':'in','ContactId':_0x4a360d[_0x41f3ce(0x1ab)],'AttachmentId':_0x4794e4[_0x41f3ce(0x1b5)][_0x41f3ce(0x1c4)]});})[_0x550446(0x23f)](function(_0x416759){const _0x4370cf=_0x550446;_0x4794e4['message']=_0x416759;if(_0x4794e4[_0x4370cf(0x259)][_0x4370cf(0x258)])return db[_0x4370cf(0x207)][_0x4370cf(0x1d2)]({'attributes':['id','name'],'where':{'id':_0x4794e4[_0x4370cf(0x259)][_0x4370cf(0x258)]}})[_0x4370cf(0x23f)](function(_0x427392){const _0xb0f04c=_0x4370cf;return _0x427392&&_0x4794e4[_0xb0f04c(0x1bb)][_0xb0f04c(0x262)]({'id':0x0,'priority':0x0,'app':_0xb0f04c(0x218),'appdata':_0x427392[_0xb0f04c(0x1c2)]+','+(_0x4794e4['account'][_0xb0f04c(0x223)]||0xa),'interval':_0xb0f04c(0x246)}),respondWithRpcPromise(_0xb0f04c(0x26b),_0xb0f04c(0x230),_0x4794e4);});return respondWithRpcPromise(_0x4370cf(0x26b),_0x4370cf(0x230),_0x4794e4);})[_0x550446(0x23f)](function(_0x651f97){const _0x2e1ace=_0x550446;if(_0x651f97){const _0x2a8c23=0xc8,_0x13a8f4='receiveMessage';return logger['info'](_0x2e1ace(0x20f),_0x13a8f4,_0x2a8c23,_0x2e1ace(0x1be)),logger[_0x2e1ace(0x22c)](_0x2e1ace(0x234),_0x13a8f4,_0x2a8c23,_0x2e1ace(0x1be),JSON['stringify'](_0x651f97)),_0x4794e4[_0x2e1ace(0x1e6)][_0x2e1ace(0x20e)]==='twilio'?_0x12ac4b[_0x2e1ace(0x242)](_0x2a8c23)[_0x2e1ace(0x252)](_0x2e1ace(0x1f6),_0x2e1ace(0x26c))[_0x2e1ace(0x1dc)](_0x2e1ace(0x1fd)):_0x12ac4b['status'](_0x2a8c23)[_0x2e1ace(0x21c)](_0x651f97);}})['catch'](handleError(_0x12ac4b,null));},exports[a642_0x577217(0x265)]=function(_0x141a59,_0x85aa7e){const _0x30cd1a=a642_0x577217;return db[_0x30cd1a(0x201)][_0x30cd1a(0x1d2)]({'where':{'id':_0x141a59['params']['id']}})[_0x30cd1a(0x23f)](handleEntityNotFound(_0x85aa7e,null))[_0x30cd1a(0x23f)](function(_0x2190b7){const _0x47e520=_0x30cd1a;if(_0x2190b7)return db[_0x47e520(0x268)][_0x47e520(0x23b)](function(_0x247039){const _0x12dd93=_0x47e520;return db[_0x12dd93(0x204)][_0x12dd93(0x22f)]({'where':{'SmsAccountId':_0x141a59['params']['id']},'transaction':_0x247039})['then'](function(){const _0x3c78e0=_0x12dd93,_0x2eedd8=_[_0x3c78e0(0x1ca)](_0x141a59[_0x3c78e0(0x1b5)],function(_0x199237){const _0x1f62c7=_0x3c78e0;return _0x199237[_0x1f62c7(0x1c7)]=_0x141a59['params']['id'],_0x199237;}),_0x167ad2=_0x2eedd8[_0x3c78e0(0x1a8)](_0x3c0469=>_0x3c0469[_0x3c78e0(0x219)]);return db[_0x3c78e0(0x204)]['bulkCreate'](_0x167ad2,{'transaction':_0x247039});});})['then'](function(){const _0x2d817e=_0x47e520;return db[_0x2d817e(0x204)][_0x2d817e(0x1da)]({'where':{'SmsAccountId':_0x141a59[_0x2d817e(0x1ae)]['id']},'order':db[_0x2d817e(0x268)][_0x2d817e(0x21e)](_0x2d817e(0x1d9))});});})['then'](respondWithResult(_0x85aa7e,null))[_0x30cd1a(0x23e)](handleError(_0x85aa7e,null));},exports['getApplications']=function(_0x1c632e,_0x2387f0){const _0x4d6797=a642_0x577217;let _0x155853={};const _0x560797={};let _0xf5dd81,_0x42a709;return db[_0x4d6797(0x201)][_0x4d6797(0x1d2)]({'where':{'id':_0x1c632e[_0x4d6797(0x1ae)]['id']}})[_0x4d6797(0x23f)](handleEntityNotFound(_0x2387f0,null))[_0x4d6797(0x23f)](function(_0x184597){const _0x30ad62=_0x4d6797;if(_0x184597)return _0xf5dd81=_0x184597,_0x560797['model']=_[_0x30ad62(0x1e7)](db['SmsApplication'][_0x30ad62(0x25d)]),_0x560797[_0x30ad62(0x26f)]=_[_0x30ad62(0x1e7)](_0x1c632e[_0x30ad62(0x26f)]),_0x560797[_0x30ad62(0x25a)]=_['intersection'](_0x560797[_0x30ad62(0x1a5)],_0x560797[_0x30ad62(0x26f)]),_0x155853[_0x30ad62(0x1b2)]=_['intersection'](_0x560797[_0x30ad62(0x1a5)],qs[_0x30ad62(0x1ff)](_0x1c632e[_0x30ad62(0x26f)][_0x30ad62(0x1ff)])),_0x155853['attributes']=_0x155853['attributes']['length']?_0x155853[_0x30ad62(0x1b2)]:_0x560797[_0x30ad62(0x1a5)],_0x155853[_0x30ad62(0x1df)]=qs[_0x30ad62(0x20d)](_0x1c632e[_0x30ad62(0x26f)][_0x30ad62(0x20d)]),_0x155853[_0x30ad62(0x1ad)]=qs[_0x30ad62(0x25a)](_['pick'](_0x1c632e[_0x30ad62(0x26f)],_0x560797[_0x30ad62(0x25a)])),_0x155853=filterAttributes(_0x155853,_0x1c632e[_0x30ad62(0x26f)][_0x30ad62(0x1a8)],_0x155853[_0x30ad62(0x1b2)],_0x1c632e[_0x30ad62(0x1d1)],![]),_0xf5dd81[_0x30ad62(0x269)](_0x155853);})['then'](function(_0x2e043f){const _0x1a4337=_0x4d6797;if(_0x2e043f)return _0x42a709=_0x2e043f[_0x1a4337(0x261)],typeof _0x1c632e[_0x1a4337(0x26f)]['nolimit']===_0x1a4337(0x1ec)&&(_0x155853[_0x1a4337(0x1a4)]=qs[_0x1a4337(0x1a4)](_0x1c632e[_0x1a4337(0x26f)][_0x1a4337(0x1a4)]),_0x155853['offset']=qs['offset'](_0x1c632e[_0x1a4337(0x26f)][_0x1a4337(0x237)])),_0xf5dd81[_0x1a4337(0x269)](_0x155853);})[_0x4d6797(0x23f)](function(_0x327900){if(_0x327900)return _0x327900?{'count':_0x42a709,'rows':_0x327900}:null;})[_0x4d6797(0x23f)](respondWithResult(_0x2387f0,null))[_0x4d6797(0x23e)](handleError(_0x2387f0,null));},exports[a642_0x577217(0x263)]=function(_0x4c18af,_0xe93fce){const _0x1ae0ce=a642_0x577217;let _0x66ad2a={'raw':![],'where':{}};const _0x560705={},_0x2bffe4={'count':0x0,'rows':[]};return db[_0x1ae0ce(0x201)]['findOne']({'where':{'id':_0x4c18af['params']['id']}})['then'](handleEntityNotFound(_0xe93fce,null))[_0x1ae0ce(0x23f)](function(_0x5823bf){const _0x1a8fa7=_0x1ae0ce;if(_0x5823bf)return _0x560705[_0x1a8fa7(0x1a5)]=_[_0x1a8fa7(0x1e7)](db[_0x1a8fa7(0x250)]['rawAttributes']),_0x560705[_0x1a8fa7(0x26f)]=_[_0x1a8fa7(0x1e7)](_0x4c18af['query']),_0x560705[_0x1a8fa7(0x25a)]=_[_0x1a8fa7(0x214)](_0x560705[_0x1a8fa7(0x1a5)],_0x560705['query']),_0x66ad2a[_0x1a8fa7(0x1b2)]=_[_0x1a8fa7(0x214)](_0x560705[_0x1a8fa7(0x1a5)],qs[_0x1a8fa7(0x1ff)](_0x4c18af[_0x1a8fa7(0x26f)][_0x1a8fa7(0x1ff)])),_0x66ad2a[_0x1a8fa7(0x1b2)]=_0x66ad2a[_0x1a8fa7(0x1b2)][_0x1a8fa7(0x261)]?_0x66ad2a[_0x1a8fa7(0x1b2)]:_0x560705[_0x1a8fa7(0x1a5)],typeof _0x4c18af['query']['nolimit']===_0x1a8fa7(0x1ec)&&(_0x66ad2a[_0x1a8fa7(0x1a4)]=qs[_0x1a8fa7(0x1a4)](_0x4c18af[_0x1a8fa7(0x26f)]['limit']),_0x66ad2a[_0x1a8fa7(0x237)]=qs['offset'](_0x4c18af['query'][_0x1a8fa7(0x237)])),_0x66ad2a['order']=qs[_0x1a8fa7(0x20d)](_0x4c18af['query'][_0x1a8fa7(0x20d)]),_0x66ad2a[_0x1a8fa7(0x1ad)]=qs[_0x1a8fa7(0x25a)](_[_0x1a8fa7(0x1e3)](_0x4c18af[_0x1a8fa7(0x26f)],_0x560705[_0x1a8fa7(0x25a)])),_0x66ad2a[_0x1a8fa7(0x1ad)][_0x1a8fa7(0x1c7)]=_0x5823bf['id'],_0x66ad2a=filterAttributes(_0x66ad2a,_0x4c18af[_0x1a8fa7(0x26f)]['filter'],_0x66ad2a[_0x1a8fa7(0x1b2)],_0x4c18af[_0x1a8fa7(0x1d1)],![]),db[_0x1a8fa7(0x250)][_0x1a8fa7(0x1ee)]({'where':_0x66ad2a['where']})[_0x1a8fa7(0x23f)](function(_0x249206){const _0x571bcd=_0x1a8fa7;return _0x2bffe4[_0x571bcd(0x1ee)]=_0x249206,_0x4c18af['query'][_0x571bcd(0x212)]&&(_0x66ad2a[_0x571bcd(0x21a)]=[{'model':db[_0x571bcd(0x1b4)],'as':_0x571bcd(0x1c0),'required':![]},{'model':db['User'],'as':_0x571bcd(0x1bc),'attributes':[_0x571bcd(0x1c2),_0x571bcd(0x1e2),_0x571bcd(0x253)],'required':![]},{'model':db[_0x571bcd(0x1a7)],'as':_0x571bcd(0x1de),'attributes':['id','name','color'],'where':_0x4c18af['query'][_0x571bcd(0x236)]?{'id':_0x4c18af[_0x571bcd(0x26f)][_0x571bcd(0x236)]}:undefined,'required':_0x4c18af[_0x571bcd(0x26f)][_0x571bcd(0x236)]?!![]:![]}]),db[_0x571bcd(0x250)][_0x571bcd(0x208)](_0x66ad2a);})[_0x1a8fa7(0x23f)](function(_0x3b57b4){return _0x2bffe4['rows']=_0x3b57b4,_0x2bffe4;});})[_0x1ae0ce(0x23f)](respondWithFilteredResult(_0xe93fce,_0x66ad2a))[_0x1ae0ce(0x23e)](handleError(_0xe93fce,null));},exports[a642_0x577217(0x1dc)]=function(_0x598f34,_0x364de2){const _0x3284c6=a642_0x577217;let _0x5b4bab,_0x5c7ba4;if(_[_0x3284c6(0x1e0)](_0x598f34[_0x3284c6(0x1b5)][_0x3284c6(0x1b5)])||_0x598f34[_0x3284c6(0x1b5)][_0x3284c6(0x1b5)]==='')throw new ValidationError('body\x20is\x20mandatory\x20and\x20not\x20empty');if(_['isNil'](_0x598f34[_0x3284c6(0x1b5)]['to']))throw new ValidationError(_0x3284c6(0x21f));const _0x14964a=_0x598f34[_0x3284c6(0x1b5)]['to'];return db[_0x3284c6(0x201)]['findOne']({'where':{'id':_0x598f34[_0x3284c6(0x1ae)]['id']},'include':[{'model':db[_0x3284c6(0x1ce)],'as':'List','include':[{'model':db[_0x3284c6(0x1b4)],'as':_0x3284c6(0x200),'where':{'mobile':_0x14964a},'limit':0x1,'order':[[_0x3284c6(0x20c),_0x3284c6(0x209)]]}]}]})[_0x3284c6(0x23f)](handleEntityNotFound(_0x364de2,null))['then'](function(_0x241f4a){const _0x56a423=_0x3284c6;if(_0x241f4a&&_0x241f4a[_0x56a423(0x255)]){_0x5b4bab=_0x241f4a[_0x56a423(0x213)]({'plain':!![]});if(_0x5b4bab[_0x56a423(0x255)]&&_0x5b4bab[_0x56a423(0x255)]['Contacts']['length'])return _0x5b4bab[_0x56a423(0x255)][_0x56a423(0x200)][0x0];return db[_0x56a423(0x1b4)][_0x56a423(0x21b)](_[_0x56a423(0x1d6)](_0x598f34[_0x56a423(0x1b5)],{'firstName':_0x14964a,'mobile':_0x14964a,'phone':_0x14964a,'ListId':_0x5b4bab[_0x56a423(0x23d)]}));}})[_0x3284c6(0x23f)](handleEntityNotFound(_0x364de2,null))[_0x3284c6(0x23f)](function(_0x1c7dad){const _0x17f3b5=_0x3284c6;if(_0x1c7dad)return _0x5c7ba4=_0x1c7dad,db[_0x17f3b5(0x250)][_0x17f3b5(0x1d2)]({'where':{'ContactId':_0x5c7ba4['id'],'closed':![],'SmsAccountId':_0x5b4bab['id']}})[_0x17f3b5(0x23f)](function(_0x216bf4){const _0xbcfc10=_0x17f3b5;if(_0x216bf4)return[_0x216bf4,![]];return db['SmsInteraction'][_0xbcfc10(0x21b)]({'UserId':_0x598f34[_0xbcfc10(0x24e)]['id'],'ContactId':_0x5c7ba4['id'],'SmsAccountId':_0x5b4bab['id'],'phone':_0x14964a,'firstMsgDirection':'out','Messages':[_['merge'](_0x598f34[_0xbcfc10(0x1b5)],{'read':![],'body':_0x598f34[_0xbcfc10(0x1b5)][_0xbcfc10(0x1b5)],'phone':_0x14964a,'SmsAccountId':_0x5b4bab['id'],'UserId':_0x598f34['user']['id'],'ContactId':_0x5c7ba4['id']})]},{'include':[{'model':db[_0xbcfc10(0x26e)],'as':_0xbcfc10(0x1b0)}]})[_0xbcfc10(0x23f)](function(_0xe1c97a){return[_0xe1c97a,!![]];});});})[_0x3284c6(0x23f)](function([_0x1b9314,_0x30f3bc]){const _0x46e52c=_0x3284c6;if(_0x30f3bc)return _0x1b9314;return db[_0x46e52c(0x26e)][_0x46e52c(0x21b)](_[_0x46e52c(0x22a)](_0x598f34[_0x46e52c(0x1b5)],{'read':![],'body':_0x598f34['body']['body'],'phone':_0x14964a,'SmsAccountId':_0x5b4bab['id'],'SmsInteractionId':_0x1b9314['id'],'UserId':_0x598f34[_0x46e52c(0x24e)]['id'],'ContactId':_0x5c7ba4['id']}))[_0x46e52c(0x23f)](function(_0x57b9c9){const _0x37f1a2=_0x46e52c;return _0x1b9314['dataValues']['Messages']=[],_0x1b9314[_0x37f1a2(0x24d)][_0x37f1a2(0x1b0)][_0x37f1a2(0x1c3)](_0x57b9c9['dataValues']),_0x1b9314;});})['then'](respondWithResult(_0x364de2,null))['catch'](handleError(_0x364de2,null));},exports[a642_0x577217(0x242)]=function(_0x530650,_0x3c06dc){const _0x4dce4f=a642_0x577217;_0x530650[_0x4dce4f(0x1b5)]['id']&&delete _0x530650[_0x4dce4f(0x1b5)]['id'];let _0xf85741,_0x106585,_0x2ba17d;return db['SmsAccount']['findOne']({'where':{'id':_0x530650['params']['id']}})['then'](handleEntityNotFound(_0x3c06dc,null))['then'](function(_0x266ae0){const _0x47d262=_0x4dce4f;if(_0x266ae0){_0x2ba17d=_0x266ae0,logger['debug'](_0x47d262(0x20f),_0x47d262(0x242),_0x47d262(0x23a),_0x266ae0[_0x47d262(0x20e)],util['inspect'](_0x530650[_0x47d262(0x1b5)],{'showHidden':![],'depth':null}));switch(_0x266ae0[_0x47d262(0x20e)]){case _0x47d262(0x220):if(_0x530650[_0x47d262(0x1b5)]['skebby_dispatch_id']&&_0x530650[_0x47d262(0x1b5)]['status'])return _0x106585=_0x530650['body'][_0x47d262(0x242)],db[_0x47d262(0x26e)][_0x47d262(0x1d2)]({'where':{'messageId':_0x530650[_0x47d262(0x1b5)][_0x47d262(0x1db)]}});break;case _0x47d262(0x1ed):if(_0x530650[_0x47d262(0x1b5)]['requestid']&&_0x530650['body']['statusInt'])return _0x106585=_0x530650[_0x47d262(0x1b5)][_0x47d262(0x1d4)],db['SmsMessage'][_0x47d262(0x1d2)]({'where':{'messageId':_0x530650[_0x47d262(0x1b5)]['requestid']}});break;case'clicksend':if(_0x530650[_0x47d262(0x1b5)][_0x47d262(0x1aa)]&&_0x530650[_0x47d262(0x1b5)][_0x47d262(0x1f4)])return _0x106585=_0x530650[_0x47d262(0x1b5)][_0x47d262(0x1f4)],db[_0x47d262(0x26e)][_0x47d262(0x1d2)]({'where':{'messageId':_0x530650['body'][_0x47d262(0x1aa)]}});break;case _0x47d262(0x24b):{const _0x16bfe8=_0x530650['body'][_0x47d262(0x1b9)][0x0];if(_0x16bfe8['messageId']&&_0x16bfe8['status'][_0x47d262(0x1b8)]==='DELIVERED')return _0x106585=_0x16bfe8[_0x47d262(0x242)][_0x47d262(0x1b8)],db['SmsMessage'][_0x47d262(0x1d2)]({'where':{'messageId':_0x16bfe8['messageId']}});}break;case'clickatell':if(_0x530650[_0x47d262(0x1b5)][_0x47d262(0x240)]&&_0x530650[_0x47d262(0x1b5)]['status'])return _0x106585=_0x530650[_0x47d262(0x1b5)][_0x47d262(0x242)],db['SmsMessage'][_0x47d262(0x1d2)]({'where':{'messageId':_0x530650['body'][_0x47d262(0x240)]}});break;case _0x47d262(0x1fb):if(_0x530650['body'][0x0][_0x47d262(0x1a9)]['id'])return _0x106585=_0x530650[_0x47d262(0x1b5)][0x0][_0x47d262(0x20e)],db[_0x47d262(0x26e)][_0x47d262(0x202)]({'where':{'messageId':_0x530650[_0x47d262(0x1b5)][0x0][_0x47d262(0x1a9)]['id']}});break;case _0x47d262(0x22d):if(_0x530650[_0x47d262(0x1b5)][_0x47d262(0x1ac)]&&_0x530650['body'][_0x47d262(0x242)])return _0x106585=_0x530650['body']['status'],db[_0x47d262(0x26e)][_0x47d262(0x1d2)]({'where':{'messageId':_0x530650['body'][_0x47d262(0x1ac)]}});break;}}})['then'](handleEntityNotFound(_0x3c06dc,null))[_0x4dce4f(0x23f)](function(_0xa6d7b1){const _0x1db1f4=_0x4dce4f;if(_0xa6d7b1){_0xf85741=_0xa6d7b1;switch(_0x2ba17d['type']){case _0x1db1f4(0x220):if(_0x106585===_0x1db1f4(0x227))return _0xf85741[_0x1db1f4(0x228)]({'read':!![]});else logger[_0x1db1f4(0x23c)](_0x1db1f4(0x20f),_0x1db1f4(0x242),_0x1db1f4(0x220),util['inspect'](_0x530650['body'],{'showHidden':![],'depth':null}));break;case _0x1db1f4(0x1ed):if(_0x106585==='1')return _0xf85741['update']({'read':!![]});else logger[_0x1db1f4(0x23c)](_0x1db1f4(0x20f),'status',_0x1db1f4(0x220),util[_0x1db1f4(0x238)](_0x530650['body'],{'showHidden':![],'depth':null}));break;case _0x1db1f4(0x226):if(!_0x530650['body']['error_code']&&_0x106585>=0xc8&&_0x106585<=0xce)return _0xf85741[_0x1db1f4(0x228)]({'read':!![]});else logger[_0x1db1f4(0x23c)](_0x1db1f4(0x20f),'status',_0x1db1f4(0x226),util[_0x1db1f4(0x238)](_0x530650[_0x1db1f4(0x1b5)],{'showHidden':![],'depth':null}));break;case _0x1db1f4(0x24b):{const _0x1777b3=_0x530650['body'][_0x1db1f4(0x1b9)][0x0];if(_0x1777b3['status'][_0x1db1f4(0x1b8)]===_0x1db1f4(0x227))return _0xf85741[_0x1db1f4(0x228)]({'read':!![]});else logger[_0x1db1f4(0x23c)]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x1db1f4(0x242),_0x1db1f4(0x24b),util[_0x1db1f4(0x238)](_0x530650[_0x1db1f4(0x1b5)],{'showHidden':![],'depth':null}));}break;case _0x1db1f4(0x1b1):if(_0x106585==_0x1db1f4(0x19c)||_0x106585==_0x1db1f4(0x1d8))return _0xf85741['update']({'read':!![]});else logger['error'](_0x1db1f4(0x20f),_0x1db1f4(0x242),'clickatell',util[_0x1db1f4(0x238)](_0x530650[_0x1db1f4(0x1b5)],{'showHidden':![],'depth':null}));break;case _0x1db1f4(0x1fb):if(_0x106585=='message-delivered')return _0xf85741[_0x1db1f4(0x228)]({'read':!![]});else logger[_0x1db1f4(0x23c)](_0x1db1f4(0x20f),_0x1db1f4(0x242),_0x1db1f4(0x1fb),util[_0x1db1f4(0x238)](_0x530650[_0x1db1f4(0x1b5)],{'showHidden':![],'depth':null}));break;case _0x1db1f4(0x22d):if(_0x106585===_0x1db1f4(0x1f8)||_0x106585==='ACCEPTD')return _0xf85741[_0x1db1f4(0x228)]({'read':!![]});else logger[_0x1db1f4(0x23c)](_0x1db1f4(0x20f),'status',_0x1db1f4(0x22d),util[_0x1db1f4(0x238)](_0x530650[_0x1db1f4(0x1b5)],{'showHidden':![],'depth':null}));break;}return _0xf85741;}})[_0x4dce4f(0x23f)](respondWithResult(_0x3c06dc,null))['catch'](handleError(_0x3c06dc,null));},exports[a642_0x577217(0x1e1)]=function(_0x403358,_0x34919f){const _0x5d650b=a642_0x577217;let _0x221421,_0x46e2bb,_0x38f140;return db[_0x5d650b(0x201)][_0x5d650b(0x1d2)]({'where':{'id':_0x403358[_0x5d650b(0x1ae)]['id']}})[_0x5d650b(0x23f)](handleEntityNotFound(_0x34919f,null))[_0x5d650b(0x23f)](function(_0x25f608){const _0x250c48=_0x5d650b;if(_0x25f608){_0x38f140=_0x25f608,logger[_0x250c48(0x22c)](_0x250c48(0x20f),_0x250c48(0x242),_0x250c48(0x23a),_0x25f608[_0x250c48(0x20e)],util[_0x250c48(0x238)](_0x403358[_0x250c48(0x26f)],{'showHidden':![],'depth':null}));switch(_0x25f608['type']){case _0x250c48(0x1a1):if(_0x403358[_0x250c48(0x26f)][_0x250c48(0x1f7)]&&_0x403358['query'][_0x250c48(0x267)])return _0x46e2bb=_0x403358[_0x250c48(0x26f)][_0x250c48(0x267)],db['SmsMessage'][_0x250c48(0x1d2)]({'where':{'messageId':_0x403358[_0x250c48(0x26f)][_0x250c48(0x1f7)]}});break;}}})[_0x5d650b(0x23f)](handleEntityNotFound(_0x34919f,null))[_0x5d650b(0x23f)](function(_0x3bef19){const _0x51bf9f=_0x5d650b;if(_0x3bef19){_0x221421=_0x3bef19;switch(_0x38f140[_0x51bf9f(0x20e)]){case _0x51bf9f(0x1a1):if(_0x46e2bb==='2'||_0x46e2bb==='6')return _0x221421[_0x51bf9f(0x228)]({'read':!![]});else logger[_0x51bf9f(0x23c)]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x51bf9f(0x242),'csc',util[_0x51bf9f(0x238)](_0x403358[_0x51bf9f(0x26f)],{'showHidden':![],'depth':null}));break;}return _0x221421;}})[_0x5d650b(0x23f)](respondWithResult(_0x34919f,null))['catch'](handleError(_0x34919f,null));},exports[a642_0x577217(0x22b)]=function(_0x54eeca,_0x57d221){const _0x5b1c84=a642_0x577217;return db['SmsAccount'][_0x5b1c84(0x1d2)]({'where':{'id':_0x54eeca[_0x5b1c84(0x1ae)]['id']}})[_0x5b1c84(0x23f)](function(_0x54ddd9){const _0x397146=_0x5b1c84;if(_0x54ddd9)return _0x54ddd9[_0x397146(0x22b)](_0x54eeca[_0x397146(0x1b5)][_0x397146(0x25c)],{'through':_[_0x397146(0x1f1)](_0x54eeca['body'],['ids','id'])})['then'](function(_0xcc4933){const _0x1d0e0c=_0x397146;for(let _0x4eed7a=0x0;_0x4eed7a<_0x54eeca[_0x1d0e0c(0x1b5)][_0x1d0e0c(0x25c)]['length'];_0x4eed7a+=0x1){socket[_0x1d0e0c(0x1e9)](_0x1d0e0c(0x239),{'UserId':_0x54eeca[_0x1d0e0c(0x1b5)][_0x1d0e0c(0x25c)][_0x4eed7a],'SmsAccountId':_0x54eeca[_0x1d0e0c(0x1ae)]['id']});}return _0xcc4933;});})[_0x5b1c84(0x23f)](respondWithResult(_0x57d221,null))[_0x5b1c84(0x23e)](handleError(_0x57d221,null));},exports[a642_0x577217(0x25f)]=function(_0x3a133d,_0x15df26){const _0x45527d=a642_0x577217;return db[_0x45527d(0x201)]['findOne']({'where':{'id':_0x3a133d[_0x45527d(0x1ae)]['id']}})[_0x45527d(0x23f)](handleEntityNotFound(_0x15df26,null))['then'](function(_0x595472){const _0x4e5729=_0x45527d;if(_0x595472)return _0x595472[_0x4e5729(0x25f)](_0x3a133d['query'][_0x4e5729(0x25c)])[_0x4e5729(0x23f)](function(){const _0x24b2fd=_0x4e5729;if(_['isArray'](_0x3a133d['query'][_0x24b2fd(0x25c)]))for(let _0xbf2fde=0x0;_0xbf2fde<_0x3a133d[_0x24b2fd(0x26f)][_0x24b2fd(0x25c)][_0x24b2fd(0x261)];_0xbf2fde+=0x1){socket['emit'](_0x24b2fd(0x221),{'UserId':Number(_0x3a133d[_0x24b2fd(0x26f)][_0x24b2fd(0x25c)][_0xbf2fde]),'SmsAccountId':Number(_0x3a133d['params']['id'])});}else socket[_0x24b2fd(0x1e9)]('userSmsAccount:remove',{'UserId':Number(_0x3a133d['query'][_0x24b2fd(0x25c)]),'SmsAccountId':Number(_0x3a133d[_0x24b2fd(0x1ae)]['id'])});});})['then'](respondWithStatusCode(_0x15df26,null))['catch'](handleError(_0x15df26,null));},exports[a642_0x577217(0x244)]=function(_0x279cba,_0x5f1a04){const _0x127a4a=a642_0x577217;let _0x5488d4={};const _0xc2ecf3={};let _0x4e408c,_0x2ed44a;return db['SmsAccount'][_0x127a4a(0x1d2)]({'where':{'id':_0x279cba[_0x127a4a(0x1ae)]['id']}})[_0x127a4a(0x23f)](handleEntityNotFound(_0x5f1a04,null))[_0x127a4a(0x23f)](function(_0x370cd4){const _0x150269=_0x127a4a;if(_0x370cd4)return _0x4e408c=_0x370cd4,_0xc2ecf3['model']=_[_0x150269(0x1e7)](db[_0x150269(0x207)][_0x150269(0x25d)]),_0xc2ecf3[_0x150269(0x26f)]=_['keys'](_0x279cba[_0x150269(0x26f)]),_0xc2ecf3[_0x150269(0x25a)]=_[_0x150269(0x214)](_0xc2ecf3[_0x150269(0x1a5)],_0xc2ecf3['query']),_0x5488d4[_0x150269(0x1b2)]=_[_0x150269(0x214)](_0xc2ecf3['model'],qs[_0x150269(0x1ff)](_0x279cba[_0x150269(0x26f)]['fields'])),_0x5488d4['attributes']=_0x5488d4[_0x150269(0x1b2)][_0x150269(0x261)]?_0x5488d4[_0x150269(0x1b2)]:_0xc2ecf3['model'],_0x5488d4[_0x150269(0x1df)]=qs[_0x150269(0x20d)](_0x279cba[_0x150269(0x26f)][_0x150269(0x20d)]),_0x5488d4[_0x150269(0x1ad)]=qs['filters'](_[_0x150269(0x1e3)](_0x279cba[_0x150269(0x26f)],_0xc2ecf3[_0x150269(0x25a)])),_0x5488d4=filterAttributes(_0x5488d4,_0x279cba[_0x150269(0x26f)][_0x150269(0x1a8)],_0x5488d4[_0x150269(0x1b2)],_0x279cba[_0x150269(0x1d1)],![]),_0x4e408c[_0x150269(0x244)](_0x5488d4);})[_0x127a4a(0x23f)](function(_0x394824){const _0x3365c8=_0x127a4a;if(_0x394824)return _0x2ed44a=_0x394824[_0x3365c8(0x261)],typeof _0x279cba['query'][_0x3365c8(0x1c8)]===_0x3365c8(0x1ec)&&(_0x5488d4[_0x3365c8(0x1a4)]=qs[_0x3365c8(0x1a4)](_0x279cba[_0x3365c8(0x26f)]['limit']),_0x5488d4['offset']=qs[_0x3365c8(0x237)](_0x279cba[_0x3365c8(0x26f)]['offset'])),_0x4e408c['getAgents'](_0x5488d4);})[_0x127a4a(0x23f)](function(_0x482117){if(_0x482117)return _0x482117?{'count':_0x2ed44a,'rows':_0x482117}:null;})[_0x127a4a(0x23f)](respondWithResult(_0x5f1a04,null))[_0x127a4a(0x23e)](handleError(_0x5f1a04,null));};