Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / server / api / smsAccount / smsAccount.controller.js
index 53bf926..49b005a 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x43fb=['zip-dir','fast-json-patch','bluebird','mustache','to-csv','ejs','lodash','squel','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','api','../../config/utils','../../config/environment','../../config/license/util','redis','defaults','localhost','socket.io-emitter','jayson/promise','request','then','SmsAccount,\x20%s,\x20%s','request\x20sent','SmsAccount,\x20%s,\x20%s,\x20%s','error','code','message','info','result','catch','sendStatus','status','count','offset','Content-Range','apply','save','update','destroy','get','SmsAccounts','UserProfileResource','end','stack','name','send','index','Pause','mandatoryDispositionPause','SmsAccount','rawAttributes','type','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','limit','order','sort','where','pick','filter','merge','map','options','includeAll','include','findAll','rows','show','params','create','Unable\x20to\x20retrieve\x20the\x20current\x20user','find','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','describe','SmsAccountId','getDispositions','Disposition','removeDispositions','ids','addAnswer','getAnswers','CannedAnswer','nolimit','removeAnswers','notify','sms','SmsApplication','Applications','account','applications','orderBy','priority','CmContact','Sequelize','ValidationError','difference','createdAt','updatedAt','ListId','Body','messageId','skebby','from','sender','text','clicksend','message_id','plivo','Text','infobip','results','originatingAddress','segmentedMessage','clickatell','fromNumber','replyMessageId','bandwidth','intelepeer','refid','isNil','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','Contacts','DESC','list','omit','contact','SmsInteraction','spread','interaction','created','push','close','unmanaged','SmsMessage','ContactId','UserId','User','unshift','agent','waitForTheAssignedAgent','Start','startRouting','receiveMessage','entity\x20found','debug','SmsAccount,\x20%s,\x20%s,\x20%s,\x20%s','twilio','set','text/xml','<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>','json','addApplications','sequelize','bulkCreate','getApplications','findOne','getInteractions','Contact','fullname','Tag','Tags','color','tag','List','user','out','Messages','dataValues','received\x20delivery\x20report\x20from','inspect','skebby_dispatch_id','connectel','requestid','statusInt','status_code','DELIVERED','groupName','redif','error_code','RECEIVED_BY_RECIPIENT','message-delivered','DELIVRD','ACCEPTD','statusGet','csc','state','message-id','emit','userSmsAccount:save','removeAgents','userSmsAccount:remove','getAgents','eml-format','rimraf'];(function(_0x119d25,_0x588c8){var _0x39cf30=function(_0x31c68c){while(--_0x31c68c){_0x119d25['push'](_0x119d25['shift']());}};_0x39cf30(++_0x588c8);}(_0x43fb,0xd2));var _0xb43f=function(_0xcf338e,_0x565cec){_0xcf338e=_0xcf338e-0x0;var _0x311485=_0x43fb[_0xcf338e];return _0x311485;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xb43f('0x0'));var rimraf=require(_0xb43f('0x1'));var zipdir=require(_0xb43f('0x2'));var jsonpatch=require(_0xb43f('0x3'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0xb43f('0x4'));var Mustache=require(_0xb43f('0x5'));var util=require('util');var path=require('path');var sox=require('sox');var csv=require(_0xb43f('0x6'));var ejs=require(_0xb43f('0x7'));var fs=require('fs');var _=require(_0xb43f('0x8'));var squel=require(_0xb43f('0x9'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0xb43f('0xa'));var toCsv=require(_0xb43f('0x6'));var querystring=require('querystring');var Papa=require(_0xb43f('0xb'));var Redis=require(_0xb43f('0xc'));var authService=require(_0xb43f('0xd'));var qs=require(_0xb43f('0xe'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0xb43f('0xf'));var utils=require(_0xb43f('0x10'));var config=require(_0xb43f('0x11'));var licenseUtil=require(_0xb43f('0x12'));var db=require('../../mysqldb')['db'];config[_0xb43f('0x13')]=_[_0xb43f('0x14')](config['redis'],{'host':_0xb43f('0x15'),'port':0x18eb});var socket=require(_0xb43f('0x16'))(new Redis(config['redis']));require('./smsAccount.socket')['register'](socket);var jayson=require(_0xb43f('0x17'));var client=jayson['client']['http']({'port':0x232c});function respondWithRpcPromise(_0xeec392,_0x4b2627,_0x411a9c,_0x59b411){return new BPromise(function(_0x2ae449,_0x369d0d){var _0x5f3672=_0x59b411||client;return _0x5f3672[_0xb43f('0x18')](_0xeec392,_0x411a9c)[_0xb43f('0x19')](function(_0x15756a){logger['info'](_0xb43f('0x1a'),_0x4b2627,_0xb43f('0x1b'));logger['debug'](_0xb43f('0x1c'),_0x4b2627,_0xb43f('0x1b'),JSON['stringify'](_0x15756a));if(_0x15756a[_0xb43f('0x1d')]){if(_0x15756a[_0xb43f('0x1d')][_0xb43f('0x1e')]===0x1f4){logger['error'](_0xb43f('0x1a'),_0x4b2627,_0x15756a['error'][_0xb43f('0x1f')]);return _0x369d0d(_0x15756a['error'][_0xb43f('0x1f')]);}logger[_0xb43f('0x1d')](_0xb43f('0x1a'),_0x4b2627,_0x15756a[_0xb43f('0x1d')][_0xb43f('0x1f')]);return _0x2ae449(_0x15756a[_0xb43f('0x1d')][_0xb43f('0x1f')]);}else{logger[_0xb43f('0x20')](_0xb43f('0x1a'),_0x4b2627,_0xb43f('0x1b'));_0x2ae449(_0x15756a[_0xb43f('0x21')][_0xb43f('0x1f')]);}})[_0xb43f('0x22')](function(_0x187e50){logger[_0xb43f('0x1d')](_0xb43f('0x1a'),_0x4b2627,_0x187e50);_0x369d0d(_0x187e50);});});}function respondWithStatusCode(_0x1739d9,_0x45a577){_0x45a577=_0x45a577||0xcc;return function(_0x234037){if(_0x234037){return _0x1739d9[_0xb43f('0x23')](_0x45a577);}return _0x1739d9[_0xb43f('0x24')](_0x45a577)['end']();};}function respondWithResult(_0xa7c0b3,_0x584b8c){_0x584b8c=_0x584b8c||0xc8;return function(_0x1c087a){if(_0x1c087a){return _0xa7c0b3[_0xb43f('0x24')](_0x584b8c)['json'](_0x1c087a);}};}function respondWithFilteredResult(_0x29081b,_0x2db57c){return function(_0x4e66de){if(_0x4e66de){var _0x4bba50=_0x4e66de[_0xb43f('0x25')],_0xcf9535=_0x2db57c['offset'],_0x10cbff=_0x2db57c[_0xb43f('0x26')]+_0x2db57c['limit'],_0xa36399;if(_0x10cbff>=_0x4bba50){_0x10cbff=_0x4bba50;_0xa36399=0xc8;}else{_0xa36399=0xce;}_0x29081b[_0xb43f('0x24')](_0xa36399);return _0x29081b['set'](_0xb43f('0x27'),_0xcf9535+'-'+_0x10cbff+'/'+_0x4bba50)['json'](_0x4e66de);}return null;};}function patchUpdates(_0x5d5a15){return function(_0x122104){try{jsonpatch[_0xb43f('0x28')](_0x122104,_0x5d5a15,!![]);}catch(_0x301ef1){return BPromise['reject'](_0x301ef1);}return _0x122104[_0xb43f('0x29')]();};}function saveUpdates(_0x36d44f,_0x236f1c){return function(_0x2b8a09){if(_0x2b8a09){return _0x2b8a09[_0xb43f('0x2a')](_0x36d44f)[_0xb43f('0x19')](function(_0x4b7d20){return _0x4b7d20;});}return null;};}function removeEntity(_0x5866c5,_0x5692ea){return function(_0x663cf1){if(_0x663cf1){return _0x663cf1[_0xb43f('0x2b')]()['then'](function(){var _0x51a377=_0x663cf1[_0xb43f('0x2c')]({'plain':!![]});var _0x21b019=_0xb43f('0x2d');return db[_0xb43f('0x2e')]['destroy']({'where':{'type':_0x21b019,'resourceId':_0x51a377['id']}})['then'](function(){return _0x663cf1;});})['then'](function(){_0x5866c5['status'](0xcc)[_0xb43f('0x2f')]();});}};}function handleEntityNotFound(_0x2c4420,_0x24fc7e){return function(_0x259eba){if(!_0x259eba){_0x2c4420[_0xb43f('0x23')](0x194);}return _0x259eba;};}function handleError(_0x3dc063,_0x189cbb){_0x189cbb=_0x189cbb||0x1f4;return function(_0x5c8c4f){logger[_0xb43f('0x1d')](_0x5c8c4f[_0xb43f('0x30')]);if(_0x5c8c4f['name']){delete _0x5c8c4f[_0xb43f('0x31')];}_0x3dc063[_0xb43f('0x24')](_0x189cbb)[_0xb43f('0x32')](_0x5c8c4f);};}exports[_0xb43f('0x33')]=function(_0xff881a,_0x225228){var _0x155687={'include':[{'model':db[_0xb43f('0x34')],'as':_0xb43f('0x35')}]},_0x54c148={},_0x4e0404={'count':0x0,'rows':[]};var _0x445974=_['map'](db[_0xb43f('0x36')][_0xb43f('0x37')],function(_0x37257d){return{'name':_0x37257d['fieldName'],'type':_0x37257d[_0xb43f('0x38')]['key']};});_0x54c148[_0xb43f('0x39')]=_['map'](_0x445974,_0xb43f('0x31'));_0x54c148[_0xb43f('0x3a')]=_[_0xb43f('0x3b')](_0xff881a[_0xb43f('0x3a')]);_0x54c148[_0xb43f('0x3c')]=_[_0xb43f('0x3d')](_0x54c148[_0xb43f('0x39')],_0x54c148[_0xb43f('0x3a')]);_0x155687[_0xb43f('0x3e')]=_['intersection'](_0x54c148[_0xb43f('0x39')],qs[_0xb43f('0x3f')](_0xff881a[_0xb43f('0x3a')][_0xb43f('0x3f')]));_0x155687[_0xb43f('0x3e')]=_0x155687[_0xb43f('0x3e')][_0xb43f('0x40')]?_0x155687[_0xb43f('0x3e')]:_0x54c148['model'];if(!_0xff881a[_0xb43f('0x3a')][_0xb43f('0x41')]('nolimit')){_0x155687['limit']=qs['limit'](_0xff881a['query'][_0xb43f('0x42')]);_0x155687[_0xb43f('0x26')]=qs[_0xb43f('0x26')](_0xff881a[_0xb43f('0x3a')][_0xb43f('0x26')]);}_0x155687[_0xb43f('0x43')]=qs[_0xb43f('0x44')](_0xff881a['query'][_0xb43f('0x44')]);_0x155687[_0xb43f('0x45')]=qs[_0xb43f('0x3c')](_[_0xb43f('0x46')](_0xff881a['query'],_0x54c148[_0xb43f('0x3c')]),_0x445974);if(_0xff881a[_0xb43f('0x3a')][_0xb43f('0x47')]){_0x155687[_0xb43f('0x45')]=_[_0xb43f('0x48')](_0x155687[_0xb43f('0x45')],{'$or':_[_0xb43f('0x49')](_0x445974,function(_0x507420){if(_0x507420[_0xb43f('0x38')]!=='VIRTUAL'){var _0x585ace={};_0x585ace[_0x507420['name']]={'$like':'%'+_0xff881a[_0xb43f('0x3a')][_0xb43f('0x47')]+'%'};return _0x585ace;}})});}_0x155687=_[_0xb43f('0x48')]({},_0x155687,_0xff881a[_0xb43f('0x4a')]);var _0x17c66f={'where':_0x155687[_0xb43f('0x45')]};return db['SmsAccount']['count'](_0x17c66f)[_0xb43f('0x19')](function(_0xcfbb79){_0x4e0404[_0xb43f('0x25')]=_0xcfbb79;if(_0xff881a[_0xb43f('0x3a')][_0xb43f('0x4b')]){_0x155687[_0xb43f('0x4c')]=[{'all':!![]}];}return db[_0xb43f('0x36')][_0xb43f('0x4d')](_0x155687);})[_0xb43f('0x19')](function(_0x3e7380){_0x4e0404[_0xb43f('0x4e')]=_0x3e7380;return _0x4e0404;})[_0xb43f('0x19')](respondWithFilteredResult(_0x225228,_0x155687))[_0xb43f('0x22')](handleError(_0x225228,null));};exports[_0xb43f('0x4f')]=function(_0x3d5f8e,_0x3a7325){var _0x1bc313={'raw':![],'where':{'id':_0x3d5f8e[_0xb43f('0x50')]['id']},'include':[{'model':db[_0xb43f('0x34')],'as':_0xb43f('0x35')}]},_0x56fb77={};_0x56fb77[_0xb43f('0x39')]=_[_0xb43f('0x3b')](db[_0xb43f('0x36')]['rawAttributes']);_0x56fb77[_0xb43f('0x3a')]=_['keys'](_0x3d5f8e['query']);_0x56fb77[_0xb43f('0x3c')]=_[_0xb43f('0x3d')](_0x56fb77[_0xb43f('0x39')],_0x56fb77[_0xb43f('0x3a')]);_0x1bc313[_0xb43f('0x3e')]=_[_0xb43f('0x3d')](_0x56fb77['model'],qs[_0xb43f('0x3f')](_0x3d5f8e[_0xb43f('0x3a')][_0xb43f('0x3f')]));_0x1bc313['attributes']=_0x1bc313['attributes'][_0xb43f('0x40')]?_0x1bc313['attributes']:_0x56fb77['model'];if(_0x3d5f8e[_0xb43f('0x3a')][_0xb43f('0x4b')]){_0x1bc313['include']=[{'all':!![]}];}_0x1bc313=_[_0xb43f('0x48')]({},_0x1bc313,_0x3d5f8e[_0xb43f('0x4a')]);return db['SmsAccount']['find'](_0x1bc313)[_0xb43f('0x19')](handleEntityNotFound(_0x3a7325,null))[_0xb43f('0x19')](respondWithResult(_0x3a7325,null))['catch'](handleError(_0x3a7325,null));};exports['create']=function(_0x2a8548,_0x4f6ab4){return db[_0xb43f('0x36')][_0xb43f('0x51')](_0x2a8548['body'],{})[_0xb43f('0x19')](function(_0x3d3fe4){var _0x4b770a=_0x2a8548['user'][_0xb43f('0x2c')]({'plain':!![]});if(!_0x4b770a)throw new Error(_0xb43f('0x52'));if(_0x4b770a['role']==='user'){var _0x6257bb=_0x3d3fe4[_0xb43f('0x2c')]({'plain':!![]});var _0x20732e=_0xb43f('0x2d');return db['UserProfileSection'][_0xb43f('0x53')]({'where':{'name':_0x20732e,'userProfileId':_0x4b770a[_0xb43f('0x54')]},'raw':!![]})[_0xb43f('0x19')](function(_0x43992d){if(_0x43992d&&_0x43992d[_0xb43f('0x55')]===0x0){return db[_0xb43f('0x2e')]['create']({'name':_0x6257bb[_0xb43f('0x31')],'resourceId':_0x6257bb['id'],'type':_0x43992d[_0xb43f('0x31')],'sectionId':_0x43992d['id']},{})[_0xb43f('0x19')](function(){return _0x3d3fe4;});}else{return _0x3d3fe4;}})[_0xb43f('0x22')](function(_0x3d71c3){logger[_0xb43f('0x1d')](_0xb43f('0x56'),_0x3d71c3);throw _0x3d71c3;});}return _0x3d3fe4;})[_0xb43f('0x19')](respondWithResult(_0x4f6ab4,0xc9))[_0xb43f('0x22')](handleError(_0x4f6ab4,null));};exports[_0xb43f('0x2a')]=function(_0x2907bb,_0xc1535a){if(_0x2907bb[_0xb43f('0x57')]['id']){delete _0x2907bb['body']['id'];}return db[_0xb43f('0x36')][_0xb43f('0x53')]({'where':{'id':_0x2907bb[_0xb43f('0x50')]['id']},'include':[{'model':db[_0xb43f('0x34')],'as':_0xb43f('0x35')}]})['then'](handleEntityNotFound(_0xc1535a,null))[_0xb43f('0x19')](saveUpdates(_0x2907bb[_0xb43f('0x57')],null))[_0xb43f('0x19')](respondWithResult(_0xc1535a,null))['catch'](handleError(_0xc1535a,null));};exports[_0xb43f('0x2b')]=function(_0x39324a,_0x2460a2){return db[_0xb43f('0x36')]['find']({'where':{'id':_0x39324a[_0xb43f('0x50')]['id']}})[_0xb43f('0x19')](handleEntityNotFound(_0x2460a2,null))[_0xb43f('0x19')](removeEntity(_0x2460a2,null))[_0xb43f('0x22')](handleError(_0x2460a2,null));};exports[_0xb43f('0x58')]=function(_0x46a10f,_0x1e9253){return db[_0xb43f('0x36')][_0xb43f('0x58')]()[_0xb43f('0x19')](respondWithResult(_0x1e9253,null))[_0xb43f('0x22')](handleError(_0x1e9253,null));};exports['addDisposition']=function(_0x5221a8,_0xb34370,_0x236faf){if(_0x5221a8['body']['id']){delete _0x5221a8[_0xb43f('0x57')]['id'];}return db[_0xb43f('0x36')][_0xb43f('0x53')]({'where':{'id':_0x5221a8[_0xb43f('0x50')]['id']}})[_0xb43f('0x19')](handleEntityNotFound(_0xb34370,null))[_0xb43f('0x19')](function(_0x32f74e){if(_0x32f74e){_0x5221a8[_0xb43f('0x57')][_0xb43f('0x59')]=_0x32f74e['id'];return db['Disposition']['create'](_0x5221a8[_0xb43f('0x57')]);}})[_0xb43f('0x19')](respondWithResult(_0xb34370,null))[_0xb43f('0x22')](handleError(_0xb34370,null));};exports[_0xb43f('0x5a')]=function(_0x4dc0f9,_0x550a8a,_0x69d307){var _0x26a6bb={'raw':![],'where':{}};var _0x3518dc={};var _0x1fdb89={'count':0x0,'rows':[]};return db[_0xb43f('0x36')]['findOne']({'where':{'id':_0x4dc0f9[_0xb43f('0x50')]['id']}})[_0xb43f('0x19')](handleEntityNotFound(_0x550a8a,null))['then'](function(_0x323428){if(_0x323428){_0x3518dc[_0xb43f('0x39')]=_[_0xb43f('0x3b')](db[_0xb43f('0x5b')]['rawAttributes']);_0x3518dc[_0xb43f('0x3a')]=_[_0xb43f('0x3b')](_0x4dc0f9[_0xb43f('0x3a')]);_0x3518dc[_0xb43f('0x3c')]=_[_0xb43f('0x3d')](_0x3518dc[_0xb43f('0x39')],_0x3518dc[_0xb43f('0x3a')]);_0x26a6bb['attributes']=_[_0xb43f('0x3d')](_0x3518dc[_0xb43f('0x39')],qs[_0xb43f('0x3f')](_0x4dc0f9[_0xb43f('0x3a')][_0xb43f('0x3f')]));_0x26a6bb['attributes']=_0x26a6bb[_0xb43f('0x3e')]['length']?_0x26a6bb[_0xb43f('0x3e')]:_0x3518dc[_0xb43f('0x39')];if(!_0x4dc0f9[_0xb43f('0x3a')][_0xb43f('0x41')]('nolimit')){_0x26a6bb[_0xb43f('0x42')]=qs['limit'](_0x4dc0f9[_0xb43f('0x3a')][_0xb43f('0x42')]);_0x26a6bb['offset']=qs[_0xb43f('0x26')](_0x4dc0f9[_0xb43f('0x3a')][_0xb43f('0x26')]);}_0x26a6bb[_0xb43f('0x43')]=qs[_0xb43f('0x44')](_0x4dc0f9[_0xb43f('0x3a')]['sort']);_0x26a6bb[_0xb43f('0x45')]=qs[_0xb43f('0x3c')](_['pick'](_0x4dc0f9[_0xb43f('0x3a')],_0x3518dc[_0xb43f('0x3c')]));_0x26a6bb[_0xb43f('0x45')][_0xb43f('0x59')]=_0x323428['id'];if(_0x4dc0f9['query']['filter']){_0x26a6bb[_0xb43f('0x45')]=_[_0xb43f('0x48')](_0x26a6bb[_0xb43f('0x45')],{'$or':_[_0xb43f('0x49')](_0x26a6bb[_0xb43f('0x3e')],function(_0x29164c){var _0x4c2c08={};_0x4c2c08[_0x29164c]={'$like':'%'+_0x4dc0f9[_0xb43f('0x3a')][_0xb43f('0x47')]+'%'};return _0x4c2c08;})});}_0x26a6bb=_[_0xb43f('0x48')]({},_0x26a6bb,_0x4dc0f9['options']);return db[_0xb43f('0x5b')][_0xb43f('0x25')]({'where':_0x26a6bb['where']})['then'](function(_0x32ec80){_0x1fdb89['count']=_0x32ec80;if(_0x4dc0f9[_0xb43f('0x3a')]['includeAll']){_0x26a6bb[_0xb43f('0x4c')]=[{'all':!![]}];}return db['Disposition']['findAll'](_0x26a6bb);})['then'](function(_0x216cd0){_0x1fdb89[_0xb43f('0x4e')]=_0x216cd0;return _0x1fdb89;});}})[_0xb43f('0x19')](respondWithFilteredResult(_0x550a8a,_0x26a6bb))[_0xb43f('0x22')](handleError(_0x550a8a,null));};exports[_0xb43f('0x5c')]=function(_0x56edb6,_0x31c486,_0x3187e0){return db['SmsAccount'][_0xb43f('0x53')]({'where':{'id':_0x56edb6[_0xb43f('0x50')]['id']}})[_0xb43f('0x19')](handleEntityNotFound(_0x31c486,null))['then'](function(_0x36f10c){if(_0x36f10c){return _0x36f10c[_0xb43f('0x5c')](_0x56edb6['query'][_0xb43f('0x5d')]);}})[_0xb43f('0x19')](respondWithStatusCode(_0x31c486,null))[_0xb43f('0x22')](handleError(_0x31c486,null));};exports[_0xb43f('0x5e')]=function(_0x192e86,_0x26e9a9,_0x19475f){if(_0x192e86[_0xb43f('0x57')]['id']){delete _0x192e86[_0xb43f('0x57')]['id'];}return db['SmsAccount'][_0xb43f('0x53')]({'where':{'id':_0x192e86[_0xb43f('0x50')]['id']}})[_0xb43f('0x19')](handleEntityNotFound(_0x26e9a9,null))['then'](function(_0x51d3b9){if(_0x51d3b9){_0x192e86[_0xb43f('0x57')][_0xb43f('0x59')]=_0x51d3b9['id'];return db['CannedAnswer'][_0xb43f('0x51')](_0x192e86[_0xb43f('0x57')]);}})[_0xb43f('0x19')](respondWithResult(_0x26e9a9,null))[_0xb43f('0x22')](handleError(_0x26e9a9,null));};exports[_0xb43f('0x5f')]=function(_0x49b505,_0x3c6b23,_0x495d83){var _0x6a508={'raw':![],'where':{}};var _0x58a05c={};var _0x411cfe={'count':0x0,'rows':[]};return db['SmsAccount']['findOne']({'where':{'id':_0x49b505[_0xb43f('0x50')]['id']}})[_0xb43f('0x19')](handleEntityNotFound(_0x3c6b23,null))[_0xb43f('0x19')](function(_0x22ee8a){if(_0x22ee8a){_0x58a05c[_0xb43f('0x39')]=_['keys'](db[_0xb43f('0x60')][_0xb43f('0x37')]);_0x58a05c[_0xb43f('0x3a')]=_[_0xb43f('0x3b')](_0x49b505[_0xb43f('0x3a')]);_0x58a05c['filters']=_[_0xb43f('0x3d')](_0x58a05c['model'],_0x58a05c['query']);_0x6a508[_0xb43f('0x3e')]=_[_0xb43f('0x3d')](_0x58a05c[_0xb43f('0x39')],qs[_0xb43f('0x3f')](_0x49b505[_0xb43f('0x3a')][_0xb43f('0x3f')]));_0x6a508[_0xb43f('0x3e')]=_0x6a508['attributes'][_0xb43f('0x40')]?_0x6a508[_0xb43f('0x3e')]:_0x58a05c[_0xb43f('0x39')];if(!_0x49b505[_0xb43f('0x3a')][_0xb43f('0x41')](_0xb43f('0x61'))){_0x6a508[_0xb43f('0x42')]=qs[_0xb43f('0x42')](_0x49b505[_0xb43f('0x3a')]['limit']);_0x6a508['offset']=qs[_0xb43f('0x26')](_0x49b505[_0xb43f('0x3a')]['offset']);}_0x6a508[_0xb43f('0x43')]=qs['sort'](_0x49b505[_0xb43f('0x3a')][_0xb43f('0x44')]);_0x6a508[_0xb43f('0x45')]=qs[_0xb43f('0x3c')](_[_0xb43f('0x46')](_0x49b505[_0xb43f('0x3a')],_0x58a05c[_0xb43f('0x3c')]));_0x6a508[_0xb43f('0x45')]['SmsAccountId']=_0x22ee8a['id'];if(_0x49b505[_0xb43f('0x3a')][_0xb43f('0x47')]){_0x6a508[_0xb43f('0x45')]=_['merge'](_0x6a508[_0xb43f('0x45')],{'$or':_[_0xb43f('0x49')](_0x6a508[_0xb43f('0x3e')],function(_0x19e4f1){var _0x19f7a3={};_0x19f7a3[_0x19e4f1]={'$like':'%'+_0x49b505[_0xb43f('0x3a')][_0xb43f('0x47')]+'%'};return _0x19f7a3;})});}_0x6a508=_[_0xb43f('0x48')]({},_0x6a508,_0x49b505[_0xb43f('0x4a')]);return db['CannedAnswer']['count']({'where':_0x6a508[_0xb43f('0x45')]})[_0xb43f('0x19')](function(_0x3fd4b1){_0x411cfe['count']=_0x3fd4b1;if(_0x49b505[_0xb43f('0x3a')][_0xb43f('0x4b')]){_0x6a508[_0xb43f('0x4c')]=[{'all':!![]}];}return db[_0xb43f('0x60')][_0xb43f('0x4d')](_0x6a508);})[_0xb43f('0x19')](function(_0x3d7cf5){_0x411cfe[_0xb43f('0x4e')]=_0x3d7cf5;return _0x411cfe;});}})[_0xb43f('0x19')](respondWithFilteredResult(_0x3c6b23,_0x6a508))[_0xb43f('0x22')](handleError(_0x3c6b23,null));};exports[_0xb43f('0x62')]=function(_0x4d08f9,_0x3acd5a,_0x18d83b){return db[_0xb43f('0x36')][_0xb43f('0x53')]({'where':{'id':_0x4d08f9[_0xb43f('0x50')]['id']}})['then'](handleEntityNotFound(_0x3acd5a,null))[_0xb43f('0x19')](function(_0x16eb7d){if(_0x16eb7d){return _0x16eb7d['removeAnswers'](_0x4d08f9['query'][_0xb43f('0x5d')]);}})[_0xb43f('0x19')](respondWithStatusCode(_0x3acd5a,null))[_0xb43f('0x22')](handleError(_0x3acd5a,null));};exports[_0xb43f('0x63')]=function(_0x3ed5f6,_0x31317d,_0x3cc176){var _0x353ca5={'channel':_0xb43f('0x64')};var _0x5b8533=[];var _0x40bbc4=[];var _0x341392={};return db[_0xb43f('0x36')]['find']({'where':{'id':_0x3ed5f6[_0xb43f('0x50')]['id']},'include':[{'model':db[_0xb43f('0x65')],'as':_0xb43f('0x66')}]})[_0xb43f('0x19')](handleEntityNotFound(_0x31317d,null))[_0xb43f('0x19')](function(_0x5c2022){_0x353ca5[_0xb43f('0x67')]=_0x5c2022;_0x353ca5[_0xb43f('0x68')]=_[_0xb43f('0x69')](_0x5c2022[_0xb43f('0x66')],[_0xb43f('0x6a')],['asc']);if(_0x353ca5[_0xb43f('0x67')][_0xb43f('0x66')]){delete _0x353ca5[_0xb43f('0x67')][_0xb43f('0x66')];}return db[_0xb43f('0x6b')][_0xb43f('0x58')]();})[_0xb43f('0x19')](function(_0x4c6385){if(!_0x4c6385){throw new db[(_0xb43f('0x6c'))][(_0xb43f('0x6d'))]('no\x20available\x20attributes');}_0x5b8533=_[_0xb43f('0x6e')](_['keys'](_0x4c6385),[_0xb43f('0x6f'),'updatedAt']);_0x40bbc4=_[_0xb43f('0x6e')](_['keys'](_0x4c6385),[_0xb43f('0x6f'),_0xb43f('0x70'),'CompanyId',_0xb43f('0x71')]);_0x353ca5[_0xb43f('0x57')]={'mapKey':'mobile'};if(_0x353ca5[_0xb43f('0x67')][_0xb43f('0x38')]){switch(_0x353ca5['account'][_0xb43f('0x38')]){case'twilio':_0x353ca5[_0xb43f('0x57')]['from']=_0x3ed5f6[_0xb43f('0x57')]['From'];_0x353ca5[_0xb43f('0x57')][_0xb43f('0x57')]=_0x3ed5f6[_0xb43f('0x57')][_0xb43f('0x72')];_0x353ca5['body'][_0xb43f('0x73')]=_0x3ed5f6[_0xb43f('0x57')]['MessageSid'];break;case _0xb43f('0x74'):_0x353ca5[_0xb43f('0x57')][_0xb43f('0x75')]='+'+_0x3ed5f6[_0xb43f('0x57')][_0xb43f('0x76')];_0x353ca5[_0xb43f('0x57')][_0xb43f('0x57')]=_0x3ed5f6[_0xb43f('0x57')][_0xb43f('0x77')];break;case'connectel':_0x353ca5[_0xb43f('0x57')][_0xb43f('0x75')]=_0x3ed5f6[_0xb43f('0x57')][_0xb43f('0x75')];_0x353ca5['body'][_0xb43f('0x57')]=_0x3ed5f6[_0xb43f('0x57')][_0xb43f('0x1f')];break;case _0xb43f('0x78'):_0x353ca5[_0xb43f('0x57')][_0xb43f('0x75')]=_0x3ed5f6['body'][_0xb43f('0x75')];_0x353ca5[_0xb43f('0x57')][_0xb43f('0x57')]=_0x3ed5f6[_0xb43f('0x57')][_0xb43f('0x57')];_0x353ca5[_0xb43f('0x57')][_0xb43f('0x73')]=_0x3ed5f6[_0xb43f('0x57')][_0xb43f('0x79')];break;case _0xb43f('0x7a'):_0x353ca5[_0xb43f('0x57')][_0xb43f('0x75')]=_0x3ed5f6['body']['From'];_0x353ca5[_0xb43f('0x57')][_0xb43f('0x57')]=_0x3ed5f6[_0xb43f('0x57')][_0xb43f('0x7b')];_0x353ca5[_0xb43f('0x57')]['messageId']=_0x3ed5f6[_0xb43f('0x57')]['MessageUUID'];break;case _0xb43f('0x7c'):_0x353ca5['body'][_0xb43f('0x75')]='+'+_0x3ed5f6[_0xb43f('0x57')][_0xb43f('0x7d')][0x0][_0xb43f('0x75')];_0x353ca5[_0xb43f('0x57')][_0xb43f('0x57')]=_0x3ed5f6[_0xb43f('0x57')][_0xb43f('0x7d')][0x0][_0xb43f('0x77')];_0x353ca5[_0xb43f('0x57')][_0xb43f('0x73')]=_0x3ed5f6[_0xb43f('0x57')][_0xb43f('0x7d')][0x0][_0xb43f('0x73')];break;case'csc':_0x353ca5[_0xb43f('0x57')][_0xb43f('0x75')]=_0x3ed5f6[_0xb43f('0x57')][_0xb43f('0x7e')];_0x353ca5['body'][_0xb43f('0x57')]=_0x3ed5f6[_0xb43f('0x57')][_0xb43f('0x7f')]['message'];break;case _0xb43f('0x80'):_0x353ca5[_0xb43f('0x57')][_0xb43f('0x75')]=_0x3ed5f6[_0xb43f('0x57')][_0xb43f('0x81')];_0x353ca5['body'][_0xb43f('0x57')]=_0x3ed5f6[_0xb43f('0x57')][_0xb43f('0x77')];_0x353ca5[_0xb43f('0x57')][_0xb43f('0x73')]=_0x3ed5f6['body'][_0xb43f('0x82')];break;case _0xb43f('0x83'):_0x353ca5[_0xb43f('0x57')][_0xb43f('0x73')]=_0x3ed5f6['body'][0x0][_0xb43f('0x1f')]['id'];_0x353ca5['body']['from']=_0x3ed5f6[_0xb43f('0x57')][0x0][_0xb43f('0x1f')][_0xb43f('0x75')];_0x353ca5[_0xb43f('0x57')][_0xb43f('0x57')]=_0x3ed5f6['body'][0x0][_0xb43f('0x1f')][_0xb43f('0x77')];break;case _0xb43f('0x84'):_0x353ca5['body'][_0xb43f('0x75')]=_0x3ed5f6[_0xb43f('0x57')]['from'];_0x353ca5[_0xb43f('0x57')][_0xb43f('0x57')]=_0x3ed5f6[_0xb43f('0x57')][_0xb43f('0x1f')];_0x353ca5[_0xb43f('0x57')][_0xb43f('0x73')]=_0x3ed5f6[_0xb43f('0x57')][_0xb43f('0x85')];break;}}if(_0x353ca5[_0xb43f('0x57')]['id']){delete _0x353ca5[_0xb43f('0x57')]['id'];}if(_[_0xb43f('0x86')](_0x353ca5[_0xb43f('0x57')][_0xb43f('0x75')])){throw new db['Sequelize']['ValidationError'](_0xb43f('0x87'));}if(_[_0xb43f('0x86')](_0x353ca5[_0xb43f('0x57')][_0xb43f('0x57')])||_0x353ca5[_0xb43f('0x57')]['body']===''){throw new db[(_0xb43f('0x6c'))][(_0xb43f('0x6d'))](_0xb43f('0x88'));}if(_[_0xb43f('0x86')](_0x353ca5['body'][_0xb43f('0x89')])){throw new db[(_0xb43f('0x6c'))][(_0xb43f('0x6d'))](_0xb43f('0x8a')+_0x40bbc4);}if(!_['includes'](_0x40bbc4,_0x353ca5[_0xb43f('0x57')][_0xb43f('0x89')])){throw new db[(_0xb43f('0x6c'))][(_0xb43f('0x6d'))](_0xb43f('0x8b')+_0x40bbc4);}_0x341392[_0x353ca5[_0xb43f('0x57')][_0xb43f('0x89')]]=_0x353ca5['body'][_0xb43f('0x75')];return db[_0xb43f('0x8c')][_0xb43f('0x53')]({'where':{'id':_0x353ca5[_0xb43f('0x67')][_0xb43f('0x71')]},'include':[{'model':db[_0xb43f('0x6b')],'as':_0xb43f('0x8d'),'where':_0x341392,'limit':0x1,'order':[['updatedAt',_0xb43f('0x8e')]]}]});})[_0xb43f('0x19')](handleEntityNotFound(_0x31317d,null))[_0xb43f('0x19')](function(_0x443bc4){if(_0x443bc4){_0x353ca5[_0xb43f('0x8f')]=_[_0xb43f('0x90')](_0x443bc4,[_0xb43f('0x8d')]);if(_0x443bc4['Contacts'][_0xb43f('0x40')]){return _0x443bc4['Contacts'][0x0];}var _0x167f3d=_['defaults'](_0x353ca5[_0xb43f('0x57')],{'firstName':_0x353ca5[_0xb43f('0x57')]['from'],'ListId':_0x443bc4['id']});_0x167f3d[_0x353ca5[_0xb43f('0x57')]['mapKey']]=_0x353ca5[_0xb43f('0x57')][_0xb43f('0x75')];return db[_0xb43f('0x6b')][_0xb43f('0x51')](_0x167f3d,{'fields':_0x5b8533,'raw':!![]});}})['then'](handleEntityNotFound(_0x31317d,null))[_0xb43f('0x19')](function(_0x5a3a4e){if(_0x5a3a4e){_0x353ca5[_0xb43f('0x91')]=_0x5a3a4e;var _0x3e6fb7={'ContactId':_0x5a3a4e['id'],'phone':_0x353ca5['body'][_0xb43f('0x75')],'SmsAccountId':_0x3ed5f6[_0xb43f('0x50')]['id']};var _0x51efef={'ContactId':_0x5a3a4e['id'],'SmsAccountId':_0x3ed5f6[_0xb43f('0x50')]['id'],'closed':![]};return db[_0xb43f('0x92')]['find']({'where':_0x51efef})[_0xb43f('0x19')](function(_0x2d84ae){if(_0x2d84ae){return[_0x2d84ae,![]];}return db['SmsInteraction']['create'](_0x3e6fb7)[_0xb43f('0x19')](function(_0x338bd7){return[_0x338bd7,!![]];});});}})[_0xb43f('0x93')](function(_0x3d3fdd,_0x34af0c){_0x353ca5[_0xb43f('0x94')]=_0x3d3fdd[_0xb43f('0x2c')]({'plain':!![]});_0x353ca5[_0xb43f('0x94')][_0xb43f('0x95')]=![];if(_0x34af0c){if(_0x353ca5[_0xb43f('0x67')]['autoclose']){_0x353ca5[_0xb43f('0x68')][_0xb43f('0x96')]({'id':0x0,'priority':_0x353ca5[_0xb43f('0x68')][_0xb43f('0x40')]+0x1,'app':_0xb43f('0x97'),'appdata':_0xb43f('0x98'),'interval':'*,*,*,*'});}_0x353ca5[_0xb43f('0x94')][_0xb43f('0x95')]=!![];}return db[_0xb43f('0x99')][_0xb43f('0x51')]({'phone':_0x353ca5[_0xb43f('0x57')][_0xb43f('0x75')],'messageId':_0x353ca5[_0xb43f('0x57')]['messageId'],'body':_0x353ca5['body'][_0xb43f('0x57')],'SmsAccountId':_0x3ed5f6[_0xb43f('0x50')]['id'],'SmsInteractionId':_0x3d3fdd['id'],'direction':'in','ContactId':_0x3d3fdd[_0xb43f('0x9a')],'AttachmentId':_0x353ca5[_0xb43f('0x57')]['AttachmentId']});})[_0xb43f('0x19')](function(_0x2016c2){_0x353ca5['message']=_0x2016c2;if(_0x353ca5[_0xb43f('0x94')][_0xb43f('0x9b')]){return db[_0xb43f('0x9c')]['find']({'attributes':['id','name'],'where':{'id':_0x353ca5[_0xb43f('0x94')]['UserId']}})[_0xb43f('0x19')](function(_0x1d9e09){if(_0x1d9e09){_0x353ca5[_0xb43f('0x68')][_0xb43f('0x9d')]({'id':0x0,'priority':0x0,'app':_0xb43f('0x9e'),'appdata':_0x1d9e09[_0xb43f('0x31')]+','+(_0x353ca5['account'][_0xb43f('0x9f')]||0xa),'interval':'*,*,*,*'});}return respondWithRpcPromise(_0xb43f('0xa0'),_0xb43f('0xa1'),_0x353ca5);});}return respondWithRpcPromise(_0xb43f('0xa0'),'startRouting',_0x353ca5);})[_0xb43f('0x19')](function(_0x21729f){if(_0x21729f){var _0x3d399c=0xc8;var _0x1a61ea=_0xb43f('0xa2');logger[_0xb43f('0x20')](_0xb43f('0x1c'),_0x1a61ea,_0x3d399c,_0xb43f('0xa3'));logger[_0xb43f('0xa4')](_0xb43f('0xa5'),_0x1a61ea,_0x3d399c,_0xb43f('0xa3'),JSON['stringify'](_0x21729f));if(_0x353ca5[_0xb43f('0x67')][_0xb43f('0x38')]===_0xb43f('0xa6')){return _0x31317d[_0xb43f('0x24')](_0x3d399c)[_0xb43f('0xa7')]('Content-Type',_0xb43f('0xa8'))[_0xb43f('0x32')](_0xb43f('0xa9'));}else{return _0x31317d['status'](_0x3d399c)[_0xb43f('0xaa')](_0x21729f);}}})['catch'](handleError(_0x31317d,null));};exports[_0xb43f('0xab')]=function(_0x142db5,_0x25e44f,_0x23cdf7){return db[_0xb43f('0x36')]['findOne']({'where':{'id':_0x142db5[_0xb43f('0x50')]['id']}})[_0xb43f('0x19')](handleEntityNotFound(_0x25e44f,null))[_0xb43f('0x19')](function(_0x1677c5){if(_0x1677c5){return db[_0xb43f('0xac')]['transaction'](function(_0x3d1a37){return db[_0xb43f('0x65')]['destroy']({'where':{'SmsAccountId':_0x142db5[_0xb43f('0x50')]['id']},'transaction':_0x3d1a37})[_0xb43f('0x19')](function(_0x3258d2){var _0x2a4f53=_['map'](_0x142db5[_0xb43f('0x57')],function(_0x2f29b9){_0x2f29b9[_0xb43f('0x59')]=_0x142db5[_0xb43f('0x50')]['id'];return _0x2f29b9;});return db[_0xb43f('0x65')][_0xb43f('0xad')](_0x2a4f53,{'transaction':_0x3d1a37});});})[_0xb43f('0x19')](function(){return db[_0xb43f('0x65')]['findAndCountAll']({'where':{'SmsAccountId':_0x142db5[_0xb43f('0x50')]['id']},'order':'priority'});});}})[_0xb43f('0x19')](respondWithResult(_0x25e44f,null))[_0xb43f('0x22')](handleError(_0x25e44f,null));};exports[_0xb43f('0xae')]=function(_0x1db5c7,_0x52c305,_0x5b8cd2){var _0x5c24a7={};var _0x4b9304={};var _0x44c8cd;var _0x55a4ff;return db[_0xb43f('0x36')][_0xb43f('0xaf')]({'where':{'id':_0x1db5c7[_0xb43f('0x50')]['id']}})['then'](handleEntityNotFound(_0x52c305,null))[_0xb43f('0x19')](function(_0x238529){if(_0x238529){_0x44c8cd=_0x238529;_0x4b9304['model']=_['keys'](db[_0xb43f('0x65')][_0xb43f('0x37')]);_0x4b9304[_0xb43f('0x3a')]=_[_0xb43f('0x3b')](_0x1db5c7[_0xb43f('0x3a')]);_0x4b9304[_0xb43f('0x3c')]=_[_0xb43f('0x3d')](_0x4b9304['model'],_0x4b9304[_0xb43f('0x3a')]);_0x5c24a7[_0xb43f('0x3e')]=_[_0xb43f('0x3d')](_0x4b9304[_0xb43f('0x39')],qs['fields'](_0x1db5c7[_0xb43f('0x3a')][_0xb43f('0x3f')]));_0x5c24a7[_0xb43f('0x3e')]=_0x5c24a7[_0xb43f('0x3e')]['length']?_0x5c24a7[_0xb43f('0x3e')]:_0x4b9304[_0xb43f('0x39')];_0x5c24a7[_0xb43f('0x43')]=qs[_0xb43f('0x44')](_0x1db5c7[_0xb43f('0x3a')]['sort']);_0x5c24a7[_0xb43f('0x45')]=qs[_0xb43f('0x3c')](_['pick'](_0x1db5c7[_0xb43f('0x3a')],_0x4b9304[_0xb43f('0x3c')]));if(_0x1db5c7[_0xb43f('0x3a')]['filter']){_0x5c24a7[_0xb43f('0x45')]=_['merge'](_0x5c24a7[_0xb43f('0x45')],{'$or':_[_0xb43f('0x49')](_0x5c24a7[_0xb43f('0x3e')],function(_0x1d2775){var _0x4ac3b8={};_0x4ac3b8[_0x1d2775]={'$like':'%'+_0x1db5c7['query'][_0xb43f('0x47')]+'%'};return _0x4ac3b8;})});}_0x5c24a7=_[_0xb43f('0x48')]({},_0x5c24a7,_0x1db5c7[_0xb43f('0x4a')]);return _0x44c8cd[_0xb43f('0xae')](_0x5c24a7);}})['then'](function(_0x24bcf0){if(_0x24bcf0){_0x55a4ff=_0x24bcf0[_0xb43f('0x40')];if(!_0x1db5c7['query'][_0xb43f('0x41')](_0xb43f('0x61'))){_0x5c24a7[_0xb43f('0x42')]=qs['limit'](_0x1db5c7[_0xb43f('0x3a')][_0xb43f('0x42')]);_0x5c24a7[_0xb43f('0x26')]=qs['offset'](_0x1db5c7[_0xb43f('0x3a')]['offset']);}return _0x44c8cd[_0xb43f('0xae')](_0x5c24a7);}})['then'](function(_0x220c99){if(_0x220c99){return _0x220c99?{'count':_0x55a4ff,'rows':_0x220c99}:null;}})[_0xb43f('0x19')](respondWithResult(_0x52c305,null))[_0xb43f('0x22')](handleError(_0x52c305,null));};exports[_0xb43f('0xb0')]=function(_0x4ca7ac,_0xab41d0,_0xf3867){var _0x4f0ce3={'raw':![],'where':{}};var _0x588f13={};var _0x9d0cc9={'count':0x0,'rows':[]};return db['SmsAccount']['findOne']({'where':{'id':_0x4ca7ac['params']['id']}})[_0xb43f('0x19')](handleEntityNotFound(_0xab41d0,null))[_0xb43f('0x19')](function(_0x34fe25){if(_0x34fe25){_0x588f13['model']=_[_0xb43f('0x3b')](db[_0xb43f('0x92')][_0xb43f('0x37')]);_0x588f13[_0xb43f('0x3a')]=_[_0xb43f('0x3b')](_0x4ca7ac['query']);_0x588f13[_0xb43f('0x3c')]=_['intersection'](_0x588f13[_0xb43f('0x39')],_0x588f13[_0xb43f('0x3a')]);_0x4f0ce3[_0xb43f('0x3e')]=_['intersection'](_0x588f13['model'],qs[_0xb43f('0x3f')](_0x4ca7ac[_0xb43f('0x3a')][_0xb43f('0x3f')]));_0x4f0ce3[_0xb43f('0x3e')]=_0x4f0ce3['attributes']['length']?_0x4f0ce3[_0xb43f('0x3e')]:_0x588f13['model'];if(!_0x4ca7ac['query'][_0xb43f('0x41')](_0xb43f('0x61'))){_0x4f0ce3[_0xb43f('0x42')]=qs[_0xb43f('0x42')](_0x4ca7ac[_0xb43f('0x3a')]['limit']);_0x4f0ce3[_0xb43f('0x26')]=qs['offset'](_0x4ca7ac['query'][_0xb43f('0x26')]);}_0x4f0ce3[_0xb43f('0x43')]=qs[_0xb43f('0x44')](_0x4ca7ac[_0xb43f('0x3a')][_0xb43f('0x44')]);_0x4f0ce3[_0xb43f('0x45')]=qs[_0xb43f('0x3c')](_[_0xb43f('0x46')](_0x4ca7ac[_0xb43f('0x3a')],_0x588f13[_0xb43f('0x3c')]));_0x4f0ce3[_0xb43f('0x45')][_0xb43f('0x59')]=_0x34fe25['id'];if(_0x4ca7ac['query'][_0xb43f('0x47')]){_0x4f0ce3[_0xb43f('0x45')]=_['merge'](_0x4f0ce3[_0xb43f('0x45')],{'$or':_['map'](_0x4f0ce3['attributes'],function(_0x4b775e){var _0x50acc5={};_0x50acc5[_0x4b775e]={'$like':'%'+_0x4ca7ac[_0xb43f('0x3a')][_0xb43f('0x47')]+'%'};return _0x50acc5;})});}_0x4f0ce3=_[_0xb43f('0x48')]({},_0x4f0ce3,_0x4ca7ac[_0xb43f('0x4a')]);return db[_0xb43f('0x92')][_0xb43f('0x25')]({'where':_0x4f0ce3[_0xb43f('0x45')]})[_0xb43f('0x19')](function(_0x4e58f0){_0x9d0cc9[_0xb43f('0x25')]=_0x4e58f0;if(_0x4ca7ac[_0xb43f('0x3a')]['includeAll']){_0x4f0ce3[_0xb43f('0x4c')]=[{'model':db[_0xb43f('0x6b')],'as':_0xb43f('0xb1'),'required':![]},{'model':db[_0xb43f('0x9c')],'as':'Owner','attributes':[_0xb43f('0x31'),_0xb43f('0xb2'),'internal'],'required':![]},{'model':db[_0xb43f('0xb3')],'as':_0xb43f('0xb4'),'attributes':['id',_0xb43f('0x31'),_0xb43f('0xb5')],'where':_0x4ca7ac[_0xb43f('0x3a')][_0xb43f('0xb6')]?{'id':_0x4ca7ac[_0xb43f('0x3a')][_0xb43f('0xb6')]}:undefined,'required':_0x4ca7ac[_0xb43f('0x3a')][_0xb43f('0xb6')]?!![]:![]}];}return db[_0xb43f('0x92')][_0xb43f('0x4d')](_0x4f0ce3);})[_0xb43f('0x19')](function(_0xa5c5ca){_0x9d0cc9[_0xb43f('0x4e')]=_0xa5c5ca;return _0x9d0cc9;});}})[_0xb43f('0x19')](respondWithFilteredResult(_0xab41d0,_0x4f0ce3))[_0xb43f('0x22')](handleError(_0xab41d0,null));};exports[_0xb43f('0x32')]=function(_0x539955,_0x189e7d,_0x18cf85){var _0xd059f0,_0x10c125,_0x23f787;if(_[_0xb43f('0x86')](_0x539955[_0xb43f('0x57')]['body'])||_0x539955[_0xb43f('0x57')]['body']===''){throw new db[(_0xb43f('0x6c'))][(_0xb43f('0x6d'))](_0xb43f('0x88'));}if(_[_0xb43f('0x86')](_0x539955[_0xb43f('0x57')]['to'])){throw new db['Sequelize'][(_0xb43f('0x6d'))]('to\x20is\x20mandatory');}_0xd059f0=_0x539955[_0xb43f('0x57')]['to'];return db[_0xb43f('0x36')][_0xb43f('0x53')]({'where':{'id':_0x539955['params']['id']},'include':[{'model':db[_0xb43f('0x8c')],'as':_0xb43f('0xb7'),'include':[{'model':db['CmContact'],'as':_0xb43f('0x8d'),'where':{'mobile':_0xd059f0},'limit':0x1,'order':[[_0xb43f('0x70'),_0xb43f('0x8e')]]}]}]})[_0xb43f('0x19')](handleEntityNotFound(_0x189e7d,null))[_0xb43f('0x19')](function(_0x11d46b){if(_0x11d46b&&_0x11d46b[_0xb43f('0xb7')]){_0x10c125=_0x11d46b[_0xb43f('0x2c')]({'plain':!![]});if(_0x10c125[_0xb43f('0xb7')]&&_0x10c125[_0xb43f('0xb7')][_0xb43f('0x8d')][_0xb43f('0x40')]){return _0x10c125[_0xb43f('0xb7')][_0xb43f('0x8d')][0x0];}return db[_0xb43f('0x6b')][_0xb43f('0x51')](_[_0xb43f('0x14')](_0x539955['body'],{'firstName':_0xd059f0,'mobile':_0xd059f0,'phone':_0xd059f0,'ListId':_0x10c125['ListId']}));}})[_0xb43f('0x19')](handleEntityNotFound(_0x189e7d,null))[_0xb43f('0x19')](function(_0x57448e){if(_0x57448e){_0x23f787=_0x57448e;return db[_0xb43f('0x92')][_0xb43f('0x53')]({'where':{'ContactId':_0x23f787['id'],'closed':![],'SmsAccountId':_0x10c125['id']}})[_0xb43f('0x19')](function(_0x54f99e){if(_0x54f99e){return[_0x54f99e,![]];}return db['SmsInteraction'][_0xb43f('0x51')]({'UserId':_0x539955[_0xb43f('0xb8')]['id'],'ContactId':_0x23f787['id'],'SmsAccountId':_0x10c125['id'],'phone':_0xd059f0,'firstMsgDirection':_0xb43f('0xb9'),'Messages':[_[_0xb43f('0x48')](_0x539955[_0xb43f('0x57')],{'read':![],'body':_0x539955['body']['body'],'phone':_0xd059f0,'SmsAccountId':_0x10c125['id'],'UserId':_0x539955['user']['id'],'ContactId':_0x23f787['id']})]},{'include':[{'model':db[_0xb43f('0x99')],'as':_0xb43f('0xba')}]})[_0xb43f('0x19')](function(_0x36acb8){return[_0x36acb8,!![]];});});}})[_0xb43f('0x93')](function(_0x3b3d59,_0x4ca5a9){if(_0x4ca5a9){return _0x3b3d59;}return db[_0xb43f('0x99')][_0xb43f('0x51')](_[_0xb43f('0x48')](_0x539955[_0xb43f('0x57')],{'read':![],'body':_0x539955[_0xb43f('0x57')]['body'],'phone':_0xd059f0,'SmsAccountId':_0x10c125['id'],'SmsInteractionId':_0x3b3d59['id'],'UserId':_0x539955[_0xb43f('0xb8')]['id'],'ContactId':_0x23f787['id']}))[_0xb43f('0x19')](function(_0x51b57a){_0x3b3d59[_0xb43f('0xbb')][_0xb43f('0xba')]=[];_0x3b3d59[_0xb43f('0xbb')]['Messages'][_0xb43f('0x96')](_0x51b57a[_0xb43f('0xbb')]);return _0x3b3d59;});})[_0xb43f('0x19')](respondWithResult(_0x189e7d,null))['catch'](handleError(_0x189e7d,null));};exports['status']=function(_0x39cb8c,_0x34e4d5,_0x39f29e){if(_0x39cb8c['body']['id']){delete _0x39cb8c[_0xb43f('0x57')]['id'];}var _0x3c0e11,_0x10882a,_0x13000f;return db[_0xb43f('0x36')][_0xb43f('0x53')]({'where':{'id':_0x39cb8c[_0xb43f('0x50')]['id']}})['then'](handleEntityNotFound(_0x34e4d5,null))[_0xb43f('0x19')](function(_0x19b407){if(_0x19b407){_0x13000f=_0x19b407;logger[_0xb43f('0xa4')](_0xb43f('0x1c'),_0xb43f('0x24'),_0xb43f('0xbc'),_0x19b407[_0xb43f('0x38')],util[_0xb43f('0xbd')](_0x39cb8c[_0xb43f('0x57')],{'showHidden':![],'depth':null}));switch(_0x19b407['type']){case _0xb43f('0x74'):if(_0x39cb8c['body'][_0xb43f('0xbe')]&&_0x39cb8c[_0xb43f('0x57')][_0xb43f('0x24')]){_0x10882a=_0x39cb8c[_0xb43f('0x57')][_0xb43f('0x24')];return db[_0xb43f('0x99')][_0xb43f('0x53')]({'where':{'messageId':_0x39cb8c['body']['skebby_dispatch_id']}});}break;case _0xb43f('0xbf'):if(_0x39cb8c['body'][_0xb43f('0xc0')]&&_0x39cb8c[_0xb43f('0x57')]['statusInt']){_0x10882a=_0x39cb8c[_0xb43f('0x57')][_0xb43f('0xc1')];return db[_0xb43f('0x99')][_0xb43f('0x53')]({'where':{'messageId':_0x39cb8c[_0xb43f('0x57')][_0xb43f('0xc0')]}});}break;case _0xb43f('0x78'):if(_0x39cb8c['body'][_0xb43f('0x79')]&&_0x39cb8c[_0xb43f('0x57')][_0xb43f('0xc2')]){_0x10882a=_0x39cb8c[_0xb43f('0x57')][_0xb43f('0xc2')];return db['SmsMessage'][_0xb43f('0x53')]({'where':{'messageId':_0x39cb8c[_0xb43f('0x57')][_0xb43f('0x79')]}});}break;case _0xb43f('0x7c'):var _0x3aef38=_0x39cb8c[_0xb43f('0x57')][_0xb43f('0x7d')][0x0];if(_0x3aef38[_0xb43f('0x73')]&&_0x3aef38[_0xb43f('0x24')]['groupName']===_0xb43f('0xc3')){_0x10882a=_0x3aef38['status'][_0xb43f('0xc4')];return db[_0xb43f('0x99')][_0xb43f('0x53')]({'where':{'messageId':_0x3aef38[_0xb43f('0x73')]}});}break;case _0xb43f('0x80'):if(_0x39cb8c[_0xb43f('0x57')][_0xb43f('0x73')]&&_0x39cb8c['body'][_0xb43f('0x24')]){_0x10882a=_0x39cb8c[_0xb43f('0x57')][_0xb43f('0x24')];return db['SmsMessage'][_0xb43f('0x53')]({'where':{'messageId':_0x39cb8c[_0xb43f('0x57')][_0xb43f('0x73')]}});}break;case'bandwidth':if(_0x39cb8c[_0xb43f('0x57')][0x0]['message']['id']){_0x10882a=_0x39cb8c['body'][0x0]['type'];return db[_0xb43f('0x99')][_0xb43f('0x53')]({'where':{'messageId':_0x39cb8c[_0xb43f('0x57')][0x0][_0xb43f('0x1f')]['id']}});}break;case _0xb43f('0x84'):if(_0x39cb8c[_0xb43f('0x57')][_0xb43f('0xc5')]&&_0x39cb8c[_0xb43f('0x57')]['status']){_0x10882a=_0x39cb8c['body'][_0xb43f('0x24')];return db['SmsMessage']['find']({'where':{'messageId':_0x39cb8c[_0xb43f('0x57')]['redif']}});}break;}}})[_0xb43f('0x19')](handleEntityNotFound(_0x34e4d5,null))[_0xb43f('0x19')](function(_0x19d498){if(_0x19d498){_0x3c0e11=_0x19d498;switch(_0x13000f[_0xb43f('0x38')]){case _0xb43f('0x74'):if(_0x10882a===_0xb43f('0xc3')){return _0x3c0e11[_0xb43f('0x2a')]({'read':!![]});}else{logger['error'](_0xb43f('0x1c'),_0xb43f('0x24'),'skebby',util[_0xb43f('0xbd')](_0x39cb8c[_0xb43f('0x57')],{'showHidden':![],'depth':null}));}break;case'connectel':if(_0x10882a==='1'){return _0x3c0e11[_0xb43f('0x2a')]({'read':!![]});}else{logger[_0xb43f('0x1d')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0xb43f('0x24'),_0xb43f('0x74'),util[_0xb43f('0xbd')](_0x39cb8c[_0xb43f('0x57')],{'showHidden':![],'depth':null}));}break;case _0xb43f('0x78'):if(!_0x39cb8c[_0xb43f('0x57')][_0xb43f('0xc6')]&&_0x10882a>=0xc8&&_0x10882a<=0xce){return _0x3c0e11['update']({'read':!![]});}else{logger['error']('SmsAccount,\x20%s,\x20%s,\x20%s',_0xb43f('0x24'),'clicksend',util[_0xb43f('0xbd')](_0x39cb8c[_0xb43f('0x57')],{'showHidden':![],'depth':null}));}break;case _0xb43f('0x7c'):var _0x5b8e1b=_0x39cb8c[_0xb43f('0x57')][_0xb43f('0x7d')][0x0];if(_0x5b8e1b[_0xb43f('0x24')][_0xb43f('0xc4')]===_0xb43f('0xc3')){return _0x3c0e11[_0xb43f('0x2a')]({'read':!![]});}else{logger['error'](_0xb43f('0x1c'),_0xb43f('0x24'),_0xb43f('0x7c'),util[_0xb43f('0xbd')](_0x39cb8c[_0xb43f('0x57')],{'showHidden':![],'depth':null}));}break;case'clickatell':if(_0x10882a=='DELIVERED_TO_GATEWAY'||_0x10882a==_0xb43f('0xc7')){return _0x3c0e11[_0xb43f('0x2a')]({'read':!![]});}else{logger[_0xb43f('0x1d')](_0xb43f('0x1c'),_0xb43f('0x24'),'clickatell',util[_0xb43f('0xbd')](_0x39cb8c[_0xb43f('0x57')],{'showHidden':![],'depth':null}));}break;case _0xb43f('0x83'):if(_0x10882a==_0xb43f('0xc8')){return _0x3c0e11[_0xb43f('0x2a')]({'read':!![]});}else{logger[_0xb43f('0x1d')](_0xb43f('0x1c'),_0xb43f('0x24'),'bandwidth',util[_0xb43f('0xbd')](_0x39cb8c['body'],{'showHidden':![],'depth':null}));}break;case _0xb43f('0x84'):if(_0x10882a===_0xb43f('0xc9')||_0x10882a===_0xb43f('0xca')){return _0x3c0e11[_0xb43f('0x2a')]({'read':!![]});}else{logger[_0xb43f('0x1d')](_0xb43f('0x1c'),_0xb43f('0x24'),_0xb43f('0x84'),util[_0xb43f('0xbd')](_0x39cb8c[_0xb43f('0x57')],{'showHidden':![],'depth':null}));}break;}return _0x3c0e11;}})[_0xb43f('0x19')](respondWithResult(_0x34e4d5,null))[_0xb43f('0x22')](handleError(_0x34e4d5,null));};exports[_0xb43f('0xcb')]=function(_0x17f242,_0x1e677f,_0x1030c1){var _0x9481d7,_0x260f64,_0xeb650d;return db[_0xb43f('0x36')]['find']({'where':{'id':_0x17f242[_0xb43f('0x50')]['id']}})['then'](handleEntityNotFound(_0x1e677f,null))[_0xb43f('0x19')](function(_0x4a6687){if(_0x4a6687){_0xeb650d=_0x4a6687;logger[_0xb43f('0xa4')](_0xb43f('0x1c'),'status',_0xb43f('0xbc'),_0x4a6687[_0xb43f('0x38')],util[_0xb43f('0xbd')](_0x17f242[_0xb43f('0x3a')],{'showHidden':![],'depth':null}));switch(_0x4a6687[_0xb43f('0x38')]){case _0xb43f('0xcc'):if(_0x17f242['query']['message-id']&&_0x17f242[_0xb43f('0x3a')][_0xb43f('0xcd')]){_0x260f64=_0x17f242[_0xb43f('0x3a')][_0xb43f('0xcd')];return db['SmsMessage'][_0xb43f('0x53')]({'where':{'messageId':_0x17f242[_0xb43f('0x3a')][_0xb43f('0xce')]}});}break;}}})[_0xb43f('0x19')](handleEntityNotFound(_0x1e677f,null))['then'](function(_0xc91d48){if(_0xc91d48){_0x9481d7=_0xc91d48;switch(_0xeb650d[_0xb43f('0x38')]){case _0xb43f('0xcc'):if(_0x260f64==='2'||_0x260f64==='6'){return _0x9481d7[_0xb43f('0x2a')]({'read':!![]});}else{logger[_0xb43f('0x1d')](_0xb43f('0x1c'),_0xb43f('0x24'),_0xb43f('0xcc'),util['inspect'](_0x17f242[_0xb43f('0x3a')],{'showHidden':![],'depth':null}));};break;}return _0x9481d7;}})[_0xb43f('0x19')](respondWithResult(_0x1e677f,null))[_0xb43f('0x22')](handleError(_0x1e677f,null));};exports['addAgents']=function(_0x3f5536,_0x352e81,_0x26ae19){return db[_0xb43f('0x36')][_0xb43f('0x53')]({'where':{'id':_0x3f5536[_0xb43f('0x50')]['id']}})[_0xb43f('0x19')](handleEntityNotFound(_0x352e81,null))[_0xb43f('0x19')](function(_0x37e8cd){if(_0x37e8cd){return _0x37e8cd['addAgents'](_0x3f5536['body'][_0xb43f('0x5d')],_[_0xb43f('0x90')](_0x3f5536[_0xb43f('0x57')],['ids','id'])||{})['spread'](function(_0x3b9301){for(var _0x310335=0x0;_0x310335<_0x3f5536['body'][_0xb43f('0x5d')][_0xb43f('0x40')];_0x310335+=0x1){socket[_0xb43f('0xcf')](_0xb43f('0xd0'),{'UserId':_0x3f5536[_0xb43f('0x57')][_0xb43f('0x5d')][_0x310335],'SmsAccountId':_0x3f5536['params']['id']});}return _0x3b9301;});}})[_0xb43f('0x19')](respondWithResult(_0x352e81,null))['catch'](handleError(_0x352e81,null));};exports[_0xb43f('0xd1')]=function(_0x3438fb,_0x40613f,_0x15ef41){return db['SmsAccount'][_0xb43f('0x53')]({'where':{'id':_0x3438fb[_0xb43f('0x50')]['id']}})[_0xb43f('0x19')](handleEntityNotFound(_0x40613f,null))[_0xb43f('0x19')](function(_0x26e3e9){if(_0x26e3e9){return _0x26e3e9[_0xb43f('0xd1')](_0x3438fb[_0xb43f('0x3a')][_0xb43f('0x5d')])[_0xb43f('0x19')](function(){if(_['isArray'](_0x3438fb[_0xb43f('0x3a')]['ids'])){for(var _0x192751=0x0;_0x192751<_0x3438fb[_0xb43f('0x3a')][_0xb43f('0x5d')][_0xb43f('0x40')];_0x192751+=0x1){socket[_0xb43f('0xcf')](_0xb43f('0xd2'),{'UserId':Number(_0x3438fb[_0xb43f('0x3a')][_0xb43f('0x5d')][_0x192751]),'SmsAccountId':Number(_0x3438fb['params']['id'])});}}else{socket[_0xb43f('0xcf')](_0xb43f('0xd2'),{'UserId':Number(_0x3438fb[_0xb43f('0x3a')][_0xb43f('0x5d')]),'SmsAccountId':Number(_0x3438fb[_0xb43f('0x50')]['id'])});}});}})[_0xb43f('0x19')](respondWithStatusCode(_0x40613f,null))[_0xb43f('0x22')](handleError(_0x40613f,null));};exports[_0xb43f('0xd3')]=function(_0x5d0e66,_0x19a979,_0x112b27){var _0x43a453={};var _0x13b48d={};var _0x17c6e7;var _0xe1c5d7;return db[_0xb43f('0x36')][_0xb43f('0xaf')]({'where':{'id':_0x5d0e66[_0xb43f('0x50')]['id']}})[_0xb43f('0x19')](handleEntityNotFound(_0x19a979,null))[_0xb43f('0x19')](function(_0x307557){if(_0x307557){_0x17c6e7=_0x307557;_0x13b48d['model']=_['keys'](db[_0xb43f('0x9c')][_0xb43f('0x37')]);_0x13b48d[_0xb43f('0x3a')]=_[_0xb43f('0x3b')](_0x5d0e66[_0xb43f('0x3a')]);_0x13b48d[_0xb43f('0x3c')]=_['intersection'](_0x13b48d[_0xb43f('0x39')],_0x13b48d[_0xb43f('0x3a')]);_0x43a453[_0xb43f('0x3e')]=_[_0xb43f('0x3d')](_0x13b48d[_0xb43f('0x39')],qs[_0xb43f('0x3f')](_0x5d0e66[_0xb43f('0x3a')]['fields']));_0x43a453[_0xb43f('0x3e')]=_0x43a453[_0xb43f('0x3e')]['length']?_0x43a453[_0xb43f('0x3e')]:_0x13b48d[_0xb43f('0x39')];_0x43a453['order']=qs['sort'](_0x5d0e66['query']['sort']);_0x43a453[_0xb43f('0x45')]=qs[_0xb43f('0x3c')](_[_0xb43f('0x46')](_0x5d0e66[_0xb43f('0x3a')],_0x13b48d[_0xb43f('0x3c')]));if(_0x5d0e66[_0xb43f('0x3a')][_0xb43f('0x47')]){_0x43a453[_0xb43f('0x45')]=_[_0xb43f('0x48')](_0x43a453[_0xb43f('0x45')],{'$or':_[_0xb43f('0x49')](_0x43a453[_0xb43f('0x3e')],function(_0x5e2504){var _0x425b2b={};_0x425b2b[_0x5e2504]={'$like':'%'+_0x5d0e66[_0xb43f('0x3a')][_0xb43f('0x47')]+'%'};return _0x425b2b;})});}_0x43a453=_[_0xb43f('0x48')]({},_0x43a453,_0x5d0e66[_0xb43f('0x4a')]);return _0x17c6e7[_0xb43f('0xd3')](_0x43a453);}})['then'](function(_0xd13ef2){if(_0xd13ef2){_0xe1c5d7=_0xd13ef2[_0xb43f('0x40')];if(!_0x5d0e66[_0xb43f('0x3a')][_0xb43f('0x41')]('nolimit')){_0x43a453[_0xb43f('0x42')]=qs[_0xb43f('0x42')](_0x5d0e66[_0xb43f('0x3a')][_0xb43f('0x42')]);_0x43a453[_0xb43f('0x26')]=qs['offset'](_0x5d0e66[_0xb43f('0x3a')][_0xb43f('0x26')]);}return _0x17c6e7[_0xb43f('0xd3')](_0x43a453);}})['then'](function(_0x4be7b5){if(_0x4be7b5){return _0x4be7b5?{'count':_0xe1c5d7,'rows':_0x4be7b5}:null;}})['then'](respondWithResult(_0x19a979,null))[_0xb43f('0x22')](handleError(_0x19a979,null));};
\ No newline at end of file
+var _0xeb45=['clicksend','message_id','plivo','Text','MessageUUID','infobip','results','csc','originatingAddress','segmentedMessage','clickatell','fromNumber','intelepeer','isNil','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','CmList','CmContact','DESC','list','omit','Contacts','contact','SmsInteraction','spread','interaction','created','autoclose','push','unmanaged','*,*,*,*','SmsMessage','ContactId','UserId','unshift','waitForTheAssignedAgent','Start','startRouting','SmsAccount,\x20%s,\x20%s,\x20%s','entity\x20found','SmsAccount,\x20%s,\x20%s,\x20%s,\x20%s','twilio','set','Content-Type','send','<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>','addApplications','sequelize','Transaction','SmsApplication','bulkCreate','findAndCountAll','priority','getApplications','nolimit','getInteractions','Contact','User','Owner','Tag','Tags','tag','to\x20is\x20mandatory','List','out','dataValues','Messages','received\x20delivery\x20report\x20from','inspect','skebby_dispatch_id','requestid','statusInt','status_code','groupName','DELIVERED','bandwidth','redif','error_code','DELIVERED_TO_GATEWAY','RECEIVED_BY_RECIPIENT','message-delivered','DELIVRD','ACCEPTD','statusGet','message-id','state','addAgents','emit','userSmsAccount:save','removeAgents','isArray','userSmsAccount:remove','getAgents','eml-format','rimraf','zip-dir','fast-json-patch','moment','mustache','util','path','to-csv','ejs','lodash','squel','jsforce','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/license/util','redis','defaults','socket.io-emitter','./smsAccount.socket','register','jayson/promise','http','request','then','info','SmsAccount,\x20%s,\x20%s','request\x20sent','debug','stringify','error','code','message','result','catch','sendStatus','status','end','json','limit','undefined','count','offset','Content-Range','apply','reject','save','update','get','SmsAccounts','UserProfileResource','destroy','stack','name','Pause','mandatoryDispositionPause','map','rawAttributes','fieldName','type','key','model','query','keys','filters','attributes','intersection','length','hasOwnProperty','sort','where','pick','merge','VIRTUAL','filter','SmsAccount','includeAll','include','rows','show','params','fields','options','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','find','describe','addDisposition','SmsAccountId','getDispositions','findOne','Disposition','order','findAll','removeDispositions','ids','addAnswer','CannedAnswer','removeAnswers','sms','account','applications','orderBy','Applications','asc','Sequelize','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','ListId','from','From','Body','messageId','MessageSid','skebby','sender','text','connectel'];(function(_0x2c16d9,_0xd68b7){var _0x3e81b1=function(_0x242700){while(--_0x242700){_0x2c16d9['push'](_0x2c16d9['shift']());}};_0x3e81b1(++_0xd68b7);}(_0xeb45,0x142));var _0x5eb4=function(_0x5daea7,_0x352f72){_0x5daea7=_0x5daea7-0x0;var _0x8d8b63=_0xeb45[_0x5daea7];return _0x8d8b63;};'use strict';var emlformat=require(_0x5eb4('0x0'));var rimraf=require(_0x5eb4('0x1'));var zipdir=require(_0x5eb4('0x2'));var jsonpatch=require(_0x5eb4('0x3'));var rp=require('request-promise');var moment=require(_0x5eb4('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x5eb4('0x5'));var util=require(_0x5eb4('0x6'));var path=require(_0x5eb4('0x7'));var sox=require('sox');var csv=require(_0x5eb4('0x8'));var ejs=require(_0x5eb4('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x5eb4('0xa'));var squel=require(_0x5eb4('0xb'));var crypto=require('crypto');var jsforce=require(_0x5eb4('0xc'));var deskjs=require('desk.js');var toCsv=require(_0x5eb4('0x8'));var querystring=require('querystring');var Papa=require(_0x5eb4('0xd'));var Redis=require(_0x5eb4('0xe'));var authService=require(_0x5eb4('0xf'));var qs=require(_0x5eb4('0x10'));var as=require(_0x5eb4('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x5eb4('0x12'))('api');var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x5eb4('0x13'));var db=require('../../mysqldb')['db'];config[_0x5eb4('0x14')]=_[_0x5eb4('0x15')](config[_0x5eb4('0x14')],{'host':'localhost','port':0x18eb});var socket=require(_0x5eb4('0x16'))(new Redis(config[_0x5eb4('0x14')]));require(_0x5eb4('0x17'))[_0x5eb4('0x18')](socket);var jayson=require(_0x5eb4('0x19'));var client=jayson['client'][_0x5eb4('0x1a')]({'port':0x232c});function respondWithRpcPromise(_0x12aba2,_0x2d96dc,_0x58652b,_0x42c7b9){return new BPromise(function(_0x2da6d7,_0x46712e){var _0x4d0b66=_0x42c7b9||client;return _0x4d0b66[_0x5eb4('0x1b')](_0x12aba2,_0x58652b)[_0x5eb4('0x1c')](function(_0x373274){logger[_0x5eb4('0x1d')](_0x5eb4('0x1e'),_0x2d96dc,_0x5eb4('0x1f'));logger[_0x5eb4('0x20')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x2d96dc,'request\x20sent',JSON[_0x5eb4('0x21')](_0x373274));if(_0x373274[_0x5eb4('0x22')]){if(_0x373274['error'][_0x5eb4('0x23')]===0x1f4){logger[_0x5eb4('0x22')](_0x5eb4('0x1e'),_0x2d96dc,_0x373274[_0x5eb4('0x22')][_0x5eb4('0x24')]);return _0x46712e(_0x373274[_0x5eb4('0x22')][_0x5eb4('0x24')]);}logger['error']('SmsAccount,\x20%s,\x20%s',_0x2d96dc,_0x373274['error']['message']);return _0x2da6d7(_0x373274[_0x5eb4('0x22')][_0x5eb4('0x24')]);}else{logger['info'](_0x5eb4('0x1e'),_0x2d96dc,_0x5eb4('0x1f'));_0x2da6d7(_0x373274[_0x5eb4('0x25')][_0x5eb4('0x24')]);}})[_0x5eb4('0x26')](function(_0x549c58){logger['error']('SmsAccount,\x20%s,\x20%s',_0x2d96dc,_0x549c58);_0x46712e(_0x549c58);});});}function respondWithStatusCode(_0xac5f03,_0x193915){_0x193915=_0x193915||0xcc;return function(_0xf3bbfb){if(_0xf3bbfb){return _0xac5f03[_0x5eb4('0x27')](_0x193915);}return _0xac5f03[_0x5eb4('0x28')](_0x193915)[_0x5eb4('0x29')]();};}function respondWithResult(_0x5bbe90,_0x44ced1){_0x44ced1=_0x44ced1||0xc8;return function(_0x280806){if(_0x280806){return _0x5bbe90[_0x5eb4('0x28')](_0x44ced1)[_0x5eb4('0x2a')](_0x280806);}};}function respondWithFilteredResult(_0x50b42b,_0x260814){return function(_0x5221ee){if(_0x5221ee){var _0x2e27db=typeof _0x260814['offset']==='undefined'&&typeof _0x260814[_0x5eb4('0x2b')]===_0x5eb4('0x2c');var _0x3180ba=_0x5221ee[_0x5eb4('0x2d')];var _0x5c497f=_0x2e27db?0x0:_0x260814[_0x5eb4('0x2e')];var _0x51f42c=_0x2e27db?_0x5221ee[_0x5eb4('0x2d')]:_0x260814[_0x5eb4('0x2e')]+_0x260814[_0x5eb4('0x2b')];var _0x1e3068;if(_0x51f42c>=_0x3180ba){_0x51f42c=_0x3180ba;_0x1e3068=0xc8;}else{_0x1e3068=0xce;}_0x50b42b['status'](_0x1e3068);return _0x50b42b['set'](_0x5eb4('0x2f'),_0x5c497f+'-'+_0x51f42c+'/'+_0x3180ba)[_0x5eb4('0x2a')](_0x5221ee);}return null;};}function patchUpdates(_0x159bb5){return function(_0x49e85f){try{jsonpatch[_0x5eb4('0x30')](_0x49e85f,_0x159bb5,!![]);}catch(_0x476118){return BPromise[_0x5eb4('0x31')](_0x476118);}return _0x49e85f[_0x5eb4('0x32')]();};}function saveUpdates(_0x4bd65f,_0x5ed8f2){return function(_0x14d762){if(_0x14d762){return _0x14d762[_0x5eb4('0x33')](_0x4bd65f)['then'](function(_0x13e4ad){return _0x13e4ad;});}return null;};}function removeEntity(_0x3c8c44,_0x5ea823){return function(_0x407468){if(_0x407468){return _0x407468['destroy']()[_0x5eb4('0x1c')](function(){var _0x5235bb=_0x407468[_0x5eb4('0x34')]({'plain':!![]});var _0x49d808=_0x5eb4('0x35');return db[_0x5eb4('0x36')][_0x5eb4('0x37')]({'where':{'type':_0x49d808,'resourceId':_0x5235bb['id']}})[_0x5eb4('0x1c')](function(){return _0x407468;});})[_0x5eb4('0x1c')](function(){_0x3c8c44[_0x5eb4('0x28')](0xcc)[_0x5eb4('0x29')]();});}};}function handleEntityNotFound(_0x4db594,_0x68c913){return function(_0x36a9eb){if(!_0x36a9eb){_0x4db594['sendStatus'](0x194);}return _0x36a9eb;};}function handleError(_0x1c763b,_0x44e294){_0x44e294=_0x44e294||0x1f4;return function(_0x5ad95b){logger[_0x5eb4('0x22')](_0x5ad95b[_0x5eb4('0x38')]);if(_0x5ad95b[_0x5eb4('0x39')]){delete _0x5ad95b[_0x5eb4('0x39')];}_0x1c763b['status'](_0x44e294)['send'](_0x5ad95b);};}exports['index']=function(_0x5e8094,_0x50dcab){var _0x265a2a={'include':[{'model':db[_0x5eb4('0x3a')],'as':_0x5eb4('0x3b')}]},_0x28a4d2={},_0x5e9282={'count':0x0,'rows':[]};var _0x2b04ea=_[_0x5eb4('0x3c')](db['SmsAccount'][_0x5eb4('0x3d')],function(_0x19e3a2){return{'name':_0x19e3a2[_0x5eb4('0x3e')],'type':_0x19e3a2[_0x5eb4('0x3f')][_0x5eb4('0x40')]};});_0x28a4d2[_0x5eb4('0x41')]=_['map'](_0x2b04ea,'name');_0x28a4d2[_0x5eb4('0x42')]=_[_0x5eb4('0x43')](_0x5e8094[_0x5eb4('0x42')]);_0x28a4d2[_0x5eb4('0x44')]=_['intersection'](_0x28a4d2[_0x5eb4('0x41')],_0x28a4d2[_0x5eb4('0x42')]);_0x265a2a[_0x5eb4('0x45')]=_[_0x5eb4('0x46')](_0x28a4d2[_0x5eb4('0x41')],qs['fields'](_0x5e8094[_0x5eb4('0x42')]['fields']));_0x265a2a[_0x5eb4('0x45')]=_0x265a2a[_0x5eb4('0x45')][_0x5eb4('0x47')]?_0x265a2a[_0x5eb4('0x45')]:_0x28a4d2[_0x5eb4('0x41')];if(!_0x5e8094[_0x5eb4('0x42')][_0x5eb4('0x48')]('nolimit')){_0x265a2a[_0x5eb4('0x2b')]=qs[_0x5eb4('0x2b')](_0x5e8094[_0x5eb4('0x42')][_0x5eb4('0x2b')]);_0x265a2a[_0x5eb4('0x2e')]=qs[_0x5eb4('0x2e')](_0x5e8094[_0x5eb4('0x42')][_0x5eb4('0x2e')]);}_0x265a2a['order']=qs[_0x5eb4('0x49')](_0x5e8094[_0x5eb4('0x42')][_0x5eb4('0x49')]);_0x265a2a[_0x5eb4('0x4a')]=qs[_0x5eb4('0x44')](_[_0x5eb4('0x4b')](_0x5e8094[_0x5eb4('0x42')],_0x28a4d2[_0x5eb4('0x44')]),_0x2b04ea);if(_0x5e8094[_0x5eb4('0x42')]['filter']){_0x265a2a['where']=_[_0x5eb4('0x4c')](_0x265a2a[_0x5eb4('0x4a')],{'$or':_[_0x5eb4('0x3c')](_0x2b04ea,function(_0x2372b6){if(_0x2372b6['type']!==_0x5eb4('0x4d')){var _0x20025e={};_0x20025e[_0x2372b6[_0x5eb4('0x39')]]={'$like':'%'+_0x5e8094[_0x5eb4('0x42')][_0x5eb4('0x4e')]+'%'};return _0x20025e;}})});}_0x265a2a=_['merge']({},_0x265a2a,_0x5e8094['options']);var _0x186250={'where':_0x265a2a[_0x5eb4('0x4a')]};return db[_0x5eb4('0x4f')][_0x5eb4('0x2d')](_0x186250)[_0x5eb4('0x1c')](function(_0x420224){_0x5e9282[_0x5eb4('0x2d')]=_0x420224;if(_0x5e8094['query'][_0x5eb4('0x50')]){_0x265a2a[_0x5eb4('0x51')]=[{'all':!![]}];}return db[_0x5eb4('0x4f')]['findAll'](_0x265a2a);})[_0x5eb4('0x1c')](function(_0x4813f4){_0x5e9282[_0x5eb4('0x52')]=_0x4813f4;return _0x5e9282;})[_0x5eb4('0x1c')](respondWithFilteredResult(_0x50dcab,_0x265a2a))[_0x5eb4('0x26')](handleError(_0x50dcab,null));};exports[_0x5eb4('0x53')]=function(_0x110ed9,_0x421682){var _0x21c103={'raw':![],'where':{'id':_0x110ed9[_0x5eb4('0x54')]['id']},'include':[{'model':db['Pause'],'as':_0x5eb4('0x3b')}]},_0x906068={};_0x906068['model']=_[_0x5eb4('0x43')](db[_0x5eb4('0x4f')][_0x5eb4('0x3d')]);_0x906068[_0x5eb4('0x42')]=_[_0x5eb4('0x43')](_0x110ed9['query']);_0x906068['filters']=_[_0x5eb4('0x46')](_0x906068['model'],_0x906068[_0x5eb4('0x42')]);_0x21c103[_0x5eb4('0x45')]=_[_0x5eb4('0x46')](_0x906068[_0x5eb4('0x41')],qs[_0x5eb4('0x55')](_0x110ed9[_0x5eb4('0x42')]['fields']));_0x21c103[_0x5eb4('0x45')]=_0x21c103['attributes'][_0x5eb4('0x47')]?_0x21c103[_0x5eb4('0x45')]:_0x906068[_0x5eb4('0x41')];if(_0x110ed9['query'][_0x5eb4('0x50')]){_0x21c103[_0x5eb4('0x51')]=[{'all':!![]}];}_0x21c103=_[_0x5eb4('0x4c')]({},_0x21c103,_0x110ed9[_0x5eb4('0x56')]);return db[_0x5eb4('0x4f')]['find'](_0x21c103)[_0x5eb4('0x1c')](handleEntityNotFound(_0x421682,null))[_0x5eb4('0x1c')](respondWithResult(_0x421682,null))[_0x5eb4('0x26')](handleError(_0x421682,null));};exports['create']=function(_0x4a9069,_0x5116fe){return db[_0x5eb4('0x4f')][_0x5eb4('0x57')](_0x4a9069['body'],{})[_0x5eb4('0x1c')](function(_0x2f30ce){var _0x4133a3=_0x4a9069[_0x5eb4('0x58')][_0x5eb4('0x34')]({'plain':!![]});if(!_0x4133a3)throw new Error(_0x5eb4('0x59'));if(_0x4133a3['role']===_0x5eb4('0x58')){var _0x52de6b=_0x2f30ce[_0x5eb4('0x34')]({'plain':!![]});var _0x498cf5=_0x5eb4('0x35');return db['UserProfileSection']['find']({'where':{'name':_0x498cf5,'userProfileId':_0x4133a3[_0x5eb4('0x5a')]},'raw':!![]})[_0x5eb4('0x1c')](function(_0x534fb6){if(_0x534fb6&&_0x534fb6[_0x5eb4('0x5b')]===0x0){return db['UserProfileResource'][_0x5eb4('0x57')]({'name':_0x52de6b['name'],'resourceId':_0x52de6b['id'],'type':_0x534fb6[_0x5eb4('0x39')],'sectionId':_0x534fb6['id']},{})['then'](function(){return _0x2f30ce;});}else{return _0x2f30ce;}})[_0x5eb4('0x26')](function(_0x5b299c){logger[_0x5eb4('0x22')](_0x5eb4('0x5c'),_0x5b299c);throw _0x5b299c;});}return _0x2f30ce;})[_0x5eb4('0x1c')](respondWithResult(_0x5116fe,0xc9))[_0x5eb4('0x26')](handleError(_0x5116fe,null));};exports[_0x5eb4('0x33')]=function(_0xa93da8,_0x456e24){if(_0xa93da8[_0x5eb4('0x5d')]['id']){delete _0xa93da8[_0x5eb4('0x5d')]['id'];}return db[_0x5eb4('0x4f')][_0x5eb4('0x5e')]({'where':{'id':_0xa93da8[_0x5eb4('0x54')]['id']},'include':[{'model':db[_0x5eb4('0x3a')],'as':_0x5eb4('0x3b')}]})[_0x5eb4('0x1c')](handleEntityNotFound(_0x456e24,null))['then'](saveUpdates(_0xa93da8[_0x5eb4('0x5d')],null))['then'](respondWithResult(_0x456e24,null))[_0x5eb4('0x26')](handleError(_0x456e24,null));};exports[_0x5eb4('0x37')]=function(_0x2a7a84,_0x19f48b){return db['SmsAccount'][_0x5eb4('0x5e')]({'where':{'id':_0x2a7a84['params']['id']}})[_0x5eb4('0x1c')](handleEntityNotFound(_0x19f48b,null))['then'](removeEntity(_0x19f48b,null))['catch'](handleError(_0x19f48b,null));};exports[_0x5eb4('0x5f')]=function(_0x5c5c5e,_0x5cae2c){return db[_0x5eb4('0x4f')][_0x5eb4('0x5f')]()[_0x5eb4('0x1c')](respondWithResult(_0x5cae2c,null))[_0x5eb4('0x26')](handleError(_0x5cae2c,null));};exports[_0x5eb4('0x60')]=function(_0x4e5ead,_0xe5cbd4,_0x406a4b){if(_0x4e5ead[_0x5eb4('0x5d')]['id']){delete _0x4e5ead[_0x5eb4('0x5d')]['id'];}return db[_0x5eb4('0x4f')][_0x5eb4('0x5e')]({'where':{'id':_0x4e5ead['params']['id']}})[_0x5eb4('0x1c')](handleEntityNotFound(_0xe5cbd4,null))['then'](function(_0x4bbe7a){if(_0x4bbe7a){_0x4e5ead[_0x5eb4('0x5d')][_0x5eb4('0x61')]=_0x4bbe7a['id'];return db['Disposition'][_0x5eb4('0x57')](_0x4e5ead[_0x5eb4('0x5d')]);}})[_0x5eb4('0x1c')](respondWithResult(_0xe5cbd4,null))['catch'](handleError(_0xe5cbd4,null));};exports[_0x5eb4('0x62')]=function(_0x5cd6f4,_0x4a1df8,_0x426316){var _0x343c57={'raw':![],'where':{}};var _0x5e2d29={};var _0x554d9d={'count':0x0,'rows':[]};return db[_0x5eb4('0x4f')][_0x5eb4('0x63')]({'where':{'id':_0x5cd6f4[_0x5eb4('0x54')]['id']}})[_0x5eb4('0x1c')](handleEntityNotFound(_0x4a1df8,null))[_0x5eb4('0x1c')](function(_0x3144e0){if(_0x3144e0){_0x5e2d29[_0x5eb4('0x41')]=_[_0x5eb4('0x43')](db[_0x5eb4('0x64')]['rawAttributes']);_0x5e2d29[_0x5eb4('0x42')]=_[_0x5eb4('0x43')](_0x5cd6f4['query']);_0x5e2d29[_0x5eb4('0x44')]=_['intersection'](_0x5e2d29['model'],_0x5e2d29[_0x5eb4('0x42')]);_0x343c57[_0x5eb4('0x45')]=_[_0x5eb4('0x46')](_0x5e2d29[_0x5eb4('0x41')],qs[_0x5eb4('0x55')](_0x5cd6f4[_0x5eb4('0x42')][_0x5eb4('0x55')]));_0x343c57[_0x5eb4('0x45')]=_0x343c57[_0x5eb4('0x45')][_0x5eb4('0x47')]?_0x343c57[_0x5eb4('0x45')]:_0x5e2d29[_0x5eb4('0x41')];if(!_0x5cd6f4[_0x5eb4('0x42')][_0x5eb4('0x48')]('nolimit')){_0x343c57[_0x5eb4('0x2b')]=qs[_0x5eb4('0x2b')](_0x5cd6f4[_0x5eb4('0x42')][_0x5eb4('0x2b')]);_0x343c57[_0x5eb4('0x2e')]=qs[_0x5eb4('0x2e')](_0x5cd6f4[_0x5eb4('0x42')][_0x5eb4('0x2e')]);}_0x343c57[_0x5eb4('0x65')]=qs['sort'](_0x5cd6f4[_0x5eb4('0x42')]['sort']);_0x343c57[_0x5eb4('0x4a')]=qs['filters'](_[_0x5eb4('0x4b')](_0x5cd6f4[_0x5eb4('0x42')],_0x5e2d29[_0x5eb4('0x44')]));_0x343c57[_0x5eb4('0x4a')][_0x5eb4('0x61')]=_0x3144e0['id'];if(_0x5cd6f4[_0x5eb4('0x42')]['filter']){_0x343c57[_0x5eb4('0x4a')]=_[_0x5eb4('0x4c')](_0x343c57[_0x5eb4('0x4a')],{'$or':_['map'](_0x343c57[_0x5eb4('0x45')],function(_0x9cad79){var _0x5b7fcf={};_0x5b7fcf[_0x9cad79]={'$like':'%'+_0x5cd6f4['query'][_0x5eb4('0x4e')]+'%'};return _0x5b7fcf;})});}_0x343c57=_[_0x5eb4('0x4c')]({},_0x343c57,_0x5cd6f4[_0x5eb4('0x56')]);return db[_0x5eb4('0x64')][_0x5eb4('0x2d')]({'where':_0x343c57['where']})[_0x5eb4('0x1c')](function(_0x3d891a){_0x554d9d['count']=_0x3d891a;if(_0x5cd6f4[_0x5eb4('0x42')][_0x5eb4('0x50')]){_0x343c57[_0x5eb4('0x51')]=[{'all':!![]}];}return db[_0x5eb4('0x64')][_0x5eb4('0x66')](_0x343c57);})['then'](function(_0x3d0c19){_0x554d9d['rows']=_0x3d0c19;return _0x554d9d;});}})['then'](respondWithFilteredResult(_0x4a1df8,_0x343c57))[_0x5eb4('0x26')](handleError(_0x4a1df8,null));};exports['removeDispositions']=function(_0x4a2323,_0x170c59,_0x45034c){return db[_0x5eb4('0x4f')]['find']({'where':{'id':_0x4a2323[_0x5eb4('0x54')]['id']}})['then'](handleEntityNotFound(_0x170c59,null))[_0x5eb4('0x1c')](function(_0x4a644f){if(_0x4a644f){return _0x4a644f[_0x5eb4('0x67')](_0x4a2323[_0x5eb4('0x42')][_0x5eb4('0x68')]);}})['then'](respondWithStatusCode(_0x170c59,null))[_0x5eb4('0x26')](handleError(_0x170c59,null));};exports[_0x5eb4('0x69')]=function(_0x454e5c,_0x26060c,_0x3c3e18){if(_0x454e5c[_0x5eb4('0x5d')]['id']){delete _0x454e5c[_0x5eb4('0x5d')]['id'];}return db['SmsAccount'][_0x5eb4('0x5e')]({'where':{'id':_0x454e5c['params']['id']}})[_0x5eb4('0x1c')](handleEntityNotFound(_0x26060c,null))[_0x5eb4('0x1c')](function(_0xa9fb69){if(_0xa9fb69){_0x454e5c[_0x5eb4('0x5d')][_0x5eb4('0x61')]=_0xa9fb69['id'];return db[_0x5eb4('0x6a')][_0x5eb4('0x57')](_0x454e5c[_0x5eb4('0x5d')]);}})[_0x5eb4('0x1c')](respondWithResult(_0x26060c,null))[_0x5eb4('0x26')](handleError(_0x26060c,null));};exports['getAnswers']=function(_0x209c39,_0x506097,_0x15ef73){var _0x285848={'raw':![],'where':{}};var _0x24ad00={};var _0x226f17={'count':0x0,'rows':[]};return db[_0x5eb4('0x4f')][_0x5eb4('0x63')]({'where':{'id':_0x209c39[_0x5eb4('0x54')]['id']}})[_0x5eb4('0x1c')](handleEntityNotFound(_0x506097,null))[_0x5eb4('0x1c')](function(_0x16df61){if(_0x16df61){_0x24ad00[_0x5eb4('0x41')]=_[_0x5eb4('0x43')](db[_0x5eb4('0x6a')][_0x5eb4('0x3d')]);_0x24ad00[_0x5eb4('0x42')]=_[_0x5eb4('0x43')](_0x209c39['query']);_0x24ad00[_0x5eb4('0x44')]=_[_0x5eb4('0x46')](_0x24ad00[_0x5eb4('0x41')],_0x24ad00[_0x5eb4('0x42')]);_0x285848[_0x5eb4('0x45')]=_[_0x5eb4('0x46')](_0x24ad00[_0x5eb4('0x41')],qs[_0x5eb4('0x55')](_0x209c39['query'][_0x5eb4('0x55')]));_0x285848[_0x5eb4('0x45')]=_0x285848[_0x5eb4('0x45')][_0x5eb4('0x47')]?_0x285848[_0x5eb4('0x45')]:_0x24ad00[_0x5eb4('0x41')];if(!_0x209c39[_0x5eb4('0x42')][_0x5eb4('0x48')]('nolimit')){_0x285848[_0x5eb4('0x2b')]=qs[_0x5eb4('0x2b')](_0x209c39[_0x5eb4('0x42')][_0x5eb4('0x2b')]);_0x285848[_0x5eb4('0x2e')]=qs[_0x5eb4('0x2e')](_0x209c39[_0x5eb4('0x42')]['offset']);}_0x285848[_0x5eb4('0x65')]=qs[_0x5eb4('0x49')](_0x209c39[_0x5eb4('0x42')][_0x5eb4('0x49')]);_0x285848['where']=qs[_0x5eb4('0x44')](_['pick'](_0x209c39[_0x5eb4('0x42')],_0x24ad00['filters']));_0x285848[_0x5eb4('0x4a')]['SmsAccountId']=_0x16df61['id'];if(_0x209c39[_0x5eb4('0x42')]['filter']){_0x285848['where']=_[_0x5eb4('0x4c')](_0x285848[_0x5eb4('0x4a')],{'$or':_[_0x5eb4('0x3c')](_0x285848[_0x5eb4('0x45')],function(_0x994737){var _0xff8392={};_0xff8392[_0x994737]={'$like':'%'+_0x209c39[_0x5eb4('0x42')][_0x5eb4('0x4e')]+'%'};return _0xff8392;})});}_0x285848=_[_0x5eb4('0x4c')]({},_0x285848,_0x209c39['options']);return db[_0x5eb4('0x6a')][_0x5eb4('0x2d')]({'where':_0x285848[_0x5eb4('0x4a')]})[_0x5eb4('0x1c')](function(_0x5985a4){_0x226f17[_0x5eb4('0x2d')]=_0x5985a4;if(_0x209c39['query'][_0x5eb4('0x50')]){_0x285848[_0x5eb4('0x51')]=[{'all':!![]}];}return db[_0x5eb4('0x6a')][_0x5eb4('0x66')](_0x285848);})[_0x5eb4('0x1c')](function(_0x59dfd1){_0x226f17[_0x5eb4('0x52')]=_0x59dfd1;return _0x226f17;});}})[_0x5eb4('0x1c')](respondWithFilteredResult(_0x506097,_0x285848))['catch'](handleError(_0x506097,null));};exports['removeAnswers']=function(_0x38e1da,_0x56f35d,_0x2c8d9b){return db[_0x5eb4('0x4f')][_0x5eb4('0x5e')]({'where':{'id':_0x38e1da['params']['id']}})[_0x5eb4('0x1c')](handleEntityNotFound(_0x56f35d,null))[_0x5eb4('0x1c')](function(_0x3333ab){if(_0x3333ab){return _0x3333ab[_0x5eb4('0x6b')](_0x38e1da[_0x5eb4('0x42')][_0x5eb4('0x68')]);}})[_0x5eb4('0x1c')](respondWithStatusCode(_0x56f35d,null))[_0x5eb4('0x26')](handleError(_0x56f35d,null));};exports['notify']=function(_0x310d90,_0x258130,_0x13cac2){var _0x510c6c={'channel':_0x5eb4('0x6c')};var _0x13bc4c=[];var _0x38a108=[];var _0x4cb719={};return db['SmsAccount'][_0x5eb4('0x5e')]({'where':{'id':_0x310d90[_0x5eb4('0x54')]['id']},'include':[{'model':db['SmsApplication'],'as':'Applications'}]})[_0x5eb4('0x1c')](handleEntityNotFound(_0x258130,null))[_0x5eb4('0x1c')](function(_0x54e5d2){_0x510c6c[_0x5eb4('0x6d')]=_0x54e5d2;_0x510c6c[_0x5eb4('0x6e')]=_[_0x5eb4('0x6f')](_0x54e5d2[_0x5eb4('0x70')],['priority'],[_0x5eb4('0x71')]);if(_0x510c6c[_0x5eb4('0x6d')][_0x5eb4('0x70')]){delete _0x510c6c[_0x5eb4('0x6d')]['Applications'];}return db['CmContact']['describe']();})[_0x5eb4('0x1c')](function(_0x46fec2){if(!_0x46fec2){throw new db[(_0x5eb4('0x72'))][(_0x5eb4('0x73'))](_0x5eb4('0x74'));}_0x13bc4c=_[_0x5eb4('0x75')](_[_0x5eb4('0x43')](_0x46fec2),[_0x5eb4('0x76'),_0x5eb4('0x77')]);_0x38a108=_[_0x5eb4('0x75')](_[_0x5eb4('0x43')](_0x46fec2),[_0x5eb4('0x76'),_0x5eb4('0x77'),'CompanyId',_0x5eb4('0x78')]);_0x510c6c[_0x5eb4('0x5d')]={'mapKey':'mobile'};if(_0x510c6c[_0x5eb4('0x6d')][_0x5eb4('0x3f')]){switch(_0x510c6c[_0x5eb4('0x6d')]['type']){case'twilio':_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x79')]=_0x310d90[_0x5eb4('0x5d')][_0x5eb4('0x7a')];_0x510c6c['body'][_0x5eb4('0x5d')]=_0x310d90[_0x5eb4('0x5d')][_0x5eb4('0x7b')];_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x7c')]=_0x310d90[_0x5eb4('0x5d')][_0x5eb4('0x7d')];break;case _0x5eb4('0x7e'):_0x510c6c['body'][_0x5eb4('0x79')]='+'+_0x310d90[_0x5eb4('0x5d')][_0x5eb4('0x7f')];_0x510c6c['body'][_0x5eb4('0x5d')]=_0x310d90[_0x5eb4('0x5d')][_0x5eb4('0x80')];break;case _0x5eb4('0x81'):_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x79')]=_0x310d90[_0x5eb4('0x5d')][_0x5eb4('0x79')];_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x5d')]=_0x310d90[_0x5eb4('0x5d')]['message'];break;case _0x5eb4('0x82'):_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x79')]=_0x310d90[_0x5eb4('0x5d')][_0x5eb4('0x79')];_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x5d')]=_0x310d90['body'][_0x5eb4('0x5d')];_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x7c')]=_0x310d90[_0x5eb4('0x5d')][_0x5eb4('0x83')];break;case _0x5eb4('0x84'):_0x510c6c['body'][_0x5eb4('0x79')]=_0x310d90[_0x5eb4('0x5d')][_0x5eb4('0x7a')];_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x5d')]=_0x310d90['body'][_0x5eb4('0x85')];_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x7c')]=_0x310d90['body'][_0x5eb4('0x86')];break;case _0x5eb4('0x87'):_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x79')]='+'+_0x310d90['body'][_0x5eb4('0x88')][0x0]['from'];_0x510c6c['body'][_0x5eb4('0x5d')]=_0x310d90[_0x5eb4('0x5d')][_0x5eb4('0x88')][0x0][_0x5eb4('0x80')];_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x7c')]=_0x310d90[_0x5eb4('0x5d')]['results'][0x0]['messageId'];break;case _0x5eb4('0x89'):_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x79')]=_0x310d90[_0x5eb4('0x5d')][_0x5eb4('0x8a')];_0x510c6c['body']['body']=_0x310d90[_0x5eb4('0x5d')][_0x5eb4('0x8b')][_0x5eb4('0x24')];break;case _0x5eb4('0x8c'):_0x510c6c['body']['from']=_0x310d90['body'][_0x5eb4('0x8d')];_0x510c6c[_0x5eb4('0x5d')]['body']=_0x310d90[_0x5eb4('0x5d')][_0x5eb4('0x80')];_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x7c')]=_0x310d90[_0x5eb4('0x5d')]['replyMessageId'];break;case'bandwidth':_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x7c')]=_0x310d90[_0x5eb4('0x5d')][0x0][_0x5eb4('0x24')]['id'];_0x510c6c[_0x5eb4('0x5d')]['from']=_0x310d90[_0x5eb4('0x5d')][0x0]['message'][_0x5eb4('0x79')];_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x5d')]=_0x310d90['body'][0x0][_0x5eb4('0x24')]['text'];break;case _0x5eb4('0x8e'):_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x79')]=_0x310d90[_0x5eb4('0x5d')][_0x5eb4('0x79')];_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x5d')]=_0x310d90['body'][_0x5eb4('0x24')];_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x7c')]=_0x310d90[_0x5eb4('0x5d')]['refid'];break;}}if(_0x510c6c[_0x5eb4('0x5d')]['id']){delete _0x510c6c[_0x5eb4('0x5d')]['id'];}if(_[_0x5eb4('0x8f')](_0x510c6c['body']['from'])){throw new db[(_0x5eb4('0x72'))]['ValidationError'](_0x5eb4('0x90'));}if(_[_0x5eb4('0x8f')](_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x5d')])||_0x510c6c['body'][_0x5eb4('0x5d')]===''){throw new db[(_0x5eb4('0x72'))][(_0x5eb4('0x73'))](_0x5eb4('0x91'));}if(_[_0x5eb4('0x8f')](_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x92')])){throw new db[(_0x5eb4('0x72'))][(_0x5eb4('0x73'))](_0x5eb4('0x93')+_0x38a108);}if(!_[_0x5eb4('0x94')](_0x38a108,_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x92')])){throw new db[(_0x5eb4('0x72'))]['ValidationError']('mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x38a108);}_0x4cb719[_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x92')]]=_0x510c6c['body'][_0x5eb4('0x79')];return db[_0x5eb4('0x95')][_0x5eb4('0x5e')]({'where':{'id':_0x510c6c[_0x5eb4('0x6d')]['ListId']},'include':[{'model':db[_0x5eb4('0x96')],'as':'Contacts','where':_0x4cb719,'limit':0x1,'order':[['updatedAt',_0x5eb4('0x97')]]}]});})[_0x5eb4('0x1c')](handleEntityNotFound(_0x258130,null))[_0x5eb4('0x1c')](function(_0x155cd5){if(_0x155cd5){_0x510c6c[_0x5eb4('0x98')]=_[_0x5eb4('0x99')](_0x155cd5,[_0x5eb4('0x9a')]);if(_0x155cd5['Contacts'][_0x5eb4('0x47')]){return _0x155cd5[_0x5eb4('0x9a')][0x0];}var _0x16ca4c=_[_0x5eb4('0x15')](_0x510c6c[_0x5eb4('0x5d')],{'firstName':_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x79')],'ListId':_0x155cd5['id']});_0x16ca4c[_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x92')]]=_0x510c6c[_0x5eb4('0x5d')]['from'];return db['CmContact'][_0x5eb4('0x57')](_0x16ca4c,{'fields':_0x13bc4c,'raw':!![]});}})[_0x5eb4('0x1c')](handleEntityNotFound(_0x258130,null))['then'](function(_0x4378d7){if(_0x4378d7){_0x510c6c[_0x5eb4('0x9b')]=_0x4378d7;var _0x10cdf5={'ContactId':_0x4378d7['id'],'phone':_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x79')],'SmsAccountId':_0x310d90[_0x5eb4('0x54')]['id']};var _0x586a66={'ContactId':_0x4378d7['id'],'SmsAccountId':_0x310d90[_0x5eb4('0x54')]['id'],'closed':![]};return db[_0x5eb4('0x9c')][_0x5eb4('0x5e')]({'where':_0x586a66})[_0x5eb4('0x1c')](function(_0x22b447){if(_0x22b447){return[_0x22b447,![]];}return db['SmsInteraction'][_0x5eb4('0x57')](_0x10cdf5)[_0x5eb4('0x1c')](function(_0x33d164){return[_0x33d164,!![]];});});}})[_0x5eb4('0x9d')](function(_0x36adff,_0x59483e){_0x510c6c[_0x5eb4('0x9e')]=_0x36adff['get']({'plain':!![]});_0x510c6c[_0x5eb4('0x9e')][_0x5eb4('0x9f')]=![];if(_0x59483e){if(_0x510c6c['account'][_0x5eb4('0xa0')]){_0x510c6c[_0x5eb4('0x6e')][_0x5eb4('0xa1')]({'id':0x0,'priority':_0x510c6c['applications']['length']+0x1,'app':'close','appdata':_0x5eb4('0xa2'),'interval':_0x5eb4('0xa3')});}_0x510c6c[_0x5eb4('0x9e')]['created']=!![];}return db[_0x5eb4('0xa4')][_0x5eb4('0x57')]({'phone':_0x510c6c['body'][_0x5eb4('0x79')],'messageId':_0x510c6c[_0x5eb4('0x5d')]['messageId'],'body':_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x5d')],'SmsAccountId':_0x310d90['params']['id'],'SmsInteractionId':_0x36adff['id'],'direction':'in','ContactId':_0x36adff[_0x5eb4('0xa5')],'AttachmentId':_0x510c6c['body']['AttachmentId']});})['then'](function(_0x14affd){_0x510c6c[_0x5eb4('0x24')]=_0x14affd;if(_0x510c6c[_0x5eb4('0x9e')][_0x5eb4('0xa6')]){return db['User'][_0x5eb4('0x5e')]({'attributes':['id',_0x5eb4('0x39')],'where':{'id':_0x510c6c[_0x5eb4('0x9e')]['UserId']}})[_0x5eb4('0x1c')](function(_0x174b53){if(_0x174b53){_0x510c6c['applications'][_0x5eb4('0xa7')]({'id':0x0,'priority':0x0,'app':'agent','appdata':_0x174b53[_0x5eb4('0x39')]+','+(_0x510c6c[_0x5eb4('0x6d')][_0x5eb4('0xa8')]||0xa),'interval':_0x5eb4('0xa3')});}return respondWithRpcPromise(_0x5eb4('0xa9'),_0x5eb4('0xaa'),_0x510c6c);});}return respondWithRpcPromise(_0x5eb4('0xa9'),_0x5eb4('0xaa'),_0x510c6c);})[_0x5eb4('0x1c')](function(_0x2ab94b){if(_0x2ab94b){var _0x30c4e4=0xc8;var _0x1159b0='receiveMessage';logger['info'](_0x5eb4('0xab'),_0x1159b0,_0x30c4e4,_0x5eb4('0xac'));logger[_0x5eb4('0x20')](_0x5eb4('0xad'),_0x1159b0,_0x30c4e4,'entity\x20found',JSON[_0x5eb4('0x21')](_0x2ab94b));if(_0x510c6c[_0x5eb4('0x6d')][_0x5eb4('0x3f')]===_0x5eb4('0xae')){return _0x258130[_0x5eb4('0x28')](_0x30c4e4)[_0x5eb4('0xaf')](_0x5eb4('0xb0'),'text/xml')[_0x5eb4('0xb1')](_0x5eb4('0xb2'));}else{return _0x258130[_0x5eb4('0x28')](_0x30c4e4)[_0x5eb4('0x2a')](_0x2ab94b);}}})[_0x5eb4('0x26')](handleError(_0x258130,null));};exports[_0x5eb4('0xb3')]=function(_0x59802e,_0x5d07c5){var _0x3312d9=_0x59802e[_0x5eb4('0x54')]['id'];var _0xdde899=_0x59802e[_0x5eb4('0x5d')];var _0xf60907=0xc8;var _0x351b0f=null;return db[_0x5eb4('0xb4')]['transaction']({'isolationLevel':db[_0x5eb4('0xb4')][_0x5eb4('0xb5')]['ISOLATION_LEVELS']['READ_COMMITTED']},function(_0x4b3b8c){return db[_0x5eb4('0x4f')]['findOne']({'where':{'id':_0x3312d9},'transaction':_0x4b3b8c})['then'](function(_0x99bce2){if(_0x99bce2){return db[_0x5eb4('0xb6')][_0x5eb4('0x37')]({'where':{'SmsAccountId':_0x3312d9},'transaction':_0x4b3b8c})[_0x5eb4('0x1c')](function(){var _0x14ef5b=_['map'](_0xdde899,function(_0xa822d8){_0xa822d8[_0x5eb4('0x61')]=_0x3312d9;return _0xa822d8;});return db[_0x5eb4('0xb6')][_0x5eb4('0xb7')](_0x14ef5b,{'transaction':_0x4b3b8c});});}else{_0xf60907=0x194;_0x351b0f=[];}});})[_0x5eb4('0x1c')](function(){if(_0xf60907!==0x194){return db[_0x5eb4('0xb6')][_0x5eb4('0xb8')]({'where':{'SmsAccountId':_0x3312d9},'order':_0x5eb4('0xb9')})[_0x5eb4('0x1c')](function(_0x14c150){_0x351b0f=_0x14c150;});}})[_0x5eb4('0x26')](function(_0x5a7988){_0xf60907=0x1f4;logger['error'](_0x5a7988[_0x5eb4('0x38')]);if(_0x5a7988[_0x5eb4('0x39')]){delete _0x5a7988[_0x5eb4('0x39')];}_0x351b0f=_0x5a7988;})['finally'](function(){if(_0x351b0f===null){_0x5d07c5[_0x5eb4('0x27')](_0xf60907);}else{if(_0xf60907===0x1f4){_0x5d07c5[_0x5eb4('0x28')](_0xf60907)[_0x5eb4('0xb1')](_0x351b0f);}else{_0x5d07c5[_0x5eb4('0x28')](_0xf60907)[_0x5eb4('0x2a')](_0x351b0f);}}});};exports[_0x5eb4('0xba')]=function(_0x1c2c55,_0x16413b,_0x1cfd6e){var _0x3dfe9d={};var _0xf81a43={};var _0x45909c;var _0x18e074;return db[_0x5eb4('0x4f')][_0x5eb4('0x63')]({'where':{'id':_0x1c2c55[_0x5eb4('0x54')]['id']}})[_0x5eb4('0x1c')](handleEntityNotFound(_0x16413b,null))[_0x5eb4('0x1c')](function(_0x5f0eb8){if(_0x5f0eb8){_0x45909c=_0x5f0eb8;_0xf81a43['model']=_[_0x5eb4('0x43')](db[_0x5eb4('0xb6')]['rawAttributes']);_0xf81a43['query']=_[_0x5eb4('0x43')](_0x1c2c55[_0x5eb4('0x42')]);_0xf81a43[_0x5eb4('0x44')]=_[_0x5eb4('0x46')](_0xf81a43['model'],_0xf81a43[_0x5eb4('0x42')]);_0x3dfe9d['attributes']=_[_0x5eb4('0x46')](_0xf81a43[_0x5eb4('0x41')],qs[_0x5eb4('0x55')](_0x1c2c55[_0x5eb4('0x42')][_0x5eb4('0x55')]));_0x3dfe9d[_0x5eb4('0x45')]=_0x3dfe9d[_0x5eb4('0x45')][_0x5eb4('0x47')]?_0x3dfe9d[_0x5eb4('0x45')]:_0xf81a43['model'];_0x3dfe9d['order']=qs[_0x5eb4('0x49')](_0x1c2c55[_0x5eb4('0x42')][_0x5eb4('0x49')]);_0x3dfe9d[_0x5eb4('0x4a')]=qs[_0x5eb4('0x44')](_[_0x5eb4('0x4b')](_0x1c2c55['query'],_0xf81a43[_0x5eb4('0x44')]));if(_0x1c2c55[_0x5eb4('0x42')][_0x5eb4('0x4e')]){_0x3dfe9d[_0x5eb4('0x4a')]=_['merge'](_0x3dfe9d[_0x5eb4('0x4a')],{'$or':_[_0x5eb4('0x3c')](_0x3dfe9d[_0x5eb4('0x45')],function(_0x38ad9a){var _0x1eb0c8={};_0x1eb0c8[_0x38ad9a]={'$like':'%'+_0x1c2c55['query'][_0x5eb4('0x4e')]+'%'};return _0x1eb0c8;})});}_0x3dfe9d=_['merge']({},_0x3dfe9d,_0x1c2c55['options']);return _0x45909c[_0x5eb4('0xba')](_0x3dfe9d);}})[_0x5eb4('0x1c')](function(_0x5aad46){if(_0x5aad46){_0x18e074=_0x5aad46[_0x5eb4('0x47')];if(!_0x1c2c55[_0x5eb4('0x42')][_0x5eb4('0x48')](_0x5eb4('0xbb'))){_0x3dfe9d[_0x5eb4('0x2b')]=qs[_0x5eb4('0x2b')](_0x1c2c55['query'][_0x5eb4('0x2b')]);_0x3dfe9d[_0x5eb4('0x2e')]=qs[_0x5eb4('0x2e')](_0x1c2c55[_0x5eb4('0x42')][_0x5eb4('0x2e')]);}return _0x45909c[_0x5eb4('0xba')](_0x3dfe9d);}})[_0x5eb4('0x1c')](function(_0x1d80e5){if(_0x1d80e5){return _0x1d80e5?{'count':_0x18e074,'rows':_0x1d80e5}:null;}})['then'](respondWithResult(_0x16413b,null))[_0x5eb4('0x26')](handleError(_0x16413b,null));};exports[_0x5eb4('0xbc')]=function(_0x370d88,_0xe988c,_0x4ccae9){var _0x522bab={'raw':![],'where':{}};var _0x2e0b57={};var _0x188d18={'count':0x0,'rows':[]};return db['SmsAccount'][_0x5eb4('0x63')]({'where':{'id':_0x370d88[_0x5eb4('0x54')]['id']}})[_0x5eb4('0x1c')](handleEntityNotFound(_0xe988c,null))[_0x5eb4('0x1c')](function(_0x58a951){if(_0x58a951){_0x2e0b57[_0x5eb4('0x41')]=_[_0x5eb4('0x43')](db[_0x5eb4('0x9c')]['rawAttributes']);_0x2e0b57['query']=_['keys'](_0x370d88['query']);_0x2e0b57['filters']=_[_0x5eb4('0x46')](_0x2e0b57[_0x5eb4('0x41')],_0x2e0b57['query']);_0x522bab['attributes']=_['intersection'](_0x2e0b57[_0x5eb4('0x41')],qs[_0x5eb4('0x55')](_0x370d88[_0x5eb4('0x42')][_0x5eb4('0x55')]));_0x522bab[_0x5eb4('0x45')]=_0x522bab[_0x5eb4('0x45')][_0x5eb4('0x47')]?_0x522bab[_0x5eb4('0x45')]:_0x2e0b57['model'];if(!_0x370d88[_0x5eb4('0x42')]['hasOwnProperty']('nolimit')){_0x522bab[_0x5eb4('0x2b')]=qs[_0x5eb4('0x2b')](_0x370d88[_0x5eb4('0x42')][_0x5eb4('0x2b')]);_0x522bab[_0x5eb4('0x2e')]=qs['offset'](_0x370d88[_0x5eb4('0x42')][_0x5eb4('0x2e')]);}_0x522bab[_0x5eb4('0x65')]=qs[_0x5eb4('0x49')](_0x370d88['query'][_0x5eb4('0x49')]);_0x522bab[_0x5eb4('0x4a')]=qs['filters'](_['pick'](_0x370d88[_0x5eb4('0x42')],_0x2e0b57['filters']));_0x522bab[_0x5eb4('0x4a')][_0x5eb4('0x61')]=_0x58a951['id'];if(_0x370d88[_0x5eb4('0x42')]['filter']){_0x522bab[_0x5eb4('0x4a')]=_[_0x5eb4('0x4c')](_0x522bab[_0x5eb4('0x4a')],{'$or':_[_0x5eb4('0x3c')](_0x522bab[_0x5eb4('0x45')],function(_0x3f0b49){var _0x5c04b9={};_0x5c04b9[_0x3f0b49]={'$like':'%'+_0x370d88['query'][_0x5eb4('0x4e')]+'%'};return _0x5c04b9;})});}_0x522bab=_[_0x5eb4('0x4c')]({},_0x522bab,_0x370d88[_0x5eb4('0x56')]);return db[_0x5eb4('0x9c')][_0x5eb4('0x2d')]({'where':_0x522bab[_0x5eb4('0x4a')]})[_0x5eb4('0x1c')](function(_0x355085){_0x188d18[_0x5eb4('0x2d')]=_0x355085;if(_0x370d88[_0x5eb4('0x42')][_0x5eb4('0x50')]){_0x522bab['include']=[{'model':db[_0x5eb4('0x96')],'as':_0x5eb4('0xbd'),'required':![]},{'model':db[_0x5eb4('0xbe')],'as':_0x5eb4('0xbf'),'attributes':[_0x5eb4('0x39'),'fullname','internal'],'required':![]},{'model':db[_0x5eb4('0xc0')],'as':_0x5eb4('0xc1'),'attributes':['id',_0x5eb4('0x39'),'color'],'where':_0x370d88[_0x5eb4('0x42')]['tag']?{'id':_0x370d88[_0x5eb4('0x42')][_0x5eb4('0xc2')]}:undefined,'required':_0x370d88[_0x5eb4('0x42')][_0x5eb4('0xc2')]?!![]:![]}];}return db['SmsInteraction'][_0x5eb4('0x66')](_0x522bab);})['then'](function(_0x142b00){_0x188d18[_0x5eb4('0x52')]=_0x142b00;return _0x188d18;});}})[_0x5eb4('0x1c')](respondWithFilteredResult(_0xe988c,_0x522bab))['catch'](handleError(_0xe988c,null));};exports[_0x5eb4('0xb1')]=function(_0x3c2668,_0x258d11,_0x2dee31){var _0x17db79,_0x1113c5,_0x2e7212;if(_[_0x5eb4('0x8f')](_0x3c2668[_0x5eb4('0x5d')][_0x5eb4('0x5d')])||_0x3c2668[_0x5eb4('0x5d')]['body']===''){throw new db['Sequelize'][(_0x5eb4('0x73'))](_0x5eb4('0x91'));}if(_['isNil'](_0x3c2668[_0x5eb4('0x5d')]['to'])){throw new db[(_0x5eb4('0x72'))][(_0x5eb4('0x73'))](_0x5eb4('0xc3'));}_0x17db79=_0x3c2668[_0x5eb4('0x5d')]['to'];return db[_0x5eb4('0x4f')][_0x5eb4('0x5e')]({'where':{'id':_0x3c2668[_0x5eb4('0x54')]['id']},'include':[{'model':db[_0x5eb4('0x95')],'as':_0x5eb4('0xc4'),'include':[{'model':db[_0x5eb4('0x96')],'as':'Contacts','where':{'mobile':_0x17db79},'limit':0x1,'order':[[_0x5eb4('0x77'),_0x5eb4('0x97')]]}]}]})[_0x5eb4('0x1c')](handleEntityNotFound(_0x258d11,null))[_0x5eb4('0x1c')](function(_0x359e94){if(_0x359e94&&_0x359e94[_0x5eb4('0xc4')]){_0x1113c5=_0x359e94[_0x5eb4('0x34')]({'plain':!![]});if(_0x1113c5[_0x5eb4('0xc4')]&&_0x1113c5[_0x5eb4('0xc4')][_0x5eb4('0x9a')]['length']){return _0x1113c5[_0x5eb4('0xc4')][_0x5eb4('0x9a')][0x0];}return db[_0x5eb4('0x96')][_0x5eb4('0x57')](_[_0x5eb4('0x15')](_0x3c2668[_0x5eb4('0x5d')],{'firstName':_0x17db79,'mobile':_0x17db79,'phone':_0x17db79,'ListId':_0x1113c5[_0x5eb4('0x78')]}));}})['then'](handleEntityNotFound(_0x258d11,null))[_0x5eb4('0x1c')](function(_0x3a6a1f){if(_0x3a6a1f){_0x2e7212=_0x3a6a1f;return db[_0x5eb4('0x9c')][_0x5eb4('0x5e')]({'where':{'ContactId':_0x2e7212['id'],'closed':![],'SmsAccountId':_0x1113c5['id']}})[_0x5eb4('0x1c')](function(_0x288a3e){if(_0x288a3e){return[_0x288a3e,![]];}return db[_0x5eb4('0x9c')][_0x5eb4('0x57')]({'UserId':_0x3c2668['user']['id'],'ContactId':_0x2e7212['id'],'SmsAccountId':_0x1113c5['id'],'phone':_0x17db79,'firstMsgDirection':_0x5eb4('0xc5'),'Messages':[_[_0x5eb4('0x4c')](_0x3c2668['body'],{'read':![],'body':_0x3c2668[_0x5eb4('0x5d')][_0x5eb4('0x5d')],'phone':_0x17db79,'SmsAccountId':_0x1113c5['id'],'UserId':_0x3c2668[_0x5eb4('0x58')]['id'],'ContactId':_0x2e7212['id']})]},{'include':[{'model':db[_0x5eb4('0xa4')],'as':'Messages'}]})['then'](function(_0x3647d6){return[_0x3647d6,!![]];});});}})[_0x5eb4('0x9d')](function(_0x2abe2a,_0x5382e4){if(_0x5382e4){return _0x2abe2a;}return db['SmsMessage']['create'](_[_0x5eb4('0x4c')](_0x3c2668[_0x5eb4('0x5d')],{'read':![],'body':_0x3c2668[_0x5eb4('0x5d')][_0x5eb4('0x5d')],'phone':_0x17db79,'SmsAccountId':_0x1113c5['id'],'SmsInteractionId':_0x2abe2a['id'],'UserId':_0x3c2668['user']['id'],'ContactId':_0x2e7212['id']}))['then'](function(_0x5bebd0){_0x2abe2a[_0x5eb4('0xc6')][_0x5eb4('0xc7')]=[];_0x2abe2a[_0x5eb4('0xc6')]['Messages'][_0x5eb4('0xa1')](_0x5bebd0[_0x5eb4('0xc6')]);return _0x2abe2a;});})[_0x5eb4('0x1c')](respondWithResult(_0x258d11,null))[_0x5eb4('0x26')](handleError(_0x258d11,null));};exports['status']=function(_0x3ccbd9,_0xef6c11,_0xf02862){if(_0x3ccbd9['body']['id']){delete _0x3ccbd9['body']['id'];}var _0x404920,_0x1f145d,_0x194fee;return db[_0x5eb4('0x4f')]['find']({'where':{'id':_0x3ccbd9[_0x5eb4('0x54')]['id']}})[_0x5eb4('0x1c')](handleEntityNotFound(_0xef6c11,null))[_0x5eb4('0x1c')](function(_0x5ecf99){if(_0x5ecf99){_0x194fee=_0x5ecf99;logger[_0x5eb4('0x20')](_0x5eb4('0xab'),_0x5eb4('0x28'),_0x5eb4('0xc8'),_0x5ecf99[_0x5eb4('0x3f')],util[_0x5eb4('0xc9')](_0x3ccbd9[_0x5eb4('0x5d')],{'showHidden':![],'depth':null}));switch(_0x5ecf99[_0x5eb4('0x3f')]){case _0x5eb4('0x7e'):if(_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0xca')]&&_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0x28')]){_0x1f145d=_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0x28')];return db[_0x5eb4('0xa4')][_0x5eb4('0x5e')]({'where':{'messageId':_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0xca')]}});}break;case _0x5eb4('0x81'):if(_0x3ccbd9['body'][_0x5eb4('0xcb')]&&_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0xcc')]){_0x1f145d=_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0xcc')];return db[_0x5eb4('0xa4')][_0x5eb4('0x5e')]({'where':{'messageId':_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0xcb')]}});}break;case'clicksend':if(_0x3ccbd9['body']['message_id']&&_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0xcd')]){_0x1f145d=_0x3ccbd9['body'][_0x5eb4('0xcd')];return db[_0x5eb4('0xa4')][_0x5eb4('0x5e')]({'where':{'messageId':_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0x83')]}});}break;case'infobip':var _0x32ea00=_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0x88')][0x0];if(_0x32ea00['messageId']&&_0x32ea00[_0x5eb4('0x28')][_0x5eb4('0xce')]===_0x5eb4('0xcf')){_0x1f145d=_0x32ea00['status'][_0x5eb4('0xce')];return db['SmsMessage'][_0x5eb4('0x5e')]({'where':{'messageId':_0x32ea00[_0x5eb4('0x7c')]}});}break;case _0x5eb4('0x8c'):if(_0x3ccbd9[_0x5eb4('0x5d')]['messageId']&&_0x3ccbd9['body']['status']){_0x1f145d=_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0x28')];return db[_0x5eb4('0xa4')][_0x5eb4('0x5e')]({'where':{'messageId':_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0x7c')]}});}break;case _0x5eb4('0xd0'):if(_0x3ccbd9[_0x5eb4('0x5d')][0x0][_0x5eb4('0x24')]['id']){_0x1f145d=_0x3ccbd9[_0x5eb4('0x5d')][0x0][_0x5eb4('0x3f')];return db[_0x5eb4('0xa4')][_0x5eb4('0x5e')]({'where':{'messageId':_0x3ccbd9[_0x5eb4('0x5d')][0x0]['message']['id']}});}break;case _0x5eb4('0x8e'):if(_0x3ccbd9['body'][_0x5eb4('0xd1')]&&_0x3ccbd9[_0x5eb4('0x5d')]['status']){_0x1f145d=_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0x28')];return db[_0x5eb4('0xa4')]['find']({'where':{'messageId':_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0xd1')]}});}break;}}})[_0x5eb4('0x1c')](handleEntityNotFound(_0xef6c11,null))[_0x5eb4('0x1c')](function(_0x5e1774){if(_0x5e1774){_0x404920=_0x5e1774;switch(_0x194fee['type']){case _0x5eb4('0x7e'):if(_0x1f145d===_0x5eb4('0xcf')){return _0x404920['update']({'read':!![]});}else{logger[_0x5eb4('0x22')](_0x5eb4('0xab'),_0x5eb4('0x28'),_0x5eb4('0x7e'),util[_0x5eb4('0xc9')](_0x3ccbd9[_0x5eb4('0x5d')],{'showHidden':![],'depth':null}));}break;case'connectel':if(_0x1f145d==='1'){return _0x404920[_0x5eb4('0x33')]({'read':!![]});}else{logger[_0x5eb4('0x22')](_0x5eb4('0xab'),'status',_0x5eb4('0x7e'),util['inspect'](_0x3ccbd9[_0x5eb4('0x5d')],{'showHidden':![],'depth':null}));}break;case _0x5eb4('0x82'):if(!_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0xd2')]&&_0x1f145d>=0xc8&&_0x1f145d<=0xce){return _0x404920[_0x5eb4('0x33')]({'read':!![]});}else{logger[_0x5eb4('0x22')](_0x5eb4('0xab'),'status','clicksend',util[_0x5eb4('0xc9')](_0x3ccbd9[_0x5eb4('0x5d')],{'showHidden':![],'depth':null}));}break;case'infobip':var _0x222b4c=_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0x88')][0x0];if(_0x222b4c[_0x5eb4('0x28')][_0x5eb4('0xce')]===_0x5eb4('0xcf')){return _0x404920[_0x5eb4('0x33')]({'read':!![]});}else{logger[_0x5eb4('0x22')](_0x5eb4('0xab'),_0x5eb4('0x28'),_0x5eb4('0x87'),util['inspect'](_0x3ccbd9[_0x5eb4('0x5d')],{'showHidden':![],'depth':null}));}break;case _0x5eb4('0x8c'):if(_0x1f145d==_0x5eb4('0xd3')||_0x1f145d==_0x5eb4('0xd4')){return _0x404920[_0x5eb4('0x33')]({'read':!![]});}else{logger[_0x5eb4('0x22')](_0x5eb4('0xab'),_0x5eb4('0x28'),_0x5eb4('0x8c'),util[_0x5eb4('0xc9')](_0x3ccbd9[_0x5eb4('0x5d')],{'showHidden':![],'depth':null}));}break;case _0x5eb4('0xd0'):if(_0x1f145d==_0x5eb4('0xd5')){return _0x404920[_0x5eb4('0x33')]({'read':!![]});}else{logger[_0x5eb4('0x22')](_0x5eb4('0xab'),_0x5eb4('0x28'),_0x5eb4('0xd0'),util[_0x5eb4('0xc9')](_0x3ccbd9[_0x5eb4('0x5d')],{'showHidden':![],'depth':null}));}break;case _0x5eb4('0x8e'):if(_0x1f145d===_0x5eb4('0xd6')||_0x1f145d===_0x5eb4('0xd7')){return _0x404920[_0x5eb4('0x33')]({'read':!![]});}else{logger['error'](_0x5eb4('0xab'),'status',_0x5eb4('0x8e'),util[_0x5eb4('0xc9')](_0x3ccbd9[_0x5eb4('0x5d')],{'showHidden':![],'depth':null}));}break;}return _0x404920;}})[_0x5eb4('0x1c')](respondWithResult(_0xef6c11,null))['catch'](handleError(_0xef6c11,null));};exports[_0x5eb4('0xd8')]=function(_0x1b013f,_0x1e649f,_0x3cd88a){var _0x1e461d,_0x2528ab,_0x72f797;return db[_0x5eb4('0x4f')][_0x5eb4('0x5e')]({'where':{'id':_0x1b013f[_0x5eb4('0x54')]['id']}})[_0x5eb4('0x1c')](handleEntityNotFound(_0x1e649f,null))[_0x5eb4('0x1c')](function(_0x176083){if(_0x176083){_0x72f797=_0x176083;logger[_0x5eb4('0x20')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x5eb4('0x28'),_0x5eb4('0xc8'),_0x176083['type'],util[_0x5eb4('0xc9')](_0x1b013f['query'],{'showHidden':![],'depth':null}));switch(_0x176083[_0x5eb4('0x3f')]){case _0x5eb4('0x89'):if(_0x1b013f['query'][_0x5eb4('0xd9')]&&_0x1b013f[_0x5eb4('0x42')][_0x5eb4('0xda')]){_0x2528ab=_0x1b013f['query'][_0x5eb4('0xda')];return db['SmsMessage'][_0x5eb4('0x5e')]({'where':{'messageId':_0x1b013f[_0x5eb4('0x42')][_0x5eb4('0xd9')]}});}break;}}})[_0x5eb4('0x1c')](handleEntityNotFound(_0x1e649f,null))[_0x5eb4('0x1c')](function(_0x136657){if(_0x136657){_0x1e461d=_0x136657;switch(_0x72f797[_0x5eb4('0x3f')]){case _0x5eb4('0x89'):if(_0x2528ab==='2'||_0x2528ab==='6'){return _0x1e461d[_0x5eb4('0x33')]({'read':!![]});}else{logger[_0x5eb4('0x22')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x5eb4('0x28'),_0x5eb4('0x89'),util['inspect'](_0x1b013f['query'],{'showHidden':![],'depth':null}));};break;}return _0x1e461d;}})['then'](respondWithResult(_0x1e649f,null))['catch'](handleError(_0x1e649f,null));};exports[_0x5eb4('0xdb')]=function(_0x32f8a3,_0x41a416,_0x36d17b){return db[_0x5eb4('0x4f')][_0x5eb4('0x5e')]({'where':{'id':_0x32f8a3['params']['id']}})[_0x5eb4('0x1c')](handleEntityNotFound(_0x41a416,null))['then'](function(_0x513fb6){if(_0x513fb6){return _0x513fb6['addAgents'](_0x32f8a3['body'][_0x5eb4('0x68')],_[_0x5eb4('0x99')](_0x32f8a3[_0x5eb4('0x5d')],[_0x5eb4('0x68'),'id'])||{})['spread'](function(_0x237ec1){for(var _0x1fff38=0x0;_0x1fff38<_0x32f8a3['body'][_0x5eb4('0x68')][_0x5eb4('0x47')];_0x1fff38+=0x1){socket[_0x5eb4('0xdc')](_0x5eb4('0xdd'),{'UserId':Number(_0x32f8a3[_0x5eb4('0x5d')][_0x5eb4('0x68')][_0x1fff38]),'SmsAccountId':Number(_0x32f8a3[_0x5eb4('0x54')]['id'])});}return _0x237ec1;});}})[_0x5eb4('0x1c')](respondWithResult(_0x41a416,null))[_0x5eb4('0x26')](handleError(_0x41a416,null));};exports[_0x5eb4('0xde')]=function(_0xb2ec0b,_0xb4d50c,_0x20f89e){return db[_0x5eb4('0x4f')][_0x5eb4('0x5e')]({'where':{'id':_0xb2ec0b[_0x5eb4('0x54')]['id']}})['then'](handleEntityNotFound(_0xb4d50c,null))['then'](function(_0x20e9af){if(_0x20e9af){return _0x20e9af[_0x5eb4('0xde')](_0xb2ec0b[_0x5eb4('0x42')][_0x5eb4('0x68')])[_0x5eb4('0x1c')](function(){if(_[_0x5eb4('0xdf')](_0xb2ec0b[_0x5eb4('0x42')][_0x5eb4('0x68')])){for(var _0x2ef2b7=0x0;_0x2ef2b7<_0xb2ec0b[_0x5eb4('0x42')][_0x5eb4('0x68')][_0x5eb4('0x47')];_0x2ef2b7+=0x1){socket[_0x5eb4('0xdc')]('userSmsAccount:remove',{'UserId':Number(_0xb2ec0b[_0x5eb4('0x42')][_0x5eb4('0x68')][_0x2ef2b7]),'SmsAccountId':Number(_0xb2ec0b[_0x5eb4('0x54')]['id'])});}}else{socket['emit'](_0x5eb4('0xe0'),{'UserId':Number(_0xb2ec0b[_0x5eb4('0x42')][_0x5eb4('0x68')]),'SmsAccountId':Number(_0xb2ec0b[_0x5eb4('0x54')]['id'])});}});}})[_0x5eb4('0x1c')](respondWithStatusCode(_0xb4d50c,null))['catch'](handleError(_0xb4d50c,null));};exports[_0x5eb4('0xe1')]=function(_0x25b2c7,_0x27cc7b,_0x2d411c){var _0x38026c={};var _0x462e2b={};var _0x2f6078;var _0x2908b4;return db[_0x5eb4('0x4f')]['findOne']({'where':{'id':_0x25b2c7[_0x5eb4('0x54')]['id']}})['then'](handleEntityNotFound(_0x27cc7b,null))[_0x5eb4('0x1c')](function(_0x514b7c){if(_0x514b7c){_0x2f6078=_0x514b7c;_0x462e2b[_0x5eb4('0x41')]=_[_0x5eb4('0x43')](db['User']['rawAttributes']);_0x462e2b[_0x5eb4('0x42')]=_[_0x5eb4('0x43')](_0x25b2c7[_0x5eb4('0x42')]);_0x462e2b[_0x5eb4('0x44')]=_['intersection'](_0x462e2b[_0x5eb4('0x41')],_0x462e2b[_0x5eb4('0x42')]);_0x38026c[_0x5eb4('0x45')]=_[_0x5eb4('0x46')](_0x462e2b[_0x5eb4('0x41')],qs['fields'](_0x25b2c7[_0x5eb4('0x42')][_0x5eb4('0x55')]));_0x38026c[_0x5eb4('0x45')]=_0x38026c['attributes'][_0x5eb4('0x47')]?_0x38026c[_0x5eb4('0x45')]:_0x462e2b[_0x5eb4('0x41')];_0x38026c[_0x5eb4('0x65')]=qs[_0x5eb4('0x49')](_0x25b2c7[_0x5eb4('0x42')][_0x5eb4('0x49')]);_0x38026c[_0x5eb4('0x4a')]=qs[_0x5eb4('0x44')](_[_0x5eb4('0x4b')](_0x25b2c7['query'],_0x462e2b[_0x5eb4('0x44')]));if(_0x25b2c7[_0x5eb4('0x42')]['filter']){_0x38026c['where']=_[_0x5eb4('0x4c')](_0x38026c[_0x5eb4('0x4a')],{'$or':_['map'](_0x38026c[_0x5eb4('0x45')],function(_0x559903){var _0x1441bf={};_0x1441bf[_0x559903]={'$like':'%'+_0x25b2c7['query'][_0x5eb4('0x4e')]+'%'};return _0x1441bf;})});}_0x38026c=_['merge']({},_0x38026c,_0x25b2c7[_0x5eb4('0x56')]);return _0x2f6078[_0x5eb4('0xe1')](_0x38026c);}})[_0x5eb4('0x1c')](function(_0x57ab24){if(_0x57ab24){_0x2908b4=_0x57ab24[_0x5eb4('0x47')];if(!_0x25b2c7['query'][_0x5eb4('0x48')](_0x5eb4('0xbb'))){_0x38026c['limit']=qs[_0x5eb4('0x2b')](_0x25b2c7[_0x5eb4('0x42')]['limit']);_0x38026c[_0x5eb4('0x2e')]=qs[_0x5eb4('0x2e')](_0x25b2c7['query'][_0x5eb4('0x2e')]);}return _0x2f6078[_0x5eb4('0xe1')](_0x38026c);}})['then'](function(_0xcdb696){if(_0xcdb696){return _0xcdb696?{'count':_0x2908b4,'rows':_0xcdb696}:null;}})['then'](respondWithResult(_0x27cc7b,null))[_0x5eb4('0x26')](handleError(_0x27cc7b,null));};
\ No newline at end of file