Built motion from commit da617fac.|2.6.6
[motion2.git] / server / api / smsAccount / smsAccount.controller.js
index 05d73c0..3732541 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x71cf=['DELIVERED','error_code','RECEIVED_BY_RECIPIENT','message-delivered','DELIVRD','ACCEPTD','state','addAgents','emit','removeAgents','userSmsAccount:remove','getAgents','eml-format','zip-dir','request-promise','moment','bluebird','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','./smsAccount.socket','register','jayson/promise','http','request','then','info','SmsAccount,\x20%s,\x20%s','request\x20sent','debug','error','code','message','catch','sendStatus','status','json','undefined','limit','offset','set','apply','reject','save','destroy','get','SmsAccounts','UserProfileResource','end','stack','name','send','Pause','mandatoryDispositionPause','SmsAccount','fieldName','type','key','model','map','keys','query','intersection','attributes','fields','hasOwnProperty','nolimit','sort','where','filters','filter','merge','VIRTUAL','options','count','includeAll','include','findAll','rows','params','rawAttributes','create','body','user','UserProfileSection','find','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','describe','addDisposition','SmsAccountId','Disposition','getDispositions','length','removeDispositions','ids','addAnswer','findOne','order','pick','CannedAnswer','removeAnswers','notify','sms','SmsApplication','Applications','account','applications','orderBy','priority','asc','CmContact','Sequelize','ValidationError','difference','updatedAt','createdAt','CompanyId','mobile','twilio','from','From','messageId','MessageSid','skebby','sender','text','connectel','message_id','plivo','Text','MessageUUID','results','csc','originatingAddress','segmentedMessage','clickatell','fromNumber','intelepeer','refid','isNil','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','ListId','Contacts','DESC','omit','SmsInteraction','interaction','autoclose','push','close','unmanaged','*,*,*,*','created','ContactId','AttachmentId','UserId','unshift','agent','Start','startRouting','receiveMessage','SmsAccount,\x20%s,\x20%s,\x20%s','SmsAccount,\x20%s,\x20%s,\x20%s,\x20%s','entity\x20found','stringify','Content-Type','text/xml','<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>','sequelize','transaction','Transaction','ISOLATION_LEVELS','findAndCountAll','finally','getApplications','Contact','User','Owner','fullname','internal','Tag','Tags','color','tag','CmList','List','out','Messages','spread','dataValues','received\x20delivery\x20report\x20from','inspect','skebby_dispatch_id','statusInt','SmsMessage','requestid','clicksend','status_code','infobip','groupName','bandwidth','redif'];(function(_0x4bd06e,_0x593701){var _0x85ebb=function(_0x26a7f2){while(--_0x26a7f2){_0x4bd06e['push'](_0x4bd06e['shift']());}};_0x85ebb(++_0x593701);}(_0x71cf,0x1d8));var _0xf71c=function(_0x416cdc,_0x213b87){_0x416cdc=_0x416cdc-0x0;var _0x1931ce=_0x71cf[_0x416cdc];return _0x1931ce;};'use strict';var emlformat=require(_0xf71c('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xf71c('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0xf71c('0x2'));var moment=require(_0xf71c('0x3'));var BPromise=require(_0xf71c('0x4'));var Mustache=require('mustache');var util=require(_0xf71c('0x5'));var path=require(_0xf71c('0x6'));var sox=require(_0xf71c('0x7'));var csv=require(_0xf71c('0x8'));var ejs=require(_0xf71c('0x9'));var fs=require('fs');var fs_extra=require(_0xf71c('0xa'));var _=require(_0xf71c('0xb'));var squel=require(_0xf71c('0xc'));var crypto=require(_0xf71c('0xd'));var jsforce=require(_0xf71c('0xe'));var deskjs=require(_0xf71c('0xf'));var toCsv=require(_0xf71c('0x8'));var querystring=require(_0xf71c('0x10'));var Papa=require(_0xf71c('0x11'));var Redis=require(_0xf71c('0x12'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0xf71c('0x13'));var hardwareService=require(_0xf71c('0x14'));var logger=require(_0xf71c('0x15'))(_0xf71c('0x16'));var utils=require('../../config/utils');var config=require(_0xf71c('0x17'));var licenseUtil=require(_0xf71c('0x18'));var db=require(_0xf71c('0x19'))['db'];config[_0xf71c('0x1a')]=_[_0xf71c('0x1b')](config[_0xf71c('0x1a')],{'host':_0xf71c('0x1c'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xf71c('0x1a')]));require(_0xf71c('0x1d'))[_0xf71c('0x1e')](socket);var jayson=require(_0xf71c('0x1f'));var client=jayson['client'][_0xf71c('0x20')]({'port':0x232c});function respondWithRpcPromise(_0xc216ad,_0x411974,_0x545d08,_0x1bcabb){return new BPromise(function(_0x429bdf,_0xc01e86){var _0x952ca3=_0x1bcabb||client;return _0x952ca3[_0xf71c('0x21')](_0xc216ad,_0x545d08)[_0xf71c('0x22')](function(_0x4d1e87){logger[_0xf71c('0x23')](_0xf71c('0x24'),_0x411974,_0xf71c('0x25'));logger[_0xf71c('0x26')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x411974,_0xf71c('0x25'),JSON['stringify'](_0x4d1e87));if(_0x4d1e87[_0xf71c('0x27')]){if(_0x4d1e87[_0xf71c('0x27')][_0xf71c('0x28')]===0x1f4){logger[_0xf71c('0x27')](_0xf71c('0x24'),_0x411974,_0x4d1e87[_0xf71c('0x27')][_0xf71c('0x29')]);return _0xc01e86(_0x4d1e87[_0xf71c('0x27')][_0xf71c('0x29')]);}logger[_0xf71c('0x27')](_0xf71c('0x24'),_0x411974,_0x4d1e87[_0xf71c('0x27')][_0xf71c('0x29')]);return _0x429bdf(_0x4d1e87[_0xf71c('0x27')][_0xf71c('0x29')]);}else{logger[_0xf71c('0x23')](_0xf71c('0x24'),_0x411974,'request\x20sent');_0x429bdf(_0x4d1e87['result']['message']);}})[_0xf71c('0x2a')](function(_0x1bbc93){logger['error'](_0xf71c('0x24'),_0x411974,_0x1bbc93);_0xc01e86(_0x1bbc93);});});}function respondWithStatusCode(_0x31b8e6,_0x4e21a3){_0x4e21a3=_0x4e21a3||0xcc;return function(_0x1f9f13){if(_0x1f9f13){return _0x31b8e6[_0xf71c('0x2b')](_0x4e21a3);}return _0x31b8e6[_0xf71c('0x2c')](_0x4e21a3)['end']();};}function respondWithResult(_0x81c5b7,_0x5d65d1){_0x5d65d1=_0x5d65d1||0xc8;return function(_0xf33226){if(_0xf33226){return _0x81c5b7[_0xf71c('0x2c')](_0x5d65d1)[_0xf71c('0x2d')](_0xf33226);}};}function respondWithFilteredResult(_0x549ca7,_0x1cc5b7){return function(_0x1a3c14){if(_0x1a3c14){var _0x5923cb=typeof _0x1cc5b7['offset']===_0xf71c('0x2e')&&typeof _0x1cc5b7[_0xf71c('0x2f')]===_0xf71c('0x2e');var _0x3ecba7=_0x1a3c14['count'];var _0x410210=_0x5923cb?0x0:_0x1cc5b7['offset'];var _0x267028=_0x5923cb?_0x1a3c14['count']:_0x1cc5b7[_0xf71c('0x30')]+_0x1cc5b7[_0xf71c('0x2f')];var _0x472ff1;if(_0x267028>=_0x3ecba7){_0x267028=_0x3ecba7;_0x472ff1=0xc8;}else{_0x472ff1=0xce;}_0x549ca7[_0xf71c('0x2c')](_0x472ff1);return _0x549ca7[_0xf71c('0x31')]('Content-Range',_0x410210+'-'+_0x267028+'/'+_0x3ecba7)[_0xf71c('0x2d')](_0x1a3c14);}return null;};}function patchUpdates(_0x4141d3){return function(_0x120e60){try{jsonpatch[_0xf71c('0x32')](_0x120e60,_0x4141d3,!![]);}catch(_0x15dd94){return BPromise[_0xf71c('0x33')](_0x15dd94);}return _0x120e60[_0xf71c('0x34')]();};}function saveUpdates(_0x19a625,_0x42980d){return function(_0x22fe20){if(_0x22fe20){return _0x22fe20['update'](_0x19a625)[_0xf71c('0x22')](function(_0x102b2f){return _0x102b2f;});}return null;};}function removeEntity(_0x47b080,_0x1a0d12){return function(_0x20a7e8){if(_0x20a7e8){return _0x20a7e8[_0xf71c('0x35')]()[_0xf71c('0x22')](function(){var _0x53cdf0=_0x20a7e8[_0xf71c('0x36')]({'plain':!![]});var _0x16a031=_0xf71c('0x37');return db[_0xf71c('0x38')][_0xf71c('0x35')]({'where':{'type':_0x16a031,'resourceId':_0x53cdf0['id']}})[_0xf71c('0x22')](function(){return _0x20a7e8;});})[_0xf71c('0x22')](function(){_0x47b080[_0xf71c('0x2c')](0xcc)[_0xf71c('0x39')]();});}};}function handleEntityNotFound(_0xdcf687,_0xa7ef20){return function(_0x5268b4){if(!_0x5268b4){_0xdcf687[_0xf71c('0x2b')](0x194);}return _0x5268b4;};}function handleError(_0x2604ac,_0x261de7){_0x261de7=_0x261de7||0x1f4;return function(_0x5f1f8d){logger[_0xf71c('0x27')](_0x5f1f8d[_0xf71c('0x3a')]);if(_0x5f1f8d[_0xf71c('0x3b')]){delete _0x5f1f8d[_0xf71c('0x3b')];}_0x2604ac[_0xf71c('0x2c')](_0x261de7)[_0xf71c('0x3c')](_0x5f1f8d);};}exports['index']=function(_0x37ee21,_0x5ee090){var _0x27d3f0={'include':[{'model':db[_0xf71c('0x3d')],'as':_0xf71c('0x3e')}]},_0x5026f1={},_0x474338={'count':0x0,'rows':[]};var _0x1f2ac3=_['map'](db[_0xf71c('0x3f')]['rawAttributes'],function(_0x1a9793){return{'name':_0x1a9793[_0xf71c('0x40')],'type':_0x1a9793[_0xf71c('0x41')][_0xf71c('0x42')]};});_0x5026f1[_0xf71c('0x43')]=_[_0xf71c('0x44')](_0x1f2ac3,_0xf71c('0x3b'));_0x5026f1['query']=_[_0xf71c('0x45')](_0x37ee21[_0xf71c('0x46')]);_0x5026f1['filters']=_[_0xf71c('0x47')](_0x5026f1['model'],_0x5026f1[_0xf71c('0x46')]);_0x27d3f0[_0xf71c('0x48')]=_['intersection'](_0x5026f1['model'],qs[_0xf71c('0x49')](_0x37ee21['query']['fields']));_0x27d3f0[_0xf71c('0x48')]=_0x27d3f0[_0xf71c('0x48')]['length']?_0x27d3f0[_0xf71c('0x48')]:_0x5026f1[_0xf71c('0x43')];if(!_0x37ee21[_0xf71c('0x46')][_0xf71c('0x4a')](_0xf71c('0x4b'))){_0x27d3f0[_0xf71c('0x2f')]=qs['limit'](_0x37ee21[_0xf71c('0x46')]['limit']);_0x27d3f0['offset']=qs['offset'](_0x37ee21[_0xf71c('0x46')][_0xf71c('0x30')]);}_0x27d3f0['order']=qs[_0xf71c('0x4c')](_0x37ee21[_0xf71c('0x46')]['sort']);_0x27d3f0[_0xf71c('0x4d')]=qs[_0xf71c('0x4e')](_['pick'](_0x37ee21[_0xf71c('0x46')],_0x5026f1['filters']),_0x1f2ac3);if(_0x37ee21[_0xf71c('0x46')][_0xf71c('0x4f')]){_0x27d3f0[_0xf71c('0x4d')]=_[_0xf71c('0x50')](_0x27d3f0['where'],{'$or':_['map'](_0x1f2ac3,function(_0x2dba5c){if(_0x2dba5c['type']!==_0xf71c('0x51')){var _0x17e3ef={};_0x17e3ef[_0x2dba5c[_0xf71c('0x3b')]]={'$like':'%'+_0x37ee21[_0xf71c('0x46')][_0xf71c('0x4f')]+'%'};return _0x17e3ef;}})});}_0x27d3f0=_[_0xf71c('0x50')]({},_0x27d3f0,_0x37ee21[_0xf71c('0x52')]);var _0x1bb86a={'where':_0x27d3f0[_0xf71c('0x4d')]};return db[_0xf71c('0x3f')][_0xf71c('0x53')](_0x1bb86a)['then'](function(_0x361a47){_0x474338[_0xf71c('0x53')]=_0x361a47;if(_0x37ee21[_0xf71c('0x46')][_0xf71c('0x54')]){_0x27d3f0[_0xf71c('0x55')]=[{'all':!![]}];}return db[_0xf71c('0x3f')][_0xf71c('0x56')](_0x27d3f0);})['then'](function(_0x59d77e){_0x474338[_0xf71c('0x57')]=_0x59d77e;return _0x474338;})['then'](respondWithFilteredResult(_0x5ee090,_0x27d3f0))[_0xf71c('0x2a')](handleError(_0x5ee090,null));};exports['show']=function(_0xf2129b,_0x349690){var _0x5c1693={'raw':![],'where':{'id':_0xf2129b[_0xf71c('0x58')]['id']},'include':[{'model':db['Pause'],'as':_0xf71c('0x3e')}]},_0xf09f40={};_0xf09f40[_0xf71c('0x43')]=_['keys'](db['SmsAccount'][_0xf71c('0x59')]);_0xf09f40[_0xf71c('0x46')]=_['keys'](_0xf2129b[_0xf71c('0x46')]);_0xf09f40['filters']=_['intersection'](_0xf09f40[_0xf71c('0x43')],_0xf09f40[_0xf71c('0x46')]);_0x5c1693[_0xf71c('0x48')]=_['intersection'](_0xf09f40['model'],qs[_0xf71c('0x49')](_0xf2129b[_0xf71c('0x46')][_0xf71c('0x49')]));_0x5c1693[_0xf71c('0x48')]=_0x5c1693[_0xf71c('0x48')]['length']?_0x5c1693[_0xf71c('0x48')]:_0xf09f40[_0xf71c('0x43')];if(_0xf2129b[_0xf71c('0x46')][_0xf71c('0x54')]){_0x5c1693[_0xf71c('0x55')]=[{'all':!![]}];}_0x5c1693=_[_0xf71c('0x50')]({},_0x5c1693,_0xf2129b['options']);return db[_0xf71c('0x3f')]['find'](_0x5c1693)['then'](handleEntityNotFound(_0x349690,null))[_0xf71c('0x22')](respondWithResult(_0x349690,null))[_0xf71c('0x2a')](handleError(_0x349690,null));};exports[_0xf71c('0x5a')]=function(_0x1ffc0a,_0x188441){return db[_0xf71c('0x3f')][_0xf71c('0x5a')](_0x1ffc0a[_0xf71c('0x5b')],{})[_0xf71c('0x22')](function(_0x47c6d4){var _0x15e0d6=_0x1ffc0a[_0xf71c('0x5c')][_0xf71c('0x36')]({'plain':!![]});if(!_0x15e0d6)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x15e0d6['role']===_0xf71c('0x5c')){var _0x37c8c0=_0x47c6d4[_0xf71c('0x36')]({'plain':!![]});var _0x3c0753=_0xf71c('0x37');return db[_0xf71c('0x5d')][_0xf71c('0x5e')]({'where':{'name':_0x3c0753,'userProfileId':_0x15e0d6[_0xf71c('0x5f')]},'raw':!![]})[_0xf71c('0x22')](function(_0x47b5e8){if(_0x47b5e8&&_0x47b5e8[_0xf71c('0x60')]===0x0){return db[_0xf71c('0x38')][_0xf71c('0x5a')]({'name':_0x37c8c0[_0xf71c('0x3b')],'resourceId':_0x37c8c0['id'],'type':_0x47b5e8['name'],'sectionId':_0x47b5e8['id']},{})['then'](function(){return _0x47c6d4;});}else{return _0x47c6d4;}})[_0xf71c('0x2a')](function(_0x156e7c){logger[_0xf71c('0x27')](_0xf71c('0x61'),_0x156e7c);throw _0x156e7c;});}return _0x47c6d4;})[_0xf71c('0x22')](respondWithResult(_0x188441,0xc9))[_0xf71c('0x2a')](handleError(_0x188441,null));};exports[_0xf71c('0x62')]=function(_0x461980,_0x3d3d26){if(_0x461980[_0xf71c('0x5b')]['id']){delete _0x461980[_0xf71c('0x5b')]['id'];}return db[_0xf71c('0x3f')][_0xf71c('0x5e')]({'where':{'id':_0x461980[_0xf71c('0x58')]['id']},'include':[{'model':db[_0xf71c('0x3d')],'as':_0xf71c('0x3e')}]})[_0xf71c('0x22')](handleEntityNotFound(_0x3d3d26,null))[_0xf71c('0x22')](saveUpdates(_0x461980[_0xf71c('0x5b')],null))[_0xf71c('0x22')](respondWithResult(_0x3d3d26,null))['catch'](handleError(_0x3d3d26,null));};exports['destroy']=function(_0x2ba7de,_0x3581e4){return db['SmsAccount'][_0xf71c('0x5e')]({'where':{'id':_0x2ba7de[_0xf71c('0x58')]['id']}})['then'](handleEntityNotFound(_0x3581e4,null))['then'](removeEntity(_0x3581e4,null))[_0xf71c('0x2a')](handleError(_0x3581e4,null));};exports[_0xf71c('0x63')]=function(_0x2a8595,_0x50f999){return db[_0xf71c('0x3f')][_0xf71c('0x63')]()[_0xf71c('0x22')](respondWithResult(_0x50f999,null))[_0xf71c('0x2a')](handleError(_0x50f999,null));};exports[_0xf71c('0x64')]=function(_0x381bd0,_0x4652b2,_0x4d348c){if(_0x381bd0[_0xf71c('0x5b')]['id']){delete _0x381bd0[_0xf71c('0x5b')]['id'];}return db['SmsAccount'][_0xf71c('0x5e')]({'where':{'id':_0x381bd0[_0xf71c('0x58')]['id']}})[_0xf71c('0x22')](handleEntityNotFound(_0x4652b2,null))['then'](function(_0x595fa0){if(_0x595fa0){_0x381bd0['body'][_0xf71c('0x65')]=_0x595fa0['id'];return db[_0xf71c('0x66')][_0xf71c('0x5a')](_0x381bd0[_0xf71c('0x5b')]);}})[_0xf71c('0x22')](respondWithResult(_0x4652b2,null))[_0xf71c('0x2a')](handleError(_0x4652b2,null));};exports[_0xf71c('0x67')]=function(_0x2470d3,_0x4c6151,_0x2138e3){var _0x4fb709={'raw':![],'where':{}};var _0x5dd094={};var _0x5a7fae={'count':0x0,'rows':[]};return db[_0xf71c('0x3f')]['findOne']({'where':{'id':_0x2470d3[_0xf71c('0x58')]['id']}})[_0xf71c('0x22')](handleEntityNotFound(_0x4c6151,null))[_0xf71c('0x22')](function(_0x395267){if(_0x395267){_0x5dd094[_0xf71c('0x43')]=_[_0xf71c('0x45')](db[_0xf71c('0x66')][_0xf71c('0x59')]);_0x5dd094['query']=_[_0xf71c('0x45')](_0x2470d3[_0xf71c('0x46')]);_0x5dd094['filters']=_[_0xf71c('0x47')](_0x5dd094['model'],_0x5dd094[_0xf71c('0x46')]);_0x4fb709['attributes']=_[_0xf71c('0x47')](_0x5dd094[_0xf71c('0x43')],qs['fields'](_0x2470d3[_0xf71c('0x46')]['fields']));_0x4fb709[_0xf71c('0x48')]=_0x4fb709['attributes'][_0xf71c('0x68')]?_0x4fb709['attributes']:_0x5dd094[_0xf71c('0x43')];if(!_0x2470d3['query']['hasOwnProperty']('nolimit')){_0x4fb709['limit']=qs[_0xf71c('0x2f')](_0x2470d3[_0xf71c('0x46')][_0xf71c('0x2f')]);_0x4fb709[_0xf71c('0x30')]=qs['offset'](_0x2470d3[_0xf71c('0x46')][_0xf71c('0x30')]);}_0x4fb709['order']=qs['sort'](_0x2470d3['query'][_0xf71c('0x4c')]);_0x4fb709[_0xf71c('0x4d')]=qs[_0xf71c('0x4e')](_['pick'](_0x2470d3[_0xf71c('0x46')],_0x5dd094[_0xf71c('0x4e')]));_0x4fb709[_0xf71c('0x4d')][_0xf71c('0x65')]=_0x395267['id'];if(_0x2470d3[_0xf71c('0x46')][_0xf71c('0x4f')]){_0x4fb709[_0xf71c('0x4d')]=_[_0xf71c('0x50')](_0x4fb709[_0xf71c('0x4d')],{'$or':_[_0xf71c('0x44')](_0x4fb709['attributes'],function(_0x568e12){var _0x30e302={};_0x30e302[_0x568e12]={'$like':'%'+_0x2470d3[_0xf71c('0x46')][_0xf71c('0x4f')]+'%'};return _0x30e302;})});}_0x4fb709=_['merge']({},_0x4fb709,_0x2470d3[_0xf71c('0x52')]);return db[_0xf71c('0x66')][_0xf71c('0x53')]({'where':_0x4fb709[_0xf71c('0x4d')]})[_0xf71c('0x22')](function(_0x3c73e8){_0x5a7fae['count']=_0x3c73e8;if(_0x2470d3[_0xf71c('0x46')]['includeAll']){_0x4fb709[_0xf71c('0x55')]=[{'all':!![]}];}return db[_0xf71c('0x66')][_0xf71c('0x56')](_0x4fb709);})[_0xf71c('0x22')](function(_0x1fdcab){_0x5a7fae[_0xf71c('0x57')]=_0x1fdcab;return _0x5a7fae;});}})[_0xf71c('0x22')](respondWithFilteredResult(_0x4c6151,_0x4fb709))['catch'](handleError(_0x4c6151,null));};exports[_0xf71c('0x69')]=function(_0x1fb2b5,_0x5cb75c,_0x3106a3){return db[_0xf71c('0x3f')][_0xf71c('0x5e')]({'where':{'id':_0x1fb2b5[_0xf71c('0x58')]['id']}})['then'](handleEntityNotFound(_0x5cb75c,null))[_0xf71c('0x22')](function(_0x12b270){if(_0x12b270){return _0x12b270[_0xf71c('0x69')](_0x1fb2b5[_0xf71c('0x46')][_0xf71c('0x6a')]);}})['then'](respondWithStatusCode(_0x5cb75c,null))['catch'](handleError(_0x5cb75c,null));};exports[_0xf71c('0x6b')]=function(_0x480029,_0x32834c,_0x423676){if(_0x480029['body']['id']){delete _0x480029['body']['id'];}return db['SmsAccount'][_0xf71c('0x5e')]({'where':{'id':_0x480029[_0xf71c('0x58')]['id']}})['then'](handleEntityNotFound(_0x32834c,null))['then'](function(_0x158bb4){if(_0x158bb4){_0x480029[_0xf71c('0x5b')][_0xf71c('0x65')]=_0x158bb4['id'];return db['CannedAnswer']['create'](_0x480029[_0xf71c('0x5b')]);}})[_0xf71c('0x22')](respondWithResult(_0x32834c,null))[_0xf71c('0x2a')](handleError(_0x32834c,null));};exports['getAnswers']=function(_0x3365bc,_0x67bc09,_0x21846b){var _0x376c4b={'raw':![],'where':{}};var _0x37b416={};var _0x4276ee={'count':0x0,'rows':[]};return db['SmsAccount'][_0xf71c('0x6c')]({'where':{'id':_0x3365bc[_0xf71c('0x58')]['id']}})[_0xf71c('0x22')](handleEntityNotFound(_0x67bc09,null))[_0xf71c('0x22')](function(_0x1db478){if(_0x1db478){_0x37b416[_0xf71c('0x43')]=_[_0xf71c('0x45')](db['CannedAnswer']['rawAttributes']);_0x37b416['query']=_[_0xf71c('0x45')](_0x3365bc['query']);_0x37b416[_0xf71c('0x4e')]=_[_0xf71c('0x47')](_0x37b416['model'],_0x37b416[_0xf71c('0x46')]);_0x376c4b[_0xf71c('0x48')]=_[_0xf71c('0x47')](_0x37b416[_0xf71c('0x43')],qs[_0xf71c('0x49')](_0x3365bc[_0xf71c('0x46')][_0xf71c('0x49')]));_0x376c4b[_0xf71c('0x48')]=_0x376c4b[_0xf71c('0x48')][_0xf71c('0x68')]?_0x376c4b[_0xf71c('0x48')]:_0x37b416[_0xf71c('0x43')];if(!_0x3365bc['query'][_0xf71c('0x4a')]('nolimit')){_0x376c4b['limit']=qs[_0xf71c('0x2f')](_0x3365bc[_0xf71c('0x46')][_0xf71c('0x2f')]);_0x376c4b[_0xf71c('0x30')]=qs[_0xf71c('0x30')](_0x3365bc[_0xf71c('0x46')][_0xf71c('0x30')]);}_0x376c4b[_0xf71c('0x6d')]=qs[_0xf71c('0x4c')](_0x3365bc[_0xf71c('0x46')]['sort']);_0x376c4b[_0xf71c('0x4d')]=qs[_0xf71c('0x4e')](_[_0xf71c('0x6e')](_0x3365bc[_0xf71c('0x46')],_0x37b416['filters']));_0x376c4b[_0xf71c('0x4d')][_0xf71c('0x65')]=_0x1db478['id'];if(_0x3365bc[_0xf71c('0x46')]['filter']){_0x376c4b['where']=_[_0xf71c('0x50')](_0x376c4b['where'],{'$or':_['map'](_0x376c4b[_0xf71c('0x48')],function(_0x30c93b){var _0x1fc587={};_0x1fc587[_0x30c93b]={'$like':'%'+_0x3365bc[_0xf71c('0x46')][_0xf71c('0x4f')]+'%'};return _0x1fc587;})});}_0x376c4b=_[_0xf71c('0x50')]({},_0x376c4b,_0x3365bc[_0xf71c('0x52')]);return db[_0xf71c('0x6f')][_0xf71c('0x53')]({'where':_0x376c4b[_0xf71c('0x4d')]})[_0xf71c('0x22')](function(_0x360192){_0x4276ee[_0xf71c('0x53')]=_0x360192;if(_0x3365bc[_0xf71c('0x46')][_0xf71c('0x54')]){_0x376c4b[_0xf71c('0x55')]=[{'all':!![]}];}return db[_0xf71c('0x6f')][_0xf71c('0x56')](_0x376c4b);})[_0xf71c('0x22')](function(_0x23a6ea){_0x4276ee['rows']=_0x23a6ea;return _0x4276ee;});}})[_0xf71c('0x22')](respondWithFilteredResult(_0x67bc09,_0x376c4b))[_0xf71c('0x2a')](handleError(_0x67bc09,null));};exports['removeAnswers']=function(_0x5df3ec,_0x32f481,_0xaa7c9f){return db[_0xf71c('0x3f')][_0xf71c('0x5e')]({'where':{'id':_0x5df3ec['params']['id']}})[_0xf71c('0x22')](handleEntityNotFound(_0x32f481,null))[_0xf71c('0x22')](function(_0x40e21c){if(_0x40e21c){return _0x40e21c[_0xf71c('0x70')](_0x5df3ec[_0xf71c('0x46')][_0xf71c('0x6a')]);}})[_0xf71c('0x22')](respondWithStatusCode(_0x32f481,null))[_0xf71c('0x2a')](handleError(_0x32f481,null));};exports[_0xf71c('0x71')]=function(_0x1152e4,_0x3e8e60,_0x59d697){var _0x24b6f8={'channel':_0xf71c('0x72')};var _0x38eda1=[];var _0x3ddf85=[];var _0x2a730={};return db[_0xf71c('0x3f')][_0xf71c('0x5e')]({'where':{'id':_0x1152e4['params']['id']},'include':[{'model':db[_0xf71c('0x73')],'as':_0xf71c('0x74')}]})['then'](handleEntityNotFound(_0x3e8e60,null))[_0xf71c('0x22')](function(_0x1f790d){_0x24b6f8[_0xf71c('0x75')]=_0x1f790d;_0x24b6f8[_0xf71c('0x76')]=_[_0xf71c('0x77')](_0x1f790d['Applications'],[_0xf71c('0x78')],[_0xf71c('0x79')]);if(_0x24b6f8[_0xf71c('0x75')]['Applications']){delete _0x24b6f8[_0xf71c('0x75')][_0xf71c('0x74')];}return db[_0xf71c('0x7a')][_0xf71c('0x63')]();})['then'](function(_0x44d75e){if(!_0x44d75e){throw new db[(_0xf71c('0x7b'))][(_0xf71c('0x7c'))]('no\x20available\x20attributes');}_0x38eda1=_[_0xf71c('0x7d')](_[_0xf71c('0x45')](_0x44d75e),['createdAt',_0xf71c('0x7e')]);_0x3ddf85=_['difference'](_[_0xf71c('0x45')](_0x44d75e),[_0xf71c('0x7f'),_0xf71c('0x7e'),_0xf71c('0x80'),'ListId']);_0x24b6f8[_0xf71c('0x5b')]={'mapKey':_0xf71c('0x81')};if(_0x24b6f8[_0xf71c('0x75')]['type']){switch(_0x24b6f8[_0xf71c('0x75')][_0xf71c('0x41')]){case _0xf71c('0x82'):_0x24b6f8[_0xf71c('0x5b')][_0xf71c('0x83')]=_0x1152e4['body'][_0xf71c('0x84')];_0x24b6f8[_0xf71c('0x5b')][_0xf71c('0x5b')]=_0x1152e4[_0xf71c('0x5b')]['Body'];_0x24b6f8[_0xf71c('0x5b')][_0xf71c('0x85')]=_0x1152e4[_0xf71c('0x5b')][_0xf71c('0x86')];break;case _0xf71c('0x87'):_0x24b6f8[_0xf71c('0x5b')][_0xf71c('0x83')]='+'+_0x1152e4['body'][_0xf71c('0x88')];_0x24b6f8[_0xf71c('0x5b')][_0xf71c('0x5b')]=_0x1152e4[_0xf71c('0x5b')][_0xf71c('0x89')];break;case _0xf71c('0x8a'):_0x24b6f8[_0xf71c('0x5b')]['from']=_0x1152e4[_0xf71c('0x5b')]['from'];_0x24b6f8[_0xf71c('0x5b')][_0xf71c('0x5b')]=_0x1152e4[_0xf71c('0x5b')][_0xf71c('0x29')];break;case'clicksend':_0x24b6f8[_0xf71c('0x5b')][_0xf71c('0x83')]=_0x1152e4[_0xf71c('0x5b')]['from'];_0x24b6f8['body'][_0xf71c('0x5b')]=_0x1152e4['body'][_0xf71c('0x5b')];_0x24b6f8[_0xf71c('0x5b')][_0xf71c('0x85')]=_0x1152e4['body'][_0xf71c('0x8b')];break;case _0xf71c('0x8c'):_0x24b6f8[_0xf71c('0x5b')][_0xf71c('0x83')]=_0x1152e4['body'][_0xf71c('0x84')];_0x24b6f8[_0xf71c('0x5b')][_0xf71c('0x5b')]=_0x1152e4[_0xf71c('0x5b')][_0xf71c('0x8d')];_0x24b6f8[_0xf71c('0x5b')]['messageId']=_0x1152e4['body'][_0xf71c('0x8e')];break;case'infobip':_0x24b6f8[_0xf71c('0x5b')][_0xf71c('0x83')]='+'+_0x1152e4[_0xf71c('0x5b')][_0xf71c('0x8f')][0x0][_0xf71c('0x83')];_0x24b6f8['body'][_0xf71c('0x5b')]=_0x1152e4[_0xf71c('0x5b')][_0xf71c('0x8f')][0x0]['text'];_0x24b6f8['body'][_0xf71c('0x85')]=_0x1152e4[_0xf71c('0x5b')][_0xf71c('0x8f')][0x0][_0xf71c('0x85')];break;case _0xf71c('0x90'):_0x24b6f8[_0xf71c('0x5b')][_0xf71c('0x83')]=_0x1152e4[_0xf71c('0x5b')][_0xf71c('0x91')];_0x24b6f8[_0xf71c('0x5b')][_0xf71c('0x5b')]=_0x1152e4[_0xf71c('0x5b')][_0xf71c('0x92')][_0xf71c('0x29')];break;case _0xf71c('0x93'):_0x24b6f8['body'][_0xf71c('0x83')]=_0x1152e4[_0xf71c('0x5b')][_0xf71c('0x94')];_0x24b6f8[_0xf71c('0x5b')]['body']=_0x1152e4['body'][_0xf71c('0x89')];_0x24b6f8[_0xf71c('0x5b')][_0xf71c('0x85')]=_0x1152e4[_0xf71c('0x5b')]['replyMessageId'];break;case'bandwidth':_0x24b6f8[_0xf71c('0x5b')][_0xf71c('0x85')]=_0x1152e4[_0xf71c('0x5b')][0x0]['message']['id'];_0x24b6f8[_0xf71c('0x5b')][_0xf71c('0x83')]=_0x1152e4[_0xf71c('0x5b')][0x0][_0xf71c('0x29')][_0xf71c('0x83')];_0x24b6f8['body'][_0xf71c('0x5b')]=_0x1152e4[_0xf71c('0x5b')][0x0][_0xf71c('0x29')][_0xf71c('0x89')];break;case _0xf71c('0x95'):_0x24b6f8[_0xf71c('0x5b')][_0xf71c('0x83')]=_0x1152e4[_0xf71c('0x5b')][_0xf71c('0x83')];_0x24b6f8[_0xf71c('0x5b')][_0xf71c('0x5b')]=_0x1152e4['body'][_0xf71c('0x29')];_0x24b6f8[_0xf71c('0x5b')]['messageId']=_0x1152e4['body'][_0xf71c('0x96')];break;}}if(_0x24b6f8[_0xf71c('0x5b')]['id']){delete _0x24b6f8[_0xf71c('0x5b')]['id'];}if(_[_0xf71c('0x97')](_0x24b6f8[_0xf71c('0x5b')][_0xf71c('0x83')])){throw new db[(_0xf71c('0x7b'))][(_0xf71c('0x7c'))](_0xf71c('0x98'));}if(_[_0xf71c('0x97')](_0x24b6f8[_0xf71c('0x5b')]['body'])||_0x24b6f8[_0xf71c('0x5b')]['body']===''){throw new db[(_0xf71c('0x7b'))][(_0xf71c('0x7c'))](_0xf71c('0x99'));}if(_[_0xf71c('0x97')](_0x24b6f8[_0xf71c('0x5b')][_0xf71c('0x9a')])){throw new db[(_0xf71c('0x7b'))][(_0xf71c('0x7c'))](_0xf71c('0x9b')+_0x3ddf85);}if(!_[_0xf71c('0x9c')](_0x3ddf85,_0x24b6f8[_0xf71c('0x5b')][_0xf71c('0x9a')])){throw new db[(_0xf71c('0x7b'))]['ValidationError']('mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x3ddf85);}_0x2a730[_0x24b6f8[_0xf71c('0x5b')][_0xf71c('0x9a')]]=_0x24b6f8[_0xf71c('0x5b')][_0xf71c('0x83')];return db['CmList']['find']({'where':{'id':_0x24b6f8[_0xf71c('0x75')][_0xf71c('0x9d')]},'include':[{'model':db[_0xf71c('0x7a')],'as':_0xf71c('0x9e'),'where':_0x2a730,'limit':0x1,'order':[[_0xf71c('0x7e'),_0xf71c('0x9f')]]}]});})['then'](handleEntityNotFound(_0x3e8e60,null))[_0xf71c('0x22')](function(_0x96b0b2){if(_0x96b0b2){_0x24b6f8['list']=_[_0xf71c('0xa0')](_0x96b0b2,[_0xf71c('0x9e')]);if(_0x96b0b2['Contacts'][_0xf71c('0x68')]){return _0x96b0b2[_0xf71c('0x9e')][0x0];}var _0x1d68c0=_[_0xf71c('0x1b')](_0x24b6f8[_0xf71c('0x5b')],{'firstName':_0x24b6f8['body'][_0xf71c('0x83')],'ListId':_0x96b0b2['id']});_0x1d68c0[_0x24b6f8['body'][_0xf71c('0x9a')]]=_0x24b6f8[_0xf71c('0x5b')][_0xf71c('0x83')];return db['CmContact']['create'](_0x1d68c0,{'fields':_0x38eda1,'raw':!![]});}})[_0xf71c('0x22')](handleEntityNotFound(_0x3e8e60,null))[_0xf71c('0x22')](function(_0x30eb42){if(_0x30eb42){_0x24b6f8['contact']=_0x30eb42;var _0x5b0d4b={'ContactId':_0x30eb42['id'],'phone':_0x24b6f8[_0xf71c('0x5b')][_0xf71c('0x83')],'SmsAccountId':_0x1152e4[_0xf71c('0x58')]['id']};var _0x4d7c2b={'ContactId':_0x30eb42['id'],'SmsAccountId':_0x1152e4['params']['id'],'closed':![]};return db['SmsInteraction'][_0xf71c('0x5e')]({'where':_0x4d7c2b})['then'](function(_0x397bc6){if(_0x397bc6){return[_0x397bc6,![]];}return db[_0xf71c('0xa1')][_0xf71c('0x5a')](_0x5b0d4b)[_0xf71c('0x22')](function(_0x3ce0fe){return[_0x3ce0fe,!![]];});});}})['spread'](function(_0x2ab2ba,_0x5b83f8){_0x24b6f8[_0xf71c('0xa2')]=_0x2ab2ba['get']({'plain':!![]});_0x24b6f8[_0xf71c('0xa2')]['created']=![];if(_0x5b83f8){if(_0x24b6f8[_0xf71c('0x75')][_0xf71c('0xa3')]){_0x24b6f8['applications'][_0xf71c('0xa4')]({'id':0x0,'priority':_0x24b6f8['applications'][_0xf71c('0x68')]+0x1,'app':_0xf71c('0xa5'),'appdata':_0xf71c('0xa6'),'interval':_0xf71c('0xa7')});}_0x24b6f8['interaction'][_0xf71c('0xa8')]=!![];}return db['SmsMessage'][_0xf71c('0x5a')]({'phone':_0x24b6f8[_0xf71c('0x5b')][_0xf71c('0x83')],'messageId':_0x24b6f8[_0xf71c('0x5b')]['messageId'],'body':_0x24b6f8[_0xf71c('0x5b')][_0xf71c('0x5b')],'SmsAccountId':_0x1152e4[_0xf71c('0x58')]['id'],'SmsInteractionId':_0x2ab2ba['id'],'direction':'in','ContactId':_0x2ab2ba[_0xf71c('0xa9')],'AttachmentId':_0x24b6f8[_0xf71c('0x5b')][_0xf71c('0xaa')]});})[_0xf71c('0x22')](function(_0x41e016){_0x24b6f8[_0xf71c('0x29')]=_0x41e016;if(_0x24b6f8[_0xf71c('0xa2')][_0xf71c('0xab')]){return db['User'][_0xf71c('0x5e')]({'attributes':['id',_0xf71c('0x3b')],'where':{'id':_0x24b6f8[_0xf71c('0xa2')][_0xf71c('0xab')]}})[_0xf71c('0x22')](function(_0x228817){if(_0x228817){_0x24b6f8[_0xf71c('0x76')][_0xf71c('0xac')]({'id':0x0,'priority':0x0,'app':_0xf71c('0xad'),'appdata':_0x228817['name']+','+(_0x24b6f8[_0xf71c('0x75')]['waitForTheAssignedAgent']||0xa),'interval':_0xf71c('0xa7')});}return respondWithRpcPromise(_0xf71c('0xae'),'startRouting',_0x24b6f8);});}return respondWithRpcPromise(_0xf71c('0xae'),_0xf71c('0xaf'),_0x24b6f8);})['then'](function(_0xf4caa4){if(_0xf4caa4){var _0x5c8064=0xc8;var _0x5c9322=_0xf71c('0xb0');logger[_0xf71c('0x23')](_0xf71c('0xb1'),_0x5c9322,_0x5c8064,'entity\x20found');logger[_0xf71c('0x26')](_0xf71c('0xb2'),_0x5c9322,_0x5c8064,_0xf71c('0xb3'),JSON[_0xf71c('0xb4')](_0xf4caa4));if(_0x24b6f8[_0xf71c('0x75')][_0xf71c('0x41')]===_0xf71c('0x82')){return _0x3e8e60['status'](_0x5c8064)[_0xf71c('0x31')](_0xf71c('0xb5'),_0xf71c('0xb6'))[_0xf71c('0x3c')](_0xf71c('0xb7'));}else{return _0x3e8e60['status'](_0x5c8064)[_0xf71c('0x2d')](_0xf4caa4);}}})['catch'](handleError(_0x3e8e60,null));};exports['addApplications']=function(_0x3c5b81,_0x3f2a37){var _0x99f370=_0x3c5b81[_0xf71c('0x58')]['id'];var _0x53252f=_0x3c5b81[_0xf71c('0x5b')];var _0x52a9cb=0xc8;var _0x5dc626=null;return db[_0xf71c('0xb8')][_0xf71c('0xb9')]({'isolationLevel':db[_0xf71c('0xb8')][_0xf71c('0xba')][_0xf71c('0xbb')]['READ_COMMITTED']},function(_0x466418){return db['SmsAccount']['findOne']({'where':{'id':_0x99f370},'transaction':_0x466418})[_0xf71c('0x22')](function(_0x387ae8){if(_0x387ae8){return db[_0xf71c('0x73')][_0xf71c('0x35')]({'where':{'SmsAccountId':_0x99f370},'transaction':_0x466418})[_0xf71c('0x22')](function(){var _0x1574cb=_['map'](_0x53252f,function(_0x488b08){_0x488b08[_0xf71c('0x65')]=_0x99f370;return _0x488b08;});return db[_0xf71c('0x73')]['bulkCreate'](_0x1574cb,{'transaction':_0x466418});});}else{_0x52a9cb=0x194;_0x5dc626=[];}});})['then'](function(){if(_0x52a9cb!==0x194){return db[_0xf71c('0x73')][_0xf71c('0xbc')]({'where':{'SmsAccountId':_0x99f370},'order':_0xf71c('0x78')})['then'](function(_0x3ca90b){_0x5dc626=_0x3ca90b;});}})[_0xf71c('0x2a')](function(_0x3cf8a9){_0x52a9cb=0x1f4;logger[_0xf71c('0x27')](_0x3cf8a9['stack']);if(_0x3cf8a9[_0xf71c('0x3b')]){delete _0x3cf8a9[_0xf71c('0x3b')];}_0x5dc626=_0x3cf8a9;})[_0xf71c('0xbd')](function(){if(_0x5dc626===null){_0x3f2a37[_0xf71c('0x2b')](_0x52a9cb);}else{if(_0x52a9cb===0x1f4){_0x3f2a37[_0xf71c('0x2c')](_0x52a9cb)[_0xf71c('0x3c')](_0x5dc626);}else{_0x3f2a37[_0xf71c('0x2c')](_0x52a9cb)[_0xf71c('0x2d')](_0x5dc626);}}});};exports[_0xf71c('0xbe')]=function(_0x1f2e30,_0x2fa292,_0x2bd97d){var _0x3c946e={};var _0x2e5213={};var _0x44860c;var _0x5c0370;return db[_0xf71c('0x3f')][_0xf71c('0x6c')]({'where':{'id':_0x1f2e30[_0xf71c('0x58')]['id']}})['then'](handleEntityNotFound(_0x2fa292,null))['then'](function(_0x1dbe1f){if(_0x1dbe1f){_0x44860c=_0x1dbe1f;_0x2e5213[_0xf71c('0x43')]=_['keys'](db[_0xf71c('0x73')][_0xf71c('0x59')]);_0x2e5213[_0xf71c('0x46')]=_['keys'](_0x1f2e30[_0xf71c('0x46')]);_0x2e5213[_0xf71c('0x4e')]=_[_0xf71c('0x47')](_0x2e5213[_0xf71c('0x43')],_0x2e5213['query']);_0x3c946e[_0xf71c('0x48')]=_[_0xf71c('0x47')](_0x2e5213['model'],qs['fields'](_0x1f2e30[_0xf71c('0x46')]['fields']));_0x3c946e['attributes']=_0x3c946e['attributes']['length']?_0x3c946e[_0xf71c('0x48')]:_0x2e5213[_0xf71c('0x43')];_0x3c946e[_0xf71c('0x6d')]=qs[_0xf71c('0x4c')](_0x1f2e30[_0xf71c('0x46')][_0xf71c('0x4c')]);_0x3c946e[_0xf71c('0x4d')]=qs[_0xf71c('0x4e')](_['pick'](_0x1f2e30[_0xf71c('0x46')],_0x2e5213[_0xf71c('0x4e')]));if(_0x1f2e30[_0xf71c('0x46')][_0xf71c('0x4f')]){_0x3c946e[_0xf71c('0x4d')]=_['merge'](_0x3c946e[_0xf71c('0x4d')],{'$or':_[_0xf71c('0x44')](_0x3c946e['attributes'],function(_0xbc84a9){var _0x3ca1e1={};_0x3ca1e1[_0xbc84a9]={'$like':'%'+_0x1f2e30['query'][_0xf71c('0x4f')]+'%'};return _0x3ca1e1;})});}_0x3c946e=_[_0xf71c('0x50')]({},_0x3c946e,_0x1f2e30['options']);return _0x44860c[_0xf71c('0xbe')](_0x3c946e);}})[_0xf71c('0x22')](function(_0x4e6b68){if(_0x4e6b68){_0x5c0370=_0x4e6b68[_0xf71c('0x68')];if(!_0x1f2e30[_0xf71c('0x46')][_0xf71c('0x4a')](_0xf71c('0x4b'))){_0x3c946e[_0xf71c('0x2f')]=qs[_0xf71c('0x2f')](_0x1f2e30[_0xf71c('0x46')][_0xf71c('0x2f')]);_0x3c946e[_0xf71c('0x30')]=qs[_0xf71c('0x30')](_0x1f2e30['query'][_0xf71c('0x30')]);}return _0x44860c[_0xf71c('0xbe')](_0x3c946e);}})[_0xf71c('0x22')](function(_0x4953d4){if(_0x4953d4){return _0x4953d4?{'count':_0x5c0370,'rows':_0x4953d4}:null;}})[_0xf71c('0x22')](respondWithResult(_0x2fa292,null))[_0xf71c('0x2a')](handleError(_0x2fa292,null));};exports['getInteractions']=function(_0x3497fd,_0x43846c,_0x58e5ef){var _0xde87b0={'raw':![],'where':{}};var _0x425f3a={};var _0x3b191e={'count':0x0,'rows':[]};return db[_0xf71c('0x3f')][_0xf71c('0x6c')]({'where':{'id':_0x3497fd[_0xf71c('0x58')]['id']}})['then'](handleEntityNotFound(_0x43846c,null))[_0xf71c('0x22')](function(_0x29ab6e){if(_0x29ab6e){_0x425f3a[_0xf71c('0x43')]=_[_0xf71c('0x45')](db[_0xf71c('0xa1')][_0xf71c('0x59')]);_0x425f3a['query']=_['keys'](_0x3497fd[_0xf71c('0x46')]);_0x425f3a['filters']=_[_0xf71c('0x47')](_0x425f3a[_0xf71c('0x43')],_0x425f3a[_0xf71c('0x46')]);_0xde87b0[_0xf71c('0x48')]=_['intersection'](_0x425f3a[_0xf71c('0x43')],qs[_0xf71c('0x49')](_0x3497fd[_0xf71c('0x46')][_0xf71c('0x49')]));_0xde87b0[_0xf71c('0x48')]=_0xde87b0[_0xf71c('0x48')][_0xf71c('0x68')]?_0xde87b0[_0xf71c('0x48')]:_0x425f3a[_0xf71c('0x43')];if(!_0x3497fd[_0xf71c('0x46')][_0xf71c('0x4a')](_0xf71c('0x4b'))){_0xde87b0[_0xf71c('0x2f')]=qs['limit'](_0x3497fd['query'][_0xf71c('0x2f')]);_0xde87b0['offset']=qs[_0xf71c('0x30')](_0x3497fd['query'][_0xf71c('0x30')]);}_0xde87b0['order']=qs[_0xf71c('0x4c')](_0x3497fd[_0xf71c('0x46')][_0xf71c('0x4c')]);_0xde87b0[_0xf71c('0x4d')]=qs[_0xf71c('0x4e')](_['pick'](_0x3497fd[_0xf71c('0x46')],_0x425f3a['filters']));_0xde87b0[_0xf71c('0x4d')][_0xf71c('0x65')]=_0x29ab6e['id'];if(_0x3497fd[_0xf71c('0x46')][_0xf71c('0x4f')]){_0xde87b0[_0xf71c('0x4d')]=_[_0xf71c('0x50')](_0xde87b0[_0xf71c('0x4d')],{'$or':_[_0xf71c('0x44')](_0xde87b0[_0xf71c('0x48')],function(_0x3b8a77){var _0x48df6a={};_0x48df6a[_0x3b8a77]={'$like':'%'+_0x3497fd['query']['filter']+'%'};return _0x48df6a;})});}_0xde87b0=_[_0xf71c('0x50')]({},_0xde87b0,_0x3497fd[_0xf71c('0x52')]);return db['SmsInteraction'][_0xf71c('0x53')]({'where':_0xde87b0[_0xf71c('0x4d')]})['then'](function(_0x5a274b){_0x3b191e['count']=_0x5a274b;if(_0x3497fd[_0xf71c('0x46')][_0xf71c('0x54')]){_0xde87b0[_0xf71c('0x55')]=[{'model':db[_0xf71c('0x7a')],'as':_0xf71c('0xbf'),'required':![]},{'model':db[_0xf71c('0xc0')],'as':_0xf71c('0xc1'),'attributes':['name',_0xf71c('0xc2'),_0xf71c('0xc3')],'required':![]},{'model':db[_0xf71c('0xc4')],'as':_0xf71c('0xc5'),'attributes':['id',_0xf71c('0x3b'),_0xf71c('0xc6')],'where':_0x3497fd[_0xf71c('0x46')][_0xf71c('0xc7')]?{'id':_0x3497fd[_0xf71c('0x46')]['tag']}:undefined,'required':_0x3497fd[_0xf71c('0x46')][_0xf71c('0xc7')]?!![]:![]}];}return db[_0xf71c('0xa1')][_0xf71c('0x56')](_0xde87b0);})[_0xf71c('0x22')](function(_0x546b61){_0x3b191e[_0xf71c('0x57')]=_0x546b61;return _0x3b191e;});}})['then'](respondWithFilteredResult(_0x43846c,_0xde87b0))[_0xf71c('0x2a')](handleError(_0x43846c,null));};exports['send']=function(_0x300160,_0x41f2e8,_0x3a6a44){var _0x5b7f24,_0x25cb6c,_0x2ecf03;if(_['isNil'](_0x300160[_0xf71c('0x5b')][_0xf71c('0x5b')])||_0x300160[_0xf71c('0x5b')][_0xf71c('0x5b')]===''){throw new db[(_0xf71c('0x7b'))][(_0xf71c('0x7c'))](_0xf71c('0x99'));}if(_[_0xf71c('0x97')](_0x300160[_0xf71c('0x5b')]['to'])){throw new db[(_0xf71c('0x7b'))][(_0xf71c('0x7c'))]('to\x20is\x20mandatory');}_0x5b7f24=_0x300160[_0xf71c('0x5b')]['to'];return db[_0xf71c('0x3f')][_0xf71c('0x5e')]({'where':{'id':_0x300160[_0xf71c('0x58')]['id']},'include':[{'model':db[_0xf71c('0xc8')],'as':'List','include':[{'model':db['CmContact'],'as':_0xf71c('0x9e'),'where':{'mobile':_0x5b7f24},'limit':0x1,'order':[['updatedAt',_0xf71c('0x9f')]]}]}]})['then'](handleEntityNotFound(_0x41f2e8,null))[_0xf71c('0x22')](function(_0x4f9514){if(_0x4f9514&&_0x4f9514[_0xf71c('0xc9')]){_0x25cb6c=_0x4f9514['get']({'plain':!![]});if(_0x25cb6c[_0xf71c('0xc9')]&&_0x25cb6c[_0xf71c('0xc9')][_0xf71c('0x9e')][_0xf71c('0x68')]){return _0x25cb6c[_0xf71c('0xc9')]['Contacts'][0x0];}return db['CmContact'][_0xf71c('0x5a')](_['defaults'](_0x300160[_0xf71c('0x5b')],{'firstName':_0x5b7f24,'mobile':_0x5b7f24,'phone':_0x5b7f24,'ListId':_0x25cb6c[_0xf71c('0x9d')]}));}})[_0xf71c('0x22')](handleEntityNotFound(_0x41f2e8,null))['then'](function(_0x22fc38){if(_0x22fc38){_0x2ecf03=_0x22fc38;return db[_0xf71c('0xa1')]['find']({'where':{'ContactId':_0x2ecf03['id'],'closed':![],'SmsAccountId':_0x25cb6c['id']}})[_0xf71c('0x22')](function(_0x1e86d6){if(_0x1e86d6){return[_0x1e86d6,![]];}return db[_0xf71c('0xa1')][_0xf71c('0x5a')]({'UserId':_0x300160['user']['id'],'ContactId':_0x2ecf03['id'],'SmsAccountId':_0x25cb6c['id'],'phone':_0x5b7f24,'firstMsgDirection':_0xf71c('0xca'),'Messages':[_[_0xf71c('0x50')](_0x300160[_0xf71c('0x5b')],{'read':![],'body':_0x300160['body'][_0xf71c('0x5b')],'phone':_0x5b7f24,'SmsAccountId':_0x25cb6c['id'],'UserId':_0x300160[_0xf71c('0x5c')]['id'],'ContactId':_0x2ecf03['id']})]},{'include':[{'model':db['SmsMessage'],'as':_0xf71c('0xcb')}]})[_0xf71c('0x22')](function(_0x302298){return[_0x302298,!![]];});});}})[_0xf71c('0xcc')](function(_0x47bcaa,_0x55c912){if(_0x55c912){return _0x47bcaa;}return db['SmsMessage'][_0xf71c('0x5a')](_['merge'](_0x300160[_0xf71c('0x5b')],{'read':![],'body':_0x300160['body']['body'],'phone':_0x5b7f24,'SmsAccountId':_0x25cb6c['id'],'SmsInteractionId':_0x47bcaa['id'],'UserId':_0x300160[_0xf71c('0x5c')]['id'],'ContactId':_0x2ecf03['id']}))[_0xf71c('0x22')](function(_0x315e26){_0x47bcaa[_0xf71c('0xcd')][_0xf71c('0xcb')]=[];_0x47bcaa[_0xf71c('0xcd')][_0xf71c('0xcb')][_0xf71c('0xa4')](_0x315e26[_0xf71c('0xcd')]);return _0x47bcaa;});})[_0xf71c('0x22')](respondWithResult(_0x41f2e8,null))[_0xf71c('0x2a')](handleError(_0x41f2e8,null));};exports[_0xf71c('0x2c')]=function(_0xd772f4,_0x4aa611,_0x105bb9){if(_0xd772f4[_0xf71c('0x5b')]['id']){delete _0xd772f4[_0xf71c('0x5b')]['id'];}var _0x164397,_0x2b1d3c,_0x2062a;return db['SmsAccount'][_0xf71c('0x5e')]({'where':{'id':_0xd772f4[_0xf71c('0x58')]['id']}})['then'](handleEntityNotFound(_0x4aa611,null))[_0xf71c('0x22')](function(_0x306346){if(_0x306346){_0x2062a=_0x306346;logger[_0xf71c('0x26')](_0xf71c('0xb1'),_0xf71c('0x2c'),_0xf71c('0xce'),_0x306346[_0xf71c('0x41')],util[_0xf71c('0xcf')](_0xd772f4[_0xf71c('0x5b')],{'showHidden':![],'depth':null}));switch(_0x306346[_0xf71c('0x41')]){case _0xf71c('0x87'):if(_0xd772f4['body']['skebby_dispatch_id']&&_0xd772f4[_0xf71c('0x5b')]['status']){_0x2b1d3c=_0xd772f4['body']['status'];return db['SmsMessage'][_0xf71c('0x5e')]({'where':{'messageId':_0xd772f4[_0xf71c('0x5b')][_0xf71c('0xd0')]}});}break;case _0xf71c('0x8a'):if(_0xd772f4[_0xf71c('0x5b')]['requestid']&&_0xd772f4[_0xf71c('0x5b')][_0xf71c('0xd1')]){_0x2b1d3c=_0xd772f4[_0xf71c('0x5b')][_0xf71c('0xd1')];return db[_0xf71c('0xd2')][_0xf71c('0x5e')]({'where':{'messageId':_0xd772f4['body'][_0xf71c('0xd3')]}});}break;case _0xf71c('0xd4'):if(_0xd772f4[_0xf71c('0x5b')]['message_id']&&_0xd772f4[_0xf71c('0x5b')]['status_code']){_0x2b1d3c=_0xd772f4['body'][_0xf71c('0xd5')];return db['SmsMessage'][_0xf71c('0x5e')]({'where':{'messageId':_0xd772f4[_0xf71c('0x5b')][_0xf71c('0x8b')]}});}break;case _0xf71c('0xd6'):var _0x207930=_0xd772f4[_0xf71c('0x5b')][_0xf71c('0x8f')][0x0];if(_0x207930[_0xf71c('0x85')]&&_0x207930[_0xf71c('0x2c')]['groupName']==='DELIVERED'){_0x2b1d3c=_0x207930[_0xf71c('0x2c')][_0xf71c('0xd7')];return db[_0xf71c('0xd2')][_0xf71c('0x5e')]({'where':{'messageId':_0x207930[_0xf71c('0x85')]}});}break;case _0xf71c('0x93'):if(_0xd772f4[_0xf71c('0x5b')][_0xf71c('0x85')]&&_0xd772f4[_0xf71c('0x5b')]['status']){_0x2b1d3c=_0xd772f4['body'][_0xf71c('0x2c')];return db['SmsMessage'][_0xf71c('0x5e')]({'where':{'messageId':_0xd772f4[_0xf71c('0x5b')][_0xf71c('0x85')]}});}break;case _0xf71c('0xd8'):if(_0xd772f4['body'][0x0][_0xf71c('0x29')]['id']){_0x2b1d3c=_0xd772f4[_0xf71c('0x5b')][0x0][_0xf71c('0x41')];return db['SmsMessage']['find']({'where':{'messageId':_0xd772f4[_0xf71c('0x5b')][0x0][_0xf71c('0x29')]['id']}});}break;case _0xf71c('0x95'):if(_0xd772f4[_0xf71c('0x5b')][_0xf71c('0xd9')]&&_0xd772f4[_0xf71c('0x5b')][_0xf71c('0x2c')]){_0x2b1d3c=_0xd772f4[_0xf71c('0x5b')][_0xf71c('0x2c')];return db['SmsMessage'][_0xf71c('0x5e')]({'where':{'messageId':_0xd772f4[_0xf71c('0x5b')]['redif']}});}break;}}})['then'](handleEntityNotFound(_0x4aa611,null))[_0xf71c('0x22')](function(_0x11eec2){if(_0x11eec2){_0x164397=_0x11eec2;switch(_0x2062a[_0xf71c('0x41')]){case _0xf71c('0x87'):if(_0x2b1d3c===_0xf71c('0xda')){return _0x164397[_0xf71c('0x62')]({'read':!![]});}else{logger[_0xf71c('0x27')](_0xf71c('0xb1'),_0xf71c('0x2c'),_0xf71c('0x87'),util['inspect'](_0xd772f4[_0xf71c('0x5b')],{'showHidden':![],'depth':null}));}break;case'connectel':if(_0x2b1d3c==='1'){return _0x164397[_0xf71c('0x62')]({'read':!![]});}else{logger['error'](_0xf71c('0xb1'),_0xf71c('0x2c'),'skebby',util[_0xf71c('0xcf')](_0xd772f4[_0xf71c('0x5b')],{'showHidden':![],'depth':null}));}break;case _0xf71c('0xd4'):if(!_0xd772f4[_0xf71c('0x5b')][_0xf71c('0xdb')]&&_0x2b1d3c>=0xc8&&_0x2b1d3c<=0xce){return _0x164397[_0xf71c('0x62')]({'read':!![]});}else{logger[_0xf71c('0x27')](_0xf71c('0xb1'),'status','clicksend',util[_0xf71c('0xcf')](_0xd772f4['body'],{'showHidden':![],'depth':null}));}break;case _0xf71c('0xd6'):var _0x4f03f9=_0xd772f4[_0xf71c('0x5b')][_0xf71c('0x8f')][0x0];if(_0x4f03f9[_0xf71c('0x2c')][_0xf71c('0xd7')]===_0xf71c('0xda')){return _0x164397[_0xf71c('0x62')]({'read':!![]});}else{logger['error'](_0xf71c('0xb1'),_0xf71c('0x2c'),_0xf71c('0xd6'),util[_0xf71c('0xcf')](_0xd772f4['body'],{'showHidden':![],'depth':null}));}break;case'clickatell':if(_0x2b1d3c=='DELIVERED_TO_GATEWAY'||_0x2b1d3c==_0xf71c('0xdc')){return _0x164397[_0xf71c('0x62')]({'read':!![]});}else{logger['error']('SmsAccount,\x20%s,\x20%s,\x20%s',_0xf71c('0x2c'),_0xf71c('0x93'),util[_0xf71c('0xcf')](_0xd772f4[_0xf71c('0x5b')],{'showHidden':![],'depth':null}));}break;case'bandwidth':if(_0x2b1d3c==_0xf71c('0xdd')){return _0x164397[_0xf71c('0x62')]({'read':!![]});}else{logger[_0xf71c('0x27')](_0xf71c('0xb1'),_0xf71c('0x2c'),'bandwidth',util['inspect'](_0xd772f4[_0xf71c('0x5b')],{'showHidden':![],'depth':null}));}break;case _0xf71c('0x95'):if(_0x2b1d3c===_0xf71c('0xde')||_0x2b1d3c===_0xf71c('0xdf')){return _0x164397[_0xf71c('0x62')]({'read':!![]});}else{logger['error'](_0xf71c('0xb1'),_0xf71c('0x2c'),_0xf71c('0x95'),util[_0xf71c('0xcf')](_0xd772f4[_0xf71c('0x5b')],{'showHidden':![],'depth':null}));}break;}return _0x164397;}})[_0xf71c('0x22')](respondWithResult(_0x4aa611,null))[_0xf71c('0x2a')](handleError(_0x4aa611,null));};exports['statusGet']=function(_0x5d911f,_0x163a1c,_0x4eb678){var _0x6b3006,_0x2094c4,_0x5a2205;return db['SmsAccount'][_0xf71c('0x5e')]({'where':{'id':_0x5d911f[_0xf71c('0x58')]['id']}})[_0xf71c('0x22')](handleEntityNotFound(_0x163a1c,null))['then'](function(_0x445d66){if(_0x445d66){_0x5a2205=_0x445d66;logger[_0xf71c('0x26')](_0xf71c('0xb1'),_0xf71c('0x2c'),_0xf71c('0xce'),_0x445d66[_0xf71c('0x41')],util[_0xf71c('0xcf')](_0x5d911f[_0xf71c('0x46')],{'showHidden':![],'depth':null}));switch(_0x445d66[_0xf71c('0x41')]){case _0xf71c('0x90'):if(_0x5d911f['query']['message-id']&&_0x5d911f['query'][_0xf71c('0xe0')]){_0x2094c4=_0x5d911f[_0xf71c('0x46')][_0xf71c('0xe0')];return db[_0xf71c('0xd2')][_0xf71c('0x5e')]({'where':{'messageId':_0x5d911f[_0xf71c('0x46')]['message-id']}});}break;}}})[_0xf71c('0x22')](handleEntityNotFound(_0x163a1c,null))[_0xf71c('0x22')](function(_0x6e1181){if(_0x6e1181){_0x6b3006=_0x6e1181;switch(_0x5a2205['type']){case _0xf71c('0x90'):if(_0x2094c4==='2'||_0x2094c4==='6'){return _0x6b3006['update']({'read':!![]});}else{logger[_0xf71c('0x27')](_0xf71c('0xb1'),'status','csc',util[_0xf71c('0xcf')](_0x5d911f[_0xf71c('0x46')],{'showHidden':![],'depth':null}));};break;}return _0x6b3006;}})[_0xf71c('0x22')](respondWithResult(_0x163a1c,null))[_0xf71c('0x2a')](handleError(_0x163a1c,null));};exports[_0xf71c('0xe1')]=function(_0x36fdbe,_0x8b39c1,_0x5c4784){return db[_0xf71c('0x3f')][_0xf71c('0x5e')]({'where':{'id':_0x36fdbe[_0xf71c('0x58')]['id']}})[_0xf71c('0x22')](handleEntityNotFound(_0x8b39c1,null))[_0xf71c('0x22')](function(_0x31679e){if(_0x31679e){return _0x31679e[_0xf71c('0xe1')](_0x36fdbe['body']['ids'],_[_0xf71c('0xa0')](_0x36fdbe[_0xf71c('0x5b')],[_0xf71c('0x6a'),'id'])||{})[_0xf71c('0xcc')](function(_0x117f3f){for(var _0x5893cf=0x0;_0x5893cf<_0x36fdbe[_0xf71c('0x5b')]['ids'][_0xf71c('0x68')];_0x5893cf+=0x1){socket[_0xf71c('0xe2')]('userSmsAccount:save',{'UserId':Number(_0x36fdbe[_0xf71c('0x5b')][_0xf71c('0x6a')][_0x5893cf]),'SmsAccountId':Number(_0x36fdbe['params']['id'])});}return _0x117f3f;});}})['then'](respondWithResult(_0x8b39c1,null))[_0xf71c('0x2a')](handleError(_0x8b39c1,null));};exports[_0xf71c('0xe3')]=function(_0x4bd5d1,_0x48d8ba,_0x46f4ff){return db[_0xf71c('0x3f')][_0xf71c('0x5e')]({'where':{'id':_0x4bd5d1['params']['id']}})['then'](handleEntityNotFound(_0x48d8ba,null))[_0xf71c('0x22')](function(_0x546c57){if(_0x546c57){return _0x546c57[_0xf71c('0xe3')](_0x4bd5d1['query'][_0xf71c('0x6a')])[_0xf71c('0x22')](function(){if(_['isArray'](_0x4bd5d1[_0xf71c('0x46')]['ids'])){for(var _0x2d6a55=0x0;_0x2d6a55<_0x4bd5d1[_0xf71c('0x46')][_0xf71c('0x6a')][_0xf71c('0x68')];_0x2d6a55+=0x1){socket['emit'](_0xf71c('0xe4'),{'UserId':Number(_0x4bd5d1['query'][_0xf71c('0x6a')][_0x2d6a55]),'SmsAccountId':Number(_0x4bd5d1[_0xf71c('0x58')]['id'])});}}else{socket[_0xf71c('0xe2')]('userSmsAccount:remove',{'UserId':Number(_0x4bd5d1[_0xf71c('0x46')][_0xf71c('0x6a')]),'SmsAccountId':Number(_0x4bd5d1['params']['id'])});}});}})[_0xf71c('0x22')](respondWithStatusCode(_0x48d8ba,null))[_0xf71c('0x2a')](handleError(_0x48d8ba,null));};exports['getAgents']=function(_0x40f37c,_0x1f1e66,_0x17cccc){var _0x4a998b={};var _0x27a6c1={};var _0x1957ef;var _0x55d273;return db[_0xf71c('0x3f')][_0xf71c('0x6c')]({'where':{'id':_0x40f37c[_0xf71c('0x58')]['id']}})[_0xf71c('0x22')](handleEntityNotFound(_0x1f1e66,null))['then'](function(_0x3bbb80){if(_0x3bbb80){_0x1957ef=_0x3bbb80;_0x27a6c1[_0xf71c('0x43')]=_['keys'](db['User']['rawAttributes']);_0x27a6c1[_0xf71c('0x46')]=_[_0xf71c('0x45')](_0x40f37c[_0xf71c('0x46')]);_0x27a6c1[_0xf71c('0x4e')]=_[_0xf71c('0x47')](_0x27a6c1[_0xf71c('0x43')],_0x27a6c1[_0xf71c('0x46')]);_0x4a998b[_0xf71c('0x48')]=_[_0xf71c('0x47')](_0x27a6c1[_0xf71c('0x43')],qs['fields'](_0x40f37c['query'][_0xf71c('0x49')]));_0x4a998b['attributes']=_0x4a998b[_0xf71c('0x48')][_0xf71c('0x68')]?_0x4a998b[_0xf71c('0x48')]:_0x27a6c1[_0xf71c('0x43')];_0x4a998b[_0xf71c('0x6d')]=qs['sort'](_0x40f37c[_0xf71c('0x46')][_0xf71c('0x4c')]);_0x4a998b[_0xf71c('0x4d')]=qs[_0xf71c('0x4e')](_[_0xf71c('0x6e')](_0x40f37c[_0xf71c('0x46')],_0x27a6c1['filters']));if(_0x40f37c[_0xf71c('0x46')][_0xf71c('0x4f')]){_0x4a998b[_0xf71c('0x4d')]=_[_0xf71c('0x50')](_0x4a998b[_0xf71c('0x4d')],{'$or':_[_0xf71c('0x44')](_0x4a998b[_0xf71c('0x48')],function(_0x7946e1){var _0x18c612={};_0x18c612[_0x7946e1]={'$like':'%'+_0x40f37c[_0xf71c('0x46')][_0xf71c('0x4f')]+'%'};return _0x18c612;})});}_0x4a998b=_[_0xf71c('0x50')]({},_0x4a998b,_0x40f37c[_0xf71c('0x52')]);return _0x1957ef[_0xf71c('0xe5')](_0x4a998b);}})[_0xf71c('0x22')](function(_0x20c2a9){if(_0x20c2a9){_0x55d273=_0x20c2a9['length'];if(!_0x40f37c[_0xf71c('0x46')]['hasOwnProperty'](_0xf71c('0x4b'))){_0x4a998b[_0xf71c('0x2f')]=qs[_0xf71c('0x2f')](_0x40f37c[_0xf71c('0x46')]['limit']);_0x4a998b[_0xf71c('0x30')]=qs[_0xf71c('0x30')](_0x40f37c[_0xf71c('0x46')][_0xf71c('0x30')]);}return _0x1957ef[_0xf71c('0xe5')](_0x4a998b);}})[_0xf71c('0x22')](function(_0x1dac6c){if(_0x1dac6c){return _0x1dac6c?{'count':_0x55d273,'rows':_0x1dac6c}:null;}})[_0xf71c('0x22')](respondWithResult(_0x1f1e66,null))[_0xf71c('0x2a')](handleError(_0x1f1e66,null));};
\ No newline at end of file
+var _0xc187=['request\x20sent','stringify','error','code','message','result','catch','status','end','json','undefined','count','offset','limit','Content-Range','apply','reject','update','SmsAccounts','UserProfileResource','destroy','sendStatus','stack','name','Pause','mandatoryDispositionPause','SmsAccount','rawAttributes','fieldName','type','key','model','map','query','keys','filters','intersection','fields','attributes','length','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','includeAll','findAll','params','include','options','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','get','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','addDisposition','SmsAccountId','Disposition','getDispositions','findOne','rows','removeDispositions','ids','CannedAnswer','getAnswers','Applications','orderBy','priority','account','CmContact','Sequelize','ValidationError','no\x20available\x20attributes','updatedAt','createdAt','CompanyId','ListId','mobile','twilio','from','From','Body','messageId','skebby','sender','text','connectel','clicksend','message_id','plivo','MessageUUID','infobip','results','csc','originatingAddress','segmentedMessage','replyMessageId','intelepeer','refid','isNil','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','CmList','DESC','omit','Contacts','contact','interaction','autoclose','push','close','unmanaged','created','SmsMessage','UserId','User','unshift','agent','waitForTheAssignedAgent','*,*,*,*','startRouting','entity\x20found','SmsAccount,\x20%s,\x20%s,\x20%s,\x20%s','set','Content-Type','text/xml','send','addApplications','sequelize','transaction','Transaction','ISOLATION_LEVELS','READ_COMMITTED','SmsApplication','bulkCreate','findAndCountAll','finally','getApplications','hasOwnProperty','SmsInteraction','Contact','Owner','internal','Tag','Tags','color','tag','to\x20is\x20mandatory','List','Messages','dataValues','received\x20delivery\x20report\x20from','inspect','skebby_dispatch_id','requestid','statusInt','status_code','groupName','DELIVERED','clickatell','bandwidth','error_code','RECEIVED_BY_RECIPIENT','DELIVRD','ACCEPTD','statusGet','message-id','state','emit','userSmsAccount:save','isArray','userSmsAccount:remove','getAgents','rimraf','zip-dir','fast-json-patch','moment','mustache','util','sox','ejs','fs-extra','lodash','squel','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./smsAccount.socket','register','client','http','request','then','info','SmsAccount,\x20%s,\x20%s','debug','SmsAccount,\x20%s,\x20%s,\x20%s'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0xc187,0xb8));var _0x7c18=function(_0x126558,_0x143c9a){_0x126558=_0x126558-0x0;var _0x1f6d14=_0xc187[_0x126558];return _0x1f6d14;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x7c18('0x0'));var zipdir=require(_0x7c18('0x1'));var jsonpatch=require(_0x7c18('0x2'));var rp=require('request-promise');var moment=require(_0x7c18('0x3'));var BPromise=require('bluebird');var Mustache=require(_0x7c18('0x4'));var util=require(_0x7c18('0x5'));var path=require('path');var sox=require(_0x7c18('0x6'));var csv=require('to-csv');var ejs=require(_0x7c18('0x7'));var fs=require('fs');var fs_extra=require(_0x7c18('0x8'));var _=require(_0x7c18('0x9'));var squel=require(_0x7c18('0xa'));var crypto=require('crypto');var jsforce=require(_0x7c18('0xb'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x7c18('0xc'));var Papa=require(_0x7c18('0xd'));var Redis=require(_0x7c18('0xe'));var authService=require(_0x7c18('0xf'));var qs=require(_0x7c18('0x10'));var as=require(_0x7c18('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x7c18('0x12'))('api');var utils=require(_0x7c18('0x13'));var config=require(_0x7c18('0x14'));var licenseUtil=require(_0x7c18('0x15'));var db=require(_0x7c18('0x16'))['db'];config[_0x7c18('0x17')]=_[_0x7c18('0x18')](config[_0x7c18('0x17')],{'host':_0x7c18('0x19'),'port':0x18eb});var socket=require(_0x7c18('0x1a'))(new Redis(config[_0x7c18('0x17')]));require(_0x7c18('0x1b'))[_0x7c18('0x1c')](socket);var jayson=require('jayson/promise');var client=jayson[_0x7c18('0x1d')][_0x7c18('0x1e')]({'port':0x232c});function respondWithRpcPromise(_0x4ae8d7,_0x5b9382,_0x7d93bc,_0x1c7c8c){return new BPromise(function(_0x574f7f,_0x1f5b9a){var _0x3ffce3=_0x1c7c8c||client;return _0x3ffce3[_0x7c18('0x1f')](_0x4ae8d7,_0x7d93bc)[_0x7c18('0x20')](function(_0x334761){logger[_0x7c18('0x21')](_0x7c18('0x22'),_0x5b9382,'request\x20sent');logger[_0x7c18('0x23')](_0x7c18('0x24'),_0x5b9382,_0x7c18('0x25'),JSON[_0x7c18('0x26')](_0x334761));if(_0x334761['error']){if(_0x334761[_0x7c18('0x27')][_0x7c18('0x28')]===0x1f4){logger['error'](_0x7c18('0x22'),_0x5b9382,_0x334761[_0x7c18('0x27')][_0x7c18('0x29')]);return _0x1f5b9a(_0x334761[_0x7c18('0x27')][_0x7c18('0x29')]);}logger[_0x7c18('0x27')](_0x7c18('0x22'),_0x5b9382,_0x334761['error'][_0x7c18('0x29')]);return _0x574f7f(_0x334761['error'][_0x7c18('0x29')]);}else{logger[_0x7c18('0x21')]('SmsAccount,\x20%s,\x20%s',_0x5b9382,_0x7c18('0x25'));_0x574f7f(_0x334761[_0x7c18('0x2a')]['message']);}})[_0x7c18('0x2b')](function(_0x11ca4e){logger[_0x7c18('0x27')](_0x7c18('0x22'),_0x5b9382,_0x11ca4e);_0x1f5b9a(_0x11ca4e);});});}function respondWithStatusCode(_0x39cf8d,_0x43d411){_0x43d411=_0x43d411||0xcc;return function(_0x4a9a22){if(_0x4a9a22){return _0x39cf8d['sendStatus'](_0x43d411);}return _0x39cf8d[_0x7c18('0x2c')](_0x43d411)[_0x7c18('0x2d')]();};}function respondWithResult(_0x12ddb3,_0x32d165){_0x32d165=_0x32d165||0xc8;return function(_0xe64f5d){if(_0xe64f5d){return _0x12ddb3[_0x7c18('0x2c')](_0x32d165)[_0x7c18('0x2e')](_0xe64f5d);}};}function respondWithFilteredResult(_0xf13e7b,_0x3bc3f8){return function(_0x217422){if(_0x217422){var _0x13c66f=typeof _0x3bc3f8['offset']===_0x7c18('0x2f')&&typeof _0x3bc3f8['limit']===_0x7c18('0x2f');var _0x58034a=_0x217422[_0x7c18('0x30')];var _0x8f538d=_0x13c66f?0x0:_0x3bc3f8[_0x7c18('0x31')];var _0x33e3d2=_0x13c66f?_0x217422[_0x7c18('0x30')]:_0x3bc3f8[_0x7c18('0x31')]+_0x3bc3f8[_0x7c18('0x32')];var _0x2664c1;if(_0x33e3d2>=_0x58034a){_0x33e3d2=_0x58034a;_0x2664c1=0xc8;}else{_0x2664c1=0xce;}_0xf13e7b[_0x7c18('0x2c')](_0x2664c1);return _0xf13e7b['set'](_0x7c18('0x33'),_0x8f538d+'-'+_0x33e3d2+'/'+_0x58034a)[_0x7c18('0x2e')](_0x217422);}return null;};}function patchUpdates(_0x3b0bd3){return function(_0xfc4c08){try{jsonpatch[_0x7c18('0x34')](_0xfc4c08,_0x3b0bd3,!![]);}catch(_0x4f3953){return BPromise[_0x7c18('0x35')](_0x4f3953);}return _0xfc4c08['save']();};}function saveUpdates(_0x4f0218,_0x4f1021){return function(_0x42d27b){if(_0x42d27b){return _0x42d27b[_0x7c18('0x36')](_0x4f0218)['then'](function(_0x5bec76){return _0x5bec76;});}return null;};}function removeEntity(_0x33ab42,_0x5b9af9){return function(_0x26312a){if(_0x26312a){return _0x26312a['destroy']()['then'](function(){var _0x1680dd=_0x26312a['get']({'plain':!![]});var _0x510f53=_0x7c18('0x37');return db[_0x7c18('0x38')][_0x7c18('0x39')]({'where':{'type':_0x510f53,'resourceId':_0x1680dd['id']}})['then'](function(){return _0x26312a;});})[_0x7c18('0x20')](function(){_0x33ab42['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x425263,_0xd047ea){return function(_0x31ff85){if(!_0x31ff85){_0x425263[_0x7c18('0x3a')](0x194);}return _0x31ff85;};}function handleError(_0x6918e5,_0x57f687){_0x57f687=_0x57f687||0x1f4;return function(_0x370f9f){logger[_0x7c18('0x27')](_0x370f9f[_0x7c18('0x3b')]);if(_0x370f9f[_0x7c18('0x3c')]){delete _0x370f9f[_0x7c18('0x3c')];}_0x6918e5[_0x7c18('0x2c')](_0x57f687)['send'](_0x370f9f);};}exports['index']=function(_0x5b4d08,_0x5bf0ed){var _0x561d48={'include':[{'model':db[_0x7c18('0x3d')],'as':_0x7c18('0x3e')}]},_0x5eb731={},_0x1e75e0={'count':0x0,'rows':[]};var _0x389292=_['map'](db[_0x7c18('0x3f')][_0x7c18('0x40')],function(_0x55f30c){return{'name':_0x55f30c[_0x7c18('0x41')],'type':_0x55f30c[_0x7c18('0x42')][_0x7c18('0x43')]};});_0x5eb731[_0x7c18('0x44')]=_[_0x7c18('0x45')](_0x389292,_0x7c18('0x3c'));_0x5eb731[_0x7c18('0x46')]=_[_0x7c18('0x47')](_0x5b4d08[_0x7c18('0x46')]);_0x5eb731[_0x7c18('0x48')]=_[_0x7c18('0x49')](_0x5eb731[_0x7c18('0x44')],_0x5eb731[_0x7c18('0x46')]);_0x561d48['attributes']=_[_0x7c18('0x49')](_0x5eb731['model'],qs[_0x7c18('0x4a')](_0x5b4d08[_0x7c18('0x46')][_0x7c18('0x4a')]));_0x561d48[_0x7c18('0x4b')]=_0x561d48['attributes'][_0x7c18('0x4c')]?_0x561d48[_0x7c18('0x4b')]:_0x5eb731[_0x7c18('0x44')];if(!_0x5b4d08[_0x7c18('0x46')]['hasOwnProperty'](_0x7c18('0x4d'))){_0x561d48[_0x7c18('0x32')]=qs[_0x7c18('0x32')](_0x5b4d08[_0x7c18('0x46')][_0x7c18('0x32')]);_0x561d48[_0x7c18('0x31')]=qs[_0x7c18('0x31')](_0x5b4d08[_0x7c18('0x46')][_0x7c18('0x31')]);}_0x561d48[_0x7c18('0x4e')]=qs[_0x7c18('0x4f')](_0x5b4d08[_0x7c18('0x46')][_0x7c18('0x4f')]);_0x561d48[_0x7c18('0x50')]=qs[_0x7c18('0x48')](_[_0x7c18('0x51')](_0x5b4d08[_0x7c18('0x46')],_0x5eb731[_0x7c18('0x48')]),_0x389292);if(_0x5b4d08[_0x7c18('0x46')][_0x7c18('0x52')]){_0x561d48[_0x7c18('0x50')]=_[_0x7c18('0x53')](_0x561d48[_0x7c18('0x50')],{'$or':_[_0x7c18('0x45')](_0x389292,function(_0x3b33ba){if(_0x3b33ba['type']!==_0x7c18('0x54')){var _0x48d4cc={};_0x48d4cc[_0x3b33ba['name']]={'$like':'%'+_0x5b4d08[_0x7c18('0x46')][_0x7c18('0x52')]+'%'};return _0x48d4cc;}})});}_0x561d48=_[_0x7c18('0x53')]({},_0x561d48,_0x5b4d08['options']);var _0x1bcf7c={'where':_0x561d48[_0x7c18('0x50')]};return db[_0x7c18('0x3f')]['count'](_0x1bcf7c)[_0x7c18('0x20')](function(_0x754f37){_0x1e75e0['count']=_0x754f37;if(_0x5b4d08[_0x7c18('0x46')][_0x7c18('0x55')]){_0x561d48['include']=[{'all':!![]}];}return db[_0x7c18('0x3f')][_0x7c18('0x56')](_0x561d48);})['then'](function(_0x257996){_0x1e75e0['rows']=_0x257996;return _0x1e75e0;})['then'](respondWithFilteredResult(_0x5bf0ed,_0x561d48))[_0x7c18('0x2b')](handleError(_0x5bf0ed,null));};exports['show']=function(_0x1ffb01,_0x49303f){var _0x1de27c={'raw':![],'where':{'id':_0x1ffb01[_0x7c18('0x57')]['id']},'include':[{'model':db[_0x7c18('0x3d')],'as':'mandatoryDispositionPause'}]},_0x762729={};_0x762729[_0x7c18('0x44')]=_[_0x7c18('0x47')](db[_0x7c18('0x3f')][_0x7c18('0x40')]);_0x762729[_0x7c18('0x46')]=_[_0x7c18('0x47')](_0x1ffb01[_0x7c18('0x46')]);_0x762729[_0x7c18('0x48')]=_[_0x7c18('0x49')](_0x762729[_0x7c18('0x44')],_0x762729['query']);_0x1de27c['attributes']=_[_0x7c18('0x49')](_0x762729['model'],qs[_0x7c18('0x4a')](_0x1ffb01[_0x7c18('0x46')][_0x7c18('0x4a')]));_0x1de27c[_0x7c18('0x4b')]=_0x1de27c[_0x7c18('0x4b')][_0x7c18('0x4c')]?_0x1de27c[_0x7c18('0x4b')]:_0x762729['model'];if(_0x1ffb01[_0x7c18('0x46')][_0x7c18('0x55')]){_0x1de27c[_0x7c18('0x58')]=[{'all':!![]}];}_0x1de27c=_[_0x7c18('0x53')]({},_0x1de27c,_0x1ffb01[_0x7c18('0x59')]);return db['SmsAccount'][_0x7c18('0x5a')](_0x1de27c)['then'](handleEntityNotFound(_0x49303f,null))[_0x7c18('0x20')](respondWithResult(_0x49303f,null))['catch'](handleError(_0x49303f,null));};exports[_0x7c18('0x5b')]=function(_0xe7d611,_0x5e9fb2){return db[_0x7c18('0x3f')]['create'](_0xe7d611[_0x7c18('0x5c')],{})[_0x7c18('0x20')](function(_0x55f4a1){var _0x465851=_0xe7d611[_0x7c18('0x5d')]['get']({'plain':!![]});if(!_0x465851)throw new Error(_0x7c18('0x5e'));if(_0x465851[_0x7c18('0x5f')]==='user'){var _0x3090cb=_0x55f4a1[_0x7c18('0x60')]({'plain':!![]});var _0x486c57=_0x7c18('0x37');return db[_0x7c18('0x61')]['find']({'where':{'name':_0x486c57,'userProfileId':_0x465851[_0x7c18('0x62')]},'raw':!![]})[_0x7c18('0x20')](function(_0x51e803){if(_0x51e803&&_0x51e803[_0x7c18('0x63')]===0x0){return db['UserProfileResource'][_0x7c18('0x5b')]({'name':_0x3090cb[_0x7c18('0x3c')],'resourceId':_0x3090cb['id'],'type':_0x51e803[_0x7c18('0x3c')],'sectionId':_0x51e803['id']},{})[_0x7c18('0x20')](function(){return _0x55f4a1;});}else{return _0x55f4a1;}})['catch'](function(_0x2d2775){logger[_0x7c18('0x27')](_0x7c18('0x64'),_0x2d2775);throw _0x2d2775;});}return _0x55f4a1;})[_0x7c18('0x20')](respondWithResult(_0x5e9fb2,0xc9))[_0x7c18('0x2b')](handleError(_0x5e9fb2,null));};exports['update']=function(_0x14333a,_0x3e07a0){if(_0x14333a['body']['id']){delete _0x14333a[_0x7c18('0x5c')]['id'];}return db[_0x7c18('0x3f')][_0x7c18('0x5a')]({'where':{'id':_0x14333a[_0x7c18('0x57')]['id']},'include':[{'model':db['Pause'],'as':'mandatoryDispositionPause'}]})[_0x7c18('0x20')](handleEntityNotFound(_0x3e07a0,null))[_0x7c18('0x20')](saveUpdates(_0x14333a[_0x7c18('0x5c')],null))[_0x7c18('0x20')](respondWithResult(_0x3e07a0,null))[_0x7c18('0x2b')](handleError(_0x3e07a0,null));};exports[_0x7c18('0x39')]=function(_0x2475f8,_0x1412d2){return db['SmsAccount'][_0x7c18('0x5a')]({'where':{'id':_0x2475f8['params']['id']}})['then'](handleEntityNotFound(_0x1412d2,null))[_0x7c18('0x20')](removeEntity(_0x1412d2,null))[_0x7c18('0x2b')](handleError(_0x1412d2,null));};exports[_0x7c18('0x65')]=function(_0x5c9278,_0x5ad530){return db[_0x7c18('0x3f')]['describe']()['then'](respondWithResult(_0x5ad530,null))[_0x7c18('0x2b')](handleError(_0x5ad530,null));};exports[_0x7c18('0x66')]=function(_0x45bcd2,_0x45a3b0,_0x13b812){if(_0x45bcd2[_0x7c18('0x5c')]['id']){delete _0x45bcd2[_0x7c18('0x5c')]['id'];}return db['SmsAccount'][_0x7c18('0x5a')]({'where':{'id':_0x45bcd2[_0x7c18('0x57')]['id']}})[_0x7c18('0x20')](handleEntityNotFound(_0x45a3b0,null))[_0x7c18('0x20')](function(_0x590fcc){if(_0x590fcc){_0x45bcd2[_0x7c18('0x5c')][_0x7c18('0x67')]=_0x590fcc['id'];return db[_0x7c18('0x68')][_0x7c18('0x5b')](_0x45bcd2[_0x7c18('0x5c')]);}})[_0x7c18('0x20')](respondWithResult(_0x45a3b0,null))[_0x7c18('0x2b')](handleError(_0x45a3b0,null));};exports[_0x7c18('0x69')]=function(_0x524d3f,_0x3df78d,_0xee1f1f){var _0x59e2ed={'raw':![],'where':{}};var _0x1b00c6={};var _0x1036a5={'count':0x0,'rows':[]};return db[_0x7c18('0x3f')][_0x7c18('0x6a')]({'where':{'id':_0x524d3f[_0x7c18('0x57')]['id']}})['then'](handleEntityNotFound(_0x3df78d,null))[_0x7c18('0x20')](function(_0x1ef77f){if(_0x1ef77f){_0x1b00c6[_0x7c18('0x44')]=_[_0x7c18('0x47')](db[_0x7c18('0x68')][_0x7c18('0x40')]);_0x1b00c6[_0x7c18('0x46')]=_[_0x7c18('0x47')](_0x524d3f['query']);_0x1b00c6['filters']=_[_0x7c18('0x49')](_0x1b00c6[_0x7c18('0x44')],_0x1b00c6[_0x7c18('0x46')]);_0x59e2ed[_0x7c18('0x4b')]=_['intersection'](_0x1b00c6[_0x7c18('0x44')],qs['fields'](_0x524d3f['query'][_0x7c18('0x4a')]));_0x59e2ed[_0x7c18('0x4b')]=_0x59e2ed['attributes'][_0x7c18('0x4c')]?_0x59e2ed[_0x7c18('0x4b')]:_0x1b00c6[_0x7c18('0x44')];if(!_0x524d3f['query']['hasOwnProperty'](_0x7c18('0x4d'))){_0x59e2ed[_0x7c18('0x32')]=qs['limit'](_0x524d3f['query'][_0x7c18('0x32')]);_0x59e2ed[_0x7c18('0x31')]=qs[_0x7c18('0x31')](_0x524d3f[_0x7c18('0x46')][_0x7c18('0x31')]);}_0x59e2ed[_0x7c18('0x4e')]=qs[_0x7c18('0x4f')](_0x524d3f[_0x7c18('0x46')][_0x7c18('0x4f')]);_0x59e2ed[_0x7c18('0x50')]=qs[_0x7c18('0x48')](_[_0x7c18('0x51')](_0x524d3f[_0x7c18('0x46')],_0x1b00c6[_0x7c18('0x48')]));_0x59e2ed[_0x7c18('0x50')]['SmsAccountId']=_0x1ef77f['id'];if(_0x524d3f[_0x7c18('0x46')]['filter']){_0x59e2ed[_0x7c18('0x50')]=_['merge'](_0x59e2ed[_0x7c18('0x50')],{'$or':_['map'](_0x59e2ed[_0x7c18('0x4b')],function(_0x128d84){var _0x3702d3={};_0x3702d3[_0x128d84]={'$like':'%'+_0x524d3f['query'][_0x7c18('0x52')]+'%'};return _0x3702d3;})});}_0x59e2ed=_[_0x7c18('0x53')]({},_0x59e2ed,_0x524d3f[_0x7c18('0x59')]);return db['Disposition'][_0x7c18('0x30')]({'where':_0x59e2ed[_0x7c18('0x50')]})['then'](function(_0x4c30a2){_0x1036a5[_0x7c18('0x30')]=_0x4c30a2;if(_0x524d3f[_0x7c18('0x46')][_0x7c18('0x55')]){_0x59e2ed['include']=[{'all':!![]}];}return db[_0x7c18('0x68')][_0x7c18('0x56')](_0x59e2ed);})['then'](function(_0xb722e5){_0x1036a5[_0x7c18('0x6b')]=_0xb722e5;return _0x1036a5;});}})[_0x7c18('0x20')](respondWithFilteredResult(_0x3df78d,_0x59e2ed))['catch'](handleError(_0x3df78d,null));};exports[_0x7c18('0x6c')]=function(_0x2197fa,_0xbd8e11,_0xc1cf51){return db[_0x7c18('0x3f')][_0x7c18('0x5a')]({'where':{'id':_0x2197fa[_0x7c18('0x57')]['id']}})[_0x7c18('0x20')](handleEntityNotFound(_0xbd8e11,null))[_0x7c18('0x20')](function(_0x492357){if(_0x492357){return _0x492357[_0x7c18('0x6c')](_0x2197fa[_0x7c18('0x46')][_0x7c18('0x6d')]);}})[_0x7c18('0x20')](respondWithStatusCode(_0xbd8e11,null))[_0x7c18('0x2b')](handleError(_0xbd8e11,null));};exports['addAnswer']=function(_0x3bd0a7,_0x72403f,_0x2eb4ee){if(_0x3bd0a7[_0x7c18('0x5c')]['id']){delete _0x3bd0a7[_0x7c18('0x5c')]['id'];}return db['SmsAccount'][_0x7c18('0x5a')]({'where':{'id':_0x3bd0a7[_0x7c18('0x57')]['id']}})[_0x7c18('0x20')](handleEntityNotFound(_0x72403f,null))[_0x7c18('0x20')](function(_0x3eba40){if(_0x3eba40){_0x3bd0a7[_0x7c18('0x5c')][_0x7c18('0x67')]=_0x3eba40['id'];return db[_0x7c18('0x6e')][_0x7c18('0x5b')](_0x3bd0a7['body']);}})[_0x7c18('0x20')](respondWithResult(_0x72403f,null))[_0x7c18('0x2b')](handleError(_0x72403f,null));};exports[_0x7c18('0x6f')]=function(_0x167e30,_0xb30dfc,_0x298abc){var _0x49af51={'raw':![],'where':{}};var _0x259cb6={};var _0x1c67a0={'count':0x0,'rows':[]};return db[_0x7c18('0x3f')][_0x7c18('0x6a')]({'where':{'id':_0x167e30['params']['id']}})['then'](handleEntityNotFound(_0xb30dfc,null))[_0x7c18('0x20')](function(_0x28bf21){if(_0x28bf21){_0x259cb6[_0x7c18('0x44')]=_[_0x7c18('0x47')](db['CannedAnswer'][_0x7c18('0x40')]);_0x259cb6[_0x7c18('0x46')]=_[_0x7c18('0x47')](_0x167e30['query']);_0x259cb6[_0x7c18('0x48')]=_[_0x7c18('0x49')](_0x259cb6[_0x7c18('0x44')],_0x259cb6[_0x7c18('0x46')]);_0x49af51['attributes']=_[_0x7c18('0x49')](_0x259cb6[_0x7c18('0x44')],qs['fields'](_0x167e30[_0x7c18('0x46')]['fields']));_0x49af51[_0x7c18('0x4b')]=_0x49af51['attributes'][_0x7c18('0x4c')]?_0x49af51[_0x7c18('0x4b')]:_0x259cb6['model'];if(!_0x167e30[_0x7c18('0x46')]['hasOwnProperty'](_0x7c18('0x4d'))){_0x49af51['limit']=qs[_0x7c18('0x32')](_0x167e30[_0x7c18('0x46')][_0x7c18('0x32')]);_0x49af51['offset']=qs['offset'](_0x167e30[_0x7c18('0x46')]['offset']);}_0x49af51[_0x7c18('0x4e')]=qs[_0x7c18('0x4f')](_0x167e30[_0x7c18('0x46')][_0x7c18('0x4f')]);_0x49af51['where']=qs[_0x7c18('0x48')](_['pick'](_0x167e30[_0x7c18('0x46')],_0x259cb6[_0x7c18('0x48')]));_0x49af51[_0x7c18('0x50')][_0x7c18('0x67')]=_0x28bf21['id'];if(_0x167e30[_0x7c18('0x46')][_0x7c18('0x52')]){_0x49af51['where']=_[_0x7c18('0x53')](_0x49af51[_0x7c18('0x50')],{'$or':_[_0x7c18('0x45')](_0x49af51[_0x7c18('0x4b')],function(_0x11bf85){var _0x256fc8={};_0x256fc8[_0x11bf85]={'$like':'%'+_0x167e30['query'][_0x7c18('0x52')]+'%'};return _0x256fc8;})});}_0x49af51=_[_0x7c18('0x53')]({},_0x49af51,_0x167e30[_0x7c18('0x59')]);return db['CannedAnswer']['count']({'where':_0x49af51[_0x7c18('0x50')]})['then'](function(_0x17bfeb){_0x1c67a0['count']=_0x17bfeb;if(_0x167e30['query']['includeAll']){_0x49af51['include']=[{'all':!![]}];}return db[_0x7c18('0x6e')][_0x7c18('0x56')](_0x49af51);})[_0x7c18('0x20')](function(_0x53fbe4){_0x1c67a0[_0x7c18('0x6b')]=_0x53fbe4;return _0x1c67a0;});}})['then'](respondWithFilteredResult(_0xb30dfc,_0x49af51))[_0x7c18('0x2b')](handleError(_0xb30dfc,null));};exports['removeAnswers']=function(_0x28a267,_0x55b0bd,_0x2fc1e4){return db[_0x7c18('0x3f')][_0x7c18('0x5a')]({'where':{'id':_0x28a267[_0x7c18('0x57')]['id']}})[_0x7c18('0x20')](handleEntityNotFound(_0x55b0bd,null))[_0x7c18('0x20')](function(_0x4df3c5){if(_0x4df3c5){return _0x4df3c5['removeAnswers'](_0x28a267[_0x7c18('0x46')][_0x7c18('0x6d')]);}})['then'](respondWithStatusCode(_0x55b0bd,null))[_0x7c18('0x2b')](handleError(_0x55b0bd,null));};exports['notify']=function(_0x3a23b1,_0x3ba2dd,_0x36d11c){var _0x2e1998={'channel':'sms'};var _0x2b673f=[];var _0x286f16=[];var _0x2417da={};return db['SmsAccount'][_0x7c18('0x5a')]({'where':{'id':_0x3a23b1[_0x7c18('0x57')]['id']},'include':[{'model':db['SmsApplication'],'as':_0x7c18('0x70')}]})[_0x7c18('0x20')](handleEntityNotFound(_0x3ba2dd,null))['then'](function(_0x4f0d2d){_0x2e1998['account']=_0x4f0d2d;_0x2e1998['applications']=_[_0x7c18('0x71')](_0x4f0d2d[_0x7c18('0x70')],[_0x7c18('0x72')],['asc']);if(_0x2e1998[_0x7c18('0x73')][_0x7c18('0x70')]){delete _0x2e1998[_0x7c18('0x73')][_0x7c18('0x70')];}return db[_0x7c18('0x74')][_0x7c18('0x65')]();})['then'](function(_0x16d8e6){if(!_0x16d8e6){throw new db[(_0x7c18('0x75'))][(_0x7c18('0x76'))](_0x7c18('0x77'));}_0x2b673f=_['difference'](_[_0x7c18('0x47')](_0x16d8e6),['createdAt',_0x7c18('0x78')]);_0x286f16=_['difference'](_[_0x7c18('0x47')](_0x16d8e6),[_0x7c18('0x79'),_0x7c18('0x78'),_0x7c18('0x7a'),_0x7c18('0x7b')]);_0x2e1998[_0x7c18('0x5c')]={'mapKey':_0x7c18('0x7c')};if(_0x2e1998[_0x7c18('0x73')][_0x7c18('0x42')]){switch(_0x2e1998['account'][_0x7c18('0x42')]){case _0x7c18('0x7d'):_0x2e1998['body'][_0x7c18('0x7e')]=_0x3a23b1[_0x7c18('0x5c')][_0x7c18('0x7f')];_0x2e1998['body'][_0x7c18('0x5c')]=_0x3a23b1[_0x7c18('0x5c')][_0x7c18('0x80')];_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x81')]=_0x3a23b1['body']['MessageSid'];break;case _0x7c18('0x82'):_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x7e')]='+'+_0x3a23b1['body'][_0x7c18('0x83')];_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x5c')]=_0x3a23b1[_0x7c18('0x5c')][_0x7c18('0x84')];break;case _0x7c18('0x85'):_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x7e')]=_0x3a23b1[_0x7c18('0x5c')][_0x7c18('0x7e')];_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x5c')]=_0x3a23b1[_0x7c18('0x5c')]['message'];break;case _0x7c18('0x86'):_0x2e1998['body'][_0x7c18('0x7e')]=_0x3a23b1[_0x7c18('0x5c')][_0x7c18('0x7e')];_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x5c')]=_0x3a23b1[_0x7c18('0x5c')][_0x7c18('0x5c')];_0x2e1998['body'][_0x7c18('0x81')]=_0x3a23b1['body'][_0x7c18('0x87')];break;case _0x7c18('0x88'):_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x7e')]=_0x3a23b1[_0x7c18('0x5c')][_0x7c18('0x7f')];_0x2e1998['body'][_0x7c18('0x5c')]=_0x3a23b1[_0x7c18('0x5c')]['Text'];_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x81')]=_0x3a23b1['body'][_0x7c18('0x89')];break;case _0x7c18('0x8a'):_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x7e')]='+'+_0x3a23b1[_0x7c18('0x5c')]['results'][0x0][_0x7c18('0x7e')];_0x2e1998[_0x7c18('0x5c')]['body']=_0x3a23b1[_0x7c18('0x5c')][_0x7c18('0x8b')][0x0][_0x7c18('0x84')];_0x2e1998[_0x7c18('0x5c')]['messageId']=_0x3a23b1[_0x7c18('0x5c')][_0x7c18('0x8b')][0x0][_0x7c18('0x81')];break;case _0x7c18('0x8c'):_0x2e1998['body'][_0x7c18('0x7e')]=_0x3a23b1[_0x7c18('0x5c')][_0x7c18('0x8d')];_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x5c')]=_0x3a23b1[_0x7c18('0x5c')][_0x7c18('0x8e')]['message'];break;case'clickatell':_0x2e1998[_0x7c18('0x5c')]['from']=_0x3a23b1['body']['fromNumber'];_0x2e1998[_0x7c18('0x5c')]['body']=_0x3a23b1[_0x7c18('0x5c')]['text'];_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x81')]=_0x3a23b1[_0x7c18('0x5c')][_0x7c18('0x8f')];break;case'bandwidth':_0x2e1998['body'][_0x7c18('0x81')]=_0x3a23b1['body'][0x0][_0x7c18('0x29')]['id'];_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x7e')]=_0x3a23b1['body'][0x0][_0x7c18('0x29')][_0x7c18('0x7e')];_0x2e1998[_0x7c18('0x5c')]['body']=_0x3a23b1[_0x7c18('0x5c')][0x0]['message'][_0x7c18('0x84')];break;case _0x7c18('0x90'):_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x7e')]=_0x3a23b1[_0x7c18('0x5c')][_0x7c18('0x7e')];_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x5c')]=_0x3a23b1[_0x7c18('0x5c')][_0x7c18('0x29')];_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x81')]=_0x3a23b1[_0x7c18('0x5c')][_0x7c18('0x91')];break;}}if(_0x2e1998[_0x7c18('0x5c')]['id']){delete _0x2e1998[_0x7c18('0x5c')]['id'];}if(_[_0x7c18('0x92')](_0x2e1998['body'][_0x7c18('0x7e')])){throw new db[(_0x7c18('0x75'))][(_0x7c18('0x76'))](_0x7c18('0x93'));}if(_[_0x7c18('0x92')](_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x5c')])||_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x5c')]===''){throw new db[(_0x7c18('0x75'))][(_0x7c18('0x76'))](_0x7c18('0x94'));}if(_['isNil'](_0x2e1998[_0x7c18('0x5c')]['mapKey'])){throw new db[(_0x7c18('0x75'))]['ValidationError']('mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x286f16);}if(!_['includes'](_0x286f16,_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x95')])){throw new db[(_0x7c18('0x75'))][(_0x7c18('0x76'))]('mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x286f16);}_0x2417da[_0x2e1998['body']['mapKey']]=_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x7e')];return db[_0x7c18('0x96')][_0x7c18('0x5a')]({'where':{'id':_0x2e1998[_0x7c18('0x73')][_0x7c18('0x7b')]},'include':[{'model':db[_0x7c18('0x74')],'as':'Contacts','where':_0x2417da,'limit':0x1,'order':[[_0x7c18('0x78'),_0x7c18('0x97')]]}]});})['then'](handleEntityNotFound(_0x3ba2dd,null))[_0x7c18('0x20')](function(_0x21a758){if(_0x21a758){_0x2e1998['list']=_[_0x7c18('0x98')](_0x21a758,[_0x7c18('0x99')]);if(_0x21a758[_0x7c18('0x99')][_0x7c18('0x4c')]){return _0x21a758[_0x7c18('0x99')][0x0];}var _0x171d46=_[_0x7c18('0x18')](_0x2e1998[_0x7c18('0x5c')],{'firstName':_0x2e1998[_0x7c18('0x5c')]['from'],'ListId':_0x21a758['id']});_0x171d46[_0x2e1998[_0x7c18('0x5c')]['mapKey']]=_0x2e1998[_0x7c18('0x5c')]['from'];return db[_0x7c18('0x74')][_0x7c18('0x5b')](_0x171d46,{'fields':_0x2b673f,'raw':!![]});}})['then'](handleEntityNotFound(_0x3ba2dd,null))[_0x7c18('0x20')](function(_0x56d259){if(_0x56d259){_0x2e1998[_0x7c18('0x9a')]=_0x56d259;var _0x27d5c1={'ContactId':_0x56d259['id'],'phone':_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x7e')],'SmsAccountId':_0x3a23b1[_0x7c18('0x57')]['id']};var _0x593165={'ContactId':_0x56d259['id'],'SmsAccountId':_0x3a23b1[_0x7c18('0x57')]['id'],'closed':![]};return db['SmsInteraction'][_0x7c18('0x5a')]({'where':_0x593165})[_0x7c18('0x20')](function(_0x48c763){if(_0x48c763){return[_0x48c763,![]];}return db['SmsInteraction'][_0x7c18('0x5b')](_0x27d5c1)[_0x7c18('0x20')](function(_0x4fcad7){return[_0x4fcad7,!![]];});});}})['spread'](function(_0x3fb410,_0x4d51f0){_0x2e1998[_0x7c18('0x9b')]=_0x3fb410[_0x7c18('0x60')]({'plain':!![]});_0x2e1998[_0x7c18('0x9b')]['created']=![];if(_0x4d51f0){if(_0x2e1998[_0x7c18('0x73')][_0x7c18('0x9c')]){_0x2e1998['applications'][_0x7c18('0x9d')]({'id':0x0,'priority':_0x2e1998['applications']['length']+0x1,'app':_0x7c18('0x9e'),'appdata':_0x7c18('0x9f'),'interval':'*,*,*,*'});}_0x2e1998[_0x7c18('0x9b')][_0x7c18('0xa0')]=!![];}return db[_0x7c18('0xa1')][_0x7c18('0x5b')]({'phone':_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x7e')],'messageId':_0x2e1998[_0x7c18('0x5c')]['messageId'],'body':_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x5c')],'SmsAccountId':_0x3a23b1['params']['id'],'SmsInteractionId':_0x3fb410['id'],'direction':'in','ContactId':_0x3fb410['ContactId'],'AttachmentId':_0x2e1998['body']['AttachmentId']});})[_0x7c18('0x20')](function(_0x2e0aac){_0x2e1998[_0x7c18('0x29')]=_0x2e0aac;if(_0x2e1998[_0x7c18('0x9b')][_0x7c18('0xa2')]){return db[_0x7c18('0xa3')][_0x7c18('0x5a')]({'attributes':['id','name'],'where':{'id':_0x2e1998['interaction'][_0x7c18('0xa2')]}})[_0x7c18('0x20')](function(_0x33b059){if(_0x33b059){_0x2e1998['applications'][_0x7c18('0xa4')]({'id':0x0,'priority':0x0,'app':_0x7c18('0xa5'),'appdata':_0x33b059[_0x7c18('0x3c')]+','+(_0x2e1998[_0x7c18('0x73')][_0x7c18('0xa6')]||0xa),'interval':_0x7c18('0xa7')});}return respondWithRpcPromise('Start',_0x7c18('0xa8'),_0x2e1998);});}return respondWithRpcPromise('Start',_0x7c18('0xa8'),_0x2e1998);})['then'](function(_0x442a96){if(_0x442a96){var _0x12f0c3=0xc8;var _0xd4120e='receiveMessage';logger[_0x7c18('0x21')](_0x7c18('0x24'),_0xd4120e,_0x12f0c3,_0x7c18('0xa9'));logger[_0x7c18('0x23')](_0x7c18('0xaa'),_0xd4120e,_0x12f0c3,'entity\x20found',JSON[_0x7c18('0x26')](_0x442a96));if(_0x2e1998[_0x7c18('0x73')][_0x7c18('0x42')]===_0x7c18('0x7d')){return _0x3ba2dd[_0x7c18('0x2c')](_0x12f0c3)[_0x7c18('0xab')](_0x7c18('0xac'),_0x7c18('0xad'))[_0x7c18('0xae')]('<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>');}else{return _0x3ba2dd['status'](_0x12f0c3)[_0x7c18('0x2e')](_0x442a96);}}})['catch'](handleError(_0x3ba2dd,null));};exports[_0x7c18('0xaf')]=function(_0x30b0af,_0x1db888){var _0xe6bff1=_0x30b0af['params']['id'];var _0x29d187=_0x30b0af[_0x7c18('0x5c')];var _0xce10a4=0xc8;var _0x45bc56=null;return db[_0x7c18('0xb0')][_0x7c18('0xb1')]({'isolationLevel':db[_0x7c18('0xb0')][_0x7c18('0xb2')][_0x7c18('0xb3')][_0x7c18('0xb4')]},function(_0x9c041a){return db[_0x7c18('0x3f')][_0x7c18('0x6a')]({'where':{'id':_0xe6bff1},'transaction':_0x9c041a})[_0x7c18('0x20')](function(_0xb5e290){if(_0xb5e290){return db[_0x7c18('0xb5')][_0x7c18('0x39')]({'where':{'SmsAccountId':_0xe6bff1},'transaction':_0x9c041a})[_0x7c18('0x20')](function(){var _0x46ae10=_[_0x7c18('0x45')](_0x29d187,function(_0x47b38a){_0x47b38a[_0x7c18('0x67')]=_0xe6bff1;return _0x47b38a;});return db[_0x7c18('0xb5')][_0x7c18('0xb6')](_0x46ae10,{'transaction':_0x9c041a});});}else{_0xce10a4=0x194;_0x45bc56=[];}});})[_0x7c18('0x20')](function(){if(_0xce10a4!==0x194){return db[_0x7c18('0xb5')][_0x7c18('0xb7')]({'where':{'SmsAccountId':_0xe6bff1},'order':_0x7c18('0x72')})[_0x7c18('0x20')](function(_0x4dd304){_0x45bc56=_0x4dd304;});}})[_0x7c18('0x2b')](function(_0x1b3a8a){_0xce10a4=0x1f4;logger[_0x7c18('0x27')](_0x1b3a8a['stack']);if(_0x1b3a8a[_0x7c18('0x3c')]){delete _0x1b3a8a[_0x7c18('0x3c')];}_0x45bc56=_0x1b3a8a;})[_0x7c18('0xb8')](function(){if(_0x45bc56===null){_0x1db888[_0x7c18('0x3a')](_0xce10a4);}else{if(_0xce10a4===0x1f4){_0x1db888[_0x7c18('0x2c')](_0xce10a4)[_0x7c18('0xae')](_0x45bc56);}else{_0x1db888[_0x7c18('0x2c')](_0xce10a4)['json'](_0x45bc56);}}});};exports[_0x7c18('0xb9')]=function(_0x29d806,_0x5bd608,_0x41a068){var _0x52a649={};var _0x1e605f={};var _0x73397;var _0x51279c;return db[_0x7c18('0x3f')]['findOne']({'where':{'id':_0x29d806[_0x7c18('0x57')]['id']}})[_0x7c18('0x20')](handleEntityNotFound(_0x5bd608,null))[_0x7c18('0x20')](function(_0x56b44c){if(_0x56b44c){_0x73397=_0x56b44c;_0x1e605f['model']=_[_0x7c18('0x47')](db[_0x7c18('0xb5')]['rawAttributes']);_0x1e605f[_0x7c18('0x46')]=_[_0x7c18('0x47')](_0x29d806[_0x7c18('0x46')]);_0x1e605f[_0x7c18('0x48')]=_['intersection'](_0x1e605f[_0x7c18('0x44')],_0x1e605f[_0x7c18('0x46')]);_0x52a649['attributes']=_['intersection'](_0x1e605f[_0x7c18('0x44')],qs[_0x7c18('0x4a')](_0x29d806[_0x7c18('0x46')]['fields']));_0x52a649[_0x7c18('0x4b')]=_0x52a649['attributes'][_0x7c18('0x4c')]?_0x52a649[_0x7c18('0x4b')]:_0x1e605f['model'];_0x52a649[_0x7c18('0x4e')]=qs['sort'](_0x29d806['query'][_0x7c18('0x4f')]);_0x52a649[_0x7c18('0x50')]=qs[_0x7c18('0x48')](_['pick'](_0x29d806['query'],_0x1e605f[_0x7c18('0x48')]));if(_0x29d806[_0x7c18('0x46')][_0x7c18('0x52')]){_0x52a649['where']=_['merge'](_0x52a649[_0x7c18('0x50')],{'$or':_[_0x7c18('0x45')](_0x52a649['attributes'],function(_0x5b0287){var _0x587acb={};_0x587acb[_0x5b0287]={'$like':'%'+_0x29d806[_0x7c18('0x46')][_0x7c18('0x52')]+'%'};return _0x587acb;})});}_0x52a649=_['merge']({},_0x52a649,_0x29d806[_0x7c18('0x59')]);return _0x73397[_0x7c18('0xb9')](_0x52a649);}})[_0x7c18('0x20')](function(_0x5f3bac){if(_0x5f3bac){_0x51279c=_0x5f3bac[_0x7c18('0x4c')];if(!_0x29d806[_0x7c18('0x46')][_0x7c18('0xba')](_0x7c18('0x4d'))){_0x52a649['limit']=qs['limit'](_0x29d806['query'][_0x7c18('0x32')]);_0x52a649[_0x7c18('0x31')]=qs[_0x7c18('0x31')](_0x29d806[_0x7c18('0x46')][_0x7c18('0x31')]);}return _0x73397['getApplications'](_0x52a649);}})[_0x7c18('0x20')](function(_0x409d4e){if(_0x409d4e){return _0x409d4e?{'count':_0x51279c,'rows':_0x409d4e}:null;}})[_0x7c18('0x20')](respondWithResult(_0x5bd608,null))[_0x7c18('0x2b')](handleError(_0x5bd608,null));};exports['getInteractions']=function(_0x44e45d,_0x12d652,_0x60ddd2){var _0xf27d02={'raw':![],'where':{}};var _0x413574={};var _0x1d0ce2={'count':0x0,'rows':[]};return db[_0x7c18('0x3f')][_0x7c18('0x6a')]({'where':{'id':_0x44e45d[_0x7c18('0x57')]['id']}})['then'](handleEntityNotFound(_0x12d652,null))['then'](function(_0x1d8e3a){if(_0x1d8e3a){_0x413574['model']=_['keys'](db[_0x7c18('0xbb')][_0x7c18('0x40')]);_0x413574[_0x7c18('0x46')]=_[_0x7c18('0x47')](_0x44e45d[_0x7c18('0x46')]);_0x413574['filters']=_[_0x7c18('0x49')](_0x413574['model'],_0x413574[_0x7c18('0x46')]);_0xf27d02['attributes']=_[_0x7c18('0x49')](_0x413574[_0x7c18('0x44')],qs['fields'](_0x44e45d[_0x7c18('0x46')]['fields']));_0xf27d02['attributes']=_0xf27d02[_0x7c18('0x4b')]['length']?_0xf27d02[_0x7c18('0x4b')]:_0x413574[_0x7c18('0x44')];if(!_0x44e45d[_0x7c18('0x46')][_0x7c18('0xba')](_0x7c18('0x4d'))){_0xf27d02['limit']=qs[_0x7c18('0x32')](_0x44e45d['query'][_0x7c18('0x32')]);_0xf27d02[_0x7c18('0x31')]=qs[_0x7c18('0x31')](_0x44e45d['query'][_0x7c18('0x31')]);}_0xf27d02[_0x7c18('0x4e')]=qs['sort'](_0x44e45d[_0x7c18('0x46')][_0x7c18('0x4f')]);_0xf27d02[_0x7c18('0x50')]=qs['filters'](_[_0x7c18('0x51')](_0x44e45d[_0x7c18('0x46')],_0x413574[_0x7c18('0x48')]));_0xf27d02[_0x7c18('0x50')][_0x7c18('0x67')]=_0x1d8e3a['id'];if(_0x44e45d[_0x7c18('0x46')][_0x7c18('0x52')]){_0xf27d02[_0x7c18('0x50')]=_[_0x7c18('0x53')](_0xf27d02[_0x7c18('0x50')],{'$or':_[_0x7c18('0x45')](_0xf27d02[_0x7c18('0x4b')],function(_0x137cdd){var _0x390f77={};_0x390f77[_0x137cdd]={'$like':'%'+_0x44e45d[_0x7c18('0x46')][_0x7c18('0x52')]+'%'};return _0x390f77;})});}_0xf27d02=_['merge']({},_0xf27d02,_0x44e45d[_0x7c18('0x59')]);return db[_0x7c18('0xbb')][_0x7c18('0x30')]({'where':_0xf27d02[_0x7c18('0x50')]})['then'](function(_0x6bf5af){_0x1d0ce2['count']=_0x6bf5af;if(_0x44e45d['query'][_0x7c18('0x55')]){_0xf27d02['include']=[{'model':db[_0x7c18('0x74')],'as':_0x7c18('0xbc'),'required':![]},{'model':db[_0x7c18('0xa3')],'as':_0x7c18('0xbd'),'attributes':['name','fullname',_0x7c18('0xbe')],'required':![]},{'model':db[_0x7c18('0xbf')],'as':_0x7c18('0xc0'),'attributes':['id',_0x7c18('0x3c'),_0x7c18('0xc1')],'where':_0x44e45d['query']['tag']?{'id':_0x44e45d[_0x7c18('0x46')][_0x7c18('0xc2')]}:undefined,'required':_0x44e45d['query'][_0x7c18('0xc2')]?!![]:![]}];}return db['SmsInteraction'][_0x7c18('0x56')](_0xf27d02);})['then'](function(_0x2ed688){_0x1d0ce2[_0x7c18('0x6b')]=_0x2ed688;return _0x1d0ce2;});}})[_0x7c18('0x20')](respondWithFilteredResult(_0x12d652,_0xf27d02))[_0x7c18('0x2b')](handleError(_0x12d652,null));};exports['send']=function(_0x4da01a,_0x367445,_0x1dc3c5){var _0xaa69fc,_0x1d826b,_0x4e8b3c;if(_['isNil'](_0x4da01a['body']['body'])||_0x4da01a[_0x7c18('0x5c')][_0x7c18('0x5c')]===''){throw new db[(_0x7c18('0x75'))]['ValidationError'](_0x7c18('0x94'));}if(_['isNil'](_0x4da01a[_0x7c18('0x5c')]['to'])){throw new db[(_0x7c18('0x75'))][(_0x7c18('0x76'))](_0x7c18('0xc3'));}_0xaa69fc=_0x4da01a['body']['to'];return db[_0x7c18('0x3f')][_0x7c18('0x5a')]({'where':{'id':_0x4da01a['params']['id']},'include':[{'model':db[_0x7c18('0x96')],'as':_0x7c18('0xc4'),'include':[{'model':db['CmContact'],'as':'Contacts','where':{'mobile':_0xaa69fc},'limit':0x1,'order':[['updatedAt','DESC']]}]}]})[_0x7c18('0x20')](handleEntityNotFound(_0x367445,null))[_0x7c18('0x20')](function(_0x299727){if(_0x299727&&_0x299727[_0x7c18('0xc4')]){_0x1d826b=_0x299727[_0x7c18('0x60')]({'plain':!![]});if(_0x1d826b['List']&&_0x1d826b[_0x7c18('0xc4')]['Contacts']['length']){return _0x1d826b[_0x7c18('0xc4')][_0x7c18('0x99')][0x0];}return db['CmContact'][_0x7c18('0x5b')](_['defaults'](_0x4da01a[_0x7c18('0x5c')],{'firstName':_0xaa69fc,'mobile':_0xaa69fc,'phone':_0xaa69fc,'ListId':_0x1d826b[_0x7c18('0x7b')]}));}})['then'](handleEntityNotFound(_0x367445,null))[_0x7c18('0x20')](function(_0x434096){if(_0x434096){_0x4e8b3c=_0x434096;return db['SmsInteraction'][_0x7c18('0x5a')]({'where':{'ContactId':_0x4e8b3c['id'],'closed':![],'SmsAccountId':_0x1d826b['id']}})[_0x7c18('0x20')](function(_0x42c1c2){if(_0x42c1c2){return[_0x42c1c2,![]];}return db[_0x7c18('0xbb')][_0x7c18('0x5b')]({'UserId':_0x4da01a[_0x7c18('0x5d')]['id'],'ContactId':_0x4e8b3c['id'],'SmsAccountId':_0x1d826b['id'],'phone':_0xaa69fc,'firstMsgDirection':'out','Messages':[_['merge'](_0x4da01a[_0x7c18('0x5c')],{'read':![],'body':_0x4da01a[_0x7c18('0x5c')][_0x7c18('0x5c')],'phone':_0xaa69fc,'SmsAccountId':_0x1d826b['id'],'UserId':_0x4da01a[_0x7c18('0x5d')]['id'],'ContactId':_0x4e8b3c['id']})]},{'include':[{'model':db[_0x7c18('0xa1')],'as':_0x7c18('0xc5')}]})[_0x7c18('0x20')](function(_0x1bcb1f){return[_0x1bcb1f,!![]];});});}})['spread'](function(_0x567d13,_0x11447e){if(_0x11447e){return _0x567d13;}return db['SmsMessage']['create'](_['merge'](_0x4da01a[_0x7c18('0x5c')],{'read':![],'body':_0x4da01a[_0x7c18('0x5c')][_0x7c18('0x5c')],'phone':_0xaa69fc,'SmsAccountId':_0x1d826b['id'],'SmsInteractionId':_0x567d13['id'],'UserId':_0x4da01a['user']['id'],'ContactId':_0x4e8b3c['id']}))[_0x7c18('0x20')](function(_0x279eae){_0x567d13[_0x7c18('0xc6')]['Messages']=[];_0x567d13['dataValues'][_0x7c18('0xc5')][_0x7c18('0x9d')](_0x279eae[_0x7c18('0xc6')]);return _0x567d13;});})[_0x7c18('0x20')](respondWithResult(_0x367445,null))[_0x7c18('0x2b')](handleError(_0x367445,null));};exports[_0x7c18('0x2c')]=function(_0x587a28,_0x2c0b7d,_0x19f7a0){if(_0x587a28['body']['id']){delete _0x587a28[_0x7c18('0x5c')]['id'];}var _0x4db0c2,_0x4f2e7b,_0x447dca;return db['SmsAccount'][_0x7c18('0x5a')]({'where':{'id':_0x587a28[_0x7c18('0x57')]['id']}})[_0x7c18('0x20')](handleEntityNotFound(_0x2c0b7d,null))[_0x7c18('0x20')](function(_0x4cde19){if(_0x4cde19){_0x447dca=_0x4cde19;logger[_0x7c18('0x23')](_0x7c18('0x24'),_0x7c18('0x2c'),_0x7c18('0xc7'),_0x4cde19[_0x7c18('0x42')],util[_0x7c18('0xc8')](_0x587a28[_0x7c18('0x5c')],{'showHidden':![],'depth':null}));switch(_0x4cde19['type']){case'skebby':if(_0x587a28[_0x7c18('0x5c')][_0x7c18('0xc9')]&&_0x587a28['body'][_0x7c18('0x2c')]){_0x4f2e7b=_0x587a28[_0x7c18('0x5c')]['status'];return db['SmsMessage'][_0x7c18('0x5a')]({'where':{'messageId':_0x587a28[_0x7c18('0x5c')][_0x7c18('0xc9')]}});}break;case'connectel':if(_0x587a28[_0x7c18('0x5c')][_0x7c18('0xca')]&&_0x587a28[_0x7c18('0x5c')][_0x7c18('0xcb')]){_0x4f2e7b=_0x587a28[_0x7c18('0x5c')]['statusInt'];return db[_0x7c18('0xa1')][_0x7c18('0x5a')]({'where':{'messageId':_0x587a28[_0x7c18('0x5c')][_0x7c18('0xca')]}});}break;case _0x7c18('0x86'):if(_0x587a28[_0x7c18('0x5c')]['message_id']&&_0x587a28[_0x7c18('0x5c')][_0x7c18('0xcc')]){_0x4f2e7b=_0x587a28[_0x7c18('0x5c')]['status_code'];return db['SmsMessage'][_0x7c18('0x5a')]({'where':{'messageId':_0x587a28['body'][_0x7c18('0x87')]}});}break;case _0x7c18('0x8a'):var _0x6a452e=_0x587a28[_0x7c18('0x5c')]['results'][0x0];if(_0x6a452e['messageId']&&_0x6a452e[_0x7c18('0x2c')][_0x7c18('0xcd')]===_0x7c18('0xce')){_0x4f2e7b=_0x6a452e[_0x7c18('0x2c')][_0x7c18('0xcd')];return db[_0x7c18('0xa1')][_0x7c18('0x5a')]({'where':{'messageId':_0x6a452e[_0x7c18('0x81')]}});}break;case _0x7c18('0xcf'):if(_0x587a28['body']['messageId']&&_0x587a28['body'][_0x7c18('0x2c')]){_0x4f2e7b=_0x587a28[_0x7c18('0x5c')][_0x7c18('0x2c')];return db['SmsMessage'][_0x7c18('0x5a')]({'where':{'messageId':_0x587a28['body'][_0x7c18('0x81')]}});}break;case _0x7c18('0xd0'):if(_0x587a28[_0x7c18('0x5c')][0x0][_0x7c18('0x29')]['id']){_0x4f2e7b=_0x587a28[_0x7c18('0x5c')][0x0][_0x7c18('0x42')];return db[_0x7c18('0xa1')][_0x7c18('0x5a')]({'where':{'messageId':_0x587a28['body'][0x0][_0x7c18('0x29')]['id']}});}break;case _0x7c18('0x90'):if(_0x587a28[_0x7c18('0x5c')]['redif']&&_0x587a28[_0x7c18('0x5c')][_0x7c18('0x2c')]){_0x4f2e7b=_0x587a28['body'][_0x7c18('0x2c')];return db[_0x7c18('0xa1')][_0x7c18('0x5a')]({'where':{'messageId':_0x587a28[_0x7c18('0x5c')]['redif']}});}break;}}})['then'](handleEntityNotFound(_0x2c0b7d,null))['then'](function(_0x416b66){if(_0x416b66){_0x4db0c2=_0x416b66;switch(_0x447dca[_0x7c18('0x42')]){case'skebby':if(_0x4f2e7b===_0x7c18('0xce')){return _0x4db0c2[_0x7c18('0x36')]({'read':!![]});}else{logger[_0x7c18('0x27')](_0x7c18('0x24'),_0x7c18('0x2c'),_0x7c18('0x82'),util['inspect'](_0x587a28[_0x7c18('0x5c')],{'showHidden':![],'depth':null}));}break;case _0x7c18('0x85'):if(_0x4f2e7b==='1'){return _0x4db0c2[_0x7c18('0x36')]({'read':!![]});}else{logger[_0x7c18('0x27')](_0x7c18('0x24'),_0x7c18('0x2c'),_0x7c18('0x82'),util['inspect'](_0x587a28[_0x7c18('0x5c')],{'showHidden':![],'depth':null}));}break;case'clicksend':if(!_0x587a28[_0x7c18('0x5c')][_0x7c18('0xd1')]&&_0x4f2e7b>=0xc8&&_0x4f2e7b<=0xce){return _0x4db0c2[_0x7c18('0x36')]({'read':!![]});}else{logger[_0x7c18('0x27')](_0x7c18('0x24'),_0x7c18('0x2c'),'clicksend',util[_0x7c18('0xc8')](_0x587a28[_0x7c18('0x5c')],{'showHidden':![],'depth':null}));}break;case _0x7c18('0x8a'):var _0x5d74d5=_0x587a28[_0x7c18('0x5c')][_0x7c18('0x8b')][0x0];if(_0x5d74d5[_0x7c18('0x2c')]['groupName']===_0x7c18('0xce')){return _0x4db0c2[_0x7c18('0x36')]({'read':!![]});}else{logger[_0x7c18('0x27')](_0x7c18('0x24'),'status',_0x7c18('0x8a'),util[_0x7c18('0xc8')](_0x587a28[_0x7c18('0x5c')],{'showHidden':![],'depth':null}));}break;case _0x7c18('0xcf'):if(_0x4f2e7b=='DELIVERED_TO_GATEWAY'||_0x4f2e7b==_0x7c18('0xd2')){return _0x4db0c2[_0x7c18('0x36')]({'read':!![]});}else{logger[_0x7c18('0x27')](_0x7c18('0x24'),'status','clickatell',util['inspect'](_0x587a28[_0x7c18('0x5c')],{'showHidden':![],'depth':null}));}break;case'bandwidth':if(_0x4f2e7b=='message-delivered'){return _0x4db0c2[_0x7c18('0x36')]({'read':!![]});}else{logger[_0x7c18('0x27')](_0x7c18('0x24'),_0x7c18('0x2c'),_0x7c18('0xd0'),util['inspect'](_0x587a28[_0x7c18('0x5c')],{'showHidden':![],'depth':null}));}break;case'intelepeer':if(_0x4f2e7b===_0x7c18('0xd3')||_0x4f2e7b===_0x7c18('0xd4')){return _0x4db0c2[_0x7c18('0x36')]({'read':!![]});}else{logger[_0x7c18('0x27')](_0x7c18('0x24'),_0x7c18('0x2c'),_0x7c18('0x90'),util[_0x7c18('0xc8')](_0x587a28['body'],{'showHidden':![],'depth':null}));}break;}return _0x4db0c2;}})[_0x7c18('0x20')](respondWithResult(_0x2c0b7d,null))[_0x7c18('0x2b')](handleError(_0x2c0b7d,null));};exports[_0x7c18('0xd5')]=function(_0x10c911,_0x1de22d,_0x3379ce){var _0x46475f,_0x2a511e,_0x2e7728;return db[_0x7c18('0x3f')]['find']({'where':{'id':_0x10c911['params']['id']}})['then'](handleEntityNotFound(_0x1de22d,null))[_0x7c18('0x20')](function(_0x2f877a){if(_0x2f877a){_0x2e7728=_0x2f877a;logger[_0x7c18('0x23')]('SmsAccount,\x20%s,\x20%s,\x20%s','status',_0x7c18('0xc7'),_0x2f877a[_0x7c18('0x42')],util[_0x7c18('0xc8')](_0x10c911['query'],{'showHidden':![],'depth':null}));switch(_0x2f877a[_0x7c18('0x42')]){case _0x7c18('0x8c'):if(_0x10c911[_0x7c18('0x46')][_0x7c18('0xd6')]&&_0x10c911['query'][_0x7c18('0xd7')]){_0x2a511e=_0x10c911[_0x7c18('0x46')][_0x7c18('0xd7')];return db[_0x7c18('0xa1')][_0x7c18('0x5a')]({'where':{'messageId':_0x10c911['query']['message-id']}});}break;}}})[_0x7c18('0x20')](handleEntityNotFound(_0x1de22d,null))[_0x7c18('0x20')](function(_0x1558b7){if(_0x1558b7){_0x46475f=_0x1558b7;switch(_0x2e7728[_0x7c18('0x42')]){case _0x7c18('0x8c'):if(_0x2a511e==='2'||_0x2a511e==='6'){return _0x46475f[_0x7c18('0x36')]({'read':!![]});}else{logger[_0x7c18('0x27')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x7c18('0x2c'),'csc',util[_0x7c18('0xc8')](_0x10c911[_0x7c18('0x46')],{'showHidden':![],'depth':null}));};break;}return _0x46475f;}})[_0x7c18('0x20')](respondWithResult(_0x1de22d,null))[_0x7c18('0x2b')](handleError(_0x1de22d,null));};exports['addAgents']=function(_0x2bbdec,_0x460845,_0x303fe0){return db[_0x7c18('0x3f')][_0x7c18('0x5a')]({'where':{'id':_0x2bbdec['params']['id']}})[_0x7c18('0x20')](handleEntityNotFound(_0x460845,null))[_0x7c18('0x20')](function(_0x5b2967){if(_0x5b2967){return _0x5b2967['addAgents'](_0x2bbdec[_0x7c18('0x5c')]['ids'],_['omit'](_0x2bbdec[_0x7c18('0x5c')],[_0x7c18('0x6d'),'id'])||{})['spread'](function(_0x29b804){for(var _0x349fed=0x0;_0x349fed<_0x2bbdec['body'][_0x7c18('0x6d')][_0x7c18('0x4c')];_0x349fed+=0x1){socket[_0x7c18('0xd8')](_0x7c18('0xd9'),{'UserId':Number(_0x2bbdec[_0x7c18('0x5c')]['ids'][_0x349fed]),'SmsAccountId':Number(_0x2bbdec[_0x7c18('0x57')]['id'])});}return _0x29b804;});}})[_0x7c18('0x20')](respondWithResult(_0x460845,null))['catch'](handleError(_0x460845,null));};exports['removeAgents']=function(_0x3f8324,_0x2fc528,_0x5f3f5f){return db['SmsAccount']['find']({'where':{'id':_0x3f8324[_0x7c18('0x57')]['id']}})['then'](handleEntityNotFound(_0x2fc528,null))[_0x7c18('0x20')](function(_0x3151c6){if(_0x3151c6){return _0x3151c6['removeAgents'](_0x3f8324[_0x7c18('0x46')][_0x7c18('0x6d')])[_0x7c18('0x20')](function(){if(_[_0x7c18('0xda')](_0x3f8324[_0x7c18('0x46')][_0x7c18('0x6d')])){for(var _0x38ac71=0x0;_0x38ac71<_0x3f8324[_0x7c18('0x46')][_0x7c18('0x6d')]['length'];_0x38ac71+=0x1){socket[_0x7c18('0xd8')](_0x7c18('0xdb'),{'UserId':Number(_0x3f8324[_0x7c18('0x46')][_0x7c18('0x6d')][_0x38ac71]),'SmsAccountId':Number(_0x3f8324[_0x7c18('0x57')]['id'])});}}else{socket[_0x7c18('0xd8')](_0x7c18('0xdb'),{'UserId':Number(_0x3f8324[_0x7c18('0x46')][_0x7c18('0x6d')]),'SmsAccountId':Number(_0x3f8324[_0x7c18('0x57')]['id'])});}});}})[_0x7c18('0x20')](respondWithStatusCode(_0x2fc528,null))['catch'](handleError(_0x2fc528,null));};exports[_0x7c18('0xdc')]=function(_0x14a645,_0x509e36,_0x38b943){var _0xbbeeb8={};var _0x2ad05f={};var _0x54ad7a;var _0x1c484d;return db[_0x7c18('0x3f')][_0x7c18('0x6a')]({'where':{'id':_0x14a645['params']['id']}})[_0x7c18('0x20')](handleEntityNotFound(_0x509e36,null))[_0x7c18('0x20')](function(_0x14ce8d){if(_0x14ce8d){_0x54ad7a=_0x14ce8d;_0x2ad05f[_0x7c18('0x44')]=_['keys'](db['User']['rawAttributes']);_0x2ad05f['query']=_['keys'](_0x14a645['query']);_0x2ad05f[_0x7c18('0x48')]=_['intersection'](_0x2ad05f[_0x7c18('0x44')],_0x2ad05f['query']);_0xbbeeb8[_0x7c18('0x4b')]=_[_0x7c18('0x49')](_0x2ad05f[_0x7c18('0x44')],qs['fields'](_0x14a645[_0x7c18('0x46')][_0x7c18('0x4a')]));_0xbbeeb8['attributes']=_0xbbeeb8[_0x7c18('0x4b')][_0x7c18('0x4c')]?_0xbbeeb8[_0x7c18('0x4b')]:_0x2ad05f[_0x7c18('0x44')];_0xbbeeb8['order']=qs['sort'](_0x14a645[_0x7c18('0x46')]['sort']);_0xbbeeb8[_0x7c18('0x50')]=qs['filters'](_[_0x7c18('0x51')](_0x14a645[_0x7c18('0x46')],_0x2ad05f[_0x7c18('0x48')]));if(_0x14a645[_0x7c18('0x46')][_0x7c18('0x52')]){_0xbbeeb8[_0x7c18('0x50')]=_[_0x7c18('0x53')](_0xbbeeb8[_0x7c18('0x50')],{'$or':_[_0x7c18('0x45')](_0xbbeeb8[_0x7c18('0x4b')],function(_0x5d61f8){var _0xbc237a={};_0xbc237a[_0x5d61f8]={'$like':'%'+_0x14a645[_0x7c18('0x46')][_0x7c18('0x52')]+'%'};return _0xbc237a;})});}_0xbbeeb8=_[_0x7c18('0x53')]({},_0xbbeeb8,_0x14a645[_0x7c18('0x59')]);return _0x54ad7a['getAgents'](_0xbbeeb8);}})[_0x7c18('0x20')](function(_0x40922a){if(_0x40922a){_0x1c484d=_0x40922a[_0x7c18('0x4c')];if(!_0x14a645[_0x7c18('0x46')]['hasOwnProperty'](_0x7c18('0x4d'))){_0xbbeeb8['limit']=qs[_0x7c18('0x32')](_0x14a645[_0x7c18('0x46')][_0x7c18('0x32')]);_0xbbeeb8[_0x7c18('0x31')]=qs[_0x7c18('0x31')](_0x14a645[_0x7c18('0x46')][_0x7c18('0x31')]);}return _0x54ad7a[_0x7c18('0xdc')](_0xbbeeb8);}})[_0x7c18('0x20')](function(_0x9d54d2){if(_0x9d54d2){return _0x9d54d2?{'count':_0x1c484d,'rows':_0x9d54d2}:null;}})[_0x7c18('0x20')](respondWithResult(_0x509e36,null))[_0x7c18('0x2b')](handleError(_0x509e36,null));};
\ No newline at end of file