Built motion from commit ffdca78c.|2.6.24
[motion2.git] / server / api / smsAccount / smsAccount.controller.js
index 6934984..862d8ef 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x995f=['notify','sms','account','applications','orderBy','Applications','priority','asc','CmContact','Sequelize','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','CompanyId','ListId','mobile','twilio','From','Body','MessageSid','skebby','from','sender','text','connectel','clicksend','messageId','message_id','plivo','Text','MessageUUID','results','csc','originatingAddress','segmentedMessage','clickatell','replyMessageId','bandwidth','intelepeer','isNil','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','mapKey','DESC','list','Contacts','contact','SmsInteraction','autoclose','push','close','*,*,*,*','ContactId','AttachmentId','interaction','User','unshift','agent','waitForTheAssignedAgent','Start','startRouting','SmsAccount,\x20%s,\x20%s,\x20%s','text/xml','<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>','addApplications','sequelize','transaction','SmsApplication','bulkCreate','findAndCountAll','pick','getApplications','getInteractions','Owner','fullname','Tag','Tags','color','tag','to\x20is\x20mandatory','List','out','SmsMessage','Messages','spread','dataValues','received\x20delivery\x20report\x20from','inspect','skebby_dispatch_id','requestid','statusInt','status_code','infobip','groupName','DELIVERED','redif','error_code','RECEIVED_BY_RECIPIENT','ACCEPTD','statusGet','message-id','addAgents','omit','emit','userSmsAccount:save','removeAgents','isArray','userSmsAccount:remove','getAgents','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','ejs','lodash','crypto','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','./smsAccount.socket','register','jayson/promise','client','http','request','info','request\x20sent','debug','stringify','error','code','message','SmsAccount,\x20%s,\x20%s','result','catch','sendStatus','end','status','json','count','offset','limit','set','Content-Range','reject','update','then','destroy','get','SmsAccounts','UserProfileResource','stack','name','send','index','Pause','mandatoryDispositionPause','map','rawAttributes','type','key','model','query','keys','filters','attributes','intersection','fields','hasOwnProperty','nolimit','sort','where','filter','merge','VIRTUAL','options','SmsAccount','includeAll','include','show','params','length','find','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','UserProfileSection','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','addDisposition','SmsAccountId','Disposition','getDispositions','findAll','rows','removeDispositions','ids','addAnswer','getAnswers','findOne','order','CannedAnswer','removeAnswers'];(function(_0x336376,_0xe4b28d){var _0x1d2a8e=function(_0x3afe68){while(--_0x3afe68){_0x336376['push'](_0x336376['shift']());}};_0x1d2a8e(++_0xe4b28d);}(_0x995f,0x14f));var _0xf995=function(_0x3c04d7,_0x472801){_0x3c04d7=_0x3c04d7-0x0;var _0x2fb24=_0x995f[_0x3c04d7];return _0x2fb24;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xf995('0x0'));var rimraf=require(_0xf995('0x1'));var zipdir=require(_0xf995('0x2'));var jsonpatch=require(_0xf995('0x3'));var rp=require(_0xf995('0x4'));var moment=require(_0xf995('0x5'));var BPromise=require(_0xf995('0x6'));var Mustache=require(_0xf995('0x7'));var util=require('util');var path=require(_0xf995('0x8'));var sox=require(_0xf995('0x9'));var csv=require('to-csv');var ejs=require(_0xf995('0xa'));var fs=require('fs');var _=require(_0xf995('0xb'));var squel=require('squel');var crypto=require(_0xf995('0xc'));var jsforce=require('jsforce');var deskjs=require(_0xf995('0xd'));var toCsv=require('to-csv');var querystring=require(_0xf995('0xe'));var Papa=require(_0xf995('0xf'));var Redis=require(_0xf995('0x10'));var authService=require('../../components/auth/service');var qs=require(_0xf995('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf995('0x12'));var logger=require(_0xf995('0x13'))(_0xf995('0x14'));var utils=require(_0xf995('0x15'));var config=require(_0xf995('0x16'));var licenseUtil=require(_0xf995('0x17'));var db=require(_0xf995('0x18'))['db'];config[_0xf995('0x19')]=_[_0xf995('0x1a')](config[_0xf995('0x19')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xf995('0x19')]));require(_0xf995('0x1b'))[_0xf995('0x1c')](socket);var jayson=require(_0xf995('0x1d'));var client=jayson[_0xf995('0x1e')][_0xf995('0x1f')]({'port':0x232c});function respondWithRpcPromise(_0x463c5b,_0x5b2b15,_0x5149b0,_0x273fb6){return new BPromise(function(_0x5c1581,_0x3c315f){var _0x2a0b8f=_0x273fb6||client;return _0x2a0b8f[_0xf995('0x20')](_0x463c5b,_0x5149b0)['then'](function(_0xdd0629){logger[_0xf995('0x21')]('SmsAccount,\x20%s,\x20%s',_0x5b2b15,_0xf995('0x22'));logger[_0xf995('0x23')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x5b2b15,_0xf995('0x22'),JSON[_0xf995('0x24')](_0xdd0629));if(_0xdd0629['error']){if(_0xdd0629[_0xf995('0x25')][_0xf995('0x26')]===0x1f4){logger['error']('SmsAccount,\x20%s,\x20%s',_0x5b2b15,_0xdd0629[_0xf995('0x25')][_0xf995('0x27')]);return _0x3c315f(_0xdd0629[_0xf995('0x25')][_0xf995('0x27')]);}logger[_0xf995('0x25')](_0xf995('0x28'),_0x5b2b15,_0xdd0629[_0xf995('0x25')]['message']);return _0x5c1581(_0xdd0629[_0xf995('0x25')][_0xf995('0x27')]);}else{logger[_0xf995('0x21')](_0xf995('0x28'),_0x5b2b15,_0xf995('0x22'));_0x5c1581(_0xdd0629[_0xf995('0x29')][_0xf995('0x27')]);}})[_0xf995('0x2a')](function(_0x535eb6){logger['error']('SmsAccount,\x20%s,\x20%s',_0x5b2b15,_0x535eb6);_0x3c315f(_0x535eb6);});});}function respondWithStatusCode(_0x4c5a6d,_0x5a4caa){_0x5a4caa=_0x5a4caa||0xcc;return function(_0x1dbc78){if(_0x1dbc78){return _0x4c5a6d[_0xf995('0x2b')](_0x5a4caa);}return _0x4c5a6d['status'](_0x5a4caa)[_0xf995('0x2c')]();};}function respondWithResult(_0x70a7be,_0x49cd79){_0x49cd79=_0x49cd79||0xc8;return function(_0x59b64b){if(_0x59b64b){return _0x70a7be[_0xf995('0x2d')](_0x49cd79)[_0xf995('0x2e')](_0x59b64b);}};}function respondWithFilteredResult(_0x20a385,_0x813b57){return function(_0xa36448){if(_0xa36448){var _0x330b31=_0xa36448[_0xf995('0x2f')],_0x10fd9d=_0x813b57[_0xf995('0x30')],_0x317fd4=_0x813b57['offset']+_0x813b57[_0xf995('0x31')],_0xe060b5;if(_0x317fd4>=_0x330b31){_0x317fd4=_0x330b31;_0xe060b5=0xc8;}else{_0xe060b5=0xce;}_0x20a385[_0xf995('0x2d')](_0xe060b5);return _0x20a385[_0xf995('0x32')](_0xf995('0x33'),_0x10fd9d+'-'+_0x317fd4+'/'+_0x330b31)[_0xf995('0x2e')](_0xa36448);}return null;};}function patchUpdates(_0x9171a1){return function(_0x1a3087){try{jsonpatch['apply'](_0x1a3087,_0x9171a1,!![]);}catch(_0x5046aa){return BPromise[_0xf995('0x34')](_0x5046aa);}return _0x1a3087['save']();};}function saveUpdates(_0x2c75d2,_0x41a9d8){return function(_0x4e14ff){if(_0x4e14ff){return _0x4e14ff[_0xf995('0x35')](_0x2c75d2)[_0xf995('0x36')](function(_0x1f2468){return _0x1f2468;});}return null;};}function removeEntity(_0x59e142,_0x10ed8a){return function(_0x22ed1c){if(_0x22ed1c){return _0x22ed1c[_0xf995('0x37')]()['then'](function(){var _0x591377=_0x22ed1c[_0xf995('0x38')]({'plain':!![]});var _0x21387f=_0xf995('0x39');return db[_0xf995('0x3a')]['destroy']({'where':{'type':_0x21387f,'resourceId':_0x591377['id']}})['then'](function(){return _0x22ed1c;});})[_0xf995('0x36')](function(){_0x59e142[_0xf995('0x2d')](0xcc)[_0xf995('0x2c')]();});}};}function handleEntityNotFound(_0x18d155,_0x3b4feb){return function(_0x870258){if(!_0x870258){_0x18d155['sendStatus'](0x194);}return _0x870258;};}function handleError(_0x5a2a7c,_0x1f1af2){_0x1f1af2=_0x1f1af2||0x1f4;return function(_0x5dcb46){logger[_0xf995('0x25')](_0x5dcb46[_0xf995('0x3b')]);if(_0x5dcb46[_0xf995('0x3c')]){delete _0x5dcb46[_0xf995('0x3c')];}_0x5a2a7c[_0xf995('0x2d')](_0x1f1af2)[_0xf995('0x3d')](_0x5dcb46);};}exports[_0xf995('0x3e')]=function(_0x104811,_0x473c1f){var _0x3b5330={'include':[{'model':db[_0xf995('0x3f')],'as':_0xf995('0x40')}]},_0x8cba0a={},_0x4e5c99={'count':0x0,'rows':[]};var _0x2a7aed=_[_0xf995('0x41')](db['SmsAccount'][_0xf995('0x42')],function(_0x377cd2){return{'name':_0x377cd2['fieldName'],'type':_0x377cd2[_0xf995('0x43')][_0xf995('0x44')]};});_0x8cba0a[_0xf995('0x45')]=_[_0xf995('0x41')](_0x2a7aed,_0xf995('0x3c'));_0x8cba0a[_0xf995('0x46')]=_[_0xf995('0x47')](_0x104811[_0xf995('0x46')]);_0x8cba0a[_0xf995('0x48')]=_['intersection'](_0x8cba0a[_0xf995('0x45')],_0x8cba0a[_0xf995('0x46')]);_0x3b5330[_0xf995('0x49')]=_[_0xf995('0x4a')](_0x8cba0a[_0xf995('0x45')],qs[_0xf995('0x4b')](_0x104811[_0xf995('0x46')][_0xf995('0x4b')]));_0x3b5330[_0xf995('0x49')]=_0x3b5330[_0xf995('0x49')]['length']?_0x3b5330[_0xf995('0x49')]:_0x8cba0a[_0xf995('0x45')];if(!_0x104811[_0xf995('0x46')][_0xf995('0x4c')](_0xf995('0x4d'))){_0x3b5330[_0xf995('0x31')]=qs[_0xf995('0x31')](_0x104811['query'][_0xf995('0x31')]);_0x3b5330[_0xf995('0x30')]=qs[_0xf995('0x30')](_0x104811[_0xf995('0x46')]['offset']);}_0x3b5330['order']=qs['sort'](_0x104811[_0xf995('0x46')][_0xf995('0x4e')]);_0x3b5330[_0xf995('0x4f')]=qs[_0xf995('0x48')](_['pick'](_0x104811['query'],_0x8cba0a['filters']),_0x2a7aed);if(_0x104811['query'][_0xf995('0x50')]){_0x3b5330[_0xf995('0x4f')]=_[_0xf995('0x51')](_0x3b5330[_0xf995('0x4f')],{'$or':_[_0xf995('0x41')](_0x2a7aed,function(_0x559074){if(_0x559074[_0xf995('0x43')]!==_0xf995('0x52')){var _0x1c2fdc={};_0x1c2fdc[_0x559074[_0xf995('0x3c')]]={'$like':'%'+_0x104811[_0xf995('0x46')][_0xf995('0x50')]+'%'};return _0x1c2fdc;}})});}_0x3b5330=_[_0xf995('0x51')]({},_0x3b5330,_0x104811[_0xf995('0x53')]);var _0x1a21b3={'where':_0x3b5330[_0xf995('0x4f')]};return db[_0xf995('0x54')]['count'](_0x1a21b3)[_0xf995('0x36')](function(_0x1146fd){_0x4e5c99[_0xf995('0x2f')]=_0x1146fd;if(_0x104811['query'][_0xf995('0x55')]){_0x3b5330[_0xf995('0x56')]=[{'all':!![]}];}return db[_0xf995('0x54')]['findAll'](_0x3b5330);})[_0xf995('0x36')](function(_0x2f420a){_0x4e5c99['rows']=_0x2f420a;return _0x4e5c99;})[_0xf995('0x36')](respondWithFilteredResult(_0x473c1f,_0x3b5330))[_0xf995('0x2a')](handleError(_0x473c1f,null));};exports[_0xf995('0x57')]=function(_0x2d5de0,_0x827ec4){var _0x1908ba={'raw':![],'where':{'id':_0x2d5de0[_0xf995('0x58')]['id']},'include':[{'model':db[_0xf995('0x3f')],'as':_0xf995('0x40')}]},_0x4beefe={};_0x4beefe['model']=_[_0xf995('0x47')](db[_0xf995('0x54')][_0xf995('0x42')]);_0x4beefe[_0xf995('0x46')]=_[_0xf995('0x47')](_0x2d5de0[_0xf995('0x46')]);_0x4beefe[_0xf995('0x48')]=_[_0xf995('0x4a')](_0x4beefe[_0xf995('0x45')],_0x4beefe[_0xf995('0x46')]);_0x1908ba[_0xf995('0x49')]=_[_0xf995('0x4a')](_0x4beefe[_0xf995('0x45')],qs['fields'](_0x2d5de0['query']['fields']));_0x1908ba['attributes']=_0x1908ba[_0xf995('0x49')][_0xf995('0x59')]?_0x1908ba['attributes']:_0x4beefe[_0xf995('0x45')];if(_0x2d5de0[_0xf995('0x46')][_0xf995('0x55')]){_0x1908ba[_0xf995('0x56')]=[{'all':!![]}];}_0x1908ba=_['merge']({},_0x1908ba,_0x2d5de0[_0xf995('0x53')]);return db[_0xf995('0x54')][_0xf995('0x5a')](_0x1908ba)[_0xf995('0x36')](handleEntityNotFound(_0x827ec4,null))[_0xf995('0x36')](respondWithResult(_0x827ec4,null))[_0xf995('0x2a')](handleError(_0x827ec4,null));};exports[_0xf995('0x5b')]=function(_0xf19ce,_0x310091){return db[_0xf995('0x54')][_0xf995('0x5b')](_0xf19ce[_0xf995('0x5c')],{})['then'](function(_0x4ebbab){var _0x3cb5a6=_0xf19ce['user'][_0xf995('0x38')]({'plain':!![]});if(!_0x3cb5a6)throw new Error(_0xf995('0x5d'));if(_0x3cb5a6[_0xf995('0x5e')]===_0xf995('0x5f')){var _0x4ce5ba=_0x4ebbab[_0xf995('0x38')]({'plain':!![]});var _0x371d21=_0xf995('0x39');return db[_0xf995('0x60')][_0xf995('0x5a')]({'where':{'name':_0x371d21,'userProfileId':_0x3cb5a6['userProfileId']},'raw':!![]})['then'](function(_0x3e0efe){if(_0x3e0efe&&_0x3e0efe['autoAssociation']===0x0){return db['UserProfileResource']['create']({'name':_0x4ce5ba['name'],'resourceId':_0x4ce5ba['id'],'type':_0x3e0efe[_0xf995('0x3c')],'sectionId':_0x3e0efe['id']},{})[_0xf995('0x36')](function(){return _0x4ebbab;});}else{return _0x4ebbab;}})['catch'](function(_0x35c01b){logger[_0xf995('0x25')](_0xf995('0x61'),_0x35c01b);throw _0x35c01b;});}return _0x4ebbab;})[_0xf995('0x36')](respondWithResult(_0x310091,0xc9))[_0xf995('0x2a')](handleError(_0x310091,null));};exports[_0xf995('0x35')]=function(_0x31e9c0,_0x2a7a40){if(_0x31e9c0[_0xf995('0x5c')]['id']){delete _0x31e9c0[_0xf995('0x5c')]['id'];}return db[_0xf995('0x54')][_0xf995('0x5a')]({'where':{'id':_0x31e9c0[_0xf995('0x58')]['id']},'include':[{'model':db[_0xf995('0x3f')],'as':'mandatoryDispositionPause'}]})['then'](handleEntityNotFound(_0x2a7a40,null))[_0xf995('0x36')](saveUpdates(_0x31e9c0[_0xf995('0x5c')],null))[_0xf995('0x36')](respondWithResult(_0x2a7a40,null))[_0xf995('0x2a')](handleError(_0x2a7a40,null));};exports[_0xf995('0x37')]=function(_0x16c8ab,_0x268f2f){return db[_0xf995('0x54')]['find']({'where':{'id':_0x16c8ab[_0xf995('0x58')]['id']}})[_0xf995('0x36')](handleEntityNotFound(_0x268f2f,null))[_0xf995('0x36')](removeEntity(_0x268f2f,null))[_0xf995('0x2a')](handleError(_0x268f2f,null));};exports[_0xf995('0x62')]=function(_0x19e527,_0x2a0773){return db[_0xf995('0x54')][_0xf995('0x62')]()[_0xf995('0x36')](respondWithResult(_0x2a0773,null))[_0xf995('0x2a')](handleError(_0x2a0773,null));};exports[_0xf995('0x63')]=function(_0x266a2a,_0x2759eb,_0x353099){if(_0x266a2a['body']['id']){delete _0x266a2a[_0xf995('0x5c')]['id'];}return db[_0xf995('0x54')]['find']({'where':{'id':_0x266a2a[_0xf995('0x58')]['id']}})[_0xf995('0x36')](handleEntityNotFound(_0x2759eb,null))['then'](function(_0x30e97d){if(_0x30e97d){_0x266a2a[_0xf995('0x5c')][_0xf995('0x64')]=_0x30e97d['id'];return db[_0xf995('0x65')][_0xf995('0x5b')](_0x266a2a[_0xf995('0x5c')]);}})[_0xf995('0x36')](respondWithResult(_0x2759eb,null))[_0xf995('0x2a')](handleError(_0x2759eb,null));};exports[_0xf995('0x66')]=function(_0x51f6f7,_0x1017eb,_0x4b76e7){var _0x794717={'raw':![],'where':{}};var _0x554543={};var _0x573844={'count':0x0,'rows':[]};return db[_0xf995('0x54')]['findOne']({'where':{'id':_0x51f6f7[_0xf995('0x58')]['id']}})['then'](handleEntityNotFound(_0x1017eb,null))[_0xf995('0x36')](function(_0x13aa27){if(_0x13aa27){_0x554543[_0xf995('0x45')]=_[_0xf995('0x47')](db['Disposition']['rawAttributes']);_0x554543[_0xf995('0x46')]=_[_0xf995('0x47')](_0x51f6f7['query']);_0x554543[_0xf995('0x48')]=_[_0xf995('0x4a')](_0x554543[_0xf995('0x45')],_0x554543[_0xf995('0x46')]);_0x794717[_0xf995('0x49')]=_[_0xf995('0x4a')](_0x554543[_0xf995('0x45')],qs['fields'](_0x51f6f7[_0xf995('0x46')][_0xf995('0x4b')]));_0x794717[_0xf995('0x49')]=_0x794717[_0xf995('0x49')][_0xf995('0x59')]?_0x794717[_0xf995('0x49')]:_0x554543[_0xf995('0x45')];if(!_0x51f6f7[_0xf995('0x46')][_0xf995('0x4c')](_0xf995('0x4d'))){_0x794717[_0xf995('0x31')]=qs['limit'](_0x51f6f7[_0xf995('0x46')][_0xf995('0x31')]);_0x794717[_0xf995('0x30')]=qs[_0xf995('0x30')](_0x51f6f7['query'][_0xf995('0x30')]);}_0x794717['order']=qs[_0xf995('0x4e')](_0x51f6f7[_0xf995('0x46')][_0xf995('0x4e')]);_0x794717[_0xf995('0x4f')]=qs[_0xf995('0x48')](_['pick'](_0x51f6f7[_0xf995('0x46')],_0x554543[_0xf995('0x48')]));_0x794717[_0xf995('0x4f')][_0xf995('0x64')]=_0x13aa27['id'];if(_0x51f6f7[_0xf995('0x46')][_0xf995('0x50')]){_0x794717['where']=_[_0xf995('0x51')](_0x794717[_0xf995('0x4f')],{'$or':_['map'](_0x794717['attributes'],function(_0x1d78a7){var _0x4e5bdd={};_0x4e5bdd[_0x1d78a7]={'$like':'%'+_0x51f6f7[_0xf995('0x46')][_0xf995('0x50')]+'%'};return _0x4e5bdd;})});}_0x794717=_[_0xf995('0x51')]({},_0x794717,_0x51f6f7[_0xf995('0x53')]);return db[_0xf995('0x65')][_0xf995('0x2f')]({'where':_0x794717[_0xf995('0x4f')]})[_0xf995('0x36')](function(_0x3b1d8b){_0x573844[_0xf995('0x2f')]=_0x3b1d8b;if(_0x51f6f7[_0xf995('0x46')][_0xf995('0x55')]){_0x794717[_0xf995('0x56')]=[{'all':!![]}];}return db['Disposition'][_0xf995('0x67')](_0x794717);})[_0xf995('0x36')](function(_0x20b64b){_0x573844[_0xf995('0x68')]=_0x20b64b;return _0x573844;});}})[_0xf995('0x36')](respondWithFilteredResult(_0x1017eb,_0x794717))['catch'](handleError(_0x1017eb,null));};exports[_0xf995('0x69')]=function(_0x400589,_0x1be928,_0x53ad5c){return db[_0xf995('0x54')][_0xf995('0x5a')]({'where':{'id':_0x400589[_0xf995('0x58')]['id']}})[_0xf995('0x36')](handleEntityNotFound(_0x1be928,null))[_0xf995('0x36')](function(_0x1f26f6){if(_0x1f26f6){return _0x1f26f6[_0xf995('0x69')](_0x400589[_0xf995('0x46')][_0xf995('0x6a')]);}})[_0xf995('0x36')](respondWithStatusCode(_0x1be928,null))['catch'](handleError(_0x1be928,null));};exports[_0xf995('0x6b')]=function(_0x316b1c,_0x54770c,_0x4a050d){if(_0x316b1c['body']['id']){delete _0x316b1c['body']['id'];}return db[_0xf995('0x54')][_0xf995('0x5a')]({'where':{'id':_0x316b1c['params']['id']}})[_0xf995('0x36')](handleEntityNotFound(_0x54770c,null))[_0xf995('0x36')](function(_0x3f732d){if(_0x3f732d){_0x316b1c[_0xf995('0x5c')]['SmsAccountId']=_0x3f732d['id'];return db['CannedAnswer'][_0xf995('0x5b')](_0x316b1c[_0xf995('0x5c')]);}})[_0xf995('0x36')](respondWithResult(_0x54770c,null))[_0xf995('0x2a')](handleError(_0x54770c,null));};exports[_0xf995('0x6c')]=function(_0x4835de,_0x4f6ba4,_0x42250c){var _0x1eff81={'raw':![],'where':{}};var _0x4c1eb9={};var _0x16dedb={'count':0x0,'rows':[]};return db['SmsAccount'][_0xf995('0x6d')]({'where':{'id':_0x4835de[_0xf995('0x58')]['id']}})[_0xf995('0x36')](handleEntityNotFound(_0x4f6ba4,null))[_0xf995('0x36')](function(_0xfbce06){if(_0xfbce06){_0x4c1eb9[_0xf995('0x45')]=_[_0xf995('0x47')](db['CannedAnswer']['rawAttributes']);_0x4c1eb9[_0xf995('0x46')]=_[_0xf995('0x47')](_0x4835de['query']);_0x4c1eb9[_0xf995('0x48')]=_['intersection'](_0x4c1eb9[_0xf995('0x45')],_0x4c1eb9[_0xf995('0x46')]);_0x1eff81[_0xf995('0x49')]=_['intersection'](_0x4c1eb9[_0xf995('0x45')],qs[_0xf995('0x4b')](_0x4835de[_0xf995('0x46')]['fields']));_0x1eff81[_0xf995('0x49')]=_0x1eff81['attributes'][_0xf995('0x59')]?_0x1eff81[_0xf995('0x49')]:_0x4c1eb9[_0xf995('0x45')];if(!_0x4835de[_0xf995('0x46')][_0xf995('0x4c')](_0xf995('0x4d'))){_0x1eff81['limit']=qs[_0xf995('0x31')](_0x4835de[_0xf995('0x46')][_0xf995('0x31')]);_0x1eff81[_0xf995('0x30')]=qs['offset'](_0x4835de[_0xf995('0x46')][_0xf995('0x30')]);}_0x1eff81[_0xf995('0x6e')]=qs[_0xf995('0x4e')](_0x4835de[_0xf995('0x46')][_0xf995('0x4e')]);_0x1eff81[_0xf995('0x4f')]=qs[_0xf995('0x48')](_['pick'](_0x4835de[_0xf995('0x46')],_0x4c1eb9['filters']));_0x1eff81['where'][_0xf995('0x64')]=_0xfbce06['id'];if(_0x4835de[_0xf995('0x46')]['filter']){_0x1eff81['where']=_[_0xf995('0x51')](_0x1eff81[_0xf995('0x4f')],{'$or':_[_0xf995('0x41')](_0x1eff81[_0xf995('0x49')],function(_0x2a3c3d){var _0x4552cd={};_0x4552cd[_0x2a3c3d]={'$like':'%'+_0x4835de[_0xf995('0x46')]['filter']+'%'};return _0x4552cd;})});}_0x1eff81=_[_0xf995('0x51')]({},_0x1eff81,_0x4835de[_0xf995('0x53')]);return db['CannedAnswer'][_0xf995('0x2f')]({'where':_0x1eff81[_0xf995('0x4f')]})[_0xf995('0x36')](function(_0xf5de8c){_0x16dedb['count']=_0xf5de8c;if(_0x4835de[_0xf995('0x46')]['includeAll']){_0x1eff81[_0xf995('0x56')]=[{'all':!![]}];}return db[_0xf995('0x6f')][_0xf995('0x67')](_0x1eff81);})[_0xf995('0x36')](function(_0x38d421){_0x16dedb['rows']=_0x38d421;return _0x16dedb;});}})[_0xf995('0x36')](respondWithFilteredResult(_0x4f6ba4,_0x1eff81))['catch'](handleError(_0x4f6ba4,null));};exports[_0xf995('0x70')]=function(_0x271f51,_0x4973d2,_0x5a67ee){return db[_0xf995('0x54')][_0xf995('0x5a')]({'where':{'id':_0x271f51[_0xf995('0x58')]['id']}})[_0xf995('0x36')](handleEntityNotFound(_0x4973d2,null))['then'](function(_0x19f0b8){if(_0x19f0b8){return _0x19f0b8[_0xf995('0x70')](_0x271f51[_0xf995('0x46')][_0xf995('0x6a')]);}})[_0xf995('0x36')](respondWithStatusCode(_0x4973d2,null))['catch'](handleError(_0x4973d2,null));};exports[_0xf995('0x71')]=function(_0x5eb722,_0x4be7c2,_0x218831){var _0x27dacc={'channel':_0xf995('0x72')};var _0x5cfb18=[];var _0x193bea=[];var _0x4b98c2={};return db[_0xf995('0x54')]['find']({'where':{'id':_0x5eb722[_0xf995('0x58')]['id']},'include':[{'model':db['SmsApplication'],'as':'Applications'}]})['then'](handleEntityNotFound(_0x4be7c2,null))[_0xf995('0x36')](function(_0x35770e){_0x27dacc[_0xf995('0x73')]=_0x35770e;_0x27dacc[_0xf995('0x74')]=_[_0xf995('0x75')](_0x35770e[_0xf995('0x76')],[_0xf995('0x77')],[_0xf995('0x78')]);if(_0x27dacc[_0xf995('0x73')][_0xf995('0x76')]){delete _0x27dacc['account'][_0xf995('0x76')];}return db[_0xf995('0x79')]['describe']();})[_0xf995('0x36')](function(_0x48944b){if(!_0x48944b){throw new db[(_0xf995('0x7a'))][(_0xf995('0x7b'))](_0xf995('0x7c'));}_0x5cfb18=_[_0xf995('0x7d')](_[_0xf995('0x47')](_0x48944b),[_0xf995('0x7e'),_0xf995('0x7f')]);_0x193bea=_[_0xf995('0x7d')](_[_0xf995('0x47')](_0x48944b),['createdAt',_0xf995('0x7f'),_0xf995('0x80'),_0xf995('0x81')]);_0x27dacc['body']={'mapKey':_0xf995('0x82')};if(_0x27dacc[_0xf995('0x73')][_0xf995('0x43')]){switch(_0x27dacc[_0xf995('0x73')][_0xf995('0x43')]){case _0xf995('0x83'):_0x27dacc[_0xf995('0x5c')]['from']=_0x5eb722[_0xf995('0x5c')][_0xf995('0x84')];_0x27dacc[_0xf995('0x5c')][_0xf995('0x5c')]=_0x5eb722[_0xf995('0x5c')][_0xf995('0x85')];_0x27dacc[_0xf995('0x5c')]['messageId']=_0x5eb722[_0xf995('0x5c')][_0xf995('0x86')];break;case _0xf995('0x87'):_0x27dacc[_0xf995('0x5c')][_0xf995('0x88')]='+'+_0x5eb722[_0xf995('0x5c')][_0xf995('0x89')];_0x27dacc[_0xf995('0x5c')][_0xf995('0x5c')]=_0x5eb722['body'][_0xf995('0x8a')];break;case _0xf995('0x8b'):_0x27dacc[_0xf995('0x5c')][_0xf995('0x88')]=_0x5eb722['body'][_0xf995('0x88')];_0x27dacc['body'][_0xf995('0x5c')]=_0x5eb722['body'][_0xf995('0x27')];break;case _0xf995('0x8c'):_0x27dacc[_0xf995('0x5c')][_0xf995('0x88')]=_0x5eb722[_0xf995('0x5c')][_0xf995('0x88')];_0x27dacc['body'][_0xf995('0x5c')]=_0x5eb722[_0xf995('0x5c')][_0xf995('0x5c')];_0x27dacc['body'][_0xf995('0x8d')]=_0x5eb722[_0xf995('0x5c')][_0xf995('0x8e')];break;case _0xf995('0x8f'):_0x27dacc['body'][_0xf995('0x88')]=_0x5eb722[_0xf995('0x5c')][_0xf995('0x84')];_0x27dacc['body'][_0xf995('0x5c')]=_0x5eb722[_0xf995('0x5c')][_0xf995('0x90')];_0x27dacc[_0xf995('0x5c')][_0xf995('0x8d')]=_0x5eb722['body'][_0xf995('0x91')];break;case'infobip':_0x27dacc[_0xf995('0x5c')][_0xf995('0x88')]='+'+_0x5eb722['body'][_0xf995('0x92')][0x0][_0xf995('0x88')];_0x27dacc[_0xf995('0x5c')][_0xf995('0x5c')]=_0x5eb722[_0xf995('0x5c')][_0xf995('0x92')][0x0][_0xf995('0x8a')];_0x27dacc[_0xf995('0x5c')][_0xf995('0x8d')]=_0x5eb722[_0xf995('0x5c')][_0xf995('0x92')][0x0][_0xf995('0x8d')];break;case _0xf995('0x93'):_0x27dacc[_0xf995('0x5c')][_0xf995('0x88')]=_0x5eb722[_0xf995('0x5c')][_0xf995('0x94')];_0x27dacc[_0xf995('0x5c')][_0xf995('0x5c')]=_0x5eb722[_0xf995('0x5c')][_0xf995('0x95')]['message'];break;case _0xf995('0x96'):_0x27dacc['body'][_0xf995('0x88')]=_0x5eb722['body']['fromNumber'];_0x27dacc[_0xf995('0x5c')]['body']=_0x5eb722[_0xf995('0x5c')][_0xf995('0x8a')];_0x27dacc[_0xf995('0x5c')][_0xf995('0x8d')]=_0x5eb722[_0xf995('0x5c')][_0xf995('0x97')];break;case _0xf995('0x98'):_0x27dacc[_0xf995('0x5c')][_0xf995('0x8d')]=_0x5eb722[_0xf995('0x5c')][0x0][_0xf995('0x27')]['id'];_0x27dacc['body'][_0xf995('0x88')]=_0x5eb722[_0xf995('0x5c')][0x0][_0xf995('0x27')][_0xf995('0x88')];_0x27dacc[_0xf995('0x5c')][_0xf995('0x5c')]=_0x5eb722['body'][0x0]['message'][_0xf995('0x8a')];break;case _0xf995('0x99'):_0x27dacc[_0xf995('0x5c')][_0xf995('0x88')]=_0x5eb722['body']['from'];_0x27dacc[_0xf995('0x5c')]['body']=_0x5eb722[_0xf995('0x5c')][_0xf995('0x27')];_0x27dacc[_0xf995('0x5c')][_0xf995('0x8d')]=_0x5eb722[_0xf995('0x5c')]['refid'];break;}}if(_0x27dacc[_0xf995('0x5c')]['id']){delete _0x27dacc[_0xf995('0x5c')]['id'];}if(_[_0xf995('0x9a')](_0x27dacc['body'][_0xf995('0x88')])){throw new db[(_0xf995('0x7a'))][(_0xf995('0x7b'))]('from\x20is\x20mandatory');}if(_['isNil'](_0x27dacc[_0xf995('0x5c')][_0xf995('0x5c')])||_0x27dacc[_0xf995('0x5c')]['body']===''){throw new db[(_0xf995('0x7a'))][(_0xf995('0x7b'))](_0xf995('0x9b'));}if(_[_0xf995('0x9a')](_0x27dacc[_0xf995('0x5c')]['mapKey'])){throw new db[(_0xf995('0x7a'))][(_0xf995('0x7b'))](_0xf995('0x9c')+_0x193bea);}if(!_['includes'](_0x193bea,_0x27dacc[_0xf995('0x5c')][_0xf995('0x9d')])){throw new db[(_0xf995('0x7a'))][(_0xf995('0x7b'))]('mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x193bea);}_0x4b98c2[_0x27dacc[_0xf995('0x5c')][_0xf995('0x9d')]]=_0x27dacc[_0xf995('0x5c')][_0xf995('0x88')];return db['CmList']['find']({'where':{'id':_0x27dacc['account'][_0xf995('0x81')]},'include':[{'model':db['CmContact'],'as':'Contacts','where':_0x4b98c2,'limit':0x1,'order':[['updatedAt',_0xf995('0x9e')]]}]});})[_0xf995('0x36')](handleEntityNotFound(_0x4be7c2,null))[_0xf995('0x36')](function(_0x4c8371){if(_0x4c8371){_0x27dacc[_0xf995('0x9f')]=_['omit'](_0x4c8371,[_0xf995('0xa0')]);if(_0x4c8371[_0xf995('0xa0')][_0xf995('0x59')]){return _0x4c8371[_0xf995('0xa0')][0x0];}var _0x46a855=_[_0xf995('0x1a')](_0x27dacc[_0xf995('0x5c')],{'firstName':_0x27dacc[_0xf995('0x5c')][_0xf995('0x88')],'ListId':_0x4c8371['id']});_0x46a855[_0x27dacc['body'][_0xf995('0x9d')]]=_0x27dacc[_0xf995('0x5c')][_0xf995('0x88')];return db[_0xf995('0x79')][_0xf995('0x5b')](_0x46a855,{'fields':_0x5cfb18,'raw':!![]});}})['then'](handleEntityNotFound(_0x4be7c2,null))['then'](function(_0x12ec82){if(_0x12ec82){_0x27dacc[_0xf995('0xa1')]=_0x12ec82;var _0x55d99e={'ContactId':_0x12ec82['id'],'phone':_0x27dacc['body'][_0xf995('0x88')],'SmsAccountId':_0x5eb722[_0xf995('0x58')]['id']};var _0x128ab2={'ContactId':_0x12ec82['id'],'SmsAccountId':_0x5eb722[_0xf995('0x58')]['id'],'closed':![]};return db[_0xf995('0xa2')]['find']({'where':_0x128ab2})[_0xf995('0x36')](function(_0x32ac96){if(_0x32ac96){return[_0x32ac96,![]];}return db[_0xf995('0xa2')][_0xf995('0x5b')](_0x55d99e)['then'](function(_0xa2aeec){return[_0xa2aeec,!![]];});});}})['spread'](function(_0x35417b,_0x1caafb){_0x27dacc['interaction']=_0x35417b[_0xf995('0x38')]({'plain':!![]});_0x27dacc['interaction']['created']=![];if(_0x1caafb){if(_0x27dacc[_0xf995('0x73')][_0xf995('0xa3')]){_0x27dacc[_0xf995('0x74')][_0xf995('0xa4')]({'id':0x0,'priority':_0x27dacc['applications']['length']+0x1,'app':_0xf995('0xa5'),'appdata':'unmanaged','interval':_0xf995('0xa6')});}_0x27dacc['interaction']['created']=!![];}return db['SmsMessage'][_0xf995('0x5b')]({'phone':_0x27dacc[_0xf995('0x5c')][_0xf995('0x88')],'messageId':_0x27dacc['body'][_0xf995('0x8d')],'body':_0x27dacc[_0xf995('0x5c')][_0xf995('0x5c')],'SmsAccountId':_0x5eb722['params']['id'],'SmsInteractionId':_0x35417b['id'],'direction':'in','ContactId':_0x35417b[_0xf995('0xa7')],'AttachmentId':_0x27dacc[_0xf995('0x5c')][_0xf995('0xa8')]});})[_0xf995('0x36')](function(_0x4d1e84){_0x27dacc[_0xf995('0x27')]=_0x4d1e84;if(_0x27dacc[_0xf995('0xa9')]['UserId']){return db[_0xf995('0xaa')][_0xf995('0x5a')]({'attributes':['id',_0xf995('0x3c')],'where':{'id':_0x27dacc['interaction']['UserId']}})['then'](function(_0xbad117){if(_0xbad117){_0x27dacc[_0xf995('0x74')][_0xf995('0xab')]({'id':0x0,'priority':0x0,'app':_0xf995('0xac'),'appdata':_0xbad117[_0xf995('0x3c')]+','+(_0x27dacc['account'][_0xf995('0xad')]||0xa),'interval':_0xf995('0xa6')});}return respondWithRpcPromise(_0xf995('0xae'),_0xf995('0xaf'),_0x27dacc);});}return respondWithRpcPromise(_0xf995('0xae'),'startRouting',_0x27dacc);})[_0xf995('0x36')](function(_0x3fd78b){if(_0x3fd78b){var _0x3a4189=0xc8;var _0x538e01='receiveMessage';logger[_0xf995('0x21')](_0xf995('0xb0'),_0x538e01,_0x3a4189,'entity\x20found');logger[_0xf995('0x23')]('SmsAccount,\x20%s,\x20%s,\x20%s,\x20%s',_0x538e01,_0x3a4189,'entity\x20found',JSON[_0xf995('0x24')](_0x3fd78b));if(_0x27dacc[_0xf995('0x73')]['type']===_0xf995('0x83')){return _0x4be7c2['status'](_0x3a4189)[_0xf995('0x32')]('Content-Type',_0xf995('0xb1'))[_0xf995('0x3d')](_0xf995('0xb2'));}else{return _0x4be7c2[_0xf995('0x2d')](_0x3a4189)[_0xf995('0x2e')](_0x3fd78b);}}})[_0xf995('0x2a')](handleError(_0x4be7c2,null));};exports[_0xf995('0xb3')]=function(_0x2581b2,_0xbf585f,_0xf03ef5){return db['SmsAccount'][_0xf995('0x6d')]({'where':{'id':_0x2581b2[_0xf995('0x58')]['id']}})[_0xf995('0x36')](handleEntityNotFound(_0xbf585f,null))['then'](function(_0x13554e){if(_0x13554e){return db[_0xf995('0xb4')][_0xf995('0xb5')](function(_0x42e818){return db[_0xf995('0xb6')][_0xf995('0x37')]({'where':{'SmsAccountId':_0x2581b2['params']['id']},'transaction':_0x42e818})[_0xf995('0x36')](function(_0x1613e4){var _0x33c285=_[_0xf995('0x41')](_0x2581b2[_0xf995('0x5c')],function(_0x1141f2){_0x1141f2[_0xf995('0x64')]=_0x2581b2[_0xf995('0x58')]['id'];return _0x1141f2;});return db[_0xf995('0xb6')][_0xf995('0xb7')](_0x33c285,{'transaction':_0x42e818});});})['then'](function(){return db['SmsApplication'][_0xf995('0xb8')]({'where':{'SmsAccountId':_0x2581b2[_0xf995('0x58')]['id']},'order':_0xf995('0x77')});});}})[_0xf995('0x36')](respondWithResult(_0xbf585f,null))[_0xf995('0x2a')](handleError(_0xbf585f,null));};exports['getApplications']=function(_0x48cc7b,_0x307fe1,_0x5c690d){var _0x1d31d6={};var _0x1bc734={};var _0xe29b11;var _0x26e1da;return db[_0xf995('0x54')][_0xf995('0x6d')]({'where':{'id':_0x48cc7b[_0xf995('0x58')]['id']}})[_0xf995('0x36')](handleEntityNotFound(_0x307fe1,null))[_0xf995('0x36')](function(_0x296da8){if(_0x296da8){_0xe29b11=_0x296da8;_0x1bc734[_0xf995('0x45')]=_[_0xf995('0x47')](db[_0xf995('0xb6')][_0xf995('0x42')]);_0x1bc734[_0xf995('0x46')]=_[_0xf995('0x47')](_0x48cc7b['query']);_0x1bc734['filters']=_[_0xf995('0x4a')](_0x1bc734[_0xf995('0x45')],_0x1bc734[_0xf995('0x46')]);_0x1d31d6[_0xf995('0x49')]=_[_0xf995('0x4a')](_0x1bc734['model'],qs['fields'](_0x48cc7b[_0xf995('0x46')][_0xf995('0x4b')]));_0x1d31d6[_0xf995('0x49')]=_0x1d31d6['attributes'][_0xf995('0x59')]?_0x1d31d6[_0xf995('0x49')]:_0x1bc734[_0xf995('0x45')];_0x1d31d6[_0xf995('0x6e')]=qs[_0xf995('0x4e')](_0x48cc7b[_0xf995('0x46')][_0xf995('0x4e')]);_0x1d31d6[_0xf995('0x4f')]=qs['filters'](_[_0xf995('0xb9')](_0x48cc7b[_0xf995('0x46')],_0x1bc734[_0xf995('0x48')]));if(_0x48cc7b[_0xf995('0x46')][_0xf995('0x50')]){_0x1d31d6[_0xf995('0x4f')]=_[_0xf995('0x51')](_0x1d31d6[_0xf995('0x4f')],{'$or':_['map'](_0x1d31d6[_0xf995('0x49')],function(_0x157de6){var _0x8ba40={};_0x8ba40[_0x157de6]={'$like':'%'+_0x48cc7b[_0xf995('0x46')]['filter']+'%'};return _0x8ba40;})});}_0x1d31d6=_[_0xf995('0x51')]({},_0x1d31d6,_0x48cc7b[_0xf995('0x53')]);return _0xe29b11[_0xf995('0xba')](_0x1d31d6);}})[_0xf995('0x36')](function(_0x19b83f){if(_0x19b83f){_0x26e1da=_0x19b83f[_0xf995('0x59')];if(!_0x48cc7b[_0xf995('0x46')]['hasOwnProperty']('nolimit')){_0x1d31d6[_0xf995('0x31')]=qs[_0xf995('0x31')](_0x48cc7b['query'][_0xf995('0x31')]);_0x1d31d6['offset']=qs[_0xf995('0x30')](_0x48cc7b[_0xf995('0x46')][_0xf995('0x30')]);}return _0xe29b11[_0xf995('0xba')](_0x1d31d6);}})[_0xf995('0x36')](function(_0x530b76){if(_0x530b76){return _0x530b76?{'count':_0x26e1da,'rows':_0x530b76}:null;}})[_0xf995('0x36')](respondWithResult(_0x307fe1,null))[_0xf995('0x2a')](handleError(_0x307fe1,null));};exports[_0xf995('0xbb')]=function(_0x1b2b1d,_0x4b4cbf,_0x215380){var _0x11c496={'raw':![],'where':{}};var _0x5f3a16={};var _0x5ce3f8={'count':0x0,'rows':[]};return db[_0xf995('0x54')]['findOne']({'where':{'id':_0x1b2b1d[_0xf995('0x58')]['id']}})[_0xf995('0x36')](handleEntityNotFound(_0x4b4cbf,null))[_0xf995('0x36')](function(_0x314e2a){if(_0x314e2a){_0x5f3a16[_0xf995('0x45')]=_[_0xf995('0x47')](db[_0xf995('0xa2')][_0xf995('0x42')]);_0x5f3a16[_0xf995('0x46')]=_['keys'](_0x1b2b1d['query']);_0x5f3a16[_0xf995('0x48')]=_['intersection'](_0x5f3a16[_0xf995('0x45')],_0x5f3a16[_0xf995('0x46')]);_0x11c496[_0xf995('0x49')]=_[_0xf995('0x4a')](_0x5f3a16[_0xf995('0x45')],qs[_0xf995('0x4b')](_0x1b2b1d['query']['fields']));_0x11c496[_0xf995('0x49')]=_0x11c496['attributes']['length']?_0x11c496[_0xf995('0x49')]:_0x5f3a16[_0xf995('0x45')];if(!_0x1b2b1d[_0xf995('0x46')][_0xf995('0x4c')]('nolimit')){_0x11c496['limit']=qs[_0xf995('0x31')](_0x1b2b1d[_0xf995('0x46')][_0xf995('0x31')]);_0x11c496['offset']=qs['offset'](_0x1b2b1d[_0xf995('0x46')][_0xf995('0x30')]);}_0x11c496[_0xf995('0x6e')]=qs['sort'](_0x1b2b1d[_0xf995('0x46')][_0xf995('0x4e')]);_0x11c496[_0xf995('0x4f')]=qs[_0xf995('0x48')](_[_0xf995('0xb9')](_0x1b2b1d[_0xf995('0x46')],_0x5f3a16['filters']));_0x11c496[_0xf995('0x4f')][_0xf995('0x64')]=_0x314e2a['id'];if(_0x1b2b1d['query'][_0xf995('0x50')]){_0x11c496[_0xf995('0x4f')]=_['merge'](_0x11c496[_0xf995('0x4f')],{'$or':_[_0xf995('0x41')](_0x11c496[_0xf995('0x49')],function(_0x1fb901){var _0x302cca={};_0x302cca[_0x1fb901]={'$like':'%'+_0x1b2b1d['query'][_0xf995('0x50')]+'%'};return _0x302cca;})});}_0x11c496=_[_0xf995('0x51')]({},_0x11c496,_0x1b2b1d[_0xf995('0x53')]);return db[_0xf995('0xa2')]['count']({'where':_0x11c496[_0xf995('0x4f')]})['then'](function(_0x1aa1a6){_0x5ce3f8[_0xf995('0x2f')]=_0x1aa1a6;if(_0x1b2b1d['query']['includeAll']){_0x11c496['include']=[{'model':db[_0xf995('0x79')],'as':'Contact','required':![]},{'model':db[_0xf995('0xaa')],'as':_0xf995('0xbc'),'attributes':[_0xf995('0x3c'),_0xf995('0xbd'),'internal'],'required':![]},{'model':db[_0xf995('0xbe')],'as':_0xf995('0xbf'),'attributes':['id',_0xf995('0x3c'),_0xf995('0xc0')],'where':_0x1b2b1d[_0xf995('0x46')][_0xf995('0xc1')]?{'id':_0x1b2b1d['query']['tag']}:undefined,'required':_0x1b2b1d[_0xf995('0x46')]['tag']?!![]:![]}];}return db[_0xf995('0xa2')][_0xf995('0x67')](_0x11c496);})[_0xf995('0x36')](function(_0x1f9176){_0x5ce3f8[_0xf995('0x68')]=_0x1f9176;return _0x5ce3f8;});}})[_0xf995('0x36')](respondWithFilteredResult(_0x4b4cbf,_0x11c496))['catch'](handleError(_0x4b4cbf,null));};exports[_0xf995('0x3d')]=function(_0x583783,_0x695420,_0x50df5d){var _0x4037da,_0x14fc3d,_0x5d7bc1;if(_['isNil'](_0x583783[_0xf995('0x5c')][_0xf995('0x5c')])||_0x583783[_0xf995('0x5c')][_0xf995('0x5c')]===''){throw new db[(_0xf995('0x7a'))]['ValidationError'](_0xf995('0x9b'));}if(_['isNil'](_0x583783[_0xf995('0x5c')]['to'])){throw new db[(_0xf995('0x7a'))][(_0xf995('0x7b'))](_0xf995('0xc2'));}_0x4037da=_0x583783[_0xf995('0x5c')]['to'];return db[_0xf995('0x54')][_0xf995('0x5a')]({'where':{'id':_0x583783[_0xf995('0x58')]['id']},'include':[{'model':db['CmList'],'as':'List','include':[{'model':db[_0xf995('0x79')],'as':_0xf995('0xa0'),'where':{'mobile':_0x4037da},'limit':0x1,'order':[[_0xf995('0x7f'),_0xf995('0x9e')]]}]}]})[_0xf995('0x36')](handleEntityNotFound(_0x695420,null))[_0xf995('0x36')](function(_0x394989){if(_0x394989&&_0x394989[_0xf995('0xc3')]){_0x14fc3d=_0x394989[_0xf995('0x38')]({'plain':!![]});if(_0x14fc3d[_0xf995('0xc3')]&&_0x14fc3d[_0xf995('0xc3')][_0xf995('0xa0')][_0xf995('0x59')]){return _0x14fc3d[_0xf995('0xc3')]['Contacts'][0x0];}return db[_0xf995('0x79')][_0xf995('0x5b')](_[_0xf995('0x1a')](_0x583783[_0xf995('0x5c')],{'firstName':_0x4037da,'mobile':_0x4037da,'phone':_0x4037da,'ListId':_0x14fc3d['ListId']}));}})[_0xf995('0x36')](handleEntityNotFound(_0x695420,null))[_0xf995('0x36')](function(_0x80c7a1){if(_0x80c7a1){_0x5d7bc1=_0x80c7a1;return db[_0xf995('0xa2')][_0xf995('0x5a')]({'where':{'ContactId':_0x5d7bc1['id'],'closed':![],'SmsAccountId':_0x14fc3d['id']}})[_0xf995('0x36')](function(_0x118708){if(_0x118708){return[_0x118708,![]];}return db[_0xf995('0xa2')]['create']({'UserId':_0x583783[_0xf995('0x5f')]['id'],'ContactId':_0x5d7bc1['id'],'SmsAccountId':_0x14fc3d['id'],'phone':_0x4037da,'firstMsgDirection':_0xf995('0xc4'),'Messages':[_['merge'](_0x583783[_0xf995('0x5c')],{'read':![],'body':_0x583783['body'][_0xf995('0x5c')],'phone':_0x4037da,'SmsAccountId':_0x14fc3d['id'],'UserId':_0x583783['user']['id'],'ContactId':_0x5d7bc1['id']})]},{'include':[{'model':db[_0xf995('0xc5')],'as':_0xf995('0xc6')}]})[_0xf995('0x36')](function(_0xf19884){return[_0xf19884,!![]];});});}})[_0xf995('0xc7')](function(_0x29077a,_0x216069){if(_0x216069){return _0x29077a;}return db[_0xf995('0xc5')][_0xf995('0x5b')](_[_0xf995('0x51')](_0x583783[_0xf995('0x5c')],{'read':![],'body':_0x583783['body'][_0xf995('0x5c')],'phone':_0x4037da,'SmsAccountId':_0x14fc3d['id'],'SmsInteractionId':_0x29077a['id'],'UserId':_0x583783['user']['id'],'ContactId':_0x5d7bc1['id']}))[_0xf995('0x36')](function(_0xcf39f4){_0x29077a[_0xf995('0xc8')][_0xf995('0xc6')]=[];_0x29077a[_0xf995('0xc8')][_0xf995('0xc6')][_0xf995('0xa4')](_0xcf39f4[_0xf995('0xc8')]);return _0x29077a;});})['then'](respondWithResult(_0x695420,null))[_0xf995('0x2a')](handleError(_0x695420,null));};exports[_0xf995('0x2d')]=function(_0x2870dc,_0x438bad,_0x547762){if(_0x2870dc[_0xf995('0x5c')]['id']){delete _0x2870dc['body']['id'];}var _0x228f78,_0x4e2f42,_0x3dea6b;return db[_0xf995('0x54')][_0xf995('0x5a')]({'where':{'id':_0x2870dc[_0xf995('0x58')]['id']}})[_0xf995('0x36')](handleEntityNotFound(_0x438bad,null))['then'](function(_0x448c1c){if(_0x448c1c){_0x3dea6b=_0x448c1c;logger['debug'](_0xf995('0xb0'),'status',_0xf995('0xc9'),_0x448c1c[_0xf995('0x43')],util[_0xf995('0xca')](_0x2870dc[_0xf995('0x5c')],{'showHidden':![],'depth':null}));switch(_0x448c1c['type']){case _0xf995('0x87'):if(_0x2870dc[_0xf995('0x5c')][_0xf995('0xcb')]&&_0x2870dc['body'][_0xf995('0x2d')]){_0x4e2f42=_0x2870dc[_0xf995('0x5c')]['status'];return db[_0xf995('0xc5')][_0xf995('0x5a')]({'where':{'messageId':_0x2870dc[_0xf995('0x5c')][_0xf995('0xcb')]}});}break;case'connectel':if(_0x2870dc['body'][_0xf995('0xcc')]&&_0x2870dc[_0xf995('0x5c')][_0xf995('0xcd')]){_0x4e2f42=_0x2870dc['body'][_0xf995('0xcd')];return db['SmsMessage']['find']({'where':{'messageId':_0x2870dc['body']['requestid']}});}break;case _0xf995('0x8c'):if(_0x2870dc[_0xf995('0x5c')][_0xf995('0x8e')]&&_0x2870dc[_0xf995('0x5c')]['status_code']){_0x4e2f42=_0x2870dc['body'][_0xf995('0xce')];return db['SmsMessage'][_0xf995('0x5a')]({'where':{'messageId':_0x2870dc[_0xf995('0x5c')][_0xf995('0x8e')]}});}break;case _0xf995('0xcf'):var _0x68d528=_0x2870dc[_0xf995('0x5c')][_0xf995('0x92')][0x0];if(_0x68d528[_0xf995('0x8d')]&&_0x68d528[_0xf995('0x2d')][_0xf995('0xd0')]===_0xf995('0xd1')){_0x4e2f42=_0x68d528['status'][_0xf995('0xd0')];return db[_0xf995('0xc5')][_0xf995('0x5a')]({'where':{'messageId':_0x68d528[_0xf995('0x8d')]}});}break;case'clickatell':if(_0x2870dc[_0xf995('0x5c')][_0xf995('0x8d')]&&_0x2870dc[_0xf995('0x5c')][_0xf995('0x2d')]){_0x4e2f42=_0x2870dc[_0xf995('0x5c')][_0xf995('0x2d')];return db[_0xf995('0xc5')]['find']({'where':{'messageId':_0x2870dc[_0xf995('0x5c')][_0xf995('0x8d')]}});}break;case'bandwidth':if(_0x2870dc[_0xf995('0x5c')][0x0][_0xf995('0x27')]['id']){_0x4e2f42=_0x2870dc[_0xf995('0x5c')][0x0][_0xf995('0x43')];return db[_0xf995('0xc5')]['find']({'where':{'messageId':_0x2870dc[_0xf995('0x5c')][0x0][_0xf995('0x27')]['id']}});}break;case _0xf995('0x99'):if(_0x2870dc[_0xf995('0x5c')][_0xf995('0xd2')]&&_0x2870dc[_0xf995('0x5c')][_0xf995('0x2d')]){_0x4e2f42=_0x2870dc[_0xf995('0x5c')][_0xf995('0x2d')];return db[_0xf995('0xc5')][_0xf995('0x5a')]({'where':{'messageId':_0x2870dc[_0xf995('0x5c')][_0xf995('0xd2')]}});}break;}}})[_0xf995('0x36')](handleEntityNotFound(_0x438bad,null))[_0xf995('0x36')](function(_0x7fea51){if(_0x7fea51){_0x228f78=_0x7fea51;switch(_0x3dea6b[_0xf995('0x43')]){case _0xf995('0x87'):if(_0x4e2f42==='DELIVERED'){return _0x228f78[_0xf995('0x35')]({'read':!![]});}else{logger[_0xf995('0x25')]('SmsAccount,\x20%s,\x20%s,\x20%s','status',_0xf995('0x87'),util[_0xf995('0xca')](_0x2870dc[_0xf995('0x5c')],{'showHidden':![],'depth':null}));}break;case'connectel':if(_0x4e2f42==='1'){return _0x228f78[_0xf995('0x35')]({'read':!![]});}else{logger[_0xf995('0x25')](_0xf995('0xb0'),_0xf995('0x2d'),_0xf995('0x87'),util[_0xf995('0xca')](_0x2870dc[_0xf995('0x5c')],{'showHidden':![],'depth':null}));}break;case _0xf995('0x8c'):if(!_0x2870dc[_0xf995('0x5c')][_0xf995('0xd3')]&&_0x4e2f42>=0xc8&&_0x4e2f42<=0xce){return _0x228f78['update']({'read':!![]});}else{logger[_0xf995('0x25')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0xf995('0x2d'),_0xf995('0x8c'),util[_0xf995('0xca')](_0x2870dc[_0xf995('0x5c')],{'showHidden':![],'depth':null}));}break;case _0xf995('0xcf'):var _0x2b187a=_0x2870dc[_0xf995('0x5c')]['results'][0x0];if(_0x2b187a[_0xf995('0x2d')][_0xf995('0xd0')]===_0xf995('0xd1')){return _0x228f78[_0xf995('0x35')]({'read':!![]});}else{logger[_0xf995('0x25')](_0xf995('0xb0'),'status',_0xf995('0xcf'),util[_0xf995('0xca')](_0x2870dc[_0xf995('0x5c')],{'showHidden':![],'depth':null}));}break;case _0xf995('0x96'):if(_0x4e2f42=='DELIVERED_TO_GATEWAY'||_0x4e2f42==_0xf995('0xd4')){return _0x228f78[_0xf995('0x35')]({'read':!![]});}else{logger[_0xf995('0x25')](_0xf995('0xb0'),_0xf995('0x2d'),'clickatell',util['inspect'](_0x2870dc[_0xf995('0x5c')],{'showHidden':![],'depth':null}));}break;case _0xf995('0x98'):if(_0x4e2f42=='message-delivered'){return _0x228f78[_0xf995('0x35')]({'read':!![]});}else{logger[_0xf995('0x25')](_0xf995('0xb0'),_0xf995('0x2d'),'bandwidth',util[_0xf995('0xca')](_0x2870dc[_0xf995('0x5c')],{'showHidden':![],'depth':null}));}break;case _0xf995('0x99'):if(_0x4e2f42==='DELIVRD'||_0x4e2f42===_0xf995('0xd5')){return _0x228f78['update']({'read':!![]});}else{logger[_0xf995('0x25')](_0xf995('0xb0'),_0xf995('0x2d'),_0xf995('0x99'),util['inspect'](_0x2870dc[_0xf995('0x5c')],{'showHidden':![],'depth':null}));}break;}return _0x228f78;}})['then'](respondWithResult(_0x438bad,null))[_0xf995('0x2a')](handleError(_0x438bad,null));};exports[_0xf995('0xd6')]=function(_0x3bf309,_0x55fd08,_0x29e1cd){var _0x337632,_0x5a0a01,_0x247f16;return db[_0xf995('0x54')][_0xf995('0x5a')]({'where':{'id':_0x3bf309[_0xf995('0x58')]['id']}})['then'](handleEntityNotFound(_0x55fd08,null))[_0xf995('0x36')](function(_0x504a29){if(_0x504a29){_0x247f16=_0x504a29;logger[_0xf995('0x23')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0xf995('0x2d'),'received\x20delivery\x20report\x20from',_0x504a29[_0xf995('0x43')],util[_0xf995('0xca')](_0x3bf309[_0xf995('0x46')],{'showHidden':![],'depth':null}));switch(_0x504a29['type']){case _0xf995('0x93'):if(_0x3bf309[_0xf995('0x46')][_0xf995('0xd7')]&&_0x3bf309[_0xf995('0x46')]['state']){_0x5a0a01=_0x3bf309[_0xf995('0x46')]['state'];return db['SmsMessage']['find']({'where':{'messageId':_0x3bf309[_0xf995('0x46')][_0xf995('0xd7')]}});}break;}}})[_0xf995('0x36')](handleEntityNotFound(_0x55fd08,null))[_0xf995('0x36')](function(_0x49c9c0){if(_0x49c9c0){_0x337632=_0x49c9c0;switch(_0x247f16['type']){case'csc':if(_0x5a0a01==='2'||_0x5a0a01==='6'){return _0x337632[_0xf995('0x35')]({'read':!![]});}else{logger['error'](_0xf995('0xb0'),_0xf995('0x2d'),_0xf995('0x93'),util[_0xf995('0xca')](_0x3bf309['query'],{'showHidden':![],'depth':null}));};break;}return _0x337632;}})['then'](respondWithResult(_0x55fd08,null))[_0xf995('0x2a')](handleError(_0x55fd08,null));};exports['addAgents']=function(_0x37cbe0,_0x5eb121,_0x4afd06){return db[_0xf995('0x54')][_0xf995('0x5a')]({'where':{'id':_0x37cbe0[_0xf995('0x58')]['id']}})[_0xf995('0x36')](handleEntityNotFound(_0x5eb121,null))[_0xf995('0x36')](function(_0x539ff4){if(_0x539ff4){return _0x539ff4[_0xf995('0xd8')](_0x37cbe0[_0xf995('0x5c')][_0xf995('0x6a')],_[_0xf995('0xd9')](_0x37cbe0[_0xf995('0x5c')],[_0xf995('0x6a'),'id'])||{})[_0xf995('0xc7')](function(_0x1cb642){for(var _0x35ba17=0x0;_0x35ba17<_0x37cbe0[_0xf995('0x5c')][_0xf995('0x6a')]['length'];_0x35ba17+=0x1){socket[_0xf995('0xda')](_0xf995('0xdb'),{'UserId':_0x37cbe0[_0xf995('0x5c')][_0xf995('0x6a')][_0x35ba17],'SmsAccountId':_0x37cbe0[_0xf995('0x58')]['id']});}return _0x1cb642;});}})[_0xf995('0x36')](respondWithResult(_0x5eb121,null))[_0xf995('0x2a')](handleError(_0x5eb121,null));};exports[_0xf995('0xdc')]=function(_0x4b83e5,_0x5061a4,_0x18c4b6){return db[_0xf995('0x54')]['find']({'where':{'id':_0x4b83e5[_0xf995('0x58')]['id']}})['then'](handleEntityNotFound(_0x5061a4,null))[_0xf995('0x36')](function(_0x4df4d7){if(_0x4df4d7){return _0x4df4d7[_0xf995('0xdc')](_0x4b83e5['query']['ids'])['then'](function(){if(_[_0xf995('0xdd')](_0x4b83e5[_0xf995('0x46')][_0xf995('0x6a')])){for(var _0x13a899=0x0;_0x13a899<_0x4b83e5[_0xf995('0x46')][_0xf995('0x6a')][_0xf995('0x59')];_0x13a899+=0x1){socket['emit'](_0xf995('0xde'),{'UserId':Number(_0x4b83e5[_0xf995('0x46')][_0xf995('0x6a')][_0x13a899]),'SmsAccountId':Number(_0x4b83e5['params']['id'])});}}else{socket[_0xf995('0xda')](_0xf995('0xde'),{'UserId':Number(_0x4b83e5[_0xf995('0x46')]['ids']),'SmsAccountId':Number(_0x4b83e5[_0xf995('0x58')]['id'])});}});}})[_0xf995('0x36')](respondWithStatusCode(_0x5061a4,null))[_0xf995('0x2a')](handleError(_0x5061a4,null));};exports[_0xf995('0xdf')]=function(_0x1e0081,_0x19b66c,_0x5e5ecd){var _0x33de8c={};var _0x11ede0={};var _0x43ec1a;var _0x515a9d;return db[_0xf995('0x54')][_0xf995('0x6d')]({'where':{'id':_0x1e0081['params']['id']}})[_0xf995('0x36')](handleEntityNotFound(_0x19b66c,null))[_0xf995('0x36')](function(_0x22798a){if(_0x22798a){_0x43ec1a=_0x22798a;_0x11ede0[_0xf995('0x45')]=_[_0xf995('0x47')](db['User']['rawAttributes']);_0x11ede0[_0xf995('0x46')]=_[_0xf995('0x47')](_0x1e0081[_0xf995('0x46')]);_0x11ede0[_0xf995('0x48')]=_[_0xf995('0x4a')](_0x11ede0[_0xf995('0x45')],_0x11ede0[_0xf995('0x46')]);_0x33de8c['attributes']=_[_0xf995('0x4a')](_0x11ede0[_0xf995('0x45')],qs[_0xf995('0x4b')](_0x1e0081[_0xf995('0x46')]['fields']));_0x33de8c[_0xf995('0x49')]=_0x33de8c[_0xf995('0x49')]['length']?_0x33de8c[_0xf995('0x49')]:_0x11ede0[_0xf995('0x45')];_0x33de8c[_0xf995('0x6e')]=qs[_0xf995('0x4e')](_0x1e0081[_0xf995('0x46')][_0xf995('0x4e')]);_0x33de8c['where']=qs[_0xf995('0x48')](_['pick'](_0x1e0081[_0xf995('0x46')],_0x11ede0[_0xf995('0x48')]));if(_0x1e0081[_0xf995('0x46')]['filter']){_0x33de8c['where']=_[_0xf995('0x51')](_0x33de8c[_0xf995('0x4f')],{'$or':_[_0xf995('0x41')](_0x33de8c[_0xf995('0x49')],function(_0x9cc9f9){var _0x24e562={};_0x24e562[_0x9cc9f9]={'$like':'%'+_0x1e0081['query'][_0xf995('0x50')]+'%'};return _0x24e562;})});}_0x33de8c=_[_0xf995('0x51')]({},_0x33de8c,_0x1e0081[_0xf995('0x53')]);return _0x43ec1a[_0xf995('0xdf')](_0x33de8c);}})['then'](function(_0x62921c){if(_0x62921c){_0x515a9d=_0x62921c[_0xf995('0x59')];if(!_0x1e0081['query'][_0xf995('0x4c')](_0xf995('0x4d'))){_0x33de8c[_0xf995('0x31')]=qs[_0xf995('0x31')](_0x1e0081['query'][_0xf995('0x31')]);_0x33de8c['offset']=qs['offset'](_0x1e0081[_0xf995('0x46')][_0xf995('0x30')]);}return _0x43ec1a['getAgents'](_0x33de8c);}})[_0xf995('0x36')](function(_0x1a73cc){if(_0x1a73cc){return _0x1a73cc?{'count':_0x515a9d,'rows':_0x1a73cc}:null;}})[_0xf995('0x36')](respondWithResult(_0x19b66c,null))['catch'](handleError(_0x19b66c,null));};
\ No newline at end of file
+var _0xc635=['Content-Range','apply','reject','update','destroy','get','SmsAccounts','UserProfileResource','name','send','index','mandatoryDispositionPause','map','SmsAccount','rawAttributes','type','model','query','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','filter','merge','options','include','show','params','keys','includeAll','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','Pause','describe','addDisposition','SmsAccountId','Disposition','getDispositions','findAll','rows','removeDispositions','addAnswer','CannedAnswer','findOne','removeAnswers','ids','sms','SmsApplication','Applications','account','applications','orderBy','asc','CmContact','Sequelize','no\x20available\x20attributes','createdAt','updatedAt','difference','CompanyId','ListId','mobile','From','messageId','MessageSid','skebby','from','sender','connectel','clicksend','message_id','plivo','Text','infobip','results','text','originatingAddress','clickatell','fromNumber','replyMessageId','intelepeer','isNil','ValidationError','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','Contacts','omit','contact','SmsInteraction','spread','interaction','created','autoclose','push','AttachmentId','UserId','User','waitForTheAssignedAgent','queueId','unshift','queue','waitForTheAssignedQueue','*,*,*,*','Start','startRouting','receiveMessage','SmsAccount,\x20%s,\x20%s,\x20%s','entity\x20found','SmsAccount,\x20%s,\x20%s,\x20%s,\x20%s','twilio','set','Content-Type','text/xml','<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>','addApplications','sequelize','Transaction','ISOLATION_LEVELS','READ_COMMITTED','bulkCreate','findAndCountAll','priority','stack','finally','getApplications','getInteractions','Owner','fullname','internal','Tags','color','tag','List','out','SmsMessage','Messages','dataValues','received\x20delivery\x20report\x20from','inspect','skebby_dispatch_id','requestid','statusInt','status_code','groupName','DELIVERED','bandwidth','redif','error_code','DELIVERED_TO_GATEWAY','RECEIVED_BY_RECIPIENT','message-delivered','DELIVRD','ACCEPTD','debug','csc','message-id','state','addAgents','removeAgents','isArray','emit','userSmsAccount:remove','getAgents','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','path','sox','to-csv','ejs','lodash','squel','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./smsAccount.socket','register','jayson/promise','client','then','SmsAccount,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','info','catch','sendStatus','status','end','json','offset','undefined','limit','count'];(function(_0x160c73,_0x2ee678){var _0xd9302=function(_0x169454){while(--_0x169454){_0x160c73['push'](_0x160c73['shift']());}};_0xd9302(++_0x2ee678);}(_0xc635,0xb6));var _0x5c63=function(_0x49c000,_0x464dd2){_0x49c000=_0x49c000-0x0;var _0x2db5dc=_0xc635[_0x49c000];return _0x2db5dc;};'use strict';var emlformat=require(_0x5c63('0x0'));var rimraf=require(_0x5c63('0x1'));var zipdir=require(_0x5c63('0x2'));var jsonpatch=require(_0x5c63('0x3'));var rp=require(_0x5c63('0x4'));var moment=require(_0x5c63('0x5'));var BPromise=require('bluebird');var Mustache=require(_0x5c63('0x6'));var util=require('util');var path=require(_0x5c63('0x7'));var sox=require(_0x5c63('0x8'));var csv=require(_0x5c63('0x9'));var ejs=require(_0x5c63('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x5c63('0xb'));var squel=require(_0x5c63('0xc'));var crypto=require('crypto');var jsforce=require(_0x5c63('0xd'));var deskjs=require(_0x5c63('0xe'));var toCsv=require(_0x5c63('0x9'));var querystring=require(_0x5c63('0xf'));var Papa=require(_0x5c63('0x10'));var Redis=require('ioredis');var authService=require(_0x5c63('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x5c63('0x12'));var hardwareService=require(_0x5c63('0x13'));var logger=require(_0x5c63('0x14'))(_0x5c63('0x15'));var utils=require('../../config/utils');var config=require(_0x5c63('0x16'));var licenseUtil=require('../../config/license/util');var db=require(_0x5c63('0x17'))['db'];config[_0x5c63('0x18')]=_[_0x5c63('0x19')](config[_0x5c63('0x18')],{'host':_0x5c63('0x1a'),'port':0x18eb});var socket=require(_0x5c63('0x1b'))(new Redis(config[_0x5c63('0x18')]));require(_0x5c63('0x1c'))[_0x5c63('0x1d')](socket);var jayson=require(_0x5c63('0x1e'));var client=jayson[_0x5c63('0x1f')]['http']({'port':0x232c});function respondWithRpcPromise(_0x3dfc24,_0x433016,_0x2bf376,_0x22e847){return new BPromise(function(_0x12374c,_0x3aae1d){var _0xb37a80=_0x22e847||client;return _0xb37a80['request'](_0x3dfc24,_0x2bf376)[_0x5c63('0x20')](function(_0x262ec1){logger['info'](_0x5c63('0x21'),_0x433016,_0x5c63('0x22'));logger['debug']('SmsAccount,\x20%s,\x20%s,\x20%s',_0x433016,'request\x20sent',JSON[_0x5c63('0x23')](_0x262ec1));if(_0x262ec1[_0x5c63('0x24')]){if(_0x262ec1[_0x5c63('0x24')][_0x5c63('0x25')]===0x1f4){logger['error'](_0x5c63('0x21'),_0x433016,_0x262ec1['error']['message']);return _0x3aae1d(_0x262ec1[_0x5c63('0x24')][_0x5c63('0x26')]);}logger['error'](_0x5c63('0x21'),_0x433016,_0x262ec1['error']['message']);return _0x12374c(_0x262ec1[_0x5c63('0x24')][_0x5c63('0x26')]);}else{logger[_0x5c63('0x27')]('SmsAccount,\x20%s,\x20%s',_0x433016,_0x5c63('0x22'));_0x12374c(_0x262ec1['result'][_0x5c63('0x26')]);}})[_0x5c63('0x28')](function(_0x38dacf){logger[_0x5c63('0x24')]('SmsAccount,\x20%s,\x20%s',_0x433016,_0x38dacf);_0x3aae1d(_0x38dacf);});});}function respondWithStatusCode(_0x16209d,_0x136ed9){_0x136ed9=_0x136ed9||0xcc;return function(_0x28563d){if(_0x28563d){return _0x16209d[_0x5c63('0x29')](_0x136ed9);}return _0x16209d[_0x5c63('0x2a')](_0x136ed9)[_0x5c63('0x2b')]();};}function respondWithResult(_0x721e0d,_0x17fe7a){_0x17fe7a=_0x17fe7a||0xc8;return function(_0x46982e){if(_0x46982e){return _0x721e0d[_0x5c63('0x2a')](_0x17fe7a)[_0x5c63('0x2c')](_0x46982e);}};}function respondWithFilteredResult(_0x199960,_0x47be08){return function(_0x7687a8){if(_0x7687a8){var _0x4616fb=typeof _0x47be08[_0x5c63('0x2d')]===_0x5c63('0x2e')&&typeof _0x47be08[_0x5c63('0x2f')]===_0x5c63('0x2e');var _0x487a13=_0x7687a8[_0x5c63('0x30')];var _0x570dc1=_0x4616fb?0x0:_0x47be08['offset'];var _0x37b867=_0x4616fb?_0x7687a8[_0x5c63('0x30')]:_0x47be08[_0x5c63('0x2d')]+_0x47be08[_0x5c63('0x2f')];var _0x4aca17;if(_0x37b867>=_0x487a13){_0x37b867=_0x487a13;_0x4aca17=0xc8;}else{_0x4aca17=0xce;}_0x199960[_0x5c63('0x2a')](_0x4aca17);return _0x199960['set'](_0x5c63('0x31'),_0x570dc1+'-'+_0x37b867+'/'+_0x487a13)[_0x5c63('0x2c')](_0x7687a8);}return null;};}function patchUpdates(_0x41dc61){return function(_0x4731ed){try{jsonpatch[_0x5c63('0x32')](_0x4731ed,_0x41dc61,!![]);}catch(_0x44a87c){return BPromise[_0x5c63('0x33')](_0x44a87c);}return _0x4731ed['save']();};}function saveUpdates(_0x71b4eb,_0x3d4767){return function(_0x3044e5){if(_0x3044e5){return _0x3044e5[_0x5c63('0x34')](_0x71b4eb)['then'](function(_0x13ffaf){return _0x13ffaf;});}return null;};}function removeEntity(_0x3f0538,_0x349ad8){return function(_0x1f41cd){if(_0x1f41cd){return _0x1f41cd[_0x5c63('0x35')]()[_0x5c63('0x20')](function(){var _0x3eacf4=_0x1f41cd[_0x5c63('0x36')]({'plain':!![]});var _0x187c26=_0x5c63('0x37');return db[_0x5c63('0x38')][_0x5c63('0x35')]({'where':{'type':_0x187c26,'resourceId':_0x3eacf4['id']}})[_0x5c63('0x20')](function(){return _0x1f41cd;});})[_0x5c63('0x20')](function(){_0x3f0538[_0x5c63('0x2a')](0xcc)[_0x5c63('0x2b')]();});}};}function handleEntityNotFound(_0x2e2423,_0x2048d5){return function(_0x3ba7be){if(!_0x3ba7be){_0x2e2423[_0x5c63('0x29')](0x194);}return _0x3ba7be;};}function handleError(_0x459f7d,_0xc88d6b){_0xc88d6b=_0xc88d6b||0x1f4;return function(_0x3cf557){logger['error'](_0x3cf557['stack']);if(_0x3cf557[_0x5c63('0x39')]){delete _0x3cf557[_0x5c63('0x39')];}_0x459f7d[_0x5c63('0x2a')](_0xc88d6b)[_0x5c63('0x3a')](_0x3cf557);};}exports[_0x5c63('0x3b')]=function(_0x36c1d0,_0x283e48){var _0x3a071a={'include':[{'model':db['Pause'],'as':_0x5c63('0x3c')}]},_0xb463e3={},_0x26fce4={'count':0x0,'rows':[]};var _0x5501de=_[_0x5c63('0x3d')](db[_0x5c63('0x3e')][_0x5c63('0x3f')],function(_0x4a5ad7){return{'name':_0x4a5ad7['fieldName'],'type':_0x4a5ad7[_0x5c63('0x40')]['key']};});_0xb463e3[_0x5c63('0x41')]=_[_0x5c63('0x3d')](_0x5501de,'name');_0xb463e3[_0x5c63('0x42')]=_['keys'](_0x36c1d0[_0x5c63('0x42')]);_0xb463e3['filters']=_[_0x5c63('0x43')](_0xb463e3[_0x5c63('0x41')],_0xb463e3[_0x5c63('0x42')]);_0x3a071a[_0x5c63('0x44')]=_[_0x5c63('0x43')](_0xb463e3[_0x5c63('0x41')],qs[_0x5c63('0x45')](_0x36c1d0[_0x5c63('0x42')][_0x5c63('0x45')]));_0x3a071a['attributes']=_0x3a071a[_0x5c63('0x44')][_0x5c63('0x46')]?_0x3a071a[_0x5c63('0x44')]:_0xb463e3[_0x5c63('0x41')];if(!_0x36c1d0[_0x5c63('0x42')][_0x5c63('0x47')](_0x5c63('0x48'))){_0x3a071a[_0x5c63('0x2f')]=qs[_0x5c63('0x2f')](_0x36c1d0[_0x5c63('0x42')][_0x5c63('0x2f')]);_0x3a071a[_0x5c63('0x2d')]=qs[_0x5c63('0x2d')](_0x36c1d0[_0x5c63('0x42')]['offset']);}_0x3a071a[_0x5c63('0x49')]=qs[_0x5c63('0x4a')](_0x36c1d0[_0x5c63('0x42')]['sort']);_0x3a071a[_0x5c63('0x4b')]=qs[_0x5c63('0x4c')](_[_0x5c63('0x4d')](_0x36c1d0['query'],_0xb463e3[_0x5c63('0x4c')]),_0x5501de);if(_0x36c1d0[_0x5c63('0x42')][_0x5c63('0x4e')]){_0x3a071a['where']=_[_0x5c63('0x4f')](_0x3a071a[_0x5c63('0x4b')],{'$or':_[_0x5c63('0x3d')](_0x5501de,function(_0x294217){if(_0x294217[_0x5c63('0x40')]!=='VIRTUAL'){var _0x3bf6b1={};_0x3bf6b1[_0x294217['name']]={'$like':'%'+_0x36c1d0[_0x5c63('0x42')][_0x5c63('0x4e')]+'%'};return _0x3bf6b1;}})});}_0x3a071a=_[_0x5c63('0x4f')]({},_0x3a071a,_0x36c1d0[_0x5c63('0x50')]);var _0x3af819={'where':_0x3a071a['where']};return db['SmsAccount'][_0x5c63('0x30')](_0x3af819)['then'](function(_0x3b67e7){_0x26fce4[_0x5c63('0x30')]=_0x3b67e7;if(_0x36c1d0[_0x5c63('0x42')]['includeAll']){_0x3a071a[_0x5c63('0x51')]=[{'all':!![]}];}return db[_0x5c63('0x3e')]['findAll'](_0x3a071a);})[_0x5c63('0x20')](function(_0x487d83){_0x26fce4['rows']=_0x487d83;return _0x26fce4;})[_0x5c63('0x20')](respondWithFilteredResult(_0x283e48,_0x3a071a))[_0x5c63('0x28')](handleError(_0x283e48,null));};exports[_0x5c63('0x52')]=function(_0x33b98c,_0x4d2a95){var _0x4fbda7={'raw':![],'where':{'id':_0x33b98c[_0x5c63('0x53')]['id']},'include':[{'model':db['Pause'],'as':_0x5c63('0x3c')}]},_0x1ebf5b={};_0x1ebf5b['model']=_[_0x5c63('0x54')](db[_0x5c63('0x3e')]['rawAttributes']);_0x1ebf5b[_0x5c63('0x42')]=_['keys'](_0x33b98c[_0x5c63('0x42')]);_0x1ebf5b[_0x5c63('0x4c')]=_[_0x5c63('0x43')](_0x1ebf5b[_0x5c63('0x41')],_0x1ebf5b[_0x5c63('0x42')]);_0x4fbda7['attributes']=_[_0x5c63('0x43')](_0x1ebf5b[_0x5c63('0x41')],qs[_0x5c63('0x45')](_0x33b98c[_0x5c63('0x42')][_0x5c63('0x45')]));_0x4fbda7[_0x5c63('0x44')]=_0x4fbda7[_0x5c63('0x44')][_0x5c63('0x46')]?_0x4fbda7[_0x5c63('0x44')]:_0x1ebf5b[_0x5c63('0x41')];if(_0x33b98c[_0x5c63('0x42')][_0x5c63('0x55')]){_0x4fbda7['include']=[{'all':!![]}];}_0x4fbda7=_[_0x5c63('0x4f')]({},_0x4fbda7,_0x33b98c[_0x5c63('0x50')]);return db[_0x5c63('0x3e')][_0x5c63('0x56')](_0x4fbda7)[_0x5c63('0x20')](handleEntityNotFound(_0x4d2a95,null))[_0x5c63('0x20')](respondWithResult(_0x4d2a95,null))[_0x5c63('0x28')](handleError(_0x4d2a95,null));};exports[_0x5c63('0x57')]=function(_0x1b4a58,_0x3b2790){return db[_0x5c63('0x3e')][_0x5c63('0x57')](_0x1b4a58[_0x5c63('0x58')],{})[_0x5c63('0x20')](function(_0x5374cd){var _0xa46cc4=_0x1b4a58[_0x5c63('0x59')]['get']({'plain':!![]});if(!_0xa46cc4)throw new Error(_0x5c63('0x5a'));if(_0xa46cc4[_0x5c63('0x5b')]===_0x5c63('0x59')){var _0x4ab3d1=_0x5374cd[_0x5c63('0x36')]({'plain':!![]});var _0x1e37e0=_0x5c63('0x37');return db[_0x5c63('0x5c')][_0x5c63('0x56')]({'where':{'name':_0x1e37e0,'userProfileId':_0xa46cc4[_0x5c63('0x5d')]},'raw':!![]})[_0x5c63('0x20')](function(_0xa31795){if(_0xa31795&&_0xa31795[_0x5c63('0x5e')]===0x0){return db['UserProfileResource'][_0x5c63('0x57')]({'name':_0x4ab3d1[_0x5c63('0x39')],'resourceId':_0x4ab3d1['id'],'type':_0xa31795[_0x5c63('0x39')],'sectionId':_0xa31795['id']},{})[_0x5c63('0x20')](function(){return _0x5374cd;});}else{return _0x5374cd;}})[_0x5c63('0x28')](function(_0x115f4f){logger[_0x5c63('0x24')](_0x5c63('0x5f'),_0x115f4f);throw _0x115f4f;});}return _0x5374cd;})[_0x5c63('0x20')](respondWithResult(_0x3b2790,0xc9))[_0x5c63('0x28')](handleError(_0x3b2790,null));};exports[_0x5c63('0x34')]=function(_0x11a17d,_0x47375d){if(_0x11a17d['body']['id']){delete _0x11a17d[_0x5c63('0x58')]['id'];}return db[_0x5c63('0x3e')][_0x5c63('0x56')]({'where':{'id':_0x11a17d['params']['id']},'include':[{'model':db[_0x5c63('0x60')],'as':_0x5c63('0x3c')}]})[_0x5c63('0x20')](handleEntityNotFound(_0x47375d,null))[_0x5c63('0x20')](saveUpdates(_0x11a17d[_0x5c63('0x58')],null))['then'](respondWithResult(_0x47375d,null))['catch'](handleError(_0x47375d,null));};exports[_0x5c63('0x35')]=function(_0x28d71a,_0x1f32d0){return db[_0x5c63('0x3e')][_0x5c63('0x56')]({'where':{'id':_0x28d71a['params']['id']}})[_0x5c63('0x20')](handleEntityNotFound(_0x1f32d0,null))['then'](removeEntity(_0x1f32d0,null))[_0x5c63('0x28')](handleError(_0x1f32d0,null));};exports[_0x5c63('0x61')]=function(_0x14f105,_0x8414ae){return db[_0x5c63('0x3e')][_0x5c63('0x61')]()['then'](respondWithResult(_0x8414ae,null))['catch'](handleError(_0x8414ae,null));};exports[_0x5c63('0x62')]=function(_0x2844f1,_0xc0ec55,_0x17d2b3){if(_0x2844f1['body']['id']){delete _0x2844f1[_0x5c63('0x58')]['id'];}return db[_0x5c63('0x3e')][_0x5c63('0x56')]({'where':{'id':_0x2844f1['params']['id']}})[_0x5c63('0x20')](handleEntityNotFound(_0xc0ec55,null))[_0x5c63('0x20')](function(_0x21e7c8){if(_0x21e7c8){_0x2844f1[_0x5c63('0x58')][_0x5c63('0x63')]=_0x21e7c8['id'];return db[_0x5c63('0x64')]['create'](_0x2844f1[_0x5c63('0x58')]);}})[_0x5c63('0x20')](respondWithResult(_0xc0ec55,null))['catch'](handleError(_0xc0ec55,null));};exports[_0x5c63('0x65')]=function(_0x1f8aa9,_0x3e480d,_0xa24626){var _0x128999={'raw':![],'where':{}};var _0x5b586e={};var _0x1db352={'count':0x0,'rows':[]};return db[_0x5c63('0x3e')]['findOne']({'where':{'id':_0x1f8aa9[_0x5c63('0x53')]['id']}})[_0x5c63('0x20')](handleEntityNotFound(_0x3e480d,null))[_0x5c63('0x20')](function(_0x17554b){if(_0x17554b){_0x5b586e['model']=_[_0x5c63('0x54')](db[_0x5c63('0x64')]['rawAttributes']);_0x5b586e['query']=_[_0x5c63('0x54')](_0x1f8aa9['query']);_0x5b586e[_0x5c63('0x4c')]=_[_0x5c63('0x43')](_0x5b586e[_0x5c63('0x41')],_0x5b586e[_0x5c63('0x42')]);_0x128999[_0x5c63('0x44')]=_[_0x5c63('0x43')](_0x5b586e[_0x5c63('0x41')],qs[_0x5c63('0x45')](_0x1f8aa9[_0x5c63('0x42')]['fields']));_0x128999[_0x5c63('0x44')]=_0x128999[_0x5c63('0x44')]['length']?_0x128999[_0x5c63('0x44')]:_0x5b586e[_0x5c63('0x41')];if(!_0x1f8aa9['query'][_0x5c63('0x47')](_0x5c63('0x48'))){_0x128999['limit']=qs[_0x5c63('0x2f')](_0x1f8aa9[_0x5c63('0x42')][_0x5c63('0x2f')]);_0x128999[_0x5c63('0x2d')]=qs[_0x5c63('0x2d')](_0x1f8aa9[_0x5c63('0x42')][_0x5c63('0x2d')]);}_0x128999[_0x5c63('0x49')]=qs['sort'](_0x1f8aa9[_0x5c63('0x42')][_0x5c63('0x4a')]);_0x128999[_0x5c63('0x4b')]=qs['filters'](_[_0x5c63('0x4d')](_0x1f8aa9['query'],_0x5b586e[_0x5c63('0x4c')]));_0x128999[_0x5c63('0x4b')][_0x5c63('0x63')]=_0x17554b['id'];if(_0x1f8aa9[_0x5c63('0x42')]['filter']){_0x128999[_0x5c63('0x4b')]=_[_0x5c63('0x4f')](_0x128999[_0x5c63('0x4b')],{'$or':_['map'](_0x128999[_0x5c63('0x44')],function(_0x5e72aa){var _0x144bc4={};_0x144bc4[_0x5e72aa]={'$like':'%'+_0x1f8aa9[_0x5c63('0x42')][_0x5c63('0x4e')]+'%'};return _0x144bc4;})});}_0x128999=_[_0x5c63('0x4f')]({},_0x128999,_0x1f8aa9['options']);return db['Disposition']['count']({'where':_0x128999[_0x5c63('0x4b')]})[_0x5c63('0x20')](function(_0x5f1287){_0x1db352[_0x5c63('0x30')]=_0x5f1287;if(_0x1f8aa9[_0x5c63('0x42')][_0x5c63('0x55')]){_0x128999[_0x5c63('0x51')]=[{'all':!![]}];}return db[_0x5c63('0x64')][_0x5c63('0x66')](_0x128999);})[_0x5c63('0x20')](function(_0x454028){_0x1db352[_0x5c63('0x67')]=_0x454028;return _0x1db352;});}})['then'](respondWithFilteredResult(_0x3e480d,_0x128999))['catch'](handleError(_0x3e480d,null));};exports[_0x5c63('0x68')]=function(_0x5e5d8f,_0x2f1a,_0x81a55b){return db[_0x5c63('0x3e')][_0x5c63('0x56')]({'where':{'id':_0x5e5d8f[_0x5c63('0x53')]['id']}})[_0x5c63('0x20')](handleEntityNotFound(_0x2f1a,null))[_0x5c63('0x20')](function(_0x48d34c){if(_0x48d34c){return _0x48d34c[_0x5c63('0x68')](_0x5e5d8f[_0x5c63('0x42')]['ids']);}})[_0x5c63('0x20')](respondWithStatusCode(_0x2f1a,null))[_0x5c63('0x28')](handleError(_0x2f1a,null));};exports[_0x5c63('0x69')]=function(_0x27a603,_0x53ddb0,_0x3fd262){if(_0x27a603[_0x5c63('0x58')]['id']){delete _0x27a603[_0x5c63('0x58')]['id'];}return db[_0x5c63('0x3e')][_0x5c63('0x56')]({'where':{'id':_0x27a603[_0x5c63('0x53')]['id']}})[_0x5c63('0x20')](handleEntityNotFound(_0x53ddb0,null))['then'](function(_0x4b7d11){if(_0x4b7d11){_0x27a603['body'][_0x5c63('0x63')]=_0x4b7d11['id'];return db[_0x5c63('0x6a')][_0x5c63('0x57')](_0x27a603[_0x5c63('0x58')]);}})[_0x5c63('0x20')](respondWithResult(_0x53ddb0,null))[_0x5c63('0x28')](handleError(_0x53ddb0,null));};exports['getAnswers']=function(_0x1aff20,_0x289b03,_0x3ab282){var _0x2fb901={'raw':![],'where':{}};var _0xa219c7={};var _0x2d89f2={'count':0x0,'rows':[]};return db[_0x5c63('0x3e')][_0x5c63('0x6b')]({'where':{'id':_0x1aff20[_0x5c63('0x53')]['id']}})[_0x5c63('0x20')](handleEntityNotFound(_0x289b03,null))[_0x5c63('0x20')](function(_0x7d6ef1){if(_0x7d6ef1){_0xa219c7[_0x5c63('0x41')]=_['keys'](db[_0x5c63('0x6a')][_0x5c63('0x3f')]);_0xa219c7['query']=_[_0x5c63('0x54')](_0x1aff20[_0x5c63('0x42')]);_0xa219c7[_0x5c63('0x4c')]=_['intersection'](_0xa219c7[_0x5c63('0x41')],_0xa219c7[_0x5c63('0x42')]);_0x2fb901[_0x5c63('0x44')]=_[_0x5c63('0x43')](_0xa219c7[_0x5c63('0x41')],qs[_0x5c63('0x45')](_0x1aff20[_0x5c63('0x42')][_0x5c63('0x45')]));_0x2fb901[_0x5c63('0x44')]=_0x2fb901[_0x5c63('0x44')][_0x5c63('0x46')]?_0x2fb901[_0x5c63('0x44')]:_0xa219c7[_0x5c63('0x41')];if(!_0x1aff20[_0x5c63('0x42')][_0x5c63('0x47')]('nolimit')){_0x2fb901[_0x5c63('0x2f')]=qs[_0x5c63('0x2f')](_0x1aff20['query'][_0x5c63('0x2f')]);_0x2fb901[_0x5c63('0x2d')]=qs[_0x5c63('0x2d')](_0x1aff20[_0x5c63('0x42')][_0x5c63('0x2d')]);}_0x2fb901[_0x5c63('0x49')]=qs[_0x5c63('0x4a')](_0x1aff20[_0x5c63('0x42')][_0x5c63('0x4a')]);_0x2fb901['where']=qs['filters'](_[_0x5c63('0x4d')](_0x1aff20[_0x5c63('0x42')],_0xa219c7[_0x5c63('0x4c')]));_0x2fb901[_0x5c63('0x4b')][_0x5c63('0x63')]=_0x7d6ef1['id'];if(_0x1aff20[_0x5c63('0x42')][_0x5c63('0x4e')]){_0x2fb901[_0x5c63('0x4b')]=_[_0x5c63('0x4f')](_0x2fb901[_0x5c63('0x4b')],{'$or':_[_0x5c63('0x3d')](_0x2fb901[_0x5c63('0x44')],function(_0x20a3d9){var _0x5f5afa={};_0x5f5afa[_0x20a3d9]={'$like':'%'+_0x1aff20['query'][_0x5c63('0x4e')]+'%'};return _0x5f5afa;})});}_0x2fb901=_[_0x5c63('0x4f')]({},_0x2fb901,_0x1aff20[_0x5c63('0x50')]);return db['CannedAnswer'][_0x5c63('0x30')]({'where':_0x2fb901[_0x5c63('0x4b')]})[_0x5c63('0x20')](function(_0x24f321){_0x2d89f2['count']=_0x24f321;if(_0x1aff20['query']['includeAll']){_0x2fb901[_0x5c63('0x51')]=[{'all':!![]}];}return db[_0x5c63('0x6a')][_0x5c63('0x66')](_0x2fb901);})['then'](function(_0x2798f7){_0x2d89f2[_0x5c63('0x67')]=_0x2798f7;return _0x2d89f2;});}})[_0x5c63('0x20')](respondWithFilteredResult(_0x289b03,_0x2fb901))[_0x5c63('0x28')](handleError(_0x289b03,null));};exports[_0x5c63('0x6c')]=function(_0x683a04,_0xb54f86,_0x4b2330){return db['SmsAccount'][_0x5c63('0x56')]({'where':{'id':_0x683a04['params']['id']}})[_0x5c63('0x20')](handleEntityNotFound(_0xb54f86,null))['then'](function(_0x326935){if(_0x326935){return _0x326935['removeAnswers'](_0x683a04[_0x5c63('0x42')][_0x5c63('0x6d')]);}})[_0x5c63('0x20')](respondWithStatusCode(_0xb54f86,null))[_0x5c63('0x28')](handleError(_0xb54f86,null));};exports['notify']=function(_0x4518e7,_0x1badbf,_0x5db922){var _0x280ebf={'channel':_0x5c63('0x6e')};var _0x1a9e6d=[];var _0x288f11=[];var _0x566d21={};return db[_0x5c63('0x3e')]['find']({'where':{'id':_0x4518e7[_0x5c63('0x53')]['id']},'include':[{'model':db[_0x5c63('0x6f')],'as':_0x5c63('0x70')}]})['then'](handleEntityNotFound(_0x1badbf,null))[_0x5c63('0x20')](function(_0x20b689){_0x280ebf[_0x5c63('0x71')]=_0x20b689;_0x280ebf[_0x5c63('0x72')]=_[_0x5c63('0x73')](_0x20b689['Applications'],['priority'],[_0x5c63('0x74')]);if(_0x280ebf['account'][_0x5c63('0x70')]){delete _0x280ebf['account']['Applications'];}return db[_0x5c63('0x75')][_0x5c63('0x61')]();})[_0x5c63('0x20')](function(_0x268c29){if(!_0x268c29){throw new db[(_0x5c63('0x76'))]['ValidationError'](_0x5c63('0x77'));}_0x1a9e6d=_['difference'](_[_0x5c63('0x54')](_0x268c29),[_0x5c63('0x78'),_0x5c63('0x79')]);_0x288f11=_[_0x5c63('0x7a')](_[_0x5c63('0x54')](_0x268c29),[_0x5c63('0x78'),_0x5c63('0x79'),_0x5c63('0x7b'),_0x5c63('0x7c')]);_0x280ebf['body']={'mapKey':_0x5c63('0x7d')};if(_0x280ebf[_0x5c63('0x71')][_0x5c63('0x40')]){switch(_0x280ebf[_0x5c63('0x71')][_0x5c63('0x40')]){case'twilio':_0x280ebf[_0x5c63('0x58')]['from']=_0x4518e7[_0x5c63('0x58')][_0x5c63('0x7e')];_0x280ebf[_0x5c63('0x58')][_0x5c63('0x58')]=_0x4518e7[_0x5c63('0x58')]['Body'];_0x280ebf['body'][_0x5c63('0x7f')]=_0x4518e7[_0x5c63('0x58')][_0x5c63('0x80')];break;case _0x5c63('0x81'):_0x280ebf[_0x5c63('0x58')][_0x5c63('0x82')]='+'+_0x4518e7[_0x5c63('0x58')][_0x5c63('0x83')];_0x280ebf[_0x5c63('0x58')][_0x5c63('0x58')]=_0x4518e7['body']['text'];break;case _0x5c63('0x84'):_0x280ebf[_0x5c63('0x58')][_0x5c63('0x82')]=_0x4518e7['body'][_0x5c63('0x82')];_0x280ebf[_0x5c63('0x58')][_0x5c63('0x58')]=_0x4518e7[_0x5c63('0x58')]['message'];break;case _0x5c63('0x85'):_0x280ebf['body']['from']=_0x4518e7[_0x5c63('0x58')][_0x5c63('0x82')];_0x280ebf[_0x5c63('0x58')]['body']=_0x4518e7['body'][_0x5c63('0x58')];_0x280ebf['body'][_0x5c63('0x7f')]=_0x4518e7[_0x5c63('0x58')][_0x5c63('0x86')];break;case _0x5c63('0x87'):_0x280ebf[_0x5c63('0x58')]['from']=_0x4518e7['body']['From'];_0x280ebf[_0x5c63('0x58')]['body']=_0x4518e7[_0x5c63('0x58')][_0x5c63('0x88')];_0x280ebf[_0x5c63('0x58')][_0x5c63('0x7f')]=_0x4518e7[_0x5c63('0x58')]['MessageUUID'];break;case _0x5c63('0x89'):_0x280ebf[_0x5c63('0x58')]['from']='+'+_0x4518e7[_0x5c63('0x58')]['results'][0x0][_0x5c63('0x82')];_0x280ebf['body'][_0x5c63('0x58')]=_0x4518e7[_0x5c63('0x58')][_0x5c63('0x8a')][0x0][_0x5c63('0x8b')];_0x280ebf['body'][_0x5c63('0x7f')]=_0x4518e7[_0x5c63('0x58')][_0x5c63('0x8a')][0x0]['messageId'];break;case'csc':_0x280ebf[_0x5c63('0x58')][_0x5c63('0x82')]=_0x4518e7[_0x5c63('0x58')][_0x5c63('0x8c')];_0x280ebf[_0x5c63('0x58')]['body']=_0x4518e7['body']['segmentedMessage']['message'];break;case _0x5c63('0x8d'):_0x280ebf[_0x5c63('0x58')][_0x5c63('0x82')]=_0x4518e7[_0x5c63('0x58')][_0x5c63('0x8e')];_0x280ebf[_0x5c63('0x58')][_0x5c63('0x58')]=_0x4518e7['body']['text'];_0x280ebf[_0x5c63('0x58')][_0x5c63('0x7f')]=_0x4518e7[_0x5c63('0x58')][_0x5c63('0x8f')];break;case'bandwidth':_0x280ebf[_0x5c63('0x58')][_0x5c63('0x7f')]=_0x4518e7[_0x5c63('0x58')][0x0][_0x5c63('0x26')]['id'];_0x280ebf[_0x5c63('0x58')][_0x5c63('0x82')]=_0x4518e7[_0x5c63('0x58')][0x0]['message']['from'];_0x280ebf['body'][_0x5c63('0x58')]=_0x4518e7[_0x5c63('0x58')][0x0][_0x5c63('0x26')]['text'];break;case _0x5c63('0x90'):_0x280ebf['body'][_0x5c63('0x82')]=_0x4518e7[_0x5c63('0x58')]['from'];_0x280ebf[_0x5c63('0x58')]['body']=_0x4518e7['body'][_0x5c63('0x26')];_0x280ebf[_0x5c63('0x58')][_0x5c63('0x7f')]=_0x4518e7['body']['refid'];break;}}if(_0x280ebf[_0x5c63('0x58')]['id']){delete _0x280ebf[_0x5c63('0x58')]['id'];}if(_[_0x5c63('0x91')](_0x280ebf['body'][_0x5c63('0x82')])){throw new db[(_0x5c63('0x76'))][(_0x5c63('0x92'))](_0x5c63('0x93'));}if(_[_0x5c63('0x91')](_0x280ebf[_0x5c63('0x58')][_0x5c63('0x58')])||_0x280ebf[_0x5c63('0x58')][_0x5c63('0x58')]===''){throw new db[(_0x5c63('0x76'))][(_0x5c63('0x92'))](_0x5c63('0x94'));}if(_[_0x5c63('0x91')](_0x280ebf[_0x5c63('0x58')][_0x5c63('0x95')])){throw new db[(_0x5c63('0x76'))][(_0x5c63('0x92'))]('mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x288f11);}if(!_[_0x5c63('0x96')](_0x288f11,_0x280ebf[_0x5c63('0x58')][_0x5c63('0x95')])){throw new db[(_0x5c63('0x76'))][(_0x5c63('0x92'))](_0x5c63('0x97')+_0x288f11);}_0x566d21[_0x280ebf['body']['mapKey']]=_0x280ebf[_0x5c63('0x58')][_0x5c63('0x82')];return db[_0x5c63('0x98')][_0x5c63('0x56')]({'where':{'id':_0x280ebf[_0x5c63('0x71')][_0x5c63('0x7c')]},'include':[{'model':db[_0x5c63('0x75')],'as':_0x5c63('0x99'),'where':_0x566d21,'limit':0x1,'order':[[_0x5c63('0x79'),'DESC']]}]});})[_0x5c63('0x20')](handleEntityNotFound(_0x1badbf,null))[_0x5c63('0x20')](function(_0x4e3865){if(_0x4e3865){_0x280ebf['list']=_[_0x5c63('0x9a')](_0x4e3865,['Contacts']);if(_0x4e3865[_0x5c63('0x99')]['length']){return _0x4e3865['Contacts'][0x0];}var _0x4eb09a=_[_0x5c63('0x19')](_0x280ebf[_0x5c63('0x58')],{'firstName':_0x280ebf[_0x5c63('0x58')]['from'],'ListId':_0x4e3865['id']});_0x4eb09a[_0x280ebf['body'][_0x5c63('0x95')]]=_0x280ebf[_0x5c63('0x58')][_0x5c63('0x82')];return db['CmContact'][_0x5c63('0x57')](_0x4eb09a,{'fields':_0x1a9e6d,'raw':!![]});}})[_0x5c63('0x20')](handleEntityNotFound(_0x1badbf,null))[_0x5c63('0x20')](function(_0x478ee7){if(_0x478ee7){_0x280ebf[_0x5c63('0x9b')]=_0x478ee7;var _0x56cf6f={'ContactId':_0x478ee7['id'],'phone':_0x280ebf[_0x5c63('0x58')][_0x5c63('0x82')],'SmsAccountId':_0x4518e7[_0x5c63('0x53')]['id']};var _0x15e2de={'ContactId':_0x478ee7['id'],'SmsAccountId':_0x4518e7['params']['id'],'closed':![]};return db[_0x5c63('0x9c')][_0x5c63('0x56')]({'where':_0x15e2de})[_0x5c63('0x20')](function(_0x5d4e74){if(_0x5d4e74){return[_0x5d4e74,![]];}return db[_0x5c63('0x9c')][_0x5c63('0x57')](_0x56cf6f)[_0x5c63('0x20')](function(_0xa608c6){return[_0xa608c6,!![]];});});}})[_0x5c63('0x9d')](function(_0x200345,_0x40ef77){_0x280ebf[_0x5c63('0x9e')]=_0x200345[_0x5c63('0x36')]({'plain':!![]});_0x280ebf['interaction'][_0x5c63('0x9f')]=![];if(_0x40ef77){if(_0x280ebf[_0x5c63('0x71')][_0x5c63('0xa0')]){_0x280ebf[_0x5c63('0x72')][_0x5c63('0xa1')]({'id':0x0,'priority':_0x280ebf['applications'][_0x5c63('0x46')]+0x1,'app':'close','appdata':'unmanaged','interval':'*,*,*,*'});}_0x280ebf[_0x5c63('0x9e')]['created']=!![];}return db['SmsMessage']['create']({'phone':_0x280ebf[_0x5c63('0x58')][_0x5c63('0x82')],'messageId':_0x280ebf[_0x5c63('0x58')][_0x5c63('0x7f')],'body':_0x280ebf[_0x5c63('0x58')][_0x5c63('0x58')],'SmsAccountId':_0x4518e7['params']['id'],'SmsInteractionId':_0x200345['id'],'direction':'in','ContactId':_0x200345['ContactId'],'AttachmentId':_0x280ebf[_0x5c63('0x58')][_0x5c63('0xa2')]});})[_0x5c63('0x20')](function(_0x3bdaab){_0x280ebf[_0x5c63('0x26')]=_0x3bdaab;if(!_0x280ebf[_0x5c63('0x9e')][_0x5c63('0xa3')])return;return db[_0x5c63('0xa4')]['find']({'attributes':['id','name'],'where':{'id':_0x280ebf[_0x5c63('0x9e')][_0x5c63('0xa3')]}});})[_0x5c63('0x20')](function(_0x29cb5d){if(_0x29cb5d){_0x280ebf['applications']['unshift']({'id':0x0,'priority':0x0,'app':'agent','appdata':_0x29cb5d[_0x5c63('0x39')]+','+(_0x280ebf[_0x5c63('0x71')][_0x5c63('0xa5')]||0xa),'interval':'*,*,*,*'});}if(!_0x280ebf[_0x5c63('0x9e')][_0x5c63('0xa6')])return;return db['SmsQueue'][_0x5c63('0x56')]({'attributes':['id','name'],'where':{'id':_0x280ebf[_0x5c63('0x9e')][_0x5c63('0xa6')]}});})[_0x5c63('0x20')](function(_0xf0b9f6){if(_0xf0b9f6){_0x280ebf[_0x5c63('0x72')][_0x5c63('0xa7')]({'id':0x0,'priority':0x1,'app':_0x5c63('0xa8'),'appdata':_0xf0b9f6[_0x5c63('0x39')]+','+(_0x280ebf[_0x5c63('0x71')][_0x5c63('0xa9')]||0x12c),'interval':_0x5c63('0xaa')});}return respondWithRpcPromise(_0x5c63('0xab'),_0x5c63('0xac'),_0x280ebf);})[_0x5c63('0x20')](function(_0x3c94ea){if(_0x3c94ea){var _0x183ecd=0xc8;var _0x476069=_0x5c63('0xad');logger[_0x5c63('0x27')](_0x5c63('0xae'),_0x476069,_0x183ecd,_0x5c63('0xaf'));logger['debug'](_0x5c63('0xb0'),_0x476069,_0x183ecd,_0x5c63('0xaf'),JSON[_0x5c63('0x23')](_0x3c94ea));if(_0x280ebf[_0x5c63('0x71')][_0x5c63('0x40')]===_0x5c63('0xb1')){return _0x1badbf['status'](_0x183ecd)[_0x5c63('0xb2')](_0x5c63('0xb3'),_0x5c63('0xb4'))[_0x5c63('0x3a')](_0x5c63('0xb5'));}else{return _0x1badbf['status'](_0x183ecd)[_0x5c63('0x2c')](_0x3c94ea);}}})[_0x5c63('0x28')](handleError(_0x1badbf,null));};exports[_0x5c63('0xb6')]=function(_0x3aef75,_0x18226a){var _0x57331f=_0x3aef75[_0x5c63('0x53')]['id'];var _0x3d26ec=_0x3aef75[_0x5c63('0x58')];var _0x4654e1=0xc8;var _0x55bc3b=null;return db[_0x5c63('0xb7')]['transaction']({'isolationLevel':db[_0x5c63('0xb7')][_0x5c63('0xb8')][_0x5c63('0xb9')][_0x5c63('0xba')]},function(_0x1bd4fa){return db[_0x5c63('0x3e')][_0x5c63('0x6b')]({'where':{'id':_0x57331f},'transaction':_0x1bd4fa})[_0x5c63('0x20')](function(_0x142649){if(_0x142649){return db['SmsApplication']['destroy']({'where':{'SmsAccountId':_0x57331f},'transaction':_0x1bd4fa})[_0x5c63('0x20')](function(){var _0x3e96ea=_[_0x5c63('0x3d')](_0x3d26ec,function(_0x55f2d2){_0x55f2d2[_0x5c63('0x63')]=_0x57331f;return _0x55f2d2;});return db[_0x5c63('0x6f')][_0x5c63('0xbb')](_0x3e96ea,{'transaction':_0x1bd4fa});});}else{_0x4654e1=0x194;_0x55bc3b=[];}});})['then'](function(){if(_0x4654e1!==0x194){return db[_0x5c63('0x6f')][_0x5c63('0xbc')]({'where':{'SmsAccountId':_0x57331f},'order':_0x5c63('0xbd')})[_0x5c63('0x20')](function(_0x390545){_0x55bc3b=_0x390545;});}})[_0x5c63('0x28')](function(_0x2bdeaf){_0x4654e1=0x1f4;logger[_0x5c63('0x24')](_0x2bdeaf[_0x5c63('0xbe')]);if(_0x2bdeaf[_0x5c63('0x39')]){delete _0x2bdeaf[_0x5c63('0x39')];}_0x55bc3b=_0x2bdeaf;})[_0x5c63('0xbf')](function(){if(_0x55bc3b===null){_0x18226a[_0x5c63('0x29')](_0x4654e1);}else{if(_0x4654e1===0x1f4){_0x18226a[_0x5c63('0x2a')](_0x4654e1)[_0x5c63('0x3a')](_0x55bc3b);}else{_0x18226a[_0x5c63('0x2a')](_0x4654e1)[_0x5c63('0x2c')](_0x55bc3b);}}});};exports['getApplications']=function(_0xfce784,_0x3be54b,_0x3462b8){var _0x569dc1={};var _0x574b6c={};var _0x2224a;var _0x39850e;return db['SmsAccount'][_0x5c63('0x6b')]({'where':{'id':_0xfce784[_0x5c63('0x53')]['id']}})[_0x5c63('0x20')](handleEntityNotFound(_0x3be54b,null))[_0x5c63('0x20')](function(_0x56e22a){if(_0x56e22a){_0x2224a=_0x56e22a;_0x574b6c['model']=_[_0x5c63('0x54')](db[_0x5c63('0x6f')][_0x5c63('0x3f')]);_0x574b6c[_0x5c63('0x42')]=_[_0x5c63('0x54')](_0xfce784['query']);_0x574b6c[_0x5c63('0x4c')]=_['intersection'](_0x574b6c[_0x5c63('0x41')],_0x574b6c[_0x5c63('0x42')]);_0x569dc1[_0x5c63('0x44')]=_[_0x5c63('0x43')](_0x574b6c[_0x5c63('0x41')],qs[_0x5c63('0x45')](_0xfce784[_0x5c63('0x42')][_0x5c63('0x45')]));_0x569dc1['attributes']=_0x569dc1[_0x5c63('0x44')][_0x5c63('0x46')]?_0x569dc1[_0x5c63('0x44')]:_0x574b6c[_0x5c63('0x41')];_0x569dc1[_0x5c63('0x49')]=qs['sort'](_0xfce784['query']['sort']);_0x569dc1[_0x5c63('0x4b')]=qs[_0x5c63('0x4c')](_[_0x5c63('0x4d')](_0xfce784[_0x5c63('0x42')],_0x574b6c['filters']));if(_0xfce784[_0x5c63('0x42')][_0x5c63('0x4e')]){_0x569dc1[_0x5c63('0x4b')]=_[_0x5c63('0x4f')](_0x569dc1[_0x5c63('0x4b')],{'$or':_[_0x5c63('0x3d')](_0x569dc1[_0x5c63('0x44')],function(_0x529618){var _0x138da3={};_0x138da3[_0x529618]={'$like':'%'+_0xfce784['query']['filter']+'%'};return _0x138da3;})});}_0x569dc1=_[_0x5c63('0x4f')]({},_0x569dc1,_0xfce784[_0x5c63('0x50')]);return _0x2224a[_0x5c63('0xc0')](_0x569dc1);}})['then'](function(_0x1edebb){if(_0x1edebb){_0x39850e=_0x1edebb['length'];if(!_0xfce784['query']['hasOwnProperty'](_0x5c63('0x48'))){_0x569dc1[_0x5c63('0x2f')]=qs[_0x5c63('0x2f')](_0xfce784['query']['limit']);_0x569dc1[_0x5c63('0x2d')]=qs[_0x5c63('0x2d')](_0xfce784[_0x5c63('0x42')][_0x5c63('0x2d')]);}return _0x2224a[_0x5c63('0xc0')](_0x569dc1);}})['then'](function(_0x5596df){if(_0x5596df){return _0x5596df?{'count':_0x39850e,'rows':_0x5596df}:null;}})['then'](respondWithResult(_0x3be54b,null))[_0x5c63('0x28')](handleError(_0x3be54b,null));};exports[_0x5c63('0xc1')]=function(_0x4d882f,_0x3dc3e2,_0x30508c){var _0x109590={'raw':![],'where':{}};var _0x332abf={};var _0x3901f3={'count':0x0,'rows':[]};return db[_0x5c63('0x3e')][_0x5c63('0x6b')]({'where':{'id':_0x4d882f['params']['id']}})[_0x5c63('0x20')](handleEntityNotFound(_0x3dc3e2,null))[_0x5c63('0x20')](function(_0x529cc5){if(_0x529cc5){_0x332abf[_0x5c63('0x41')]=_[_0x5c63('0x54')](db['SmsInteraction'][_0x5c63('0x3f')]);_0x332abf[_0x5c63('0x42')]=_[_0x5c63('0x54')](_0x4d882f[_0x5c63('0x42')]);_0x332abf['filters']=_[_0x5c63('0x43')](_0x332abf[_0x5c63('0x41')],_0x332abf[_0x5c63('0x42')]);_0x109590['attributes']=_[_0x5c63('0x43')](_0x332abf['model'],qs[_0x5c63('0x45')](_0x4d882f[_0x5c63('0x42')][_0x5c63('0x45')]));_0x109590[_0x5c63('0x44')]=_0x109590[_0x5c63('0x44')][_0x5c63('0x46')]?_0x109590[_0x5c63('0x44')]:_0x332abf[_0x5c63('0x41')];if(!_0x4d882f['query'][_0x5c63('0x47')](_0x5c63('0x48'))){_0x109590[_0x5c63('0x2f')]=qs['limit'](_0x4d882f[_0x5c63('0x42')]['limit']);_0x109590[_0x5c63('0x2d')]=qs[_0x5c63('0x2d')](_0x4d882f['query'][_0x5c63('0x2d')]);}_0x109590[_0x5c63('0x49')]=qs['sort'](_0x4d882f[_0x5c63('0x42')][_0x5c63('0x4a')]);_0x109590[_0x5c63('0x4b')]=qs['filters'](_[_0x5c63('0x4d')](_0x4d882f[_0x5c63('0x42')],_0x332abf[_0x5c63('0x4c')]));_0x109590[_0x5c63('0x4b')][_0x5c63('0x63')]=_0x529cc5['id'];if(_0x4d882f[_0x5c63('0x42')][_0x5c63('0x4e')]){_0x109590['where']=_[_0x5c63('0x4f')](_0x109590[_0x5c63('0x4b')],{'$or':_[_0x5c63('0x3d')](_0x109590[_0x5c63('0x44')],function(_0xf90fcf){var _0x23ae34={};_0x23ae34[_0xf90fcf]={'$like':'%'+_0x4d882f[_0x5c63('0x42')]['filter']+'%'};return _0x23ae34;})});}_0x109590=_[_0x5c63('0x4f')]({},_0x109590,_0x4d882f['options']);return db[_0x5c63('0x9c')][_0x5c63('0x30')]({'where':_0x109590[_0x5c63('0x4b')]})['then'](function(_0x12c7dc){_0x3901f3[_0x5c63('0x30')]=_0x12c7dc;if(_0x4d882f[_0x5c63('0x42')]['includeAll']){_0x109590[_0x5c63('0x51')]=[{'model':db['CmContact'],'as':'Contact','required':![]},{'model':db['User'],'as':_0x5c63('0xc2'),'attributes':[_0x5c63('0x39'),_0x5c63('0xc3'),_0x5c63('0xc4')],'required':![]},{'model':db['Tag'],'as':_0x5c63('0xc5'),'attributes':['id','name',_0x5c63('0xc6')],'where':_0x4d882f[_0x5c63('0x42')][_0x5c63('0xc7')]?{'id':_0x4d882f[_0x5c63('0x42')][_0x5c63('0xc7')]}:undefined,'required':_0x4d882f[_0x5c63('0x42')][_0x5c63('0xc7')]?!![]:![]}];}return db['SmsInteraction'][_0x5c63('0x66')](_0x109590);})[_0x5c63('0x20')](function(_0x30e629){_0x3901f3['rows']=_0x30e629;return _0x3901f3;});}})['then'](respondWithFilteredResult(_0x3dc3e2,_0x109590))['catch'](handleError(_0x3dc3e2,null));};exports[_0x5c63('0x3a')]=function(_0x15402e,_0x1bb296,_0x1a131d){var _0x58ce24,_0x364b2b,_0xf6a530;if(_[_0x5c63('0x91')](_0x15402e[_0x5c63('0x58')][_0x5c63('0x58')])||_0x15402e['body']['body']===''){throw new db[(_0x5c63('0x76'))]['ValidationError'](_0x5c63('0x94'));}if(_['isNil'](_0x15402e['body']['to'])){throw new db['Sequelize'][(_0x5c63('0x92'))]('to\x20is\x20mandatory');}_0x58ce24=_0x15402e[_0x5c63('0x58')]['to'];return db[_0x5c63('0x3e')][_0x5c63('0x56')]({'where':{'id':_0x15402e[_0x5c63('0x53')]['id']},'include':[{'model':db[_0x5c63('0x98')],'as':_0x5c63('0xc8'),'include':[{'model':db['CmContact'],'as':_0x5c63('0x99'),'where':{'mobile':_0x58ce24},'limit':0x1,'order':[[_0x5c63('0x79'),'DESC']]}]}]})[_0x5c63('0x20')](handleEntityNotFound(_0x1bb296,null))['then'](function(_0x550bfe){if(_0x550bfe&&_0x550bfe[_0x5c63('0xc8')]){_0x364b2b=_0x550bfe['get']({'plain':!![]});if(_0x364b2b['List']&&_0x364b2b[_0x5c63('0xc8')]['Contacts'][_0x5c63('0x46')]){return _0x364b2b['List'][_0x5c63('0x99')][0x0];}return db[_0x5c63('0x75')][_0x5c63('0x57')](_[_0x5c63('0x19')](_0x15402e[_0x5c63('0x58')],{'firstName':_0x58ce24,'mobile':_0x58ce24,'phone':_0x58ce24,'ListId':_0x364b2b['ListId']}));}})[_0x5c63('0x20')](handleEntityNotFound(_0x1bb296,null))[_0x5c63('0x20')](function(_0x229f91){if(_0x229f91){_0xf6a530=_0x229f91;return db[_0x5c63('0x9c')]['find']({'where':{'ContactId':_0xf6a530['id'],'closed':![],'SmsAccountId':_0x364b2b['id']}})[_0x5c63('0x20')](function(_0x12bfdb){if(_0x12bfdb){return[_0x12bfdb,![]];}return db[_0x5c63('0x9c')][_0x5c63('0x57')]({'UserId':_0x15402e[_0x5c63('0x59')]['id'],'ContactId':_0xf6a530['id'],'SmsAccountId':_0x364b2b['id'],'phone':_0x58ce24,'firstMsgDirection':_0x5c63('0xc9'),'Messages':[_['merge'](_0x15402e[_0x5c63('0x58')],{'read':![],'body':_0x15402e['body'][_0x5c63('0x58')],'phone':_0x58ce24,'SmsAccountId':_0x364b2b['id'],'UserId':_0x15402e[_0x5c63('0x59')]['id'],'ContactId':_0xf6a530['id']})]},{'include':[{'model':db[_0x5c63('0xca')],'as':_0x5c63('0xcb')}]})[_0x5c63('0x20')](function(_0x311587){return[_0x311587,!![]];});});}})['spread'](function(_0x110e09,_0x456fb0){if(_0x456fb0){return _0x110e09;}return db[_0x5c63('0xca')][_0x5c63('0x57')](_[_0x5c63('0x4f')](_0x15402e[_0x5c63('0x58')],{'read':![],'body':_0x15402e[_0x5c63('0x58')][_0x5c63('0x58')],'phone':_0x58ce24,'SmsAccountId':_0x364b2b['id'],'SmsInteractionId':_0x110e09['id'],'UserId':_0x15402e[_0x5c63('0x59')]['id'],'ContactId':_0xf6a530['id']}))[_0x5c63('0x20')](function(_0x12af98){_0x110e09[_0x5c63('0xcc')][_0x5c63('0xcb')]=[];_0x110e09[_0x5c63('0xcc')][_0x5c63('0xcb')][_0x5c63('0xa1')](_0x12af98[_0x5c63('0xcc')]);return _0x110e09;});})[_0x5c63('0x20')](respondWithResult(_0x1bb296,null))['catch'](handleError(_0x1bb296,null));};exports[_0x5c63('0x2a')]=function(_0x320591,_0x117365,_0x25ed18){if(_0x320591[_0x5c63('0x58')]['id']){delete _0x320591['body']['id'];}var _0x3e57db,_0x2c1a66,_0x180e9a;return db['SmsAccount'][_0x5c63('0x56')]({'where':{'id':_0x320591['params']['id']}})[_0x5c63('0x20')](handleEntityNotFound(_0x117365,null))[_0x5c63('0x20')](function(_0x1d15b7){if(_0x1d15b7){_0x180e9a=_0x1d15b7;logger['debug'](_0x5c63('0xae'),_0x5c63('0x2a'),_0x5c63('0xcd'),_0x1d15b7[_0x5c63('0x40')],util[_0x5c63('0xce')](_0x320591['body'],{'showHidden':![],'depth':null}));switch(_0x1d15b7[_0x5c63('0x40')]){case _0x5c63('0x81'):if(_0x320591[_0x5c63('0x58')]['skebby_dispatch_id']&&_0x320591['body'][_0x5c63('0x2a')]){_0x2c1a66=_0x320591[_0x5c63('0x58')][_0x5c63('0x2a')];return db[_0x5c63('0xca')][_0x5c63('0x56')]({'where':{'messageId':_0x320591['body'][_0x5c63('0xcf')]}});}break;case'connectel':if(_0x320591['body'][_0x5c63('0xd0')]&&_0x320591[_0x5c63('0x58')][_0x5c63('0xd1')]){_0x2c1a66=_0x320591['body'][_0x5c63('0xd1')];return db[_0x5c63('0xca')]['find']({'where':{'messageId':_0x320591[_0x5c63('0x58')]['requestid']}});}break;case _0x5c63('0x85'):if(_0x320591[_0x5c63('0x58')]['message_id']&&_0x320591[_0x5c63('0x58')]['status_code']){_0x2c1a66=_0x320591['body'][_0x5c63('0xd2')];return db['SmsMessage'][_0x5c63('0x56')]({'where':{'messageId':_0x320591['body']['message_id']}});}break;case _0x5c63('0x89'):var _0xa58159=_0x320591[_0x5c63('0x58')]['results'][0x0];if(_0xa58159[_0x5c63('0x7f')]&&_0xa58159[_0x5c63('0x2a')][_0x5c63('0xd3')]===_0x5c63('0xd4')){_0x2c1a66=_0xa58159[_0x5c63('0x2a')][_0x5c63('0xd3')];return db['SmsMessage']['find']({'where':{'messageId':_0xa58159[_0x5c63('0x7f')]}});}break;case _0x5c63('0x8d'):if(_0x320591[_0x5c63('0x58')][_0x5c63('0x7f')]&&_0x320591['body']['status']){_0x2c1a66=_0x320591['body'][_0x5c63('0x2a')];return db['SmsMessage'][_0x5c63('0x56')]({'where':{'messageId':_0x320591['body'][_0x5c63('0x7f')]}});}break;case _0x5c63('0xd5'):if(_0x320591[_0x5c63('0x58')][0x0]['message']['id']){_0x2c1a66=_0x320591['body'][0x0][_0x5c63('0x40')];return db[_0x5c63('0xca')][_0x5c63('0x56')]({'where':{'messageId':_0x320591[_0x5c63('0x58')][0x0][_0x5c63('0x26')]['id']}});}break;case _0x5c63('0x90'):if(_0x320591[_0x5c63('0x58')][_0x5c63('0xd6')]&&_0x320591[_0x5c63('0x58')]['status']){_0x2c1a66=_0x320591[_0x5c63('0x58')][_0x5c63('0x2a')];return db[_0x5c63('0xca')]['find']({'where':{'messageId':_0x320591[_0x5c63('0x58')]['redif']}});}break;}}})[_0x5c63('0x20')](handleEntityNotFound(_0x117365,null))[_0x5c63('0x20')](function(_0x4defc0){if(_0x4defc0){_0x3e57db=_0x4defc0;switch(_0x180e9a[_0x5c63('0x40')]){case _0x5c63('0x81'):if(_0x2c1a66==='DELIVERED'){return _0x3e57db[_0x5c63('0x34')]({'read':!![]});}else{logger[_0x5c63('0x24')](_0x5c63('0xae'),_0x5c63('0x2a'),_0x5c63('0x81'),util[_0x5c63('0xce')](_0x320591[_0x5c63('0x58')],{'showHidden':![],'depth':null}));}break;case _0x5c63('0x84'):if(_0x2c1a66==='1'){return _0x3e57db['update']({'read':!![]});}else{logger[_0x5c63('0x24')](_0x5c63('0xae'),'status',_0x5c63('0x81'),util['inspect'](_0x320591['body'],{'showHidden':![],'depth':null}));}break;case _0x5c63('0x85'):if(!_0x320591[_0x5c63('0x58')][_0x5c63('0xd7')]&&_0x2c1a66>=0xc8&&_0x2c1a66<=0xce){return _0x3e57db[_0x5c63('0x34')]({'read':!![]});}else{logger[_0x5c63('0x24')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x5c63('0x2a'),_0x5c63('0x85'),util[_0x5c63('0xce')](_0x320591[_0x5c63('0x58')],{'showHidden':![],'depth':null}));}break;case'infobip':var _0x5bb1bf=_0x320591['body'][_0x5c63('0x8a')][0x0];if(_0x5bb1bf[_0x5c63('0x2a')]['groupName']===_0x5c63('0xd4')){return _0x3e57db[_0x5c63('0x34')]({'read':!![]});}else{logger[_0x5c63('0x24')](_0x5c63('0xae'),_0x5c63('0x2a'),_0x5c63('0x89'),util[_0x5c63('0xce')](_0x320591['body'],{'showHidden':![],'depth':null}));}break;case _0x5c63('0x8d'):if(_0x2c1a66==_0x5c63('0xd8')||_0x2c1a66==_0x5c63('0xd9')){return _0x3e57db[_0x5c63('0x34')]({'read':!![]});}else{logger[_0x5c63('0x24')]('SmsAccount,\x20%s,\x20%s,\x20%s','status',_0x5c63('0x8d'),util['inspect'](_0x320591[_0x5c63('0x58')],{'showHidden':![],'depth':null}));}break;case _0x5c63('0xd5'):if(_0x2c1a66==_0x5c63('0xda')){return _0x3e57db[_0x5c63('0x34')]({'read':!![]});}else{logger[_0x5c63('0x24')](_0x5c63('0xae'),_0x5c63('0x2a'),_0x5c63('0xd5'),util[_0x5c63('0xce')](_0x320591[_0x5c63('0x58')],{'showHidden':![],'depth':null}));}break;case _0x5c63('0x90'):if(_0x2c1a66===_0x5c63('0xdb')||_0x2c1a66===_0x5c63('0xdc')){return _0x3e57db['update']({'read':!![]});}else{logger[_0x5c63('0x24')]('SmsAccount,\x20%s,\x20%s,\x20%s','status','intelepeer',util[_0x5c63('0xce')](_0x320591[_0x5c63('0x58')],{'showHidden':![],'depth':null}));}break;}return _0x3e57db;}})[_0x5c63('0x20')](respondWithResult(_0x117365,null))[_0x5c63('0x28')](handleError(_0x117365,null));};exports['statusGet']=function(_0x1075f5,_0x365bb3,_0x46c4f4){var _0x103b63,_0x8b3030,_0x12fa50;return db['SmsAccount']['find']({'where':{'id':_0x1075f5['params']['id']}})[_0x5c63('0x20')](handleEntityNotFound(_0x365bb3,null))[_0x5c63('0x20')](function(_0x497741){if(_0x497741){_0x12fa50=_0x497741;logger[_0x5c63('0xdd')](_0x5c63('0xae'),_0x5c63('0x2a'),_0x5c63('0xcd'),_0x497741[_0x5c63('0x40')],util['inspect'](_0x1075f5['query'],{'showHidden':![],'depth':null}));switch(_0x497741['type']){case _0x5c63('0xde'):if(_0x1075f5['query'][_0x5c63('0xdf')]&&_0x1075f5[_0x5c63('0x42')][_0x5c63('0xe0')]){_0x8b3030=_0x1075f5[_0x5c63('0x42')][_0x5c63('0xe0')];return db[_0x5c63('0xca')]['find']({'where':{'messageId':_0x1075f5[_0x5c63('0x42')][_0x5c63('0xdf')]}});}break;}}})[_0x5c63('0x20')](handleEntityNotFound(_0x365bb3,null))[_0x5c63('0x20')](function(_0x4ac63c){if(_0x4ac63c){_0x103b63=_0x4ac63c;switch(_0x12fa50[_0x5c63('0x40')]){case'csc':if(_0x8b3030==='2'||_0x8b3030==='6'){return _0x103b63['update']({'read':!![]});}else{logger['error']('SmsAccount,\x20%s,\x20%s,\x20%s',_0x5c63('0x2a'),'csc',util[_0x5c63('0xce')](_0x1075f5[_0x5c63('0x42')],{'showHidden':![],'depth':null}));};break;}return _0x103b63;}})[_0x5c63('0x20')](respondWithResult(_0x365bb3,null))[_0x5c63('0x28')](handleError(_0x365bb3,null));};exports[_0x5c63('0xe1')]=function(_0x29ed61,_0x3bacb1,_0x46e313){return db['SmsAccount']['find']({'where':{'id':_0x29ed61['params']['id']}})[_0x5c63('0x20')](handleEntityNotFound(_0x3bacb1,null))[_0x5c63('0x20')](function(_0x3756b8){if(_0x3756b8){return _0x3756b8['addAgents'](_0x29ed61[_0x5c63('0x58')][_0x5c63('0x6d')],_[_0x5c63('0x9a')](_0x29ed61['body'],['ids','id'])||{})[_0x5c63('0x9d')](function(_0x5efc77){for(var _0x1bec57=0x0;_0x1bec57<_0x29ed61[_0x5c63('0x58')][_0x5c63('0x6d')]['length'];_0x1bec57+=0x1){socket['emit']('userSmsAccount:save',{'UserId':Number(_0x29ed61[_0x5c63('0x58')][_0x5c63('0x6d')][_0x1bec57]),'SmsAccountId':Number(_0x29ed61[_0x5c63('0x53')]['id'])});}return _0x5efc77;});}})['then'](respondWithResult(_0x3bacb1,null))[_0x5c63('0x28')](handleError(_0x3bacb1,null));};exports['removeAgents']=function(_0x585532,_0x57df43,_0x132e28){return db[_0x5c63('0x3e')][_0x5c63('0x56')]({'where':{'id':_0x585532['params']['id']}})[_0x5c63('0x20')](handleEntityNotFound(_0x57df43,null))[_0x5c63('0x20')](function(_0x143448){if(_0x143448){return _0x143448[_0x5c63('0xe2')](_0x585532[_0x5c63('0x42')]['ids'])[_0x5c63('0x20')](function(){if(_[_0x5c63('0xe3')](_0x585532[_0x5c63('0x42')][_0x5c63('0x6d')])){for(var _0x54a1f3=0x0;_0x54a1f3<_0x585532[_0x5c63('0x42')][_0x5c63('0x6d')][_0x5c63('0x46')];_0x54a1f3+=0x1){socket[_0x5c63('0xe4')](_0x5c63('0xe5'),{'UserId':Number(_0x585532[_0x5c63('0x42')][_0x5c63('0x6d')][_0x54a1f3]),'SmsAccountId':Number(_0x585532[_0x5c63('0x53')]['id'])});}}else{socket[_0x5c63('0xe4')](_0x5c63('0xe5'),{'UserId':Number(_0x585532['query'][_0x5c63('0x6d')]),'SmsAccountId':Number(_0x585532[_0x5c63('0x53')]['id'])});}});}})[_0x5c63('0x20')](respondWithStatusCode(_0x57df43,null))['catch'](handleError(_0x57df43,null));};exports[_0x5c63('0xe6')]=function(_0x36f98d,_0x16de52,_0x16b463){var _0x1430ea={};var _0x992eb6={};var _0x5ef289;var _0x5aa378;return db[_0x5c63('0x3e')][_0x5c63('0x6b')]({'where':{'id':_0x36f98d[_0x5c63('0x53')]['id']}})[_0x5c63('0x20')](handleEntityNotFound(_0x16de52,null))[_0x5c63('0x20')](function(_0x4ffb66){if(_0x4ffb66){_0x5ef289=_0x4ffb66;_0x992eb6[_0x5c63('0x41')]=_['keys'](db[_0x5c63('0xa4')][_0x5c63('0x3f')]);_0x992eb6[_0x5c63('0x42')]=_['keys'](_0x36f98d[_0x5c63('0x42')]);_0x992eb6[_0x5c63('0x4c')]=_[_0x5c63('0x43')](_0x992eb6['model'],_0x992eb6[_0x5c63('0x42')]);_0x1430ea['attributes']=_[_0x5c63('0x43')](_0x992eb6[_0x5c63('0x41')],qs[_0x5c63('0x45')](_0x36f98d[_0x5c63('0x42')]['fields']));_0x1430ea[_0x5c63('0x44')]=_0x1430ea[_0x5c63('0x44')]['length']?_0x1430ea[_0x5c63('0x44')]:_0x992eb6[_0x5c63('0x41')];_0x1430ea[_0x5c63('0x49')]=qs[_0x5c63('0x4a')](_0x36f98d[_0x5c63('0x42')][_0x5c63('0x4a')]);_0x1430ea['where']=qs[_0x5c63('0x4c')](_[_0x5c63('0x4d')](_0x36f98d[_0x5c63('0x42')],_0x992eb6[_0x5c63('0x4c')]));if(_0x36f98d[_0x5c63('0x42')][_0x5c63('0x4e')]){_0x1430ea[_0x5c63('0x4b')]=_[_0x5c63('0x4f')](_0x1430ea['where'],{'$or':_[_0x5c63('0x3d')](_0x1430ea[_0x5c63('0x44')],function(_0x1164cf){var _0x3b4aea={};_0x3b4aea[_0x1164cf]={'$like':'%'+_0x36f98d[_0x5c63('0x42')][_0x5c63('0x4e')]+'%'};return _0x3b4aea;})});}_0x1430ea=_[_0x5c63('0x4f')]({},_0x1430ea,_0x36f98d[_0x5c63('0x50')]);return _0x5ef289[_0x5c63('0xe6')](_0x1430ea);}})[_0x5c63('0x20')](function(_0x12ec4b){if(_0x12ec4b){_0x5aa378=_0x12ec4b['length'];if(!_0x36f98d[_0x5c63('0x42')][_0x5c63('0x47')](_0x5c63('0x48'))){_0x1430ea[_0x5c63('0x2f')]=qs[_0x5c63('0x2f')](_0x36f98d['query'][_0x5c63('0x2f')]);_0x1430ea[_0x5c63('0x2d')]=qs[_0x5c63('0x2d')](_0x36f98d[_0x5c63('0x42')][_0x5c63('0x2d')]);}return _0x5ef289[_0x5c63('0xe6')](_0x1430ea);}})['then'](function(_0x138c16){if(_0x138c16){return _0x138c16?{'count':_0x5aa378,'rows':_0x138c16}:null;}})[_0x5c63('0x20')](respondWithResult(_0x16de52,null))[_0x5c63('0x28')](handleError(_0x16de52,null));};
\ No newline at end of file