Built motion from commit 85328c08.|2.5.50
[motion2.git] / server / api / smsAccount / smsAccount.controller.js
index 99626aa..9b08fcd 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 _0x681b=['no\x20available\x20attributes','difference','createdAt','updatedAt','CompanyId','ListId','mobile','twilio','from','From','messageId','MessageSid','skebby','sender','connectel','clicksend','message_id','plivo','Text','MessageUUID','results','csc','originatingAddress','clickatell','fromNumber','text','intelepeer','refid','from\x20is\x20mandatory','isNil','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','CmContact','Contacts','list','contact','SmsInteraction','spread','interaction','created','close','unmanaged','*,*,*,*','AttachmentId','User','UserId','unshift','agent','startRouting','Start','receiveMessage','entity\x20found','stringify','set','Content-Type','text/xml','addApplications','sequelize','transaction','ISOLATION_LEVELS','bulkCreate','findAndCountAll','stack','getApplications','getInteractions','fullname','internal','Tag','Tags','tag','body\x20is\x20mandatory\x20and\x20not\x20empty','to\x20is\x20mandatory','List','out','SmsMessage','Messages','dataValues','push','received\x20delivery\x20report\x20from','inspect','skebby_dispatch_id','requestid','statusInt','status_code','infobip','groupName','DELIVERED','bandwidth','redif','error_code','message-delivered','DELIVRD','ACCEPTD','statusGet','message-id','state','addAgents','omit','emit','userSmsAccount:save','removeAgents','isArray','userSmsAccount:remove','getAgents','eml-format','rimraf','zip-dir','fast-json-patch','moment','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','register','http','request','then','info','SmsAccount,\x20%s,\x20%s','debug','SmsAccount,\x20%s,\x20%s,\x20%s','request\x20sent','error','code','message','result','catch','sendStatus','status','end','json','offset','limit','undefined','count','Content-Range','apply','reject','get','SmsAccounts','UserProfileResource','destroy','name','send','Pause','mandatoryDispositionPause','SmsAccount','rawAttributes','fieldName','type','key','model','map','query','keys','filters','attributes','fields','length','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','includeAll','include','findAll','rows','show','params','intersection','options','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','find','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','describe','addDisposition','SmsAccountId','Disposition','getDispositions','hasOwnProperty','removeDispositions','ids','addAnswer','getAnswers','findOne','CannedAnswer','removeAnswers','sms','SmsApplication','account','applications','orderBy','Applications','priority','asc','Sequelize','ValidationError'];(function(_0x2ef740,_0x1c81be){var _0x50214b=function(_0x1b4413){while(--_0x1b4413){_0x2ef740['push'](_0x2ef740['shift']());}};_0x50214b(++_0x1c81be);}(_0x681b,0x6b));var _0xb681=function(_0x1e6a64,_0x1001d5){_0x1e6a64=_0x1e6a64-0x0;var _0x2fc43c=_0x681b[_0x1e6a64];return _0x2fc43c;};'use strict';var emlformat=require(_0xb681('0x0'));var rimraf=require(_0xb681('0x1'));var zipdir=require(_0xb681('0x2'));var jsonpatch=require(_0xb681('0x3'));var rp=require('request-promise');var moment=require(_0xb681('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xb681('0x5'));var util=require(_0xb681('0x6'));var path=require(_0xb681('0x7'));var sox=require(_0xb681('0x8'));var csv=require(_0xb681('0x9'));var ejs=require(_0xb681('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xb681('0xb'));var squel=require(_0xb681('0xc'));var crypto=require(_0xb681('0xd'));var jsforce=require(_0xb681('0xe'));var deskjs=require(_0xb681('0xf'));var toCsv=require(_0xb681('0x9'));var querystring=require('querystring');var Papa=require(_0xb681('0x10'));var Redis=require(_0xb681('0x11'));var authService=require(_0xb681('0x12'));var qs=require(_0xb681('0x13'));var as=require(_0xb681('0x14'));var hardwareService=require(_0xb681('0x15'));var logger=require(_0xb681('0x16'))(_0xb681('0x17'));var utils=require('../../config/utils');var config=require(_0xb681('0x18'));var licenseUtil=require(_0xb681('0x19'));var db=require(_0xb681('0x1a'))['db'];config[_0xb681('0x1b')]=_[_0xb681('0x1c')](config['redis'],{'host':_0xb681('0x1d'),'port':0x18eb});var socket=require(_0xb681('0x1e'))(new Redis(config[_0xb681('0x1b')]));require('./smsAccount.socket')[_0xb681('0x1f')](socket);var jayson=require('jayson/promise');var client=jayson['client'][_0xb681('0x20')]({'port':0x232c});function respondWithRpcPromise(_0x509163,_0x28a100,_0x1b697b,_0x3be0b7){return new BPromise(function(_0x41f90e,_0xc90e18){var _0x4339aa=_0x3be0b7||client;return _0x4339aa[_0xb681('0x21')](_0x509163,_0x1b697b)[_0xb681('0x22')](function(_0x422a08){logger[_0xb681('0x23')](_0xb681('0x24'),_0x28a100,'request\x20sent');logger[_0xb681('0x25')](_0xb681('0x26'),_0x28a100,_0xb681('0x27'),JSON['stringify'](_0x422a08));if(_0x422a08[_0xb681('0x28')]){if(_0x422a08['error'][_0xb681('0x29')]===0x1f4){logger[_0xb681('0x28')](_0xb681('0x24'),_0x28a100,_0x422a08[_0xb681('0x28')]['message']);return _0xc90e18(_0x422a08[_0xb681('0x28')][_0xb681('0x2a')]);}logger[_0xb681('0x28')]('SmsAccount,\x20%s,\x20%s',_0x28a100,_0x422a08[_0xb681('0x28')][_0xb681('0x2a')]);return _0x41f90e(_0x422a08[_0xb681('0x28')][_0xb681('0x2a')]);}else{logger[_0xb681('0x23')](_0xb681('0x24'),_0x28a100,_0xb681('0x27'));_0x41f90e(_0x422a08[_0xb681('0x2b')][_0xb681('0x2a')]);}})[_0xb681('0x2c')](function(_0x1b448c){logger[_0xb681('0x28')](_0xb681('0x24'),_0x28a100,_0x1b448c);_0xc90e18(_0x1b448c);});});}function respondWithStatusCode(_0x243c81,_0x4e866b){_0x4e866b=_0x4e866b||0xcc;return function(_0x445db6){if(_0x445db6){return _0x243c81[_0xb681('0x2d')](_0x4e866b);}return _0x243c81[_0xb681('0x2e')](_0x4e866b)[_0xb681('0x2f')]();};}function respondWithResult(_0x2026ad,_0x114cfd){_0x114cfd=_0x114cfd||0xc8;return function(_0x357006){if(_0x357006){return _0x2026ad['status'](_0x114cfd)[_0xb681('0x30')](_0x357006);}};}function respondWithFilteredResult(_0x37b715,_0x2b11d7){return function(_0x4d3bf3){if(_0x4d3bf3){var _0x290817=typeof _0x2b11d7[_0xb681('0x31')]==='undefined'&&typeof _0x2b11d7[_0xb681('0x32')]===_0xb681('0x33');var _0x40f4df=_0x4d3bf3[_0xb681('0x34')];var _0x37897d=_0x290817?0x0:_0x2b11d7[_0xb681('0x31')];var _0x39ecf0=_0x290817?_0x4d3bf3['count']:_0x2b11d7[_0xb681('0x31')]+_0x2b11d7['limit'];var _0x248b03;if(_0x39ecf0>=_0x40f4df){_0x39ecf0=_0x40f4df;_0x248b03=0xc8;}else{_0x248b03=0xce;}_0x37b715[_0xb681('0x2e')](_0x248b03);return _0x37b715['set'](_0xb681('0x35'),_0x37897d+'-'+_0x39ecf0+'/'+_0x40f4df)['json'](_0x4d3bf3);}return null;};}function patchUpdates(_0x223d4f){return function(_0x280dc6){try{jsonpatch[_0xb681('0x36')](_0x280dc6,_0x223d4f,!![]);}catch(_0x4603f6){return BPromise[_0xb681('0x37')](_0x4603f6);}return _0x280dc6['save']();};}function saveUpdates(_0x1820c8,_0x3cab01){return function(_0x209573){if(_0x209573){return _0x209573['update'](_0x1820c8)[_0xb681('0x22')](function(_0x272796){return _0x272796;});}return null;};}function removeEntity(_0x2e42d3,_0x41ee80){return function(_0x3c4e68){if(_0x3c4e68){return _0x3c4e68['destroy']()['then'](function(){var _0x9bb0db=_0x3c4e68[_0xb681('0x38')]({'plain':!![]});var _0x205ec7=_0xb681('0x39');return db[_0xb681('0x3a')][_0xb681('0x3b')]({'where':{'type':_0x205ec7,'resourceId':_0x9bb0db['id']}})['then'](function(){return _0x3c4e68;});})[_0xb681('0x22')](function(){_0x2e42d3['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x2afc39,_0x38461d){return function(_0x4e526f){if(!_0x4e526f){_0x2afc39[_0xb681('0x2d')](0x194);}return _0x4e526f;};}function handleError(_0x30092d,_0x3a82a8){_0x3a82a8=_0x3a82a8||0x1f4;return function(_0x3c9d25){logger[_0xb681('0x28')](_0x3c9d25['stack']);if(_0x3c9d25[_0xb681('0x3c')]){delete _0x3c9d25[_0xb681('0x3c')];}_0x30092d[_0xb681('0x2e')](_0x3a82a8)[_0xb681('0x3d')](_0x3c9d25);};}exports['index']=function(_0x108fd9,_0x10f735){var _0x3c213a={'include':[{'model':db[_0xb681('0x3e')],'as':_0xb681('0x3f')}]},_0x545915={},_0x1d5730={'count':0x0,'rows':[]};var _0x40de8d=_['map'](db[_0xb681('0x40')][_0xb681('0x41')],function(_0x240213){return{'name':_0x240213[_0xb681('0x42')],'type':_0x240213[_0xb681('0x43')][_0xb681('0x44')]};});_0x545915[_0xb681('0x45')]=_[_0xb681('0x46')](_0x40de8d,_0xb681('0x3c'));_0x545915[_0xb681('0x47')]=_[_0xb681('0x48')](_0x108fd9[_0xb681('0x47')]);_0x545915[_0xb681('0x49')]=_['intersection'](_0x545915[_0xb681('0x45')],_0x545915[_0xb681('0x47')]);_0x3c213a[_0xb681('0x4a')]=_['intersection'](_0x545915['model'],qs[_0xb681('0x4b')](_0x108fd9[_0xb681('0x47')]['fields']));_0x3c213a[_0xb681('0x4a')]=_0x3c213a[_0xb681('0x4a')][_0xb681('0x4c')]?_0x3c213a['attributes']:_0x545915['model'];if(!_0x108fd9[_0xb681('0x47')]['hasOwnProperty'](_0xb681('0x4d'))){_0x3c213a[_0xb681('0x32')]=qs['limit'](_0x108fd9['query'][_0xb681('0x32')]);_0x3c213a[_0xb681('0x31')]=qs[_0xb681('0x31')](_0x108fd9[_0xb681('0x47')][_0xb681('0x31')]);}_0x3c213a[_0xb681('0x4e')]=qs[_0xb681('0x4f')](_0x108fd9['query'][_0xb681('0x4f')]);_0x3c213a[_0xb681('0x50')]=qs[_0xb681('0x49')](_[_0xb681('0x51')](_0x108fd9[_0xb681('0x47')],_0x545915[_0xb681('0x49')]),_0x40de8d);if(_0x108fd9[_0xb681('0x47')][_0xb681('0x52')]){_0x3c213a[_0xb681('0x50')]=_[_0xb681('0x53')](_0x3c213a[_0xb681('0x50')],{'$or':_[_0xb681('0x46')](_0x40de8d,function(_0x11475f){if(_0x11475f[_0xb681('0x43')]!==_0xb681('0x54')){var _0x416d53={};_0x416d53[_0x11475f[_0xb681('0x3c')]]={'$like':'%'+_0x108fd9['query'][_0xb681('0x52')]+'%'};return _0x416d53;}})});}_0x3c213a=_[_0xb681('0x53')]({},_0x3c213a,_0x108fd9['options']);var _0x20eac1={'where':_0x3c213a['where']};return db[_0xb681('0x40')][_0xb681('0x34')](_0x20eac1)[_0xb681('0x22')](function(_0x1d62c4){_0x1d5730[_0xb681('0x34')]=_0x1d62c4;if(_0x108fd9[_0xb681('0x47')][_0xb681('0x55')]){_0x3c213a[_0xb681('0x56')]=[{'all':!![]}];}return db['SmsAccount'][_0xb681('0x57')](_0x3c213a);})[_0xb681('0x22')](function(_0x166185){_0x1d5730[_0xb681('0x58')]=_0x166185;return _0x1d5730;})[_0xb681('0x22')](respondWithFilteredResult(_0x10f735,_0x3c213a))['catch'](handleError(_0x10f735,null));};exports[_0xb681('0x59')]=function(_0x23913d,_0x324ffe){var _0x38e9aa={'raw':![],'where':{'id':_0x23913d[_0xb681('0x5a')]['id']},'include':[{'model':db[_0xb681('0x3e')],'as':_0xb681('0x3f')}]},_0x2cc525={};_0x2cc525[_0xb681('0x45')]=_[_0xb681('0x48')](db[_0xb681('0x40')][_0xb681('0x41')]);_0x2cc525[_0xb681('0x47')]=_[_0xb681('0x48')](_0x23913d['query']);_0x2cc525[_0xb681('0x49')]=_[_0xb681('0x5b')](_0x2cc525['model'],_0x2cc525[_0xb681('0x47')]);_0x38e9aa[_0xb681('0x4a')]=_[_0xb681('0x5b')](_0x2cc525[_0xb681('0x45')],qs[_0xb681('0x4b')](_0x23913d[_0xb681('0x47')][_0xb681('0x4b')]));_0x38e9aa[_0xb681('0x4a')]=_0x38e9aa[_0xb681('0x4a')][_0xb681('0x4c')]?_0x38e9aa['attributes']:_0x2cc525[_0xb681('0x45')];if(_0x23913d[_0xb681('0x47')][_0xb681('0x55')]){_0x38e9aa[_0xb681('0x56')]=[{'all':!![]}];}_0x38e9aa=_[_0xb681('0x53')]({},_0x38e9aa,_0x23913d[_0xb681('0x5c')]);return db[_0xb681('0x40')]['find'](_0x38e9aa)[_0xb681('0x22')](handleEntityNotFound(_0x324ffe,null))[_0xb681('0x22')](respondWithResult(_0x324ffe,null))[_0xb681('0x2c')](handleError(_0x324ffe,null));};exports['create']=function(_0x4b1d9c,_0x15fe4e){return db[_0xb681('0x40')][_0xb681('0x5d')](_0x4b1d9c[_0xb681('0x5e')],{})[_0xb681('0x22')](function(_0x136987){var _0x4ecb2e=_0x4b1d9c[_0xb681('0x5f')][_0xb681('0x38')]({'plain':!![]});if(!_0x4ecb2e)throw new Error(_0xb681('0x60'));if(_0x4ecb2e[_0xb681('0x61')]===_0xb681('0x5f')){var _0x4ac6cc=_0x136987['get']({'plain':!![]});var _0x1e4483=_0xb681('0x39');return db[_0xb681('0x62')][_0xb681('0x63')]({'where':{'name':_0x1e4483,'userProfileId':_0x4ecb2e[_0xb681('0x64')]},'raw':!![]})[_0xb681('0x22')](function(_0x46ecb2){if(_0x46ecb2&&_0x46ecb2[_0xb681('0x65')]===0x0){return db[_0xb681('0x3a')][_0xb681('0x5d')]({'name':_0x4ac6cc[_0xb681('0x3c')],'resourceId':_0x4ac6cc['id'],'type':_0x46ecb2[_0xb681('0x3c')],'sectionId':_0x46ecb2['id']},{})[_0xb681('0x22')](function(){return _0x136987;});}else{return _0x136987;}})[_0xb681('0x2c')](function(_0x5d19ee){logger[_0xb681('0x28')](_0xb681('0x66'),_0x5d19ee);throw _0x5d19ee;});}return _0x136987;})[_0xb681('0x22')](respondWithResult(_0x15fe4e,0xc9))['catch'](handleError(_0x15fe4e,null));};exports[_0xb681('0x67')]=function(_0x28c735,_0x34fc65){if(_0x28c735['body']['id']){delete _0x28c735[_0xb681('0x5e')]['id'];}return db[_0xb681('0x40')][_0xb681('0x63')]({'where':{'id':_0x28c735[_0xb681('0x5a')]['id']},'include':[{'model':db[_0xb681('0x3e')],'as':_0xb681('0x3f')}]})[_0xb681('0x22')](handleEntityNotFound(_0x34fc65,null))[_0xb681('0x22')](saveUpdates(_0x28c735[_0xb681('0x5e')],null))[_0xb681('0x22')](respondWithResult(_0x34fc65,null))[_0xb681('0x2c')](handleError(_0x34fc65,null));};exports[_0xb681('0x3b')]=function(_0x31fa32,_0x2eb342){return db[_0xb681('0x40')][_0xb681('0x63')]({'where':{'id':_0x31fa32[_0xb681('0x5a')]['id']}})[_0xb681('0x22')](handleEntityNotFound(_0x2eb342,null))[_0xb681('0x22')](removeEntity(_0x2eb342,null))[_0xb681('0x2c')](handleError(_0x2eb342,null));};exports['describe']=function(_0x592d54,_0x3232bb){return db[_0xb681('0x40')][_0xb681('0x68')]()[_0xb681('0x22')](respondWithResult(_0x3232bb,null))['catch'](handleError(_0x3232bb,null));};exports[_0xb681('0x69')]=function(_0x478de9,_0x2ec566,_0x423a5d){if(_0x478de9[_0xb681('0x5e')]['id']){delete _0x478de9[_0xb681('0x5e')]['id'];}return db[_0xb681('0x40')][_0xb681('0x63')]({'where':{'id':_0x478de9[_0xb681('0x5a')]['id']}})[_0xb681('0x22')](handleEntityNotFound(_0x2ec566,null))[_0xb681('0x22')](function(_0x38c8b8){if(_0x38c8b8){_0x478de9[_0xb681('0x5e')][_0xb681('0x6a')]=_0x38c8b8['id'];return db[_0xb681('0x6b')][_0xb681('0x5d')](_0x478de9[_0xb681('0x5e')]);}})[_0xb681('0x22')](respondWithResult(_0x2ec566,null))[_0xb681('0x2c')](handleError(_0x2ec566,null));};exports[_0xb681('0x6c')]=function(_0x52000f,_0x5e6b1a,_0x33acbb){var _0x122046={'raw':![],'where':{}};var _0x8ab275={};var _0x33d07c={'count':0x0,'rows':[]};return db[_0xb681('0x40')]['findOne']({'where':{'id':_0x52000f[_0xb681('0x5a')]['id']}})['then'](handleEntityNotFound(_0x5e6b1a,null))['then'](function(_0x5415cb){if(_0x5415cb){_0x8ab275[_0xb681('0x45')]=_['keys'](db[_0xb681('0x6b')][_0xb681('0x41')]);_0x8ab275[_0xb681('0x47')]=_['keys'](_0x52000f['query']);_0x8ab275[_0xb681('0x49')]=_['intersection'](_0x8ab275[_0xb681('0x45')],_0x8ab275[_0xb681('0x47')]);_0x122046[_0xb681('0x4a')]=_['intersection'](_0x8ab275[_0xb681('0x45')],qs[_0xb681('0x4b')](_0x52000f[_0xb681('0x47')][_0xb681('0x4b')]));_0x122046['attributes']=_0x122046['attributes'][_0xb681('0x4c')]?_0x122046[_0xb681('0x4a')]:_0x8ab275[_0xb681('0x45')];if(!_0x52000f['query'][_0xb681('0x6d')](_0xb681('0x4d'))){_0x122046[_0xb681('0x32')]=qs['limit'](_0x52000f[_0xb681('0x47')][_0xb681('0x32')]);_0x122046[_0xb681('0x31')]=qs[_0xb681('0x31')](_0x52000f[_0xb681('0x47')][_0xb681('0x31')]);}_0x122046['order']=qs[_0xb681('0x4f')](_0x52000f[_0xb681('0x47')][_0xb681('0x4f')]);_0x122046['where']=qs['filters'](_[_0xb681('0x51')](_0x52000f['query'],_0x8ab275[_0xb681('0x49')]));_0x122046[_0xb681('0x50')][_0xb681('0x6a')]=_0x5415cb['id'];if(_0x52000f[_0xb681('0x47')][_0xb681('0x52')]){_0x122046[_0xb681('0x50')]=_[_0xb681('0x53')](_0x122046[_0xb681('0x50')],{'$or':_[_0xb681('0x46')](_0x122046['attributes'],function(_0x3da1fd){var _0x5697f3={};_0x5697f3[_0x3da1fd]={'$like':'%'+_0x52000f[_0xb681('0x47')][_0xb681('0x52')]+'%'};return _0x5697f3;})});}_0x122046=_[_0xb681('0x53')]({},_0x122046,_0x52000f[_0xb681('0x5c')]);return db[_0xb681('0x6b')]['count']({'where':_0x122046[_0xb681('0x50')]})[_0xb681('0x22')](function(_0x1efba8){_0x33d07c[_0xb681('0x34')]=_0x1efba8;if(_0x52000f['query'][_0xb681('0x55')]){_0x122046['include']=[{'all':!![]}];}return db[_0xb681('0x6b')][_0xb681('0x57')](_0x122046);})['then'](function(_0x17172f){_0x33d07c['rows']=_0x17172f;return _0x33d07c;});}})[_0xb681('0x22')](respondWithFilteredResult(_0x5e6b1a,_0x122046))[_0xb681('0x2c')](handleError(_0x5e6b1a,null));};exports[_0xb681('0x6e')]=function(_0x4d36d1,_0x2be5c1,_0x434bf2){return db[_0xb681('0x40')][_0xb681('0x63')]({'where':{'id':_0x4d36d1[_0xb681('0x5a')]['id']}})[_0xb681('0x22')](handleEntityNotFound(_0x2be5c1,null))[_0xb681('0x22')](function(_0x30c2e5){if(_0x30c2e5){return _0x30c2e5[_0xb681('0x6e')](_0x4d36d1[_0xb681('0x47')][_0xb681('0x6f')]);}})[_0xb681('0x22')](respondWithStatusCode(_0x2be5c1,null))[_0xb681('0x2c')](handleError(_0x2be5c1,null));};exports[_0xb681('0x70')]=function(_0x3bf323,_0x4b9a9e,_0x4e8caf){if(_0x3bf323[_0xb681('0x5e')]['id']){delete _0x3bf323[_0xb681('0x5e')]['id'];}return db['SmsAccount'][_0xb681('0x63')]({'where':{'id':_0x3bf323[_0xb681('0x5a')]['id']}})[_0xb681('0x22')](handleEntityNotFound(_0x4b9a9e,null))[_0xb681('0x22')](function(_0x2aed49){if(_0x2aed49){_0x3bf323[_0xb681('0x5e')][_0xb681('0x6a')]=_0x2aed49['id'];return db['CannedAnswer'][_0xb681('0x5d')](_0x3bf323['body']);}})[_0xb681('0x22')](respondWithResult(_0x4b9a9e,null))[_0xb681('0x2c')](handleError(_0x4b9a9e,null));};exports[_0xb681('0x71')]=function(_0x2fa0c4,_0x3d53dc,_0x4d53bf){var _0x30f146={'raw':![],'where':{}};var _0x43d0a7={};var _0x2821ba={'count':0x0,'rows':[]};return db[_0xb681('0x40')][_0xb681('0x72')]({'where':{'id':_0x2fa0c4[_0xb681('0x5a')]['id']}})[_0xb681('0x22')](handleEntityNotFound(_0x3d53dc,null))['then'](function(_0x2b3249){if(_0x2b3249){_0x43d0a7['model']=_[_0xb681('0x48')](db['CannedAnswer']['rawAttributes']);_0x43d0a7[_0xb681('0x47')]=_[_0xb681('0x48')](_0x2fa0c4[_0xb681('0x47')]);_0x43d0a7[_0xb681('0x49')]=_[_0xb681('0x5b')](_0x43d0a7[_0xb681('0x45')],_0x43d0a7['query']);_0x30f146['attributes']=_[_0xb681('0x5b')](_0x43d0a7[_0xb681('0x45')],qs[_0xb681('0x4b')](_0x2fa0c4[_0xb681('0x47')][_0xb681('0x4b')]));_0x30f146['attributes']=_0x30f146[_0xb681('0x4a')][_0xb681('0x4c')]?_0x30f146['attributes']:_0x43d0a7[_0xb681('0x45')];if(!_0x2fa0c4[_0xb681('0x47')][_0xb681('0x6d')]('nolimit')){_0x30f146[_0xb681('0x32')]=qs[_0xb681('0x32')](_0x2fa0c4['query']['limit']);_0x30f146[_0xb681('0x31')]=qs[_0xb681('0x31')](_0x2fa0c4[_0xb681('0x47')][_0xb681('0x31')]);}_0x30f146['order']=qs[_0xb681('0x4f')](_0x2fa0c4[_0xb681('0x47')][_0xb681('0x4f')]);_0x30f146[_0xb681('0x50')]=qs['filters'](_[_0xb681('0x51')](_0x2fa0c4[_0xb681('0x47')],_0x43d0a7['filters']));_0x30f146[_0xb681('0x50')][_0xb681('0x6a')]=_0x2b3249['id'];if(_0x2fa0c4[_0xb681('0x47')]['filter']){_0x30f146[_0xb681('0x50')]=_[_0xb681('0x53')](_0x30f146[_0xb681('0x50')],{'$or':_['map'](_0x30f146['attributes'],function(_0x11c34c){var _0x270bd9={};_0x270bd9[_0x11c34c]={'$like':'%'+_0x2fa0c4[_0xb681('0x47')][_0xb681('0x52')]+'%'};return _0x270bd9;})});}_0x30f146=_[_0xb681('0x53')]({},_0x30f146,_0x2fa0c4['options']);return db[_0xb681('0x73')][_0xb681('0x34')]({'where':_0x30f146[_0xb681('0x50')]})[_0xb681('0x22')](function(_0x298de3){_0x2821ba[_0xb681('0x34')]=_0x298de3;if(_0x2fa0c4['query']['includeAll']){_0x30f146[_0xb681('0x56')]=[{'all':!![]}];}return db['CannedAnswer']['findAll'](_0x30f146);})[_0xb681('0x22')](function(_0x1dbb77){_0x2821ba[_0xb681('0x58')]=_0x1dbb77;return _0x2821ba;});}})['then'](respondWithFilteredResult(_0x3d53dc,_0x30f146))[_0xb681('0x2c')](handleError(_0x3d53dc,null));};exports[_0xb681('0x74')]=function(_0x162ed8,_0x38bd11,_0x879b7d){return db[_0xb681('0x40')][_0xb681('0x63')]({'where':{'id':_0x162ed8['params']['id']}})[_0xb681('0x22')](handleEntityNotFound(_0x38bd11,null))[_0xb681('0x22')](function(_0x1b07a6){if(_0x1b07a6){return _0x1b07a6[_0xb681('0x74')](_0x162ed8[_0xb681('0x47')][_0xb681('0x6f')]);}})[_0xb681('0x22')](respondWithStatusCode(_0x38bd11,null))[_0xb681('0x2c')](handleError(_0x38bd11,null));};exports['notify']=function(_0x42ee57,_0x432860,_0x1129ea){var _0x434275={'channel':_0xb681('0x75')};var _0x25f260=[];var _0x30719d=[];var _0x38ffcb={};return db['SmsAccount'][_0xb681('0x63')]({'where':{'id':_0x42ee57['params']['id']},'include':[{'model':db[_0xb681('0x76')],'as':'Applications'}]})[_0xb681('0x22')](handleEntityNotFound(_0x432860,null))[_0xb681('0x22')](function(_0x438546){_0x434275[_0xb681('0x77')]=_0x438546;_0x434275[_0xb681('0x78')]=_[_0xb681('0x79')](_0x438546[_0xb681('0x7a')],[_0xb681('0x7b')],[_0xb681('0x7c')]);if(_0x434275[_0xb681('0x77')][_0xb681('0x7a')]){delete _0x434275[_0xb681('0x77')][_0xb681('0x7a')];}return db['CmContact'][_0xb681('0x68')]();})[_0xb681('0x22')](function(_0x1b4dd2){if(!_0x1b4dd2){throw new db[(_0xb681('0x7d'))][(_0xb681('0x7e'))](_0xb681('0x7f'));}_0x25f260=_[_0xb681('0x80')](_[_0xb681('0x48')](_0x1b4dd2),[_0xb681('0x81'),_0xb681('0x82')]);_0x30719d=_[_0xb681('0x80')](_[_0xb681('0x48')](_0x1b4dd2),[_0xb681('0x81'),_0xb681('0x82'),_0xb681('0x83'),_0xb681('0x84')]);_0x434275[_0xb681('0x5e')]={'mapKey':_0xb681('0x85')};if(_0x434275[_0xb681('0x77')][_0xb681('0x43')]){switch(_0x434275[_0xb681('0x77')][_0xb681('0x43')]){case _0xb681('0x86'):_0x434275[_0xb681('0x5e')][_0xb681('0x87')]=_0x42ee57[_0xb681('0x5e')][_0xb681('0x88')];_0x434275[_0xb681('0x5e')][_0xb681('0x5e')]=_0x42ee57['body']['Body'];_0x434275[_0xb681('0x5e')][_0xb681('0x89')]=_0x42ee57[_0xb681('0x5e')][_0xb681('0x8a')];break;case _0xb681('0x8b'):_0x434275[_0xb681('0x5e')]['from']='+'+_0x42ee57['body'][_0xb681('0x8c')];_0x434275[_0xb681('0x5e')][_0xb681('0x5e')]=_0x42ee57['body']['text'];break;case _0xb681('0x8d'):_0x434275[_0xb681('0x5e')]['from']=_0x42ee57[_0xb681('0x5e')]['from'];_0x434275[_0xb681('0x5e')][_0xb681('0x5e')]=_0x42ee57[_0xb681('0x5e')][_0xb681('0x2a')];break;case _0xb681('0x8e'):_0x434275[_0xb681('0x5e')][_0xb681('0x87')]=_0x42ee57[_0xb681('0x5e')]['from'];_0x434275[_0xb681('0x5e')][_0xb681('0x5e')]=_0x42ee57[_0xb681('0x5e')]['body'];_0x434275[_0xb681('0x5e')]['messageId']=_0x42ee57[_0xb681('0x5e')][_0xb681('0x8f')];break;case _0xb681('0x90'):_0x434275['body'][_0xb681('0x87')]=_0x42ee57[_0xb681('0x5e')][_0xb681('0x88')];_0x434275[_0xb681('0x5e')][_0xb681('0x5e')]=_0x42ee57['body'][_0xb681('0x91')];_0x434275[_0xb681('0x5e')][_0xb681('0x89')]=_0x42ee57['body'][_0xb681('0x92')];break;case'infobip':_0x434275['body'][_0xb681('0x87')]='+'+_0x42ee57[_0xb681('0x5e')][_0xb681('0x93')][0x0][_0xb681('0x87')];_0x434275[_0xb681('0x5e')][_0xb681('0x5e')]=_0x42ee57[_0xb681('0x5e')][_0xb681('0x93')][0x0]['text'];_0x434275[_0xb681('0x5e')]['messageId']=_0x42ee57[_0xb681('0x5e')][_0xb681('0x93')][0x0][_0xb681('0x89')];break;case _0xb681('0x94'):_0x434275[_0xb681('0x5e')][_0xb681('0x87')]=_0x42ee57[_0xb681('0x5e')][_0xb681('0x95')];_0x434275[_0xb681('0x5e')][_0xb681('0x5e')]=_0x42ee57['body']['segmentedMessage'][_0xb681('0x2a')];break;case _0xb681('0x96'):_0x434275['body']['from']=_0x42ee57[_0xb681('0x5e')][_0xb681('0x97')];_0x434275['body']['body']=_0x42ee57[_0xb681('0x5e')]['text'];_0x434275['body']['messageId']=_0x42ee57[_0xb681('0x5e')]['replyMessageId'];break;case'bandwidth':_0x434275[_0xb681('0x5e')][_0xb681('0x89')]=_0x42ee57[_0xb681('0x5e')][0x0][_0xb681('0x2a')]['id'];_0x434275[_0xb681('0x5e')][_0xb681('0x87')]=_0x42ee57[_0xb681('0x5e')][0x0][_0xb681('0x2a')][_0xb681('0x87')];_0x434275[_0xb681('0x5e')][_0xb681('0x5e')]=_0x42ee57[_0xb681('0x5e')][0x0][_0xb681('0x2a')][_0xb681('0x98')];break;case _0xb681('0x99'):_0x434275[_0xb681('0x5e')][_0xb681('0x87')]=_0x42ee57[_0xb681('0x5e')][_0xb681('0x87')];_0x434275[_0xb681('0x5e')]['body']=_0x42ee57['body'][_0xb681('0x2a')];_0x434275['body'][_0xb681('0x89')]=_0x42ee57['body'][_0xb681('0x9a')];break;}}if(_0x434275[_0xb681('0x5e')]['id']){delete _0x434275['body']['id'];}if(_['isNil'](_0x434275[_0xb681('0x5e')][_0xb681('0x87')])){throw new db['Sequelize'][(_0xb681('0x7e'))](_0xb681('0x9b'));}if(_['isNil'](_0x434275[_0xb681('0x5e')]['body'])||_0x434275[_0xb681('0x5e')][_0xb681('0x5e')]===''){throw new db[(_0xb681('0x7d'))]['ValidationError']('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0xb681('0x9c')](_0x434275[_0xb681('0x5e')][_0xb681('0x9d')])){throw new db[(_0xb681('0x7d'))][(_0xb681('0x7e'))](_0xb681('0x9e')+_0x30719d);}if(!_[_0xb681('0x9f')](_0x30719d,_0x434275[_0xb681('0x5e')][_0xb681('0x9d')])){throw new db[(_0xb681('0x7d'))][(_0xb681('0x7e'))](_0xb681('0xa0')+_0x30719d);}_0x38ffcb[_0x434275[_0xb681('0x5e')][_0xb681('0x9d')]]=_0x434275['body'][_0xb681('0x87')];return db[_0xb681('0xa1')]['find']({'where':{'id':_0x434275['account'][_0xb681('0x84')]},'include':[{'model':db[_0xb681('0xa2')],'as':_0xb681('0xa3'),'where':_0x38ffcb,'limit':0x1,'order':[[_0xb681('0x82'),'DESC']]}]});})[_0xb681('0x22')](handleEntityNotFound(_0x432860,null))[_0xb681('0x22')](function(_0x463e54){if(_0x463e54){_0x434275[_0xb681('0xa4')]=_['omit'](_0x463e54,[_0xb681('0xa3')]);if(_0x463e54['Contacts'][_0xb681('0x4c')]){return _0x463e54[_0xb681('0xa3')][0x0];}var _0x5c352d=_['defaults'](_0x434275['body'],{'firstName':_0x434275['body'][_0xb681('0x87')],'ListId':_0x463e54['id']});_0x5c352d[_0x434275[_0xb681('0x5e')][_0xb681('0x9d')]]=_0x434275[_0xb681('0x5e')][_0xb681('0x87')];return db[_0xb681('0xa2')]['create'](_0x5c352d,{'fields':_0x25f260,'raw':!![]});}})[_0xb681('0x22')](handleEntityNotFound(_0x432860,null))[_0xb681('0x22')](function(_0x4fcace){if(_0x4fcace){_0x434275[_0xb681('0xa5')]=_0x4fcace;var _0x47e652={'ContactId':_0x4fcace['id'],'phone':_0x434275[_0xb681('0x5e')][_0xb681('0x87')],'SmsAccountId':_0x42ee57[_0xb681('0x5a')]['id']};var _0x4163b3={'ContactId':_0x4fcace['id'],'SmsAccountId':_0x42ee57['params']['id'],'closed':![]};return db[_0xb681('0xa6')][_0xb681('0x63')]({'where':_0x4163b3})[_0xb681('0x22')](function(_0x2cb638){if(_0x2cb638){return[_0x2cb638,![]];}return db['SmsInteraction']['create'](_0x47e652)['then'](function(_0x358ebc){return[_0x358ebc,!![]];});});}})[_0xb681('0xa7')](function(_0xfbea99,_0x467c74){_0x434275[_0xb681('0xa8')]=_0xfbea99[_0xb681('0x38')]({'plain':!![]});_0x434275[_0xb681('0xa8')][_0xb681('0xa9')]=![];if(_0x467c74){if(_0x434275[_0xb681('0x77')]['autoclose']){_0x434275['applications']['push']({'id':0x0,'priority':_0x434275[_0xb681('0x78')]['length']+0x1,'app':_0xb681('0xaa'),'appdata':_0xb681('0xab'),'interval':_0xb681('0xac')});}_0x434275[_0xb681('0xa8')][_0xb681('0xa9')]=!![];}return db['SmsMessage'][_0xb681('0x5d')]({'phone':_0x434275[_0xb681('0x5e')][_0xb681('0x87')],'messageId':_0x434275['body']['messageId'],'body':_0x434275[_0xb681('0x5e')][_0xb681('0x5e')],'SmsAccountId':_0x42ee57[_0xb681('0x5a')]['id'],'SmsInteractionId':_0xfbea99['id'],'direction':'in','ContactId':_0xfbea99['ContactId'],'AttachmentId':_0x434275[_0xb681('0x5e')][_0xb681('0xad')]});})[_0xb681('0x22')](function(_0x35571c){_0x434275[_0xb681('0x2a')]=_0x35571c;if(_0x434275['interaction']['UserId']){return db[_0xb681('0xae')]['find']({'attributes':['id',_0xb681('0x3c')],'where':{'id':_0x434275[_0xb681('0xa8')][_0xb681('0xaf')]}})['then'](function(_0x1d53fa){if(_0x1d53fa){_0x434275[_0xb681('0x78')][_0xb681('0xb0')]({'id':0x0,'priority':0x0,'app':_0xb681('0xb1'),'appdata':_0x1d53fa[_0xb681('0x3c')]+','+(_0x434275[_0xb681('0x77')]['waitForTheAssignedAgent']||0xa),'interval':_0xb681('0xac')});}return respondWithRpcPromise('Start',_0xb681('0xb2'),_0x434275);});}return respondWithRpcPromise(_0xb681('0xb3'),_0xb681('0xb2'),_0x434275);})['then'](function(_0x2321a7){if(_0x2321a7){var _0x1d0d66=0xc8;var _0x101003=_0xb681('0xb4');logger[_0xb681('0x23')](_0xb681('0x26'),_0x101003,_0x1d0d66,_0xb681('0xb5'));logger['debug']('SmsAccount,\x20%s,\x20%s,\x20%s,\x20%s',_0x101003,_0x1d0d66,_0xb681('0xb5'),JSON[_0xb681('0xb6')](_0x2321a7));if(_0x434275[_0xb681('0x77')][_0xb681('0x43')]===_0xb681('0x86')){return _0x432860[_0xb681('0x2e')](_0x1d0d66)[_0xb681('0xb7')](_0xb681('0xb8'),_0xb681('0xb9'))['send']('<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>');}else{return _0x432860[_0xb681('0x2e')](_0x1d0d66)[_0xb681('0x30')](_0x2321a7);}}})['catch'](handleError(_0x432860,null));};exports[_0xb681('0xba')]=function(_0x1052a9,_0x28d868){var _0x48d15d=_0x1052a9[_0xb681('0x5a')]['id'];var _0x2a7974=_0x1052a9[_0xb681('0x5e')];var _0x509670=0xc8;var _0x397c74=null;return db[_0xb681('0xbb')][_0xb681('0xbc')]({'isolationLevel':db[_0xb681('0xbb')]['Transaction'][_0xb681('0xbd')]['READ_COMMITTED']},function(_0x57536c){return db[_0xb681('0x40')]['findOne']({'where':{'id':_0x48d15d},'transaction':_0x57536c})['then'](function(_0x211822){if(_0x211822){return db[_0xb681('0x76')][_0xb681('0x3b')]({'where':{'SmsAccountId':_0x48d15d},'transaction':_0x57536c})['then'](function(){var _0x3d4d8f=_[_0xb681('0x46')](_0x2a7974,function(_0xd91a39){_0xd91a39['SmsAccountId']=_0x48d15d;return _0xd91a39;});return db['SmsApplication'][_0xb681('0xbe')](_0x3d4d8f,{'transaction':_0x57536c});});}else{_0x509670=0x194;_0x397c74=[];}});})[_0xb681('0x22')](function(){if(_0x509670!==0x194){return db[_0xb681('0x76')][_0xb681('0xbf')]({'where':{'SmsAccountId':_0x48d15d},'order':_0xb681('0x7b')})[_0xb681('0x22')](function(_0x4d819e){_0x397c74=_0x4d819e;});}})[_0xb681('0x2c')](function(_0x51a3fa){_0x509670=0x1f4;logger[_0xb681('0x28')](_0x51a3fa[_0xb681('0xc0')]);if(_0x51a3fa['name']){delete _0x51a3fa[_0xb681('0x3c')];}_0x397c74=_0x51a3fa;})['finally'](function(){if(_0x397c74===null){_0x28d868[_0xb681('0x2d')](_0x509670);}else{if(_0x509670===0x1f4){_0x28d868[_0xb681('0x2e')](_0x509670)['send'](_0x397c74);}else{_0x28d868[_0xb681('0x2e')](_0x509670)[_0xb681('0x30')](_0x397c74);}}});};exports[_0xb681('0xc1')]=function(_0x3b65f5,_0x3c783e,_0x402432){var _0x10bee4={};var _0x51456a={};var _0x5877b8;var _0x4d1bdc;return db['SmsAccount'][_0xb681('0x72')]({'where':{'id':_0x3b65f5[_0xb681('0x5a')]['id']}})[_0xb681('0x22')](handleEntityNotFound(_0x3c783e,null))['then'](function(_0x2fb438){if(_0x2fb438){_0x5877b8=_0x2fb438;_0x51456a[_0xb681('0x45')]=_['keys'](db[_0xb681('0x76')][_0xb681('0x41')]);_0x51456a[_0xb681('0x47')]=_[_0xb681('0x48')](_0x3b65f5[_0xb681('0x47')]);_0x51456a[_0xb681('0x49')]=_[_0xb681('0x5b')](_0x51456a[_0xb681('0x45')],_0x51456a[_0xb681('0x47')]);_0x10bee4['attributes']=_[_0xb681('0x5b')](_0x51456a[_0xb681('0x45')],qs['fields'](_0x3b65f5['query'][_0xb681('0x4b')]));_0x10bee4[_0xb681('0x4a')]=_0x10bee4[_0xb681('0x4a')]['length']?_0x10bee4[_0xb681('0x4a')]:_0x51456a['model'];_0x10bee4[_0xb681('0x4e')]=qs[_0xb681('0x4f')](_0x3b65f5[_0xb681('0x47')][_0xb681('0x4f')]);_0x10bee4['where']=qs[_0xb681('0x49')](_['pick'](_0x3b65f5[_0xb681('0x47')],_0x51456a['filters']));if(_0x3b65f5[_0xb681('0x47')][_0xb681('0x52')]){_0x10bee4[_0xb681('0x50')]=_[_0xb681('0x53')](_0x10bee4[_0xb681('0x50')],{'$or':_[_0xb681('0x46')](_0x10bee4['attributes'],function(_0x286bd0){var _0x54439d={};_0x54439d[_0x286bd0]={'$like':'%'+_0x3b65f5[_0xb681('0x47')][_0xb681('0x52')]+'%'};return _0x54439d;})});}_0x10bee4=_[_0xb681('0x53')]({},_0x10bee4,_0x3b65f5[_0xb681('0x5c')]);return _0x5877b8[_0xb681('0xc1')](_0x10bee4);}})[_0xb681('0x22')](function(_0x4dc190){if(_0x4dc190){_0x4d1bdc=_0x4dc190['length'];if(!_0x3b65f5['query'][_0xb681('0x6d')](_0xb681('0x4d'))){_0x10bee4[_0xb681('0x32')]=qs[_0xb681('0x32')](_0x3b65f5[_0xb681('0x47')]['limit']);_0x10bee4[_0xb681('0x31')]=qs[_0xb681('0x31')](_0x3b65f5[_0xb681('0x47')][_0xb681('0x31')]);}return _0x5877b8[_0xb681('0xc1')](_0x10bee4);}})[_0xb681('0x22')](function(_0x4bf48b){if(_0x4bf48b){return _0x4bf48b?{'count':_0x4d1bdc,'rows':_0x4bf48b}:null;}})[_0xb681('0x22')](respondWithResult(_0x3c783e,null))[_0xb681('0x2c')](handleError(_0x3c783e,null));};exports[_0xb681('0xc2')]=function(_0x32c5ad,_0x585429,_0x555423){var _0x3bb675={'raw':![],'where':{}};var _0x18cf6e={};var _0x2d2ce8={'count':0x0,'rows':[]};return db[_0xb681('0x40')][_0xb681('0x72')]({'where':{'id':_0x32c5ad[_0xb681('0x5a')]['id']}})[_0xb681('0x22')](handleEntityNotFound(_0x585429,null))[_0xb681('0x22')](function(_0x3fa6a1){if(_0x3fa6a1){_0x18cf6e[_0xb681('0x45')]=_[_0xb681('0x48')](db[_0xb681('0xa6')][_0xb681('0x41')]);_0x18cf6e['query']=_[_0xb681('0x48')](_0x32c5ad[_0xb681('0x47')]);_0x18cf6e[_0xb681('0x49')]=_[_0xb681('0x5b')](_0x18cf6e[_0xb681('0x45')],_0x18cf6e[_0xb681('0x47')]);_0x3bb675[_0xb681('0x4a')]=_[_0xb681('0x5b')](_0x18cf6e[_0xb681('0x45')],qs[_0xb681('0x4b')](_0x32c5ad[_0xb681('0x47')][_0xb681('0x4b')]));_0x3bb675[_0xb681('0x4a')]=_0x3bb675['attributes']['length']?_0x3bb675['attributes']:_0x18cf6e[_0xb681('0x45')];if(!_0x32c5ad[_0xb681('0x47')][_0xb681('0x6d')](_0xb681('0x4d'))){_0x3bb675[_0xb681('0x32')]=qs[_0xb681('0x32')](_0x32c5ad[_0xb681('0x47')]['limit']);_0x3bb675[_0xb681('0x31')]=qs[_0xb681('0x31')](_0x32c5ad[_0xb681('0x47')][_0xb681('0x31')]);}_0x3bb675['order']=qs[_0xb681('0x4f')](_0x32c5ad[_0xb681('0x47')][_0xb681('0x4f')]);_0x3bb675[_0xb681('0x50')]=qs['filters'](_[_0xb681('0x51')](_0x32c5ad[_0xb681('0x47')],_0x18cf6e[_0xb681('0x49')]));_0x3bb675['where'][_0xb681('0x6a')]=_0x3fa6a1['id'];if(_0x32c5ad[_0xb681('0x47')][_0xb681('0x52')]){_0x3bb675[_0xb681('0x50')]=_[_0xb681('0x53')](_0x3bb675[_0xb681('0x50')],{'$or':_[_0xb681('0x46')](_0x3bb675[_0xb681('0x4a')],function(_0x48fc4c){var _0x399b7f={};_0x399b7f[_0x48fc4c]={'$like':'%'+_0x32c5ad[_0xb681('0x47')]['filter']+'%'};return _0x399b7f;})});}_0x3bb675=_[_0xb681('0x53')]({},_0x3bb675,_0x32c5ad[_0xb681('0x5c')]);return db[_0xb681('0xa6')][_0xb681('0x34')]({'where':_0x3bb675[_0xb681('0x50')]})['then'](function(_0x556893){_0x2d2ce8['count']=_0x556893;if(_0x32c5ad['query']['includeAll']){_0x3bb675[_0xb681('0x56')]=[{'model':db[_0xb681('0xa2')],'as':'Contact','required':![]},{'model':db['User'],'as':'Owner','attributes':[_0xb681('0x3c'),_0xb681('0xc3'),_0xb681('0xc4')],'required':![]},{'model':db[_0xb681('0xc5')],'as':_0xb681('0xc6'),'attributes':['id',_0xb681('0x3c'),'color'],'where':_0x32c5ad[_0xb681('0x47')][_0xb681('0xc7')]?{'id':_0x32c5ad[_0xb681('0x47')][_0xb681('0xc7')]}:undefined,'required':_0x32c5ad['query'][_0xb681('0xc7')]?!![]:![]}];}return db[_0xb681('0xa6')][_0xb681('0x57')](_0x3bb675);})[_0xb681('0x22')](function(_0x53c21a){_0x2d2ce8[_0xb681('0x58')]=_0x53c21a;return _0x2d2ce8;});}})[_0xb681('0x22')](respondWithFilteredResult(_0x585429,_0x3bb675))[_0xb681('0x2c')](handleError(_0x585429,null));};exports[_0xb681('0x3d')]=function(_0x249328,_0x1ca1e2,_0x1517a1){var _0x59cee1,_0x4ec013,_0x45f9f6;if(_[_0xb681('0x9c')](_0x249328[_0xb681('0x5e')][_0xb681('0x5e')])||_0x249328[_0xb681('0x5e')][_0xb681('0x5e')]===''){throw new db['Sequelize']['ValidationError'](_0xb681('0xc8'));}if(_[_0xb681('0x9c')](_0x249328[_0xb681('0x5e')]['to'])){throw new db[(_0xb681('0x7d'))]['ValidationError'](_0xb681('0xc9'));}_0x59cee1=_0x249328['body']['to'];return db[_0xb681('0x40')][_0xb681('0x63')]({'where':{'id':_0x249328[_0xb681('0x5a')]['id']},'include':[{'model':db['CmList'],'as':'List','include':[{'model':db[_0xb681('0xa2')],'as':_0xb681('0xa3'),'where':{'mobile':_0x59cee1},'limit':0x1,'order':[[_0xb681('0x82'),'DESC']]}]}]})[_0xb681('0x22')](handleEntityNotFound(_0x1ca1e2,null))['then'](function(_0x2fa4bc){if(_0x2fa4bc&&_0x2fa4bc[_0xb681('0xca')]){_0x4ec013=_0x2fa4bc[_0xb681('0x38')]({'plain':!![]});if(_0x4ec013[_0xb681('0xca')]&&_0x4ec013[_0xb681('0xca')][_0xb681('0xa3')][_0xb681('0x4c')]){return _0x4ec013['List'][_0xb681('0xa3')][0x0];}return db[_0xb681('0xa2')][_0xb681('0x5d')](_[_0xb681('0x1c')](_0x249328['body'],{'firstName':_0x59cee1,'mobile':_0x59cee1,'phone':_0x59cee1,'ListId':_0x4ec013[_0xb681('0x84')]}));}})[_0xb681('0x22')](handleEntityNotFound(_0x1ca1e2,null))[_0xb681('0x22')](function(_0x53721b){if(_0x53721b){_0x45f9f6=_0x53721b;return db[_0xb681('0xa6')][_0xb681('0x63')]({'where':{'ContactId':_0x45f9f6['id'],'closed':![],'SmsAccountId':_0x4ec013['id']}})[_0xb681('0x22')](function(_0xa5c21e){if(_0xa5c21e){return[_0xa5c21e,![]];}return db[_0xb681('0xa6')]['create']({'UserId':_0x249328[_0xb681('0x5f')]['id'],'ContactId':_0x45f9f6['id'],'SmsAccountId':_0x4ec013['id'],'phone':_0x59cee1,'firstMsgDirection':_0xb681('0xcb'),'Messages':[_['merge'](_0x249328['body'],{'read':![],'body':_0x249328[_0xb681('0x5e')]['body'],'phone':_0x59cee1,'SmsAccountId':_0x4ec013['id'],'UserId':_0x249328[_0xb681('0x5f')]['id'],'ContactId':_0x45f9f6['id']})]},{'include':[{'model':db[_0xb681('0xcc')],'as':_0xb681('0xcd')}]})[_0xb681('0x22')](function(_0x39b842){return[_0x39b842,!![]];});});}})['spread'](function(_0x17315d,_0x3f7faa){if(_0x3f7faa){return _0x17315d;}return db[_0xb681('0xcc')]['create'](_[_0xb681('0x53')](_0x249328[_0xb681('0x5e')],{'read':![],'body':_0x249328[_0xb681('0x5e')][_0xb681('0x5e')],'phone':_0x59cee1,'SmsAccountId':_0x4ec013['id'],'SmsInteractionId':_0x17315d['id'],'UserId':_0x249328[_0xb681('0x5f')]['id'],'ContactId':_0x45f9f6['id']}))[_0xb681('0x22')](function(_0x29c0ca){_0x17315d[_0xb681('0xce')]['Messages']=[];_0x17315d[_0xb681('0xce')][_0xb681('0xcd')][_0xb681('0xcf')](_0x29c0ca[_0xb681('0xce')]);return _0x17315d;});})['then'](respondWithResult(_0x1ca1e2,null))[_0xb681('0x2c')](handleError(_0x1ca1e2,null));};exports[_0xb681('0x2e')]=function(_0x25b40d,_0x4f05a2,_0x3197a2){if(_0x25b40d['body']['id']){delete _0x25b40d['body']['id'];}var _0x93fd66,_0x34c662,_0x5b068a;return db[_0xb681('0x40')][_0xb681('0x63')]({'where':{'id':_0x25b40d[_0xb681('0x5a')]['id']}})[_0xb681('0x22')](handleEntityNotFound(_0x4f05a2,null))[_0xb681('0x22')](function(_0x1bf22f){if(_0x1bf22f){_0x5b068a=_0x1bf22f;logger['debug'](_0xb681('0x26'),'status',_0xb681('0xd0'),_0x1bf22f[_0xb681('0x43')],util[_0xb681('0xd1')](_0x25b40d['body'],{'showHidden':![],'depth':null}));switch(_0x1bf22f['type']){case _0xb681('0x8b'):if(_0x25b40d[_0xb681('0x5e')][_0xb681('0xd2')]&&_0x25b40d['body'][_0xb681('0x2e')]){_0x34c662=_0x25b40d[_0xb681('0x5e')][_0xb681('0x2e')];return db['SmsMessage'][_0xb681('0x63')]({'where':{'messageId':_0x25b40d['body'][_0xb681('0xd2')]}});}break;case _0xb681('0x8d'):if(_0x25b40d[_0xb681('0x5e')][_0xb681('0xd3')]&&_0x25b40d['body'][_0xb681('0xd4')]){_0x34c662=_0x25b40d[_0xb681('0x5e')][_0xb681('0xd4')];return db[_0xb681('0xcc')][_0xb681('0x63')]({'where':{'messageId':_0x25b40d[_0xb681('0x5e')]['requestid']}});}break;case _0xb681('0x8e'):if(_0x25b40d[_0xb681('0x5e')][_0xb681('0x8f')]&&_0x25b40d[_0xb681('0x5e')][_0xb681('0xd5')]){_0x34c662=_0x25b40d['body']['status_code'];return db[_0xb681('0xcc')][_0xb681('0x63')]({'where':{'messageId':_0x25b40d[_0xb681('0x5e')]['message_id']}});}break;case _0xb681('0xd6'):var _0x324d23=_0x25b40d[_0xb681('0x5e')]['results'][0x0];if(_0x324d23[_0xb681('0x89')]&&_0x324d23[_0xb681('0x2e')][_0xb681('0xd7')]===_0xb681('0xd8')){_0x34c662=_0x324d23[_0xb681('0x2e')]['groupName'];return db['SmsMessage'][_0xb681('0x63')]({'where':{'messageId':_0x324d23[_0xb681('0x89')]}});}break;case'clickatell':if(_0x25b40d[_0xb681('0x5e')][_0xb681('0x89')]&&_0x25b40d[_0xb681('0x5e')]['status']){_0x34c662=_0x25b40d[_0xb681('0x5e')]['status'];return db[_0xb681('0xcc')][_0xb681('0x63')]({'where':{'messageId':_0x25b40d['body'][_0xb681('0x89')]}});}break;case _0xb681('0xd9'):if(_0x25b40d['body'][0x0][_0xb681('0x2a')]['id']){_0x34c662=_0x25b40d[_0xb681('0x5e')][0x0]['type'];return db['SmsMessage'][_0xb681('0x63')]({'where':{'messageId':_0x25b40d['body'][0x0]['message']['id']}});}break;case _0xb681('0x99'):if(_0x25b40d['body'][_0xb681('0xda')]&&_0x25b40d[_0xb681('0x5e')][_0xb681('0x2e')]){_0x34c662=_0x25b40d[_0xb681('0x5e')]['status'];return db[_0xb681('0xcc')][_0xb681('0x63')]({'where':{'messageId':_0x25b40d['body']['redif']}});}break;}}})[_0xb681('0x22')](handleEntityNotFound(_0x4f05a2,null))[_0xb681('0x22')](function(_0x1cb7df){if(_0x1cb7df){_0x93fd66=_0x1cb7df;switch(_0x5b068a['type']){case _0xb681('0x8b'):if(_0x34c662===_0xb681('0xd8')){return _0x93fd66[_0xb681('0x67')]({'read':!![]});}else{logger['error'](_0xb681('0x26'),_0xb681('0x2e'),'skebby',util[_0xb681('0xd1')](_0x25b40d['body'],{'showHidden':![],'depth':null}));}break;case _0xb681('0x8d'):if(_0x34c662==='1'){return _0x93fd66[_0xb681('0x67')]({'read':!![]});}else{logger[_0xb681('0x28')](_0xb681('0x26'),_0xb681('0x2e'),_0xb681('0x8b'),util['inspect'](_0x25b40d[_0xb681('0x5e')],{'showHidden':![],'depth':null}));}break;case _0xb681('0x8e'):if(!_0x25b40d[_0xb681('0x5e')][_0xb681('0xdb')]&&_0x34c662>=0xc8&&_0x34c662<=0xce){return _0x93fd66[_0xb681('0x67')]({'read':!![]});}else{logger[_0xb681('0x28')](_0xb681('0x26'),_0xb681('0x2e'),_0xb681('0x8e'),util[_0xb681('0xd1')](_0x25b40d['body'],{'showHidden':![],'depth':null}));}break;case'infobip':var _0x1c2425=_0x25b40d[_0xb681('0x5e')]['results'][0x0];if(_0x1c2425[_0xb681('0x2e')][_0xb681('0xd7')]==='DELIVERED'){return _0x93fd66[_0xb681('0x67')]({'read':!![]});}else{logger[_0xb681('0x28')](_0xb681('0x26'),'status','infobip',util[_0xb681('0xd1')](_0x25b40d['body'],{'showHidden':![],'depth':null}));}break;case'clickatell':if(_0x34c662=='DELIVERED_TO_GATEWAY'||_0x34c662=='RECEIVED_BY_RECIPIENT'){return _0x93fd66[_0xb681('0x67')]({'read':!![]});}else{logger[_0xb681('0x28')](_0xb681('0x26'),_0xb681('0x2e'),_0xb681('0x96'),util[_0xb681('0xd1')](_0x25b40d['body'],{'showHidden':![],'depth':null}));}break;case _0xb681('0xd9'):if(_0x34c662==_0xb681('0xdc')){return _0x93fd66['update']({'read':!![]});}else{logger[_0xb681('0x28')](_0xb681('0x26'),'status','bandwidth',util[_0xb681('0xd1')](_0x25b40d[_0xb681('0x5e')],{'showHidden':![],'depth':null}));}break;case _0xb681('0x99'):if(_0x34c662===_0xb681('0xdd')||_0x34c662===_0xb681('0xde')){return _0x93fd66[_0xb681('0x67')]({'read':!![]});}else{logger['error']('SmsAccount,\x20%s,\x20%s,\x20%s',_0xb681('0x2e'),'intelepeer',util[_0xb681('0xd1')](_0x25b40d['body'],{'showHidden':![],'depth':null}));}break;}return _0x93fd66;}})[_0xb681('0x22')](respondWithResult(_0x4f05a2,null))['catch'](handleError(_0x4f05a2,null));};exports[_0xb681('0xdf')]=function(_0x44b606,_0x177be8,_0x47d016){var _0x48a14e,_0x43d24d,_0x57f5e9;return db['SmsAccount'][_0xb681('0x63')]({'where':{'id':_0x44b606['params']['id']}})[_0xb681('0x22')](handleEntityNotFound(_0x177be8,null))[_0xb681('0x22')](function(_0x123bdf){if(_0x123bdf){_0x57f5e9=_0x123bdf;logger['debug'](_0xb681('0x26'),'status',_0xb681('0xd0'),_0x123bdf['type'],util['inspect'](_0x44b606['query'],{'showHidden':![],'depth':null}));switch(_0x123bdf['type']){case _0xb681('0x94'):if(_0x44b606[_0xb681('0x47')][_0xb681('0xe0')]&&_0x44b606[_0xb681('0x47')][_0xb681('0xe1')]){_0x43d24d=_0x44b606[_0xb681('0x47')]['state'];return db[_0xb681('0xcc')][_0xb681('0x63')]({'where':{'messageId':_0x44b606[_0xb681('0x47')]['message-id']}});}break;}}})['then'](handleEntityNotFound(_0x177be8,null))[_0xb681('0x22')](function(_0x32e33a){if(_0x32e33a){_0x48a14e=_0x32e33a;switch(_0x57f5e9[_0xb681('0x43')]){case _0xb681('0x94'):if(_0x43d24d==='2'||_0x43d24d==='6'){return _0x48a14e[_0xb681('0x67')]({'read':!![]});}else{logger[_0xb681('0x28')](_0xb681('0x26'),_0xb681('0x2e'),_0xb681('0x94'),util[_0xb681('0xd1')](_0x44b606[_0xb681('0x47')],{'showHidden':![],'depth':null}));};break;}return _0x48a14e;}})[_0xb681('0x22')](respondWithResult(_0x177be8,null))[_0xb681('0x2c')](handleError(_0x177be8,null));};exports[_0xb681('0xe2')]=function(_0x5937f9,_0x3ee615,_0x38382f){return db[_0xb681('0x40')][_0xb681('0x63')]({'where':{'id':_0x5937f9[_0xb681('0x5a')]['id']}})['then'](handleEntityNotFound(_0x3ee615,null))[_0xb681('0x22')](function(_0x46372a){if(_0x46372a){return _0x46372a[_0xb681('0xe2')](_0x5937f9['body'][_0xb681('0x6f')],_[_0xb681('0xe3')](_0x5937f9['body'],['ids','id'])||{})[_0xb681('0xa7')](function(_0x3c326e){for(var _0x15d04e=0x0;_0x15d04e<_0x5937f9[_0xb681('0x5e')]['ids']['length'];_0x15d04e+=0x1){socket[_0xb681('0xe4')](_0xb681('0xe5'),{'UserId':Number(_0x5937f9[_0xb681('0x5e')][_0xb681('0x6f')][_0x15d04e]),'SmsAccountId':Number(_0x5937f9['params']['id'])});}return _0x3c326e;});}})[_0xb681('0x22')](respondWithResult(_0x3ee615,null))[_0xb681('0x2c')](handleError(_0x3ee615,null));};exports[_0xb681('0xe6')]=function(_0x2114e5,_0x560d1b,_0xda2040){return db['SmsAccount']['find']({'where':{'id':_0x2114e5[_0xb681('0x5a')]['id']}})[_0xb681('0x22')](handleEntityNotFound(_0x560d1b,null))[_0xb681('0x22')](function(_0xe11fe0){if(_0xe11fe0){return _0xe11fe0['removeAgents'](_0x2114e5[_0xb681('0x47')]['ids'])[_0xb681('0x22')](function(){if(_[_0xb681('0xe7')](_0x2114e5[_0xb681('0x47')][_0xb681('0x6f')])){for(var _0x55ddf5=0x0;_0x55ddf5<_0x2114e5[_0xb681('0x47')][_0xb681('0x6f')][_0xb681('0x4c')];_0x55ddf5+=0x1){socket['emit'](_0xb681('0xe8'),{'UserId':Number(_0x2114e5[_0xb681('0x47')][_0xb681('0x6f')][_0x55ddf5]),'SmsAccountId':Number(_0x2114e5['params']['id'])});}}else{socket[_0xb681('0xe4')](_0xb681('0xe8'),{'UserId':Number(_0x2114e5[_0xb681('0x47')][_0xb681('0x6f')]),'SmsAccountId':Number(_0x2114e5[_0xb681('0x5a')]['id'])});}});}})['then'](respondWithStatusCode(_0x560d1b,null))[_0xb681('0x2c')](handleError(_0x560d1b,null));};exports[_0xb681('0xe9')]=function(_0x5416b1,_0x4691ab,_0x35187e){var _0x1f9bbe={};var _0x34f1b7={};var _0x4976b0;var _0x1da534;return db[_0xb681('0x40')][_0xb681('0x72')]({'where':{'id':_0x5416b1[_0xb681('0x5a')]['id']}})[_0xb681('0x22')](handleEntityNotFound(_0x4691ab,null))[_0xb681('0x22')](function(_0x5bc605){if(_0x5bc605){_0x4976b0=_0x5bc605;_0x34f1b7[_0xb681('0x45')]=_[_0xb681('0x48')](db[_0xb681('0xae')]['rawAttributes']);_0x34f1b7['query']=_[_0xb681('0x48')](_0x5416b1[_0xb681('0x47')]);_0x34f1b7[_0xb681('0x49')]=_[_0xb681('0x5b')](_0x34f1b7['model'],_0x34f1b7[_0xb681('0x47')]);_0x1f9bbe[_0xb681('0x4a')]=_[_0xb681('0x5b')](_0x34f1b7[_0xb681('0x45')],qs[_0xb681('0x4b')](_0x5416b1['query']['fields']));_0x1f9bbe[_0xb681('0x4a')]=_0x1f9bbe[_0xb681('0x4a')]['length']?_0x1f9bbe[_0xb681('0x4a')]:_0x34f1b7[_0xb681('0x45')];_0x1f9bbe['order']=qs[_0xb681('0x4f')](_0x5416b1['query'][_0xb681('0x4f')]);_0x1f9bbe['where']=qs[_0xb681('0x49')](_['pick'](_0x5416b1['query'],_0x34f1b7[_0xb681('0x49')]));if(_0x5416b1[_0xb681('0x47')][_0xb681('0x52')]){_0x1f9bbe[_0xb681('0x50')]=_[_0xb681('0x53')](_0x1f9bbe[_0xb681('0x50')],{'$or':_[_0xb681('0x46')](_0x1f9bbe[_0xb681('0x4a')],function(_0x10f1ea){var _0x43c3f9={};_0x43c3f9[_0x10f1ea]={'$like':'%'+_0x5416b1[_0xb681('0x47')][_0xb681('0x52')]+'%'};return _0x43c3f9;})});}_0x1f9bbe=_[_0xb681('0x53')]({},_0x1f9bbe,_0x5416b1['options']);return _0x4976b0[_0xb681('0xe9')](_0x1f9bbe);}})[_0xb681('0x22')](function(_0x306da9){if(_0x306da9){_0x1da534=_0x306da9[_0xb681('0x4c')];if(!_0x5416b1[_0xb681('0x47')][_0xb681('0x6d')](_0xb681('0x4d'))){_0x1f9bbe['limit']=qs[_0xb681('0x32')](_0x5416b1['query'][_0xb681('0x32')]);_0x1f9bbe[_0xb681('0x31')]=qs['offset'](_0x5416b1[_0xb681('0x47')]['offset']);}return _0x4976b0[_0xb681('0xe9')](_0x1f9bbe);}})[_0xb681('0x22')](function(_0x3e78a9){if(_0x3e78a9){return _0x3e78a9?{'count':_0x1da534,'rows':_0x3e78a9}:null;}})[_0xb681('0x22')](respondWithResult(_0x4691ab,null))[_0xb681('0x2c')](handleError(_0x4691ab,null));};
\ No newline at end of file