Built motion from commit e0fa946e.|2.6.5
[motion2.git] / server / api / smsAccount / smsAccount.controller.js
index ec6fc14..4040862 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x8df1=['Unable\x20to\x20retrieve\x20the\x20current\x20user','role','find','userProfileId','autoAssociation','describe','addDisposition','SmsAccountId','findOne','Disposition','hasOwnProperty','sort','pick','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','removeAnswers','notify','sms','SmsApplication','Applications','orderBy','priority','asc','account','CmContact','ValidationError','no\x20available\x20attributes','difference','updatedAt','createdAt','ListId','mobile','twilio','from','From','messageId','MessageSid','sender','text','clicksend','message_id','plivo','MessageUUID','infobip','results','csc','originatingAddress','segmentedMessage','clickatell','fromNumber','replyMessageId','bandwidth','intelepeer','refid','Sequelize','from\x20is\x20mandatory','isNil','body\x20is\x20mandatory\x20and\x20not\x20empty','includes','mapKey','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','DESC','list','omit','Contacts','contact','SmsInteraction','interaction','created','applications','push','close','unmanaged','*,*,*,*','ContactId','AttachmentId','User','UserId','unshift','agent','startRouting','Start','receiveMessage','SmsAccount,\x20%s,\x20%s,\x20%s','SmsAccount,\x20%s,\x20%s,\x20%s,\x20%s','set','Content-Type','text/xml','<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>','addApplications','sequelize','transaction','ISOLATION_LEVELS','READ_COMMITTED','bulkCreate','findAndCountAll','stack','finally','getApplications','Contact','Owner','internal','Tag','Tags','color','tag','to\x20is\x20mandatory','List','out','SmsMessage','Messages','spread','dataValues','inspect','skebby','skebby_dispatch_id','connectel','requestid','statusInt','status_code','groupName','DELIVERED','redif','error_code','DELIVERED_TO_GATEWAY','RECEIVED_BY_RECIPIENT','message-delivered','DELIVRD','statusGet','message-id','state','addAgents','userSmsAccount:save','removeAgents','isArray','emit','getAgents','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','ejs','fs-extra','squel','desk.js','to-csv','querystring','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/license/util','../../mysqldb','defaults','redis','localhost','socket.io-emitter','./smsAccount.socket','register','jayson/promise','client','http','request','info','SmsAccount,\x20%s,\x20%s','debug','request\x20sent','stringify','error','code','message','sendStatus','status','json','undefined','limit','count','offset','Content-Range','apply','reject','save','update','destroy','SmsAccounts','UserProfileResource','then','end','name','send','index','Pause','mandatoryDispositionPause','map','SmsAccount','fieldName','type','key','model','query','keys','intersection','attributes','fields','length','nolimit','order','where','filters','filter','merge','options','includeAll','include','findAll','rows','params','rawAttributes','catch','create','body','user','get'];(function(_0x467e9a,_0x3f060b){var _0x54ab51=function(_0x275f7c){while(--_0x275f7c){_0x467e9a['push'](_0x467e9a['shift']());}};_0x54ab51(++_0x3f060b);}(_0x8df1,0x8d));var _0x18df=function(_0x1e30c6,_0x22fee5){_0x1e30c6=_0x1e30c6-0x0;var _0x445ac8=_0x8df1[_0x1e30c6];return _0x445ac8;};'use strict';var emlformat=require(_0x18df('0x0'));var rimraf=require(_0x18df('0x1'));var zipdir=require(_0x18df('0x2'));var jsonpatch=require(_0x18df('0x3'));var rp=require(_0x18df('0x4'));var moment=require(_0x18df('0x5'));var BPromise=require(_0x18df('0x6'));var Mustache=require(_0x18df('0x7'));var util=require(_0x18df('0x8'));var path=require(_0x18df('0x9'));var sox=require(_0x18df('0xa'));var csv=require('to-csv');var ejs=require(_0x18df('0xb'));var fs=require('fs');var fs_extra=require(_0x18df('0xc'));var _=require('lodash');var squel=require(_0x18df('0xd'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x18df('0xe'));var toCsv=require(_0x18df('0xf'));var querystring=require(_0x18df('0x10'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x18df('0x11'));var qs=require(_0x18df('0x12'));var as=require(_0x18df('0x13'));var hardwareService=require(_0x18df('0x14'));var logger=require('../../config/logger')(_0x18df('0x15'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x18df('0x16'));var db=require(_0x18df('0x17'))['db'];config['redis']=_[_0x18df('0x18')](config[_0x18df('0x19')],{'host':_0x18df('0x1a'),'port':0x18eb});var socket=require(_0x18df('0x1b'))(new Redis(config['redis']));require(_0x18df('0x1c'))[_0x18df('0x1d')](socket);var jayson=require(_0x18df('0x1e'));var client=jayson[_0x18df('0x1f')][_0x18df('0x20')]({'port':0x232c});function respondWithRpcPromise(_0x5ce615,_0x4ac7dc,_0x49a716,_0x4b3574){return new BPromise(function(_0x55d9e6,_0x45230f){var _0x2062c7=_0x4b3574||client;return _0x2062c7[_0x18df('0x21')](_0x5ce615,_0x49a716)['then'](function(_0x3b2be1){logger[_0x18df('0x22')](_0x18df('0x23'),_0x4ac7dc,'request\x20sent');logger[_0x18df('0x24')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x4ac7dc,_0x18df('0x25'),JSON[_0x18df('0x26')](_0x3b2be1));if(_0x3b2be1['error']){if(_0x3b2be1[_0x18df('0x27')][_0x18df('0x28')]===0x1f4){logger[_0x18df('0x27')]('SmsAccount,\x20%s,\x20%s',_0x4ac7dc,_0x3b2be1[_0x18df('0x27')][_0x18df('0x29')]);return _0x45230f(_0x3b2be1[_0x18df('0x27')]['message']);}logger[_0x18df('0x27')](_0x18df('0x23'),_0x4ac7dc,_0x3b2be1[_0x18df('0x27')]['message']);return _0x55d9e6(_0x3b2be1[_0x18df('0x27')][_0x18df('0x29')]);}else{logger[_0x18df('0x22')]('SmsAccount,\x20%s,\x20%s',_0x4ac7dc,_0x18df('0x25'));_0x55d9e6(_0x3b2be1['result']['message']);}})['catch'](function(_0x38254e){logger['error']('SmsAccount,\x20%s,\x20%s',_0x4ac7dc,_0x38254e);_0x45230f(_0x38254e);});});}function respondWithStatusCode(_0x1f9185,_0x41cc2a){_0x41cc2a=_0x41cc2a||0xcc;return function(_0x49d763){if(_0x49d763){return _0x1f9185[_0x18df('0x2a')](_0x41cc2a);}return _0x1f9185[_0x18df('0x2b')](_0x41cc2a)['end']();};}function respondWithResult(_0x4fb5f2,_0x5f1856){_0x5f1856=_0x5f1856||0xc8;return function(_0x4bc132){if(_0x4bc132){return _0x4fb5f2[_0x18df('0x2b')](_0x5f1856)[_0x18df('0x2c')](_0x4bc132);}};}function respondWithFilteredResult(_0x3f7505,_0x54ae19){return function(_0x2c91b6){if(_0x2c91b6){var _0x21eaf2=typeof _0x54ae19['offset']===_0x18df('0x2d')&&typeof _0x54ae19[_0x18df('0x2e')]===_0x18df('0x2d');var _0x39340b=_0x2c91b6[_0x18df('0x2f')];var _0x4f0c3b=_0x21eaf2?0x0:_0x54ae19['offset'];var _0x597a7d=_0x21eaf2?_0x2c91b6[_0x18df('0x2f')]:_0x54ae19[_0x18df('0x30')]+_0x54ae19[_0x18df('0x2e')];var _0x5a4800;if(_0x597a7d>=_0x39340b){_0x597a7d=_0x39340b;_0x5a4800=0xc8;}else{_0x5a4800=0xce;}_0x3f7505['status'](_0x5a4800);return _0x3f7505['set'](_0x18df('0x31'),_0x4f0c3b+'-'+_0x597a7d+'/'+_0x39340b)[_0x18df('0x2c')](_0x2c91b6);}return null;};}function patchUpdates(_0x519a5a){return function(_0x50f0d4){try{jsonpatch[_0x18df('0x32')](_0x50f0d4,_0x519a5a,!![]);}catch(_0x3e46cd){return BPromise[_0x18df('0x33')](_0x3e46cd);}return _0x50f0d4[_0x18df('0x34')]();};}function saveUpdates(_0x4f0822,_0x41d8b4){return function(_0x16d515){if(_0x16d515){return _0x16d515[_0x18df('0x35')](_0x4f0822)['then'](function(_0xf498fd){return _0xf498fd;});}return null;};}function removeEntity(_0xdd08d9,_0x4ebc58){return function(_0x3732cc){if(_0x3732cc){return _0x3732cc[_0x18df('0x36')]()['then'](function(){var _0x457a21=_0x3732cc['get']({'plain':!![]});var _0x432fcc=_0x18df('0x37');return db[_0x18df('0x38')][_0x18df('0x36')]({'where':{'type':_0x432fcc,'resourceId':_0x457a21['id']}})[_0x18df('0x39')](function(){return _0x3732cc;});})[_0x18df('0x39')](function(){_0xdd08d9['status'](0xcc)[_0x18df('0x3a')]();});}};}function handleEntityNotFound(_0x55f175,_0x3c1552){return function(_0x4a23d5){if(!_0x4a23d5){_0x55f175[_0x18df('0x2a')](0x194);}return _0x4a23d5;};}function handleError(_0x3a1cc4,_0xbb5583){_0xbb5583=_0xbb5583||0x1f4;return function(_0x53d5c0){logger[_0x18df('0x27')](_0x53d5c0['stack']);if(_0x53d5c0[_0x18df('0x3b')]){delete _0x53d5c0[_0x18df('0x3b')];}_0x3a1cc4[_0x18df('0x2b')](_0xbb5583)[_0x18df('0x3c')](_0x53d5c0);};}exports[_0x18df('0x3d')]=function(_0x9fc023,_0x5a9af6){var _0x3d360a={'include':[{'model':db[_0x18df('0x3e')],'as':_0x18df('0x3f')}]},_0x3141ff={},_0x3043ac={'count':0x0,'rows':[]};var _0x44b1e7=_[_0x18df('0x40')](db[_0x18df('0x41')]['rawAttributes'],function(_0x94e19a){return{'name':_0x94e19a[_0x18df('0x42')],'type':_0x94e19a[_0x18df('0x43')][_0x18df('0x44')]};});_0x3141ff[_0x18df('0x45')]=_[_0x18df('0x40')](_0x44b1e7,_0x18df('0x3b'));_0x3141ff[_0x18df('0x46')]=_[_0x18df('0x47')](_0x9fc023[_0x18df('0x46')]);_0x3141ff['filters']=_[_0x18df('0x48')](_0x3141ff[_0x18df('0x45')],_0x3141ff[_0x18df('0x46')]);_0x3d360a[_0x18df('0x49')]=_[_0x18df('0x48')](_0x3141ff['model'],qs[_0x18df('0x4a')](_0x9fc023[_0x18df('0x46')]['fields']));_0x3d360a[_0x18df('0x49')]=_0x3d360a['attributes'][_0x18df('0x4b')]?_0x3d360a[_0x18df('0x49')]:_0x3141ff[_0x18df('0x45')];if(!_0x9fc023[_0x18df('0x46')]['hasOwnProperty'](_0x18df('0x4c'))){_0x3d360a[_0x18df('0x2e')]=qs['limit'](_0x9fc023['query']['limit']);_0x3d360a[_0x18df('0x30')]=qs[_0x18df('0x30')](_0x9fc023['query'][_0x18df('0x30')]);}_0x3d360a[_0x18df('0x4d')]=qs['sort'](_0x9fc023['query']['sort']);_0x3d360a[_0x18df('0x4e')]=qs[_0x18df('0x4f')](_['pick'](_0x9fc023[_0x18df('0x46')],_0x3141ff[_0x18df('0x4f')]),_0x44b1e7);if(_0x9fc023[_0x18df('0x46')][_0x18df('0x50')]){_0x3d360a[_0x18df('0x4e')]=_[_0x18df('0x51')](_0x3d360a[_0x18df('0x4e')],{'$or':_[_0x18df('0x40')](_0x44b1e7,function(_0x2741f1){if(_0x2741f1[_0x18df('0x43')]!=='VIRTUAL'){var _0x15e8be={};_0x15e8be[_0x2741f1[_0x18df('0x3b')]]={'$like':'%'+_0x9fc023[_0x18df('0x46')][_0x18df('0x50')]+'%'};return _0x15e8be;}})});}_0x3d360a=_[_0x18df('0x51')]({},_0x3d360a,_0x9fc023[_0x18df('0x52')]);var _0xcbfaf5={'where':_0x3d360a[_0x18df('0x4e')]};return db[_0x18df('0x41')][_0x18df('0x2f')](_0xcbfaf5)['then'](function(_0x419b58){_0x3043ac[_0x18df('0x2f')]=_0x419b58;if(_0x9fc023[_0x18df('0x46')][_0x18df('0x53')]){_0x3d360a[_0x18df('0x54')]=[{'all':!![]}];}return db['SmsAccount'][_0x18df('0x55')](_0x3d360a);})[_0x18df('0x39')](function(_0x227864){_0x3043ac[_0x18df('0x56')]=_0x227864;return _0x3043ac;})[_0x18df('0x39')](respondWithFilteredResult(_0x5a9af6,_0x3d360a))['catch'](handleError(_0x5a9af6,null));};exports['show']=function(_0xf67827,_0xb5fd93){var _0xc11e21={'raw':![],'where':{'id':_0xf67827[_0x18df('0x57')]['id']},'include':[{'model':db['Pause'],'as':_0x18df('0x3f')}]},_0x1dee24={};_0x1dee24[_0x18df('0x45')]=_[_0x18df('0x47')](db['SmsAccount'][_0x18df('0x58')]);_0x1dee24['query']=_[_0x18df('0x47')](_0xf67827['query']);_0x1dee24['filters']=_[_0x18df('0x48')](_0x1dee24[_0x18df('0x45')],_0x1dee24[_0x18df('0x46')]);_0xc11e21[_0x18df('0x49')]=_['intersection'](_0x1dee24['model'],qs[_0x18df('0x4a')](_0xf67827[_0x18df('0x46')][_0x18df('0x4a')]));_0xc11e21['attributes']=_0xc11e21[_0x18df('0x49')][_0x18df('0x4b')]?_0xc11e21['attributes']:_0x1dee24[_0x18df('0x45')];if(_0xf67827['query'][_0x18df('0x53')]){_0xc11e21[_0x18df('0x54')]=[{'all':!![]}];}_0xc11e21=_[_0x18df('0x51')]({},_0xc11e21,_0xf67827[_0x18df('0x52')]);return db[_0x18df('0x41')]['find'](_0xc11e21)[_0x18df('0x39')](handleEntityNotFound(_0xb5fd93,null))[_0x18df('0x39')](respondWithResult(_0xb5fd93,null))[_0x18df('0x59')](handleError(_0xb5fd93,null));};exports[_0x18df('0x5a')]=function(_0x45080f,_0x369f3c){return db['SmsAccount'][_0x18df('0x5a')](_0x45080f[_0x18df('0x5b')],{})[_0x18df('0x39')](function(_0x4e3b34){var _0x255e4f=_0x45080f[_0x18df('0x5c')][_0x18df('0x5d')]({'plain':!![]});if(!_0x255e4f)throw new Error(_0x18df('0x5e'));if(_0x255e4f[_0x18df('0x5f')]===_0x18df('0x5c')){var _0x5b4fe6=_0x4e3b34[_0x18df('0x5d')]({'plain':!![]});var _0x56ef2e=_0x18df('0x37');return db['UserProfileSection'][_0x18df('0x60')]({'where':{'name':_0x56ef2e,'userProfileId':_0x255e4f[_0x18df('0x61')]},'raw':!![]})[_0x18df('0x39')](function(_0x2a2f68){if(_0x2a2f68&&_0x2a2f68[_0x18df('0x62')]===0x0){return db[_0x18df('0x38')]['create']({'name':_0x5b4fe6['name'],'resourceId':_0x5b4fe6['id'],'type':_0x2a2f68[_0x18df('0x3b')],'sectionId':_0x2a2f68['id']},{})[_0x18df('0x39')](function(){return _0x4e3b34;});}else{return _0x4e3b34;}})['catch'](function(_0x8adf82){logger[_0x18df('0x27')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x8adf82);throw _0x8adf82;});}return _0x4e3b34;})[_0x18df('0x39')](respondWithResult(_0x369f3c,0xc9))[_0x18df('0x59')](handleError(_0x369f3c,null));};exports['update']=function(_0x2f8192,_0x3b9474){if(_0x2f8192['body']['id']){delete _0x2f8192[_0x18df('0x5b')]['id'];}return db[_0x18df('0x41')][_0x18df('0x60')]({'where':{'id':_0x2f8192[_0x18df('0x57')]['id']},'include':[{'model':db['Pause'],'as':_0x18df('0x3f')}]})[_0x18df('0x39')](handleEntityNotFound(_0x3b9474,null))[_0x18df('0x39')](saveUpdates(_0x2f8192['body'],null))['then'](respondWithResult(_0x3b9474,null))['catch'](handleError(_0x3b9474,null));};exports[_0x18df('0x36')]=function(_0x68eb1b,_0x28c255){return db[_0x18df('0x41')][_0x18df('0x60')]({'where':{'id':_0x68eb1b['params']['id']}})[_0x18df('0x39')](handleEntityNotFound(_0x28c255,null))['then'](removeEntity(_0x28c255,null))[_0x18df('0x59')](handleError(_0x28c255,null));};exports[_0x18df('0x63')]=function(_0x9ee47f,_0x393773){return db['SmsAccount'][_0x18df('0x63')]()[_0x18df('0x39')](respondWithResult(_0x393773,null))[_0x18df('0x59')](handleError(_0x393773,null));};exports[_0x18df('0x64')]=function(_0x4c3244,_0x7ed389,_0x40cfdf){if(_0x4c3244[_0x18df('0x5b')]['id']){delete _0x4c3244['body']['id'];}return db[_0x18df('0x41')][_0x18df('0x60')]({'where':{'id':_0x4c3244['params']['id']}})[_0x18df('0x39')](handleEntityNotFound(_0x7ed389,null))['then'](function(_0x446bb7){if(_0x446bb7){_0x4c3244[_0x18df('0x5b')][_0x18df('0x65')]=_0x446bb7['id'];return db['Disposition']['create'](_0x4c3244[_0x18df('0x5b')]);}})[_0x18df('0x39')](respondWithResult(_0x7ed389,null))[_0x18df('0x59')](handleError(_0x7ed389,null));};exports['getDispositions']=function(_0x406b58,_0x3ea2f6,_0x5e6dc5){var _0x113e91={'raw':![],'where':{}};var _0x174a77={};var _0x39210e={'count':0x0,'rows':[]};return db[_0x18df('0x41')][_0x18df('0x66')]({'where':{'id':_0x406b58[_0x18df('0x57')]['id']}})[_0x18df('0x39')](handleEntityNotFound(_0x3ea2f6,null))[_0x18df('0x39')](function(_0x155f39){if(_0x155f39){_0x174a77[_0x18df('0x45')]=_[_0x18df('0x47')](db[_0x18df('0x67')]['rawAttributes']);_0x174a77[_0x18df('0x46')]=_['keys'](_0x406b58['query']);_0x174a77[_0x18df('0x4f')]=_[_0x18df('0x48')](_0x174a77[_0x18df('0x45')],_0x174a77['query']);_0x113e91['attributes']=_[_0x18df('0x48')](_0x174a77[_0x18df('0x45')],qs[_0x18df('0x4a')](_0x406b58['query']['fields']));_0x113e91['attributes']=_0x113e91[_0x18df('0x49')]['length']?_0x113e91['attributes']:_0x174a77['model'];if(!_0x406b58['query'][_0x18df('0x68')](_0x18df('0x4c'))){_0x113e91[_0x18df('0x2e')]=qs['limit'](_0x406b58[_0x18df('0x46')][_0x18df('0x2e')]);_0x113e91[_0x18df('0x30')]=qs['offset'](_0x406b58[_0x18df('0x46')][_0x18df('0x30')]);}_0x113e91[_0x18df('0x4d')]=qs[_0x18df('0x69')](_0x406b58[_0x18df('0x46')]['sort']);_0x113e91[_0x18df('0x4e')]=qs[_0x18df('0x4f')](_[_0x18df('0x6a')](_0x406b58[_0x18df('0x46')],_0x174a77[_0x18df('0x4f')]));_0x113e91[_0x18df('0x4e')][_0x18df('0x65')]=_0x155f39['id'];if(_0x406b58[_0x18df('0x46')][_0x18df('0x50')]){_0x113e91[_0x18df('0x4e')]=_[_0x18df('0x51')](_0x113e91['where'],{'$or':_['map'](_0x113e91[_0x18df('0x49')],function(_0x1cab0c){var _0x9a5021={};_0x9a5021[_0x1cab0c]={'$like':'%'+_0x406b58['query']['filter']+'%'};return _0x9a5021;})});}_0x113e91=_['merge']({},_0x113e91,_0x406b58[_0x18df('0x52')]);return db['Disposition'][_0x18df('0x2f')]({'where':_0x113e91['where']})[_0x18df('0x39')](function(_0x4e2eeb){_0x39210e[_0x18df('0x2f')]=_0x4e2eeb;if(_0x406b58[_0x18df('0x46')][_0x18df('0x53')]){_0x113e91[_0x18df('0x54')]=[{'all':!![]}];}return db['Disposition']['findAll'](_0x113e91);})['then'](function(_0x1ecaa2){_0x39210e['rows']=_0x1ecaa2;return _0x39210e;});}})[_0x18df('0x39')](respondWithFilteredResult(_0x3ea2f6,_0x113e91))[_0x18df('0x59')](handleError(_0x3ea2f6,null));};exports['removeDispositions']=function(_0x4dd4c0,_0xe35c1e,_0x74b424){return db[_0x18df('0x41')][_0x18df('0x60')]({'where':{'id':_0x4dd4c0[_0x18df('0x57')]['id']}})[_0x18df('0x39')](handleEntityNotFound(_0xe35c1e,null))['then'](function(_0x244da2){if(_0x244da2){return _0x244da2[_0x18df('0x6b')](_0x4dd4c0[_0x18df('0x46')][_0x18df('0x6c')]);}})[_0x18df('0x39')](respondWithStatusCode(_0xe35c1e,null))[_0x18df('0x59')](handleError(_0xe35c1e,null));};exports[_0x18df('0x6d')]=function(_0x1ddf52,_0x207526,_0x37e0f3){if(_0x1ddf52[_0x18df('0x5b')]['id']){delete _0x1ddf52[_0x18df('0x5b')]['id'];}return db[_0x18df('0x41')][_0x18df('0x60')]({'where':{'id':_0x1ddf52[_0x18df('0x57')]['id']}})[_0x18df('0x39')](handleEntityNotFound(_0x207526,null))[_0x18df('0x39')](function(_0x445d4a){if(_0x445d4a){_0x1ddf52[_0x18df('0x5b')]['SmsAccountId']=_0x445d4a['id'];return db[_0x18df('0x6e')]['create'](_0x1ddf52['body']);}})[_0x18df('0x39')](respondWithResult(_0x207526,null))[_0x18df('0x59')](handleError(_0x207526,null));};exports[_0x18df('0x6f')]=function(_0x3053cb,_0x362883,_0x21fa55){var _0x3f6cb4={'raw':![],'where':{}};var _0xe46ffd={};var _0x1439a8={'count':0x0,'rows':[]};return db[_0x18df('0x41')][_0x18df('0x66')]({'where':{'id':_0x3053cb[_0x18df('0x57')]['id']}})['then'](handleEntityNotFound(_0x362883,null))['then'](function(_0x5d8ff2){if(_0x5d8ff2){_0xe46ffd[_0x18df('0x45')]=_[_0x18df('0x47')](db['CannedAnswer'][_0x18df('0x58')]);_0xe46ffd[_0x18df('0x46')]=_[_0x18df('0x47')](_0x3053cb[_0x18df('0x46')]);_0xe46ffd[_0x18df('0x4f')]=_[_0x18df('0x48')](_0xe46ffd[_0x18df('0x45')],_0xe46ffd[_0x18df('0x46')]);_0x3f6cb4[_0x18df('0x49')]=_[_0x18df('0x48')](_0xe46ffd[_0x18df('0x45')],qs['fields'](_0x3053cb[_0x18df('0x46')][_0x18df('0x4a')]));_0x3f6cb4[_0x18df('0x49')]=_0x3f6cb4['attributes'][_0x18df('0x4b')]?_0x3f6cb4[_0x18df('0x49')]:_0xe46ffd[_0x18df('0x45')];if(!_0x3053cb[_0x18df('0x46')][_0x18df('0x68')](_0x18df('0x4c'))){_0x3f6cb4[_0x18df('0x2e')]=qs[_0x18df('0x2e')](_0x3053cb[_0x18df('0x46')][_0x18df('0x2e')]);_0x3f6cb4[_0x18df('0x30')]=qs[_0x18df('0x30')](_0x3053cb[_0x18df('0x46')][_0x18df('0x30')]);}_0x3f6cb4[_0x18df('0x4d')]=qs[_0x18df('0x69')](_0x3053cb['query'][_0x18df('0x69')]);_0x3f6cb4[_0x18df('0x4e')]=qs[_0x18df('0x4f')](_['pick'](_0x3053cb[_0x18df('0x46')],_0xe46ffd['filters']));_0x3f6cb4[_0x18df('0x4e')]['SmsAccountId']=_0x5d8ff2['id'];if(_0x3053cb[_0x18df('0x46')][_0x18df('0x50')]){_0x3f6cb4[_0x18df('0x4e')]=_[_0x18df('0x51')](_0x3f6cb4['where'],{'$or':_[_0x18df('0x40')](_0x3f6cb4[_0x18df('0x49')],function(_0x189bd3){var _0xd19eb6={};_0xd19eb6[_0x189bd3]={'$like':'%'+_0x3053cb[_0x18df('0x46')][_0x18df('0x50')]+'%'};return _0xd19eb6;})});}_0x3f6cb4=_[_0x18df('0x51')]({},_0x3f6cb4,_0x3053cb[_0x18df('0x52')]);return db['CannedAnswer'][_0x18df('0x2f')]({'where':_0x3f6cb4[_0x18df('0x4e')]})['then'](function(_0x119428){_0x1439a8[_0x18df('0x2f')]=_0x119428;if(_0x3053cb[_0x18df('0x46')][_0x18df('0x53')]){_0x3f6cb4['include']=[{'all':!![]}];}return db[_0x18df('0x6e')][_0x18df('0x55')](_0x3f6cb4);})[_0x18df('0x39')](function(_0x44311c){_0x1439a8[_0x18df('0x56')]=_0x44311c;return _0x1439a8;});}})[_0x18df('0x39')](respondWithFilteredResult(_0x362883,_0x3f6cb4))[_0x18df('0x59')](handleError(_0x362883,null));};exports[_0x18df('0x70')]=function(_0xa35aa9,_0x391dc4,_0x9ed826){return db[_0x18df('0x41')][_0x18df('0x60')]({'where':{'id':_0xa35aa9[_0x18df('0x57')]['id']}})[_0x18df('0x39')](handleEntityNotFound(_0x391dc4,null))['then'](function(_0x29a868){if(_0x29a868){return _0x29a868['removeAnswers'](_0xa35aa9[_0x18df('0x46')][_0x18df('0x6c')]);}})[_0x18df('0x39')](respondWithStatusCode(_0x391dc4,null))[_0x18df('0x59')](handleError(_0x391dc4,null));};exports[_0x18df('0x71')]=function(_0x319256,_0x683a64,_0xab28ad){var _0x58a02f={'channel':_0x18df('0x72')};var _0x4d6481=[];var _0x40ebed=[];var _0x5379aa={};return db['SmsAccount'][_0x18df('0x60')]({'where':{'id':_0x319256[_0x18df('0x57')]['id']},'include':[{'model':db[_0x18df('0x73')],'as':_0x18df('0x74')}]})['then'](handleEntityNotFound(_0x683a64,null))[_0x18df('0x39')](function(_0x5dd718){_0x58a02f['account']=_0x5dd718;_0x58a02f['applications']=_[_0x18df('0x75')](_0x5dd718[_0x18df('0x74')],[_0x18df('0x76')],[_0x18df('0x77')]);if(_0x58a02f['account'][_0x18df('0x74')]){delete _0x58a02f[_0x18df('0x78')][_0x18df('0x74')];}return db[_0x18df('0x79')][_0x18df('0x63')]();})[_0x18df('0x39')](function(_0x36eb10){if(!_0x36eb10){throw new db['Sequelize'][(_0x18df('0x7a'))](_0x18df('0x7b'));}_0x4d6481=_[_0x18df('0x7c')](_[_0x18df('0x47')](_0x36eb10),['createdAt',_0x18df('0x7d')]);_0x40ebed=_['difference'](_[_0x18df('0x47')](_0x36eb10),[_0x18df('0x7e'),_0x18df('0x7d'),'CompanyId',_0x18df('0x7f')]);_0x58a02f['body']={'mapKey':_0x18df('0x80')};if(_0x58a02f[_0x18df('0x78')]['type']){switch(_0x58a02f[_0x18df('0x78')][_0x18df('0x43')]){case _0x18df('0x81'):_0x58a02f[_0x18df('0x5b')][_0x18df('0x82')]=_0x319256['body'][_0x18df('0x83')];_0x58a02f[_0x18df('0x5b')]['body']=_0x319256[_0x18df('0x5b')]['Body'];_0x58a02f[_0x18df('0x5b')][_0x18df('0x84')]=_0x319256[_0x18df('0x5b')][_0x18df('0x85')];break;case'skebby':_0x58a02f[_0x18df('0x5b')]['from']='+'+_0x319256['body'][_0x18df('0x86')];_0x58a02f[_0x18df('0x5b')]['body']=_0x319256[_0x18df('0x5b')][_0x18df('0x87')];break;case'connectel':_0x58a02f[_0x18df('0x5b')][_0x18df('0x82')]=_0x319256[_0x18df('0x5b')]['from'];_0x58a02f[_0x18df('0x5b')][_0x18df('0x5b')]=_0x319256[_0x18df('0x5b')][_0x18df('0x29')];break;case _0x18df('0x88'):_0x58a02f[_0x18df('0x5b')][_0x18df('0x82')]=_0x319256['body'][_0x18df('0x82')];_0x58a02f[_0x18df('0x5b')][_0x18df('0x5b')]=_0x319256['body'][_0x18df('0x5b')];_0x58a02f[_0x18df('0x5b')][_0x18df('0x84')]=_0x319256['body'][_0x18df('0x89')];break;case _0x18df('0x8a'):_0x58a02f[_0x18df('0x5b')][_0x18df('0x82')]=_0x319256['body']['From'];_0x58a02f['body'][_0x18df('0x5b')]=_0x319256[_0x18df('0x5b')]['Text'];_0x58a02f['body'][_0x18df('0x84')]=_0x319256['body'][_0x18df('0x8b')];break;case _0x18df('0x8c'):_0x58a02f[_0x18df('0x5b')]['from']='+'+_0x319256[_0x18df('0x5b')][_0x18df('0x8d')][0x0][_0x18df('0x82')];_0x58a02f[_0x18df('0x5b')][_0x18df('0x5b')]=_0x319256[_0x18df('0x5b')][_0x18df('0x8d')][0x0][_0x18df('0x87')];_0x58a02f[_0x18df('0x5b')]['messageId']=_0x319256[_0x18df('0x5b')][_0x18df('0x8d')][0x0][_0x18df('0x84')];break;case _0x18df('0x8e'):_0x58a02f[_0x18df('0x5b')]['from']=_0x319256['body'][_0x18df('0x8f')];_0x58a02f[_0x18df('0x5b')][_0x18df('0x5b')]=_0x319256[_0x18df('0x5b')][_0x18df('0x90')][_0x18df('0x29')];break;case _0x18df('0x91'):_0x58a02f[_0x18df('0x5b')]['from']=_0x319256[_0x18df('0x5b')][_0x18df('0x92')];_0x58a02f[_0x18df('0x5b')][_0x18df('0x5b')]=_0x319256['body'][_0x18df('0x87')];_0x58a02f[_0x18df('0x5b')][_0x18df('0x84')]=_0x319256['body'][_0x18df('0x93')];break;case _0x18df('0x94'):_0x58a02f[_0x18df('0x5b')][_0x18df('0x84')]=_0x319256[_0x18df('0x5b')][0x0][_0x18df('0x29')]['id'];_0x58a02f['body'][_0x18df('0x82')]=_0x319256[_0x18df('0x5b')][0x0][_0x18df('0x29')][_0x18df('0x82')];_0x58a02f[_0x18df('0x5b')]['body']=_0x319256[_0x18df('0x5b')][0x0]['message']['text'];break;case _0x18df('0x95'):_0x58a02f['body']['from']=_0x319256[_0x18df('0x5b')][_0x18df('0x82')];_0x58a02f[_0x18df('0x5b')][_0x18df('0x5b')]=_0x319256[_0x18df('0x5b')][_0x18df('0x29')];_0x58a02f[_0x18df('0x5b')]['messageId']=_0x319256[_0x18df('0x5b')][_0x18df('0x96')];break;}}if(_0x58a02f[_0x18df('0x5b')]['id']){delete _0x58a02f[_0x18df('0x5b')]['id'];}if(_['isNil'](_0x58a02f[_0x18df('0x5b')][_0x18df('0x82')])){throw new db[(_0x18df('0x97'))][(_0x18df('0x7a'))](_0x18df('0x98'));}if(_[_0x18df('0x99')](_0x58a02f[_0x18df('0x5b')][_0x18df('0x5b')])||_0x58a02f[_0x18df('0x5b')][_0x18df('0x5b')]===''){throw new db['Sequelize'][(_0x18df('0x7a'))](_0x18df('0x9a'));}if(_['isNil'](_0x58a02f['body']['mapKey'])){throw new db[(_0x18df('0x97'))][(_0x18df('0x7a'))]('mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x40ebed);}if(!_[_0x18df('0x9b')](_0x40ebed,_0x58a02f[_0x18df('0x5b')][_0x18df('0x9c')])){throw new db['Sequelize']['ValidationError'](_0x18df('0x9d')+_0x40ebed);}_0x5379aa[_0x58a02f[_0x18df('0x5b')][_0x18df('0x9c')]]=_0x58a02f[_0x18df('0x5b')][_0x18df('0x82')];return db[_0x18df('0x9e')]['find']({'where':{'id':_0x58a02f['account']['ListId']},'include':[{'model':db[_0x18df('0x79')],'as':'Contacts','where':_0x5379aa,'limit':0x1,'order':[['updatedAt',_0x18df('0x9f')]]}]});})['then'](handleEntityNotFound(_0x683a64,null))['then'](function(_0x4e4f46){if(_0x4e4f46){_0x58a02f[_0x18df('0xa0')]=_[_0x18df('0xa1')](_0x4e4f46,[_0x18df('0xa2')]);if(_0x4e4f46[_0x18df('0xa2')][_0x18df('0x4b')]){return _0x4e4f46['Contacts'][0x0];}var _0x17d9a6=_[_0x18df('0x18')](_0x58a02f[_0x18df('0x5b')],{'firstName':_0x58a02f[_0x18df('0x5b')]['from'],'ListId':_0x4e4f46['id']});_0x17d9a6[_0x58a02f[_0x18df('0x5b')][_0x18df('0x9c')]]=_0x58a02f[_0x18df('0x5b')][_0x18df('0x82')];return db[_0x18df('0x79')][_0x18df('0x5a')](_0x17d9a6,{'fields':_0x4d6481,'raw':!![]});}})['then'](handleEntityNotFound(_0x683a64,null))[_0x18df('0x39')](function(_0x1b3c6b){if(_0x1b3c6b){_0x58a02f[_0x18df('0xa3')]=_0x1b3c6b;var _0x132877={'ContactId':_0x1b3c6b['id'],'phone':_0x58a02f[_0x18df('0x5b')][_0x18df('0x82')],'SmsAccountId':_0x319256[_0x18df('0x57')]['id']};var _0x35d1c0={'ContactId':_0x1b3c6b['id'],'SmsAccountId':_0x319256[_0x18df('0x57')]['id'],'closed':![]};return db['SmsInteraction']['find']({'where':_0x35d1c0})[_0x18df('0x39')](function(_0x4c1fa2){if(_0x4c1fa2){return[_0x4c1fa2,![]];}return db[_0x18df('0xa4')]['create'](_0x132877)[_0x18df('0x39')](function(_0x570e83){return[_0x570e83,!![]];});});}})['spread'](function(_0x3b4e4d,_0x1033f4){_0x58a02f[_0x18df('0xa5')]=_0x3b4e4d[_0x18df('0x5d')]({'plain':!![]});_0x58a02f[_0x18df('0xa5')][_0x18df('0xa6')]=![];if(_0x1033f4){if(_0x58a02f[_0x18df('0x78')]['autoclose']){_0x58a02f[_0x18df('0xa7')][_0x18df('0xa8')]({'id':0x0,'priority':_0x58a02f['applications'][_0x18df('0x4b')]+0x1,'app':_0x18df('0xa9'),'appdata':_0x18df('0xaa'),'interval':_0x18df('0xab')});}_0x58a02f['interaction']['created']=!![];}return db['SmsMessage'][_0x18df('0x5a')]({'phone':_0x58a02f[_0x18df('0x5b')]['from'],'messageId':_0x58a02f[_0x18df('0x5b')][_0x18df('0x84')],'body':_0x58a02f[_0x18df('0x5b')][_0x18df('0x5b')],'SmsAccountId':_0x319256[_0x18df('0x57')]['id'],'SmsInteractionId':_0x3b4e4d['id'],'direction':'in','ContactId':_0x3b4e4d[_0x18df('0xac')],'AttachmentId':_0x58a02f['body'][_0x18df('0xad')]});})[_0x18df('0x39')](function(_0xd4f56f){_0x58a02f[_0x18df('0x29')]=_0xd4f56f;if(_0x58a02f[_0x18df('0xa5')]['UserId']){return db[_0x18df('0xae')][_0x18df('0x60')]({'attributes':['id',_0x18df('0x3b')],'where':{'id':_0x58a02f['interaction'][_0x18df('0xaf')]}})[_0x18df('0x39')](function(_0xb86a59){if(_0xb86a59){_0x58a02f[_0x18df('0xa7')][_0x18df('0xb0')]({'id':0x0,'priority':0x0,'app':_0x18df('0xb1'),'appdata':_0xb86a59[_0x18df('0x3b')]+','+(_0x58a02f['account']['waitForTheAssignedAgent']||0xa),'interval':_0x18df('0xab')});}return respondWithRpcPromise('Start',_0x18df('0xb2'),_0x58a02f);});}return respondWithRpcPromise(_0x18df('0xb3'),_0x18df('0xb2'),_0x58a02f);})[_0x18df('0x39')](function(_0x4ddb66){if(_0x4ddb66){var _0xdfac7c=0xc8;var _0x54834c=_0x18df('0xb4');logger[_0x18df('0x22')](_0x18df('0xb5'),_0x54834c,_0xdfac7c,'entity\x20found');logger[_0x18df('0x24')](_0x18df('0xb6'),_0x54834c,_0xdfac7c,'entity\x20found',JSON['stringify'](_0x4ddb66));if(_0x58a02f[_0x18df('0x78')][_0x18df('0x43')]===_0x18df('0x81')){return _0x683a64[_0x18df('0x2b')](_0xdfac7c)[_0x18df('0xb7')](_0x18df('0xb8'),_0x18df('0xb9'))['send'](_0x18df('0xba'));}else{return _0x683a64['status'](_0xdfac7c)[_0x18df('0x2c')](_0x4ddb66);}}})[_0x18df('0x59')](handleError(_0x683a64,null));};exports[_0x18df('0xbb')]=function(_0x4defc2,_0x3f4e67){var _0x5b68c9=_0x4defc2[_0x18df('0x57')]['id'];var _0x18d2c5=_0x4defc2[_0x18df('0x5b')];var _0x46103d=0xc8;var _0x30a8b3=null;return db[_0x18df('0xbc')][_0x18df('0xbd')]({'isolationLevel':db['sequelize']['Transaction'][_0x18df('0xbe')][_0x18df('0xbf')]},function(_0x154533){return db['SmsAccount'][_0x18df('0x66')]({'where':{'id':_0x5b68c9},'transaction':_0x154533})['then'](function(_0x3b497d){if(_0x3b497d){return db[_0x18df('0x73')][_0x18df('0x36')]({'where':{'SmsAccountId':_0x5b68c9},'transaction':_0x154533})[_0x18df('0x39')](function(){var _0x5dd2fc=_['map'](_0x18d2c5,function(_0x206d88){_0x206d88[_0x18df('0x65')]=_0x5b68c9;return _0x206d88;});return db['SmsApplication'][_0x18df('0xc0')](_0x5dd2fc,{'transaction':_0x154533});});}else{_0x46103d=0x194;_0x30a8b3=[];}});})['then'](function(){if(_0x46103d!==0x194){return db[_0x18df('0x73')][_0x18df('0xc1')]({'where':{'SmsAccountId':_0x5b68c9},'order':_0x18df('0x76')})[_0x18df('0x39')](function(_0x5b9db4){_0x30a8b3=_0x5b9db4;});}})[_0x18df('0x59')](function(_0x1563f4){_0x46103d=0x1f4;logger[_0x18df('0x27')](_0x1563f4[_0x18df('0xc2')]);if(_0x1563f4[_0x18df('0x3b')]){delete _0x1563f4[_0x18df('0x3b')];}_0x30a8b3=_0x1563f4;})[_0x18df('0xc3')](function(){if(_0x30a8b3===null){_0x3f4e67[_0x18df('0x2a')](_0x46103d);}else{if(_0x46103d===0x1f4){_0x3f4e67[_0x18df('0x2b')](_0x46103d)[_0x18df('0x3c')](_0x30a8b3);}else{_0x3f4e67[_0x18df('0x2b')](_0x46103d)[_0x18df('0x2c')](_0x30a8b3);}}});};exports[_0x18df('0xc4')]=function(_0x1c17f5,_0x34929b,_0x65abf1){var _0x2e0ea8={};var _0x481039={};var _0x56f737;var _0x113da6;return db['SmsAccount']['findOne']({'where':{'id':_0x1c17f5[_0x18df('0x57')]['id']}})[_0x18df('0x39')](handleEntityNotFound(_0x34929b,null))[_0x18df('0x39')](function(_0x247798){if(_0x247798){_0x56f737=_0x247798;_0x481039[_0x18df('0x45')]=_[_0x18df('0x47')](db[_0x18df('0x73')][_0x18df('0x58')]);_0x481039['query']=_[_0x18df('0x47')](_0x1c17f5['query']);_0x481039['filters']=_[_0x18df('0x48')](_0x481039['model'],_0x481039[_0x18df('0x46')]);_0x2e0ea8[_0x18df('0x49')]=_[_0x18df('0x48')](_0x481039[_0x18df('0x45')],qs['fields'](_0x1c17f5['query'][_0x18df('0x4a')]));_0x2e0ea8['attributes']=_0x2e0ea8['attributes'][_0x18df('0x4b')]?_0x2e0ea8[_0x18df('0x49')]:_0x481039[_0x18df('0x45')];_0x2e0ea8['order']=qs['sort'](_0x1c17f5[_0x18df('0x46')][_0x18df('0x69')]);_0x2e0ea8[_0x18df('0x4e')]=qs[_0x18df('0x4f')](_[_0x18df('0x6a')](_0x1c17f5[_0x18df('0x46')],_0x481039[_0x18df('0x4f')]));if(_0x1c17f5[_0x18df('0x46')]['filter']){_0x2e0ea8[_0x18df('0x4e')]=_[_0x18df('0x51')](_0x2e0ea8[_0x18df('0x4e')],{'$or':_[_0x18df('0x40')](_0x2e0ea8[_0x18df('0x49')],function(_0x2cc521){var _0x52d474={};_0x52d474[_0x2cc521]={'$like':'%'+_0x1c17f5[_0x18df('0x46')]['filter']+'%'};return _0x52d474;})});}_0x2e0ea8=_[_0x18df('0x51')]({},_0x2e0ea8,_0x1c17f5[_0x18df('0x52')]);return _0x56f737[_0x18df('0xc4')](_0x2e0ea8);}})[_0x18df('0x39')](function(_0x33f649){if(_0x33f649){_0x113da6=_0x33f649[_0x18df('0x4b')];if(!_0x1c17f5[_0x18df('0x46')][_0x18df('0x68')](_0x18df('0x4c'))){_0x2e0ea8['limit']=qs[_0x18df('0x2e')](_0x1c17f5[_0x18df('0x46')]['limit']);_0x2e0ea8['offset']=qs[_0x18df('0x30')](_0x1c17f5[_0x18df('0x46')]['offset']);}return _0x56f737[_0x18df('0xc4')](_0x2e0ea8);}})[_0x18df('0x39')](function(_0x346900){if(_0x346900){return _0x346900?{'count':_0x113da6,'rows':_0x346900}:null;}})[_0x18df('0x39')](respondWithResult(_0x34929b,null))[_0x18df('0x59')](handleError(_0x34929b,null));};exports['getInteractions']=function(_0x28b2ab,_0x2dfbee,_0x21d9d8){var _0x3ee1f2={'raw':![],'where':{}};var _0x384b85={};var _0x227397={'count':0x0,'rows':[]};return db[_0x18df('0x41')][_0x18df('0x66')]({'where':{'id':_0x28b2ab[_0x18df('0x57')]['id']}})[_0x18df('0x39')](handleEntityNotFound(_0x2dfbee,null))['then'](function(_0x188902){if(_0x188902){_0x384b85['model']=_[_0x18df('0x47')](db[_0x18df('0xa4')][_0x18df('0x58')]);_0x384b85['query']=_[_0x18df('0x47')](_0x28b2ab[_0x18df('0x46')]);_0x384b85[_0x18df('0x4f')]=_[_0x18df('0x48')](_0x384b85[_0x18df('0x45')],_0x384b85[_0x18df('0x46')]);_0x3ee1f2[_0x18df('0x49')]=_[_0x18df('0x48')](_0x384b85['model'],qs['fields'](_0x28b2ab[_0x18df('0x46')][_0x18df('0x4a')]));_0x3ee1f2[_0x18df('0x49')]=_0x3ee1f2['attributes'][_0x18df('0x4b')]?_0x3ee1f2[_0x18df('0x49')]:_0x384b85[_0x18df('0x45')];if(!_0x28b2ab[_0x18df('0x46')]['hasOwnProperty']('nolimit')){_0x3ee1f2['limit']=qs['limit'](_0x28b2ab[_0x18df('0x46')][_0x18df('0x2e')]);_0x3ee1f2[_0x18df('0x30')]=qs[_0x18df('0x30')](_0x28b2ab[_0x18df('0x46')][_0x18df('0x30')]);}_0x3ee1f2[_0x18df('0x4d')]=qs[_0x18df('0x69')](_0x28b2ab['query']['sort']);_0x3ee1f2['where']=qs[_0x18df('0x4f')](_['pick'](_0x28b2ab['query'],_0x384b85[_0x18df('0x4f')]));_0x3ee1f2[_0x18df('0x4e')][_0x18df('0x65')]=_0x188902['id'];if(_0x28b2ab[_0x18df('0x46')]['filter']){_0x3ee1f2[_0x18df('0x4e')]=_[_0x18df('0x51')](_0x3ee1f2[_0x18df('0x4e')],{'$or':_[_0x18df('0x40')](_0x3ee1f2[_0x18df('0x49')],function(_0x36daba){var _0x50ebf4={};_0x50ebf4[_0x36daba]={'$like':'%'+_0x28b2ab['query'][_0x18df('0x50')]+'%'};return _0x50ebf4;})});}_0x3ee1f2=_['merge']({},_0x3ee1f2,_0x28b2ab[_0x18df('0x52')]);return db[_0x18df('0xa4')][_0x18df('0x2f')]({'where':_0x3ee1f2['where']})[_0x18df('0x39')](function(_0xd455c4){_0x227397['count']=_0xd455c4;if(_0x28b2ab['query']['includeAll']){_0x3ee1f2[_0x18df('0x54')]=[{'model':db[_0x18df('0x79')],'as':_0x18df('0xc5'),'required':![]},{'model':db[_0x18df('0xae')],'as':_0x18df('0xc6'),'attributes':[_0x18df('0x3b'),'fullname',_0x18df('0xc7')],'required':![]},{'model':db[_0x18df('0xc8')],'as':_0x18df('0xc9'),'attributes':['id','name',_0x18df('0xca')],'where':_0x28b2ab['query'][_0x18df('0xcb')]?{'id':_0x28b2ab[_0x18df('0x46')][_0x18df('0xcb')]}:undefined,'required':_0x28b2ab['query'][_0x18df('0xcb')]?!![]:![]}];}return db[_0x18df('0xa4')][_0x18df('0x55')](_0x3ee1f2);})[_0x18df('0x39')](function(_0x4a40d7){_0x227397['rows']=_0x4a40d7;return _0x227397;});}})[_0x18df('0x39')](respondWithFilteredResult(_0x2dfbee,_0x3ee1f2))[_0x18df('0x59')](handleError(_0x2dfbee,null));};exports[_0x18df('0x3c')]=function(_0x31c5ae,_0x45aef6,_0x2c0827){var _0x17ed18,_0x415377,_0x22f119;if(_[_0x18df('0x99')](_0x31c5ae[_0x18df('0x5b')]['body'])||_0x31c5ae[_0x18df('0x5b')][_0x18df('0x5b')]===''){throw new db[(_0x18df('0x97'))][(_0x18df('0x7a'))](_0x18df('0x9a'));}if(_[_0x18df('0x99')](_0x31c5ae[_0x18df('0x5b')]['to'])){throw new db[(_0x18df('0x97'))][(_0x18df('0x7a'))](_0x18df('0xcc'));}_0x17ed18=_0x31c5ae['body']['to'];return db[_0x18df('0x41')][_0x18df('0x60')]({'where':{'id':_0x31c5ae['params']['id']},'include':[{'model':db[_0x18df('0x9e')],'as':_0x18df('0xcd'),'include':[{'model':db[_0x18df('0x79')],'as':_0x18df('0xa2'),'where':{'mobile':_0x17ed18},'limit':0x1,'order':[[_0x18df('0x7d'),_0x18df('0x9f')]]}]}]})['then'](handleEntityNotFound(_0x45aef6,null))[_0x18df('0x39')](function(_0x23344e){if(_0x23344e&&_0x23344e[_0x18df('0xcd')]){_0x415377=_0x23344e['get']({'plain':!![]});if(_0x415377[_0x18df('0xcd')]&&_0x415377[_0x18df('0xcd')]['Contacts'][_0x18df('0x4b')]){return _0x415377[_0x18df('0xcd')][_0x18df('0xa2')][0x0];}return db[_0x18df('0x79')][_0x18df('0x5a')](_[_0x18df('0x18')](_0x31c5ae['body'],{'firstName':_0x17ed18,'mobile':_0x17ed18,'phone':_0x17ed18,'ListId':_0x415377[_0x18df('0x7f')]}));}})[_0x18df('0x39')](handleEntityNotFound(_0x45aef6,null))[_0x18df('0x39')](function(_0x1ec41a){if(_0x1ec41a){_0x22f119=_0x1ec41a;return db['SmsInteraction'][_0x18df('0x60')]({'where':{'ContactId':_0x22f119['id'],'closed':![],'SmsAccountId':_0x415377['id']}})['then'](function(_0x1e95cc){if(_0x1e95cc){return[_0x1e95cc,![]];}return db[_0x18df('0xa4')][_0x18df('0x5a')]({'UserId':_0x31c5ae[_0x18df('0x5c')]['id'],'ContactId':_0x22f119['id'],'SmsAccountId':_0x415377['id'],'phone':_0x17ed18,'firstMsgDirection':_0x18df('0xce'),'Messages':[_[_0x18df('0x51')](_0x31c5ae['body'],{'read':![],'body':_0x31c5ae['body'][_0x18df('0x5b')],'phone':_0x17ed18,'SmsAccountId':_0x415377['id'],'UserId':_0x31c5ae[_0x18df('0x5c')]['id'],'ContactId':_0x22f119['id']})]},{'include':[{'model':db[_0x18df('0xcf')],'as':_0x18df('0xd0')}]})[_0x18df('0x39')](function(_0x5c285e){return[_0x5c285e,!![]];});});}})[_0x18df('0xd1')](function(_0x5b74b5,_0x37a632){if(_0x37a632){return _0x5b74b5;}return db[_0x18df('0xcf')][_0x18df('0x5a')](_[_0x18df('0x51')](_0x31c5ae[_0x18df('0x5b')],{'read':![],'body':_0x31c5ae[_0x18df('0x5b')][_0x18df('0x5b')],'phone':_0x17ed18,'SmsAccountId':_0x415377['id'],'SmsInteractionId':_0x5b74b5['id'],'UserId':_0x31c5ae[_0x18df('0x5c')]['id'],'ContactId':_0x22f119['id']}))[_0x18df('0x39')](function(_0x167f7d){_0x5b74b5['dataValues'][_0x18df('0xd0')]=[];_0x5b74b5[_0x18df('0xd2')][_0x18df('0xd0')][_0x18df('0xa8')](_0x167f7d[_0x18df('0xd2')]);return _0x5b74b5;});})['then'](respondWithResult(_0x45aef6,null))[_0x18df('0x59')](handleError(_0x45aef6,null));};exports[_0x18df('0x2b')]=function(_0x284310,_0x30f4d4,_0x1e188b){if(_0x284310['body']['id']){delete _0x284310[_0x18df('0x5b')]['id'];}var _0x6a1621,_0x5280d9,_0x555d80;return db[_0x18df('0x41')][_0x18df('0x60')]({'where':{'id':_0x284310[_0x18df('0x57')]['id']}})[_0x18df('0x39')](handleEntityNotFound(_0x30f4d4,null))[_0x18df('0x39')](function(_0x527222){if(_0x527222){_0x555d80=_0x527222;logger[_0x18df('0x24')](_0x18df('0xb5'),_0x18df('0x2b'),'received\x20delivery\x20report\x20from',_0x527222[_0x18df('0x43')],util[_0x18df('0xd3')](_0x284310['body'],{'showHidden':![],'depth':null}));switch(_0x527222[_0x18df('0x43')]){case _0x18df('0xd4'):if(_0x284310[_0x18df('0x5b')][_0x18df('0xd5')]&&_0x284310[_0x18df('0x5b')]['status']){_0x5280d9=_0x284310[_0x18df('0x5b')][_0x18df('0x2b')];return db[_0x18df('0xcf')][_0x18df('0x60')]({'where':{'messageId':_0x284310[_0x18df('0x5b')]['skebby_dispatch_id']}});}break;case _0x18df('0xd6'):if(_0x284310[_0x18df('0x5b')][_0x18df('0xd7')]&&_0x284310[_0x18df('0x5b')][_0x18df('0xd8')]){_0x5280d9=_0x284310['body'][_0x18df('0xd8')];return db[_0x18df('0xcf')][_0x18df('0x60')]({'where':{'messageId':_0x284310[_0x18df('0x5b')][_0x18df('0xd7')]}});}break;case _0x18df('0x88'):if(_0x284310['body'][_0x18df('0x89')]&&_0x284310[_0x18df('0x5b')][_0x18df('0xd9')]){_0x5280d9=_0x284310[_0x18df('0x5b')][_0x18df('0xd9')];return db[_0x18df('0xcf')]['find']({'where':{'messageId':_0x284310[_0x18df('0x5b')][_0x18df('0x89')]}});}break;case _0x18df('0x8c'):var _0x5977f8=_0x284310['body'][_0x18df('0x8d')][0x0];if(_0x5977f8[_0x18df('0x84')]&&_0x5977f8[_0x18df('0x2b')][_0x18df('0xda')]===_0x18df('0xdb')){_0x5280d9=_0x5977f8[_0x18df('0x2b')][_0x18df('0xda')];return db[_0x18df('0xcf')][_0x18df('0x60')]({'where':{'messageId':_0x5977f8[_0x18df('0x84')]}});}break;case _0x18df('0x91'):if(_0x284310[_0x18df('0x5b')][_0x18df('0x84')]&&_0x284310['body'][_0x18df('0x2b')]){_0x5280d9=_0x284310[_0x18df('0x5b')][_0x18df('0x2b')];return db[_0x18df('0xcf')][_0x18df('0x60')]({'where':{'messageId':_0x284310['body'][_0x18df('0x84')]}});}break;case'bandwidth':if(_0x284310['body'][0x0][_0x18df('0x29')]['id']){_0x5280d9=_0x284310[_0x18df('0x5b')][0x0][_0x18df('0x43')];return db[_0x18df('0xcf')][_0x18df('0x60')]({'where':{'messageId':_0x284310[_0x18df('0x5b')][0x0]['message']['id']}});}break;case _0x18df('0x95'):if(_0x284310[_0x18df('0x5b')][_0x18df('0xdc')]&&_0x284310[_0x18df('0x5b')][_0x18df('0x2b')]){_0x5280d9=_0x284310[_0x18df('0x5b')][_0x18df('0x2b')];return db[_0x18df('0xcf')][_0x18df('0x60')]({'where':{'messageId':_0x284310[_0x18df('0x5b')][_0x18df('0xdc')]}});}break;}}})['then'](handleEntityNotFound(_0x30f4d4,null))[_0x18df('0x39')](function(_0x50da47){if(_0x50da47){_0x6a1621=_0x50da47;switch(_0x555d80[_0x18df('0x43')]){case _0x18df('0xd4'):if(_0x5280d9==='DELIVERED'){return _0x6a1621['update']({'read':!![]});}else{logger[_0x18df('0x27')](_0x18df('0xb5'),'status',_0x18df('0xd4'),util['inspect'](_0x284310[_0x18df('0x5b')],{'showHidden':![],'depth':null}));}break;case _0x18df('0xd6'):if(_0x5280d9==='1'){return _0x6a1621[_0x18df('0x35')]({'read':!![]});}else{logger[_0x18df('0x27')](_0x18df('0xb5'),'status',_0x18df('0xd4'),util[_0x18df('0xd3')](_0x284310[_0x18df('0x5b')],{'showHidden':![],'depth':null}));}break;case _0x18df('0x88'):if(!_0x284310[_0x18df('0x5b')][_0x18df('0xdd')]&&_0x5280d9>=0xc8&&_0x5280d9<=0xce){return _0x6a1621[_0x18df('0x35')]({'read':!![]});}else{logger[_0x18df('0x27')](_0x18df('0xb5'),_0x18df('0x2b'),_0x18df('0x88'),util[_0x18df('0xd3')](_0x284310[_0x18df('0x5b')],{'showHidden':![],'depth':null}));}break;case _0x18df('0x8c'):var _0x481642=_0x284310[_0x18df('0x5b')]['results'][0x0];if(_0x481642['status'][_0x18df('0xda')]===_0x18df('0xdb')){return _0x6a1621[_0x18df('0x35')]({'read':!![]});}else{logger['error']('SmsAccount,\x20%s,\x20%s,\x20%s',_0x18df('0x2b'),'infobip',util['inspect'](_0x284310[_0x18df('0x5b')],{'showHidden':![],'depth':null}));}break;case _0x18df('0x91'):if(_0x5280d9==_0x18df('0xde')||_0x5280d9==_0x18df('0xdf')){return _0x6a1621[_0x18df('0x35')]({'read':!![]});}else{logger[_0x18df('0x27')](_0x18df('0xb5'),'status','clickatell',util['inspect'](_0x284310['body'],{'showHidden':![],'depth':null}));}break;case _0x18df('0x94'):if(_0x5280d9==_0x18df('0xe0')){return _0x6a1621[_0x18df('0x35')]({'read':!![]});}else{logger['error'](_0x18df('0xb5'),_0x18df('0x2b'),_0x18df('0x94'),util[_0x18df('0xd3')](_0x284310[_0x18df('0x5b')],{'showHidden':![],'depth':null}));}break;case _0x18df('0x95'):if(_0x5280d9===_0x18df('0xe1')||_0x5280d9==='ACCEPTD'){return _0x6a1621[_0x18df('0x35')]({'read':!![]});}else{logger[_0x18df('0x27')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x18df('0x2b'),_0x18df('0x95'),util[_0x18df('0xd3')](_0x284310[_0x18df('0x5b')],{'showHidden':![],'depth':null}));}break;}return _0x6a1621;}})[_0x18df('0x39')](respondWithResult(_0x30f4d4,null))['catch'](handleError(_0x30f4d4,null));};exports[_0x18df('0xe2')]=function(_0x3fd502,_0x5e60a2,_0x499f){var _0x2c1783,_0x18cc45,_0x258de6;return db[_0x18df('0x41')][_0x18df('0x60')]({'where':{'id':_0x3fd502['params']['id']}})[_0x18df('0x39')](handleEntityNotFound(_0x5e60a2,null))[_0x18df('0x39')](function(_0x1152d8){if(_0x1152d8){_0x258de6=_0x1152d8;logger[_0x18df('0x24')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x18df('0x2b'),'received\x20delivery\x20report\x20from',_0x1152d8[_0x18df('0x43')],util[_0x18df('0xd3')](_0x3fd502['query'],{'showHidden':![],'depth':null}));switch(_0x1152d8[_0x18df('0x43')]){case _0x18df('0x8e'):if(_0x3fd502['query'][_0x18df('0xe3')]&&_0x3fd502[_0x18df('0x46')]['state']){_0x18cc45=_0x3fd502[_0x18df('0x46')][_0x18df('0xe4')];return db[_0x18df('0xcf')]['find']({'where':{'messageId':_0x3fd502[_0x18df('0x46')][_0x18df('0xe3')]}});}break;}}})['then'](handleEntityNotFound(_0x5e60a2,null))[_0x18df('0x39')](function(_0x3e8e04){if(_0x3e8e04){_0x2c1783=_0x3e8e04;switch(_0x258de6['type']){case _0x18df('0x8e'):if(_0x18cc45==='2'||_0x18cc45==='6'){return _0x2c1783[_0x18df('0x35')]({'read':!![]});}else{logger['error']('SmsAccount,\x20%s,\x20%s,\x20%s',_0x18df('0x2b'),'csc',util[_0x18df('0xd3')](_0x3fd502['query'],{'showHidden':![],'depth':null}));};break;}return _0x2c1783;}})['then'](respondWithResult(_0x5e60a2,null))[_0x18df('0x59')](handleError(_0x5e60a2,null));};exports[_0x18df('0xe5')]=function(_0x10fa02,_0x197e66,_0x4234e6){return db[_0x18df('0x41')]['find']({'where':{'id':_0x10fa02[_0x18df('0x57')]['id']}})[_0x18df('0x39')](handleEntityNotFound(_0x197e66,null))[_0x18df('0x39')](function(_0x48cd05){if(_0x48cd05){return _0x48cd05[_0x18df('0xe5')](_0x10fa02[_0x18df('0x5b')][_0x18df('0x6c')],_[_0x18df('0xa1')](_0x10fa02[_0x18df('0x5b')],[_0x18df('0x6c'),'id'])||{})[_0x18df('0xd1')](function(_0x5d84c5){for(var _0x31e7fd=0x0;_0x31e7fd<_0x10fa02['body'][_0x18df('0x6c')][_0x18df('0x4b')];_0x31e7fd+=0x1){socket['emit'](_0x18df('0xe6'),{'UserId':Number(_0x10fa02['body'][_0x18df('0x6c')][_0x31e7fd]),'SmsAccountId':Number(_0x10fa02[_0x18df('0x57')]['id'])});}return _0x5d84c5;});}})[_0x18df('0x39')](respondWithResult(_0x197e66,null))['catch'](handleError(_0x197e66,null));};exports[_0x18df('0xe7')]=function(_0x4496b9,_0x15acf8,_0x35a300){return db[_0x18df('0x41')][_0x18df('0x60')]({'where':{'id':_0x4496b9[_0x18df('0x57')]['id']}})[_0x18df('0x39')](handleEntityNotFound(_0x15acf8,null))['then'](function(_0x15cad3){if(_0x15cad3){return _0x15cad3['removeAgents'](_0x4496b9[_0x18df('0x46')][_0x18df('0x6c')])[_0x18df('0x39')](function(){if(_[_0x18df('0xe8')](_0x4496b9['query'][_0x18df('0x6c')])){for(var _0x3a6bff=0x0;_0x3a6bff<_0x4496b9[_0x18df('0x46')]['ids']['length'];_0x3a6bff+=0x1){socket[_0x18df('0xe9')]('userSmsAccount:remove',{'UserId':Number(_0x4496b9[_0x18df('0x46')][_0x18df('0x6c')][_0x3a6bff]),'SmsAccountId':Number(_0x4496b9['params']['id'])});}}else{socket['emit']('userSmsAccount:remove',{'UserId':Number(_0x4496b9[_0x18df('0x46')][_0x18df('0x6c')]),'SmsAccountId':Number(_0x4496b9[_0x18df('0x57')]['id'])});}});}})['then'](respondWithStatusCode(_0x15acf8,null))[_0x18df('0x59')](handleError(_0x15acf8,null));};exports[_0x18df('0xea')]=function(_0x53e044,_0x57878d,_0x4dcbf7){var _0x40fd2f={};var _0x13ee15={};var _0x15f2a8;var _0x3f25da;return db[_0x18df('0x41')]['findOne']({'where':{'id':_0x53e044['params']['id']}})[_0x18df('0x39')](handleEntityNotFound(_0x57878d,null))[_0x18df('0x39')](function(_0x1993d9){if(_0x1993d9){_0x15f2a8=_0x1993d9;_0x13ee15[_0x18df('0x45')]=_[_0x18df('0x47')](db[_0x18df('0xae')]['rawAttributes']);_0x13ee15['query']=_[_0x18df('0x47')](_0x53e044['query']);_0x13ee15[_0x18df('0x4f')]=_['intersection'](_0x13ee15[_0x18df('0x45')],_0x13ee15[_0x18df('0x46')]);_0x40fd2f[_0x18df('0x49')]=_['intersection'](_0x13ee15[_0x18df('0x45')],qs[_0x18df('0x4a')](_0x53e044[_0x18df('0x46')]['fields']));_0x40fd2f['attributes']=_0x40fd2f[_0x18df('0x49')][_0x18df('0x4b')]?_0x40fd2f['attributes']:_0x13ee15[_0x18df('0x45')];_0x40fd2f[_0x18df('0x4d')]=qs[_0x18df('0x69')](_0x53e044['query']['sort']);_0x40fd2f['where']=qs['filters'](_[_0x18df('0x6a')](_0x53e044[_0x18df('0x46')],_0x13ee15[_0x18df('0x4f')]));if(_0x53e044['query']['filter']){_0x40fd2f[_0x18df('0x4e')]=_[_0x18df('0x51')](_0x40fd2f[_0x18df('0x4e')],{'$or':_[_0x18df('0x40')](_0x40fd2f[_0x18df('0x49')],function(_0x51c8a9){var _0x3480c8={};_0x3480c8[_0x51c8a9]={'$like':'%'+_0x53e044['query'][_0x18df('0x50')]+'%'};return _0x3480c8;})});}_0x40fd2f=_[_0x18df('0x51')]({},_0x40fd2f,_0x53e044[_0x18df('0x52')]);return _0x15f2a8['getAgents'](_0x40fd2f);}})[_0x18df('0x39')](function(_0x159cfe){if(_0x159cfe){_0x3f25da=_0x159cfe[_0x18df('0x4b')];if(!_0x53e044[_0x18df('0x46')][_0x18df('0x68')](_0x18df('0x4c'))){_0x40fd2f[_0x18df('0x2e')]=qs[_0x18df('0x2e')](_0x53e044['query']['limit']);_0x40fd2f[_0x18df('0x30')]=qs[_0x18df('0x30')](_0x53e044['query'][_0x18df('0x30')]);}return _0x15f2a8[_0x18df('0xea')](_0x40fd2f);}})['then'](function(_0x31c0bd){if(_0x31c0bd){return _0x31c0bd?{'count':_0x3f25da,'rows':_0x31c0bd}:null;}})[_0x18df('0x39')](respondWithResult(_0x57878d,null))[_0x18df('0x59')](handleError(_0x57878d,null));};
\ No newline at end of file
+var _0x72c2=['agent','waitForTheAssignedAgent','Start','startRouting','receiveMessage','entity\x20found','set','Content-Type','text/xml','addApplications','sequelize','transaction','Transaction','ISOLATION_LEVELS','READ_COMMITTED','SmsApplication','findAndCountAll','finally','getApplications','getInteractions','Contact','Owner','fullname','Tag','Tags','color','tag','to\x20is\x20mandatory','List','ListId','out','Messages','dataValues','received\x20delivery\x20report\x20from','inspect','skebby_dispatch_id','statusInt','requestid','clicksend','status_code','DELIVERED','groupName','bandwidth','redif','DELIVERED_TO_GATEWAY','RECEIVED_BY_RECIPIENT','message-delivered','ACCEPTD','statusGet','state','message-id','omit','emit','removeAgents','isArray','userSmsAccount:remove','getAgents','eml-format','zip-dir','fast-json-patch','moment','bluebird','mustache','path','sox','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','localhost','socket.io-emitter','./smsAccount.socket','register','client','http','request','info','SmsAccount,\x20%s,\x20%s','debug','SmsAccount,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','message','sendStatus','end','status','json','undefined','count','offset','limit','Content-Range','apply','reject','save','destroy','then','SmsAccounts','stack','name','send','mandatoryDispositionPause','map','SmsAccount','fieldName','type','query','intersection','attributes','model','nolimit','order','sort','where','filters','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','show','params','Pause','keys','rawAttributes','fields','length','find','catch','create','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','autoAssociation','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','body','describe','addDisposition','SmsAccountId','Disposition','getDispositions','findOne','hasOwnProperty','removeDispositions','ids','addAnswer','CannedAnswer','removeAnswers','notify','sms','Applications','account','applications','orderBy','priority','asc','CmContact','Sequelize','ValidationError','createdAt','updatedAt','mobile','twilio','from','From','Body','MessageSid','skebby','sender','text','connectel','messageId','message_id','plivo','Text','MessageUUID','infobip','results','csc','originatingAddress','segmentedMessage','clickatell','fromNumber','replyMessageId','intelepeer','refid','isNil','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','DESC','list','Contacts','defaults','contact','SmsInteraction','spread','interaction','created','autoclose','push','unmanaged','*,*,*,*','SmsMessage','UserId','User'];(function(_0x555788,_0x207c93){var _0x2ec89b=function(_0x376709){while(--_0x376709){_0x555788['push'](_0x555788['shift']());}};_0x2ec89b(++_0x207c93);}(_0x72c2,0x123));var _0x272c=function(_0x21cbb2,_0x1c3dc1){_0x21cbb2=_0x21cbb2-0x0;var _0x3caeb0=_0x72c2[_0x21cbb2];return _0x3caeb0;};'use strict';var emlformat=require(_0x272c('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x272c('0x1'));var jsonpatch=require(_0x272c('0x2'));var rp=require('request-promise');var moment=require(_0x272c('0x3'));var BPromise=require(_0x272c('0x4'));var Mustache=require(_0x272c('0x5'));var util=require('util');var path=require(_0x272c('0x6'));var sox=require(_0x272c('0x7'));var csv=require('to-csv');var ejs=require(_0x272c('0x8'));var fs=require('fs');var fs_extra=require(_0x272c('0x9'));var _=require(_0x272c('0xa'));var squel=require(_0x272c('0xb'));var crypto=require(_0x272c('0xc'));var jsforce=require(_0x272c('0xd'));var deskjs=require(_0x272c('0xe'));var toCsv=require('to-csv');var querystring=require(_0x272c('0xf'));var Papa=require(_0x272c('0x10'));var Redis=require(_0x272c('0x11'));var authService=require(_0x272c('0x12'));var qs=require(_0x272c('0x13'));var as=require(_0x272c('0x14'));var hardwareService=require(_0x272c('0x15'));var logger=require(_0x272c('0x16'))(_0x272c('0x17'));var utils=require(_0x272c('0x18'));var config=require(_0x272c('0x19'));var licenseUtil=require(_0x272c('0x1a'));var db=require(_0x272c('0x1b'))['db'];config['redis']=_['defaults'](config[_0x272c('0x1c')],{'host':_0x272c('0x1d'),'port':0x18eb});var socket=require(_0x272c('0x1e'))(new Redis(config[_0x272c('0x1c')]));require(_0x272c('0x1f'))[_0x272c('0x20')](socket);var jayson=require('jayson/promise');var client=jayson[_0x272c('0x21')][_0x272c('0x22')]({'port':0x232c});function respondWithRpcPromise(_0x4d2087,_0x2b7371,_0x2be89a,_0x1ce2f1){return new BPromise(function(_0x4ab6ba,_0x5cbe6a){var _0x2da2e9=_0x1ce2f1||client;return _0x2da2e9[_0x272c('0x23')](_0x4d2087,_0x2be89a)['then'](function(_0x19c05b){logger[_0x272c('0x24')](_0x272c('0x25'),_0x2b7371,'request\x20sent');logger[_0x272c('0x26')](_0x272c('0x27'),_0x2b7371,_0x272c('0x28'),JSON[_0x272c('0x29')](_0x19c05b));if(_0x19c05b[_0x272c('0x2a')]){if(_0x19c05b['error']['code']===0x1f4){logger[_0x272c('0x2a')](_0x272c('0x25'),_0x2b7371,_0x19c05b[_0x272c('0x2a')]['message']);return _0x5cbe6a(_0x19c05b[_0x272c('0x2a')]['message']);}logger[_0x272c('0x2a')](_0x272c('0x25'),_0x2b7371,_0x19c05b[_0x272c('0x2a')][_0x272c('0x2b')]);return _0x4ab6ba(_0x19c05b[_0x272c('0x2a')][_0x272c('0x2b')]);}else{logger[_0x272c('0x24')](_0x272c('0x25'),_0x2b7371,'request\x20sent');_0x4ab6ba(_0x19c05b['result'][_0x272c('0x2b')]);}})['catch'](function(_0x22d0be){logger[_0x272c('0x2a')](_0x272c('0x25'),_0x2b7371,_0x22d0be);_0x5cbe6a(_0x22d0be);});});}function respondWithStatusCode(_0x221862,_0x1bcefd){_0x1bcefd=_0x1bcefd||0xcc;return function(_0x23b217){if(_0x23b217){return _0x221862[_0x272c('0x2c')](_0x1bcefd);}return _0x221862['status'](_0x1bcefd)[_0x272c('0x2d')]();};}function respondWithResult(_0x1dbb5b,_0x1ec395){_0x1ec395=_0x1ec395||0xc8;return function(_0x36f88a){if(_0x36f88a){return _0x1dbb5b[_0x272c('0x2e')](_0x1ec395)[_0x272c('0x2f')](_0x36f88a);}};}function respondWithFilteredResult(_0x4bc3a1,_0x3ba851){return function(_0x481c30){if(_0x481c30){var _0x3d8f57=typeof _0x3ba851['offset']===_0x272c('0x30')&&typeof _0x3ba851['limit']===_0x272c('0x30');var _0x2fb6d4=_0x481c30[_0x272c('0x31')];var _0x22a93a=_0x3d8f57?0x0:_0x3ba851[_0x272c('0x32')];var _0x1b1ef9=_0x3d8f57?_0x481c30[_0x272c('0x31')]:_0x3ba851['offset']+_0x3ba851[_0x272c('0x33')];var _0x4a459b;if(_0x1b1ef9>=_0x2fb6d4){_0x1b1ef9=_0x2fb6d4;_0x4a459b=0xc8;}else{_0x4a459b=0xce;}_0x4bc3a1['status'](_0x4a459b);return _0x4bc3a1['set'](_0x272c('0x34'),_0x22a93a+'-'+_0x1b1ef9+'/'+_0x2fb6d4)[_0x272c('0x2f')](_0x481c30);}return null;};}function patchUpdates(_0x48bc14){return function(_0x461611){try{jsonpatch[_0x272c('0x35')](_0x461611,_0x48bc14,!![]);}catch(_0x594e4b){return BPromise[_0x272c('0x36')](_0x594e4b);}return _0x461611[_0x272c('0x37')]();};}function saveUpdates(_0x463451,_0x132553){return function(_0x168b40){if(_0x168b40){return _0x168b40['update'](_0x463451)['then'](function(_0x1798ad){return _0x1798ad;});}return null;};}function removeEntity(_0x8b5070,_0x17b904){return function(_0x1fc700){if(_0x1fc700){return _0x1fc700[_0x272c('0x38')]()[_0x272c('0x39')](function(){var _0x52a197=_0x1fc700['get']({'plain':!![]});var _0x486620=_0x272c('0x3a');return db['UserProfileResource'][_0x272c('0x38')]({'where':{'type':_0x486620,'resourceId':_0x52a197['id']}})[_0x272c('0x39')](function(){return _0x1fc700;});})[_0x272c('0x39')](function(){_0x8b5070[_0x272c('0x2e')](0xcc)[_0x272c('0x2d')]();});}};}function handleEntityNotFound(_0x4c7ef5,_0x2dc8fd){return function(_0xc516a0){if(!_0xc516a0){_0x4c7ef5[_0x272c('0x2c')](0x194);}return _0xc516a0;};}function handleError(_0x43136b,_0x5cce6b){_0x5cce6b=_0x5cce6b||0x1f4;return function(_0x4deaac){logger[_0x272c('0x2a')](_0x4deaac[_0x272c('0x3b')]);if(_0x4deaac[_0x272c('0x3c')]){delete _0x4deaac[_0x272c('0x3c')];}_0x43136b['status'](_0x5cce6b)[_0x272c('0x3d')](_0x4deaac);};}exports['index']=function(_0x56fc5a,_0x5d0c81){var _0x540d2c={'include':[{'model':db['Pause'],'as':_0x272c('0x3e')}]},_0x4324db={},_0x46f35e={'count':0x0,'rows':[]};var _0x3233e4=_[_0x272c('0x3f')](db[_0x272c('0x40')]['rawAttributes'],function(_0x366ca0){return{'name':_0x366ca0[_0x272c('0x41')],'type':_0x366ca0[_0x272c('0x42')]['key']};});_0x4324db['model']=_[_0x272c('0x3f')](_0x3233e4,_0x272c('0x3c'));_0x4324db[_0x272c('0x43')]=_['keys'](_0x56fc5a[_0x272c('0x43')]);_0x4324db['filters']=_[_0x272c('0x44')](_0x4324db['model'],_0x4324db['query']);_0x540d2c[_0x272c('0x45')]=_[_0x272c('0x44')](_0x4324db[_0x272c('0x46')],qs['fields'](_0x56fc5a[_0x272c('0x43')]['fields']));_0x540d2c[_0x272c('0x45')]=_0x540d2c[_0x272c('0x45')]['length']?_0x540d2c['attributes']:_0x4324db[_0x272c('0x46')];if(!_0x56fc5a[_0x272c('0x43')]['hasOwnProperty'](_0x272c('0x47'))){_0x540d2c[_0x272c('0x33')]=qs[_0x272c('0x33')](_0x56fc5a[_0x272c('0x43')][_0x272c('0x33')]);_0x540d2c[_0x272c('0x32')]=qs[_0x272c('0x32')](_0x56fc5a[_0x272c('0x43')]['offset']);}_0x540d2c[_0x272c('0x48')]=qs[_0x272c('0x49')](_0x56fc5a['query'][_0x272c('0x49')]);_0x540d2c[_0x272c('0x4a')]=qs[_0x272c('0x4b')](_[_0x272c('0x4c')](_0x56fc5a[_0x272c('0x43')],_0x4324db[_0x272c('0x4b')]),_0x3233e4);if(_0x56fc5a[_0x272c('0x43')][_0x272c('0x4d')]){_0x540d2c[_0x272c('0x4a')]=_[_0x272c('0x4e')](_0x540d2c[_0x272c('0x4a')],{'$or':_[_0x272c('0x3f')](_0x3233e4,function(_0x1ec56c){if(_0x1ec56c[_0x272c('0x42')]!==_0x272c('0x4f')){var _0x120c89={};_0x120c89[_0x1ec56c[_0x272c('0x3c')]]={'$like':'%'+_0x56fc5a[_0x272c('0x43')][_0x272c('0x4d')]+'%'};return _0x120c89;}})});}_0x540d2c=_[_0x272c('0x4e')]({},_0x540d2c,_0x56fc5a[_0x272c('0x50')]);var _0x301bcc={'where':_0x540d2c['where']};return db['SmsAccount'][_0x272c('0x31')](_0x301bcc)['then'](function(_0x3cfb11){_0x46f35e[_0x272c('0x31')]=_0x3cfb11;if(_0x56fc5a['query'][_0x272c('0x51')]){_0x540d2c[_0x272c('0x52')]=[{'all':!![]}];}return db[_0x272c('0x40')][_0x272c('0x53')](_0x540d2c);})[_0x272c('0x39')](function(_0x2ba28a){_0x46f35e[_0x272c('0x54')]=_0x2ba28a;return _0x46f35e;})['then'](respondWithFilteredResult(_0x5d0c81,_0x540d2c))['catch'](handleError(_0x5d0c81,null));};exports[_0x272c('0x55')]=function(_0x4ecfb,_0x23a335){var _0x15ed48={'raw':![],'where':{'id':_0x4ecfb[_0x272c('0x56')]['id']},'include':[{'model':db[_0x272c('0x57')],'as':_0x272c('0x3e')}]},_0x33a4cc={};_0x33a4cc[_0x272c('0x46')]=_[_0x272c('0x58')](db[_0x272c('0x40')][_0x272c('0x59')]);_0x33a4cc[_0x272c('0x43')]=_['keys'](_0x4ecfb[_0x272c('0x43')]);_0x33a4cc[_0x272c('0x4b')]=_[_0x272c('0x44')](_0x33a4cc[_0x272c('0x46')],_0x33a4cc['query']);_0x15ed48[_0x272c('0x45')]=_[_0x272c('0x44')](_0x33a4cc[_0x272c('0x46')],qs[_0x272c('0x5a')](_0x4ecfb[_0x272c('0x43')][_0x272c('0x5a')]));_0x15ed48[_0x272c('0x45')]=_0x15ed48[_0x272c('0x45')][_0x272c('0x5b')]?_0x15ed48[_0x272c('0x45')]:_0x33a4cc['model'];if(_0x4ecfb[_0x272c('0x43')][_0x272c('0x51')]){_0x15ed48[_0x272c('0x52')]=[{'all':!![]}];}_0x15ed48=_['merge']({},_0x15ed48,_0x4ecfb['options']);return db[_0x272c('0x40')][_0x272c('0x5c')](_0x15ed48)[_0x272c('0x39')](handleEntityNotFound(_0x23a335,null))[_0x272c('0x39')](respondWithResult(_0x23a335,null))[_0x272c('0x5d')](handleError(_0x23a335,null));};exports['create']=function(_0x4ec06c,_0x1d548f){return db[_0x272c('0x40')][_0x272c('0x5e')](_0x4ec06c['body'],{})['then'](function(_0x139cda){var _0x473a52=_0x4ec06c[_0x272c('0x5f')][_0x272c('0x60')]({'plain':!![]});if(!_0x473a52)throw new Error(_0x272c('0x61'));if(_0x473a52['role']===_0x272c('0x5f')){var _0xb8a65e=_0x139cda[_0x272c('0x60')]({'plain':!![]});var _0x2478f9='SmsAccounts';return db[_0x272c('0x62')][_0x272c('0x5c')]({'where':{'name':_0x2478f9,'userProfileId':_0x473a52['userProfileId']},'raw':!![]})[_0x272c('0x39')](function(_0x220790){if(_0x220790&&_0x220790[_0x272c('0x63')]===0x0){return db[_0x272c('0x64')][_0x272c('0x5e')]({'name':_0xb8a65e[_0x272c('0x3c')],'resourceId':_0xb8a65e['id'],'type':_0x220790[_0x272c('0x3c')],'sectionId':_0x220790['id']},{})[_0x272c('0x39')](function(){return _0x139cda;});}else{return _0x139cda;}})[_0x272c('0x5d')](function(_0xbd5935){logger[_0x272c('0x2a')](_0x272c('0x65'),_0xbd5935);throw _0xbd5935;});}return _0x139cda;})[_0x272c('0x39')](respondWithResult(_0x1d548f,0xc9))[_0x272c('0x5d')](handleError(_0x1d548f,null));};exports[_0x272c('0x66')]=function(_0x5dd8f7,_0x3b8df9){if(_0x5dd8f7['body']['id']){delete _0x5dd8f7[_0x272c('0x67')]['id'];}return db[_0x272c('0x40')][_0x272c('0x5c')]({'where':{'id':_0x5dd8f7['params']['id']},'include':[{'model':db['Pause'],'as':'mandatoryDispositionPause'}]})[_0x272c('0x39')](handleEntityNotFound(_0x3b8df9,null))[_0x272c('0x39')](saveUpdates(_0x5dd8f7[_0x272c('0x67')],null))[_0x272c('0x39')](respondWithResult(_0x3b8df9,null))[_0x272c('0x5d')](handleError(_0x3b8df9,null));};exports[_0x272c('0x38')]=function(_0x53a1f9,_0x48aacf){return db[_0x272c('0x40')]['find']({'where':{'id':_0x53a1f9[_0x272c('0x56')]['id']}})[_0x272c('0x39')](handleEntityNotFound(_0x48aacf,null))[_0x272c('0x39')](removeEntity(_0x48aacf,null))[_0x272c('0x5d')](handleError(_0x48aacf,null));};exports['describe']=function(_0x5afc52,_0x3ddf34){return db[_0x272c('0x40')][_0x272c('0x68')]()[_0x272c('0x39')](respondWithResult(_0x3ddf34,null))[_0x272c('0x5d')](handleError(_0x3ddf34,null));};exports[_0x272c('0x69')]=function(_0x1a1d6b,_0x4c9e88,_0x4a7ed3){if(_0x1a1d6b[_0x272c('0x67')]['id']){delete _0x1a1d6b[_0x272c('0x67')]['id'];}return db[_0x272c('0x40')][_0x272c('0x5c')]({'where':{'id':_0x1a1d6b['params']['id']}})['then'](handleEntityNotFound(_0x4c9e88,null))[_0x272c('0x39')](function(_0x3f8b03){if(_0x3f8b03){_0x1a1d6b[_0x272c('0x67')][_0x272c('0x6a')]=_0x3f8b03['id'];return db[_0x272c('0x6b')][_0x272c('0x5e')](_0x1a1d6b[_0x272c('0x67')]);}})[_0x272c('0x39')](respondWithResult(_0x4c9e88,null))[_0x272c('0x5d')](handleError(_0x4c9e88,null));};exports[_0x272c('0x6c')]=function(_0x4f90e4,_0x24d367,_0x1fd2aa){var _0x185791={'raw':![],'where':{}};var _0x44568b={};var _0x455660={'count':0x0,'rows':[]};return db[_0x272c('0x40')][_0x272c('0x6d')]({'where':{'id':_0x4f90e4[_0x272c('0x56')]['id']}})['then'](handleEntityNotFound(_0x24d367,null))[_0x272c('0x39')](function(_0x32c2e7){if(_0x32c2e7){_0x44568b['model']=_[_0x272c('0x58')](db[_0x272c('0x6b')][_0x272c('0x59')]);_0x44568b[_0x272c('0x43')]=_['keys'](_0x4f90e4['query']);_0x44568b[_0x272c('0x4b')]=_['intersection'](_0x44568b[_0x272c('0x46')],_0x44568b[_0x272c('0x43')]);_0x185791['attributes']=_[_0x272c('0x44')](_0x44568b[_0x272c('0x46')],qs['fields'](_0x4f90e4[_0x272c('0x43')]['fields']));_0x185791[_0x272c('0x45')]=_0x185791[_0x272c('0x45')][_0x272c('0x5b')]?_0x185791[_0x272c('0x45')]:_0x44568b[_0x272c('0x46')];if(!_0x4f90e4['query'][_0x272c('0x6e')](_0x272c('0x47'))){_0x185791[_0x272c('0x33')]=qs[_0x272c('0x33')](_0x4f90e4[_0x272c('0x43')][_0x272c('0x33')]);_0x185791[_0x272c('0x32')]=qs[_0x272c('0x32')](_0x4f90e4[_0x272c('0x43')]['offset']);}_0x185791[_0x272c('0x48')]=qs[_0x272c('0x49')](_0x4f90e4[_0x272c('0x43')]['sort']);_0x185791[_0x272c('0x4a')]=qs[_0x272c('0x4b')](_[_0x272c('0x4c')](_0x4f90e4[_0x272c('0x43')],_0x44568b[_0x272c('0x4b')]));_0x185791[_0x272c('0x4a')][_0x272c('0x6a')]=_0x32c2e7['id'];if(_0x4f90e4[_0x272c('0x43')]['filter']){_0x185791[_0x272c('0x4a')]=_['merge'](_0x185791[_0x272c('0x4a')],{'$or':_[_0x272c('0x3f')](_0x185791['attributes'],function(_0x570c3d){var _0x2a74d9={};_0x2a74d9[_0x570c3d]={'$like':'%'+_0x4f90e4[_0x272c('0x43')][_0x272c('0x4d')]+'%'};return _0x2a74d9;})});}_0x185791=_[_0x272c('0x4e')]({},_0x185791,_0x4f90e4['options']);return db[_0x272c('0x6b')][_0x272c('0x31')]({'where':_0x185791[_0x272c('0x4a')]})[_0x272c('0x39')](function(_0x5a46e7){_0x455660[_0x272c('0x31')]=_0x5a46e7;if(_0x4f90e4[_0x272c('0x43')]['includeAll']){_0x185791[_0x272c('0x52')]=[{'all':!![]}];}return db[_0x272c('0x6b')]['findAll'](_0x185791);})['then'](function(_0x58acd4){_0x455660[_0x272c('0x54')]=_0x58acd4;return _0x455660;});}})[_0x272c('0x39')](respondWithFilteredResult(_0x24d367,_0x185791))[_0x272c('0x5d')](handleError(_0x24d367,null));};exports['removeDispositions']=function(_0x2c5374,_0x58fd89,_0x31c250){return db['SmsAccount']['find']({'where':{'id':_0x2c5374[_0x272c('0x56')]['id']}})[_0x272c('0x39')](handleEntityNotFound(_0x58fd89,null))['then'](function(_0x2be381){if(_0x2be381){return _0x2be381[_0x272c('0x6f')](_0x2c5374[_0x272c('0x43')][_0x272c('0x70')]);}})[_0x272c('0x39')](respondWithStatusCode(_0x58fd89,null))[_0x272c('0x5d')](handleError(_0x58fd89,null));};exports[_0x272c('0x71')]=function(_0x3b0f57,_0x3f300a,_0x24ecdd){if(_0x3b0f57[_0x272c('0x67')]['id']){delete _0x3b0f57[_0x272c('0x67')]['id'];}return db[_0x272c('0x40')][_0x272c('0x5c')]({'where':{'id':_0x3b0f57['params']['id']}})[_0x272c('0x39')](handleEntityNotFound(_0x3f300a,null))[_0x272c('0x39')](function(_0x57e359){if(_0x57e359){_0x3b0f57[_0x272c('0x67')][_0x272c('0x6a')]=_0x57e359['id'];return db[_0x272c('0x72')][_0x272c('0x5e')](_0x3b0f57[_0x272c('0x67')]);}})[_0x272c('0x39')](respondWithResult(_0x3f300a,null))[_0x272c('0x5d')](handleError(_0x3f300a,null));};exports['getAnswers']=function(_0x369a60,_0x46bf68,_0x370c0e){var _0x2f6d00={'raw':![],'where':{}};var _0x439cba={};var _0x21a5d1={'count':0x0,'rows':[]};return db['SmsAccount'][_0x272c('0x6d')]({'where':{'id':_0x369a60[_0x272c('0x56')]['id']}})[_0x272c('0x39')](handleEntityNotFound(_0x46bf68,null))[_0x272c('0x39')](function(_0x313dc6){if(_0x313dc6){_0x439cba[_0x272c('0x46')]=_[_0x272c('0x58')](db[_0x272c('0x72')]['rawAttributes']);_0x439cba[_0x272c('0x43')]=_[_0x272c('0x58')](_0x369a60[_0x272c('0x43')]);_0x439cba[_0x272c('0x4b')]=_['intersection'](_0x439cba[_0x272c('0x46')],_0x439cba['query']);_0x2f6d00[_0x272c('0x45')]=_['intersection'](_0x439cba[_0x272c('0x46')],qs[_0x272c('0x5a')](_0x369a60['query'][_0x272c('0x5a')]));_0x2f6d00[_0x272c('0x45')]=_0x2f6d00[_0x272c('0x45')][_0x272c('0x5b')]?_0x2f6d00[_0x272c('0x45')]:_0x439cba[_0x272c('0x46')];if(!_0x369a60[_0x272c('0x43')][_0x272c('0x6e')](_0x272c('0x47'))){_0x2f6d00[_0x272c('0x33')]=qs[_0x272c('0x33')](_0x369a60[_0x272c('0x43')][_0x272c('0x33')]);_0x2f6d00[_0x272c('0x32')]=qs[_0x272c('0x32')](_0x369a60[_0x272c('0x43')][_0x272c('0x32')]);}_0x2f6d00[_0x272c('0x48')]=qs[_0x272c('0x49')](_0x369a60[_0x272c('0x43')]['sort']);_0x2f6d00[_0x272c('0x4a')]=qs[_0x272c('0x4b')](_[_0x272c('0x4c')](_0x369a60['query'],_0x439cba[_0x272c('0x4b')]));_0x2f6d00['where'][_0x272c('0x6a')]=_0x313dc6['id'];if(_0x369a60[_0x272c('0x43')]['filter']){_0x2f6d00[_0x272c('0x4a')]=_[_0x272c('0x4e')](_0x2f6d00[_0x272c('0x4a')],{'$or':_[_0x272c('0x3f')](_0x2f6d00['attributes'],function(_0x14e523){var _0x49c403={};_0x49c403[_0x14e523]={'$like':'%'+_0x369a60['query'][_0x272c('0x4d')]+'%'};return _0x49c403;})});}_0x2f6d00=_[_0x272c('0x4e')]({},_0x2f6d00,_0x369a60[_0x272c('0x50')]);return db['CannedAnswer'][_0x272c('0x31')]({'where':_0x2f6d00[_0x272c('0x4a')]})[_0x272c('0x39')](function(_0x3c2a65){_0x21a5d1['count']=_0x3c2a65;if(_0x369a60[_0x272c('0x43')][_0x272c('0x51')]){_0x2f6d00['include']=[{'all':!![]}];}return db[_0x272c('0x72')][_0x272c('0x53')](_0x2f6d00);})['then'](function(_0x4afb13){_0x21a5d1[_0x272c('0x54')]=_0x4afb13;return _0x21a5d1;});}})[_0x272c('0x39')](respondWithFilteredResult(_0x46bf68,_0x2f6d00))['catch'](handleError(_0x46bf68,null));};exports['removeAnswers']=function(_0x51b5fb,_0x3ffe31,_0x1b8168){return db['SmsAccount'][_0x272c('0x5c')]({'where':{'id':_0x51b5fb[_0x272c('0x56')]['id']}})['then'](handleEntityNotFound(_0x3ffe31,null))[_0x272c('0x39')](function(_0xc09bb3){if(_0xc09bb3){return _0xc09bb3[_0x272c('0x73')](_0x51b5fb[_0x272c('0x43')][_0x272c('0x70')]);}})['then'](respondWithStatusCode(_0x3ffe31,null))['catch'](handleError(_0x3ffe31,null));};exports[_0x272c('0x74')]=function(_0x5c82a6,_0x174e40,_0x34ca50){var _0x3ca1b2={'channel':_0x272c('0x75')};var _0xa70ba2=[];var _0x1fa0f6=[];var _0x1607d7={};return db['SmsAccount'][_0x272c('0x5c')]({'where':{'id':_0x5c82a6['params']['id']},'include':[{'model':db['SmsApplication'],'as':_0x272c('0x76')}]})['then'](handleEntityNotFound(_0x174e40,null))[_0x272c('0x39')](function(_0x5711b4){_0x3ca1b2[_0x272c('0x77')]=_0x5711b4;_0x3ca1b2[_0x272c('0x78')]=_[_0x272c('0x79')](_0x5711b4[_0x272c('0x76')],[_0x272c('0x7a')],[_0x272c('0x7b')]);if(_0x3ca1b2[_0x272c('0x77')][_0x272c('0x76')]){delete _0x3ca1b2[_0x272c('0x77')][_0x272c('0x76')];}return db[_0x272c('0x7c')]['describe']();})[_0x272c('0x39')](function(_0x35bee9){if(!_0x35bee9){throw new db[(_0x272c('0x7d'))][(_0x272c('0x7e'))]('no\x20available\x20attributes');}_0xa70ba2=_['difference'](_[_0x272c('0x58')](_0x35bee9),[_0x272c('0x7f'),_0x272c('0x80')]);_0x1fa0f6=_['difference'](_[_0x272c('0x58')](_0x35bee9),[_0x272c('0x7f'),'updatedAt','CompanyId','ListId']);_0x3ca1b2[_0x272c('0x67')]={'mapKey':_0x272c('0x81')};if(_0x3ca1b2[_0x272c('0x77')][_0x272c('0x42')]){switch(_0x3ca1b2[_0x272c('0x77')]['type']){case _0x272c('0x82'):_0x3ca1b2[_0x272c('0x67')][_0x272c('0x83')]=_0x5c82a6[_0x272c('0x67')][_0x272c('0x84')];_0x3ca1b2['body'][_0x272c('0x67')]=_0x5c82a6[_0x272c('0x67')][_0x272c('0x85')];_0x3ca1b2[_0x272c('0x67')]['messageId']=_0x5c82a6['body'][_0x272c('0x86')];break;case _0x272c('0x87'):_0x3ca1b2['body'][_0x272c('0x83')]='+'+_0x5c82a6[_0x272c('0x67')][_0x272c('0x88')];_0x3ca1b2[_0x272c('0x67')][_0x272c('0x67')]=_0x5c82a6['body'][_0x272c('0x89')];break;case _0x272c('0x8a'):_0x3ca1b2[_0x272c('0x67')]['from']=_0x5c82a6[_0x272c('0x67')][_0x272c('0x83')];_0x3ca1b2[_0x272c('0x67')][_0x272c('0x67')]=_0x5c82a6[_0x272c('0x67')][_0x272c('0x2b')];break;case'clicksend':_0x3ca1b2['body'][_0x272c('0x83')]=_0x5c82a6[_0x272c('0x67')][_0x272c('0x83')];_0x3ca1b2['body']['body']=_0x5c82a6['body'][_0x272c('0x67')];_0x3ca1b2[_0x272c('0x67')][_0x272c('0x8b')]=_0x5c82a6[_0x272c('0x67')][_0x272c('0x8c')];break;case _0x272c('0x8d'):_0x3ca1b2[_0x272c('0x67')][_0x272c('0x83')]=_0x5c82a6['body'][_0x272c('0x84')];_0x3ca1b2[_0x272c('0x67')][_0x272c('0x67')]=_0x5c82a6[_0x272c('0x67')][_0x272c('0x8e')];_0x3ca1b2[_0x272c('0x67')]['messageId']=_0x5c82a6[_0x272c('0x67')][_0x272c('0x8f')];break;case _0x272c('0x90'):_0x3ca1b2[_0x272c('0x67')][_0x272c('0x83')]='+'+_0x5c82a6[_0x272c('0x67')][_0x272c('0x91')][0x0][_0x272c('0x83')];_0x3ca1b2[_0x272c('0x67')]['body']=_0x5c82a6['body']['results'][0x0][_0x272c('0x89')];_0x3ca1b2[_0x272c('0x67')][_0x272c('0x8b')]=_0x5c82a6['body'][_0x272c('0x91')][0x0][_0x272c('0x8b')];break;case _0x272c('0x92'):_0x3ca1b2[_0x272c('0x67')][_0x272c('0x83')]=_0x5c82a6[_0x272c('0x67')][_0x272c('0x93')];_0x3ca1b2[_0x272c('0x67')][_0x272c('0x67')]=_0x5c82a6[_0x272c('0x67')][_0x272c('0x94')]['message'];break;case _0x272c('0x95'):_0x3ca1b2[_0x272c('0x67')][_0x272c('0x83')]=_0x5c82a6['body'][_0x272c('0x96')];_0x3ca1b2[_0x272c('0x67')][_0x272c('0x67')]=_0x5c82a6['body']['text'];_0x3ca1b2[_0x272c('0x67')]['messageId']=_0x5c82a6[_0x272c('0x67')][_0x272c('0x97')];break;case'bandwidth':_0x3ca1b2[_0x272c('0x67')][_0x272c('0x8b')]=_0x5c82a6[_0x272c('0x67')][0x0]['message']['id'];_0x3ca1b2['body'][_0x272c('0x83')]=_0x5c82a6[_0x272c('0x67')][0x0][_0x272c('0x2b')][_0x272c('0x83')];_0x3ca1b2[_0x272c('0x67')]['body']=_0x5c82a6['body'][0x0][_0x272c('0x2b')]['text'];break;case _0x272c('0x98'):_0x3ca1b2['body']['from']=_0x5c82a6['body'][_0x272c('0x83')];_0x3ca1b2[_0x272c('0x67')][_0x272c('0x67')]=_0x5c82a6[_0x272c('0x67')][_0x272c('0x2b')];_0x3ca1b2[_0x272c('0x67')][_0x272c('0x8b')]=_0x5c82a6[_0x272c('0x67')][_0x272c('0x99')];break;}}if(_0x3ca1b2[_0x272c('0x67')]['id']){delete _0x3ca1b2['body']['id'];}if(_[_0x272c('0x9a')](_0x3ca1b2[_0x272c('0x67')][_0x272c('0x83')])){throw new db['Sequelize'][(_0x272c('0x7e'))]('from\x20is\x20mandatory');}if(_[_0x272c('0x9a')](_0x3ca1b2[_0x272c('0x67')]['body'])||_0x3ca1b2[_0x272c('0x67')][_0x272c('0x67')]===''){throw new db[(_0x272c('0x7d'))][(_0x272c('0x7e'))](_0x272c('0x9b'));}if(_['isNil'](_0x3ca1b2[_0x272c('0x67')][_0x272c('0x9c')])){throw new db[(_0x272c('0x7d'))][(_0x272c('0x7e'))](_0x272c('0x9d')+_0x1fa0f6);}if(!_[_0x272c('0x9e')](_0x1fa0f6,_0x3ca1b2[_0x272c('0x67')]['mapKey'])){throw new db[(_0x272c('0x7d'))][(_0x272c('0x7e'))](_0x272c('0x9f')+_0x1fa0f6);}_0x1607d7[_0x3ca1b2[_0x272c('0x67')]['mapKey']]=_0x3ca1b2[_0x272c('0x67')][_0x272c('0x83')];return db[_0x272c('0xa0')][_0x272c('0x5c')]({'where':{'id':_0x3ca1b2[_0x272c('0x77')]['ListId']},'include':[{'model':db['CmContact'],'as':'Contacts','where':_0x1607d7,'limit':0x1,'order':[[_0x272c('0x80'),_0x272c('0xa1')]]}]});})[_0x272c('0x39')](handleEntityNotFound(_0x174e40,null))['then'](function(_0x21a3b1){if(_0x21a3b1){_0x3ca1b2[_0x272c('0xa2')]=_['omit'](_0x21a3b1,[_0x272c('0xa3')]);if(_0x21a3b1['Contacts'][_0x272c('0x5b')]){return _0x21a3b1[_0x272c('0xa3')][0x0];}var _0xccfb6a=_[_0x272c('0xa4')](_0x3ca1b2[_0x272c('0x67')],{'firstName':_0x3ca1b2[_0x272c('0x67')]['from'],'ListId':_0x21a3b1['id']});_0xccfb6a[_0x3ca1b2['body'][_0x272c('0x9c')]]=_0x3ca1b2[_0x272c('0x67')][_0x272c('0x83')];return db['CmContact'][_0x272c('0x5e')](_0xccfb6a,{'fields':_0xa70ba2,'raw':!![]});}})[_0x272c('0x39')](handleEntityNotFound(_0x174e40,null))['then'](function(_0x32d71d){if(_0x32d71d){_0x3ca1b2[_0x272c('0xa5')]=_0x32d71d;var _0x595b92={'ContactId':_0x32d71d['id'],'phone':_0x3ca1b2[_0x272c('0x67')]['from'],'SmsAccountId':_0x5c82a6[_0x272c('0x56')]['id']};var _0x4660ab={'ContactId':_0x32d71d['id'],'SmsAccountId':_0x5c82a6[_0x272c('0x56')]['id'],'closed':![]};return db[_0x272c('0xa6')]['find']({'where':_0x4660ab})[_0x272c('0x39')](function(_0x255934){if(_0x255934){return[_0x255934,![]];}return db[_0x272c('0xa6')][_0x272c('0x5e')](_0x595b92)[_0x272c('0x39')](function(_0x429861){return[_0x429861,!![]];});});}})[_0x272c('0xa7')](function(_0x4f3dba,_0x80d85c){_0x3ca1b2[_0x272c('0xa8')]=_0x4f3dba[_0x272c('0x60')]({'plain':!![]});_0x3ca1b2[_0x272c('0xa8')][_0x272c('0xa9')]=![];if(_0x80d85c){if(_0x3ca1b2[_0x272c('0x77')][_0x272c('0xaa')]){_0x3ca1b2['applications'][_0x272c('0xab')]({'id':0x0,'priority':_0x3ca1b2[_0x272c('0x78')]['length']+0x1,'app':'close','appdata':_0x272c('0xac'),'interval':_0x272c('0xad')});}_0x3ca1b2[_0x272c('0xa8')][_0x272c('0xa9')]=!![];}return db[_0x272c('0xae')]['create']({'phone':_0x3ca1b2[_0x272c('0x67')]['from'],'messageId':_0x3ca1b2[_0x272c('0x67')][_0x272c('0x8b')],'body':_0x3ca1b2[_0x272c('0x67')][_0x272c('0x67')],'SmsAccountId':_0x5c82a6[_0x272c('0x56')]['id'],'SmsInteractionId':_0x4f3dba['id'],'direction':'in','ContactId':_0x4f3dba['ContactId'],'AttachmentId':_0x3ca1b2[_0x272c('0x67')]['AttachmentId']});})[_0x272c('0x39')](function(_0x200f34){_0x3ca1b2[_0x272c('0x2b')]=_0x200f34;if(_0x3ca1b2[_0x272c('0xa8')][_0x272c('0xaf')]){return db[_0x272c('0xb0')][_0x272c('0x5c')]({'attributes':['id','name'],'where':{'id':_0x3ca1b2[_0x272c('0xa8')]['UserId']}})['then'](function(_0x282c8d){if(_0x282c8d){_0x3ca1b2['applications']['unshift']({'id':0x0,'priority':0x0,'app':_0x272c('0xb1'),'appdata':_0x282c8d[_0x272c('0x3c')]+','+(_0x3ca1b2['account'][_0x272c('0xb2')]||0xa),'interval':_0x272c('0xad')});}return respondWithRpcPromise(_0x272c('0xb3'),_0x272c('0xb4'),_0x3ca1b2);});}return respondWithRpcPromise(_0x272c('0xb3'),'startRouting',_0x3ca1b2);})[_0x272c('0x39')](function(_0x5a26d2){if(_0x5a26d2){var _0x44ea06=0xc8;var _0x45897f=_0x272c('0xb5');logger[_0x272c('0x24')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x45897f,_0x44ea06,_0x272c('0xb6'));logger[_0x272c('0x26')]('SmsAccount,\x20%s,\x20%s,\x20%s,\x20%s',_0x45897f,_0x44ea06,'entity\x20found',JSON[_0x272c('0x29')](_0x5a26d2));if(_0x3ca1b2['account'][_0x272c('0x42')]===_0x272c('0x82')){return _0x174e40[_0x272c('0x2e')](_0x44ea06)[_0x272c('0xb7')](_0x272c('0xb8'),_0x272c('0xb9'))['send']('<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>');}else{return _0x174e40['status'](_0x44ea06)[_0x272c('0x2f')](_0x5a26d2);}}})['catch'](handleError(_0x174e40,null));};exports[_0x272c('0xba')]=function(_0x48e425,_0x575a29){var _0x12bf40=_0x48e425[_0x272c('0x56')]['id'];var _0xb6067=_0x48e425[_0x272c('0x67')];var _0x2573b7=0xc8;var _0xc695e2=null;return db[_0x272c('0xbb')][_0x272c('0xbc')]({'isolationLevel':db[_0x272c('0xbb')][_0x272c('0xbd')][_0x272c('0xbe')][_0x272c('0xbf')]},function(_0x12055c){return db['SmsAccount'][_0x272c('0x6d')]({'where':{'id':_0x12bf40},'transaction':_0x12055c})['then'](function(_0x1d8987){if(_0x1d8987){return db[_0x272c('0xc0')][_0x272c('0x38')]({'where':{'SmsAccountId':_0x12bf40},'transaction':_0x12055c})['then'](function(){var _0x3a1b23=_[_0x272c('0x3f')](_0xb6067,function(_0x5f21f5){_0x5f21f5[_0x272c('0x6a')]=_0x12bf40;return _0x5f21f5;});return db[_0x272c('0xc0')]['bulkCreate'](_0x3a1b23,{'transaction':_0x12055c});});}else{_0x2573b7=0x194;_0xc695e2=[];}});})[_0x272c('0x39')](function(){if(_0x2573b7!==0x194){return db[_0x272c('0xc0')][_0x272c('0xc1')]({'where':{'SmsAccountId':_0x12bf40},'order':_0x272c('0x7a')})[_0x272c('0x39')](function(_0x235339){_0xc695e2=_0x235339;});}})[_0x272c('0x5d')](function(_0x447a60){_0x2573b7=0x1f4;logger[_0x272c('0x2a')](_0x447a60[_0x272c('0x3b')]);if(_0x447a60['name']){delete _0x447a60[_0x272c('0x3c')];}_0xc695e2=_0x447a60;})[_0x272c('0xc2')](function(){if(_0xc695e2===null){_0x575a29[_0x272c('0x2c')](_0x2573b7);}else{if(_0x2573b7===0x1f4){_0x575a29['status'](_0x2573b7)[_0x272c('0x3d')](_0xc695e2);}else{_0x575a29[_0x272c('0x2e')](_0x2573b7)[_0x272c('0x2f')](_0xc695e2);}}});};exports[_0x272c('0xc3')]=function(_0x4151c5,_0x4ab1ad,_0x5be1ab){var _0x2c0702={};var _0xf2399d={};var _0x137144;var _0x513263;return db[_0x272c('0x40')][_0x272c('0x6d')]({'where':{'id':_0x4151c5['params']['id']}})[_0x272c('0x39')](handleEntityNotFound(_0x4ab1ad,null))[_0x272c('0x39')](function(_0x55a03d){if(_0x55a03d){_0x137144=_0x55a03d;_0xf2399d[_0x272c('0x46')]=_[_0x272c('0x58')](db['SmsApplication']['rawAttributes']);_0xf2399d[_0x272c('0x43')]=_[_0x272c('0x58')](_0x4151c5[_0x272c('0x43')]);_0xf2399d['filters']=_['intersection'](_0xf2399d[_0x272c('0x46')],_0xf2399d[_0x272c('0x43')]);_0x2c0702[_0x272c('0x45')]=_[_0x272c('0x44')](_0xf2399d['model'],qs[_0x272c('0x5a')](_0x4151c5[_0x272c('0x43')][_0x272c('0x5a')]));_0x2c0702['attributes']=_0x2c0702['attributes'][_0x272c('0x5b')]?_0x2c0702[_0x272c('0x45')]:_0xf2399d[_0x272c('0x46')];_0x2c0702[_0x272c('0x48')]=qs[_0x272c('0x49')](_0x4151c5[_0x272c('0x43')]['sort']);_0x2c0702[_0x272c('0x4a')]=qs[_0x272c('0x4b')](_[_0x272c('0x4c')](_0x4151c5[_0x272c('0x43')],_0xf2399d[_0x272c('0x4b')]));if(_0x4151c5['query'][_0x272c('0x4d')]){_0x2c0702[_0x272c('0x4a')]=_[_0x272c('0x4e')](_0x2c0702[_0x272c('0x4a')],{'$or':_['map'](_0x2c0702['attributes'],function(_0x3bda88){var _0x34a41f={};_0x34a41f[_0x3bda88]={'$like':'%'+_0x4151c5[_0x272c('0x43')][_0x272c('0x4d')]+'%'};return _0x34a41f;})});}_0x2c0702=_[_0x272c('0x4e')]({},_0x2c0702,_0x4151c5[_0x272c('0x50')]);return _0x137144['getApplications'](_0x2c0702);}})['then'](function(_0x57a8ec){if(_0x57a8ec){_0x513263=_0x57a8ec[_0x272c('0x5b')];if(!_0x4151c5[_0x272c('0x43')]['hasOwnProperty'](_0x272c('0x47'))){_0x2c0702[_0x272c('0x33')]=qs[_0x272c('0x33')](_0x4151c5['query'][_0x272c('0x33')]);_0x2c0702[_0x272c('0x32')]=qs[_0x272c('0x32')](_0x4151c5['query'][_0x272c('0x32')]);}return _0x137144[_0x272c('0xc3')](_0x2c0702);}})['then'](function(_0x2a77e4){if(_0x2a77e4){return _0x2a77e4?{'count':_0x513263,'rows':_0x2a77e4}:null;}})['then'](respondWithResult(_0x4ab1ad,null))[_0x272c('0x5d')](handleError(_0x4ab1ad,null));};exports[_0x272c('0xc4')]=function(_0x1247f2,_0x1aebdb,_0x38928d){var _0x41d2f4={'raw':![],'where':{}};var _0x38d961={};var _0x11be76={'count':0x0,'rows':[]};return db[_0x272c('0x40')][_0x272c('0x6d')]({'where':{'id':_0x1247f2[_0x272c('0x56')]['id']}})[_0x272c('0x39')](handleEntityNotFound(_0x1aebdb,null))[_0x272c('0x39')](function(_0x4a9ac3){if(_0x4a9ac3){_0x38d961[_0x272c('0x46')]=_[_0x272c('0x58')](db[_0x272c('0xa6')][_0x272c('0x59')]);_0x38d961['query']=_[_0x272c('0x58')](_0x1247f2[_0x272c('0x43')]);_0x38d961['filters']=_[_0x272c('0x44')](_0x38d961[_0x272c('0x46')],_0x38d961[_0x272c('0x43')]);_0x41d2f4[_0x272c('0x45')]=_[_0x272c('0x44')](_0x38d961[_0x272c('0x46')],qs[_0x272c('0x5a')](_0x1247f2[_0x272c('0x43')][_0x272c('0x5a')]));_0x41d2f4[_0x272c('0x45')]=_0x41d2f4['attributes']['length']?_0x41d2f4['attributes']:_0x38d961[_0x272c('0x46')];if(!_0x1247f2[_0x272c('0x43')][_0x272c('0x6e')]('nolimit')){_0x41d2f4['limit']=qs[_0x272c('0x33')](_0x1247f2['query'][_0x272c('0x33')]);_0x41d2f4[_0x272c('0x32')]=qs[_0x272c('0x32')](_0x1247f2[_0x272c('0x43')]['offset']);}_0x41d2f4[_0x272c('0x48')]=qs[_0x272c('0x49')](_0x1247f2[_0x272c('0x43')][_0x272c('0x49')]);_0x41d2f4[_0x272c('0x4a')]=qs[_0x272c('0x4b')](_[_0x272c('0x4c')](_0x1247f2[_0x272c('0x43')],_0x38d961['filters']));_0x41d2f4['where']['SmsAccountId']=_0x4a9ac3['id'];if(_0x1247f2[_0x272c('0x43')][_0x272c('0x4d')]){_0x41d2f4[_0x272c('0x4a')]=_[_0x272c('0x4e')](_0x41d2f4[_0x272c('0x4a')],{'$or':_[_0x272c('0x3f')](_0x41d2f4['attributes'],function(_0x1732d6){var _0x18eacd={};_0x18eacd[_0x1732d6]={'$like':'%'+_0x1247f2[_0x272c('0x43')][_0x272c('0x4d')]+'%'};return _0x18eacd;})});}_0x41d2f4=_[_0x272c('0x4e')]({},_0x41d2f4,_0x1247f2[_0x272c('0x50')]);return db[_0x272c('0xa6')][_0x272c('0x31')]({'where':_0x41d2f4[_0x272c('0x4a')]})[_0x272c('0x39')](function(_0x213b0e){_0x11be76[_0x272c('0x31')]=_0x213b0e;if(_0x1247f2[_0x272c('0x43')]['includeAll']){_0x41d2f4[_0x272c('0x52')]=[{'model':db[_0x272c('0x7c')],'as':_0x272c('0xc5'),'required':![]},{'model':db['User'],'as':_0x272c('0xc6'),'attributes':[_0x272c('0x3c'),_0x272c('0xc7'),'internal'],'required':![]},{'model':db[_0x272c('0xc8')],'as':_0x272c('0xc9'),'attributes':['id','name',_0x272c('0xca')],'where':_0x1247f2[_0x272c('0x43')]['tag']?{'id':_0x1247f2['query'][_0x272c('0xcb')]}:undefined,'required':_0x1247f2['query'][_0x272c('0xcb')]?!![]:![]}];}return db[_0x272c('0xa6')][_0x272c('0x53')](_0x41d2f4);})[_0x272c('0x39')](function(_0x59e332){_0x11be76[_0x272c('0x54')]=_0x59e332;return _0x11be76;});}})[_0x272c('0x39')](respondWithFilteredResult(_0x1aebdb,_0x41d2f4))[_0x272c('0x5d')](handleError(_0x1aebdb,null));};exports['send']=function(_0x32c6ed,_0x212b2b,_0x5229a1){var _0x52a472,_0x286dfa,_0x1fcec7;if(_['isNil'](_0x32c6ed[_0x272c('0x67')][_0x272c('0x67')])||_0x32c6ed[_0x272c('0x67')][_0x272c('0x67')]===''){throw new db[(_0x272c('0x7d'))][(_0x272c('0x7e'))](_0x272c('0x9b'));}if(_[_0x272c('0x9a')](_0x32c6ed[_0x272c('0x67')]['to'])){throw new db[(_0x272c('0x7d'))][(_0x272c('0x7e'))](_0x272c('0xcc'));}_0x52a472=_0x32c6ed[_0x272c('0x67')]['to'];return db[_0x272c('0x40')][_0x272c('0x5c')]({'where':{'id':_0x32c6ed[_0x272c('0x56')]['id']},'include':[{'model':db[_0x272c('0xa0')],'as':_0x272c('0xcd'),'include':[{'model':db[_0x272c('0x7c')],'as':'Contacts','where':{'mobile':_0x52a472},'limit':0x1,'order':[[_0x272c('0x80'),_0x272c('0xa1')]]}]}]})['then'](handleEntityNotFound(_0x212b2b,null))[_0x272c('0x39')](function(_0x994199){if(_0x994199&&_0x994199[_0x272c('0xcd')]){_0x286dfa=_0x994199['get']({'plain':!![]});if(_0x286dfa[_0x272c('0xcd')]&&_0x286dfa[_0x272c('0xcd')]['Contacts']['length']){return _0x286dfa[_0x272c('0xcd')][_0x272c('0xa3')][0x0];}return db['CmContact'][_0x272c('0x5e')](_[_0x272c('0xa4')](_0x32c6ed['body'],{'firstName':_0x52a472,'mobile':_0x52a472,'phone':_0x52a472,'ListId':_0x286dfa[_0x272c('0xce')]}));}})[_0x272c('0x39')](handleEntityNotFound(_0x212b2b,null))[_0x272c('0x39')](function(_0x147b53){if(_0x147b53){_0x1fcec7=_0x147b53;return db[_0x272c('0xa6')][_0x272c('0x5c')]({'where':{'ContactId':_0x1fcec7['id'],'closed':![],'SmsAccountId':_0x286dfa['id']}})[_0x272c('0x39')](function(_0x45502e){if(_0x45502e){return[_0x45502e,![]];}return db[_0x272c('0xa6')]['create']({'UserId':_0x32c6ed['user']['id'],'ContactId':_0x1fcec7['id'],'SmsAccountId':_0x286dfa['id'],'phone':_0x52a472,'firstMsgDirection':_0x272c('0xcf'),'Messages':[_[_0x272c('0x4e')](_0x32c6ed[_0x272c('0x67')],{'read':![],'body':_0x32c6ed[_0x272c('0x67')][_0x272c('0x67')],'phone':_0x52a472,'SmsAccountId':_0x286dfa['id'],'UserId':_0x32c6ed[_0x272c('0x5f')]['id'],'ContactId':_0x1fcec7['id']})]},{'include':[{'model':db[_0x272c('0xae')],'as':_0x272c('0xd0')}]})[_0x272c('0x39')](function(_0x45def6){return[_0x45def6,!![]];});});}})[_0x272c('0xa7')](function(_0x185074,_0x17e7b9){if(_0x17e7b9){return _0x185074;}return db[_0x272c('0xae')][_0x272c('0x5e')](_[_0x272c('0x4e')](_0x32c6ed['body'],{'read':![],'body':_0x32c6ed[_0x272c('0x67')]['body'],'phone':_0x52a472,'SmsAccountId':_0x286dfa['id'],'SmsInteractionId':_0x185074['id'],'UserId':_0x32c6ed[_0x272c('0x5f')]['id'],'ContactId':_0x1fcec7['id']}))[_0x272c('0x39')](function(_0x39e683){_0x185074[_0x272c('0xd1')]['Messages']=[];_0x185074[_0x272c('0xd1')][_0x272c('0xd0')][_0x272c('0xab')](_0x39e683[_0x272c('0xd1')]);return _0x185074;});})[_0x272c('0x39')](respondWithResult(_0x212b2b,null))[_0x272c('0x5d')](handleError(_0x212b2b,null));};exports[_0x272c('0x2e')]=function(_0x347027,_0x6d090a,_0x4c544c){if(_0x347027[_0x272c('0x67')]['id']){delete _0x347027[_0x272c('0x67')]['id'];}var _0x3ed2b9,_0x2a9cc4,_0x3b185c;return db['SmsAccount'][_0x272c('0x5c')]({'where':{'id':_0x347027[_0x272c('0x56')]['id']}})[_0x272c('0x39')](handleEntityNotFound(_0x6d090a,null))[_0x272c('0x39')](function(_0x19b932){if(_0x19b932){_0x3b185c=_0x19b932;logger[_0x272c('0x26')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x272c('0x2e'),_0x272c('0xd2'),_0x19b932['type'],util[_0x272c('0xd3')](_0x347027['body'],{'showHidden':![],'depth':null}));switch(_0x19b932[_0x272c('0x42')]){case _0x272c('0x87'):if(_0x347027[_0x272c('0x67')][_0x272c('0xd4')]&&_0x347027['body'][_0x272c('0x2e')]){_0x2a9cc4=_0x347027[_0x272c('0x67')][_0x272c('0x2e')];return db[_0x272c('0xae')][_0x272c('0x5c')]({'where':{'messageId':_0x347027[_0x272c('0x67')][_0x272c('0xd4')]}});}break;case _0x272c('0x8a'):if(_0x347027[_0x272c('0x67')]['requestid']&&_0x347027['body']['statusInt']){_0x2a9cc4=_0x347027[_0x272c('0x67')][_0x272c('0xd5')];return db[_0x272c('0xae')][_0x272c('0x5c')]({'where':{'messageId':_0x347027['body'][_0x272c('0xd6')]}});}break;case _0x272c('0xd7'):if(_0x347027[_0x272c('0x67')][_0x272c('0x8c')]&&_0x347027[_0x272c('0x67')][_0x272c('0xd8')]){_0x2a9cc4=_0x347027[_0x272c('0x67')][_0x272c('0xd8')];return db[_0x272c('0xae')]['find']({'where':{'messageId':_0x347027[_0x272c('0x67')][_0x272c('0x8c')]}});}break;case _0x272c('0x90'):var _0x20921=_0x347027[_0x272c('0x67')]['results'][0x0];if(_0x20921[_0x272c('0x8b')]&&_0x20921[_0x272c('0x2e')]['groupName']===_0x272c('0xd9')){_0x2a9cc4=_0x20921[_0x272c('0x2e')][_0x272c('0xda')];return db[_0x272c('0xae')][_0x272c('0x5c')]({'where':{'messageId':_0x20921[_0x272c('0x8b')]}});}break;case _0x272c('0x95'):if(_0x347027[_0x272c('0x67')][_0x272c('0x8b')]&&_0x347027['body'][_0x272c('0x2e')]){_0x2a9cc4=_0x347027[_0x272c('0x67')][_0x272c('0x2e')];return db[_0x272c('0xae')][_0x272c('0x5c')]({'where':{'messageId':_0x347027[_0x272c('0x67')][_0x272c('0x8b')]}});}break;case _0x272c('0xdb'):if(_0x347027[_0x272c('0x67')][0x0][_0x272c('0x2b')]['id']){_0x2a9cc4=_0x347027[_0x272c('0x67')][0x0][_0x272c('0x42')];return db['SmsMessage'][_0x272c('0x5c')]({'where':{'messageId':_0x347027[_0x272c('0x67')][0x0][_0x272c('0x2b')]['id']}});}break;case'intelepeer':if(_0x347027[_0x272c('0x67')][_0x272c('0xdc')]&&_0x347027[_0x272c('0x67')]['status']){_0x2a9cc4=_0x347027[_0x272c('0x67')][_0x272c('0x2e')];return db['SmsMessage']['find']({'where':{'messageId':_0x347027[_0x272c('0x67')]['redif']}});}break;}}})[_0x272c('0x39')](handleEntityNotFound(_0x6d090a,null))[_0x272c('0x39')](function(_0x179c2c){if(_0x179c2c){_0x3ed2b9=_0x179c2c;switch(_0x3b185c[_0x272c('0x42')]){case _0x272c('0x87'):if(_0x2a9cc4==='DELIVERED'){return _0x3ed2b9[_0x272c('0x66')]({'read':!![]});}else{logger[_0x272c('0x2a')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x272c('0x2e'),_0x272c('0x87'),util[_0x272c('0xd3')](_0x347027['body'],{'showHidden':![],'depth':null}));}break;case _0x272c('0x8a'):if(_0x2a9cc4==='1'){return _0x3ed2b9[_0x272c('0x66')]({'read':!![]});}else{logger[_0x272c('0x2a')](_0x272c('0x27'),_0x272c('0x2e'),_0x272c('0x87'),util[_0x272c('0xd3')](_0x347027[_0x272c('0x67')],{'showHidden':![],'depth':null}));}break;case _0x272c('0xd7'):if(!_0x347027[_0x272c('0x67')]['error_code']&&_0x2a9cc4>=0xc8&&_0x2a9cc4<=0xce){return _0x3ed2b9[_0x272c('0x66')]({'read':!![]});}else{logger[_0x272c('0x2a')](_0x272c('0x27'),'status',_0x272c('0xd7'),util['inspect'](_0x347027[_0x272c('0x67')],{'showHidden':![],'depth':null}));}break;case _0x272c('0x90'):var _0x45394e=_0x347027[_0x272c('0x67')][_0x272c('0x91')][0x0];if(_0x45394e[_0x272c('0x2e')][_0x272c('0xda')]===_0x272c('0xd9')){return _0x3ed2b9[_0x272c('0x66')]({'read':!![]});}else{logger[_0x272c('0x2a')](_0x272c('0x27'),_0x272c('0x2e'),_0x272c('0x90'),util['inspect'](_0x347027[_0x272c('0x67')],{'showHidden':![],'depth':null}));}break;case _0x272c('0x95'):if(_0x2a9cc4==_0x272c('0xdd')||_0x2a9cc4==_0x272c('0xde')){return _0x3ed2b9['update']({'read':!![]});}else{logger[_0x272c('0x2a')](_0x272c('0x27'),_0x272c('0x2e'),_0x272c('0x95'),util[_0x272c('0xd3')](_0x347027['body'],{'showHidden':![],'depth':null}));}break;case _0x272c('0xdb'):if(_0x2a9cc4==_0x272c('0xdf')){return _0x3ed2b9[_0x272c('0x66')]({'read':!![]});}else{logger[_0x272c('0x2a')](_0x272c('0x27'),'status',_0x272c('0xdb'),util[_0x272c('0xd3')](_0x347027['body'],{'showHidden':![],'depth':null}));}break;case _0x272c('0x98'):if(_0x2a9cc4==='DELIVRD'||_0x2a9cc4===_0x272c('0xe0')){return _0x3ed2b9['update']({'read':!![]});}else{logger[_0x272c('0x2a')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x272c('0x2e'),_0x272c('0x98'),util[_0x272c('0xd3')](_0x347027[_0x272c('0x67')],{'showHidden':![],'depth':null}));}break;}return _0x3ed2b9;}})['then'](respondWithResult(_0x6d090a,null))[_0x272c('0x5d')](handleError(_0x6d090a,null));};exports[_0x272c('0xe1')]=function(_0x3661a5,_0x57fe93,_0x4dc126){var _0x3be19e,_0x3683f2,_0x5efbe3;return db['SmsAccount'][_0x272c('0x5c')]({'where':{'id':_0x3661a5['params']['id']}})['then'](handleEntityNotFound(_0x57fe93,null))[_0x272c('0x39')](function(_0x47f783){if(_0x47f783){_0x5efbe3=_0x47f783;logger[_0x272c('0x26')](_0x272c('0x27'),_0x272c('0x2e'),_0x272c('0xd2'),_0x47f783['type'],util[_0x272c('0xd3')](_0x3661a5[_0x272c('0x43')],{'showHidden':![],'depth':null}));switch(_0x47f783[_0x272c('0x42')]){case _0x272c('0x92'):if(_0x3661a5[_0x272c('0x43')]['message-id']&&_0x3661a5[_0x272c('0x43')][_0x272c('0xe2')]){_0x3683f2=_0x3661a5[_0x272c('0x43')][_0x272c('0xe2')];return db['SmsMessage'][_0x272c('0x5c')]({'where':{'messageId':_0x3661a5[_0x272c('0x43')][_0x272c('0xe3')]}});}break;}}})[_0x272c('0x39')](handleEntityNotFound(_0x57fe93,null))[_0x272c('0x39')](function(_0x44cca0){if(_0x44cca0){_0x3be19e=_0x44cca0;switch(_0x5efbe3['type']){case _0x272c('0x92'):if(_0x3683f2==='2'||_0x3683f2==='6'){return _0x3be19e[_0x272c('0x66')]({'read':!![]});}else{logger[_0x272c('0x2a')](_0x272c('0x27'),_0x272c('0x2e'),_0x272c('0x92'),util[_0x272c('0xd3')](_0x3661a5[_0x272c('0x43')],{'showHidden':![],'depth':null}));};break;}return _0x3be19e;}})[_0x272c('0x39')](respondWithResult(_0x57fe93,null))[_0x272c('0x5d')](handleError(_0x57fe93,null));};exports['addAgents']=function(_0x4b3c5c,_0x2244b5,_0x298f1d){return db[_0x272c('0x40')][_0x272c('0x5c')]({'where':{'id':_0x4b3c5c[_0x272c('0x56')]['id']}})[_0x272c('0x39')](handleEntityNotFound(_0x2244b5,null))['then'](function(_0x4fb370){if(_0x4fb370){return _0x4fb370['addAgents'](_0x4b3c5c[_0x272c('0x67')]['ids'],_[_0x272c('0xe4')](_0x4b3c5c[_0x272c('0x67')],[_0x272c('0x70'),'id'])||{})[_0x272c('0xa7')](function(_0x343812){for(var _0x174e0a=0x0;_0x174e0a<_0x4b3c5c[_0x272c('0x67')]['ids'][_0x272c('0x5b')];_0x174e0a+=0x1){socket[_0x272c('0xe5')]('userSmsAccount:save',{'UserId':Number(_0x4b3c5c[_0x272c('0x67')][_0x272c('0x70')][_0x174e0a]),'SmsAccountId':Number(_0x4b3c5c[_0x272c('0x56')]['id'])});}return _0x343812;});}})[_0x272c('0x39')](respondWithResult(_0x2244b5,null))[_0x272c('0x5d')](handleError(_0x2244b5,null));};exports[_0x272c('0xe6')]=function(_0xa4a459,_0x5f51b9,_0x429e7e){return db[_0x272c('0x40')][_0x272c('0x5c')]({'where':{'id':_0xa4a459[_0x272c('0x56')]['id']}})[_0x272c('0x39')](handleEntityNotFound(_0x5f51b9,null))['then'](function(_0x7910b6){if(_0x7910b6){return _0x7910b6[_0x272c('0xe6')](_0xa4a459['query'][_0x272c('0x70')])[_0x272c('0x39')](function(){if(_[_0x272c('0xe7')](_0xa4a459['query'][_0x272c('0x70')])){for(var _0x3d4d03=0x0;_0x3d4d03<_0xa4a459[_0x272c('0x43')][_0x272c('0x70')][_0x272c('0x5b')];_0x3d4d03+=0x1){socket[_0x272c('0xe5')](_0x272c('0xe8'),{'UserId':Number(_0xa4a459[_0x272c('0x43')][_0x272c('0x70')][_0x3d4d03]),'SmsAccountId':Number(_0xa4a459[_0x272c('0x56')]['id'])});}}else{socket['emit'](_0x272c('0xe8'),{'UserId':Number(_0xa4a459['query'][_0x272c('0x70')]),'SmsAccountId':Number(_0xa4a459['params']['id'])});}});}})['then'](respondWithStatusCode(_0x5f51b9,null))['catch'](handleError(_0x5f51b9,null));};exports[_0x272c('0xe9')]=function(_0x429516,_0x475323,_0x4033b1){var _0x47c2a6={};var _0x2b77e3={};var _0x25d5a5;var _0x1359b8;return db[_0x272c('0x40')]['findOne']({'where':{'id':_0x429516['params']['id']}})[_0x272c('0x39')](handleEntityNotFound(_0x475323,null))[_0x272c('0x39')](function(_0x48555b){if(_0x48555b){_0x25d5a5=_0x48555b;_0x2b77e3[_0x272c('0x46')]=_[_0x272c('0x58')](db['User'][_0x272c('0x59')]);_0x2b77e3['query']=_[_0x272c('0x58')](_0x429516[_0x272c('0x43')]);_0x2b77e3['filters']=_[_0x272c('0x44')](_0x2b77e3[_0x272c('0x46')],_0x2b77e3[_0x272c('0x43')]);_0x47c2a6[_0x272c('0x45')]=_[_0x272c('0x44')](_0x2b77e3[_0x272c('0x46')],qs[_0x272c('0x5a')](_0x429516[_0x272c('0x43')][_0x272c('0x5a')]));_0x47c2a6[_0x272c('0x45')]=_0x47c2a6[_0x272c('0x45')]['length']?_0x47c2a6[_0x272c('0x45')]:_0x2b77e3[_0x272c('0x46')];_0x47c2a6['order']=qs[_0x272c('0x49')](_0x429516[_0x272c('0x43')][_0x272c('0x49')]);_0x47c2a6['where']=qs[_0x272c('0x4b')](_[_0x272c('0x4c')](_0x429516[_0x272c('0x43')],_0x2b77e3[_0x272c('0x4b')]));if(_0x429516[_0x272c('0x43')]['filter']){_0x47c2a6['where']=_['merge'](_0x47c2a6[_0x272c('0x4a')],{'$or':_['map'](_0x47c2a6[_0x272c('0x45')],function(_0x1911fa){var _0x59faa8={};_0x59faa8[_0x1911fa]={'$like':'%'+_0x429516[_0x272c('0x43')][_0x272c('0x4d')]+'%'};return _0x59faa8;})});}_0x47c2a6=_['merge']({},_0x47c2a6,_0x429516[_0x272c('0x50')]);return _0x25d5a5[_0x272c('0xe9')](_0x47c2a6);}})[_0x272c('0x39')](function(_0x319642){if(_0x319642){_0x1359b8=_0x319642[_0x272c('0x5b')];if(!_0x429516[_0x272c('0x43')]['hasOwnProperty'](_0x272c('0x47'))){_0x47c2a6['limit']=qs['limit'](_0x429516[_0x272c('0x43')][_0x272c('0x33')]);_0x47c2a6[_0x272c('0x32')]=qs[_0x272c('0x32')](_0x429516['query'][_0x272c('0x32')]);}return _0x25d5a5[_0x272c('0xe9')](_0x47c2a6);}})[_0x272c('0x39')](function(_0x219906){if(_0x219906){return _0x219906?{'count':_0x1359b8,'rows':_0x219906}:null;}})['then'](respondWithResult(_0x475323,null))[_0x272c('0x5d')](handleError(_0x475323,null));};
\ No newline at end of file