f855c608bfa3a363014c7df379e605aa0950ead8
[motion-next.git] / server / api / smsAccount / smsAccount.controller.js
1 const a542_0x470f=['Content-Range','DESC','infobip','from\x20is\x20mandatory','UserProfileResource','autoAssociation','createdAt','findAndCountAll','code','CmContact','statusInt','addAgents','type','inspect','User','message_id','offset','model','<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>','attributes','mobile','Content-Type','updatedAt','removeDispositions','SmsMessage','addApplications','query','body','fullname','fields','isArray','undefined','order','DELIVRD','Pause','util','CannedAnswer','clicksend','keys','entity\x20found','merge','include','params','describe','message-id','transaction','SmsAccounts','body\x20is\x20mandatory\x20and\x20not\x20empty','filters','addDisposition','intelepeer','account','destroy','RECEIVED_BY_RECIPIENT','text/xml','SmsInteraction','applications','omit','from','ListId','difference','request\x20sent','map','stack','waitForTheAssignedAgent','interaction','rows','isNil','catch','*,*,*,*','jayson/promise','VIRTUAL','defaults','skebby_dispatch_id','info','update','refid','rawAttributes','messageId','includes','SmsAccountId','priority','status','internal','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','debug','sequelize','connectel','asc','error','emit','Applications','fromNumber','tag','send','userProfileId','then','index','length','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','userSmsAccount:remove','notify','pick','addAnswer','status_code','client','Contacts','Messages','Tags','name','requestid','autoclose','UserProfileSection','request','endpoint\x20/status\x20POST\x20/','getApplications','./smsAccount.socket','findOne','SmsAccount,\x20%s,\x20%s','set','result','unshift','mapKey','skebby','SmsAccount','includeAll','receiveMessage','where','user','Text','limit','intersection','contact','CompanyId','error_code','findAll','count','filter','originatingAddress','getAgents','startRouting','statusGet','fieldName','replyMessageId','results','../../config/logger','UserId','../../rediscache','From','sender','removeAgents','http','log','SmsApplication','groupName','Start','like','sms','Contact','SmsAccount,\x20%s,\x20%s,\x20%s,\x20%s','ids','csc','text','DELIVERED','close','key','create','state','getInteractions','received\x20delivery\x20report\x20from','dataValues','agent','push','sort','List','mandatoryDispositionPause','sendStatus','options','orderBy','message','SmsAccount,\x20%s,\x20%s,\x20%s','Owner','nolimit','out','json','ACCEPTD','getDispositions','end','removeAnswers','plivo','no\x20available\x20attributes','clickatell','Disposition','../../mysqldb','get','stringify','redif','../../components/parsers/qs','to\x20is\x20mandatory'];(function(_0x2e5d6e,_0x470fda){const _0x2922e7=function(_0xc131bd){while(--_0xc131bd){_0x2e5d6e['push'](_0x2e5d6e['shift']());}};_0x2922e7(++_0x470fda);}(a542_0x470f,0x18e));const a542_0x2922=function(_0x2e5d6e,_0x470fda){_0x2e5d6e=_0x2e5d6e-0x0;let _0x2922e7=a542_0x470f[_0x2e5d6e];return _0x2922e7;};const _0x28cdd3=a542_0x2922;'use strict';const util=require(_0x28cdd3('0x23')),_=require('lodash'),qs=require(_0x28cdd3('0xc5')),logger=require(_0x28cdd3('0x91'))('api'),{getSocket}=require(_0x28cdd3('0x93')),socket=getSocket(),db=require(_0x28cdd3('0xc1'))['db'],{Op,ValidationError}=require('sequelize');require(_0x28cdd3('0x74'))['register'](socket);const jayson=require(_0x28cdd3('0x46')),client=jayson[_0x28cdd3('0x69')][_0x28cdd3('0x97')]({'port':0x232c});function respondWithRpcPromise(_0xc131bd,_0x1c63eb,_0x335675,_0xc130ec){return new Promise(function(_0x2aad62,_0x3a9273){const _0x34c666=a542_0x2922,_0x441608=_0xc130ec||client;return _0x441608[_0x34c666('0x71')](_0xc131bd,_0x335675)[_0x34c666('0x60')](function(_0x49b5fa){const _0x38a04c=_0x34c666;logger[_0x38a04c('0x4a')](_0x38a04c('0x76'),_0x1c63eb,_0x38a04c('0x3d')),logger[_0x38a04c('0x55')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x1c63eb,_0x38a04c('0x3d'),JSON[_0x38a04c('0xc3')](_0x49b5fa));if(_0x49b5fa[_0x38a04c('0x59')]){if(_0x49b5fa[_0x38a04c('0x59')][_0x38a04c('0x8')]===0x1f4)return logger['error']('SmsAccount,\x20%s,\x20%s',_0x1c63eb,_0x49b5fa['error'][_0x38a04c('0xb3')]),_0x3a9273(_0x49b5fa[_0x38a04c('0x59')][_0x38a04c('0xb3')]);return logger[_0x38a04c('0x59')](_0x38a04c('0x76'),_0x1c63eb,_0x49b5fa[_0x38a04c('0x59')]['message']),_0x2aad62(_0x49b5fa[_0x38a04c('0x59')][_0x38a04c('0xb3')]);}else logger[_0x38a04c('0x4a')]('SmsAccount,\x20%s,\x20%s',_0x1c63eb,_0x38a04c('0x3d')),_0x2aad62(_0x49b5fa[_0x38a04c('0x78')][_0x38a04c('0xb3')]);})[_0x34c666('0x44')](function(_0x34ce3b){const _0x4abb0e=_0x34c666;logger[_0x4abb0e('0x59')](_0x4abb0e('0x76'),_0x1c63eb,_0x34ce3b),_0x3a9273(_0x34ce3b);});});}function respondWithStatusCode(_0x368a6a,_0x490f83){return _0x490f83=_0x490f83||0xcc,function(_0x58af60){const _0x266c0d=a542_0x2922;if(_0x58af60)return _0x368a6a[_0x266c0d('0xb0')](_0x490f83);return _0x368a6a[_0x266c0d('0x52')](_0x490f83)[_0x266c0d('0xbb')]();};}function respondWithResult(_0x50f750,_0x120803){return _0x120803=_0x120803||0xc8,function(_0x55d5fa){const _0x4889bf=a542_0x2922;if(_0x55d5fa)return _0x50f750[_0x4889bf('0x52')](_0x120803)['json'](_0x55d5fa);};}function respondWithFilteredResult(_0x5dc4f3,_0x2e8835){return function(_0xf0ca05){const _0x49d74e=a542_0x2922;if(_0xf0ca05){const _0x5abc32=_0xf0ca05[_0x49d74e('0x88')],_0x53e2c1=_0x2e8835[_0x49d74e('0x10')];let _0x3c51a8=_0x2e8835[_0x49d74e('0x10')]+_0x2e8835['limit'],_0x3a0ec4;return _0x3c51a8>=_0x5abc32?(_0x3c51a8=_0x5abc32,_0x3a0ec4=0xc8):_0x3a0ec4=0xce,_0x5dc4f3[_0x49d74e('0x52')](_0x3a0ec4),_0x5dc4f3[_0x49d74e('0x77')](_0x49d74e('0x0'),_0x53e2c1+'-'+_0x3c51a8+'/'+_0x5abc32)[_0x49d74e('0xb8')](_0xf0ca05);}return null;};}function saveUpdates(_0x1d7719){return function(_0xcf18de){const _0x1b87af=a542_0x2922;if(_0xcf18de)return _0xcf18de[_0x1b87af('0x4b')](_0x1d7719)[_0x1b87af('0x60')](function(_0x3f3682){return _0x3f3682;});return null;};}function removeEntity(_0xe3a6b){return function(_0x530b62){const _0x255120=a542_0x2922;if(_0x530b62)return _0x530b62[_0x255120('0x34')]()[_0x255120('0x60')](function(){const _0x1cff1f=_0x255120,_0x3ee9b2=_0x530b62[_0x1cff1f('0xc2')]({'plain':!![]}),_0xd8431=_0x1cff1f('0x2e');return db[_0x1cff1f('0x4')][_0x1cff1f('0x34')]({'where':{'type':_0xd8431,'resourceId':_0x3ee9b2['id']}})[_0x1cff1f('0x60')](function(){return _0x530b62;});})[_0x255120('0x60')](function(){const _0x4f95fa=_0x255120;_0xe3a6b[_0x4f95fa('0x52')](0xcc)['end']();});};}function handleEntityNotFound(_0x3412a5){return function(_0x5e920a){const _0x1a5c86=a542_0x2922;return!_0x5e920a&&_0x3412a5[_0x1a5c86('0xb0')](0x194),_0x5e920a;};}function handleError(_0x43fdb2,_0x2ab2d6){return _0x2ab2d6=_0x2ab2d6||0x1f4,function(_0x2e509d){const _0x564894=a542_0x2922;logger[_0x564894('0x59')](_0x2e509d[_0x564894('0x3f')]),_0x2e509d[_0x564894('0x6d')]&&delete _0x2e509d[_0x564894('0x6d')],_0x43fdb2[_0x564894('0x52')](_0x2ab2d6)[_0x564894('0x5e')](_0x2e509d);};}exports[_0x28cdd3('0x61')]=function(_0x3e19bc,_0x24df83){const _0x2841e0=_0x28cdd3;let _0xf0db3d={'include':[{'model':db['Pause'],'as':_0x2841e0('0xaf')}]};const _0x29c70a={},_0x5195e8={'count':0x0,'rows':[]},_0x1ca522=_[_0x2841e0('0x3e')](db['SmsAccount'][_0x2841e0('0x4d')],function(_0x492d62){const _0x3ef871=_0x2841e0;return{'name':_0x492d62[_0x3ef871('0x8e')],'type':_0x492d62[_0x3ef871('0xc')][_0x3ef871('0xa5')]};});_0x29c70a[_0x2841e0('0x11')]=_[_0x2841e0('0x3e')](_0x1ca522,'name'),_0x29c70a[_0x2841e0('0x1a')]=_['keys'](_0x3e19bc[_0x2841e0('0x1a')]),_0x29c70a[_0x2841e0('0x30')]=_[_0x2841e0('0x83')](_0x29c70a['model'],_0x29c70a[_0x2841e0('0x1a')]),_0xf0db3d['attributes']=_['intersection'](_0x29c70a[_0x2841e0('0x11')],qs[_0x2841e0('0x1d')](_0x3e19bc[_0x2841e0('0x1a')]['fields'])),_0xf0db3d[_0x2841e0('0x13')]=_0xf0db3d[_0x2841e0('0x13')][_0x2841e0('0x62')]?_0xf0db3d[_0x2841e0('0x13')]:_0x29c70a[_0x2841e0('0x11')];typeof _0x3e19bc[_0x2841e0('0x1a')][_0x2841e0('0xb6')]===_0x2841e0('0x1f')&&(_0xf0db3d['limit']=qs[_0x2841e0('0x82')](_0x3e19bc[_0x2841e0('0x1a')][_0x2841e0('0x82')]),_0xf0db3d['offset']=qs[_0x2841e0('0x10')](_0x3e19bc[_0x2841e0('0x1a')]['offset']));_0xf0db3d[_0x2841e0('0x20')]=qs['sort'](_0x3e19bc[_0x2841e0('0x1a')]['sort']),_0xf0db3d[_0x2841e0('0x7f')]=qs[_0x2841e0('0x30')](_[_0x2841e0('0x66')](_0x3e19bc['query'],_0x29c70a[_0x2841e0('0x30')]),_0x1ca522);_0x3e19bc[_0x2841e0('0x1a')][_0x2841e0('0x89')]&&(_0xf0db3d[_0x2841e0('0x7f')]=_[_0x2841e0('0x28')](_0xf0db3d[_0x2841e0('0x7f')],{[Op['or']]:_[_0x2841e0('0x3e')](_0x1ca522,function(_0x26f896){const _0x14d4d9=_0x2841e0;if(_0x26f896[_0x14d4d9('0xc')]!==_0x14d4d9('0x47')){const _0x397436={};return _0x397436[_0x26f896[_0x14d4d9('0x6d')]]={[Op[_0x14d4d9('0x9c')]]:'%'+_0x3e19bc[_0x14d4d9('0x1a')][_0x14d4d9('0x89')]+'%'},_0x397436;}})}));_0xf0db3d=_[_0x2841e0('0x28')]({},_0xf0db3d,_0x3e19bc[_0x2841e0('0xb1')]);const _0x25d97c={'where':_0xf0db3d[_0x2841e0('0x7f')]};return db['SmsAccount'][_0x2841e0('0x88')](_0x25d97c)['then'](function(_0x5bfe13){const _0x34525d=_0x2841e0;return _0x5195e8[_0x34525d('0x88')]=_0x5bfe13,_0x3e19bc[_0x34525d('0x1a')][_0x34525d('0x7d')]&&(_0xf0db3d[_0x34525d('0x29')]=[{'all':!![]}]),db[_0x34525d('0x7c')]['findAll'](_0xf0db3d);})[_0x2841e0('0x60')](function(_0x1c1e91){const _0x1afd41=_0x2841e0;return _0x5195e8[_0x1afd41('0x42')]=_0x1c1e91,_0x5195e8;})[_0x2841e0('0x60')](respondWithFilteredResult(_0x24df83,_0xf0db3d))[_0x2841e0('0x44')](handleError(_0x24df83,null));},exports['show']=function(_0x4520dc,_0x47f845){const _0x443ab5=_0x28cdd3;let _0x125fca={'raw':![],'where':{'id':_0x4520dc['params']['id']},'include':[{'model':db[_0x443ab5('0x22')],'as':_0x443ab5('0xaf')}]};const _0x3c40d8={};return _0x3c40d8['model']=_[_0x443ab5('0x26')](db[_0x443ab5('0x7c')][_0x443ab5('0x4d')]),_0x3c40d8[_0x443ab5('0x1a')]=_[_0x443ab5('0x26')](_0x4520dc[_0x443ab5('0x1a')]),_0x3c40d8[_0x443ab5('0x30')]=_[_0x443ab5('0x83')](_0x3c40d8[_0x443ab5('0x11')],_0x3c40d8[_0x443ab5('0x1a')]),_0x125fca['attributes']=_[_0x443ab5('0x83')](_0x3c40d8['model'],qs[_0x443ab5('0x1d')](_0x4520dc[_0x443ab5('0x1a')][_0x443ab5('0x1d')])),_0x125fca[_0x443ab5('0x13')]=_0x125fca[_0x443ab5('0x13')][_0x443ab5('0x62')]?_0x125fca[_0x443ab5('0x13')]:_0x3c40d8[_0x443ab5('0x11')],_0x4520dc['query'][_0x443ab5('0x7d')]&&(_0x125fca[_0x443ab5('0x29')]=[{'all':!![]}]),_0x125fca=_['merge']({},_0x125fca,_0x4520dc['options']),db['SmsAccount'][_0x443ab5('0x75')](_0x125fca)['then'](handleEntityNotFound(_0x47f845,null))[_0x443ab5('0x60')](respondWithResult(_0x47f845,null))[_0x443ab5('0x44')](handleError(_0x47f845,null));},exports[_0x28cdd3('0xa6')]=function(_0x2eb52e,_0x241ddf){const _0x290ec4=_0x28cdd3;return db[_0x290ec4('0x7c')][_0x290ec4('0xa6')](_0x2eb52e[_0x290ec4('0x1b')],{})[_0x290ec4('0x60')](function(_0x49c0e0){const _0x38ee3d=_0x290ec4,_0x591632=_0x2eb52e[_0x38ee3d('0x80')][_0x38ee3d('0xc2')]({'plain':!![]});if(!_0x591632)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x591632['role']===_0x38ee3d('0x80')){const _0x5b647b=_0x49c0e0[_0x38ee3d('0xc2')]({'plain':!![]}),_0x55971b=_0x38ee3d('0x2e');return db[_0x38ee3d('0x70')][_0x38ee3d('0x75')]({'where':{'name':_0x55971b,'userProfileId':_0x591632[_0x38ee3d('0x5f')]},'raw':!![]})['then'](function(_0x38007e){const _0x507844=_0x38ee3d;return _0x38007e&&_0x38007e[_0x507844('0x5')]===0x0?db['UserProfileResource']['create']({'name':_0x5b647b[_0x507844('0x6d')],'resourceId':_0x5b647b['id'],'type':_0x38007e[_0x507844('0x6d')],'sectionId':_0x38007e['id']},{})[_0x507844('0x60')](function(){return _0x49c0e0;}):_0x49c0e0;})[_0x38ee3d('0x44')](function(_0x461e18){const _0x304ff7=_0x38ee3d;logger['error'](_0x304ff7('0x63'),_0x461e18);throw _0x461e18;});}return _0x49c0e0;})[_0x290ec4('0x60')](respondWithResult(_0x241ddf,0xc9))[_0x290ec4('0x44')](handleError(_0x241ddf,null));},exports[_0x28cdd3('0x4b')]=function(_0x4a5421,_0x5f4e4f){const _0x5bc94a=_0x28cdd3;return _0x4a5421[_0x5bc94a('0x1b')]['id']&&delete _0x4a5421[_0x5bc94a('0x1b')]['id'],db['SmsAccount'][_0x5bc94a('0x75')]({'where':{'id':_0x4a5421[_0x5bc94a('0x2a')]['id']},'include':[{'model':db[_0x5bc94a('0x22')],'as':_0x5bc94a('0xaf')}]})['then'](handleEntityNotFound(_0x5f4e4f,null))[_0x5bc94a('0x60')](saveUpdates(_0x4a5421[_0x5bc94a('0x1b')],null))[_0x5bc94a('0x60')](respondWithResult(_0x5f4e4f,null))[_0x5bc94a('0x44')](handleError(_0x5f4e4f,null));},exports[_0x28cdd3('0x34')]=function(_0x4b4abf,_0x2274fe){const _0x36cd17=_0x28cdd3;return db[_0x36cd17('0x7c')][_0x36cd17('0x75')]({'where':{'id':_0x4b4abf[_0x36cd17('0x2a')]['id']}})[_0x36cd17('0x60')](handleEntityNotFound(_0x2274fe,null))[_0x36cd17('0x60')](removeEntity(_0x2274fe,null))['catch'](handleError(_0x2274fe,null));},exports[_0x28cdd3('0x2b')]=function(_0xa2dde4,_0x30b444){const _0x2cdefc=_0x28cdd3;return db['SmsAccount'][_0x2cdefc('0x2b')]()['then'](respondWithResult(_0x30b444,null))[_0x2cdefc('0x44')](handleError(_0x30b444,null));},exports[_0x28cdd3('0x31')]=function(_0x327fbc,_0x448b9f){const _0x57e7ea=_0x28cdd3;return _0x327fbc[_0x57e7ea('0x1b')]['id']&&delete _0x327fbc[_0x57e7ea('0x1b')]['id'],db['SmsAccount'][_0x57e7ea('0x75')]({'where':{'id':_0x327fbc[_0x57e7ea('0x2a')]['id']}})[_0x57e7ea('0x60')](handleEntityNotFound(_0x448b9f,null))['then'](function(_0x453aea){const _0x59df64=_0x57e7ea;if(_0x453aea)return _0x327fbc[_0x59df64('0x1b')][_0x59df64('0x50')]=_0x453aea['id'],db[_0x59df64('0xc0')][_0x59df64('0xa6')](_0x327fbc[_0x59df64('0x1b')]);})[_0x57e7ea('0x60')](respondWithResult(_0x448b9f,null))[_0x57e7ea('0x44')](handleError(_0x448b9f,null));},exports[_0x28cdd3('0xba')]=function(_0x149ff0,_0x41981b){const _0x24ece9=_0x28cdd3;let _0x218f2e={'raw':![],'where':{}};const _0x1bbc0b={},_0xf32ef8={'count':0x0,'rows':[]};return db[_0x24ece9('0x7c')][_0x24ece9('0x75')]({'where':{'id':_0x149ff0['params']['id']}})[_0x24ece9('0x60')](handleEntityNotFound(_0x41981b,null))['then'](function(_0xa7a00){const _0x162402=_0x24ece9;if(_0xa7a00)return _0x1bbc0b['model']=_['keys'](db[_0x162402('0xc0')][_0x162402('0x4d')]),_0x1bbc0b[_0x162402('0x1a')]=_['keys'](_0x149ff0[_0x162402('0x1a')]),_0x1bbc0b[_0x162402('0x30')]=_[_0x162402('0x83')](_0x1bbc0b['model'],_0x1bbc0b[_0x162402('0x1a')]),_0x218f2e[_0x162402('0x13')]=_[_0x162402('0x83')](_0x1bbc0b[_0x162402('0x11')],qs[_0x162402('0x1d')](_0x149ff0[_0x162402('0x1a')]['fields'])),_0x218f2e[_0x162402('0x13')]=_0x218f2e[_0x162402('0x13')][_0x162402('0x62')]?_0x218f2e[_0x162402('0x13')]:_0x1bbc0b[_0x162402('0x11')],typeof _0x149ff0['query']['nolimit']===_0x162402('0x1f')&&(_0x218f2e[_0x162402('0x82')]=qs[_0x162402('0x82')](_0x149ff0['query'][_0x162402('0x82')]),_0x218f2e[_0x162402('0x10')]=qs[_0x162402('0x10')](_0x149ff0[_0x162402('0x1a')][_0x162402('0x10')])),_0x218f2e['order']=qs[_0x162402('0xad')](_0x149ff0[_0x162402('0x1a')]['sort']),_0x218f2e[_0x162402('0x7f')]=qs[_0x162402('0x30')](_['pick'](_0x149ff0[_0x162402('0x1a')],_0x1bbc0b[_0x162402('0x30')])),_0x218f2e[_0x162402('0x7f')][_0x162402('0x50')]=_0xa7a00['id'],_0x149ff0['query'][_0x162402('0x89')]&&(_0x218f2e['where']=_['merge'](_0x218f2e[_0x162402('0x7f')],{[Op['or']]:_['map'](_0x218f2e[_0x162402('0x13')],function(_0x52b48c){const _0x5ee267=_0x162402,_0xac731b={};return _0xac731b[_0x52b48c]={[Op['like']]:'%'+_0x149ff0[_0x5ee267('0x1a')][_0x5ee267('0x89')]+'%'},_0xac731b;})})),_0x218f2e=_['merge']({},_0x218f2e,_0x149ff0['options']),db[_0x162402('0xc0')][_0x162402('0x88')]({'where':_0x218f2e[_0x162402('0x7f')]})[_0x162402('0x60')](function(_0x5b6a37){const _0x4f9ac2=_0x162402;return _0xf32ef8[_0x4f9ac2('0x88')]=_0x5b6a37,_0x149ff0['query']['includeAll']&&(_0x218f2e[_0x4f9ac2('0x29')]=[{'all':!![]}]),db[_0x4f9ac2('0xc0')][_0x4f9ac2('0x87')](_0x218f2e);})[_0x162402('0x60')](function(_0x36c211){const _0x3f886e=_0x162402;return _0xf32ef8[_0x3f886e('0x42')]=_0x36c211,_0xf32ef8;});})[_0x24ece9('0x60')](respondWithFilteredResult(_0x41981b,_0x218f2e))['catch'](handleError(_0x41981b,null));},exports[_0x28cdd3('0x17')]=function(_0x2dabce,_0x57b28a){const _0x3c8d60=_0x28cdd3;return db['SmsAccount'][_0x3c8d60('0x75')]({'where':{'id':_0x2dabce[_0x3c8d60('0x2a')]['id']}})[_0x3c8d60('0x60')](handleEntityNotFound(_0x57b28a,null))[_0x3c8d60('0x60')](function(_0x53012e){const _0x24425e=_0x3c8d60;if(_0x53012e)return _0x53012e['removeDispositions'](_0x2dabce['query'][_0x24425e('0xa0')]);})[_0x3c8d60('0x60')](respondWithStatusCode(_0x57b28a,null))[_0x3c8d60('0x44')](handleError(_0x57b28a,null));},exports[_0x28cdd3('0x67')]=function(_0x180f33,_0x4dd4a8){const _0x196c27=_0x28cdd3;return _0x180f33[_0x196c27('0x1b')]['id']&&delete _0x180f33[_0x196c27('0x1b')]['id'],db[_0x196c27('0x7c')]['findOne']({'where':{'id':_0x180f33[_0x196c27('0x2a')]['id']}})['then'](handleEntityNotFound(_0x4dd4a8,null))[_0x196c27('0x60')](function(_0x2a5efc){const _0x246a01=_0x196c27;if(_0x2a5efc)return _0x180f33[_0x246a01('0x1b')][_0x246a01('0x50')]=_0x2a5efc['id'],db[_0x246a01('0x24')]['create'](_0x180f33[_0x246a01('0x1b')]);})[_0x196c27('0x60')](respondWithResult(_0x4dd4a8,null))[_0x196c27('0x44')](handleError(_0x4dd4a8,null));},exports['getAnswers']=function(_0x3e5f4a,_0x31190b){const _0x549db9=_0x28cdd3;let _0x4982fb={'raw':![],'where':{}};const _0x23e92b={},_0x28d02e={'count':0x0,'rows':[]};return db[_0x549db9('0x7c')][_0x549db9('0x75')]({'where':{'id':_0x3e5f4a[_0x549db9('0x2a')]['id']}})[_0x549db9('0x60')](handleEntityNotFound(_0x31190b,null))[_0x549db9('0x60')](function(_0xcbbaf3){const _0x27fec0=_0x549db9;if(_0xcbbaf3)return _0x23e92b[_0x27fec0('0x11')]=_[_0x27fec0('0x26')](db['CannedAnswer'][_0x27fec0('0x4d')]),_0x23e92b[_0x27fec0('0x1a')]=_[_0x27fec0('0x26')](_0x3e5f4a['query']),_0x23e92b[_0x27fec0('0x30')]=_[_0x27fec0('0x83')](_0x23e92b[_0x27fec0('0x11')],_0x23e92b[_0x27fec0('0x1a')]),_0x4982fb[_0x27fec0('0x13')]=_[_0x27fec0('0x83')](_0x23e92b['model'],qs[_0x27fec0('0x1d')](_0x3e5f4a[_0x27fec0('0x1a')][_0x27fec0('0x1d')])),_0x4982fb[_0x27fec0('0x13')]=_0x4982fb[_0x27fec0('0x13')]['length']?_0x4982fb[_0x27fec0('0x13')]:_0x23e92b['model'],typeof _0x3e5f4a[_0x27fec0('0x1a')]['nolimit']===_0x27fec0('0x1f')&&(_0x4982fb[_0x27fec0('0x82')]=qs[_0x27fec0('0x82')](_0x3e5f4a[_0x27fec0('0x1a')][_0x27fec0('0x82')]),_0x4982fb[_0x27fec0('0x10')]=qs[_0x27fec0('0x10')](_0x3e5f4a[_0x27fec0('0x1a')][_0x27fec0('0x10')])),_0x4982fb[_0x27fec0('0x20')]=qs[_0x27fec0('0xad')](_0x3e5f4a['query']['sort']),_0x4982fb[_0x27fec0('0x7f')]=qs[_0x27fec0('0x30')](_[_0x27fec0('0x66')](_0x3e5f4a[_0x27fec0('0x1a')],_0x23e92b[_0x27fec0('0x30')])),_0x4982fb[_0x27fec0('0x7f')][_0x27fec0('0x50')]=_0xcbbaf3['id'],_0x3e5f4a[_0x27fec0('0x1a')][_0x27fec0('0x89')]&&(_0x4982fb[_0x27fec0('0x7f')]=_[_0x27fec0('0x28')](_0x4982fb[_0x27fec0('0x7f')],{[Op['or']]:_[_0x27fec0('0x3e')](_0x4982fb[_0x27fec0('0x13')],function(_0xbb4266){const _0x48dba3=_0x27fec0,_0x10cba9={};return _0x10cba9[_0xbb4266]={[Op[_0x48dba3('0x9c')]]:'%'+_0x3e5f4a['query'][_0x48dba3('0x89')]+'%'},_0x10cba9;})})),_0x4982fb=_[_0x27fec0('0x28')]({},_0x4982fb,_0x3e5f4a[_0x27fec0('0xb1')]),db[_0x27fec0('0x24')]['count']({'where':_0x4982fb[_0x27fec0('0x7f')]})[_0x27fec0('0x60')](function(_0x35afc8){const _0x554447=_0x27fec0;return _0x28d02e[_0x554447('0x88')]=_0x35afc8,_0x3e5f4a[_0x554447('0x1a')]['includeAll']&&(_0x4982fb[_0x554447('0x29')]=[{'all':!![]}]),db[_0x554447('0x24')][_0x554447('0x87')](_0x4982fb);})['then'](function(_0x30d639){const _0x532bc3=_0x27fec0;return _0x28d02e[_0x532bc3('0x42')]=_0x30d639,_0x28d02e;});})[_0x549db9('0x60')](respondWithFilteredResult(_0x31190b,_0x4982fb))[_0x549db9('0x44')](handleError(_0x31190b,null));},exports[_0x28cdd3('0xbc')]=function(_0x2402eb,_0x29a931){const _0x461ec4=_0x28cdd3;return db[_0x461ec4('0x7c')][_0x461ec4('0x75')]({'where':{'id':_0x2402eb['params']['id']}})[_0x461ec4('0x60')](handleEntityNotFound(_0x29a931,null))[_0x461ec4('0x60')](function(_0x3bf97d){const _0x4074d9=_0x461ec4;if(_0x3bf97d)return _0x3bf97d['removeAnswers'](_0x2402eb[_0x4074d9('0x1a')]['ids']);})[_0x461ec4('0x60')](respondWithStatusCode(_0x29a931,null))[_0x461ec4('0x44')](handleError(_0x29a931,null));},exports[_0x28cdd3('0x65')]=function(_0xb9f965,_0x1e03fd){const _0x1d930e=_0x28cdd3,_0xde54ba={'channel':_0x1d930e('0x9d')};let _0x30862e=[],_0x28acf1=[];const _0x45f977={};return db['SmsAccount'][_0x1d930e('0x75')]({'where':{'id':_0xb9f965[_0x1d930e('0x2a')]['id']},'include':[{'model':db['SmsApplication'],'as':_0x1d930e('0x5b')}]})['then'](handleEntityNotFound(_0x1e03fd,null))[_0x1d930e('0x60')](function(_0x3b6f09){const _0x3a8ed6=_0x1d930e;return _0xde54ba['account']=_0x3b6f09,_0xde54ba[_0x3a8ed6('0x38')]=_[_0x3a8ed6('0xb2')](_0x3b6f09['Applications'],[_0x3a8ed6('0x51')],[_0x3a8ed6('0x58')]),_0xde54ba[_0x3a8ed6('0x33')][_0x3a8ed6('0x5b')]&&delete _0xde54ba[_0x3a8ed6('0x33')][_0x3a8ed6('0x5b')],db['CmContact'][_0x3a8ed6('0x2b')]();})[_0x1d930e('0x60')](function(_0x328d61){const _0x2b45d7=_0x1d930e;if(!_0x328d61)throw new ValidationError(_0x2b45d7('0xbe'));_0x30862e=_[_0x2b45d7('0x3c')](_['keys'](_0x328d61),[_0x2b45d7('0x6'),_0x2b45d7('0x16')]),_0x28acf1=_[_0x2b45d7('0x3c')](_[_0x2b45d7('0x26')](_0x328d61),[_0x2b45d7('0x6'),'updatedAt',_0x2b45d7('0x85'),_0x2b45d7('0x3b')]),_0xde54ba[_0x2b45d7('0x1b')]={'mapKey':_0x2b45d7('0x14')};if(_0xde54ba['account']['type'])switch(_0xde54ba[_0x2b45d7('0x33')][_0x2b45d7('0xc')]){case'twilio':_0xde54ba['body']['from']=_0xb9f965[_0x2b45d7('0x1b')][_0x2b45d7('0x94')],_0xde54ba[_0x2b45d7('0x1b')][_0x2b45d7('0x1b')]=_0xb9f965['body']['Body'],_0xde54ba['body'][_0x2b45d7('0x4e')]=_0xb9f965[_0x2b45d7('0x1b')]['MessageSid'];break;case _0x2b45d7('0x7b'):_0xde54ba['body']['from']='+'+_0xb9f965['body'][_0x2b45d7('0x95')],_0xde54ba[_0x2b45d7('0x1b')][_0x2b45d7('0x1b')]=_0xb9f965['body'][_0x2b45d7('0xa2')];break;case'connectel':_0xde54ba[_0x2b45d7('0x1b')][_0x2b45d7('0x3a')]=_0xb9f965['body'][_0x2b45d7('0x3a')],_0xde54ba[_0x2b45d7('0x1b')]['body']=_0xb9f965['body'][_0x2b45d7('0xb3')];break;case _0x2b45d7('0x25'):_0xde54ba[_0x2b45d7('0x1b')][_0x2b45d7('0x3a')]=_0xb9f965[_0x2b45d7('0x1b')][_0x2b45d7('0x3a')],_0xde54ba['body'][_0x2b45d7('0x1b')]=_0xb9f965[_0x2b45d7('0x1b')]['body'],_0xde54ba['body'][_0x2b45d7('0x4e')]=_0xb9f965['body'][_0x2b45d7('0xf')];break;case _0x2b45d7('0xbd'):_0xde54ba['body']['from']=_0xb9f965[_0x2b45d7('0x1b')][_0x2b45d7('0x94')],_0xde54ba[_0x2b45d7('0x1b')][_0x2b45d7('0x1b')]=_0xb9f965[_0x2b45d7('0x1b')][_0x2b45d7('0x81')],_0xde54ba['body'][_0x2b45d7('0x4e')]=_0xb9f965[_0x2b45d7('0x1b')]['MessageUUID'];break;case _0x2b45d7('0x2'):_0xde54ba[_0x2b45d7('0x1b')]['from']='+'+_0xb9f965['body'][_0x2b45d7('0x90')][0x0]['from'],_0xde54ba[_0x2b45d7('0x1b')][_0x2b45d7('0x1b')]=_0xb9f965[_0x2b45d7('0x1b')]['results'][0x0]['text'],_0xde54ba[_0x2b45d7('0x1b')]['messageId']=_0xb9f965[_0x2b45d7('0x1b')][_0x2b45d7('0x90')][0x0]['messageId'];break;case _0x2b45d7('0xa1'):_0xde54ba['body'][_0x2b45d7('0x3a')]=_0xb9f965[_0x2b45d7('0x1b')][_0x2b45d7('0x8a')],_0xde54ba[_0x2b45d7('0x1b')]['body']=_0xb9f965['body']['segmentedMessage'][_0x2b45d7('0xb3')];break;case _0x2b45d7('0xbf'):_0xde54ba[_0x2b45d7('0x1b')]['from']=_0xb9f965[_0x2b45d7('0x1b')][_0x2b45d7('0x5c')],_0xde54ba[_0x2b45d7('0x1b')]['body']=_0xb9f965[_0x2b45d7('0x1b')][_0x2b45d7('0xa2')],_0xde54ba[_0x2b45d7('0x1b')]['messageId']=_0xb9f965[_0x2b45d7('0x1b')][_0x2b45d7('0x8f')];break;case _0x2b45d7('0x32'):_0xde54ba[_0x2b45d7('0x1b')][_0x2b45d7('0x3a')]=_0xb9f965['body'][_0x2b45d7('0x3a')],_0xde54ba['body'][_0x2b45d7('0x1b')]=_0xb9f965[_0x2b45d7('0x1b')]['message'],_0xde54ba[_0x2b45d7('0x1b')][_0x2b45d7('0x4e')]=_0xb9f965[_0x2b45d7('0x1b')][_0x2b45d7('0x4c')];break;}_0xde54ba['body']['id']&&delete _0xde54ba[_0x2b45d7('0x1b')]['id'];if(_[_0x2b45d7('0x43')](_0xde54ba[_0x2b45d7('0x1b')]['from']))throw new ValidationError(_0x2b45d7('0x3'));if(_[_0x2b45d7('0x43')](_0xde54ba[_0x2b45d7('0x1b')][_0x2b45d7('0x1b')])||_0xde54ba[_0x2b45d7('0x1b')][_0x2b45d7('0x1b')]==='')throw new ValidationError(_0x2b45d7('0x2f'));if(_[_0x2b45d7('0x43')](_0xde54ba['body']['mapKey']))throw new ValidationError(_0x2b45d7('0x54')+_0x28acf1);if(!_[_0x2b45d7('0x4f')](_0x28acf1,_0xde54ba['body'][_0x2b45d7('0x7a')]))throw new ValidationError('mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x28acf1);return _0x45f977[_0xde54ba[_0x2b45d7('0x1b')][_0x2b45d7('0x7a')]]=_0xde54ba[_0x2b45d7('0x1b')]['from'],db['CmList']['findOne']({'where':{'id':_0xde54ba['account'][_0x2b45d7('0x3b')]},'include':[{'model':db[_0x2b45d7('0x9')],'as':_0x2b45d7('0x6a'),'where':_0x45f977,'limit':0x1,'order':[[_0x2b45d7('0x16'),_0x2b45d7('0x1')]]}]});})['then'](handleEntityNotFound(_0x1e03fd,null))[_0x1d930e('0x60')](function(_0x3eca6c){const _0x1e0f11=_0x1d930e;if(_0x3eca6c){_0xde54ba['list']=_[_0x1e0f11('0x39')](_0x3eca6c,[_0x1e0f11('0x6a')]);if(_0x3eca6c[_0x1e0f11('0x6a')][_0x1e0f11('0x62')])return _0x3eca6c[_0x1e0f11('0x6a')][0x0];const _0x4561a1=_[_0x1e0f11('0x48')](_0xde54ba[_0x1e0f11('0x1b')],{'firstName':_0xde54ba[_0x1e0f11('0x1b')][_0x1e0f11('0x3a')],'ListId':_0x3eca6c['id']});return _0x4561a1[_0xde54ba[_0x1e0f11('0x1b')][_0x1e0f11('0x7a')]]=_0xde54ba[_0x1e0f11('0x1b')][_0x1e0f11('0x3a')],db['CmContact'][_0x1e0f11('0xa6')](_0x4561a1,{'fields':_0x30862e,'raw':!![]});}})['then'](handleEntityNotFound(_0x1e03fd,null))[_0x1d930e('0x60')](function(_0x40804d){const _0x3c733e=_0x1d930e;if(_0x40804d){_0xde54ba[_0x3c733e('0x84')]=_0x40804d;const _0x1f7d26={'ContactId':_0x40804d['id'],'phone':_0xde54ba[_0x3c733e('0x1b')][_0x3c733e('0x3a')],'SmsAccountId':_0xb9f965[_0x3c733e('0x2a')]['id']},_0x524894={'ContactId':_0x40804d['id'],'SmsAccountId':_0xb9f965[_0x3c733e('0x2a')]['id'],'closed':![]};return db['SmsInteraction'][_0x3c733e('0x75')]({'where':_0x524894})[_0x3c733e('0x60')](function(_0x4c9095){const _0x5af34f=_0x3c733e;if(_0x4c9095)return[_0x4c9095,![]];return db[_0x5af34f('0x37')]['create'](_0x1f7d26)[_0x5af34f('0x60')](function(_0x2f02f9){return[_0x2f02f9,!![]];});});}})[_0x1d930e('0x60')](function([_0x489d86,_0x3c5700]){const _0x3e1c41=_0x1d930e;return _0xde54ba['interaction']=_0x489d86['get']({'plain':!![]}),_0xde54ba['interaction']['created']=![],_0x3c5700&&(_0xde54ba['account'][_0x3e1c41('0x6f')]&&_0xde54ba[_0x3e1c41('0x38')]['push']({'id':0x0,'priority':_0xde54ba[_0x3e1c41('0x38')][_0x3e1c41('0x62')]+0x1,'app':_0x3e1c41('0xa4'),'appdata':'unmanaged','interval':_0x3e1c41('0x45')}),_0xde54ba['interaction']['created']=!![]),db[_0x3e1c41('0x18')]['create']({'phone':_0xde54ba['body']['from'],'messageId':_0xde54ba['body'][_0x3e1c41('0x4e')],'body':_0xde54ba['body']['body'],'SmsAccountId':_0xb9f965[_0x3e1c41('0x2a')]['id'],'SmsInteractionId':_0x489d86['id'],'direction':'in','ContactId':_0x489d86['ContactId'],'AttachmentId':_0xde54ba[_0x3e1c41('0x1b')]['AttachmentId']});})[_0x1d930e('0x60')](function(_0x46bc22){const _0x48e82a=_0x1d930e;_0xde54ba[_0x48e82a('0xb3')]=_0x46bc22;if(_0xde54ba[_0x48e82a('0x41')][_0x48e82a('0x92')])return db['User'][_0x48e82a('0x75')]({'attributes':['id','name'],'where':{'id':_0xde54ba[_0x48e82a('0x41')][_0x48e82a('0x92')]}})[_0x48e82a('0x60')](function(_0x4fce75){const _0x4c52a8=_0x48e82a;return _0x4fce75&&_0xde54ba[_0x4c52a8('0x38')][_0x4c52a8('0x79')]({'id':0x0,'priority':0x0,'app':_0x4c52a8('0xab'),'appdata':_0x4fce75['name']+','+(_0xde54ba[_0x4c52a8('0x33')][_0x4c52a8('0x40')]||0xa),'interval':_0x4c52a8('0x45')}),respondWithRpcPromise(_0x4c52a8('0x9b'),_0x4c52a8('0x8c'),_0xde54ba);});return respondWithRpcPromise(_0x48e82a('0x9b'),_0x48e82a('0x8c'),_0xde54ba);})['then'](function(_0x5673ef){const _0x2a3fb2=_0x1d930e;if(_0x5673ef){const _0x1a3526=0xc8,_0x32cf2b=_0x2a3fb2('0x7e');return logger[_0x2a3fb2('0x4a')](_0x2a3fb2('0xb4'),_0x32cf2b,_0x1a3526,_0x2a3fb2('0x27')),logger['debug'](_0x2a3fb2('0x9f'),_0x32cf2b,_0x1a3526,_0x2a3fb2('0x27'),JSON[_0x2a3fb2('0xc3')](_0x5673ef)),_0xde54ba['account'][_0x2a3fb2('0xc')]==='twilio'?_0x1e03fd[_0x2a3fb2('0x52')](_0x1a3526)[_0x2a3fb2('0x77')](_0x2a3fb2('0x15'),_0x2a3fb2('0x36'))[_0x2a3fb2('0x5e')](_0x2a3fb2('0x12')):_0x1e03fd[_0x2a3fb2('0x52')](_0x1a3526)[_0x2a3fb2('0xb8')](_0x5673ef);}})[_0x1d930e('0x44')](handleError(_0x1e03fd,null));},exports[_0x28cdd3('0x19')]=function(_0x1d5f86,_0x2e8e74){const _0x3821f2=_0x28cdd3;return db[_0x3821f2('0x7c')][_0x3821f2('0x75')]({'where':{'id':_0x1d5f86[_0x3821f2('0x2a')]['id']}})[_0x3821f2('0x60')](handleEntityNotFound(_0x2e8e74,null))[_0x3821f2('0x60')](function(_0x2d2029){const _0x57720f=_0x3821f2;if(_0x2d2029)return db[_0x57720f('0x56')][_0x57720f('0x2d')](function(_0x41653e){const _0x572a67=_0x57720f;return db[_0x572a67('0x99')][_0x572a67('0x34')]({'where':{'SmsAccountId':_0x1d5f86['params']['id']},'transaction':_0x41653e})[_0x572a67('0x60')](function(){const _0x1592e4=_0x572a67,_0x4db95b=_[_0x1592e4('0x3e')](_0x1d5f86[_0x1592e4('0x1b')],function(_0x3a047a){const _0x21b9ab=_0x1592e4;return _0x3a047a[_0x21b9ab('0x50')]=_0x1d5f86[_0x21b9ab('0x2a')]['id'],_0x3a047a;});return db['SmsApplication']['bulkCreate'](_0x4db95b,{'transaction':_0x41653e});});})[_0x57720f('0x60')](function(){const _0x2d664c=_0x57720f;return db['SmsApplication'][_0x2d664c('0x7')]({'where':{'SmsAccountId':_0x1d5f86['params']['id']},'order':_0x2d664c('0x51')});});})[_0x3821f2('0x60')](respondWithResult(_0x2e8e74,null))['catch'](handleError(_0x2e8e74,null));},exports[_0x28cdd3('0x73')]=function(_0x451080,_0x713e6){const _0x17aaaa=_0x28cdd3;let _0x184790={};const _0x56434e={};let _0x4576ad,_0x1ce543;return db[_0x17aaaa('0x7c')][_0x17aaaa('0x75')]({'where':{'id':_0x451080[_0x17aaaa('0x2a')]['id']}})[_0x17aaaa('0x60')](handleEntityNotFound(_0x713e6,null))[_0x17aaaa('0x60')](function(_0xc87c94){const _0x26f2ce=_0x17aaaa;if(_0xc87c94)return _0x4576ad=_0xc87c94,_0x56434e[_0x26f2ce('0x11')]=_[_0x26f2ce('0x26')](db[_0x26f2ce('0x99')][_0x26f2ce('0x4d')]),_0x56434e[_0x26f2ce('0x1a')]=_['keys'](_0x451080[_0x26f2ce('0x1a')]),_0x56434e[_0x26f2ce('0x30')]=_['intersection'](_0x56434e[_0x26f2ce('0x11')],_0x56434e[_0x26f2ce('0x1a')]),_0x184790[_0x26f2ce('0x13')]=_[_0x26f2ce('0x83')](_0x56434e[_0x26f2ce('0x11')],qs[_0x26f2ce('0x1d')](_0x451080['query'][_0x26f2ce('0x1d')])),_0x184790['attributes']=_0x184790[_0x26f2ce('0x13')][_0x26f2ce('0x62')]?_0x184790[_0x26f2ce('0x13')]:_0x56434e['model'],_0x184790[_0x26f2ce('0x20')]=qs[_0x26f2ce('0xad')](_0x451080[_0x26f2ce('0x1a')][_0x26f2ce('0xad')]),_0x184790[_0x26f2ce('0x7f')]=qs['filters'](_[_0x26f2ce('0x66')](_0x451080[_0x26f2ce('0x1a')],_0x56434e['filters'])),_0x451080[_0x26f2ce('0x1a')][_0x26f2ce('0x89')]&&(_0x184790[_0x26f2ce('0x7f')]=_['merge'](_0x184790['where'],{[Op['or']]:_[_0x26f2ce('0x3e')](_0x184790[_0x26f2ce('0x13')],function(_0x3400eb){const _0x431959=_0x26f2ce,_0x38bbd5={};return _0x38bbd5[_0x3400eb]={[Op[_0x431959('0x9c')]]:'%'+_0x451080['query'][_0x431959('0x89')]+'%'},_0x38bbd5;})})),_0x184790=_[_0x26f2ce('0x28')]({},_0x184790,_0x451080[_0x26f2ce('0xb1')]),_0x4576ad[_0x26f2ce('0x73')](_0x184790);})[_0x17aaaa('0x60')](function(_0x5db273){const _0x185bca=_0x17aaaa;if(_0x5db273)return _0x1ce543=_0x5db273[_0x185bca('0x62')],typeof _0x451080[_0x185bca('0x1a')][_0x185bca('0xb6')]==='undefined'&&(_0x184790[_0x185bca('0x82')]=qs[_0x185bca('0x82')](_0x451080[_0x185bca('0x1a')][_0x185bca('0x82')]),_0x184790[_0x185bca('0x10')]=qs[_0x185bca('0x10')](_0x451080[_0x185bca('0x1a')][_0x185bca('0x10')])),_0x4576ad['getApplications'](_0x184790);})[_0x17aaaa('0x60')](function(_0x53acc7){if(_0x53acc7)return _0x53acc7?{'count':_0x1ce543,'rows':_0x53acc7}:null;})['then'](respondWithResult(_0x713e6,null))['catch'](handleError(_0x713e6,null));},exports[_0x28cdd3('0xa8')]=function(_0x98626d,_0x419bea){const _0x4a86e7=_0x28cdd3;let _0x32d9b7={'raw':![],'where':{}};const _0xe1ef2d={},_0x3637c2={'count':0x0,'rows':[]};return db[_0x4a86e7('0x7c')][_0x4a86e7('0x75')]({'where':{'id':_0x98626d[_0x4a86e7('0x2a')]['id']}})[_0x4a86e7('0x60')](handleEntityNotFound(_0x419bea,null))[_0x4a86e7('0x60')](function(_0x22d9f1){const _0x4eb498=_0x4a86e7;if(_0x22d9f1)return _0xe1ef2d[_0x4eb498('0x11')]=_[_0x4eb498('0x26')](db[_0x4eb498('0x37')][_0x4eb498('0x4d')]),_0xe1ef2d['query']=_[_0x4eb498('0x26')](_0x98626d[_0x4eb498('0x1a')]),_0xe1ef2d[_0x4eb498('0x30')]=_[_0x4eb498('0x83')](_0xe1ef2d[_0x4eb498('0x11')],_0xe1ef2d['query']),_0x32d9b7['attributes']=_[_0x4eb498('0x83')](_0xe1ef2d[_0x4eb498('0x11')],qs[_0x4eb498('0x1d')](_0x98626d[_0x4eb498('0x1a')][_0x4eb498('0x1d')])),_0x32d9b7['attributes']=_0x32d9b7[_0x4eb498('0x13')][_0x4eb498('0x62')]?_0x32d9b7[_0x4eb498('0x13')]:_0xe1ef2d[_0x4eb498('0x11')],typeof _0x98626d['query'][_0x4eb498('0xb6')]==='undefined'&&(_0x32d9b7[_0x4eb498('0x82')]=qs['limit'](_0x98626d[_0x4eb498('0x1a')]['limit']),_0x32d9b7[_0x4eb498('0x10')]=qs[_0x4eb498('0x10')](_0x98626d[_0x4eb498('0x1a')]['offset'])),_0x32d9b7[_0x4eb498('0x20')]=qs[_0x4eb498('0xad')](_0x98626d[_0x4eb498('0x1a')][_0x4eb498('0xad')]),_0x32d9b7[_0x4eb498('0x7f')]=qs['filters'](_[_0x4eb498('0x66')](_0x98626d[_0x4eb498('0x1a')],_0xe1ef2d[_0x4eb498('0x30')])),_0x32d9b7[_0x4eb498('0x7f')][_0x4eb498('0x50')]=_0x22d9f1['id'],_0x98626d[_0x4eb498('0x1a')]['filter']&&(_0x32d9b7['where']=_[_0x4eb498('0x28')](_0x32d9b7[_0x4eb498('0x7f')],{[Op['or']]:_[_0x4eb498('0x3e')](_0x32d9b7[_0x4eb498('0x13')],function(_0x11d24b){const _0x210c2f=_0x4eb498,_0x211a97={};return _0x211a97[_0x11d24b]={[Op[_0x210c2f('0x9c')]]:'%'+_0x98626d[_0x210c2f('0x1a')][_0x210c2f('0x89')]+'%'},_0x211a97;})})),_0x32d9b7=_['merge']({},_0x32d9b7,_0x98626d[_0x4eb498('0xb1')]),db['SmsInteraction']['count']({'where':_0x32d9b7[_0x4eb498('0x7f')]})[_0x4eb498('0x60')](function(_0xf40ac6){const _0x168f9f=_0x4eb498;return _0x3637c2[_0x168f9f('0x88')]=_0xf40ac6,_0x98626d[_0x168f9f('0x1a')][_0x168f9f('0x7d')]&&(_0x32d9b7[_0x168f9f('0x29')]=[{'model':db['CmContact'],'as':_0x168f9f('0x9e'),'required':![]},{'model':db[_0x168f9f('0xe')],'as':_0x168f9f('0xb5'),'attributes':[_0x168f9f('0x6d'),_0x168f9f('0x1c'),_0x168f9f('0x53')],'required':![]},{'model':db['Tag'],'as':_0x168f9f('0x6c'),'attributes':['id',_0x168f9f('0x6d'),'color'],'where':_0x98626d[_0x168f9f('0x1a')][_0x168f9f('0x5d')]?{'id':_0x98626d[_0x168f9f('0x1a')][_0x168f9f('0x5d')]}:undefined,'required':_0x98626d[_0x168f9f('0x1a')][_0x168f9f('0x5d')]?!![]:![]}]),db['SmsInteraction'][_0x168f9f('0x87')](_0x32d9b7);})[_0x4eb498('0x60')](function(_0x429ba3){const _0x19fe62=_0x4eb498;return _0x3637c2[_0x19fe62('0x42')]=_0x429ba3,_0x3637c2;});})[_0x4a86e7('0x60')](respondWithFilteredResult(_0x419bea,_0x32d9b7))[_0x4a86e7('0x44')](handleError(_0x419bea,null));},exports[_0x28cdd3('0x5e')]=function(_0x408fea,_0x876962){const _0xf65987=_0x28cdd3;let _0x593e18,_0xbc2105;if(_[_0xf65987('0x43')](_0x408fea[_0xf65987('0x1b')][_0xf65987('0x1b')])||_0x408fea[_0xf65987('0x1b')][_0xf65987('0x1b')]==='')throw new ValidationError(_0xf65987('0x2f'));if(_[_0xf65987('0x43')](_0x408fea[_0xf65987('0x1b')]['to']))throw new ValidationError(_0xf65987('0xc6'));const _0xc97f78=_0x408fea[_0xf65987('0x1b')]['to'];return db[_0xf65987('0x7c')][_0xf65987('0x75')]({'where':{'id':_0x408fea[_0xf65987('0x2a')]['id']},'include':[{'model':db['CmList'],'as':_0xf65987('0xae'),'include':[{'model':db[_0xf65987('0x9')],'as':_0xf65987('0x6a'),'where':{'mobile':_0xc97f78},'limit':0x1,'order':[[_0xf65987('0x16'),_0xf65987('0x1')]]}]}]})['then'](handleEntityNotFound(_0x876962,null))[_0xf65987('0x60')](function(_0x16c8c7){const _0x5d81d5=_0xf65987;if(_0x16c8c7&&_0x16c8c7[_0x5d81d5('0xae')]){_0x593e18=_0x16c8c7[_0x5d81d5('0xc2')]({'plain':!![]});if(_0x593e18[_0x5d81d5('0xae')]&&_0x593e18[_0x5d81d5('0xae')]['Contacts'][_0x5d81d5('0x62')])return _0x593e18[_0x5d81d5('0xae')][_0x5d81d5('0x6a')][0x0];return db['CmContact'][_0x5d81d5('0xa6')](_[_0x5d81d5('0x48')](_0x408fea['body'],{'firstName':_0xc97f78,'mobile':_0xc97f78,'phone':_0xc97f78,'ListId':_0x593e18[_0x5d81d5('0x3b')]}));}})[_0xf65987('0x60')](handleEntityNotFound(_0x876962,null))[_0xf65987('0x60')](function(_0x2fcf94){const _0xde5353=_0xf65987;if(_0x2fcf94)return _0xbc2105=_0x2fcf94,db[_0xde5353('0x37')][_0xde5353('0x75')]({'where':{'ContactId':_0xbc2105['id'],'closed':![],'SmsAccountId':_0x593e18['id']}})[_0xde5353('0x60')](function(_0x2fb102){const _0x384a84=_0xde5353;if(_0x2fb102)return[_0x2fb102,![]];return db['SmsInteraction'][_0x384a84('0xa6')]({'UserId':_0x408fea[_0x384a84('0x80')]['id'],'ContactId':_0xbc2105['id'],'SmsAccountId':_0x593e18['id'],'phone':_0xc97f78,'firstMsgDirection':_0x384a84('0xb7'),'Messages':[_['merge'](_0x408fea[_0x384a84('0x1b')],{'read':![],'body':_0x408fea[_0x384a84('0x1b')]['body'],'phone':_0xc97f78,'SmsAccountId':_0x593e18['id'],'UserId':_0x408fea[_0x384a84('0x80')]['id'],'ContactId':_0xbc2105['id']})]},{'include':[{'model':db[_0x384a84('0x18')],'as':_0x384a84('0x6b')}]})[_0x384a84('0x60')](function(_0x33972a){return[_0x33972a,!![]];});});})['then'](function([_0x23c768,_0x10b72c]){const _0x1e7ef5=_0xf65987;if(_0x10b72c)return _0x23c768;return db[_0x1e7ef5('0x18')][_0x1e7ef5('0xa6')](_['merge'](_0x408fea[_0x1e7ef5('0x1b')],{'read':![],'body':_0x408fea[_0x1e7ef5('0x1b')][_0x1e7ef5('0x1b')],'phone':_0xc97f78,'SmsAccountId':_0x593e18['id'],'SmsInteractionId':_0x23c768['id'],'UserId':_0x408fea['user']['id'],'ContactId':_0xbc2105['id']}))[_0x1e7ef5('0x60')](function(_0x5bc108){const _0x4e8a42=_0x1e7ef5;return _0x23c768[_0x4e8a42('0xaa')][_0x4e8a42('0x6b')]=[],_0x23c768[_0x4e8a42('0xaa')][_0x4e8a42('0x6b')][_0x4e8a42('0xac')](_0x5bc108[_0x4e8a42('0xaa')]),_0x23c768;});})[_0xf65987('0x60')](respondWithResult(_0x876962,null))[_0xf65987('0x44')](handleError(_0x876962,null));},exports[_0x28cdd3('0x52')]=function(_0x1574bd,_0x4d24c1){const _0x5a1948=_0x28cdd3;_0x1574bd['body']['id']&&delete _0x1574bd[_0x5a1948('0x1b')]['id'];console[_0x5a1948('0x98')](_0x5a1948('0x72'),_0x1574bd[_0x5a1948('0x1b')]);let _0x219716,_0x3b9ea8,_0x42d74f;return db[_0x5a1948('0x7c')][_0x5a1948('0x75')]({'where':{'id':_0x1574bd[_0x5a1948('0x2a')]['id']}})[_0x5a1948('0x60')](handleEntityNotFound(_0x4d24c1,null))[_0x5a1948('0x60')](function(_0x4b68ad){const _0x30da55=_0x5a1948;if(_0x4b68ad){_0x42d74f=_0x4b68ad,logger[_0x30da55('0x55')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x30da55('0x52'),_0x30da55('0xa9'),_0x4b68ad[_0x30da55('0xc')],util['inspect'](_0x1574bd['body'],{'showHidden':![],'depth':null}));switch(_0x4b68ad[_0x30da55('0xc')]){case _0x30da55('0x7b'):if(_0x1574bd[_0x30da55('0x1b')]['skebby_dispatch_id']&&_0x1574bd[_0x30da55('0x1b')][_0x30da55('0x52')])return _0x3b9ea8=_0x1574bd[_0x30da55('0x1b')]['status'],db['SmsMessage'][_0x30da55('0x75')]({'where':{'messageId':_0x1574bd['body'][_0x30da55('0x49')]}});break;case _0x30da55('0x57'):if(_0x1574bd[_0x30da55('0x1b')]['requestid']&&_0x1574bd[_0x30da55('0x1b')]['statusInt'])return _0x3b9ea8=_0x1574bd['body'][_0x30da55('0xa')],db[_0x30da55('0x18')][_0x30da55('0x75')]({'where':{'messageId':_0x1574bd[_0x30da55('0x1b')][_0x30da55('0x6e')]}});break;case _0x30da55('0x25'):if(_0x1574bd[_0x30da55('0x1b')]['message_id']&&_0x1574bd[_0x30da55('0x1b')][_0x30da55('0x68')])return _0x3b9ea8=_0x1574bd[_0x30da55('0x1b')][_0x30da55('0x68')],db[_0x30da55('0x18')][_0x30da55('0x75')]({'where':{'messageId':_0x1574bd[_0x30da55('0x1b')][_0x30da55('0xf')]}});break;case _0x30da55('0x2'):{const _0x168420=_0x1574bd[_0x30da55('0x1b')]['results'][0x0];if(_0x168420['messageId']&&_0x168420[_0x30da55('0x52')][_0x30da55('0x9a')]===_0x30da55('0xa3'))return _0x3b9ea8=_0x168420['status'][_0x30da55('0x9a')],db[_0x30da55('0x18')][_0x30da55('0x75')]({'where':{'messageId':_0x168420[_0x30da55('0x4e')]}});}break;case _0x30da55('0xbf'):if(_0x1574bd['body']['messageId']&&_0x1574bd[_0x30da55('0x1b')]['status'])return _0x3b9ea8=_0x1574bd[_0x30da55('0x1b')][_0x30da55('0x52')],db[_0x30da55('0x18')]['findOne']({'where':{'messageId':_0x1574bd[_0x30da55('0x1b')][_0x30da55('0x4e')]}});break;case _0x30da55('0x32'):if(_0x1574bd[_0x30da55('0x1b')][_0x30da55('0xc4')]&&_0x1574bd[_0x30da55('0x1b')][_0x30da55('0x52')])return _0x3b9ea8=_0x1574bd[_0x30da55('0x1b')][_0x30da55('0x52')],db[_0x30da55('0x18')]['findOne']({'where':{'messageId':_0x1574bd['body'][_0x30da55('0xc4')]}});break;}}})[_0x5a1948('0x60')](handleEntityNotFound(_0x4d24c1,null))[_0x5a1948('0x60')](function(_0x586f54){const _0x27275c=_0x5a1948;if(_0x586f54){_0x219716=_0x586f54;switch(_0x42d74f[_0x27275c('0xc')]){case _0x27275c('0x7b'):if(_0x3b9ea8==='DELIVERED')return _0x219716[_0x27275c('0x4b')]({'read':!![]});else logger[_0x27275c('0x59')](_0x27275c('0xb4'),'status','skebby',util[_0x27275c('0xd')](_0x1574bd['body'],{'showHidden':![],'depth':null}));break;case _0x27275c('0x57'):if(_0x3b9ea8==='1')return _0x219716[_0x27275c('0x4b')]({'read':!![]});else logger[_0x27275c('0x59')](_0x27275c('0xb4'),_0x27275c('0x52'),_0x27275c('0x7b'),util['inspect'](_0x1574bd[_0x27275c('0x1b')],{'showHidden':![],'depth':null}));break;case _0x27275c('0x25'):if(!_0x1574bd[_0x27275c('0x1b')][_0x27275c('0x86')]&&_0x3b9ea8>=0xc8&&_0x3b9ea8<=0xce)return _0x219716[_0x27275c('0x4b')]({'read':!![]});else logger[_0x27275c('0x59')](_0x27275c('0xb4'),_0x27275c('0x52'),_0x27275c('0x25'),util[_0x27275c('0xd')](_0x1574bd[_0x27275c('0x1b')],{'showHidden':![],'depth':null}));break;case'infobip':{const _0x9acfe1=_0x1574bd[_0x27275c('0x1b')][_0x27275c('0x90')][0x0];if(_0x9acfe1[_0x27275c('0x52')][_0x27275c('0x9a')]===_0x27275c('0xa3'))return _0x219716[_0x27275c('0x4b')]({'read':!![]});else logger[_0x27275c('0x59')](_0x27275c('0xb4'),'status',_0x27275c('0x2'),util[_0x27275c('0xd')](_0x1574bd[_0x27275c('0x1b')],{'showHidden':![],'depth':null}));}break;case _0x27275c('0xbf'):if(_0x3b9ea8=='DELIVERED_TO_GATEWAY'||_0x3b9ea8==_0x27275c('0x35'))return _0x219716['update']({'read':!![]});else logger[_0x27275c('0x59')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x27275c('0x52'),_0x27275c('0xbf'),util[_0x27275c('0xd')](_0x1574bd['body'],{'showHidden':![],'depth':null}));break;case'intelepeer':if(_0x3b9ea8===_0x27275c('0x21')||_0x3b9ea8===_0x27275c('0xb9'))return _0x219716[_0x27275c('0x4b')]({'read':!![]});else logger[_0x27275c('0x59')](_0x27275c('0xb4'),_0x27275c('0x52'),_0x27275c('0x32'),util['inspect'](_0x1574bd['body'],{'showHidden':![],'depth':null}));break;}return _0x219716;}})[_0x5a1948('0x60')](respondWithResult(_0x4d24c1,null))[_0x5a1948('0x44')](handleError(_0x4d24c1,null));},exports[_0x28cdd3('0x8d')]=function(_0x4711eb,_0xc5db8a){const _0x10594c=_0x28cdd3;let _0x3fb837,_0x214577,_0x3a284d;return db['SmsAccount'][_0x10594c('0x75')]({'where':{'id':_0x4711eb[_0x10594c('0x2a')]['id']}})[_0x10594c('0x60')](handleEntityNotFound(_0xc5db8a,null))[_0x10594c('0x60')](function(_0x37e2a3){const _0xb73288=_0x10594c;if(_0x37e2a3){_0x3a284d=_0x37e2a3,logger[_0xb73288('0x55')](_0xb73288('0xb4'),_0xb73288('0x52'),'received\x20delivery\x20report\x20from',_0x37e2a3[_0xb73288('0xc')],util['inspect'](_0x4711eb['query'],{'showHidden':![],'depth':null}));switch(_0x37e2a3[_0xb73288('0xc')]){case'csc':if(_0x4711eb[_0xb73288('0x1a')]['message-id']&&_0x4711eb['query'][_0xb73288('0xa7')])return _0x214577=_0x4711eb['query'][_0xb73288('0xa7')],db[_0xb73288('0x18')][_0xb73288('0x75')]({'where':{'messageId':_0x4711eb[_0xb73288('0x1a')][_0xb73288('0x2c')]}});break;}}})['then'](handleEntityNotFound(_0xc5db8a,null))['then'](function(_0x4f6f6e){const _0x590ceb=_0x10594c;if(_0x4f6f6e){_0x3fb837=_0x4f6f6e;switch(_0x3a284d[_0x590ceb('0xc')]){case _0x590ceb('0xa1'):if(_0x214577==='2'||_0x214577==='6')return _0x3fb837['update']({'read':!![]});else logger[_0x590ceb('0x59')](_0x590ceb('0xb4'),_0x590ceb('0x52'),'csc',util['inspect'](_0x4711eb[_0x590ceb('0x1a')],{'showHidden':![],'depth':null}));break;}return _0x3fb837;}})['then'](respondWithResult(_0xc5db8a,null))[_0x10594c('0x44')](handleError(_0xc5db8a,null));},exports[_0x28cdd3('0xb')]=function(_0x1b6591,_0x2b22a1){const _0x1ff3f5=_0x28cdd3;return db[_0x1ff3f5('0x7c')][_0x1ff3f5('0x75')]({'where':{'id':_0x1b6591[_0x1ff3f5('0x2a')]['id']}})[_0x1ff3f5('0x60')](function(_0x22fc5c){const _0x17e932=_0x1ff3f5;if(_0x22fc5c)return _0x22fc5c[_0x17e932('0xb')](_0x1b6591[_0x17e932('0x1b')][_0x17e932('0xa0')],{'through':_['omit'](_0x1b6591['body'],[_0x17e932('0xa0'),'id'])})['then'](function(_0x1110c1){const _0x23f175=_0x17e932;for(let _0x1b3bee=0x0;_0x1b3bee<_0x1b6591[_0x23f175('0x1b')][_0x23f175('0xa0')][_0x23f175('0x62')];_0x1b3bee+=0x1){socket['emit']('userSmsAccount:save',{'UserId':_0x1b6591['body'][_0x23f175('0xa0')][_0x1b3bee],'SmsAccountId':_0x1b6591[_0x23f175('0x2a')]['id']});}return _0x1110c1;});})[_0x1ff3f5('0x60')](respondWithResult(_0x2b22a1,null))[_0x1ff3f5('0x44')](handleError(_0x2b22a1,null));},exports[_0x28cdd3('0x96')]=function(_0x2d153f,_0x39c937){const _0x521f68=_0x28cdd3;return db[_0x521f68('0x7c')]['findOne']({'where':{'id':_0x2d153f[_0x521f68('0x2a')]['id']}})[_0x521f68('0x60')](handleEntityNotFound(_0x39c937,null))['then'](function(_0x4c825c){const _0x2dc5de=_0x521f68;if(_0x4c825c)return _0x4c825c['removeAgents'](_0x2d153f[_0x2dc5de('0x1a')][_0x2dc5de('0xa0')])[_0x2dc5de('0x60')](function(){const _0x5eb079=_0x2dc5de;if(_[_0x5eb079('0x1e')](_0x2d153f['query']['ids']))for(let _0x10af2=0x0;_0x10af2<_0x2d153f['query'][_0x5eb079('0xa0')]['length'];_0x10af2+=0x1){socket['emit'](_0x5eb079('0x64'),{'UserId':Number(_0x2d153f[_0x5eb079('0x1a')][_0x5eb079('0xa0')][_0x10af2]),'SmsAccountId':Number(_0x2d153f['params']['id'])});}else socket[_0x5eb079('0x5a')](_0x5eb079('0x64'),{'UserId':Number(_0x2d153f[_0x5eb079('0x1a')]['ids']),'SmsAccountId':Number(_0x2d153f[_0x5eb079('0x2a')]['id'])});});})[_0x521f68('0x60')](respondWithStatusCode(_0x39c937,null))[_0x521f68('0x44')](handleError(_0x39c937,null));},exports[_0x28cdd3('0x8b')]=function(_0x228884,_0x2dcc33){const _0x14a18c=_0x28cdd3;let _0x37fef8={};const _0x97a6e5={};let _0x40edb0,_0x705117;return db[_0x14a18c('0x7c')][_0x14a18c('0x75')]({'where':{'id':_0x228884[_0x14a18c('0x2a')]['id']}})[_0x14a18c('0x60')](handleEntityNotFound(_0x2dcc33,null))[_0x14a18c('0x60')](function(_0x315a33){const _0x21c367=_0x14a18c;if(_0x315a33)return _0x40edb0=_0x315a33,_0x97a6e5[_0x21c367('0x11')]=_[_0x21c367('0x26')](db[_0x21c367('0xe')][_0x21c367('0x4d')]),_0x97a6e5[_0x21c367('0x1a')]=_[_0x21c367('0x26')](_0x228884[_0x21c367('0x1a')]),_0x97a6e5[_0x21c367('0x30')]=_[_0x21c367('0x83')](_0x97a6e5[_0x21c367('0x11')],_0x97a6e5[_0x21c367('0x1a')]),_0x37fef8['attributes']=_['intersection'](_0x97a6e5[_0x21c367('0x11')],qs[_0x21c367('0x1d')](_0x228884['query'][_0x21c367('0x1d')])),_0x37fef8[_0x21c367('0x13')]=_0x37fef8[_0x21c367('0x13')][_0x21c367('0x62')]?_0x37fef8[_0x21c367('0x13')]:_0x97a6e5[_0x21c367('0x11')],_0x37fef8[_0x21c367('0x20')]=qs['sort'](_0x228884[_0x21c367('0x1a')][_0x21c367('0xad')]),_0x37fef8[_0x21c367('0x7f')]=qs[_0x21c367('0x30')](_['pick'](_0x228884[_0x21c367('0x1a')],_0x97a6e5[_0x21c367('0x30')])),_0x228884[_0x21c367('0x1a')][_0x21c367('0x89')]&&(_0x37fef8[_0x21c367('0x7f')]=_[_0x21c367('0x28')](_0x37fef8[_0x21c367('0x7f')],{[Op['or']]:_[_0x21c367('0x3e')](_0x37fef8[_0x21c367('0x13')],function(_0x42a6f1){const _0x49b3e1=_0x21c367,_0x23f3d1={};return _0x23f3d1[_0x42a6f1]={[Op[_0x49b3e1('0x9c')]]:'%'+_0x228884[_0x49b3e1('0x1a')][_0x49b3e1('0x89')]+'%'},_0x23f3d1;})})),_0x37fef8=_[_0x21c367('0x28')]({},_0x37fef8,_0x228884[_0x21c367('0xb1')]),_0x40edb0[_0x21c367('0x8b')](_0x37fef8);})['then'](function(_0x5656e1){const _0x53fd7e=_0x14a18c;if(_0x5656e1)return _0x705117=_0x5656e1[_0x53fd7e('0x62')],typeof _0x228884['query'][_0x53fd7e('0xb6')]==='undefined'&&(_0x37fef8['limit']=qs[_0x53fd7e('0x82')](_0x228884[_0x53fd7e('0x1a')][_0x53fd7e('0x82')]),_0x37fef8['offset']=qs[_0x53fd7e('0x10')](_0x228884[_0x53fd7e('0x1a')][_0x53fd7e('0x10')])),_0x40edb0[_0x53fd7e('0x8b')](_0x37fef8);})[_0x14a18c('0x60')](function(_0x23cdc2){if(_0x23cdc2)return _0x23cdc2?{'count':_0x705117,'rows':_0x23cdc2}:null;})[_0x14a18c('0x60')](respondWithResult(_0x2dcc33,null))[_0x14a18c('0x44')](handleError(_0x2dcc33,null));};