Built motion from commit 775e2a94.|2.6.3
[motion2.git] / server / api / smsAccount / smsAccount.controller.js
index 99626aa..e31623e 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xaf9e=['statusGet','message-id','state','addAgents','omit','emit','userSmsAccount:save','removeAgents','isArray','userSmsAccount:remove','getAgents','eml-format','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./smsAccount.socket','register','jayson/promise','request','then','info','request\x20sent','debug','stringify','error','code','SmsAccount,\x20%s,\x20%s','message','result','catch','sendStatus','status','end','undefined','count','offset','set','json','apply','reject','update','destroy','SmsAccounts','UserProfileResource','stack','name','send','index','mandatoryDispositionPause','map','type','key','query','keys','filters','intersection','attributes','fields','length','model','hasOwnProperty','nolimit','limit','order','pick','where','merge','filter','options','SmsAccount','includeAll','include','rows','show','params','Pause','find','create','user','get','role','UserProfileSection','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','describe','addDisposition','SmsAccountId','getDispositions','findOne','Disposition','rawAttributes','sort','findAll','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','removeAnswers','notify','sms','Applications','orderBy','asc','account','CmContact','Sequelize','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','ListId','twilio','From','Body','messageId','MessageSid','skebby','from','sender','connectel','message_id','plivo','Text','MessageUUID','infobip','results','text','csc','originatingAddress','segmentedMessage','fromNumber','replyMessageId','bandwidth','refid','isNil','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','CmList','Contacts','DESC','list','contact','SmsInteraction','spread','interaction','autoclose','push','applications','close','unmanaged','*,*,*,*','SmsMessage','ContactId','UserId','User','unshift','agent','startRouting','SmsAccount,\x20%s,\x20%s,\x20%s','entity\x20found','SmsAccount,\x20%s,\x20%s,\x20%s,\x20%s','Content-Type','text/xml','<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>','transaction','Transaction','ISOLATION_LEVELS','READ_COMMITTED','SmsApplication','findAndCountAll','priority','finally','getApplications','getInteractions','Contact','Owner','fullname','internal','Tags','color','tag','body\x20is\x20mandatory\x20and\x20not\x20empty','to\x20is\x20mandatory','List','out','Messages','dataValues','received\x20delivery\x20report\x20from','inspect','skebby_dispatch_id','requestid','statusInt','clicksend','status_code','groupName','DELIVERED','clickatell','intelepeer','redif','error_code','DELIVERED_TO_GATEWAY','RECEIVED_BY_RECIPIENT','message-delivered','DELIVRD','ACCEPTD'];(function(_0x3e44fa,_0x75ed2a){var _0x2a0aba=function(_0x1db6a7){while(--_0x1db6a7){_0x3e44fa['push'](_0x3e44fa['shift']());}};_0x2a0aba(++_0x75ed2a);}(_0xaf9e,0xf6));var _0xeaf9=function(_0x16f9be,_0x533f56){_0x16f9be=_0x16f9be-0x0;var _0x53706f=_0xaf9e[_0x16f9be];return _0x53706f;};'use strict';var emlformat=require(_0xeaf9('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0xeaf9('0x1'));var rp=require(_0xeaf9('0x2'));var moment=require(_0xeaf9('0x3'));var BPromise=require(_0xeaf9('0x4'));var Mustache=require(_0xeaf9('0x5'));var util=require(_0xeaf9('0x6'));var path=require(_0xeaf9('0x7'));var sox=require(_0xeaf9('0x8'));var csv=require(_0xeaf9('0x9'));var ejs=require(_0xeaf9('0xa'));var fs=require('fs');var fs_extra=require(_0xeaf9('0xb'));var _=require(_0xeaf9('0xc'));var squel=require('squel');var crypto=require(_0xeaf9('0xd'));var jsforce=require(_0xeaf9('0xe'));var deskjs=require('desk.js');var toCsv=require(_0xeaf9('0x9'));var querystring=require('querystring');var Papa=require(_0xeaf9('0xf'));var Redis=require(_0xeaf9('0x10'));var authService=require(_0xeaf9('0x11'));var qs=require(_0xeaf9('0x12'));var as=require(_0xeaf9('0x13'));var hardwareService=require(_0xeaf9('0x14'));var logger=require('../../config/logger')(_0xeaf9('0x15'));var utils=require(_0xeaf9('0x16'));var config=require(_0xeaf9('0x17'));var licenseUtil=require(_0xeaf9('0x18'));var db=require(_0xeaf9('0x19'))['db'];config[_0xeaf9('0x1a')]=_[_0xeaf9('0x1b')](config[_0xeaf9('0x1a')],{'host':_0xeaf9('0x1c'),'port':0x18eb});var socket=require(_0xeaf9('0x1d'))(new Redis(config['redis']));require(_0xeaf9('0x1e'))[_0xeaf9('0x1f')](socket);var jayson=require(_0xeaf9('0x20'));var client=jayson['client']['http']({'port':0x232c});function respondWithRpcPromise(_0x1cd1e2,_0x2369a3,_0x26e8c8,_0x45e811){return new BPromise(function(_0xd46ad9,_0x50c16c){var _0xcaa6da=_0x45e811||client;return _0xcaa6da[_0xeaf9('0x21')](_0x1cd1e2,_0x26e8c8)[_0xeaf9('0x22')](function(_0x3fad38){logger[_0xeaf9('0x23')]('SmsAccount,\x20%s,\x20%s',_0x2369a3,_0xeaf9('0x24'));logger[_0xeaf9('0x25')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x2369a3,_0xeaf9('0x24'),JSON[_0xeaf9('0x26')](_0x3fad38));if(_0x3fad38[_0xeaf9('0x27')]){if(_0x3fad38[_0xeaf9('0x27')][_0xeaf9('0x28')]===0x1f4){logger[_0xeaf9('0x27')](_0xeaf9('0x29'),_0x2369a3,_0x3fad38[_0xeaf9('0x27')][_0xeaf9('0x2a')]);return _0x50c16c(_0x3fad38['error']['message']);}logger['error'](_0xeaf9('0x29'),_0x2369a3,_0x3fad38[_0xeaf9('0x27')][_0xeaf9('0x2a')]);return _0xd46ad9(_0x3fad38[_0xeaf9('0x27')][_0xeaf9('0x2a')]);}else{logger['info'](_0xeaf9('0x29'),_0x2369a3,_0xeaf9('0x24'));_0xd46ad9(_0x3fad38[_0xeaf9('0x2b')][_0xeaf9('0x2a')]);}})[_0xeaf9('0x2c')](function(_0x426132){logger[_0xeaf9('0x27')](_0xeaf9('0x29'),_0x2369a3,_0x426132);_0x50c16c(_0x426132);});});}function respondWithStatusCode(_0xe20d4c,_0x2faae7){_0x2faae7=_0x2faae7||0xcc;return function(_0x39a4a4){if(_0x39a4a4){return _0xe20d4c[_0xeaf9('0x2d')](_0x2faae7);}return _0xe20d4c[_0xeaf9('0x2e')](_0x2faae7)[_0xeaf9('0x2f')]();};}function respondWithResult(_0x5115cd,_0x59e574){_0x59e574=_0x59e574||0xc8;return function(_0xcc159a){if(_0xcc159a){return _0x5115cd[_0xeaf9('0x2e')](_0x59e574)['json'](_0xcc159a);}};}function respondWithFilteredResult(_0x5d4fc7,_0xc64d8b){return function(_0x35da7f){if(_0x35da7f){var _0x425080=typeof _0xc64d8b['offset']===_0xeaf9('0x30')&&typeof _0xc64d8b['limit']===_0xeaf9('0x30');var _0xd38e35=_0x35da7f[_0xeaf9('0x31')];var _0x56fcc5=_0x425080?0x0:_0xc64d8b[_0xeaf9('0x32')];var _0x9b27c1=_0x425080?_0x35da7f[_0xeaf9('0x31')]:_0xc64d8b[_0xeaf9('0x32')]+_0xc64d8b['limit'];var _0xb5d6f6;if(_0x9b27c1>=_0xd38e35){_0x9b27c1=_0xd38e35;_0xb5d6f6=0xc8;}else{_0xb5d6f6=0xce;}_0x5d4fc7[_0xeaf9('0x2e')](_0xb5d6f6);return _0x5d4fc7[_0xeaf9('0x33')]('Content-Range',_0x56fcc5+'-'+_0x9b27c1+'/'+_0xd38e35)[_0xeaf9('0x34')](_0x35da7f);}return null;};}function patchUpdates(_0x2f8acf){return function(_0x14ed71){try{jsonpatch[_0xeaf9('0x35')](_0x14ed71,_0x2f8acf,!![]);}catch(_0xf71c22){return BPromise[_0xeaf9('0x36')](_0xf71c22);}return _0x14ed71['save']();};}function saveUpdates(_0x3fa079,_0x1de3a2){return function(_0x529364){if(_0x529364){return _0x529364[_0xeaf9('0x37')](_0x3fa079)[_0xeaf9('0x22')](function(_0x488fa8){return _0x488fa8;});}return null;};}function removeEntity(_0x4b14e4,_0x1c3459){return function(_0x2341fb){if(_0x2341fb){return _0x2341fb[_0xeaf9('0x38')]()['then'](function(){var _0x579c9b=_0x2341fb['get']({'plain':!![]});var _0x2f6a0b=_0xeaf9('0x39');return db[_0xeaf9('0x3a')][_0xeaf9('0x38')]({'where':{'type':_0x2f6a0b,'resourceId':_0x579c9b['id']}})[_0xeaf9('0x22')](function(){return _0x2341fb;});})[_0xeaf9('0x22')](function(){_0x4b14e4[_0xeaf9('0x2e')](0xcc)[_0xeaf9('0x2f')]();});}};}function handleEntityNotFound(_0xe74081,_0x21a55c){return function(_0x23bcae){if(!_0x23bcae){_0xe74081[_0xeaf9('0x2d')](0x194);}return _0x23bcae;};}function handleError(_0x270c7c,_0x430e87){_0x430e87=_0x430e87||0x1f4;return function(_0x5206ab){logger[_0xeaf9('0x27')](_0x5206ab[_0xeaf9('0x3b')]);if(_0x5206ab['name']){delete _0x5206ab[_0xeaf9('0x3c')];}_0x270c7c['status'](_0x430e87)[_0xeaf9('0x3d')](_0x5206ab);};}exports[_0xeaf9('0x3e')]=function(_0x4d36cc,_0x54771f){var _0x281a67={'include':[{'model':db['Pause'],'as':_0xeaf9('0x3f')}]},_0x2c0204={},_0x4bdcfd={'count':0x0,'rows':[]};var _0x3e430c=_[_0xeaf9('0x40')](db['SmsAccount']['rawAttributes'],function(_0x2237c8){return{'name':_0x2237c8['fieldName'],'type':_0x2237c8[_0xeaf9('0x41')][_0xeaf9('0x42')]};});_0x2c0204['model']=_['map'](_0x3e430c,'name');_0x2c0204[_0xeaf9('0x43')]=_[_0xeaf9('0x44')](_0x4d36cc[_0xeaf9('0x43')]);_0x2c0204[_0xeaf9('0x45')]=_[_0xeaf9('0x46')](_0x2c0204['model'],_0x2c0204[_0xeaf9('0x43')]);_0x281a67[_0xeaf9('0x47')]=_['intersection'](_0x2c0204['model'],qs[_0xeaf9('0x48')](_0x4d36cc[_0xeaf9('0x43')]['fields']));_0x281a67['attributes']=_0x281a67['attributes'][_0xeaf9('0x49')]?_0x281a67['attributes']:_0x2c0204[_0xeaf9('0x4a')];if(!_0x4d36cc[_0xeaf9('0x43')][_0xeaf9('0x4b')](_0xeaf9('0x4c'))){_0x281a67[_0xeaf9('0x4d')]=qs[_0xeaf9('0x4d')](_0x4d36cc['query'][_0xeaf9('0x4d')]);_0x281a67[_0xeaf9('0x32')]=qs['offset'](_0x4d36cc[_0xeaf9('0x43')][_0xeaf9('0x32')]);}_0x281a67[_0xeaf9('0x4e')]=qs['sort'](_0x4d36cc[_0xeaf9('0x43')]['sort']);_0x281a67['where']=qs[_0xeaf9('0x45')](_[_0xeaf9('0x4f')](_0x4d36cc[_0xeaf9('0x43')],_0x2c0204['filters']),_0x3e430c);if(_0x4d36cc[_0xeaf9('0x43')]['filter']){_0x281a67[_0xeaf9('0x50')]=_[_0xeaf9('0x51')](_0x281a67['where'],{'$or':_[_0xeaf9('0x40')](_0x3e430c,function(_0x4d9932){if(_0x4d9932[_0xeaf9('0x41')]!=='VIRTUAL'){var _0x1637fd={};_0x1637fd[_0x4d9932[_0xeaf9('0x3c')]]={'$like':'%'+_0x4d36cc[_0xeaf9('0x43')][_0xeaf9('0x52')]+'%'};return _0x1637fd;}})});}_0x281a67=_['merge']({},_0x281a67,_0x4d36cc[_0xeaf9('0x53')]);var _0x10ad12={'where':_0x281a67['where']};return db[_0xeaf9('0x54')]['count'](_0x10ad12)['then'](function(_0x1e4f10){_0x4bdcfd[_0xeaf9('0x31')]=_0x1e4f10;if(_0x4d36cc['query'][_0xeaf9('0x55')]){_0x281a67[_0xeaf9('0x56')]=[{'all':!![]}];}return db[_0xeaf9('0x54')]['findAll'](_0x281a67);})[_0xeaf9('0x22')](function(_0x44ed98){_0x4bdcfd[_0xeaf9('0x57')]=_0x44ed98;return _0x4bdcfd;})[_0xeaf9('0x22')](respondWithFilteredResult(_0x54771f,_0x281a67))[_0xeaf9('0x2c')](handleError(_0x54771f,null));};exports[_0xeaf9('0x58')]=function(_0x2a2265,_0x296ad2){var _0x4d9cde={'raw':![],'where':{'id':_0x2a2265[_0xeaf9('0x59')]['id']},'include':[{'model':db[_0xeaf9('0x5a')],'as':'mandatoryDispositionPause'}]},_0x57509c={};_0x57509c[_0xeaf9('0x4a')]=_[_0xeaf9('0x44')](db[_0xeaf9('0x54')]['rawAttributes']);_0x57509c['query']=_[_0xeaf9('0x44')](_0x2a2265[_0xeaf9('0x43')]);_0x57509c[_0xeaf9('0x45')]=_[_0xeaf9('0x46')](_0x57509c[_0xeaf9('0x4a')],_0x57509c[_0xeaf9('0x43')]);_0x4d9cde[_0xeaf9('0x47')]=_['intersection'](_0x57509c['model'],qs[_0xeaf9('0x48')](_0x2a2265[_0xeaf9('0x43')]['fields']));_0x4d9cde[_0xeaf9('0x47')]=_0x4d9cde['attributes']['length']?_0x4d9cde[_0xeaf9('0x47')]:_0x57509c['model'];if(_0x2a2265['query']['includeAll']){_0x4d9cde[_0xeaf9('0x56')]=[{'all':!![]}];}_0x4d9cde=_[_0xeaf9('0x51')]({},_0x4d9cde,_0x2a2265[_0xeaf9('0x53')]);return db['SmsAccount'][_0xeaf9('0x5b')](_0x4d9cde)[_0xeaf9('0x22')](handleEntityNotFound(_0x296ad2,null))[_0xeaf9('0x22')](respondWithResult(_0x296ad2,null))[_0xeaf9('0x2c')](handleError(_0x296ad2,null));};exports[_0xeaf9('0x5c')]=function(_0x524a50,_0xcf9b82){return db[_0xeaf9('0x54')][_0xeaf9('0x5c')](_0x524a50['body'],{})[_0xeaf9('0x22')](function(_0x11613c){var _0x2220d2=_0x524a50[_0xeaf9('0x5d')][_0xeaf9('0x5e')]({'plain':!![]});if(!_0x2220d2)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x2220d2[_0xeaf9('0x5f')]===_0xeaf9('0x5d')){var _0x2b6ec5=_0x11613c[_0xeaf9('0x5e')]({'plain':!![]});var _0x249794='SmsAccounts';return db[_0xeaf9('0x60')][_0xeaf9('0x5b')]({'where':{'name':_0x249794,'userProfileId':_0x2220d2['userProfileId']},'raw':!![]})['then'](function(_0x3efec5){if(_0x3efec5&&_0x3efec5[_0xeaf9('0x61')]===0x0){return db[_0xeaf9('0x3a')]['create']({'name':_0x2b6ec5[_0xeaf9('0x3c')],'resourceId':_0x2b6ec5['id'],'type':_0x3efec5['name'],'sectionId':_0x3efec5['id']},{})['then'](function(){return _0x11613c;});}else{return _0x11613c;}})[_0xeaf9('0x2c')](function(_0xfaaf04){logger['error'](_0xeaf9('0x62'),_0xfaaf04);throw _0xfaaf04;});}return _0x11613c;})['then'](respondWithResult(_0xcf9b82,0xc9))['catch'](handleError(_0xcf9b82,null));};exports[_0xeaf9('0x37')]=function(_0x5e1192,_0x1dfb28){if(_0x5e1192['body']['id']){delete _0x5e1192[_0xeaf9('0x63')]['id'];}return db['SmsAccount'][_0xeaf9('0x5b')]({'where':{'id':_0x5e1192['params']['id']},'include':[{'model':db['Pause'],'as':'mandatoryDispositionPause'}]})[_0xeaf9('0x22')](handleEntityNotFound(_0x1dfb28,null))[_0xeaf9('0x22')](saveUpdates(_0x5e1192['body'],null))[_0xeaf9('0x22')](respondWithResult(_0x1dfb28,null))[_0xeaf9('0x2c')](handleError(_0x1dfb28,null));};exports['destroy']=function(_0x55bbbf,_0x1e7a66){return db['SmsAccount'][_0xeaf9('0x5b')]({'where':{'id':_0x55bbbf[_0xeaf9('0x59')]['id']}})[_0xeaf9('0x22')](handleEntityNotFound(_0x1e7a66,null))['then'](removeEntity(_0x1e7a66,null))[_0xeaf9('0x2c')](handleError(_0x1e7a66,null));};exports['describe']=function(_0xf6755d,_0x3104f6){return db[_0xeaf9('0x54')][_0xeaf9('0x64')]()[_0xeaf9('0x22')](respondWithResult(_0x3104f6,null))[_0xeaf9('0x2c')](handleError(_0x3104f6,null));};exports[_0xeaf9('0x65')]=function(_0x21c62d,_0x19378f,_0x255afb){if(_0x21c62d[_0xeaf9('0x63')]['id']){delete _0x21c62d[_0xeaf9('0x63')]['id'];}return db['SmsAccount'][_0xeaf9('0x5b')]({'where':{'id':_0x21c62d[_0xeaf9('0x59')]['id']}})['then'](handleEntityNotFound(_0x19378f,null))[_0xeaf9('0x22')](function(_0x5b965b){if(_0x5b965b){_0x21c62d[_0xeaf9('0x63')][_0xeaf9('0x66')]=_0x5b965b['id'];return db['Disposition'][_0xeaf9('0x5c')](_0x21c62d[_0xeaf9('0x63')]);}})[_0xeaf9('0x22')](respondWithResult(_0x19378f,null))[_0xeaf9('0x2c')](handleError(_0x19378f,null));};exports[_0xeaf9('0x67')]=function(_0x1f2586,_0x1c80a7,_0x2287c6){var _0x5df70d={'raw':![],'where':{}};var _0x1e662a={};var _0x590e3e={'count':0x0,'rows':[]};return db[_0xeaf9('0x54')][_0xeaf9('0x68')]({'where':{'id':_0x1f2586[_0xeaf9('0x59')]['id']}})[_0xeaf9('0x22')](handleEntityNotFound(_0x1c80a7,null))[_0xeaf9('0x22')](function(_0x354eb1){if(_0x354eb1){_0x1e662a[_0xeaf9('0x4a')]=_['keys'](db[_0xeaf9('0x69')][_0xeaf9('0x6a')]);_0x1e662a[_0xeaf9('0x43')]=_[_0xeaf9('0x44')](_0x1f2586['query']);_0x1e662a['filters']=_[_0xeaf9('0x46')](_0x1e662a['model'],_0x1e662a['query']);_0x5df70d[_0xeaf9('0x47')]=_[_0xeaf9('0x46')](_0x1e662a[_0xeaf9('0x4a')],qs['fields'](_0x1f2586[_0xeaf9('0x43')]['fields']));_0x5df70d[_0xeaf9('0x47')]=_0x5df70d[_0xeaf9('0x47')][_0xeaf9('0x49')]?_0x5df70d[_0xeaf9('0x47')]:_0x1e662a['model'];if(!_0x1f2586[_0xeaf9('0x43')][_0xeaf9('0x4b')]('nolimit')){_0x5df70d['limit']=qs[_0xeaf9('0x4d')](_0x1f2586[_0xeaf9('0x43')][_0xeaf9('0x4d')]);_0x5df70d[_0xeaf9('0x32')]=qs[_0xeaf9('0x32')](_0x1f2586['query'][_0xeaf9('0x32')]);}_0x5df70d['order']=qs['sort'](_0x1f2586[_0xeaf9('0x43')][_0xeaf9('0x6b')]);_0x5df70d[_0xeaf9('0x50')]=qs[_0xeaf9('0x45')](_[_0xeaf9('0x4f')](_0x1f2586['query'],_0x1e662a[_0xeaf9('0x45')]));_0x5df70d[_0xeaf9('0x50')]['SmsAccountId']=_0x354eb1['id'];if(_0x1f2586[_0xeaf9('0x43')][_0xeaf9('0x52')]){_0x5df70d[_0xeaf9('0x50')]=_[_0xeaf9('0x51')](_0x5df70d[_0xeaf9('0x50')],{'$or':_['map'](_0x5df70d[_0xeaf9('0x47')],function(_0x1dd9b1){var _0x541f91={};_0x541f91[_0x1dd9b1]={'$like':'%'+_0x1f2586[_0xeaf9('0x43')][_0xeaf9('0x52')]+'%'};return _0x541f91;})});}_0x5df70d=_[_0xeaf9('0x51')]({},_0x5df70d,_0x1f2586['options']);return db[_0xeaf9('0x69')][_0xeaf9('0x31')]({'where':_0x5df70d[_0xeaf9('0x50')]})[_0xeaf9('0x22')](function(_0x5aa746){_0x590e3e[_0xeaf9('0x31')]=_0x5aa746;if(_0x1f2586[_0xeaf9('0x43')]['includeAll']){_0x5df70d[_0xeaf9('0x56')]=[{'all':!![]}];}return db[_0xeaf9('0x69')][_0xeaf9('0x6c')](_0x5df70d);})[_0xeaf9('0x22')](function(_0x2fa565){_0x590e3e[_0xeaf9('0x57')]=_0x2fa565;return _0x590e3e;});}})['then'](respondWithFilteredResult(_0x1c80a7,_0x5df70d))[_0xeaf9('0x2c')](handleError(_0x1c80a7,null));};exports[_0xeaf9('0x6d')]=function(_0x11fd9d,_0x55d84f,_0x2a1e90){return db['SmsAccount'][_0xeaf9('0x5b')]({'where':{'id':_0x11fd9d[_0xeaf9('0x59')]['id']}})[_0xeaf9('0x22')](handleEntityNotFound(_0x55d84f,null))[_0xeaf9('0x22')](function(_0x4f6fea){if(_0x4f6fea){return _0x4f6fea[_0xeaf9('0x6d')](_0x11fd9d[_0xeaf9('0x43')][_0xeaf9('0x6e')]);}})[_0xeaf9('0x22')](respondWithStatusCode(_0x55d84f,null))['catch'](handleError(_0x55d84f,null));};exports[_0xeaf9('0x6f')]=function(_0x2f5d18,_0x1ad516,_0x372f2b){if(_0x2f5d18[_0xeaf9('0x63')]['id']){delete _0x2f5d18[_0xeaf9('0x63')]['id'];}return db['SmsAccount'][_0xeaf9('0x5b')]({'where':{'id':_0x2f5d18[_0xeaf9('0x59')]['id']}})['then'](handleEntityNotFound(_0x1ad516,null))['then'](function(_0x2e6ec6){if(_0x2e6ec6){_0x2f5d18['body']['SmsAccountId']=_0x2e6ec6['id'];return db[_0xeaf9('0x70')]['create'](_0x2f5d18[_0xeaf9('0x63')]);}})[_0xeaf9('0x22')](respondWithResult(_0x1ad516,null))['catch'](handleError(_0x1ad516,null));};exports[_0xeaf9('0x71')]=function(_0x15f8e3,_0xce72b1,_0x45e8ea){var _0x4bf03f={'raw':![],'where':{}};var _0x49b162={};var _0x11a1b7={'count':0x0,'rows':[]};return db['SmsAccount'][_0xeaf9('0x68')]({'where':{'id':_0x15f8e3[_0xeaf9('0x59')]['id']}})[_0xeaf9('0x22')](handleEntityNotFound(_0xce72b1,null))[_0xeaf9('0x22')](function(_0x16bdd5){if(_0x16bdd5){_0x49b162['model']=_[_0xeaf9('0x44')](db['CannedAnswer'][_0xeaf9('0x6a')]);_0x49b162['query']=_['keys'](_0x15f8e3['query']);_0x49b162[_0xeaf9('0x45')]=_[_0xeaf9('0x46')](_0x49b162['model'],_0x49b162[_0xeaf9('0x43')]);_0x4bf03f['attributes']=_[_0xeaf9('0x46')](_0x49b162[_0xeaf9('0x4a')],qs[_0xeaf9('0x48')](_0x15f8e3[_0xeaf9('0x43')]['fields']));_0x4bf03f['attributes']=_0x4bf03f['attributes'][_0xeaf9('0x49')]?_0x4bf03f[_0xeaf9('0x47')]:_0x49b162[_0xeaf9('0x4a')];if(!_0x15f8e3[_0xeaf9('0x43')][_0xeaf9('0x4b')](_0xeaf9('0x4c'))){_0x4bf03f[_0xeaf9('0x4d')]=qs['limit'](_0x15f8e3[_0xeaf9('0x43')][_0xeaf9('0x4d')]);_0x4bf03f['offset']=qs['offset'](_0x15f8e3[_0xeaf9('0x43')][_0xeaf9('0x32')]);}_0x4bf03f[_0xeaf9('0x4e')]=qs['sort'](_0x15f8e3[_0xeaf9('0x43')][_0xeaf9('0x6b')]);_0x4bf03f[_0xeaf9('0x50')]=qs[_0xeaf9('0x45')](_[_0xeaf9('0x4f')](_0x15f8e3[_0xeaf9('0x43')],_0x49b162[_0xeaf9('0x45')]));_0x4bf03f[_0xeaf9('0x50')]['SmsAccountId']=_0x16bdd5['id'];if(_0x15f8e3['query']['filter']){_0x4bf03f['where']=_['merge'](_0x4bf03f[_0xeaf9('0x50')],{'$or':_[_0xeaf9('0x40')](_0x4bf03f[_0xeaf9('0x47')],function(_0x530c47){var _0x5808aa={};_0x5808aa[_0x530c47]={'$like':'%'+_0x15f8e3[_0xeaf9('0x43')][_0xeaf9('0x52')]+'%'};return _0x5808aa;})});}_0x4bf03f=_[_0xeaf9('0x51')]({},_0x4bf03f,_0x15f8e3[_0xeaf9('0x53')]);return db['CannedAnswer'][_0xeaf9('0x31')]({'where':_0x4bf03f[_0xeaf9('0x50')]})[_0xeaf9('0x22')](function(_0x3cd485){_0x11a1b7[_0xeaf9('0x31')]=_0x3cd485;if(_0x15f8e3[_0xeaf9('0x43')][_0xeaf9('0x55')]){_0x4bf03f[_0xeaf9('0x56')]=[{'all':!![]}];}return db[_0xeaf9('0x70')][_0xeaf9('0x6c')](_0x4bf03f);})[_0xeaf9('0x22')](function(_0x20125c){_0x11a1b7['rows']=_0x20125c;return _0x11a1b7;});}})[_0xeaf9('0x22')](respondWithFilteredResult(_0xce72b1,_0x4bf03f))[_0xeaf9('0x2c')](handleError(_0xce72b1,null));};exports[_0xeaf9('0x72')]=function(_0x4d5340,_0x389e10,_0x510893){return db['SmsAccount'][_0xeaf9('0x5b')]({'where':{'id':_0x4d5340['params']['id']}})[_0xeaf9('0x22')](handleEntityNotFound(_0x389e10,null))[_0xeaf9('0x22')](function(_0x47ce3c){if(_0x47ce3c){return _0x47ce3c[_0xeaf9('0x72')](_0x4d5340[_0xeaf9('0x43')]['ids']);}})['then'](respondWithStatusCode(_0x389e10,null))[_0xeaf9('0x2c')](handleError(_0x389e10,null));};exports[_0xeaf9('0x73')]=function(_0x45272a,_0x48f789,_0x1dc012){var _0x54a4ec={'channel':_0xeaf9('0x74')};var _0xbab89f=[];var _0x1595fd=[];var _0x501ab4={};return db['SmsAccount']['find']({'where':{'id':_0x45272a[_0xeaf9('0x59')]['id']},'include':[{'model':db['SmsApplication'],'as':_0xeaf9('0x75')}]})[_0xeaf9('0x22')](handleEntityNotFound(_0x48f789,null))[_0xeaf9('0x22')](function(_0x1959d4){_0x54a4ec['account']=_0x1959d4;_0x54a4ec['applications']=_[_0xeaf9('0x76')](_0x1959d4[_0xeaf9('0x75')],['priority'],[_0xeaf9('0x77')]);if(_0x54a4ec[_0xeaf9('0x78')][_0xeaf9('0x75')]){delete _0x54a4ec[_0xeaf9('0x78')][_0xeaf9('0x75')];}return db[_0xeaf9('0x79')]['describe']();})[_0xeaf9('0x22')](function(_0x43d822){if(!_0x43d822){throw new db[(_0xeaf9('0x7a'))][(_0xeaf9('0x7b'))](_0xeaf9('0x7c'));}_0xbab89f=_[_0xeaf9('0x7d')](_[_0xeaf9('0x44')](_0x43d822),[_0xeaf9('0x7e'),_0xeaf9('0x7f')]);_0x1595fd=_[_0xeaf9('0x7d')](_[_0xeaf9('0x44')](_0x43d822),['createdAt','updatedAt','CompanyId',_0xeaf9('0x80')]);_0x54a4ec[_0xeaf9('0x63')]={'mapKey':'mobile'};if(_0x54a4ec[_0xeaf9('0x78')]['type']){switch(_0x54a4ec[_0xeaf9('0x78')][_0xeaf9('0x41')]){case _0xeaf9('0x81'):_0x54a4ec[_0xeaf9('0x63')]['from']=_0x45272a[_0xeaf9('0x63')][_0xeaf9('0x82')];_0x54a4ec['body'][_0xeaf9('0x63')]=_0x45272a[_0xeaf9('0x63')][_0xeaf9('0x83')];_0x54a4ec['body'][_0xeaf9('0x84')]=_0x45272a[_0xeaf9('0x63')][_0xeaf9('0x85')];break;case _0xeaf9('0x86'):_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x87')]='+'+_0x45272a[_0xeaf9('0x63')][_0xeaf9('0x88')];_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x63')]=_0x45272a[_0xeaf9('0x63')]['text'];break;case _0xeaf9('0x89'):_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x87')]=_0x45272a['body'][_0xeaf9('0x87')];_0x54a4ec[_0xeaf9('0x63')]['body']=_0x45272a[_0xeaf9('0x63')][_0xeaf9('0x2a')];break;case'clicksend':_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x87')]=_0x45272a['body']['from'];_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x63')]=_0x45272a[_0xeaf9('0x63')][_0xeaf9('0x63')];_0x54a4ec[_0xeaf9('0x63')]['messageId']=_0x45272a[_0xeaf9('0x63')][_0xeaf9('0x8a')];break;case _0xeaf9('0x8b'):_0x54a4ec['body'][_0xeaf9('0x87')]=_0x45272a['body'][_0xeaf9('0x82')];_0x54a4ec['body'][_0xeaf9('0x63')]=_0x45272a[_0xeaf9('0x63')][_0xeaf9('0x8c')];_0x54a4ec[_0xeaf9('0x63')]['messageId']=_0x45272a[_0xeaf9('0x63')][_0xeaf9('0x8d')];break;case _0xeaf9('0x8e'):_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x87')]='+'+_0x45272a[_0xeaf9('0x63')][_0xeaf9('0x8f')][0x0][_0xeaf9('0x87')];_0x54a4ec[_0xeaf9('0x63')]['body']=_0x45272a[_0xeaf9('0x63')][_0xeaf9('0x8f')][0x0][_0xeaf9('0x90')];_0x54a4ec['body'][_0xeaf9('0x84')]=_0x45272a['body'][_0xeaf9('0x8f')][0x0][_0xeaf9('0x84')];break;case _0xeaf9('0x91'):_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x87')]=_0x45272a['body'][_0xeaf9('0x92')];_0x54a4ec['body'][_0xeaf9('0x63')]=_0x45272a['body'][_0xeaf9('0x93')]['message'];break;case'clickatell':_0x54a4ec[_0xeaf9('0x63')]['from']=_0x45272a[_0xeaf9('0x63')][_0xeaf9('0x94')];_0x54a4ec['body'][_0xeaf9('0x63')]=_0x45272a[_0xeaf9('0x63')]['text'];_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x84')]=_0x45272a['body'][_0xeaf9('0x95')];break;case _0xeaf9('0x96'):_0x54a4ec[_0xeaf9('0x63')]['messageId']=_0x45272a['body'][0x0][_0xeaf9('0x2a')]['id'];_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x87')]=_0x45272a['body'][0x0][_0xeaf9('0x2a')][_0xeaf9('0x87')];_0x54a4ec['body']['body']=_0x45272a[_0xeaf9('0x63')][0x0][_0xeaf9('0x2a')][_0xeaf9('0x90')];break;case'intelepeer':_0x54a4ec[_0xeaf9('0x63')]['from']=_0x45272a['body']['from'];_0x54a4ec[_0xeaf9('0x63')]['body']=_0x45272a[_0xeaf9('0x63')]['message'];_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x84')]=_0x45272a['body'][_0xeaf9('0x97')];break;}}if(_0x54a4ec[_0xeaf9('0x63')]['id']){delete _0x54a4ec[_0xeaf9('0x63')]['id'];}if(_[_0xeaf9('0x98')](_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x87')])){throw new db[(_0xeaf9('0x7a'))]['ValidationError']('from\x20is\x20mandatory');}if(_[_0xeaf9('0x98')](_0x54a4ec['body'][_0xeaf9('0x63')])||_0x54a4ec[_0xeaf9('0x63')]['body']===''){throw new db[(_0xeaf9('0x7a'))]['ValidationError']('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0xeaf9('0x98')](_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x99')])){throw new db[(_0xeaf9('0x7a'))][(_0xeaf9('0x7b'))](_0xeaf9('0x9a')+_0x1595fd);}if(!_[_0xeaf9('0x9b')](_0x1595fd,_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x99')])){throw new db[(_0xeaf9('0x7a'))][(_0xeaf9('0x7b'))]('mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x1595fd);}_0x501ab4[_0x54a4ec[_0xeaf9('0x63')]['mapKey']]=_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x87')];return db[_0xeaf9('0x9c')]['find']({'where':{'id':_0x54a4ec[_0xeaf9('0x78')][_0xeaf9('0x80')]},'include':[{'model':db[_0xeaf9('0x79')],'as':_0xeaf9('0x9d'),'where':_0x501ab4,'limit':0x1,'order':[[_0xeaf9('0x7f'),_0xeaf9('0x9e')]]}]});})[_0xeaf9('0x22')](handleEntityNotFound(_0x48f789,null))[_0xeaf9('0x22')](function(_0x1d49df){if(_0x1d49df){_0x54a4ec[_0xeaf9('0x9f')]=_['omit'](_0x1d49df,['Contacts']);if(_0x1d49df['Contacts'][_0xeaf9('0x49')]){return _0x1d49df[_0xeaf9('0x9d')][0x0];}var _0x3f3c79=_[_0xeaf9('0x1b')](_0x54a4ec[_0xeaf9('0x63')],{'firstName':_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x87')],'ListId':_0x1d49df['id']});_0x3f3c79[_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x99')]]=_0x54a4ec[_0xeaf9('0x63')]['from'];return db[_0xeaf9('0x79')][_0xeaf9('0x5c')](_0x3f3c79,{'fields':_0xbab89f,'raw':!![]});}})[_0xeaf9('0x22')](handleEntityNotFound(_0x48f789,null))[_0xeaf9('0x22')](function(_0x56c854){if(_0x56c854){_0x54a4ec[_0xeaf9('0xa0')]=_0x56c854;var _0x25637e={'ContactId':_0x56c854['id'],'phone':_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x87')],'SmsAccountId':_0x45272a['params']['id']};var _0x79ef0a={'ContactId':_0x56c854['id'],'SmsAccountId':_0x45272a[_0xeaf9('0x59')]['id'],'closed':![]};return db[_0xeaf9('0xa1')]['find']({'where':_0x79ef0a})['then'](function(_0x4bfe01){if(_0x4bfe01){return[_0x4bfe01,![]];}return db['SmsInteraction'][_0xeaf9('0x5c')](_0x25637e)['then'](function(_0x59ca51){return[_0x59ca51,!![]];});});}})[_0xeaf9('0xa2')](function(_0x4527ce,_0x71ad6e){_0x54a4ec[_0xeaf9('0xa3')]=_0x4527ce[_0xeaf9('0x5e')]({'plain':!![]});_0x54a4ec['interaction']['created']=![];if(_0x71ad6e){if(_0x54a4ec['account'][_0xeaf9('0xa4')]){_0x54a4ec['applications'][_0xeaf9('0xa5')]({'id':0x0,'priority':_0x54a4ec[_0xeaf9('0xa6')][_0xeaf9('0x49')]+0x1,'app':_0xeaf9('0xa7'),'appdata':_0xeaf9('0xa8'),'interval':_0xeaf9('0xa9')});}_0x54a4ec[_0xeaf9('0xa3')]['created']=!![];}return db[_0xeaf9('0xaa')][_0xeaf9('0x5c')]({'phone':_0x54a4ec[_0xeaf9('0x63')][_0xeaf9('0x87')],'messageId':_0x54a4ec['body'][_0xeaf9('0x84')],'body':_0x54a4ec['body'][_0xeaf9('0x63')],'SmsAccountId':_0x45272a['params']['id'],'SmsInteractionId':_0x4527ce['id'],'direction':'in','ContactId':_0x4527ce[_0xeaf9('0xab')],'AttachmentId':_0x54a4ec['body']['AttachmentId']});})['then'](function(_0x56fca0){_0x54a4ec[_0xeaf9('0x2a')]=_0x56fca0;if(_0x54a4ec[_0xeaf9('0xa3')][_0xeaf9('0xac')]){return db[_0xeaf9('0xad')][_0xeaf9('0x5b')]({'attributes':['id',_0xeaf9('0x3c')],'where':{'id':_0x54a4ec[_0xeaf9('0xa3')][_0xeaf9('0xac')]}})[_0xeaf9('0x22')](function(_0x2dd97e){if(_0x2dd97e){_0x54a4ec['applications'][_0xeaf9('0xae')]({'id':0x0,'priority':0x0,'app':_0xeaf9('0xaf'),'appdata':_0x2dd97e['name']+','+(_0x54a4ec[_0xeaf9('0x78')]['waitForTheAssignedAgent']||0xa),'interval':_0xeaf9('0xa9')});}return respondWithRpcPromise('Start','startRouting',_0x54a4ec);});}return respondWithRpcPromise('Start',_0xeaf9('0xb0'),_0x54a4ec);})[_0xeaf9('0x22')](function(_0x4de8a0){if(_0x4de8a0){var _0x396706=0xc8;var _0x52a698='receiveMessage';logger[_0xeaf9('0x23')](_0xeaf9('0xb1'),_0x52a698,_0x396706,_0xeaf9('0xb2'));logger['debug'](_0xeaf9('0xb3'),_0x52a698,_0x396706,_0xeaf9('0xb2'),JSON[_0xeaf9('0x26')](_0x4de8a0));if(_0x54a4ec['account'][_0xeaf9('0x41')]===_0xeaf9('0x81')){return _0x48f789[_0xeaf9('0x2e')](_0x396706)[_0xeaf9('0x33')](_0xeaf9('0xb4'),_0xeaf9('0xb5'))[_0xeaf9('0x3d')](_0xeaf9('0xb6'));}else{return _0x48f789['status'](_0x396706)[_0xeaf9('0x34')](_0x4de8a0);}}})[_0xeaf9('0x2c')](handleError(_0x48f789,null));};exports['addApplications']=function(_0x4e7271,_0x24e165){var _0x74c094=_0x4e7271[_0xeaf9('0x59')]['id'];var _0x33fd6a=_0x4e7271[_0xeaf9('0x63')];var _0x3c0b8f=0xc8;var _0x4a6347=null;return db['sequelize'][_0xeaf9('0xb7')]({'isolationLevel':db['sequelize'][_0xeaf9('0xb8')][_0xeaf9('0xb9')][_0xeaf9('0xba')]},function(_0x120b10){return db[_0xeaf9('0x54')][_0xeaf9('0x68')]({'where':{'id':_0x74c094},'transaction':_0x120b10})[_0xeaf9('0x22')](function(_0x2050d7){if(_0x2050d7){return db[_0xeaf9('0xbb')][_0xeaf9('0x38')]({'where':{'SmsAccountId':_0x74c094},'transaction':_0x120b10})[_0xeaf9('0x22')](function(){var _0x4001ac=_[_0xeaf9('0x40')](_0x33fd6a,function(_0x26275d){_0x26275d[_0xeaf9('0x66')]=_0x74c094;return _0x26275d;});return db[_0xeaf9('0xbb')]['bulkCreate'](_0x4001ac,{'transaction':_0x120b10});});}else{_0x3c0b8f=0x194;_0x4a6347=[];}});})[_0xeaf9('0x22')](function(){if(_0x3c0b8f!==0x194){return db['SmsApplication'][_0xeaf9('0xbc')]({'where':{'SmsAccountId':_0x74c094},'order':_0xeaf9('0xbd')})[_0xeaf9('0x22')](function(_0x4d350d){_0x4a6347=_0x4d350d;});}})['catch'](function(_0x1b41f9){_0x3c0b8f=0x1f4;logger[_0xeaf9('0x27')](_0x1b41f9[_0xeaf9('0x3b')]);if(_0x1b41f9[_0xeaf9('0x3c')]){delete _0x1b41f9[_0xeaf9('0x3c')];}_0x4a6347=_0x1b41f9;})[_0xeaf9('0xbe')](function(){if(_0x4a6347===null){_0x24e165['sendStatus'](_0x3c0b8f);}else{if(_0x3c0b8f===0x1f4){_0x24e165[_0xeaf9('0x2e')](_0x3c0b8f)[_0xeaf9('0x3d')](_0x4a6347);}else{_0x24e165[_0xeaf9('0x2e')](_0x3c0b8f)[_0xeaf9('0x34')](_0x4a6347);}}});};exports['getApplications']=function(_0x44af0f,_0x1b2097,_0xe48055){var _0xc69d84={};var _0x41d6fe={};var _0x4be25a;var _0x2fad53;return db[_0xeaf9('0x54')][_0xeaf9('0x68')]({'where':{'id':_0x44af0f[_0xeaf9('0x59')]['id']}})[_0xeaf9('0x22')](handleEntityNotFound(_0x1b2097,null))[_0xeaf9('0x22')](function(_0x4d757f){if(_0x4d757f){_0x4be25a=_0x4d757f;_0x41d6fe[_0xeaf9('0x4a')]=_['keys'](db[_0xeaf9('0xbb')]['rawAttributes']);_0x41d6fe[_0xeaf9('0x43')]=_[_0xeaf9('0x44')](_0x44af0f[_0xeaf9('0x43')]);_0x41d6fe[_0xeaf9('0x45')]=_['intersection'](_0x41d6fe[_0xeaf9('0x4a')],_0x41d6fe[_0xeaf9('0x43')]);_0xc69d84[_0xeaf9('0x47')]=_['intersection'](_0x41d6fe[_0xeaf9('0x4a')],qs['fields'](_0x44af0f['query'][_0xeaf9('0x48')]));_0xc69d84['attributes']=_0xc69d84[_0xeaf9('0x47')][_0xeaf9('0x49')]?_0xc69d84[_0xeaf9('0x47')]:_0x41d6fe[_0xeaf9('0x4a')];_0xc69d84['order']=qs[_0xeaf9('0x6b')](_0x44af0f[_0xeaf9('0x43')]['sort']);_0xc69d84['where']=qs['filters'](_['pick'](_0x44af0f[_0xeaf9('0x43')],_0x41d6fe[_0xeaf9('0x45')]));if(_0x44af0f[_0xeaf9('0x43')]['filter']){_0xc69d84[_0xeaf9('0x50')]=_['merge'](_0xc69d84[_0xeaf9('0x50')],{'$or':_['map'](_0xc69d84[_0xeaf9('0x47')],function(_0x1c4a0e){var _0x385a93={};_0x385a93[_0x1c4a0e]={'$like':'%'+_0x44af0f['query'][_0xeaf9('0x52')]+'%'};return _0x385a93;})});}_0xc69d84=_[_0xeaf9('0x51')]({},_0xc69d84,_0x44af0f[_0xeaf9('0x53')]);return _0x4be25a['getApplications'](_0xc69d84);}})[_0xeaf9('0x22')](function(_0x509ccb){if(_0x509ccb){_0x2fad53=_0x509ccb[_0xeaf9('0x49')];if(!_0x44af0f[_0xeaf9('0x43')][_0xeaf9('0x4b')](_0xeaf9('0x4c'))){_0xc69d84['limit']=qs[_0xeaf9('0x4d')](_0x44af0f[_0xeaf9('0x43')]['limit']);_0xc69d84[_0xeaf9('0x32')]=qs[_0xeaf9('0x32')](_0x44af0f[_0xeaf9('0x43')][_0xeaf9('0x32')]);}return _0x4be25a[_0xeaf9('0xbf')](_0xc69d84);}})[_0xeaf9('0x22')](function(_0x4f890b){if(_0x4f890b){return _0x4f890b?{'count':_0x2fad53,'rows':_0x4f890b}:null;}})[_0xeaf9('0x22')](respondWithResult(_0x1b2097,null))[_0xeaf9('0x2c')](handleError(_0x1b2097,null));};exports[_0xeaf9('0xc0')]=function(_0x43de75,_0x54ca87,_0x38c8a0){var _0x2c0dfe={'raw':![],'where':{}};var _0x25617c={};var _0x33a97a={'count':0x0,'rows':[]};return db[_0xeaf9('0x54')][_0xeaf9('0x68')]({'where':{'id':_0x43de75[_0xeaf9('0x59')]['id']}})[_0xeaf9('0x22')](handleEntityNotFound(_0x54ca87,null))[_0xeaf9('0x22')](function(_0x37ae4d){if(_0x37ae4d){_0x25617c[_0xeaf9('0x4a')]=_[_0xeaf9('0x44')](db['SmsInteraction']['rawAttributes']);_0x25617c[_0xeaf9('0x43')]=_[_0xeaf9('0x44')](_0x43de75[_0xeaf9('0x43')]);_0x25617c['filters']=_[_0xeaf9('0x46')](_0x25617c[_0xeaf9('0x4a')],_0x25617c[_0xeaf9('0x43')]);_0x2c0dfe[_0xeaf9('0x47')]=_[_0xeaf9('0x46')](_0x25617c[_0xeaf9('0x4a')],qs[_0xeaf9('0x48')](_0x43de75[_0xeaf9('0x43')][_0xeaf9('0x48')]));_0x2c0dfe[_0xeaf9('0x47')]=_0x2c0dfe['attributes'][_0xeaf9('0x49')]?_0x2c0dfe[_0xeaf9('0x47')]:_0x25617c[_0xeaf9('0x4a')];if(!_0x43de75['query']['hasOwnProperty'](_0xeaf9('0x4c'))){_0x2c0dfe['limit']=qs[_0xeaf9('0x4d')](_0x43de75[_0xeaf9('0x43')][_0xeaf9('0x4d')]);_0x2c0dfe[_0xeaf9('0x32')]=qs[_0xeaf9('0x32')](_0x43de75[_0xeaf9('0x43')]['offset']);}_0x2c0dfe[_0xeaf9('0x4e')]=qs[_0xeaf9('0x6b')](_0x43de75[_0xeaf9('0x43')][_0xeaf9('0x6b')]);_0x2c0dfe[_0xeaf9('0x50')]=qs[_0xeaf9('0x45')](_[_0xeaf9('0x4f')](_0x43de75[_0xeaf9('0x43')],_0x25617c[_0xeaf9('0x45')]));_0x2c0dfe['where'][_0xeaf9('0x66')]=_0x37ae4d['id'];if(_0x43de75[_0xeaf9('0x43')]['filter']){_0x2c0dfe[_0xeaf9('0x50')]=_['merge'](_0x2c0dfe[_0xeaf9('0x50')],{'$or':_['map'](_0x2c0dfe['attributes'],function(_0x1b99b9){var _0x292d2a={};_0x292d2a[_0x1b99b9]={'$like':'%'+_0x43de75[_0xeaf9('0x43')][_0xeaf9('0x52')]+'%'};return _0x292d2a;})});}_0x2c0dfe=_[_0xeaf9('0x51')]({},_0x2c0dfe,_0x43de75['options']);return db[_0xeaf9('0xa1')]['count']({'where':_0x2c0dfe[_0xeaf9('0x50')]})[_0xeaf9('0x22')](function(_0x1aea70){_0x33a97a[_0xeaf9('0x31')]=_0x1aea70;if(_0x43de75[_0xeaf9('0x43')][_0xeaf9('0x55')]){_0x2c0dfe[_0xeaf9('0x56')]=[{'model':db['CmContact'],'as':_0xeaf9('0xc1'),'required':![]},{'model':db[_0xeaf9('0xad')],'as':_0xeaf9('0xc2'),'attributes':[_0xeaf9('0x3c'),_0xeaf9('0xc3'),_0xeaf9('0xc4')],'required':![]},{'model':db['Tag'],'as':_0xeaf9('0xc5'),'attributes':['id','name',_0xeaf9('0xc6')],'where':_0x43de75[_0xeaf9('0x43')][_0xeaf9('0xc7')]?{'id':_0x43de75[_0xeaf9('0x43')]['tag']}:undefined,'required':_0x43de75[_0xeaf9('0x43')][_0xeaf9('0xc7')]?!![]:![]}];}return db[_0xeaf9('0xa1')]['findAll'](_0x2c0dfe);})[_0xeaf9('0x22')](function(_0x3417ed){_0x33a97a['rows']=_0x3417ed;return _0x33a97a;});}})['then'](respondWithFilteredResult(_0x54ca87,_0x2c0dfe))[_0xeaf9('0x2c')](handleError(_0x54ca87,null));};exports[_0xeaf9('0x3d')]=function(_0x59f650,_0x312e79,_0x387805){var _0x1392cc,_0x16b026,_0x9d1728;if(_[_0xeaf9('0x98')](_0x59f650[_0xeaf9('0x63')][_0xeaf9('0x63')])||_0x59f650[_0xeaf9('0x63')][_0xeaf9('0x63')]===''){throw new db[(_0xeaf9('0x7a'))][(_0xeaf9('0x7b'))](_0xeaf9('0xc8'));}if(_['isNil'](_0x59f650[_0xeaf9('0x63')]['to'])){throw new db['Sequelize'][(_0xeaf9('0x7b'))](_0xeaf9('0xc9'));}_0x1392cc=_0x59f650[_0xeaf9('0x63')]['to'];return db[_0xeaf9('0x54')][_0xeaf9('0x5b')]({'where':{'id':_0x59f650['params']['id']},'include':[{'model':db[_0xeaf9('0x9c')],'as':_0xeaf9('0xca'),'include':[{'model':db[_0xeaf9('0x79')],'as':'Contacts','where':{'mobile':_0x1392cc},'limit':0x1,'order':[[_0xeaf9('0x7f'),_0xeaf9('0x9e')]]}]}]})[_0xeaf9('0x22')](handleEntityNotFound(_0x312e79,null))['then'](function(_0x853f87){if(_0x853f87&&_0x853f87[_0xeaf9('0xca')]){_0x16b026=_0x853f87['get']({'plain':!![]});if(_0x16b026['List']&&_0x16b026[_0xeaf9('0xca')][_0xeaf9('0x9d')][_0xeaf9('0x49')]){return _0x16b026[_0xeaf9('0xca')][_0xeaf9('0x9d')][0x0];}return db[_0xeaf9('0x79')][_0xeaf9('0x5c')](_[_0xeaf9('0x1b')](_0x59f650['body'],{'firstName':_0x1392cc,'mobile':_0x1392cc,'phone':_0x1392cc,'ListId':_0x16b026[_0xeaf9('0x80')]}));}})[_0xeaf9('0x22')](handleEntityNotFound(_0x312e79,null))['then'](function(_0x144b20){if(_0x144b20){_0x9d1728=_0x144b20;return db[_0xeaf9('0xa1')][_0xeaf9('0x5b')]({'where':{'ContactId':_0x9d1728['id'],'closed':![],'SmsAccountId':_0x16b026['id']}})['then'](function(_0x153ef2){if(_0x153ef2){return[_0x153ef2,![]];}return db[_0xeaf9('0xa1')][_0xeaf9('0x5c')]({'UserId':_0x59f650[_0xeaf9('0x5d')]['id'],'ContactId':_0x9d1728['id'],'SmsAccountId':_0x16b026['id'],'phone':_0x1392cc,'firstMsgDirection':_0xeaf9('0xcb'),'Messages':[_['merge'](_0x59f650[_0xeaf9('0x63')],{'read':![],'body':_0x59f650[_0xeaf9('0x63')][_0xeaf9('0x63')],'phone':_0x1392cc,'SmsAccountId':_0x16b026['id'],'UserId':_0x59f650[_0xeaf9('0x5d')]['id'],'ContactId':_0x9d1728['id']})]},{'include':[{'model':db[_0xeaf9('0xaa')],'as':_0xeaf9('0xcc')}]})['then'](function(_0x544193){return[_0x544193,!![]];});});}})[_0xeaf9('0xa2')](function(_0x2f7896,_0x2bd188){if(_0x2bd188){return _0x2f7896;}return db[_0xeaf9('0xaa')]['create'](_[_0xeaf9('0x51')](_0x59f650[_0xeaf9('0x63')],{'read':![],'body':_0x59f650['body'][_0xeaf9('0x63')],'phone':_0x1392cc,'SmsAccountId':_0x16b026['id'],'SmsInteractionId':_0x2f7896['id'],'UserId':_0x59f650['user']['id'],'ContactId':_0x9d1728['id']}))[_0xeaf9('0x22')](function(_0x9a03b3){_0x2f7896['dataValues'][_0xeaf9('0xcc')]=[];_0x2f7896[_0xeaf9('0xcd')][_0xeaf9('0xcc')][_0xeaf9('0xa5')](_0x9a03b3[_0xeaf9('0xcd')]);return _0x2f7896;});})[_0xeaf9('0x22')](respondWithResult(_0x312e79,null))[_0xeaf9('0x2c')](handleError(_0x312e79,null));};exports['status']=function(_0x15bc03,_0x1fe7a9,_0x1f521c){if(_0x15bc03['body']['id']){delete _0x15bc03['body']['id'];}var _0x54cd85,_0x5d7754,_0x61f3da;return db[_0xeaf9('0x54')][_0xeaf9('0x5b')]({'where':{'id':_0x15bc03[_0xeaf9('0x59')]['id']}})[_0xeaf9('0x22')](handleEntityNotFound(_0x1fe7a9,null))[_0xeaf9('0x22')](function(_0x370782){if(_0x370782){_0x61f3da=_0x370782;logger['debug'](_0xeaf9('0xb1'),'status',_0xeaf9('0xce'),_0x370782['type'],util[_0xeaf9('0xcf')](_0x15bc03[_0xeaf9('0x63')],{'showHidden':![],'depth':null}));switch(_0x370782[_0xeaf9('0x41')]){case _0xeaf9('0x86'):if(_0x15bc03['body']['skebby_dispatch_id']&&_0x15bc03[_0xeaf9('0x63')][_0xeaf9('0x2e')]){_0x5d7754=_0x15bc03[_0xeaf9('0x63')][_0xeaf9('0x2e')];return db[_0xeaf9('0xaa')][_0xeaf9('0x5b')]({'where':{'messageId':_0x15bc03[_0xeaf9('0x63')][_0xeaf9('0xd0')]}});}break;case _0xeaf9('0x89'):if(_0x15bc03['body'][_0xeaf9('0xd1')]&&_0x15bc03[_0xeaf9('0x63')][_0xeaf9('0xd2')]){_0x5d7754=_0x15bc03[_0xeaf9('0x63')][_0xeaf9('0xd2')];return db[_0xeaf9('0xaa')]['find']({'where':{'messageId':_0x15bc03['body'][_0xeaf9('0xd1')]}});}break;case _0xeaf9('0xd3'):if(_0x15bc03[_0xeaf9('0x63')][_0xeaf9('0x8a')]&&_0x15bc03[_0xeaf9('0x63')]['status_code']){_0x5d7754=_0x15bc03['body'][_0xeaf9('0xd4')];return db['SmsMessage'][_0xeaf9('0x5b')]({'where':{'messageId':_0x15bc03[_0xeaf9('0x63')]['message_id']}});}break;case _0xeaf9('0x8e'):var _0x22d058=_0x15bc03[_0xeaf9('0x63')][_0xeaf9('0x8f')][0x0];if(_0x22d058['messageId']&&_0x22d058[_0xeaf9('0x2e')][_0xeaf9('0xd5')]===_0xeaf9('0xd6')){_0x5d7754=_0x22d058[_0xeaf9('0x2e')]['groupName'];return db['SmsMessage'][_0xeaf9('0x5b')]({'where':{'messageId':_0x22d058[_0xeaf9('0x84')]}});}break;case _0xeaf9('0xd7'):if(_0x15bc03[_0xeaf9('0x63')]['messageId']&&_0x15bc03[_0xeaf9('0x63')][_0xeaf9('0x2e')]){_0x5d7754=_0x15bc03['body'][_0xeaf9('0x2e')];return db[_0xeaf9('0xaa')][_0xeaf9('0x5b')]({'where':{'messageId':_0x15bc03['body']['messageId']}});}break;case _0xeaf9('0x96'):if(_0x15bc03['body'][0x0][_0xeaf9('0x2a')]['id']){_0x5d7754=_0x15bc03['body'][0x0]['type'];return db[_0xeaf9('0xaa')][_0xeaf9('0x5b')]({'where':{'messageId':_0x15bc03['body'][0x0][_0xeaf9('0x2a')]['id']}});}break;case _0xeaf9('0xd8'):if(_0x15bc03['body'][_0xeaf9('0xd9')]&&_0x15bc03[_0xeaf9('0x63')]['status']){_0x5d7754=_0x15bc03['body'][_0xeaf9('0x2e')];return db[_0xeaf9('0xaa')][_0xeaf9('0x5b')]({'where':{'messageId':_0x15bc03['body'][_0xeaf9('0xd9')]}});}break;}}})['then'](handleEntityNotFound(_0x1fe7a9,null))['then'](function(_0x3667f0){if(_0x3667f0){_0x54cd85=_0x3667f0;switch(_0x61f3da[_0xeaf9('0x41')]){case _0xeaf9('0x86'):if(_0x5d7754===_0xeaf9('0xd6')){return _0x54cd85[_0xeaf9('0x37')]({'read':!![]});}else{logger[_0xeaf9('0x27')](_0xeaf9('0xb1'),_0xeaf9('0x2e'),_0xeaf9('0x86'),util[_0xeaf9('0xcf')](_0x15bc03[_0xeaf9('0x63')],{'showHidden':![],'depth':null}));}break;case _0xeaf9('0x89'):if(_0x5d7754==='1'){return _0x54cd85[_0xeaf9('0x37')]({'read':!![]});}else{logger[_0xeaf9('0x27')]('SmsAccount,\x20%s,\x20%s,\x20%s','status',_0xeaf9('0x86'),util[_0xeaf9('0xcf')](_0x15bc03[_0xeaf9('0x63')],{'showHidden':![],'depth':null}));}break;case'clicksend':if(!_0x15bc03[_0xeaf9('0x63')][_0xeaf9('0xda')]&&_0x5d7754>=0xc8&&_0x5d7754<=0xce){return _0x54cd85[_0xeaf9('0x37')]({'read':!![]});}else{logger[_0xeaf9('0x27')]('SmsAccount,\x20%s,\x20%s,\x20%s','status',_0xeaf9('0xd3'),util[_0xeaf9('0xcf')](_0x15bc03[_0xeaf9('0x63')],{'showHidden':![],'depth':null}));}break;case'infobip':var _0xdf4729=_0x15bc03[_0xeaf9('0x63')][_0xeaf9('0x8f')][0x0];if(_0xdf4729[_0xeaf9('0x2e')]['groupName']===_0xeaf9('0xd6')){return _0x54cd85['update']({'read':!![]});}else{logger['error'](_0xeaf9('0xb1'),_0xeaf9('0x2e'),_0xeaf9('0x8e'),util[_0xeaf9('0xcf')](_0x15bc03[_0xeaf9('0x63')],{'showHidden':![],'depth':null}));}break;case _0xeaf9('0xd7'):if(_0x5d7754==_0xeaf9('0xdb')||_0x5d7754==_0xeaf9('0xdc')){return _0x54cd85['update']({'read':!![]});}else{logger[_0xeaf9('0x27')](_0xeaf9('0xb1'),_0xeaf9('0x2e'),'clickatell',util[_0xeaf9('0xcf')](_0x15bc03[_0xeaf9('0x63')],{'showHidden':![],'depth':null}));}break;case _0xeaf9('0x96'):if(_0x5d7754==_0xeaf9('0xdd')){return _0x54cd85[_0xeaf9('0x37')]({'read':!![]});}else{logger['error'](_0xeaf9('0xb1'),'status',_0xeaf9('0x96'),util[_0xeaf9('0xcf')](_0x15bc03[_0xeaf9('0x63')],{'showHidden':![],'depth':null}));}break;case _0xeaf9('0xd8'):if(_0x5d7754===_0xeaf9('0xde')||_0x5d7754===_0xeaf9('0xdf')){return _0x54cd85[_0xeaf9('0x37')]({'read':!![]});}else{logger[_0xeaf9('0x27')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0xeaf9('0x2e'),_0xeaf9('0xd8'),util[_0xeaf9('0xcf')](_0x15bc03['body'],{'showHidden':![],'depth':null}));}break;}return _0x54cd85;}})[_0xeaf9('0x22')](respondWithResult(_0x1fe7a9,null))['catch'](handleError(_0x1fe7a9,null));};exports[_0xeaf9('0xe0')]=function(_0x5577a2,_0x44d700,_0xb1d4e1){var _0x177baa,_0x366784,_0x58e9f4;return db[_0xeaf9('0x54')][_0xeaf9('0x5b')]({'where':{'id':_0x5577a2[_0xeaf9('0x59')]['id']}})[_0xeaf9('0x22')](handleEntityNotFound(_0x44d700,null))[_0xeaf9('0x22')](function(_0x1c8fb7){if(_0x1c8fb7){_0x58e9f4=_0x1c8fb7;logger[_0xeaf9('0x25')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0xeaf9('0x2e'),_0xeaf9('0xce'),_0x1c8fb7[_0xeaf9('0x41')],util[_0xeaf9('0xcf')](_0x5577a2[_0xeaf9('0x43')],{'showHidden':![],'depth':null}));switch(_0x1c8fb7[_0xeaf9('0x41')]){case _0xeaf9('0x91'):if(_0x5577a2[_0xeaf9('0x43')][_0xeaf9('0xe1')]&&_0x5577a2['query'][_0xeaf9('0xe2')]){_0x366784=_0x5577a2['query'][_0xeaf9('0xe2')];return db[_0xeaf9('0xaa')][_0xeaf9('0x5b')]({'where':{'messageId':_0x5577a2[_0xeaf9('0x43')][_0xeaf9('0xe1')]}});}break;}}})[_0xeaf9('0x22')](handleEntityNotFound(_0x44d700,null))['then'](function(_0x251dda){if(_0x251dda){_0x177baa=_0x251dda;switch(_0x58e9f4['type']){case _0xeaf9('0x91'):if(_0x366784==='2'||_0x366784==='6'){return _0x177baa[_0xeaf9('0x37')]({'read':!![]});}else{logger[_0xeaf9('0x27')](_0xeaf9('0xb1'),_0xeaf9('0x2e'),'csc',util[_0xeaf9('0xcf')](_0x5577a2[_0xeaf9('0x43')],{'showHidden':![],'depth':null}));};break;}return _0x177baa;}})[_0xeaf9('0x22')](respondWithResult(_0x44d700,null))[_0xeaf9('0x2c')](handleError(_0x44d700,null));};exports['addAgents']=function(_0x5a6cb7,_0x2e5a29,_0x212143){return db[_0xeaf9('0x54')][_0xeaf9('0x5b')]({'where':{'id':_0x5a6cb7[_0xeaf9('0x59')]['id']}})[_0xeaf9('0x22')](handleEntityNotFound(_0x2e5a29,null))['then'](function(_0x50ee91){if(_0x50ee91){return _0x50ee91[_0xeaf9('0xe3')](_0x5a6cb7[_0xeaf9('0x63')]['ids'],_[_0xeaf9('0xe4')](_0x5a6cb7[_0xeaf9('0x63')],['ids','id'])||{})[_0xeaf9('0xa2')](function(_0x326176){for(var _0x1e2da6=0x0;_0x1e2da6<_0x5a6cb7[_0xeaf9('0x63')][_0xeaf9('0x6e')][_0xeaf9('0x49')];_0x1e2da6+=0x1){socket[_0xeaf9('0xe5')](_0xeaf9('0xe6'),{'UserId':Number(_0x5a6cb7[_0xeaf9('0x63')][_0xeaf9('0x6e')][_0x1e2da6]),'SmsAccountId':Number(_0x5a6cb7[_0xeaf9('0x59')]['id'])});}return _0x326176;});}})[_0xeaf9('0x22')](respondWithResult(_0x2e5a29,null))[_0xeaf9('0x2c')](handleError(_0x2e5a29,null));};exports[_0xeaf9('0xe7')]=function(_0x29b118,_0x4ec05c,_0x49454c){return db[_0xeaf9('0x54')]['find']({'where':{'id':_0x29b118['params']['id']}})[_0xeaf9('0x22')](handleEntityNotFound(_0x4ec05c,null))[_0xeaf9('0x22')](function(_0x2de83d){if(_0x2de83d){return _0x2de83d[_0xeaf9('0xe7')](_0x29b118['query']['ids'])[_0xeaf9('0x22')](function(){if(_[_0xeaf9('0xe8')](_0x29b118[_0xeaf9('0x43')][_0xeaf9('0x6e')])){for(var _0x54bf7d=0x0;_0x54bf7d<_0x29b118['query']['ids'][_0xeaf9('0x49')];_0x54bf7d+=0x1){socket[_0xeaf9('0xe5')](_0xeaf9('0xe9'),{'UserId':Number(_0x29b118[_0xeaf9('0x43')][_0xeaf9('0x6e')][_0x54bf7d]),'SmsAccountId':Number(_0x29b118['params']['id'])});}}else{socket[_0xeaf9('0xe5')]('userSmsAccount:remove',{'UserId':Number(_0x29b118[_0xeaf9('0x43')][_0xeaf9('0x6e')]),'SmsAccountId':Number(_0x29b118[_0xeaf9('0x59')]['id'])});}});}})[_0xeaf9('0x22')](respondWithStatusCode(_0x4ec05c,null))['catch'](handleError(_0x4ec05c,null));};exports[_0xeaf9('0xea')]=function(_0x22af22,_0x4a9fad,_0x4a8a24){var _0x2759fb={};var _0x5050ff={};var _0x224caa;var _0x4eaaf0;return db['SmsAccount'][_0xeaf9('0x68')]({'where':{'id':_0x22af22[_0xeaf9('0x59')]['id']}})[_0xeaf9('0x22')](handleEntityNotFound(_0x4a9fad,null))['then'](function(_0x50136c){if(_0x50136c){_0x224caa=_0x50136c;_0x5050ff[_0xeaf9('0x4a')]=_[_0xeaf9('0x44')](db['User'][_0xeaf9('0x6a')]);_0x5050ff[_0xeaf9('0x43')]=_[_0xeaf9('0x44')](_0x22af22[_0xeaf9('0x43')]);_0x5050ff['filters']=_[_0xeaf9('0x46')](_0x5050ff[_0xeaf9('0x4a')],_0x5050ff['query']);_0x2759fb[_0xeaf9('0x47')]=_[_0xeaf9('0x46')](_0x5050ff[_0xeaf9('0x4a')],qs['fields'](_0x22af22[_0xeaf9('0x43')][_0xeaf9('0x48')]));_0x2759fb[_0xeaf9('0x47')]=_0x2759fb[_0xeaf9('0x47')]['length']?_0x2759fb['attributes']:_0x5050ff['model'];_0x2759fb[_0xeaf9('0x4e')]=qs[_0xeaf9('0x6b')](_0x22af22[_0xeaf9('0x43')][_0xeaf9('0x6b')]);_0x2759fb[_0xeaf9('0x50')]=qs[_0xeaf9('0x45')](_[_0xeaf9('0x4f')](_0x22af22['query'],_0x5050ff[_0xeaf9('0x45')]));if(_0x22af22[_0xeaf9('0x43')]['filter']){_0x2759fb[_0xeaf9('0x50')]=_[_0xeaf9('0x51')](_0x2759fb['where'],{'$or':_[_0xeaf9('0x40')](_0x2759fb[_0xeaf9('0x47')],function(_0x368af7){var _0x484d78={};_0x484d78[_0x368af7]={'$like':'%'+_0x22af22[_0xeaf9('0x43')]['filter']+'%'};return _0x484d78;})});}_0x2759fb=_['merge']({},_0x2759fb,_0x22af22[_0xeaf9('0x53')]);return _0x224caa['getAgents'](_0x2759fb);}})[_0xeaf9('0x22')](function(_0x488a0a){if(_0x488a0a){_0x4eaaf0=_0x488a0a[_0xeaf9('0x49')];if(!_0x22af22[_0xeaf9('0x43')][_0xeaf9('0x4b')](_0xeaf9('0x4c'))){_0x2759fb[_0xeaf9('0x4d')]=qs[_0xeaf9('0x4d')](_0x22af22[_0xeaf9('0x43')][_0xeaf9('0x4d')]);_0x2759fb['offset']=qs[_0xeaf9('0x32')](_0x22af22[_0xeaf9('0x43')][_0xeaf9('0x32')]);}return _0x224caa[_0xeaf9('0xea')](_0x2759fb);}})[_0xeaf9('0x22')](function(_0x1d02f1){if(_0x1d02f1){return _0x1d02f1?{'count':_0x4eaaf0,'rows':_0x1d02f1}:null;}})['then'](respondWithResult(_0x4a9fad,null))[_0xeaf9('0x2c')](handleError(_0x4a9fad,null));};
\ No newline at end of file
+var _0x07a6=['request-promise','moment','mustache','util','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/environment','../../config/license/util','redis','defaults','localhost','socket.io-emitter','register','jayson/promise','client','http','request','then','info','SmsAccount,\x20%s,\x20%s','request\x20sent','error','message','result','status','end','json','offset','limit','undefined','count','Content-Range','apply','save','update','destroy','UserProfileResource','sendStatus','stack','name','index','Pause','mandatoryDispositionPause','map','SmsAccount','fieldName','type','key','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filters','filter','merge','VIRTUAL','options','include','findAll','rows','catch','params','includeAll','find','create','body','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','addDisposition','SmsAccountId','getDispositions','findOne','Disposition','rawAttributes','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','removeAnswers','notify','SmsApplication','Applications','orderBy','priority','asc','account','difference','createdAt','updatedAt','CompanyId','ListId','twilio','messageId','MessageSid','skebby','sender','text','from','clicksend','message_id','plivo','From','Text','MessageUUID','results','csc','originatingAddress','segmentedMessage','fromNumber','replyMessageId','bandwidth','intelepeer','refid','isNil','Sequelize','ValidationError','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','Contacts','DESC','list','omit','CmContact','contact','SmsInteraction','spread','interaction','created','autoclose','applications','push','close','unmanaged','*,*,*,*','SmsMessage','UserId','User','agent','waitForTheAssignedAgent','Start','startRouting','receiveMessage','SmsAccount,\x20%s,\x20%s,\x20%s','entity\x20found','debug','stringify','set','Content-Type','text/xml','send','addApplications','sequelize','Transaction','bulkCreate','finally','getApplications','getInteractions','fullname','internal','color','tag','to\x20is\x20mandatory','List','out','Messages','dataValues','received\x20delivery\x20report\x20from','inspect','skebby_dispatch_id','requestid','statusInt','status_code','groupName','DELIVERED','clickatell','redif','error_code','infobip','DELIVERED_TO_GATEWAY','message-delivered','DELIVRD','statusGet','message-id','state','addAgents','emit','userSmsAccount:save','removeAgents','isArray','userSmsAccount:remove','getAgents','rimraf','zip-dir','fast-json-patch'];(function(_0x55015a,_0x4bda6f){var _0x1082c2=function(_0x2f622e){while(--_0x2f622e){_0x55015a['push'](_0x55015a['shift']());}};_0x1082c2(++_0x4bda6f);}(_0x07a6,0xde));var _0x607a=function(_0x5d9db,_0x3a929f){_0x5d9db=_0x5d9db-0x0;var _0x396aea=_0x07a6[_0x5d9db];return _0x396aea;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x607a('0x0'));var zipdir=require(_0x607a('0x1'));var jsonpatch=require(_0x607a('0x2'));var rp=require(_0x607a('0x3'));var moment=require(_0x607a('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x607a('0x5'));var util=require(_0x607a('0x6'));var path=require('path');var sox=require(_0x607a('0x7'));var csv=require(_0x607a('0x8'));var ejs=require(_0x607a('0x9'));var fs=require('fs');var fs_extra=require(_0x607a('0xa'));var _=require(_0x607a('0xb'));var squel=require(_0x607a('0xc'));var crypto=require(_0x607a('0xd'));var jsforce=require(_0x607a('0xe'));var deskjs=require(_0x607a('0xf'));var toCsv=require(_0x607a('0x8'));var querystring=require(_0x607a('0x10'));var Papa=require('papaparse');var Redis=require(_0x607a('0x11'));var authService=require(_0x607a('0x12'));var qs=require(_0x607a('0x13'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x607a('0x14'));var logger=require('../../config/logger')('api');var utils=require('../../config/utils');var config=require(_0x607a('0x15'));var licenseUtil=require(_0x607a('0x16'));var db=require('../../mysqldb')['db'];config[_0x607a('0x17')]=_[_0x607a('0x18')](config['redis'],{'host':_0x607a('0x19'),'port':0x18eb});var socket=require(_0x607a('0x1a'))(new Redis(config[_0x607a('0x17')]));require('./smsAccount.socket')[_0x607a('0x1b')](socket);var jayson=require(_0x607a('0x1c'));var client=jayson[_0x607a('0x1d')][_0x607a('0x1e')]({'port':0x232c});function respondWithRpcPromise(_0xd13e32,_0xd130b,_0x14df92,_0x4ae404){return new BPromise(function(_0xcf1e49,_0x25afb6){var _0x46f755=_0x4ae404||client;return _0x46f755[_0x607a('0x1f')](_0xd13e32,_0x14df92)[_0x607a('0x20')](function(_0x406aa5){logger[_0x607a('0x21')](_0x607a('0x22'),_0xd130b,_0x607a('0x23'));logger['debug']('SmsAccount,\x20%s,\x20%s,\x20%s',_0xd130b,'request\x20sent',JSON['stringify'](_0x406aa5));if(_0x406aa5[_0x607a('0x24')]){if(_0x406aa5['error']['code']===0x1f4){logger['error'](_0x607a('0x22'),_0xd130b,_0x406aa5[_0x607a('0x24')][_0x607a('0x25')]);return _0x25afb6(_0x406aa5[_0x607a('0x24')][_0x607a('0x25')]);}logger[_0x607a('0x24')](_0x607a('0x22'),_0xd130b,_0x406aa5[_0x607a('0x24')][_0x607a('0x25')]);return _0xcf1e49(_0x406aa5['error']['message']);}else{logger[_0x607a('0x21')](_0x607a('0x22'),_0xd130b,_0x607a('0x23'));_0xcf1e49(_0x406aa5[_0x607a('0x26')][_0x607a('0x25')]);}})['catch'](function(_0x53497a){logger[_0x607a('0x24')](_0x607a('0x22'),_0xd130b,_0x53497a);_0x25afb6(_0x53497a);});});}function respondWithStatusCode(_0x40332f,_0x31bf9f){_0x31bf9f=_0x31bf9f||0xcc;return function(_0x9ce831){if(_0x9ce831){return _0x40332f['sendStatus'](_0x31bf9f);}return _0x40332f[_0x607a('0x27')](_0x31bf9f)[_0x607a('0x28')]();};}function respondWithResult(_0x18b655,_0x32991e){_0x32991e=_0x32991e||0xc8;return function(_0x577eaf){if(_0x577eaf){return _0x18b655[_0x607a('0x27')](_0x32991e)[_0x607a('0x29')](_0x577eaf);}};}function respondWithFilteredResult(_0x478509,_0xab703e){return function(_0x101876){if(_0x101876){var _0x4c24b8=typeof _0xab703e[_0x607a('0x2a')]==='undefined'&&typeof _0xab703e[_0x607a('0x2b')]===_0x607a('0x2c');var _0x18dfa1=_0x101876[_0x607a('0x2d')];var _0x52dba7=_0x4c24b8?0x0:_0xab703e[_0x607a('0x2a')];var _0xbbece8=_0x4c24b8?_0x101876[_0x607a('0x2d')]:_0xab703e['offset']+_0xab703e[_0x607a('0x2b')];var _0x3df38f;if(_0xbbece8>=_0x18dfa1){_0xbbece8=_0x18dfa1;_0x3df38f=0xc8;}else{_0x3df38f=0xce;}_0x478509[_0x607a('0x27')](_0x3df38f);return _0x478509['set'](_0x607a('0x2e'),_0x52dba7+'-'+_0xbbece8+'/'+_0x18dfa1)['json'](_0x101876);}return null;};}function patchUpdates(_0x185ad0){return function(_0x5f4734){try{jsonpatch[_0x607a('0x2f')](_0x5f4734,_0x185ad0,!![]);}catch(_0x207a6a){return BPromise['reject'](_0x207a6a);}return _0x5f4734[_0x607a('0x30')]();};}function saveUpdates(_0x4f7bdd,_0x5cf265){return function(_0x2110f7){if(_0x2110f7){return _0x2110f7[_0x607a('0x31')](_0x4f7bdd)[_0x607a('0x20')](function(_0x3e1e43){return _0x3e1e43;});}return null;};}function removeEntity(_0x563206,_0x18c684){return function(_0x15e787){if(_0x15e787){return _0x15e787[_0x607a('0x32')]()[_0x607a('0x20')](function(){var _0x14af5c=_0x15e787['get']({'plain':!![]});var _0x3624dd='SmsAccounts';return db[_0x607a('0x33')][_0x607a('0x32')]({'where':{'type':_0x3624dd,'resourceId':_0x14af5c['id']}})[_0x607a('0x20')](function(){return _0x15e787;});})[_0x607a('0x20')](function(){_0x563206[_0x607a('0x27')](0xcc)[_0x607a('0x28')]();});}};}function handleEntityNotFound(_0x2e647f,_0x5b2f90){return function(_0x46d543){if(!_0x46d543){_0x2e647f[_0x607a('0x34')](0x194);}return _0x46d543;};}function handleError(_0x33e9be,_0x30d72b){_0x30d72b=_0x30d72b||0x1f4;return function(_0x5e3564){logger[_0x607a('0x24')](_0x5e3564[_0x607a('0x35')]);if(_0x5e3564['name']){delete _0x5e3564[_0x607a('0x36')];}_0x33e9be['status'](_0x30d72b)['send'](_0x5e3564);};}exports[_0x607a('0x37')]=function(_0x4453bf,_0xd2c98c){var _0x51a7a8={'include':[{'model':db[_0x607a('0x38')],'as':_0x607a('0x39')}]},_0xa0435b={},_0x299fd8={'count':0x0,'rows':[]};var _0x38a380=_[_0x607a('0x3a')](db[_0x607a('0x3b')]['rawAttributes'],function(_0x4221df){return{'name':_0x4221df[_0x607a('0x3c')],'type':_0x4221df[_0x607a('0x3d')][_0x607a('0x3e')]};});_0xa0435b[_0x607a('0x3f')]=_[_0x607a('0x3a')](_0x38a380,_0x607a('0x36'));_0xa0435b[_0x607a('0x40')]=_[_0x607a('0x41')](_0x4453bf['query']);_0xa0435b['filters']=_[_0x607a('0x42')](_0xa0435b[_0x607a('0x3f')],_0xa0435b[_0x607a('0x40')]);_0x51a7a8[_0x607a('0x43')]=_['intersection'](_0xa0435b[_0x607a('0x3f')],qs[_0x607a('0x44')](_0x4453bf[_0x607a('0x40')][_0x607a('0x44')]));_0x51a7a8[_0x607a('0x43')]=_0x51a7a8[_0x607a('0x43')][_0x607a('0x45')]?_0x51a7a8[_0x607a('0x43')]:_0xa0435b[_0x607a('0x3f')];if(!_0x4453bf[_0x607a('0x40')][_0x607a('0x46')](_0x607a('0x47'))){_0x51a7a8[_0x607a('0x2b')]=qs[_0x607a('0x2b')](_0x4453bf[_0x607a('0x40')]['limit']);_0x51a7a8['offset']=qs[_0x607a('0x2a')](_0x4453bf['query'][_0x607a('0x2a')]);}_0x51a7a8[_0x607a('0x48')]=qs[_0x607a('0x49')](_0x4453bf[_0x607a('0x40')][_0x607a('0x49')]);_0x51a7a8[_0x607a('0x4a')]=qs['filters'](_[_0x607a('0x4b')](_0x4453bf['query'],_0xa0435b[_0x607a('0x4c')]),_0x38a380);if(_0x4453bf['query'][_0x607a('0x4d')]){_0x51a7a8[_0x607a('0x4a')]=_[_0x607a('0x4e')](_0x51a7a8[_0x607a('0x4a')],{'$or':_[_0x607a('0x3a')](_0x38a380,function(_0x503d41){if(_0x503d41[_0x607a('0x3d')]!==_0x607a('0x4f')){var _0x167888={};_0x167888[_0x503d41[_0x607a('0x36')]]={'$like':'%'+_0x4453bf[_0x607a('0x40')][_0x607a('0x4d')]+'%'};return _0x167888;}})});}_0x51a7a8=_[_0x607a('0x4e')]({},_0x51a7a8,_0x4453bf[_0x607a('0x50')]);var _0x4c7063={'where':_0x51a7a8['where']};return db[_0x607a('0x3b')][_0x607a('0x2d')](_0x4c7063)['then'](function(_0x3801e2){_0x299fd8[_0x607a('0x2d')]=_0x3801e2;if(_0x4453bf['query']['includeAll']){_0x51a7a8[_0x607a('0x51')]=[{'all':!![]}];}return db[_0x607a('0x3b')][_0x607a('0x52')](_0x51a7a8);})[_0x607a('0x20')](function(_0x3d3c5a){_0x299fd8[_0x607a('0x53')]=_0x3d3c5a;return _0x299fd8;})[_0x607a('0x20')](respondWithFilteredResult(_0xd2c98c,_0x51a7a8))[_0x607a('0x54')](handleError(_0xd2c98c,null));};exports['show']=function(_0x11ef8b,_0x2f2fe1){var _0x1236d2={'raw':![],'where':{'id':_0x11ef8b[_0x607a('0x55')]['id']},'include':[{'model':db['Pause'],'as':_0x607a('0x39')}]},_0x46b25b={};_0x46b25b[_0x607a('0x3f')]=_[_0x607a('0x41')](db[_0x607a('0x3b')]['rawAttributes']);_0x46b25b[_0x607a('0x40')]=_['keys'](_0x11ef8b['query']);_0x46b25b[_0x607a('0x4c')]=_[_0x607a('0x42')](_0x46b25b[_0x607a('0x3f')],_0x46b25b[_0x607a('0x40')]);_0x1236d2[_0x607a('0x43')]=_[_0x607a('0x42')](_0x46b25b[_0x607a('0x3f')],qs[_0x607a('0x44')](_0x11ef8b[_0x607a('0x40')]['fields']));_0x1236d2[_0x607a('0x43')]=_0x1236d2['attributes']['length']?_0x1236d2[_0x607a('0x43')]:_0x46b25b['model'];if(_0x11ef8b['query'][_0x607a('0x56')]){_0x1236d2[_0x607a('0x51')]=[{'all':!![]}];}_0x1236d2=_[_0x607a('0x4e')]({},_0x1236d2,_0x11ef8b[_0x607a('0x50')]);return db[_0x607a('0x3b')][_0x607a('0x57')](_0x1236d2)[_0x607a('0x20')](handleEntityNotFound(_0x2f2fe1,null))[_0x607a('0x20')](respondWithResult(_0x2f2fe1,null))[_0x607a('0x54')](handleError(_0x2f2fe1,null));};exports[_0x607a('0x58')]=function(_0x5b5556,_0x3298d2){return db[_0x607a('0x3b')][_0x607a('0x58')](_0x5b5556[_0x607a('0x59')],{})[_0x607a('0x20')](function(_0x1e04fe){var _0x18a323=_0x5b5556[_0x607a('0x5a')][_0x607a('0x5b')]({'plain':!![]});if(!_0x18a323)throw new Error(_0x607a('0x5c'));if(_0x18a323[_0x607a('0x5d')]===_0x607a('0x5a')){var _0x5c12d5=_0x1e04fe[_0x607a('0x5b')]({'plain':!![]});var _0x410b4b='SmsAccounts';return db['UserProfileSection'][_0x607a('0x57')]({'where':{'name':_0x410b4b,'userProfileId':_0x18a323['userProfileId']},'raw':!![]})[_0x607a('0x20')](function(_0x337ad8){if(_0x337ad8&&_0x337ad8[_0x607a('0x5e')]===0x0){return db['UserProfileResource'][_0x607a('0x58')]({'name':_0x5c12d5['name'],'resourceId':_0x5c12d5['id'],'type':_0x337ad8[_0x607a('0x36')],'sectionId':_0x337ad8['id']},{})[_0x607a('0x20')](function(){return _0x1e04fe;});}else{return _0x1e04fe;}})[_0x607a('0x54')](function(_0x381323){logger['error'](_0x607a('0x5f'),_0x381323);throw _0x381323;});}return _0x1e04fe;})[_0x607a('0x20')](respondWithResult(_0x3298d2,0xc9))['catch'](handleError(_0x3298d2,null));};exports[_0x607a('0x31')]=function(_0x3ed92c,_0x270d69){if(_0x3ed92c[_0x607a('0x59')]['id']){delete _0x3ed92c[_0x607a('0x59')]['id'];}return db[_0x607a('0x3b')]['find']({'where':{'id':_0x3ed92c[_0x607a('0x55')]['id']},'include':[{'model':db[_0x607a('0x38')],'as':_0x607a('0x39')}]})[_0x607a('0x20')](handleEntityNotFound(_0x270d69,null))['then'](saveUpdates(_0x3ed92c[_0x607a('0x59')],null))[_0x607a('0x20')](respondWithResult(_0x270d69,null))['catch'](handleError(_0x270d69,null));};exports['destroy']=function(_0x2c10b6,_0x105e26){return db[_0x607a('0x3b')][_0x607a('0x57')]({'where':{'id':_0x2c10b6[_0x607a('0x55')]['id']}})[_0x607a('0x20')](handleEntityNotFound(_0x105e26,null))['then'](removeEntity(_0x105e26,null))[_0x607a('0x54')](handleError(_0x105e26,null));};exports['describe']=function(_0x558b62,_0x2eb6fd){return db['SmsAccount'][_0x607a('0x60')]()[_0x607a('0x20')](respondWithResult(_0x2eb6fd,null))['catch'](handleError(_0x2eb6fd,null));};exports[_0x607a('0x61')]=function(_0x45c00b,_0x2c9d23,_0x937185){if(_0x45c00b[_0x607a('0x59')]['id']){delete _0x45c00b['body']['id'];}return db['SmsAccount']['find']({'where':{'id':_0x45c00b[_0x607a('0x55')]['id']}})['then'](handleEntityNotFound(_0x2c9d23,null))[_0x607a('0x20')](function(_0xda1586){if(_0xda1586){_0x45c00b[_0x607a('0x59')][_0x607a('0x62')]=_0xda1586['id'];return db['Disposition'][_0x607a('0x58')](_0x45c00b[_0x607a('0x59')]);}})['then'](respondWithResult(_0x2c9d23,null))[_0x607a('0x54')](handleError(_0x2c9d23,null));};exports[_0x607a('0x63')]=function(_0x311655,_0xcf6d87,_0x2e084b){var _0xb5a0b5={'raw':![],'where':{}};var _0x23256f={};var _0x3a14c0={'count':0x0,'rows':[]};return db['SmsAccount'][_0x607a('0x64')]({'where':{'id':_0x311655[_0x607a('0x55')]['id']}})[_0x607a('0x20')](handleEntityNotFound(_0xcf6d87,null))[_0x607a('0x20')](function(_0x5c6589){if(_0x5c6589){_0x23256f[_0x607a('0x3f')]=_[_0x607a('0x41')](db[_0x607a('0x65')][_0x607a('0x66')]);_0x23256f[_0x607a('0x40')]=_[_0x607a('0x41')](_0x311655['query']);_0x23256f[_0x607a('0x4c')]=_[_0x607a('0x42')](_0x23256f[_0x607a('0x3f')],_0x23256f[_0x607a('0x40')]);_0xb5a0b5[_0x607a('0x43')]=_['intersection'](_0x23256f[_0x607a('0x3f')],qs[_0x607a('0x44')](_0x311655[_0x607a('0x40')][_0x607a('0x44')]));_0xb5a0b5[_0x607a('0x43')]=_0xb5a0b5['attributes']['length']?_0xb5a0b5['attributes']:_0x23256f[_0x607a('0x3f')];if(!_0x311655[_0x607a('0x40')][_0x607a('0x46')](_0x607a('0x47'))){_0xb5a0b5[_0x607a('0x2b')]=qs[_0x607a('0x2b')](_0x311655[_0x607a('0x40')]['limit']);_0xb5a0b5['offset']=qs[_0x607a('0x2a')](_0x311655['query'][_0x607a('0x2a')]);}_0xb5a0b5[_0x607a('0x48')]=qs['sort'](_0x311655[_0x607a('0x40')][_0x607a('0x49')]);_0xb5a0b5[_0x607a('0x4a')]=qs['filters'](_[_0x607a('0x4b')](_0x311655['query'],_0x23256f[_0x607a('0x4c')]));_0xb5a0b5[_0x607a('0x4a')]['SmsAccountId']=_0x5c6589['id'];if(_0x311655[_0x607a('0x40')][_0x607a('0x4d')]){_0xb5a0b5['where']=_[_0x607a('0x4e')](_0xb5a0b5['where'],{'$or':_[_0x607a('0x3a')](_0xb5a0b5[_0x607a('0x43')],function(_0x359b0a){var _0x5efe9d={};_0x5efe9d[_0x359b0a]={'$like':'%'+_0x311655[_0x607a('0x40')][_0x607a('0x4d')]+'%'};return _0x5efe9d;})});}_0xb5a0b5=_['merge']({},_0xb5a0b5,_0x311655[_0x607a('0x50')]);return db[_0x607a('0x65')]['count']({'where':_0xb5a0b5[_0x607a('0x4a')]})[_0x607a('0x20')](function(_0x576929){_0x3a14c0[_0x607a('0x2d')]=_0x576929;if(_0x311655['query'][_0x607a('0x56')]){_0xb5a0b5[_0x607a('0x51')]=[{'all':!![]}];}return db[_0x607a('0x65')][_0x607a('0x52')](_0xb5a0b5);})['then'](function(_0x3fbe2c){_0x3a14c0[_0x607a('0x53')]=_0x3fbe2c;return _0x3a14c0;});}})[_0x607a('0x20')](respondWithFilteredResult(_0xcf6d87,_0xb5a0b5))[_0x607a('0x54')](handleError(_0xcf6d87,null));};exports[_0x607a('0x67')]=function(_0x27b69e,_0x63d396,_0x34207c){return db[_0x607a('0x3b')][_0x607a('0x57')]({'where':{'id':_0x27b69e[_0x607a('0x55')]['id']}})['then'](handleEntityNotFound(_0x63d396,null))[_0x607a('0x20')](function(_0x21071b){if(_0x21071b){return _0x21071b[_0x607a('0x67')](_0x27b69e[_0x607a('0x40')][_0x607a('0x68')]);}})[_0x607a('0x20')](respondWithStatusCode(_0x63d396,null))['catch'](handleError(_0x63d396,null));};exports[_0x607a('0x69')]=function(_0x53d4e1,_0x4e94e2,_0x36624b){if(_0x53d4e1['body']['id']){delete _0x53d4e1['body']['id'];}return db[_0x607a('0x3b')]['find']({'where':{'id':_0x53d4e1[_0x607a('0x55')]['id']}})['then'](handleEntityNotFound(_0x4e94e2,null))[_0x607a('0x20')](function(_0x4ceb7d){if(_0x4ceb7d){_0x53d4e1[_0x607a('0x59')][_0x607a('0x62')]=_0x4ceb7d['id'];return db[_0x607a('0x6a')]['create'](_0x53d4e1['body']);}})[_0x607a('0x20')](respondWithResult(_0x4e94e2,null))['catch'](handleError(_0x4e94e2,null));};exports[_0x607a('0x6b')]=function(_0x417d4e,_0x56aba1,_0x9faa8){var _0x383316={'raw':![],'where':{}};var _0x3eab3b={};var _0x41ea63={'count':0x0,'rows':[]};return db[_0x607a('0x3b')][_0x607a('0x64')]({'where':{'id':_0x417d4e[_0x607a('0x55')]['id']}})['then'](handleEntityNotFound(_0x56aba1,null))['then'](function(_0x52fd98){if(_0x52fd98){_0x3eab3b['model']=_['keys'](db[_0x607a('0x6a')]['rawAttributes']);_0x3eab3b[_0x607a('0x40')]=_[_0x607a('0x41')](_0x417d4e[_0x607a('0x40')]);_0x3eab3b[_0x607a('0x4c')]=_[_0x607a('0x42')](_0x3eab3b[_0x607a('0x3f')],_0x3eab3b[_0x607a('0x40')]);_0x383316[_0x607a('0x43')]=_[_0x607a('0x42')](_0x3eab3b[_0x607a('0x3f')],qs[_0x607a('0x44')](_0x417d4e[_0x607a('0x40')][_0x607a('0x44')]));_0x383316[_0x607a('0x43')]=_0x383316[_0x607a('0x43')]['length']?_0x383316[_0x607a('0x43')]:_0x3eab3b[_0x607a('0x3f')];if(!_0x417d4e['query'][_0x607a('0x46')](_0x607a('0x47'))){_0x383316[_0x607a('0x2b')]=qs[_0x607a('0x2b')](_0x417d4e[_0x607a('0x40')]['limit']);_0x383316['offset']=qs[_0x607a('0x2a')](_0x417d4e[_0x607a('0x40')]['offset']);}_0x383316[_0x607a('0x48')]=qs[_0x607a('0x49')](_0x417d4e[_0x607a('0x40')][_0x607a('0x49')]);_0x383316[_0x607a('0x4a')]=qs['filters'](_[_0x607a('0x4b')](_0x417d4e['query'],_0x3eab3b[_0x607a('0x4c')]));_0x383316['where'][_0x607a('0x62')]=_0x52fd98['id'];if(_0x417d4e[_0x607a('0x40')][_0x607a('0x4d')]){_0x383316[_0x607a('0x4a')]=_['merge'](_0x383316['where'],{'$or':_[_0x607a('0x3a')](_0x383316[_0x607a('0x43')],function(_0x2f14bc){var _0xf75acf={};_0xf75acf[_0x2f14bc]={'$like':'%'+_0x417d4e[_0x607a('0x40')]['filter']+'%'};return _0xf75acf;})});}_0x383316=_['merge']({},_0x383316,_0x417d4e[_0x607a('0x50')]);return db[_0x607a('0x6a')][_0x607a('0x2d')]({'where':_0x383316['where']})[_0x607a('0x20')](function(_0x59e3cc){_0x41ea63[_0x607a('0x2d')]=_0x59e3cc;if(_0x417d4e[_0x607a('0x40')][_0x607a('0x56')]){_0x383316['include']=[{'all':!![]}];}return db[_0x607a('0x6a')][_0x607a('0x52')](_0x383316);})['then'](function(_0x394e55){_0x41ea63[_0x607a('0x53')]=_0x394e55;return _0x41ea63;});}})[_0x607a('0x20')](respondWithFilteredResult(_0x56aba1,_0x383316))[_0x607a('0x54')](handleError(_0x56aba1,null));};exports['removeAnswers']=function(_0xd5f984,_0x4cfc9f,_0x210c8f){return db['SmsAccount'][_0x607a('0x57')]({'where':{'id':_0xd5f984[_0x607a('0x55')]['id']}})[_0x607a('0x20')](handleEntityNotFound(_0x4cfc9f,null))[_0x607a('0x20')](function(_0x11b55a){if(_0x11b55a){return _0x11b55a[_0x607a('0x6c')](_0xd5f984[_0x607a('0x40')][_0x607a('0x68')]);}})[_0x607a('0x20')](respondWithStatusCode(_0x4cfc9f,null))[_0x607a('0x54')](handleError(_0x4cfc9f,null));};exports[_0x607a('0x6d')]=function(_0x12d31f,_0x71df54,_0x5db4f4){var _0x5eb53d={'channel':'sms'};var _0x367731=[];var _0x2b25c7=[];var _0x5162b8={};return db['SmsAccount'][_0x607a('0x57')]({'where':{'id':_0x12d31f['params']['id']},'include':[{'model':db[_0x607a('0x6e')],'as':_0x607a('0x6f')}]})[_0x607a('0x20')](handleEntityNotFound(_0x71df54,null))[_0x607a('0x20')](function(_0xa49a60){_0x5eb53d['account']=_0xa49a60;_0x5eb53d['applications']=_[_0x607a('0x70')](_0xa49a60[_0x607a('0x6f')],[_0x607a('0x71')],[_0x607a('0x72')]);if(_0x5eb53d[_0x607a('0x73')][_0x607a('0x6f')]){delete _0x5eb53d[_0x607a('0x73')][_0x607a('0x6f')];}return db['CmContact'][_0x607a('0x60')]();})[_0x607a('0x20')](function(_0x3ed7ce){if(!_0x3ed7ce){throw new db['Sequelize']['ValidationError']('no\x20available\x20attributes');}_0x367731=_[_0x607a('0x74')](_[_0x607a('0x41')](_0x3ed7ce),[_0x607a('0x75'),_0x607a('0x76')]);_0x2b25c7=_['difference'](_[_0x607a('0x41')](_0x3ed7ce),['createdAt',_0x607a('0x76'),_0x607a('0x77'),_0x607a('0x78')]);_0x5eb53d[_0x607a('0x59')]={'mapKey':'mobile'};if(_0x5eb53d[_0x607a('0x73')][_0x607a('0x3d')]){switch(_0x5eb53d[_0x607a('0x73')][_0x607a('0x3d')]){case _0x607a('0x79'):_0x5eb53d[_0x607a('0x59')]['from']=_0x12d31f[_0x607a('0x59')]['From'];_0x5eb53d['body'][_0x607a('0x59')]=_0x12d31f[_0x607a('0x59')]['Body'];_0x5eb53d[_0x607a('0x59')][_0x607a('0x7a')]=_0x12d31f[_0x607a('0x59')][_0x607a('0x7b')];break;case _0x607a('0x7c'):_0x5eb53d['body']['from']='+'+_0x12d31f[_0x607a('0x59')][_0x607a('0x7d')];_0x5eb53d[_0x607a('0x59')][_0x607a('0x59')]=_0x12d31f[_0x607a('0x59')][_0x607a('0x7e')];break;case'connectel':_0x5eb53d[_0x607a('0x59')][_0x607a('0x7f')]=_0x12d31f[_0x607a('0x59')][_0x607a('0x7f')];_0x5eb53d['body'][_0x607a('0x59')]=_0x12d31f[_0x607a('0x59')][_0x607a('0x25')];break;case _0x607a('0x80'):_0x5eb53d['body'][_0x607a('0x7f')]=_0x12d31f[_0x607a('0x59')]['from'];_0x5eb53d['body'][_0x607a('0x59')]=_0x12d31f[_0x607a('0x59')][_0x607a('0x59')];_0x5eb53d['body'][_0x607a('0x7a')]=_0x12d31f[_0x607a('0x59')][_0x607a('0x81')];break;case _0x607a('0x82'):_0x5eb53d[_0x607a('0x59')][_0x607a('0x7f')]=_0x12d31f['body'][_0x607a('0x83')];_0x5eb53d[_0x607a('0x59')]['body']=_0x12d31f[_0x607a('0x59')][_0x607a('0x84')];_0x5eb53d['body'][_0x607a('0x7a')]=_0x12d31f[_0x607a('0x59')][_0x607a('0x85')];break;case'infobip':_0x5eb53d[_0x607a('0x59')][_0x607a('0x7f')]='+'+_0x12d31f['body'][_0x607a('0x86')][0x0][_0x607a('0x7f')];_0x5eb53d[_0x607a('0x59')][_0x607a('0x59')]=_0x12d31f['body'][_0x607a('0x86')][0x0]['text'];_0x5eb53d[_0x607a('0x59')]['messageId']=_0x12d31f[_0x607a('0x59')][_0x607a('0x86')][0x0][_0x607a('0x7a')];break;case _0x607a('0x87'):_0x5eb53d['body']['from']=_0x12d31f[_0x607a('0x59')][_0x607a('0x88')];_0x5eb53d[_0x607a('0x59')][_0x607a('0x59')]=_0x12d31f['body'][_0x607a('0x89')]['message'];break;case'clickatell':_0x5eb53d[_0x607a('0x59')][_0x607a('0x7f')]=_0x12d31f['body'][_0x607a('0x8a')];_0x5eb53d['body']['body']=_0x12d31f[_0x607a('0x59')][_0x607a('0x7e')];_0x5eb53d[_0x607a('0x59')][_0x607a('0x7a')]=_0x12d31f[_0x607a('0x59')][_0x607a('0x8b')];break;case _0x607a('0x8c'):_0x5eb53d[_0x607a('0x59')][_0x607a('0x7a')]=_0x12d31f[_0x607a('0x59')][0x0][_0x607a('0x25')]['id'];_0x5eb53d[_0x607a('0x59')][_0x607a('0x7f')]=_0x12d31f[_0x607a('0x59')][0x0]['message']['from'];_0x5eb53d[_0x607a('0x59')][_0x607a('0x59')]=_0x12d31f[_0x607a('0x59')][0x0][_0x607a('0x25')][_0x607a('0x7e')];break;case _0x607a('0x8d'):_0x5eb53d['body'][_0x607a('0x7f')]=_0x12d31f[_0x607a('0x59')][_0x607a('0x7f')];_0x5eb53d['body']['body']=_0x12d31f[_0x607a('0x59')][_0x607a('0x25')];_0x5eb53d[_0x607a('0x59')][_0x607a('0x7a')]=_0x12d31f[_0x607a('0x59')][_0x607a('0x8e')];break;}}if(_0x5eb53d['body']['id']){delete _0x5eb53d[_0x607a('0x59')]['id'];}if(_[_0x607a('0x8f')](_0x5eb53d[_0x607a('0x59')][_0x607a('0x7f')])){throw new db[(_0x607a('0x90'))][(_0x607a('0x91'))](_0x607a('0x92'));}if(_['isNil'](_0x5eb53d[_0x607a('0x59')][_0x607a('0x59')])||_0x5eb53d[_0x607a('0x59')]['body']===''){throw new db['Sequelize']['ValidationError'](_0x607a('0x93'));}if(_[_0x607a('0x8f')](_0x5eb53d['body'][_0x607a('0x94')])){throw new db[(_0x607a('0x90'))][(_0x607a('0x91'))]('mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x2b25c7);}if(!_[_0x607a('0x95')](_0x2b25c7,_0x5eb53d[_0x607a('0x59')]['mapKey'])){throw new db[(_0x607a('0x90'))][(_0x607a('0x91'))](_0x607a('0x96')+_0x2b25c7);}_0x5162b8[_0x5eb53d[_0x607a('0x59')][_0x607a('0x94')]]=_0x5eb53d[_0x607a('0x59')][_0x607a('0x7f')];return db[_0x607a('0x97')][_0x607a('0x57')]({'where':{'id':_0x5eb53d[_0x607a('0x73')][_0x607a('0x78')]},'include':[{'model':db['CmContact'],'as':_0x607a('0x98'),'where':_0x5162b8,'limit':0x1,'order':[['updatedAt',_0x607a('0x99')]]}]});})[_0x607a('0x20')](handleEntityNotFound(_0x71df54,null))[_0x607a('0x20')](function(_0x3b4f59){if(_0x3b4f59){_0x5eb53d[_0x607a('0x9a')]=_[_0x607a('0x9b')](_0x3b4f59,[_0x607a('0x98')]);if(_0x3b4f59[_0x607a('0x98')][_0x607a('0x45')]){return _0x3b4f59[_0x607a('0x98')][0x0];}var _0x284dea=_['defaults'](_0x5eb53d['body'],{'firstName':_0x5eb53d[_0x607a('0x59')][_0x607a('0x7f')],'ListId':_0x3b4f59['id']});_0x284dea[_0x5eb53d[_0x607a('0x59')]['mapKey']]=_0x5eb53d['body'][_0x607a('0x7f')];return db[_0x607a('0x9c')]['create'](_0x284dea,{'fields':_0x367731,'raw':!![]});}})[_0x607a('0x20')](handleEntityNotFound(_0x71df54,null))[_0x607a('0x20')](function(_0x17b794){if(_0x17b794){_0x5eb53d[_0x607a('0x9d')]=_0x17b794;var _0x2ee1cb={'ContactId':_0x17b794['id'],'phone':_0x5eb53d['body'][_0x607a('0x7f')],'SmsAccountId':_0x12d31f[_0x607a('0x55')]['id']};var _0x10f6b1={'ContactId':_0x17b794['id'],'SmsAccountId':_0x12d31f['params']['id'],'closed':![]};return db[_0x607a('0x9e')][_0x607a('0x57')]({'where':_0x10f6b1})[_0x607a('0x20')](function(_0x10c6d2){if(_0x10c6d2){return[_0x10c6d2,![]];}return db['SmsInteraction'][_0x607a('0x58')](_0x2ee1cb)[_0x607a('0x20')](function(_0x53cbac){return[_0x53cbac,!![]];});});}})[_0x607a('0x9f')](function(_0x90681a,_0x29320a){_0x5eb53d['interaction']=_0x90681a[_0x607a('0x5b')]({'plain':!![]});_0x5eb53d[_0x607a('0xa0')][_0x607a('0xa1')]=![];if(_0x29320a){if(_0x5eb53d[_0x607a('0x73')][_0x607a('0xa2')]){_0x5eb53d[_0x607a('0xa3')][_0x607a('0xa4')]({'id':0x0,'priority':_0x5eb53d[_0x607a('0xa3')]['length']+0x1,'app':_0x607a('0xa5'),'appdata':_0x607a('0xa6'),'interval':_0x607a('0xa7')});}_0x5eb53d[_0x607a('0xa0')][_0x607a('0xa1')]=!![];}return db[_0x607a('0xa8')]['create']({'phone':_0x5eb53d[_0x607a('0x59')][_0x607a('0x7f')],'messageId':_0x5eb53d[_0x607a('0x59')][_0x607a('0x7a')],'body':_0x5eb53d[_0x607a('0x59')][_0x607a('0x59')],'SmsAccountId':_0x12d31f[_0x607a('0x55')]['id'],'SmsInteractionId':_0x90681a['id'],'direction':'in','ContactId':_0x90681a['ContactId'],'AttachmentId':_0x5eb53d[_0x607a('0x59')]['AttachmentId']});})[_0x607a('0x20')](function(_0x514ada){_0x5eb53d[_0x607a('0x25')]=_0x514ada;if(_0x5eb53d['interaction'][_0x607a('0xa9')]){return db[_0x607a('0xaa')][_0x607a('0x57')]({'attributes':['id',_0x607a('0x36')],'where':{'id':_0x5eb53d[_0x607a('0xa0')]['UserId']}})[_0x607a('0x20')](function(_0x1750fc){if(_0x1750fc){_0x5eb53d['applications']['unshift']({'id':0x0,'priority':0x0,'app':_0x607a('0xab'),'appdata':_0x1750fc[_0x607a('0x36')]+','+(_0x5eb53d[_0x607a('0x73')][_0x607a('0xac')]||0xa),'interval':_0x607a('0xa7')});}return respondWithRpcPromise(_0x607a('0xad'),'startRouting',_0x5eb53d);});}return respondWithRpcPromise(_0x607a('0xad'),_0x607a('0xae'),_0x5eb53d);})[_0x607a('0x20')](function(_0x56338d){if(_0x56338d){var _0x1f9d65=0xc8;var _0x4d74f8=_0x607a('0xaf');logger[_0x607a('0x21')](_0x607a('0xb0'),_0x4d74f8,_0x1f9d65,_0x607a('0xb1'));logger[_0x607a('0xb2')]('SmsAccount,\x20%s,\x20%s,\x20%s,\x20%s',_0x4d74f8,_0x1f9d65,'entity\x20found',JSON[_0x607a('0xb3')](_0x56338d));if(_0x5eb53d[_0x607a('0x73')][_0x607a('0x3d')]===_0x607a('0x79')){return _0x71df54['status'](_0x1f9d65)[_0x607a('0xb4')](_0x607a('0xb5'),_0x607a('0xb6'))[_0x607a('0xb7')]('<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>');}else{return _0x71df54[_0x607a('0x27')](_0x1f9d65)[_0x607a('0x29')](_0x56338d);}}})[_0x607a('0x54')](handleError(_0x71df54,null));};exports[_0x607a('0xb8')]=function(_0x280bb0,_0x4f2d0d){var _0xba02fa=_0x280bb0['params']['id'];var _0x3926a2=_0x280bb0['body'];var _0x98c601=0xc8;var _0x47e935=null;return db[_0x607a('0xb9')]['transaction']({'isolationLevel':db[_0x607a('0xb9')][_0x607a('0xba')]['ISOLATION_LEVELS']['READ_COMMITTED']},function(_0x23105c){return db['SmsAccount'][_0x607a('0x64')]({'where':{'id':_0xba02fa},'transaction':_0x23105c})[_0x607a('0x20')](function(_0x4ffb69){if(_0x4ffb69){return db[_0x607a('0x6e')][_0x607a('0x32')]({'where':{'SmsAccountId':_0xba02fa},'transaction':_0x23105c})[_0x607a('0x20')](function(){var _0x4f9400=_[_0x607a('0x3a')](_0x3926a2,function(_0x15bedc){_0x15bedc[_0x607a('0x62')]=_0xba02fa;return _0x15bedc;});return db[_0x607a('0x6e')][_0x607a('0xbb')](_0x4f9400,{'transaction':_0x23105c});});}else{_0x98c601=0x194;_0x47e935=[];}});})['then'](function(){if(_0x98c601!==0x194){return db[_0x607a('0x6e')]['findAndCountAll']({'where':{'SmsAccountId':_0xba02fa},'order':_0x607a('0x71')})[_0x607a('0x20')](function(_0x341249){_0x47e935=_0x341249;});}})[_0x607a('0x54')](function(_0x4f6548){_0x98c601=0x1f4;logger[_0x607a('0x24')](_0x4f6548[_0x607a('0x35')]);if(_0x4f6548[_0x607a('0x36')]){delete _0x4f6548[_0x607a('0x36')];}_0x47e935=_0x4f6548;})[_0x607a('0xbc')](function(){if(_0x47e935===null){_0x4f2d0d[_0x607a('0x34')](_0x98c601);}else{if(_0x98c601===0x1f4){_0x4f2d0d['status'](_0x98c601)[_0x607a('0xb7')](_0x47e935);}else{_0x4f2d0d[_0x607a('0x27')](_0x98c601)[_0x607a('0x29')](_0x47e935);}}});};exports[_0x607a('0xbd')]=function(_0x34d1e4,_0x2de04d,_0x5b8317){var _0x47a72b={};var _0x3bb630={};var _0x27789a;var _0x377f97;return db[_0x607a('0x3b')]['findOne']({'where':{'id':_0x34d1e4['params']['id']}})[_0x607a('0x20')](handleEntityNotFound(_0x2de04d,null))['then'](function(_0x440f6b){if(_0x440f6b){_0x27789a=_0x440f6b;_0x3bb630[_0x607a('0x3f')]=_[_0x607a('0x41')](db[_0x607a('0x6e')][_0x607a('0x66')]);_0x3bb630[_0x607a('0x40')]=_['keys'](_0x34d1e4[_0x607a('0x40')]);_0x3bb630[_0x607a('0x4c')]=_['intersection'](_0x3bb630[_0x607a('0x3f')],_0x3bb630[_0x607a('0x40')]);_0x47a72b['attributes']=_['intersection'](_0x3bb630['model'],qs[_0x607a('0x44')](_0x34d1e4[_0x607a('0x40')][_0x607a('0x44')]));_0x47a72b[_0x607a('0x43')]=_0x47a72b[_0x607a('0x43')]['length']?_0x47a72b[_0x607a('0x43')]:_0x3bb630['model'];_0x47a72b[_0x607a('0x48')]=qs[_0x607a('0x49')](_0x34d1e4[_0x607a('0x40')]['sort']);_0x47a72b[_0x607a('0x4a')]=qs[_0x607a('0x4c')](_[_0x607a('0x4b')](_0x34d1e4[_0x607a('0x40')],_0x3bb630[_0x607a('0x4c')]));if(_0x34d1e4['query']['filter']){_0x47a72b['where']=_['merge'](_0x47a72b['where'],{'$or':_[_0x607a('0x3a')](_0x47a72b[_0x607a('0x43')],function(_0x10f758){var _0x385a25={};_0x385a25[_0x10f758]={'$like':'%'+_0x34d1e4['query'][_0x607a('0x4d')]+'%'};return _0x385a25;})});}_0x47a72b=_[_0x607a('0x4e')]({},_0x47a72b,_0x34d1e4['options']);return _0x27789a[_0x607a('0xbd')](_0x47a72b);}})['then'](function(_0x12d3a8){if(_0x12d3a8){_0x377f97=_0x12d3a8[_0x607a('0x45')];if(!_0x34d1e4['query'][_0x607a('0x46')](_0x607a('0x47'))){_0x47a72b['limit']=qs['limit'](_0x34d1e4[_0x607a('0x40')][_0x607a('0x2b')]);_0x47a72b[_0x607a('0x2a')]=qs[_0x607a('0x2a')](_0x34d1e4[_0x607a('0x40')][_0x607a('0x2a')]);}return _0x27789a[_0x607a('0xbd')](_0x47a72b);}})[_0x607a('0x20')](function(_0x441a41){if(_0x441a41){return _0x441a41?{'count':_0x377f97,'rows':_0x441a41}:null;}})[_0x607a('0x20')](respondWithResult(_0x2de04d,null))[_0x607a('0x54')](handleError(_0x2de04d,null));};exports[_0x607a('0xbe')]=function(_0x2872fc,_0xf4be0,_0x1668bc){var _0x5d06d0={'raw':![],'where':{}};var _0x6d37e={};var _0x2a39af={'count':0x0,'rows':[]};return db[_0x607a('0x3b')]['findOne']({'where':{'id':_0x2872fc[_0x607a('0x55')]['id']}})[_0x607a('0x20')](handleEntityNotFound(_0xf4be0,null))['then'](function(_0x455887){if(_0x455887){_0x6d37e[_0x607a('0x3f')]=_[_0x607a('0x41')](db['SmsInteraction'][_0x607a('0x66')]);_0x6d37e[_0x607a('0x40')]=_[_0x607a('0x41')](_0x2872fc[_0x607a('0x40')]);_0x6d37e[_0x607a('0x4c')]=_[_0x607a('0x42')](_0x6d37e[_0x607a('0x3f')],_0x6d37e[_0x607a('0x40')]);_0x5d06d0[_0x607a('0x43')]=_['intersection'](_0x6d37e[_0x607a('0x3f')],qs[_0x607a('0x44')](_0x2872fc[_0x607a('0x40')][_0x607a('0x44')]));_0x5d06d0['attributes']=_0x5d06d0[_0x607a('0x43')][_0x607a('0x45')]?_0x5d06d0[_0x607a('0x43')]:_0x6d37e[_0x607a('0x3f')];if(!_0x2872fc[_0x607a('0x40')][_0x607a('0x46')]('nolimit')){_0x5d06d0[_0x607a('0x2b')]=qs['limit'](_0x2872fc[_0x607a('0x40')]['limit']);_0x5d06d0['offset']=qs['offset'](_0x2872fc[_0x607a('0x40')][_0x607a('0x2a')]);}_0x5d06d0['order']=qs[_0x607a('0x49')](_0x2872fc['query'][_0x607a('0x49')]);_0x5d06d0['where']=qs['filters'](_[_0x607a('0x4b')](_0x2872fc[_0x607a('0x40')],_0x6d37e[_0x607a('0x4c')]));_0x5d06d0[_0x607a('0x4a')][_0x607a('0x62')]=_0x455887['id'];if(_0x2872fc[_0x607a('0x40')][_0x607a('0x4d')]){_0x5d06d0['where']=_[_0x607a('0x4e')](_0x5d06d0[_0x607a('0x4a')],{'$or':_[_0x607a('0x3a')](_0x5d06d0[_0x607a('0x43')],function(_0x506f0a){var _0x37d1ea={};_0x37d1ea[_0x506f0a]={'$like':'%'+_0x2872fc[_0x607a('0x40')][_0x607a('0x4d')]+'%'};return _0x37d1ea;})});}_0x5d06d0=_[_0x607a('0x4e')]({},_0x5d06d0,_0x2872fc[_0x607a('0x50')]);return db['SmsInteraction'][_0x607a('0x2d')]({'where':_0x5d06d0[_0x607a('0x4a')]})[_0x607a('0x20')](function(_0x11195a){_0x2a39af[_0x607a('0x2d')]=_0x11195a;if(_0x2872fc[_0x607a('0x40')][_0x607a('0x56')]){_0x5d06d0['include']=[{'model':db['CmContact'],'as':'Contact','required':![]},{'model':db['User'],'as':'Owner','attributes':['name',_0x607a('0xbf'),_0x607a('0xc0')],'required':![]},{'model':db['Tag'],'as':'Tags','attributes':['id',_0x607a('0x36'),_0x607a('0xc1')],'where':_0x2872fc[_0x607a('0x40')][_0x607a('0xc2')]?{'id':_0x2872fc['query']['tag']}:undefined,'required':_0x2872fc['query'][_0x607a('0xc2')]?!![]:![]}];}return db[_0x607a('0x9e')]['findAll'](_0x5d06d0);})[_0x607a('0x20')](function(_0x499894){_0x2a39af['rows']=_0x499894;return _0x2a39af;});}})[_0x607a('0x20')](respondWithFilteredResult(_0xf4be0,_0x5d06d0))[_0x607a('0x54')](handleError(_0xf4be0,null));};exports[_0x607a('0xb7')]=function(_0x1cf870,_0x31f988,_0x218581){var _0x1c6fc4,_0x50a560,_0x53ef11;if(_[_0x607a('0x8f')](_0x1cf870[_0x607a('0x59')]['body'])||_0x1cf870[_0x607a('0x59')][_0x607a('0x59')]===''){throw new db[(_0x607a('0x90'))][(_0x607a('0x91'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0x607a('0x8f')](_0x1cf870[_0x607a('0x59')]['to'])){throw new db['Sequelize'][(_0x607a('0x91'))](_0x607a('0xc3'));}_0x1c6fc4=_0x1cf870['body']['to'];return db['SmsAccount'][_0x607a('0x57')]({'where':{'id':_0x1cf870[_0x607a('0x55')]['id']},'include':[{'model':db['CmList'],'as':_0x607a('0xc4'),'include':[{'model':db[_0x607a('0x9c')],'as':_0x607a('0x98'),'where':{'mobile':_0x1c6fc4},'limit':0x1,'order':[[_0x607a('0x76'),_0x607a('0x99')]]}]}]})['then'](handleEntityNotFound(_0x31f988,null))[_0x607a('0x20')](function(_0x59be5b){if(_0x59be5b&&_0x59be5b[_0x607a('0xc4')]){_0x50a560=_0x59be5b['get']({'plain':!![]});if(_0x50a560[_0x607a('0xc4')]&&_0x50a560[_0x607a('0xc4')][_0x607a('0x98')][_0x607a('0x45')]){return _0x50a560[_0x607a('0xc4')][_0x607a('0x98')][0x0];}return db['CmContact'][_0x607a('0x58')](_[_0x607a('0x18')](_0x1cf870[_0x607a('0x59')],{'firstName':_0x1c6fc4,'mobile':_0x1c6fc4,'phone':_0x1c6fc4,'ListId':_0x50a560[_0x607a('0x78')]}));}})[_0x607a('0x20')](handleEntityNotFound(_0x31f988,null))[_0x607a('0x20')](function(_0x4c79e1){if(_0x4c79e1){_0x53ef11=_0x4c79e1;return db['SmsInteraction'][_0x607a('0x57')]({'where':{'ContactId':_0x53ef11['id'],'closed':![],'SmsAccountId':_0x50a560['id']}})['then'](function(_0x430334){if(_0x430334){return[_0x430334,![]];}return db[_0x607a('0x9e')][_0x607a('0x58')]({'UserId':_0x1cf870[_0x607a('0x5a')]['id'],'ContactId':_0x53ef11['id'],'SmsAccountId':_0x50a560['id'],'phone':_0x1c6fc4,'firstMsgDirection':_0x607a('0xc5'),'Messages':[_[_0x607a('0x4e')](_0x1cf870['body'],{'read':![],'body':_0x1cf870['body']['body'],'phone':_0x1c6fc4,'SmsAccountId':_0x50a560['id'],'UserId':_0x1cf870[_0x607a('0x5a')]['id'],'ContactId':_0x53ef11['id']})]},{'include':[{'model':db[_0x607a('0xa8')],'as':_0x607a('0xc6')}]})[_0x607a('0x20')](function(_0x22c811){return[_0x22c811,!![]];});});}})[_0x607a('0x9f')](function(_0x36641c,_0x3719d9){if(_0x3719d9){return _0x36641c;}return db[_0x607a('0xa8')][_0x607a('0x58')](_[_0x607a('0x4e')](_0x1cf870[_0x607a('0x59')],{'read':![],'body':_0x1cf870['body']['body'],'phone':_0x1c6fc4,'SmsAccountId':_0x50a560['id'],'SmsInteractionId':_0x36641c['id'],'UserId':_0x1cf870['user']['id'],'ContactId':_0x53ef11['id']}))[_0x607a('0x20')](function(_0x2af4d3){_0x36641c[_0x607a('0xc7')]['Messages']=[];_0x36641c['dataValues'][_0x607a('0xc6')][_0x607a('0xa4')](_0x2af4d3[_0x607a('0xc7')]);return _0x36641c;});})['then'](respondWithResult(_0x31f988,null))[_0x607a('0x54')](handleError(_0x31f988,null));};exports[_0x607a('0x27')]=function(_0x41ccab,_0xa45f5e,_0x5551e5){if(_0x41ccab['body']['id']){delete _0x41ccab[_0x607a('0x59')]['id'];}var _0x1b7f40,_0x442c80,_0x51f0b5;return db[_0x607a('0x3b')][_0x607a('0x57')]({'where':{'id':_0x41ccab[_0x607a('0x55')]['id']}})[_0x607a('0x20')](handleEntityNotFound(_0xa45f5e,null))[_0x607a('0x20')](function(_0x1b4748){if(_0x1b4748){_0x51f0b5=_0x1b4748;logger[_0x607a('0xb2')](_0x607a('0xb0'),_0x607a('0x27'),_0x607a('0xc8'),_0x1b4748[_0x607a('0x3d')],util[_0x607a('0xc9')](_0x41ccab[_0x607a('0x59')],{'showHidden':![],'depth':null}));switch(_0x1b4748[_0x607a('0x3d')]){case'skebby':if(_0x41ccab[_0x607a('0x59')][_0x607a('0xca')]&&_0x41ccab[_0x607a('0x59')][_0x607a('0x27')]){_0x442c80=_0x41ccab[_0x607a('0x59')]['status'];return db[_0x607a('0xa8')]['find']({'where':{'messageId':_0x41ccab['body']['skebby_dispatch_id']}});}break;case'connectel':if(_0x41ccab[_0x607a('0x59')][_0x607a('0xcb')]&&_0x41ccab[_0x607a('0x59')][_0x607a('0xcc')]){_0x442c80=_0x41ccab['body'][_0x607a('0xcc')];return db[_0x607a('0xa8')]['find']({'where':{'messageId':_0x41ccab[_0x607a('0x59')][_0x607a('0xcb')]}});}break;case _0x607a('0x80'):if(_0x41ccab[_0x607a('0x59')]['message_id']&&_0x41ccab['body'][_0x607a('0xcd')]){_0x442c80=_0x41ccab[_0x607a('0x59')][_0x607a('0xcd')];return db[_0x607a('0xa8')][_0x607a('0x57')]({'where':{'messageId':_0x41ccab[_0x607a('0x59')][_0x607a('0x81')]}});}break;case'infobip':var _0x4b47a8=_0x41ccab['body'][_0x607a('0x86')][0x0];if(_0x4b47a8['messageId']&&_0x4b47a8['status'][_0x607a('0xce')]===_0x607a('0xcf')){_0x442c80=_0x4b47a8[_0x607a('0x27')]['groupName'];return db[_0x607a('0xa8')][_0x607a('0x57')]({'where':{'messageId':_0x4b47a8[_0x607a('0x7a')]}});}break;case _0x607a('0xd0'):if(_0x41ccab['body'][_0x607a('0x7a')]&&_0x41ccab[_0x607a('0x59')]['status']){_0x442c80=_0x41ccab[_0x607a('0x59')]['status'];return db[_0x607a('0xa8')][_0x607a('0x57')]({'where':{'messageId':_0x41ccab['body'][_0x607a('0x7a')]}});}break;case _0x607a('0x8c'):if(_0x41ccab[_0x607a('0x59')][0x0]['message']['id']){_0x442c80=_0x41ccab[_0x607a('0x59')][0x0][_0x607a('0x3d')];return db[_0x607a('0xa8')][_0x607a('0x57')]({'where':{'messageId':_0x41ccab[_0x607a('0x59')][0x0][_0x607a('0x25')]['id']}});}break;case'intelepeer':if(_0x41ccab['body'][_0x607a('0xd1')]&&_0x41ccab[_0x607a('0x59')][_0x607a('0x27')]){_0x442c80=_0x41ccab[_0x607a('0x59')]['status'];return db[_0x607a('0xa8')][_0x607a('0x57')]({'where':{'messageId':_0x41ccab[_0x607a('0x59')][_0x607a('0xd1')]}});}break;}}})[_0x607a('0x20')](handleEntityNotFound(_0xa45f5e,null))['then'](function(_0x349872){if(_0x349872){_0x1b7f40=_0x349872;switch(_0x51f0b5[_0x607a('0x3d')]){case _0x607a('0x7c'):if(_0x442c80===_0x607a('0xcf')){return _0x1b7f40['update']({'read':!![]});}else{logger[_0x607a('0x24')](_0x607a('0xb0'),'status',_0x607a('0x7c'),util[_0x607a('0xc9')](_0x41ccab[_0x607a('0x59')],{'showHidden':![],'depth':null}));}break;case'connectel':if(_0x442c80==='1'){return _0x1b7f40['update']({'read':!![]});}else{logger[_0x607a('0x24')](_0x607a('0xb0'),_0x607a('0x27'),_0x607a('0x7c'),util[_0x607a('0xc9')](_0x41ccab[_0x607a('0x59')],{'showHidden':![],'depth':null}));}break;case'clicksend':if(!_0x41ccab[_0x607a('0x59')][_0x607a('0xd2')]&&_0x442c80>=0xc8&&_0x442c80<=0xce){return _0x1b7f40[_0x607a('0x31')]({'read':!![]});}else{logger[_0x607a('0x24')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x607a('0x27'),'clicksend',util[_0x607a('0xc9')](_0x41ccab['body'],{'showHidden':![],'depth':null}));}break;case _0x607a('0xd3'):var _0x14ca86=_0x41ccab[_0x607a('0x59')][_0x607a('0x86')][0x0];if(_0x14ca86[_0x607a('0x27')]['groupName']==='DELIVERED'){return _0x1b7f40['update']({'read':!![]});}else{logger['error'](_0x607a('0xb0'),'status',_0x607a('0xd3'),util[_0x607a('0xc9')](_0x41ccab[_0x607a('0x59')],{'showHidden':![],'depth':null}));}break;case _0x607a('0xd0'):if(_0x442c80==_0x607a('0xd4')||_0x442c80=='RECEIVED_BY_RECIPIENT'){return _0x1b7f40[_0x607a('0x31')]({'read':!![]});}else{logger[_0x607a('0x24')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x607a('0x27'),_0x607a('0xd0'),util[_0x607a('0xc9')](_0x41ccab[_0x607a('0x59')],{'showHidden':![],'depth':null}));}break;case _0x607a('0x8c'):if(_0x442c80==_0x607a('0xd5')){return _0x1b7f40['update']({'read':!![]});}else{logger[_0x607a('0x24')]('SmsAccount,\x20%s,\x20%s,\x20%s','status','bandwidth',util[_0x607a('0xc9')](_0x41ccab[_0x607a('0x59')],{'showHidden':![],'depth':null}));}break;case _0x607a('0x8d'):if(_0x442c80===_0x607a('0xd6')||_0x442c80==='ACCEPTD'){return _0x1b7f40[_0x607a('0x31')]({'read':!![]});}else{logger[_0x607a('0x24')](_0x607a('0xb0'),_0x607a('0x27'),_0x607a('0x8d'),util[_0x607a('0xc9')](_0x41ccab['body'],{'showHidden':![],'depth':null}));}break;}return _0x1b7f40;}})[_0x607a('0x20')](respondWithResult(_0xa45f5e,null))[_0x607a('0x54')](handleError(_0xa45f5e,null));};exports[_0x607a('0xd7')]=function(_0x25ca0e,_0x35464d,_0x21570d){var _0x50f6ff,_0x4f5419,_0x4a70f6;return db['SmsAccount']['find']({'where':{'id':_0x25ca0e['params']['id']}})['then'](handleEntityNotFound(_0x35464d,null))['then'](function(_0x444398){if(_0x444398){_0x4a70f6=_0x444398;logger[_0x607a('0xb2')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x607a('0x27'),'received\x20delivery\x20report\x20from',_0x444398[_0x607a('0x3d')],util[_0x607a('0xc9')](_0x25ca0e[_0x607a('0x40')],{'showHidden':![],'depth':null}));switch(_0x444398[_0x607a('0x3d')]){case _0x607a('0x87'):if(_0x25ca0e[_0x607a('0x40')][_0x607a('0xd8')]&&_0x25ca0e['query']['state']){_0x4f5419=_0x25ca0e[_0x607a('0x40')][_0x607a('0xd9')];return db[_0x607a('0xa8')][_0x607a('0x57')]({'where':{'messageId':_0x25ca0e[_0x607a('0x40')][_0x607a('0xd8')]}});}break;}}})[_0x607a('0x20')](handleEntityNotFound(_0x35464d,null))['then'](function(_0x42a831){if(_0x42a831){_0x50f6ff=_0x42a831;switch(_0x4a70f6[_0x607a('0x3d')]){case _0x607a('0x87'):if(_0x4f5419==='2'||_0x4f5419==='6'){return _0x50f6ff[_0x607a('0x31')]({'read':!![]});}else{logger[_0x607a('0x24')](_0x607a('0xb0'),_0x607a('0x27'),_0x607a('0x87'),util[_0x607a('0xc9')](_0x25ca0e['query'],{'showHidden':![],'depth':null}));};break;}return _0x50f6ff;}})['then'](respondWithResult(_0x35464d,null))['catch'](handleError(_0x35464d,null));};exports['addAgents']=function(_0xdf2f76,_0x1c5668,_0x32f01a){return db[_0x607a('0x3b')][_0x607a('0x57')]({'where':{'id':_0xdf2f76[_0x607a('0x55')]['id']}})[_0x607a('0x20')](handleEntityNotFound(_0x1c5668,null))['then'](function(_0x4ae42f){if(_0x4ae42f){return _0x4ae42f[_0x607a('0xda')](_0xdf2f76['body']['ids'],_[_0x607a('0x9b')](_0xdf2f76[_0x607a('0x59')],[_0x607a('0x68'),'id'])||{})['spread'](function(_0x13556f){for(var _0xd048cc=0x0;_0xd048cc<_0xdf2f76['body']['ids']['length'];_0xd048cc+=0x1){socket[_0x607a('0xdb')](_0x607a('0xdc'),{'UserId':Number(_0xdf2f76[_0x607a('0x59')][_0x607a('0x68')][_0xd048cc]),'SmsAccountId':Number(_0xdf2f76[_0x607a('0x55')]['id'])});}return _0x13556f;});}})['then'](respondWithResult(_0x1c5668,null))[_0x607a('0x54')](handleError(_0x1c5668,null));};exports[_0x607a('0xdd')]=function(_0x2bc5dc,_0x1481ae,_0x306c9a){return db['SmsAccount']['find']({'where':{'id':_0x2bc5dc[_0x607a('0x55')]['id']}})[_0x607a('0x20')](handleEntityNotFound(_0x1481ae,null))[_0x607a('0x20')](function(_0x413cf5){if(_0x413cf5){return _0x413cf5[_0x607a('0xdd')](_0x2bc5dc[_0x607a('0x40')][_0x607a('0x68')])[_0x607a('0x20')](function(){if(_[_0x607a('0xde')](_0x2bc5dc[_0x607a('0x40')][_0x607a('0x68')])){for(var _0x4114c9=0x0;_0x4114c9<_0x2bc5dc['query'][_0x607a('0x68')][_0x607a('0x45')];_0x4114c9+=0x1){socket[_0x607a('0xdb')](_0x607a('0xdf'),{'UserId':Number(_0x2bc5dc['query'][_0x607a('0x68')][_0x4114c9]),'SmsAccountId':Number(_0x2bc5dc[_0x607a('0x55')]['id'])});}}else{socket[_0x607a('0xdb')](_0x607a('0xdf'),{'UserId':Number(_0x2bc5dc['query'][_0x607a('0x68')]),'SmsAccountId':Number(_0x2bc5dc[_0x607a('0x55')]['id'])});}});}})[_0x607a('0x20')](respondWithStatusCode(_0x1481ae,null))[_0x607a('0x54')](handleError(_0x1481ae,null));};exports['getAgents']=function(_0x5d6d58,_0x204233,_0x196def){var _0xb3120c={};var _0xe31e8a={};var _0x137b10;var _0x17d6be;return db[_0x607a('0x3b')][_0x607a('0x64')]({'where':{'id':_0x5d6d58['params']['id']}})[_0x607a('0x20')](handleEntityNotFound(_0x204233,null))[_0x607a('0x20')](function(_0x1a94ad){if(_0x1a94ad){_0x137b10=_0x1a94ad;_0xe31e8a[_0x607a('0x3f')]=_['keys'](db[_0x607a('0xaa')][_0x607a('0x66')]);_0xe31e8a[_0x607a('0x40')]=_[_0x607a('0x41')](_0x5d6d58[_0x607a('0x40')]);_0xe31e8a['filters']=_[_0x607a('0x42')](_0xe31e8a['model'],_0xe31e8a[_0x607a('0x40')]);_0xb3120c[_0x607a('0x43')]=_[_0x607a('0x42')](_0xe31e8a[_0x607a('0x3f')],qs[_0x607a('0x44')](_0x5d6d58[_0x607a('0x40')][_0x607a('0x44')]));_0xb3120c[_0x607a('0x43')]=_0xb3120c[_0x607a('0x43')][_0x607a('0x45')]?_0xb3120c['attributes']:_0xe31e8a['model'];_0xb3120c[_0x607a('0x48')]=qs[_0x607a('0x49')](_0x5d6d58[_0x607a('0x40')]['sort']);_0xb3120c['where']=qs[_0x607a('0x4c')](_[_0x607a('0x4b')](_0x5d6d58['query'],_0xe31e8a[_0x607a('0x4c')]));if(_0x5d6d58[_0x607a('0x40')][_0x607a('0x4d')]){_0xb3120c['where']=_[_0x607a('0x4e')](_0xb3120c[_0x607a('0x4a')],{'$or':_['map'](_0xb3120c[_0x607a('0x43')],function(_0x389ab1){var _0x313f1e={};_0x313f1e[_0x389ab1]={'$like':'%'+_0x5d6d58[_0x607a('0x40')][_0x607a('0x4d')]+'%'};return _0x313f1e;})});}_0xb3120c=_[_0x607a('0x4e')]({},_0xb3120c,_0x5d6d58[_0x607a('0x50')]);return _0x137b10[_0x607a('0xe0')](_0xb3120c);}})[_0x607a('0x20')](function(_0x4746ae){if(_0x4746ae){_0x17d6be=_0x4746ae[_0x607a('0x45')];if(!_0x5d6d58[_0x607a('0x40')][_0x607a('0x46')]('nolimit')){_0xb3120c[_0x607a('0x2b')]=qs[_0x607a('0x2b')](_0x5d6d58['query'][_0x607a('0x2b')]);_0xb3120c[_0x607a('0x2a')]=qs[_0x607a('0x2a')](_0x5d6d58[_0x607a('0x40')]['offset']);}return _0x137b10['getAgents'](_0xb3120c);}})[_0x607a('0x20')](function(_0x3814f7){if(_0x3814f7){return _0x3814f7?{'count':_0x17d6be,'rows':_0x3814f7}:null;}})['then'](respondWithResult(_0x204233,null))[_0x607a('0x54')](handleError(_0x204233,null));};
\ No newline at end of file