Built motion from commit (unavailable).|2.5.31
[motion2.git] / server / api / smsAccount / smsAccount.controller.js
index 6934984..a21c65f 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 _0x6bd6=['ejs','fs-extra','lodash','jsforce','to-csv','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','localhost','register','jayson/promise','client','http','then','info','request\x20sent','debug','SmsAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','SmsAccount,\x20%s,\x20%s','message','result','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','destroy','UserProfileResource','stack','name','send','Pause','map','SmsAccount','fieldName','type','key','model','keys','query','filters','intersection','attributes','fields','hasOwnProperty','nolimit','order','sort','pick','where','merge','filter','include','findAll','rows','catch','show','mandatoryDispositionPause','rawAttributes','length','create','body','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','SmsAccounts','UserProfileSection','find','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','describe','addDisposition','Disposition','getDispositions','findOne','SmsAccountId','options','removeDispositions','ids','addAnswer','CannedAnswer','removeAnswers','notify','sms','SmsApplication','Applications','account','applications','orderBy','priority','Sequelize','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','mobile','from','From','Body','skebby','text','connectel','messageId','message_id','plivo','MessageUUID','infobip','results','csc','originatingAddress','fromNumber','replyMessageId','bandwidth','intelepeer','refid','isNil','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','includes','mapKey','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','ListId','CmContact','Contacts','contact','SmsInteraction','spread','interaction','created','autoclose','push','close','unmanaged','*,*,*,*','SmsMessage','ContactId','AttachmentId','UserId','User','agent','startRouting','Start','receiveMessage','entity\x20found','SmsAccount,\x20%s,\x20%s,\x20%s,\x20%s','Content-Type','text/xml','<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>','addApplications','sequelize','transaction','findAndCountAll','getApplications','getInteractions','includeAll','Contact','Owner','internal','Tag','color','tag','DESC','List','defaults','dataValues','Messages','received\x20delivery\x20report\x20from','inspect','skebby_dispatch_id','requestid','statusInt','status_code','DELIVERED','groupName','clickatell','redif','clicksend','DELIVERED_TO_GATEWAY','RECEIVED_BY_RECIPIENT','message-delivered','DELIVRD','ACCEPTD','statusGet','message-id','state','addAgents','omit','userSmsAccount:save','removeAgents','emit','userSmsAccount:remove','getAgents','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','path'];(function(_0x39c734,_0x2f3e06){var _0xb2a2f9=function(_0x502f3f){while(--_0x502f3f){_0x39c734['push'](_0x39c734['shift']());}};_0xb2a2f9(++_0x2f3e06);}(_0x6bd6,0xda));var _0x66bd=function(_0xea81a1,_0xb28e9e){_0xea81a1=_0xea81a1-0x0;var _0x2cd030=_0x6bd6[_0xea81a1];return _0x2cd030;};'use strict';var emlformat=require(_0x66bd('0x0'));var rimraf=require(_0x66bd('0x1'));var zipdir=require(_0x66bd('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x66bd('0x3'));var moment=require(_0x66bd('0x4'));var BPromise=require(_0x66bd('0x5'));var Mustache=require(_0x66bd('0x6'));var util=require(_0x66bd('0x7'));var path=require(_0x66bd('0x8'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x66bd('0x9'));var fs=require('fs');var fs_extra=require(_0x66bd('0xa'));var _=require(_0x66bd('0xb'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x66bd('0xc'));var deskjs=require('desk.js');var toCsv=require(_0x66bd('0xd'));var querystring=require('querystring');var Papa=require(_0x66bd('0xe'));var Redis=require(_0x66bd('0xf'));var authService=require(_0x66bd('0x10'));var qs=require(_0x66bd('0x11'));var as=require(_0x66bd('0x12'));var hardwareService=require(_0x66bd('0x13'));var logger=require(_0x66bd('0x14'))('api');var utils=require(_0x66bd('0x15'));var config=require(_0x66bd('0x16'));var licenseUtil=require(_0x66bd('0x17'));var db=require(_0x66bd('0x18'))['db'];config['redis']=_['defaults'](config[_0x66bd('0x19')],{'host':_0x66bd('0x1a'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x66bd('0x19')]));require('./smsAccount.socket')[_0x66bd('0x1b')](socket);var jayson=require(_0x66bd('0x1c'));var client=jayson[_0x66bd('0x1d')][_0x66bd('0x1e')]({'port':0x232c});function respondWithRpcPromise(_0x1eb8ba,_0x327b14,_0x4ed1a7,_0x15b087){return new BPromise(function(_0xe96ffe,_0x466ac7){var _0x3e4b74=_0x15b087||client;return _0x3e4b74['request'](_0x1eb8ba,_0x4ed1a7)[_0x66bd('0x1f')](function(_0xedba23){logger[_0x66bd('0x20')]('SmsAccount,\x20%s,\x20%s',_0x327b14,_0x66bd('0x21'));logger[_0x66bd('0x22')](_0x66bd('0x23'),_0x327b14,_0x66bd('0x21'),JSON[_0x66bd('0x24')](_0xedba23));if(_0xedba23[_0x66bd('0x25')]){if(_0xedba23[_0x66bd('0x25')][_0x66bd('0x26')]===0x1f4){logger[_0x66bd('0x25')](_0x66bd('0x27'),_0x327b14,_0xedba23[_0x66bd('0x25')]['message']);return _0x466ac7(_0xedba23[_0x66bd('0x25')][_0x66bd('0x28')]);}logger[_0x66bd('0x25')]('SmsAccount,\x20%s,\x20%s',_0x327b14,_0xedba23[_0x66bd('0x25')][_0x66bd('0x28')]);return _0xe96ffe(_0xedba23[_0x66bd('0x25')][_0x66bd('0x28')]);}else{logger[_0x66bd('0x20')]('SmsAccount,\x20%s,\x20%s',_0x327b14,_0x66bd('0x21'));_0xe96ffe(_0xedba23[_0x66bd('0x29')][_0x66bd('0x28')]);}})['catch'](function(_0x3d3cfb){logger[_0x66bd('0x25')](_0x66bd('0x27'),_0x327b14,_0x3d3cfb);_0x466ac7(_0x3d3cfb);});});}function respondWithStatusCode(_0x38fd52,_0x4bc7cd){_0x4bc7cd=_0x4bc7cd||0xcc;return function(_0x59ed24){if(_0x59ed24){return _0x38fd52[_0x66bd('0x2a')](_0x4bc7cd);}return _0x38fd52[_0x66bd('0x2b')](_0x4bc7cd)[_0x66bd('0x2c')]();};}function respondWithResult(_0x236a30,_0x2023ed){_0x2023ed=_0x2023ed||0xc8;return function(_0x35c49d){if(_0x35c49d){return _0x236a30[_0x66bd('0x2b')](_0x2023ed)[_0x66bd('0x2d')](_0x35c49d);}};}function respondWithFilteredResult(_0x685c87,_0x46bafb){return function(_0x4b32bd){if(_0x4b32bd){var _0x19b428=typeof _0x46bafb[_0x66bd('0x2e')]===_0x66bd('0x2f')&&typeof _0x46bafb[_0x66bd('0x30')]===_0x66bd('0x2f');var _0xe24c69=_0x4b32bd['count'];var _0x57ccee=_0x19b428?0x0:_0x46bafb[_0x66bd('0x2e')];var _0x50744b=_0x19b428?_0x4b32bd[_0x66bd('0x31')]:_0x46bafb[_0x66bd('0x2e')]+_0x46bafb[_0x66bd('0x30')];var _0xd5e7dc;if(_0x50744b>=_0xe24c69){_0x50744b=_0xe24c69;_0xd5e7dc=0xc8;}else{_0xd5e7dc=0xce;}_0x685c87['status'](_0xd5e7dc);return _0x685c87[_0x66bd('0x32')](_0x66bd('0x33'),_0x57ccee+'-'+_0x50744b+'/'+_0xe24c69)[_0x66bd('0x2d')](_0x4b32bd);}return null;};}function patchUpdates(_0x356118){return function(_0x2f14e5){try{jsonpatch[_0x66bd('0x34')](_0x2f14e5,_0x356118,!![]);}catch(_0x92203a){return BPromise[_0x66bd('0x35')](_0x92203a);}return _0x2f14e5[_0x66bd('0x36')]();};}function saveUpdates(_0x56a28d,_0x18c645){return function(_0x540486){if(_0x540486){return _0x540486[_0x66bd('0x37')](_0x56a28d)[_0x66bd('0x1f')](function(_0x343757){return _0x343757;});}return null;};}function removeEntity(_0x283cf7,_0x39c5fe){return function(_0x3aa5b6){if(_0x3aa5b6){return _0x3aa5b6[_0x66bd('0x38')]()[_0x66bd('0x1f')](function(){var _0x856ca5=_0x3aa5b6['get']({'plain':!![]});var _0xa8a195='SmsAccounts';return db[_0x66bd('0x39')][_0x66bd('0x38')]({'where':{'type':_0xa8a195,'resourceId':_0x856ca5['id']}})[_0x66bd('0x1f')](function(){return _0x3aa5b6;});})[_0x66bd('0x1f')](function(){_0x283cf7[_0x66bd('0x2b')](0xcc)[_0x66bd('0x2c')]();});}};}function handleEntityNotFound(_0x4c42,_0x35e1ba){return function(_0x403c1c){if(!_0x403c1c){_0x4c42['sendStatus'](0x194);}return _0x403c1c;};}function handleError(_0x566ece,_0x588082){_0x588082=_0x588082||0x1f4;return function(_0x20c686){logger[_0x66bd('0x25')](_0x20c686[_0x66bd('0x3a')]);if(_0x20c686[_0x66bd('0x3b')]){delete _0x20c686[_0x66bd('0x3b')];}_0x566ece[_0x66bd('0x2b')](_0x588082)[_0x66bd('0x3c')](_0x20c686);};}exports['index']=function(_0x585201,_0x477e78){var _0x16eb0c={'include':[{'model':db[_0x66bd('0x3d')],'as':'mandatoryDispositionPause'}]},_0x1a9585={},_0x43f3af={'count':0x0,'rows':[]};var _0x9e6b20=_[_0x66bd('0x3e')](db[_0x66bd('0x3f')]['rawAttributes'],function(_0x49d7b0){return{'name':_0x49d7b0[_0x66bd('0x40')],'type':_0x49d7b0[_0x66bd('0x41')][_0x66bd('0x42')]};});_0x1a9585[_0x66bd('0x43')]=_[_0x66bd('0x3e')](_0x9e6b20,_0x66bd('0x3b'));_0x1a9585['query']=_[_0x66bd('0x44')](_0x585201[_0x66bd('0x45')]);_0x1a9585[_0x66bd('0x46')]=_[_0x66bd('0x47')](_0x1a9585[_0x66bd('0x43')],_0x1a9585[_0x66bd('0x45')]);_0x16eb0c[_0x66bd('0x48')]=_[_0x66bd('0x47')](_0x1a9585[_0x66bd('0x43')],qs[_0x66bd('0x49')](_0x585201[_0x66bd('0x45')][_0x66bd('0x49')]));_0x16eb0c[_0x66bd('0x48')]=_0x16eb0c[_0x66bd('0x48')]['length']?_0x16eb0c[_0x66bd('0x48')]:_0x1a9585[_0x66bd('0x43')];if(!_0x585201[_0x66bd('0x45')][_0x66bd('0x4a')](_0x66bd('0x4b'))){_0x16eb0c[_0x66bd('0x30')]=qs[_0x66bd('0x30')](_0x585201[_0x66bd('0x45')][_0x66bd('0x30')]);_0x16eb0c['offset']=qs[_0x66bd('0x2e')](_0x585201[_0x66bd('0x45')]['offset']);}_0x16eb0c[_0x66bd('0x4c')]=qs[_0x66bd('0x4d')](_0x585201[_0x66bd('0x45')][_0x66bd('0x4d')]);_0x16eb0c['where']=qs['filters'](_[_0x66bd('0x4e')](_0x585201['query'],_0x1a9585['filters']),_0x9e6b20);if(_0x585201[_0x66bd('0x45')]['filter']){_0x16eb0c[_0x66bd('0x4f')]=_[_0x66bd('0x50')](_0x16eb0c[_0x66bd('0x4f')],{'$or':_[_0x66bd('0x3e')](_0x9e6b20,function(_0x4be6f9){if(_0x4be6f9[_0x66bd('0x41')]!=='VIRTUAL'){var _0x417a3a={};_0x417a3a[_0x4be6f9['name']]={'$like':'%'+_0x585201['query'][_0x66bd('0x51')]+'%'};return _0x417a3a;}})});}_0x16eb0c=_['merge']({},_0x16eb0c,_0x585201['options']);var _0x4d23ad={'where':_0x16eb0c[_0x66bd('0x4f')]};return db[_0x66bd('0x3f')]['count'](_0x4d23ad)[_0x66bd('0x1f')](function(_0x324584){_0x43f3af[_0x66bd('0x31')]=_0x324584;if(_0x585201[_0x66bd('0x45')]['includeAll']){_0x16eb0c[_0x66bd('0x52')]=[{'all':!![]}];}return db['SmsAccount'][_0x66bd('0x53')](_0x16eb0c);})[_0x66bd('0x1f')](function(_0x5e05e6){_0x43f3af[_0x66bd('0x54')]=_0x5e05e6;return _0x43f3af;})['then'](respondWithFilteredResult(_0x477e78,_0x16eb0c))[_0x66bd('0x55')](handleError(_0x477e78,null));};exports[_0x66bd('0x56')]=function(_0x59875a,_0x5d3eef){var _0x3e1819={'raw':![],'where':{'id':_0x59875a['params']['id']},'include':[{'model':db[_0x66bd('0x3d')],'as':_0x66bd('0x57')}]},_0x44bc15={};_0x44bc15[_0x66bd('0x43')]=_[_0x66bd('0x44')](db['SmsAccount'][_0x66bd('0x58')]);_0x44bc15[_0x66bd('0x45')]=_[_0x66bd('0x44')](_0x59875a[_0x66bd('0x45')]);_0x44bc15[_0x66bd('0x46')]=_[_0x66bd('0x47')](_0x44bc15[_0x66bd('0x43')],_0x44bc15['query']);_0x3e1819[_0x66bd('0x48')]=_[_0x66bd('0x47')](_0x44bc15[_0x66bd('0x43')],qs[_0x66bd('0x49')](_0x59875a[_0x66bd('0x45')][_0x66bd('0x49')]));_0x3e1819['attributes']=_0x3e1819['attributes'][_0x66bd('0x59')]?_0x3e1819[_0x66bd('0x48')]:_0x44bc15[_0x66bd('0x43')];if(_0x59875a[_0x66bd('0x45')]['includeAll']){_0x3e1819[_0x66bd('0x52')]=[{'all':!![]}];}_0x3e1819=_['merge']({},_0x3e1819,_0x59875a['options']);return db[_0x66bd('0x3f')]['find'](_0x3e1819)[_0x66bd('0x1f')](handleEntityNotFound(_0x5d3eef,null))['then'](respondWithResult(_0x5d3eef,null))['catch'](handleError(_0x5d3eef,null));};exports['create']=function(_0x574504,_0x24f76a){return db[_0x66bd('0x3f')][_0x66bd('0x5a')](_0x574504[_0x66bd('0x5b')],{})[_0x66bd('0x1f')](function(_0x5c2076){var _0x3040d8=_0x574504[_0x66bd('0x5c')][_0x66bd('0x5d')]({'plain':!![]});if(!_0x3040d8)throw new Error(_0x66bd('0x5e'));if(_0x3040d8[_0x66bd('0x5f')]===_0x66bd('0x5c')){var _0x55a5c4=_0x5c2076[_0x66bd('0x5d')]({'plain':!![]});var _0x4c087a=_0x66bd('0x60');return db[_0x66bd('0x61')][_0x66bd('0x62')]({'where':{'name':_0x4c087a,'userProfileId':_0x3040d8[_0x66bd('0x63')]},'raw':!![]})[_0x66bd('0x1f')](function(_0x18b769){if(_0x18b769&&_0x18b769[_0x66bd('0x64')]===0x0){return db['UserProfileResource'][_0x66bd('0x5a')]({'name':_0x55a5c4['name'],'resourceId':_0x55a5c4['id'],'type':_0x18b769[_0x66bd('0x3b')],'sectionId':_0x18b769['id']},{})[_0x66bd('0x1f')](function(){return _0x5c2076;});}else{return _0x5c2076;}})[_0x66bd('0x55')](function(_0x483fc8){logger['error'](_0x66bd('0x65'),_0x483fc8);throw _0x483fc8;});}return _0x5c2076;})[_0x66bd('0x1f')](respondWithResult(_0x24f76a,0xc9))[_0x66bd('0x55')](handleError(_0x24f76a,null));};exports['update']=function(_0x1a64cc,_0x34aaa0){if(_0x1a64cc[_0x66bd('0x5b')]['id']){delete _0x1a64cc['body']['id'];}return db[_0x66bd('0x3f')][_0x66bd('0x62')]({'where':{'id':_0x1a64cc[_0x66bd('0x66')]['id']},'include':[{'model':db[_0x66bd('0x3d')],'as':_0x66bd('0x57')}]})[_0x66bd('0x1f')](handleEntityNotFound(_0x34aaa0,null))[_0x66bd('0x1f')](saveUpdates(_0x1a64cc['body'],null))['then'](respondWithResult(_0x34aaa0,null))[_0x66bd('0x55')](handleError(_0x34aaa0,null));};exports[_0x66bd('0x38')]=function(_0x44e835,_0x579c25){return db['SmsAccount'][_0x66bd('0x62')]({'where':{'id':_0x44e835[_0x66bd('0x66')]['id']}})['then'](handleEntityNotFound(_0x579c25,null))[_0x66bd('0x1f')](removeEntity(_0x579c25,null))['catch'](handleError(_0x579c25,null));};exports['describe']=function(_0x2f00ef,_0x2be71c){return db[_0x66bd('0x3f')][_0x66bd('0x67')]()['then'](respondWithResult(_0x2be71c,null))['catch'](handleError(_0x2be71c,null));};exports[_0x66bd('0x68')]=function(_0x4f2618,_0x4e4af4,_0x1e15dc){if(_0x4f2618[_0x66bd('0x5b')]['id']){delete _0x4f2618[_0x66bd('0x5b')]['id'];}return db[_0x66bd('0x3f')][_0x66bd('0x62')]({'where':{'id':_0x4f2618[_0x66bd('0x66')]['id']}})[_0x66bd('0x1f')](handleEntityNotFound(_0x4e4af4,null))['then'](function(_0x10f296){if(_0x10f296){_0x4f2618[_0x66bd('0x5b')]['SmsAccountId']=_0x10f296['id'];return db[_0x66bd('0x69')][_0x66bd('0x5a')](_0x4f2618[_0x66bd('0x5b')]);}})['then'](respondWithResult(_0x4e4af4,null))['catch'](handleError(_0x4e4af4,null));};exports[_0x66bd('0x6a')]=function(_0x2b3a6d,_0x49d131,_0x28e502){var _0x18fa73={'raw':![],'where':{}};var _0x52d930={};var _0x4a7ff4={'count':0x0,'rows':[]};return db[_0x66bd('0x3f')][_0x66bd('0x6b')]({'where':{'id':_0x2b3a6d[_0x66bd('0x66')]['id']}})[_0x66bd('0x1f')](handleEntityNotFound(_0x49d131,null))[_0x66bd('0x1f')](function(_0x18ed8a){if(_0x18ed8a){_0x52d930['model']=_[_0x66bd('0x44')](db[_0x66bd('0x69')][_0x66bd('0x58')]);_0x52d930[_0x66bd('0x45')]=_[_0x66bd('0x44')](_0x2b3a6d['query']);_0x52d930[_0x66bd('0x46')]=_['intersection'](_0x52d930[_0x66bd('0x43')],_0x52d930['query']);_0x18fa73[_0x66bd('0x48')]=_['intersection'](_0x52d930[_0x66bd('0x43')],qs['fields'](_0x2b3a6d['query'][_0x66bd('0x49')]));_0x18fa73['attributes']=_0x18fa73[_0x66bd('0x48')]['length']?_0x18fa73[_0x66bd('0x48')]:_0x52d930[_0x66bd('0x43')];if(!_0x2b3a6d[_0x66bd('0x45')]['hasOwnProperty'](_0x66bd('0x4b'))){_0x18fa73[_0x66bd('0x30')]=qs[_0x66bd('0x30')](_0x2b3a6d[_0x66bd('0x45')][_0x66bd('0x30')]);_0x18fa73[_0x66bd('0x2e')]=qs['offset'](_0x2b3a6d[_0x66bd('0x45')]['offset']);}_0x18fa73[_0x66bd('0x4c')]=qs[_0x66bd('0x4d')](_0x2b3a6d[_0x66bd('0x45')][_0x66bd('0x4d')]);_0x18fa73[_0x66bd('0x4f')]=qs[_0x66bd('0x46')](_['pick'](_0x2b3a6d[_0x66bd('0x45')],_0x52d930[_0x66bd('0x46')]));_0x18fa73[_0x66bd('0x4f')][_0x66bd('0x6c')]=_0x18ed8a['id'];if(_0x2b3a6d[_0x66bd('0x45')][_0x66bd('0x51')]){_0x18fa73[_0x66bd('0x4f')]=_['merge'](_0x18fa73[_0x66bd('0x4f')],{'$or':_[_0x66bd('0x3e')](_0x18fa73[_0x66bd('0x48')],function(_0x5cc03c){var _0x3af3a1={};_0x3af3a1[_0x5cc03c]={'$like':'%'+_0x2b3a6d[_0x66bd('0x45')]['filter']+'%'};return _0x3af3a1;})});}_0x18fa73=_[_0x66bd('0x50')]({},_0x18fa73,_0x2b3a6d[_0x66bd('0x6d')]);return db[_0x66bd('0x69')][_0x66bd('0x31')]({'where':_0x18fa73[_0x66bd('0x4f')]})[_0x66bd('0x1f')](function(_0x41c9bc){_0x4a7ff4[_0x66bd('0x31')]=_0x41c9bc;if(_0x2b3a6d['query']['includeAll']){_0x18fa73[_0x66bd('0x52')]=[{'all':!![]}];}return db[_0x66bd('0x69')]['findAll'](_0x18fa73);})[_0x66bd('0x1f')](function(_0x537cc2){_0x4a7ff4[_0x66bd('0x54')]=_0x537cc2;return _0x4a7ff4;});}})[_0x66bd('0x1f')](respondWithFilteredResult(_0x49d131,_0x18fa73))[_0x66bd('0x55')](handleError(_0x49d131,null));};exports[_0x66bd('0x6e')]=function(_0x3907cd,_0x3d240c,_0x253cbb){return db[_0x66bd('0x3f')][_0x66bd('0x62')]({'where':{'id':_0x3907cd['params']['id']}})[_0x66bd('0x1f')](handleEntityNotFound(_0x3d240c,null))['then'](function(_0x1d8a8d){if(_0x1d8a8d){return _0x1d8a8d[_0x66bd('0x6e')](_0x3907cd['query'][_0x66bd('0x6f')]);}})[_0x66bd('0x1f')](respondWithStatusCode(_0x3d240c,null))[_0x66bd('0x55')](handleError(_0x3d240c,null));};exports[_0x66bd('0x70')]=function(_0x473086,_0x571457,_0x243e72){if(_0x473086['body']['id']){delete _0x473086[_0x66bd('0x5b')]['id'];}return db[_0x66bd('0x3f')][_0x66bd('0x62')]({'where':{'id':_0x473086[_0x66bd('0x66')]['id']}})['then'](handleEntityNotFound(_0x571457,null))['then'](function(_0x2f66e0){if(_0x2f66e0){_0x473086[_0x66bd('0x5b')][_0x66bd('0x6c')]=_0x2f66e0['id'];return db[_0x66bd('0x71')]['create'](_0x473086[_0x66bd('0x5b')]);}})[_0x66bd('0x1f')](respondWithResult(_0x571457,null))[_0x66bd('0x55')](handleError(_0x571457,null));};exports['getAnswers']=function(_0x479a8e,_0xe20b1e,_0x152897){var _0x213bbc={'raw':![],'where':{}};var _0x1a67dc={};var _0x1d467c={'count':0x0,'rows':[]};return db['SmsAccount'][_0x66bd('0x6b')]({'where':{'id':_0x479a8e[_0x66bd('0x66')]['id']}})[_0x66bd('0x1f')](handleEntityNotFound(_0xe20b1e,null))[_0x66bd('0x1f')](function(_0x41f414){if(_0x41f414){_0x1a67dc[_0x66bd('0x43')]=_[_0x66bd('0x44')](db['CannedAnswer'][_0x66bd('0x58')]);_0x1a67dc[_0x66bd('0x45')]=_[_0x66bd('0x44')](_0x479a8e['query']);_0x1a67dc[_0x66bd('0x46')]=_[_0x66bd('0x47')](_0x1a67dc[_0x66bd('0x43')],_0x1a67dc['query']);_0x213bbc[_0x66bd('0x48')]=_[_0x66bd('0x47')](_0x1a67dc[_0x66bd('0x43')],qs[_0x66bd('0x49')](_0x479a8e[_0x66bd('0x45')][_0x66bd('0x49')]));_0x213bbc['attributes']=_0x213bbc[_0x66bd('0x48')][_0x66bd('0x59')]?_0x213bbc[_0x66bd('0x48')]:_0x1a67dc[_0x66bd('0x43')];if(!_0x479a8e['query'][_0x66bd('0x4a')](_0x66bd('0x4b'))){_0x213bbc[_0x66bd('0x30')]=qs['limit'](_0x479a8e[_0x66bd('0x45')][_0x66bd('0x30')]);_0x213bbc[_0x66bd('0x2e')]=qs[_0x66bd('0x2e')](_0x479a8e[_0x66bd('0x45')][_0x66bd('0x2e')]);}_0x213bbc['order']=qs[_0x66bd('0x4d')](_0x479a8e['query'][_0x66bd('0x4d')]);_0x213bbc[_0x66bd('0x4f')]=qs[_0x66bd('0x46')](_['pick'](_0x479a8e[_0x66bd('0x45')],_0x1a67dc[_0x66bd('0x46')]));_0x213bbc[_0x66bd('0x4f')][_0x66bd('0x6c')]=_0x41f414['id'];if(_0x479a8e[_0x66bd('0x45')][_0x66bd('0x51')]){_0x213bbc[_0x66bd('0x4f')]=_[_0x66bd('0x50')](_0x213bbc['where'],{'$or':_[_0x66bd('0x3e')](_0x213bbc[_0x66bd('0x48')],function(_0x2372d9){var _0x1095c8={};_0x1095c8[_0x2372d9]={'$like':'%'+_0x479a8e[_0x66bd('0x45')][_0x66bd('0x51')]+'%'};return _0x1095c8;})});}_0x213bbc=_[_0x66bd('0x50')]({},_0x213bbc,_0x479a8e[_0x66bd('0x6d')]);return db[_0x66bd('0x71')]['count']({'where':_0x213bbc['where']})[_0x66bd('0x1f')](function(_0x3a64d1){_0x1d467c[_0x66bd('0x31')]=_0x3a64d1;if(_0x479a8e['query']['includeAll']){_0x213bbc[_0x66bd('0x52')]=[{'all':!![]}];}return db['CannedAnswer']['findAll'](_0x213bbc);})[_0x66bd('0x1f')](function(_0x24e2ff){_0x1d467c['rows']=_0x24e2ff;return _0x1d467c;});}})[_0x66bd('0x1f')](respondWithFilteredResult(_0xe20b1e,_0x213bbc))[_0x66bd('0x55')](handleError(_0xe20b1e,null));};exports[_0x66bd('0x72')]=function(_0x13e000,_0x285015,_0x2a66e0){return db['SmsAccount'][_0x66bd('0x62')]({'where':{'id':_0x13e000['params']['id']}})[_0x66bd('0x1f')](handleEntityNotFound(_0x285015,null))[_0x66bd('0x1f')](function(_0x4b4c05){if(_0x4b4c05){return _0x4b4c05[_0x66bd('0x72')](_0x13e000['query'][_0x66bd('0x6f')]);}})[_0x66bd('0x1f')](respondWithStatusCode(_0x285015,null))[_0x66bd('0x55')](handleError(_0x285015,null));};exports[_0x66bd('0x73')]=function(_0x1a2894,_0x509d5e,_0x32d989){var _0x3b02f2={'channel':_0x66bd('0x74')};var _0x182054=[];var _0x4818fd=[];var _0x29bc16={};return db['SmsAccount'][_0x66bd('0x62')]({'where':{'id':_0x1a2894[_0x66bd('0x66')]['id']},'include':[{'model':db[_0x66bd('0x75')],'as':_0x66bd('0x76')}]})['then'](handleEntityNotFound(_0x509d5e,null))['then'](function(_0x3f4475){_0x3b02f2[_0x66bd('0x77')]=_0x3f4475;_0x3b02f2[_0x66bd('0x78')]=_[_0x66bd('0x79')](_0x3f4475[_0x66bd('0x76')],[_0x66bd('0x7a')],['asc']);if(_0x3b02f2[_0x66bd('0x77')][_0x66bd('0x76')]){delete _0x3b02f2[_0x66bd('0x77')][_0x66bd('0x76')];}return db['CmContact'][_0x66bd('0x67')]();})[_0x66bd('0x1f')](function(_0x983900){if(!_0x983900){throw new db[(_0x66bd('0x7b'))][(_0x66bd('0x7c'))](_0x66bd('0x7d'));}_0x182054=_[_0x66bd('0x7e')](_[_0x66bd('0x44')](_0x983900),[_0x66bd('0x7f'),_0x66bd('0x80')]);_0x4818fd=_[_0x66bd('0x7e')](_['keys'](_0x983900),[_0x66bd('0x7f'),_0x66bd('0x80'),'CompanyId','ListId']);_0x3b02f2[_0x66bd('0x5b')]={'mapKey':_0x66bd('0x81')};if(_0x3b02f2[_0x66bd('0x77')][_0x66bd('0x41')]){switch(_0x3b02f2[_0x66bd('0x77')][_0x66bd('0x41')]){case'twilio':_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x82')]=_0x1a2894[_0x66bd('0x5b')][_0x66bd('0x83')];_0x3b02f2['body'][_0x66bd('0x5b')]=_0x1a2894[_0x66bd('0x5b')][_0x66bd('0x84')];_0x3b02f2[_0x66bd('0x5b')]['messageId']=_0x1a2894[_0x66bd('0x5b')]['MessageSid'];break;case _0x66bd('0x85'):_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x82')]='+'+_0x1a2894[_0x66bd('0x5b')]['sender'];_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x5b')]=_0x1a2894[_0x66bd('0x5b')][_0x66bd('0x86')];break;case _0x66bd('0x87'):_0x3b02f2[_0x66bd('0x5b')]['from']=_0x1a2894[_0x66bd('0x5b')][_0x66bd('0x82')];_0x3b02f2['body'][_0x66bd('0x5b')]=_0x1a2894[_0x66bd('0x5b')]['message'];break;case'clicksend':_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x82')]=_0x1a2894[_0x66bd('0x5b')]['from'];_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x5b')]=_0x1a2894[_0x66bd('0x5b')][_0x66bd('0x5b')];_0x3b02f2['body'][_0x66bd('0x88')]=_0x1a2894[_0x66bd('0x5b')][_0x66bd('0x89')];break;case _0x66bd('0x8a'):_0x3b02f2[_0x66bd('0x5b')]['from']=_0x1a2894[_0x66bd('0x5b')][_0x66bd('0x83')];_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x5b')]=_0x1a2894[_0x66bd('0x5b')]['Text'];_0x3b02f2[_0x66bd('0x5b')]['messageId']=_0x1a2894['body'][_0x66bd('0x8b')];break;case _0x66bd('0x8c'):_0x3b02f2[_0x66bd('0x5b')]['from']='+'+_0x1a2894[_0x66bd('0x5b')][_0x66bd('0x8d')][0x0][_0x66bd('0x82')];_0x3b02f2[_0x66bd('0x5b')]['body']=_0x1a2894[_0x66bd('0x5b')][_0x66bd('0x8d')][0x0]['text'];_0x3b02f2['body'][_0x66bd('0x88')]=_0x1a2894[_0x66bd('0x5b')][_0x66bd('0x8d')][0x0][_0x66bd('0x88')];break;case _0x66bd('0x8e'):_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x82')]=_0x1a2894[_0x66bd('0x5b')][_0x66bd('0x8f')];_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x5b')]=_0x1a2894[_0x66bd('0x5b')]['segmentedMessage'][_0x66bd('0x28')];break;case'clickatell':_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x82')]=_0x1a2894['body'][_0x66bd('0x90')];_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x5b')]=_0x1a2894[_0x66bd('0x5b')][_0x66bd('0x86')];_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x88')]=_0x1a2894[_0x66bd('0x5b')][_0x66bd('0x91')];break;case _0x66bd('0x92'):_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x88')]=_0x1a2894[_0x66bd('0x5b')][0x0]['message']['id'];_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x82')]=_0x1a2894[_0x66bd('0x5b')][0x0][_0x66bd('0x28')][_0x66bd('0x82')];_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x5b')]=_0x1a2894[_0x66bd('0x5b')][0x0][_0x66bd('0x28')]['text'];break;case _0x66bd('0x93'):_0x3b02f2['body']['from']=_0x1a2894['body']['from'];_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x5b')]=_0x1a2894[_0x66bd('0x5b')]['message'];_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x88')]=_0x1a2894[_0x66bd('0x5b')][_0x66bd('0x94')];break;}}if(_0x3b02f2['body']['id']){delete _0x3b02f2['body']['id'];}if(_[_0x66bd('0x95')](_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x82')])){throw new db[(_0x66bd('0x7b'))][(_0x66bd('0x7c'))](_0x66bd('0x96'));}if(_['isNil'](_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x5b')])||_0x3b02f2['body'][_0x66bd('0x5b')]===''){throw new db['Sequelize'][(_0x66bd('0x7c'))](_0x66bd('0x97'));}if(_[_0x66bd('0x95')](_0x3b02f2[_0x66bd('0x5b')]['mapKey'])){throw new db[(_0x66bd('0x7b'))]['ValidationError']('mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x4818fd);}if(!_[_0x66bd('0x98')](_0x4818fd,_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x99')])){throw new db[(_0x66bd('0x7b'))]['ValidationError'](_0x66bd('0x9a')+_0x4818fd);}_0x29bc16[_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x99')]]=_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x82')];return db[_0x66bd('0x9b')]['find']({'where':{'id':_0x3b02f2[_0x66bd('0x77')][_0x66bd('0x9c')]},'include':[{'model':db[_0x66bd('0x9d')],'as':_0x66bd('0x9e'),'where':_0x29bc16,'limit':0x1,'order':[[_0x66bd('0x80'),'DESC']]}]});})[_0x66bd('0x1f')](handleEntityNotFound(_0x509d5e,null))['then'](function(_0x5bb1d2){if(_0x5bb1d2){_0x3b02f2['list']=_['omit'](_0x5bb1d2,['Contacts']);if(_0x5bb1d2['Contacts']['length']){return _0x5bb1d2[_0x66bd('0x9e')][0x0];}var _0x24a129=_['defaults'](_0x3b02f2['body'],{'firstName':_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x82')],'ListId':_0x5bb1d2['id']});_0x24a129[_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x99')]]=_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x82')];return db[_0x66bd('0x9d')][_0x66bd('0x5a')](_0x24a129,{'fields':_0x182054,'raw':!![]});}})[_0x66bd('0x1f')](handleEntityNotFound(_0x509d5e,null))[_0x66bd('0x1f')](function(_0x1decfb){if(_0x1decfb){_0x3b02f2[_0x66bd('0x9f')]=_0x1decfb;var _0x27d5af={'ContactId':_0x1decfb['id'],'phone':_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x82')],'SmsAccountId':_0x1a2894['params']['id']};var _0x2ca589={'ContactId':_0x1decfb['id'],'SmsAccountId':_0x1a2894[_0x66bd('0x66')]['id'],'closed':![]};return db[_0x66bd('0xa0')][_0x66bd('0x62')]({'where':_0x2ca589})[_0x66bd('0x1f')](function(_0x41b882){if(_0x41b882){return[_0x41b882,![]];}return db['SmsInteraction']['create'](_0x27d5af)[_0x66bd('0x1f')](function(_0x2b5a67){return[_0x2b5a67,!![]];});});}})[_0x66bd('0xa1')](function(_0x4d0061,_0x17a9b3){_0x3b02f2[_0x66bd('0xa2')]=_0x4d0061[_0x66bd('0x5d')]({'plain':!![]});_0x3b02f2[_0x66bd('0xa2')][_0x66bd('0xa3')]=![];if(_0x17a9b3){if(_0x3b02f2['account'][_0x66bd('0xa4')]){_0x3b02f2[_0x66bd('0x78')][_0x66bd('0xa5')]({'id':0x0,'priority':_0x3b02f2[_0x66bd('0x78')][_0x66bd('0x59')]+0x1,'app':_0x66bd('0xa6'),'appdata':_0x66bd('0xa7'),'interval':_0x66bd('0xa8')});}_0x3b02f2[_0x66bd('0xa2')][_0x66bd('0xa3')]=!![];}return db[_0x66bd('0xa9')][_0x66bd('0x5a')]({'phone':_0x3b02f2['body'][_0x66bd('0x82')],'messageId':_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x88')],'body':_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x5b')],'SmsAccountId':_0x1a2894[_0x66bd('0x66')]['id'],'SmsInteractionId':_0x4d0061['id'],'direction':'in','ContactId':_0x4d0061[_0x66bd('0xaa')],'AttachmentId':_0x3b02f2['body'][_0x66bd('0xab')]});})['then'](function(_0x1db80a){_0x3b02f2[_0x66bd('0x28')]=_0x1db80a;if(_0x3b02f2[_0x66bd('0xa2')][_0x66bd('0xac')]){return db[_0x66bd('0xad')][_0x66bd('0x62')]({'attributes':['id',_0x66bd('0x3b')],'where':{'id':_0x3b02f2[_0x66bd('0xa2')][_0x66bd('0xac')]}})[_0x66bd('0x1f')](function(_0x4d0fd5){if(_0x4d0fd5){_0x3b02f2['applications']['unshift']({'id':0x0,'priority':0x0,'app':_0x66bd('0xae'),'appdata':_0x4d0fd5[_0x66bd('0x3b')]+','+(_0x3b02f2[_0x66bd('0x77')]['waitForTheAssignedAgent']||0xa),'interval':_0x66bd('0xa8')});}return respondWithRpcPromise('Start',_0x66bd('0xaf'),_0x3b02f2);});}return respondWithRpcPromise(_0x66bd('0xb0'),_0x66bd('0xaf'),_0x3b02f2);})[_0x66bd('0x1f')](function(_0x113f62){if(_0x113f62){var _0x1233a4=0xc8;var _0x39dcfe=_0x66bd('0xb1');logger[_0x66bd('0x20')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x39dcfe,_0x1233a4,_0x66bd('0xb2'));logger[_0x66bd('0x22')](_0x66bd('0xb3'),_0x39dcfe,_0x1233a4,_0x66bd('0xb2'),JSON[_0x66bd('0x24')](_0x113f62));if(_0x3b02f2[_0x66bd('0x77')][_0x66bd('0x41')]==='twilio'){return _0x509d5e[_0x66bd('0x2b')](_0x1233a4)['set'](_0x66bd('0xb4'),_0x66bd('0xb5'))[_0x66bd('0x3c')](_0x66bd('0xb6'));}else{return _0x509d5e[_0x66bd('0x2b')](_0x1233a4)['json'](_0x113f62);}}})[_0x66bd('0x55')](handleError(_0x509d5e,null));};exports[_0x66bd('0xb7')]=function(_0x2ac93d,_0x2b1552,_0x2503b6){return db['SmsAccount'][_0x66bd('0x6b')]({'where':{'id':_0x2ac93d[_0x66bd('0x66')]['id']}})['then'](handleEntityNotFound(_0x2b1552,null))['then'](function(_0x5e0ecf){if(_0x5e0ecf){return db[_0x66bd('0xb8')][_0x66bd('0xb9')](function(_0x47b95c){return db[_0x66bd('0x75')][_0x66bd('0x38')]({'where':{'SmsAccountId':_0x2ac93d['params']['id']},'transaction':_0x47b95c})[_0x66bd('0x1f')](function(_0x3b87c0){var _0x200da8=_[_0x66bd('0x3e')](_0x2ac93d['body'],function(_0x28f933){_0x28f933['SmsAccountId']=_0x2ac93d[_0x66bd('0x66')]['id'];return _0x28f933;});return db[_0x66bd('0x75')]['bulkCreate'](_0x200da8,{'transaction':_0x47b95c});});})['then'](function(){return db[_0x66bd('0x75')][_0x66bd('0xba')]({'where':{'SmsAccountId':_0x2ac93d['params']['id']},'order':_0x66bd('0x7a')});});}})['then'](respondWithResult(_0x2b1552,null))[_0x66bd('0x55')](handleError(_0x2b1552,null));};exports[_0x66bd('0xbb')]=function(_0x28e593,_0xadc1b4,_0x49ff48){var _0x382808={};var _0x16ef6a={};var _0x8d1086;var _0x49f000;return db[_0x66bd('0x3f')]['findOne']({'where':{'id':_0x28e593['params']['id']}})[_0x66bd('0x1f')](handleEntityNotFound(_0xadc1b4,null))[_0x66bd('0x1f')](function(_0x25e03d){if(_0x25e03d){_0x8d1086=_0x25e03d;_0x16ef6a['model']=_[_0x66bd('0x44')](db[_0x66bd('0x75')][_0x66bd('0x58')]);_0x16ef6a[_0x66bd('0x45')]=_[_0x66bd('0x44')](_0x28e593['query']);_0x16ef6a[_0x66bd('0x46')]=_['intersection'](_0x16ef6a[_0x66bd('0x43')],_0x16ef6a[_0x66bd('0x45')]);_0x382808[_0x66bd('0x48')]=_[_0x66bd('0x47')](_0x16ef6a['model'],qs[_0x66bd('0x49')](_0x28e593[_0x66bd('0x45')][_0x66bd('0x49')]));_0x382808[_0x66bd('0x48')]=_0x382808['attributes']['length']?_0x382808[_0x66bd('0x48')]:_0x16ef6a['model'];_0x382808[_0x66bd('0x4c')]=qs['sort'](_0x28e593[_0x66bd('0x45')][_0x66bd('0x4d')]);_0x382808[_0x66bd('0x4f')]=qs['filters'](_['pick'](_0x28e593['query'],_0x16ef6a[_0x66bd('0x46')]));if(_0x28e593[_0x66bd('0x45')][_0x66bd('0x51')]){_0x382808[_0x66bd('0x4f')]=_[_0x66bd('0x50')](_0x382808['where'],{'$or':_[_0x66bd('0x3e')](_0x382808['attributes'],function(_0x237488){var _0x6da74c={};_0x6da74c[_0x237488]={'$like':'%'+_0x28e593[_0x66bd('0x45')][_0x66bd('0x51')]+'%'};return _0x6da74c;})});}_0x382808=_[_0x66bd('0x50')]({},_0x382808,_0x28e593['options']);return _0x8d1086[_0x66bd('0xbb')](_0x382808);}})[_0x66bd('0x1f')](function(_0x2ae45a){if(_0x2ae45a){_0x49f000=_0x2ae45a[_0x66bd('0x59')];if(!_0x28e593[_0x66bd('0x45')][_0x66bd('0x4a')](_0x66bd('0x4b'))){_0x382808[_0x66bd('0x30')]=qs[_0x66bd('0x30')](_0x28e593[_0x66bd('0x45')][_0x66bd('0x30')]);_0x382808['offset']=qs[_0x66bd('0x2e')](_0x28e593[_0x66bd('0x45')][_0x66bd('0x2e')]);}return _0x8d1086['getApplications'](_0x382808);}})['then'](function(_0x2217b7){if(_0x2217b7){return _0x2217b7?{'count':_0x49f000,'rows':_0x2217b7}:null;}})[_0x66bd('0x1f')](respondWithResult(_0xadc1b4,null))['catch'](handleError(_0xadc1b4,null));};exports[_0x66bd('0xbc')]=function(_0x2feb25,_0x1e03cb,_0x5b9631){var _0x309050={'raw':![],'where':{}};var _0x12c3ba={};var _0x5a22ab={'count':0x0,'rows':[]};return db[_0x66bd('0x3f')][_0x66bd('0x6b')]({'where':{'id':_0x2feb25[_0x66bd('0x66')]['id']}})[_0x66bd('0x1f')](handleEntityNotFound(_0x1e03cb,null))[_0x66bd('0x1f')](function(_0x4d3914){if(_0x4d3914){_0x12c3ba[_0x66bd('0x43')]=_[_0x66bd('0x44')](db[_0x66bd('0xa0')]['rawAttributes']);_0x12c3ba[_0x66bd('0x45')]=_['keys'](_0x2feb25[_0x66bd('0x45')]);_0x12c3ba['filters']=_['intersection'](_0x12c3ba['model'],_0x12c3ba['query']);_0x309050[_0x66bd('0x48')]=_[_0x66bd('0x47')](_0x12c3ba['model'],qs[_0x66bd('0x49')](_0x2feb25['query'][_0x66bd('0x49')]));_0x309050['attributes']=_0x309050[_0x66bd('0x48')][_0x66bd('0x59')]?_0x309050[_0x66bd('0x48')]:_0x12c3ba[_0x66bd('0x43')];if(!_0x2feb25['query']['hasOwnProperty'](_0x66bd('0x4b'))){_0x309050[_0x66bd('0x30')]=qs[_0x66bd('0x30')](_0x2feb25['query'][_0x66bd('0x30')]);_0x309050['offset']=qs[_0x66bd('0x2e')](_0x2feb25[_0x66bd('0x45')][_0x66bd('0x2e')]);}_0x309050[_0x66bd('0x4c')]=qs[_0x66bd('0x4d')](_0x2feb25[_0x66bd('0x45')][_0x66bd('0x4d')]);_0x309050[_0x66bd('0x4f')]=qs[_0x66bd('0x46')](_[_0x66bd('0x4e')](_0x2feb25[_0x66bd('0x45')],_0x12c3ba[_0x66bd('0x46')]));_0x309050[_0x66bd('0x4f')][_0x66bd('0x6c')]=_0x4d3914['id'];if(_0x2feb25[_0x66bd('0x45')][_0x66bd('0x51')]){_0x309050[_0x66bd('0x4f')]=_[_0x66bd('0x50')](_0x309050[_0x66bd('0x4f')],{'$or':_['map'](_0x309050[_0x66bd('0x48')],function(_0x333d83){var _0x3467ee={};_0x3467ee[_0x333d83]={'$like':'%'+_0x2feb25['query'][_0x66bd('0x51')]+'%'};return _0x3467ee;})});}_0x309050=_[_0x66bd('0x50')]({},_0x309050,_0x2feb25[_0x66bd('0x6d')]);return db['SmsInteraction'][_0x66bd('0x31')]({'where':_0x309050[_0x66bd('0x4f')]})[_0x66bd('0x1f')](function(_0x9bc3b6){_0x5a22ab[_0x66bd('0x31')]=_0x9bc3b6;if(_0x2feb25[_0x66bd('0x45')][_0x66bd('0xbd')]){_0x309050[_0x66bd('0x52')]=[{'model':db[_0x66bd('0x9d')],'as':_0x66bd('0xbe'),'required':![]},{'model':db[_0x66bd('0xad')],'as':_0x66bd('0xbf'),'attributes':[_0x66bd('0x3b'),'fullname',_0x66bd('0xc0')],'required':![]},{'model':db[_0x66bd('0xc1')],'as':'Tags','attributes':['id',_0x66bd('0x3b'),_0x66bd('0xc2')],'where':_0x2feb25['query'][_0x66bd('0xc3')]?{'id':_0x2feb25[_0x66bd('0x45')][_0x66bd('0xc3')]}:undefined,'required':_0x2feb25['query'][_0x66bd('0xc3')]?!![]:![]}];}return db['SmsInteraction'][_0x66bd('0x53')](_0x309050);})[_0x66bd('0x1f')](function(_0x1e988c){_0x5a22ab[_0x66bd('0x54')]=_0x1e988c;return _0x5a22ab;});}})[_0x66bd('0x1f')](respondWithFilteredResult(_0x1e03cb,_0x309050))['catch'](handleError(_0x1e03cb,null));};exports[_0x66bd('0x3c')]=function(_0x3cc19f,_0x58d867,_0xb431a){var _0xd1b890,_0x11bdd2,_0x42c297;if(_[_0x66bd('0x95')](_0x3cc19f['body'][_0x66bd('0x5b')])||_0x3cc19f[_0x66bd('0x5b')][_0x66bd('0x5b')]===''){throw new db['Sequelize'][(_0x66bd('0x7c'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_['isNil'](_0x3cc19f[_0x66bd('0x5b')]['to'])){throw new db[(_0x66bd('0x7b'))][(_0x66bd('0x7c'))]('to\x20is\x20mandatory');}_0xd1b890=_0x3cc19f[_0x66bd('0x5b')]['to'];return db[_0x66bd('0x3f')][_0x66bd('0x62')]({'where':{'id':_0x3cc19f[_0x66bd('0x66')]['id']},'include':[{'model':db[_0x66bd('0x9b')],'as':'List','include':[{'model':db['CmContact'],'as':_0x66bd('0x9e'),'where':{'mobile':_0xd1b890},'limit':0x1,'order':[['updatedAt',_0x66bd('0xc4')]]}]}]})[_0x66bd('0x1f')](handleEntityNotFound(_0x58d867,null))[_0x66bd('0x1f')](function(_0x218461){if(_0x218461&&_0x218461[_0x66bd('0xc5')]){_0x11bdd2=_0x218461['get']({'plain':!![]});if(_0x11bdd2[_0x66bd('0xc5')]&&_0x11bdd2[_0x66bd('0xc5')][_0x66bd('0x9e')]['length']){return _0x11bdd2[_0x66bd('0xc5')][_0x66bd('0x9e')][0x0];}return db['CmContact'][_0x66bd('0x5a')](_[_0x66bd('0xc6')](_0x3cc19f[_0x66bd('0x5b')],{'firstName':_0xd1b890,'mobile':_0xd1b890,'phone':_0xd1b890,'ListId':_0x11bdd2[_0x66bd('0x9c')]}));}})['then'](handleEntityNotFound(_0x58d867,null))[_0x66bd('0x1f')](function(_0xafda4c){if(_0xafda4c){_0x42c297=_0xafda4c;return db[_0x66bd('0xa0')][_0x66bd('0x62')]({'where':{'ContactId':_0x42c297['id'],'closed':![],'SmsAccountId':_0x11bdd2['id']}})[_0x66bd('0x1f')](function(_0x331a82){if(_0x331a82){return[_0x331a82,![]];}return db[_0x66bd('0xa0')][_0x66bd('0x5a')]({'UserId':_0x3cc19f[_0x66bd('0x5c')]['id'],'ContactId':_0x42c297['id'],'SmsAccountId':_0x11bdd2['id'],'phone':_0xd1b890,'firstMsgDirection':'out','Messages':[_[_0x66bd('0x50')](_0x3cc19f[_0x66bd('0x5b')],{'read':![],'body':_0x3cc19f[_0x66bd('0x5b')]['body'],'phone':_0xd1b890,'SmsAccountId':_0x11bdd2['id'],'UserId':_0x3cc19f['user']['id'],'ContactId':_0x42c297['id']})]},{'include':[{'model':db[_0x66bd('0xa9')],'as':'Messages'}]})[_0x66bd('0x1f')](function(_0x11be90){return[_0x11be90,!![]];});});}})[_0x66bd('0xa1')](function(_0x45fea7,_0xde6a1c){if(_0xde6a1c){return _0x45fea7;}return db[_0x66bd('0xa9')][_0x66bd('0x5a')](_[_0x66bd('0x50')](_0x3cc19f[_0x66bd('0x5b')],{'read':![],'body':_0x3cc19f['body']['body'],'phone':_0xd1b890,'SmsAccountId':_0x11bdd2['id'],'SmsInteractionId':_0x45fea7['id'],'UserId':_0x3cc19f[_0x66bd('0x5c')]['id'],'ContactId':_0x42c297['id']}))[_0x66bd('0x1f')](function(_0x5c5e1e){_0x45fea7[_0x66bd('0xc7')][_0x66bd('0xc8')]=[];_0x45fea7[_0x66bd('0xc7')][_0x66bd('0xc8')][_0x66bd('0xa5')](_0x5c5e1e[_0x66bd('0xc7')]);return _0x45fea7;});})[_0x66bd('0x1f')](respondWithResult(_0x58d867,null))[_0x66bd('0x55')](handleError(_0x58d867,null));};exports[_0x66bd('0x2b')]=function(_0x56ec3d,_0x2e95b0,_0x45cf34){if(_0x56ec3d[_0x66bd('0x5b')]['id']){delete _0x56ec3d[_0x66bd('0x5b')]['id'];}var _0x567a2f,_0x5bf30f,_0x1ceea0;return db['SmsAccount'][_0x66bd('0x62')]({'where':{'id':_0x56ec3d['params']['id']}})['then'](handleEntityNotFound(_0x2e95b0,null))[_0x66bd('0x1f')](function(_0x47901e){if(_0x47901e){_0x1ceea0=_0x47901e;logger[_0x66bd('0x22')](_0x66bd('0x23'),_0x66bd('0x2b'),_0x66bd('0xc9'),_0x47901e[_0x66bd('0x41')],util[_0x66bd('0xca')](_0x56ec3d[_0x66bd('0x5b')],{'showHidden':![],'depth':null}));switch(_0x47901e[_0x66bd('0x41')]){case'skebby':if(_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0xcb')]&&_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0x2b')]){_0x5bf30f=_0x56ec3d[_0x66bd('0x5b')]['status'];return db[_0x66bd('0xa9')][_0x66bd('0x62')]({'where':{'messageId':_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0xcb')]}});}break;case'connectel':if(_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0xcc')]&&_0x56ec3d['body'][_0x66bd('0xcd')]){_0x5bf30f=_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0xcd')];return db[_0x66bd('0xa9')][_0x66bd('0x62')]({'where':{'messageId':_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0xcc')]}});}break;case'clicksend':if(_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0x89')]&&_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0xce')]){_0x5bf30f=_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0xce')];return db[_0x66bd('0xa9')][_0x66bd('0x62')]({'where':{'messageId':_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0x89')]}});}break;case _0x66bd('0x8c'):var _0xe62c9a=_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0x8d')][0x0];if(_0xe62c9a[_0x66bd('0x88')]&&_0xe62c9a[_0x66bd('0x2b')]['groupName']===_0x66bd('0xcf')){_0x5bf30f=_0xe62c9a['status'][_0x66bd('0xd0')];return db[_0x66bd('0xa9')]['find']({'where':{'messageId':_0xe62c9a['messageId']}});}break;case _0x66bd('0xd1'):if(_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0x88')]&&_0x56ec3d[_0x66bd('0x5b')]['status']){_0x5bf30f=_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0x2b')];return db[_0x66bd('0xa9')][_0x66bd('0x62')]({'where':{'messageId':_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0x88')]}});}break;case _0x66bd('0x92'):if(_0x56ec3d[_0x66bd('0x5b')][0x0][_0x66bd('0x28')]['id']){_0x5bf30f=_0x56ec3d['body'][0x0][_0x66bd('0x41')];return db[_0x66bd('0xa9')][_0x66bd('0x62')]({'where':{'messageId':_0x56ec3d['body'][0x0][_0x66bd('0x28')]['id']}});}break;case _0x66bd('0x93'):if(_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0xd2')]&&_0x56ec3d[_0x66bd('0x5b')]['status']){_0x5bf30f=_0x56ec3d['body'][_0x66bd('0x2b')];return db[_0x66bd('0xa9')][_0x66bd('0x62')]({'where':{'messageId':_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0xd2')]}});}break;}}})['then'](handleEntityNotFound(_0x2e95b0,null))[_0x66bd('0x1f')](function(_0x56a9dc){if(_0x56a9dc){_0x567a2f=_0x56a9dc;switch(_0x1ceea0[_0x66bd('0x41')]){case _0x66bd('0x85'):if(_0x5bf30f===_0x66bd('0xcf')){return _0x567a2f['update']({'read':!![]});}else{logger[_0x66bd('0x25')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x66bd('0x2b'),_0x66bd('0x85'),util['inspect'](_0x56ec3d[_0x66bd('0x5b')],{'showHidden':![],'depth':null}));}break;case _0x66bd('0x87'):if(_0x5bf30f==='1'){return _0x567a2f[_0x66bd('0x37')]({'read':!![]});}else{logger['error']('SmsAccount,\x20%s,\x20%s,\x20%s',_0x66bd('0x2b'),_0x66bd('0x85'),util[_0x66bd('0xca')](_0x56ec3d['body'],{'showHidden':![],'depth':null}));}break;case _0x66bd('0xd3'):if(!_0x56ec3d[_0x66bd('0x5b')]['error_code']&&_0x5bf30f>=0xc8&&_0x5bf30f<=0xce){return _0x567a2f[_0x66bd('0x37')]({'read':!![]});}else{logger[_0x66bd('0x25')]('SmsAccount,\x20%s,\x20%s,\x20%s','status',_0x66bd('0xd3'),util[_0x66bd('0xca')](_0x56ec3d[_0x66bd('0x5b')],{'showHidden':![],'depth':null}));}break;case _0x66bd('0x8c'):var _0x5b3880=_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0x8d')][0x0];if(_0x5b3880[_0x66bd('0x2b')]['groupName']===_0x66bd('0xcf')){return _0x567a2f[_0x66bd('0x37')]({'read':!![]});}else{logger['error']('SmsAccount,\x20%s,\x20%s,\x20%s',_0x66bd('0x2b'),_0x66bd('0x8c'),util[_0x66bd('0xca')](_0x56ec3d[_0x66bd('0x5b')],{'showHidden':![],'depth':null}));}break;case _0x66bd('0xd1'):if(_0x5bf30f==_0x66bd('0xd4')||_0x5bf30f==_0x66bd('0xd5')){return _0x567a2f[_0x66bd('0x37')]({'read':!![]});}else{logger[_0x66bd('0x25')](_0x66bd('0x23'),_0x66bd('0x2b'),_0x66bd('0xd1'),util['inspect'](_0x56ec3d['body'],{'showHidden':![],'depth':null}));}break;case'bandwidth':if(_0x5bf30f==_0x66bd('0xd6')){return _0x567a2f[_0x66bd('0x37')]({'read':!![]});}else{logger['error'](_0x66bd('0x23'),'status','bandwidth',util['inspect'](_0x56ec3d['body'],{'showHidden':![],'depth':null}));}break;case'intelepeer':if(_0x5bf30f===_0x66bd('0xd7')||_0x5bf30f===_0x66bd('0xd8')){return _0x567a2f[_0x66bd('0x37')]({'read':!![]});}else{logger[_0x66bd('0x25')](_0x66bd('0x23'),'status',_0x66bd('0x93'),util[_0x66bd('0xca')](_0x56ec3d[_0x66bd('0x5b')],{'showHidden':![],'depth':null}));}break;}return _0x567a2f;}})[_0x66bd('0x1f')](respondWithResult(_0x2e95b0,null))[_0x66bd('0x55')](handleError(_0x2e95b0,null));};exports[_0x66bd('0xd9')]=function(_0x2d8e34,_0x3bed58,_0x3b2fa0){var _0x378682,_0x384409,_0xfdae5a;return db[_0x66bd('0x3f')][_0x66bd('0x62')]({'where':{'id':_0x2d8e34[_0x66bd('0x66')]['id']}})['then'](handleEntityNotFound(_0x3bed58,null))[_0x66bd('0x1f')](function(_0x12a982){if(_0x12a982){_0xfdae5a=_0x12a982;logger['debug'](_0x66bd('0x23'),_0x66bd('0x2b'),_0x66bd('0xc9'),_0x12a982[_0x66bd('0x41')],util[_0x66bd('0xca')](_0x2d8e34[_0x66bd('0x45')],{'showHidden':![],'depth':null}));switch(_0x12a982['type']){case'csc':if(_0x2d8e34[_0x66bd('0x45')][_0x66bd('0xda')]&&_0x2d8e34['query'][_0x66bd('0xdb')]){_0x384409=_0x2d8e34['query'][_0x66bd('0xdb')];return db['SmsMessage'][_0x66bd('0x62')]({'where':{'messageId':_0x2d8e34[_0x66bd('0x45')][_0x66bd('0xda')]}});}break;}}})['then'](handleEntityNotFound(_0x3bed58,null))[_0x66bd('0x1f')](function(_0x2153a8){if(_0x2153a8){_0x378682=_0x2153a8;switch(_0xfdae5a[_0x66bd('0x41')]){case _0x66bd('0x8e'):if(_0x384409==='2'||_0x384409==='6'){return _0x378682[_0x66bd('0x37')]({'read':!![]});}else{logger['error'](_0x66bd('0x23'),_0x66bd('0x2b'),_0x66bd('0x8e'),util[_0x66bd('0xca')](_0x2d8e34[_0x66bd('0x45')],{'showHidden':![],'depth':null}));};break;}return _0x378682;}})[_0x66bd('0x1f')](respondWithResult(_0x3bed58,null))['catch'](handleError(_0x3bed58,null));};exports[_0x66bd('0xdc')]=function(_0x368971,_0x4514b9,_0x3a2f59){return db['SmsAccount'][_0x66bd('0x62')]({'where':{'id':_0x368971[_0x66bd('0x66')]['id']}})[_0x66bd('0x1f')](handleEntityNotFound(_0x4514b9,null))['then'](function(_0xae76b6){if(_0xae76b6){return _0xae76b6[_0x66bd('0xdc')](_0x368971[_0x66bd('0x5b')]['ids'],_[_0x66bd('0xdd')](_0x368971[_0x66bd('0x5b')],[_0x66bd('0x6f'),'id'])||{})[_0x66bd('0xa1')](function(_0x315fa2){for(var _0x45902a=0x0;_0x45902a<_0x368971[_0x66bd('0x5b')][_0x66bd('0x6f')][_0x66bd('0x59')];_0x45902a+=0x1){socket['emit'](_0x66bd('0xde'),{'UserId':_0x368971[_0x66bd('0x5b')][_0x66bd('0x6f')][_0x45902a],'SmsAccountId':_0x368971[_0x66bd('0x66')]['id']});}return _0x315fa2;});}})[_0x66bd('0x1f')](respondWithResult(_0x4514b9,null))[_0x66bd('0x55')](handleError(_0x4514b9,null));};exports['removeAgents']=function(_0x5dbd01,_0x390b9b,_0x49959e){return db[_0x66bd('0x3f')][_0x66bd('0x62')]({'where':{'id':_0x5dbd01['params']['id']}})[_0x66bd('0x1f')](handleEntityNotFound(_0x390b9b,null))[_0x66bd('0x1f')](function(_0x8a5623){if(_0x8a5623){return _0x8a5623[_0x66bd('0xdf')](_0x5dbd01[_0x66bd('0x45')]['ids'])[_0x66bd('0x1f')](function(){if(_['isArray'](_0x5dbd01['query'][_0x66bd('0x6f')])){for(var _0x1516da=0x0;_0x1516da<_0x5dbd01['query'][_0x66bd('0x6f')][_0x66bd('0x59')];_0x1516da+=0x1){socket[_0x66bd('0xe0')](_0x66bd('0xe1'),{'UserId':Number(_0x5dbd01['query'][_0x66bd('0x6f')][_0x1516da]),'SmsAccountId':Number(_0x5dbd01['params']['id'])});}}else{socket[_0x66bd('0xe0')]('userSmsAccount:remove',{'UserId':Number(_0x5dbd01['query']['ids']),'SmsAccountId':Number(_0x5dbd01[_0x66bd('0x66')]['id'])});}});}})[_0x66bd('0x1f')](respondWithStatusCode(_0x390b9b,null))[_0x66bd('0x55')](handleError(_0x390b9b,null));};exports[_0x66bd('0xe2')]=function(_0x3db265,_0x49bd6c,_0x9de193){var _0x46c4ae={};var _0x4a11d9={};var _0xd02b55;var _0x23448f;return db[_0x66bd('0x3f')][_0x66bd('0x6b')]({'where':{'id':_0x3db265['params']['id']}})[_0x66bd('0x1f')](handleEntityNotFound(_0x49bd6c,null))[_0x66bd('0x1f')](function(_0xc4ad71){if(_0xc4ad71){_0xd02b55=_0xc4ad71;_0x4a11d9[_0x66bd('0x43')]=_[_0x66bd('0x44')](db['User'][_0x66bd('0x58')]);_0x4a11d9[_0x66bd('0x45')]=_[_0x66bd('0x44')](_0x3db265['query']);_0x4a11d9[_0x66bd('0x46')]=_[_0x66bd('0x47')](_0x4a11d9[_0x66bd('0x43')],_0x4a11d9[_0x66bd('0x45')]);_0x46c4ae['attributes']=_[_0x66bd('0x47')](_0x4a11d9[_0x66bd('0x43')],qs[_0x66bd('0x49')](_0x3db265[_0x66bd('0x45')][_0x66bd('0x49')]));_0x46c4ae[_0x66bd('0x48')]=_0x46c4ae[_0x66bd('0x48')][_0x66bd('0x59')]?_0x46c4ae[_0x66bd('0x48')]:_0x4a11d9[_0x66bd('0x43')];_0x46c4ae[_0x66bd('0x4c')]=qs[_0x66bd('0x4d')](_0x3db265['query'][_0x66bd('0x4d')]);_0x46c4ae[_0x66bd('0x4f')]=qs[_0x66bd('0x46')](_[_0x66bd('0x4e')](_0x3db265['query'],_0x4a11d9[_0x66bd('0x46')]));if(_0x3db265['query'][_0x66bd('0x51')]){_0x46c4ae[_0x66bd('0x4f')]=_['merge'](_0x46c4ae[_0x66bd('0x4f')],{'$or':_[_0x66bd('0x3e')](_0x46c4ae[_0x66bd('0x48')],function(_0x5f4aa6){var _0x4ce74d={};_0x4ce74d[_0x5f4aa6]={'$like':'%'+_0x3db265['query'][_0x66bd('0x51')]+'%'};return _0x4ce74d;})});}_0x46c4ae=_[_0x66bd('0x50')]({},_0x46c4ae,_0x3db265[_0x66bd('0x6d')]);return _0xd02b55[_0x66bd('0xe2')](_0x46c4ae);}})[_0x66bd('0x1f')](function(_0x167e24){if(_0x167e24){_0x23448f=_0x167e24[_0x66bd('0x59')];if(!_0x3db265[_0x66bd('0x45')][_0x66bd('0x4a')](_0x66bd('0x4b'))){_0x46c4ae[_0x66bd('0x30')]=qs[_0x66bd('0x30')](_0x3db265['query'][_0x66bd('0x30')]);_0x46c4ae['offset']=qs[_0x66bd('0x2e')](_0x3db265['query'][_0x66bd('0x2e')]);}return _0xd02b55['getAgents'](_0x46c4ae);}})['then'](function(_0x275c14){if(_0x275c14){return _0x275c14?{'count':_0x23448f,'rows':_0x275c14}:null;}})['then'](respondWithResult(_0x49bd6c,null))[_0x66bd('0x55')](handleError(_0x49bd6c,null));};
\ No newline at end of file