Built motion from commit da617fac.|2.6.6
[motion2.git] / server / api / smsAccount / smsAccount.controller.js
index 53bf926..3732541 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 _0xc187=['request\x20sent','stringify','error','code','message','result','catch','status','end','json','undefined','count','offset','limit','Content-Range','apply','reject','update','SmsAccounts','UserProfileResource','destroy','sendStatus','stack','name','Pause','mandatoryDispositionPause','SmsAccount','rawAttributes','fieldName','type','key','model','map','query','keys','filters','intersection','fields','attributes','length','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','includeAll','findAll','params','include','options','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','get','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','addDisposition','SmsAccountId','Disposition','getDispositions','findOne','rows','removeDispositions','ids','CannedAnswer','getAnswers','Applications','orderBy','priority','account','CmContact','Sequelize','ValidationError','no\x20available\x20attributes','updatedAt','createdAt','CompanyId','ListId','mobile','twilio','from','From','Body','messageId','skebby','sender','text','connectel','clicksend','message_id','plivo','MessageUUID','infobip','results','csc','originatingAddress','segmentedMessage','replyMessageId','intelepeer','refid','isNil','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','CmList','DESC','omit','Contacts','contact','interaction','autoclose','push','close','unmanaged','created','SmsMessage','UserId','User','unshift','agent','waitForTheAssignedAgent','*,*,*,*','startRouting','entity\x20found','SmsAccount,\x20%s,\x20%s,\x20%s,\x20%s','set','Content-Type','text/xml','send','addApplications','sequelize','transaction','Transaction','ISOLATION_LEVELS','READ_COMMITTED','SmsApplication','bulkCreate','findAndCountAll','finally','getApplications','hasOwnProperty','SmsInteraction','Contact','Owner','internal','Tag','Tags','color','tag','to\x20is\x20mandatory','List','Messages','dataValues','received\x20delivery\x20report\x20from','inspect','skebby_dispatch_id','requestid','statusInt','status_code','groupName','DELIVERED','clickatell','bandwidth','error_code','RECEIVED_BY_RECIPIENT','DELIVRD','ACCEPTD','statusGet','message-id','state','emit','userSmsAccount:save','isArray','userSmsAccount:remove','getAgents','rimraf','zip-dir','fast-json-patch','moment','mustache','util','sox','ejs','fs-extra','lodash','squel','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./smsAccount.socket','register','client','http','request','then','info','SmsAccount,\x20%s,\x20%s','debug','SmsAccount,\x20%s,\x20%s,\x20%s'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0xc187,0xb8));var _0x7c18=function(_0x126558,_0x143c9a){_0x126558=_0x126558-0x0;var _0x1f6d14=_0xc187[_0x126558];return _0x1f6d14;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x7c18('0x0'));var zipdir=require(_0x7c18('0x1'));var jsonpatch=require(_0x7c18('0x2'));var rp=require('request-promise');var moment=require(_0x7c18('0x3'));var BPromise=require('bluebird');var Mustache=require(_0x7c18('0x4'));var util=require(_0x7c18('0x5'));var path=require('path');var sox=require(_0x7c18('0x6'));var csv=require('to-csv');var ejs=require(_0x7c18('0x7'));var fs=require('fs');var fs_extra=require(_0x7c18('0x8'));var _=require(_0x7c18('0x9'));var squel=require(_0x7c18('0xa'));var crypto=require('crypto');var jsforce=require(_0x7c18('0xb'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x7c18('0xc'));var Papa=require(_0x7c18('0xd'));var Redis=require(_0x7c18('0xe'));var authService=require(_0x7c18('0xf'));var qs=require(_0x7c18('0x10'));var as=require(_0x7c18('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x7c18('0x12'))('api');var utils=require(_0x7c18('0x13'));var config=require(_0x7c18('0x14'));var licenseUtil=require(_0x7c18('0x15'));var db=require(_0x7c18('0x16'))['db'];config[_0x7c18('0x17')]=_[_0x7c18('0x18')](config[_0x7c18('0x17')],{'host':_0x7c18('0x19'),'port':0x18eb});var socket=require(_0x7c18('0x1a'))(new Redis(config[_0x7c18('0x17')]));require(_0x7c18('0x1b'))[_0x7c18('0x1c')](socket);var jayson=require('jayson/promise');var client=jayson[_0x7c18('0x1d')][_0x7c18('0x1e')]({'port':0x232c});function respondWithRpcPromise(_0x4ae8d7,_0x5b9382,_0x7d93bc,_0x1c7c8c){return new BPromise(function(_0x574f7f,_0x1f5b9a){var _0x3ffce3=_0x1c7c8c||client;return _0x3ffce3[_0x7c18('0x1f')](_0x4ae8d7,_0x7d93bc)[_0x7c18('0x20')](function(_0x334761){logger[_0x7c18('0x21')](_0x7c18('0x22'),_0x5b9382,'request\x20sent');logger[_0x7c18('0x23')](_0x7c18('0x24'),_0x5b9382,_0x7c18('0x25'),JSON[_0x7c18('0x26')](_0x334761));if(_0x334761['error']){if(_0x334761[_0x7c18('0x27')][_0x7c18('0x28')]===0x1f4){logger['error'](_0x7c18('0x22'),_0x5b9382,_0x334761[_0x7c18('0x27')][_0x7c18('0x29')]);return _0x1f5b9a(_0x334761[_0x7c18('0x27')][_0x7c18('0x29')]);}logger[_0x7c18('0x27')](_0x7c18('0x22'),_0x5b9382,_0x334761['error'][_0x7c18('0x29')]);return _0x574f7f(_0x334761['error'][_0x7c18('0x29')]);}else{logger[_0x7c18('0x21')]('SmsAccount,\x20%s,\x20%s',_0x5b9382,_0x7c18('0x25'));_0x574f7f(_0x334761[_0x7c18('0x2a')]['message']);}})[_0x7c18('0x2b')](function(_0x11ca4e){logger[_0x7c18('0x27')](_0x7c18('0x22'),_0x5b9382,_0x11ca4e);_0x1f5b9a(_0x11ca4e);});});}function respondWithStatusCode(_0x39cf8d,_0x43d411){_0x43d411=_0x43d411||0xcc;return function(_0x4a9a22){if(_0x4a9a22){return _0x39cf8d['sendStatus'](_0x43d411);}return _0x39cf8d[_0x7c18('0x2c')](_0x43d411)[_0x7c18('0x2d')]();};}function respondWithResult(_0x12ddb3,_0x32d165){_0x32d165=_0x32d165||0xc8;return function(_0xe64f5d){if(_0xe64f5d){return _0x12ddb3[_0x7c18('0x2c')](_0x32d165)[_0x7c18('0x2e')](_0xe64f5d);}};}function respondWithFilteredResult(_0xf13e7b,_0x3bc3f8){return function(_0x217422){if(_0x217422){var _0x13c66f=typeof _0x3bc3f8['offset']===_0x7c18('0x2f')&&typeof _0x3bc3f8['limit']===_0x7c18('0x2f');var _0x58034a=_0x217422[_0x7c18('0x30')];var _0x8f538d=_0x13c66f?0x0:_0x3bc3f8[_0x7c18('0x31')];var _0x33e3d2=_0x13c66f?_0x217422[_0x7c18('0x30')]:_0x3bc3f8[_0x7c18('0x31')]+_0x3bc3f8[_0x7c18('0x32')];var _0x2664c1;if(_0x33e3d2>=_0x58034a){_0x33e3d2=_0x58034a;_0x2664c1=0xc8;}else{_0x2664c1=0xce;}_0xf13e7b[_0x7c18('0x2c')](_0x2664c1);return _0xf13e7b['set'](_0x7c18('0x33'),_0x8f538d+'-'+_0x33e3d2+'/'+_0x58034a)[_0x7c18('0x2e')](_0x217422);}return null;};}function patchUpdates(_0x3b0bd3){return function(_0xfc4c08){try{jsonpatch[_0x7c18('0x34')](_0xfc4c08,_0x3b0bd3,!![]);}catch(_0x4f3953){return BPromise[_0x7c18('0x35')](_0x4f3953);}return _0xfc4c08['save']();};}function saveUpdates(_0x4f0218,_0x4f1021){return function(_0x42d27b){if(_0x42d27b){return _0x42d27b[_0x7c18('0x36')](_0x4f0218)['then'](function(_0x5bec76){return _0x5bec76;});}return null;};}function removeEntity(_0x33ab42,_0x5b9af9){return function(_0x26312a){if(_0x26312a){return _0x26312a['destroy']()['then'](function(){var _0x1680dd=_0x26312a['get']({'plain':!![]});var _0x510f53=_0x7c18('0x37');return db[_0x7c18('0x38')][_0x7c18('0x39')]({'where':{'type':_0x510f53,'resourceId':_0x1680dd['id']}})['then'](function(){return _0x26312a;});})[_0x7c18('0x20')](function(){_0x33ab42['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x425263,_0xd047ea){return function(_0x31ff85){if(!_0x31ff85){_0x425263[_0x7c18('0x3a')](0x194);}return _0x31ff85;};}function handleError(_0x6918e5,_0x57f687){_0x57f687=_0x57f687||0x1f4;return function(_0x370f9f){logger[_0x7c18('0x27')](_0x370f9f[_0x7c18('0x3b')]);if(_0x370f9f[_0x7c18('0x3c')]){delete _0x370f9f[_0x7c18('0x3c')];}_0x6918e5[_0x7c18('0x2c')](_0x57f687)['send'](_0x370f9f);};}exports['index']=function(_0x5b4d08,_0x5bf0ed){var _0x561d48={'include':[{'model':db[_0x7c18('0x3d')],'as':_0x7c18('0x3e')}]},_0x5eb731={},_0x1e75e0={'count':0x0,'rows':[]};var _0x389292=_['map'](db[_0x7c18('0x3f')][_0x7c18('0x40')],function(_0x55f30c){return{'name':_0x55f30c[_0x7c18('0x41')],'type':_0x55f30c[_0x7c18('0x42')][_0x7c18('0x43')]};});_0x5eb731[_0x7c18('0x44')]=_[_0x7c18('0x45')](_0x389292,_0x7c18('0x3c'));_0x5eb731[_0x7c18('0x46')]=_[_0x7c18('0x47')](_0x5b4d08[_0x7c18('0x46')]);_0x5eb731[_0x7c18('0x48')]=_[_0x7c18('0x49')](_0x5eb731[_0x7c18('0x44')],_0x5eb731[_0x7c18('0x46')]);_0x561d48['attributes']=_[_0x7c18('0x49')](_0x5eb731['model'],qs[_0x7c18('0x4a')](_0x5b4d08[_0x7c18('0x46')][_0x7c18('0x4a')]));_0x561d48[_0x7c18('0x4b')]=_0x561d48['attributes'][_0x7c18('0x4c')]?_0x561d48[_0x7c18('0x4b')]:_0x5eb731[_0x7c18('0x44')];if(!_0x5b4d08[_0x7c18('0x46')]['hasOwnProperty'](_0x7c18('0x4d'))){_0x561d48[_0x7c18('0x32')]=qs[_0x7c18('0x32')](_0x5b4d08[_0x7c18('0x46')][_0x7c18('0x32')]);_0x561d48[_0x7c18('0x31')]=qs[_0x7c18('0x31')](_0x5b4d08[_0x7c18('0x46')][_0x7c18('0x31')]);}_0x561d48[_0x7c18('0x4e')]=qs[_0x7c18('0x4f')](_0x5b4d08[_0x7c18('0x46')][_0x7c18('0x4f')]);_0x561d48[_0x7c18('0x50')]=qs[_0x7c18('0x48')](_[_0x7c18('0x51')](_0x5b4d08[_0x7c18('0x46')],_0x5eb731[_0x7c18('0x48')]),_0x389292);if(_0x5b4d08[_0x7c18('0x46')][_0x7c18('0x52')]){_0x561d48[_0x7c18('0x50')]=_[_0x7c18('0x53')](_0x561d48[_0x7c18('0x50')],{'$or':_[_0x7c18('0x45')](_0x389292,function(_0x3b33ba){if(_0x3b33ba['type']!==_0x7c18('0x54')){var _0x48d4cc={};_0x48d4cc[_0x3b33ba['name']]={'$like':'%'+_0x5b4d08[_0x7c18('0x46')][_0x7c18('0x52')]+'%'};return _0x48d4cc;}})});}_0x561d48=_[_0x7c18('0x53')]({},_0x561d48,_0x5b4d08['options']);var _0x1bcf7c={'where':_0x561d48[_0x7c18('0x50')]};return db[_0x7c18('0x3f')]['count'](_0x1bcf7c)[_0x7c18('0x20')](function(_0x754f37){_0x1e75e0['count']=_0x754f37;if(_0x5b4d08[_0x7c18('0x46')][_0x7c18('0x55')]){_0x561d48['include']=[{'all':!![]}];}return db[_0x7c18('0x3f')][_0x7c18('0x56')](_0x561d48);})['then'](function(_0x257996){_0x1e75e0['rows']=_0x257996;return _0x1e75e0;})['then'](respondWithFilteredResult(_0x5bf0ed,_0x561d48))[_0x7c18('0x2b')](handleError(_0x5bf0ed,null));};exports['show']=function(_0x1ffb01,_0x49303f){var _0x1de27c={'raw':![],'where':{'id':_0x1ffb01[_0x7c18('0x57')]['id']},'include':[{'model':db[_0x7c18('0x3d')],'as':'mandatoryDispositionPause'}]},_0x762729={};_0x762729[_0x7c18('0x44')]=_[_0x7c18('0x47')](db[_0x7c18('0x3f')][_0x7c18('0x40')]);_0x762729[_0x7c18('0x46')]=_[_0x7c18('0x47')](_0x1ffb01[_0x7c18('0x46')]);_0x762729[_0x7c18('0x48')]=_[_0x7c18('0x49')](_0x762729[_0x7c18('0x44')],_0x762729['query']);_0x1de27c['attributes']=_[_0x7c18('0x49')](_0x762729['model'],qs[_0x7c18('0x4a')](_0x1ffb01[_0x7c18('0x46')][_0x7c18('0x4a')]));_0x1de27c[_0x7c18('0x4b')]=_0x1de27c[_0x7c18('0x4b')][_0x7c18('0x4c')]?_0x1de27c[_0x7c18('0x4b')]:_0x762729['model'];if(_0x1ffb01[_0x7c18('0x46')][_0x7c18('0x55')]){_0x1de27c[_0x7c18('0x58')]=[{'all':!![]}];}_0x1de27c=_[_0x7c18('0x53')]({},_0x1de27c,_0x1ffb01[_0x7c18('0x59')]);return db['SmsAccount'][_0x7c18('0x5a')](_0x1de27c)['then'](handleEntityNotFound(_0x49303f,null))[_0x7c18('0x20')](respondWithResult(_0x49303f,null))['catch'](handleError(_0x49303f,null));};exports[_0x7c18('0x5b')]=function(_0xe7d611,_0x5e9fb2){return db[_0x7c18('0x3f')]['create'](_0xe7d611[_0x7c18('0x5c')],{})[_0x7c18('0x20')](function(_0x55f4a1){var _0x465851=_0xe7d611[_0x7c18('0x5d')]['get']({'plain':!![]});if(!_0x465851)throw new Error(_0x7c18('0x5e'));if(_0x465851[_0x7c18('0x5f')]==='user'){var _0x3090cb=_0x55f4a1[_0x7c18('0x60')]({'plain':!![]});var _0x486c57=_0x7c18('0x37');return db[_0x7c18('0x61')]['find']({'where':{'name':_0x486c57,'userProfileId':_0x465851[_0x7c18('0x62')]},'raw':!![]})[_0x7c18('0x20')](function(_0x51e803){if(_0x51e803&&_0x51e803[_0x7c18('0x63')]===0x0){return db['UserProfileResource'][_0x7c18('0x5b')]({'name':_0x3090cb[_0x7c18('0x3c')],'resourceId':_0x3090cb['id'],'type':_0x51e803[_0x7c18('0x3c')],'sectionId':_0x51e803['id']},{})[_0x7c18('0x20')](function(){return _0x55f4a1;});}else{return _0x55f4a1;}})['catch'](function(_0x2d2775){logger[_0x7c18('0x27')](_0x7c18('0x64'),_0x2d2775);throw _0x2d2775;});}return _0x55f4a1;})[_0x7c18('0x20')](respondWithResult(_0x5e9fb2,0xc9))[_0x7c18('0x2b')](handleError(_0x5e9fb2,null));};exports['update']=function(_0x14333a,_0x3e07a0){if(_0x14333a['body']['id']){delete _0x14333a[_0x7c18('0x5c')]['id'];}return db[_0x7c18('0x3f')][_0x7c18('0x5a')]({'where':{'id':_0x14333a[_0x7c18('0x57')]['id']},'include':[{'model':db['Pause'],'as':'mandatoryDispositionPause'}]})[_0x7c18('0x20')](handleEntityNotFound(_0x3e07a0,null))[_0x7c18('0x20')](saveUpdates(_0x14333a[_0x7c18('0x5c')],null))[_0x7c18('0x20')](respondWithResult(_0x3e07a0,null))[_0x7c18('0x2b')](handleError(_0x3e07a0,null));};exports[_0x7c18('0x39')]=function(_0x2475f8,_0x1412d2){return db['SmsAccount'][_0x7c18('0x5a')]({'where':{'id':_0x2475f8['params']['id']}})['then'](handleEntityNotFound(_0x1412d2,null))[_0x7c18('0x20')](removeEntity(_0x1412d2,null))[_0x7c18('0x2b')](handleError(_0x1412d2,null));};exports[_0x7c18('0x65')]=function(_0x5c9278,_0x5ad530){return db[_0x7c18('0x3f')]['describe']()['then'](respondWithResult(_0x5ad530,null))[_0x7c18('0x2b')](handleError(_0x5ad530,null));};exports[_0x7c18('0x66')]=function(_0x45bcd2,_0x45a3b0,_0x13b812){if(_0x45bcd2[_0x7c18('0x5c')]['id']){delete _0x45bcd2[_0x7c18('0x5c')]['id'];}return db['SmsAccount'][_0x7c18('0x5a')]({'where':{'id':_0x45bcd2[_0x7c18('0x57')]['id']}})[_0x7c18('0x20')](handleEntityNotFound(_0x45a3b0,null))[_0x7c18('0x20')](function(_0x590fcc){if(_0x590fcc){_0x45bcd2[_0x7c18('0x5c')][_0x7c18('0x67')]=_0x590fcc['id'];return db[_0x7c18('0x68')][_0x7c18('0x5b')](_0x45bcd2[_0x7c18('0x5c')]);}})[_0x7c18('0x20')](respondWithResult(_0x45a3b0,null))[_0x7c18('0x2b')](handleError(_0x45a3b0,null));};exports[_0x7c18('0x69')]=function(_0x524d3f,_0x3df78d,_0xee1f1f){var _0x59e2ed={'raw':![],'where':{}};var _0x1b00c6={};var _0x1036a5={'count':0x0,'rows':[]};return db[_0x7c18('0x3f')][_0x7c18('0x6a')]({'where':{'id':_0x524d3f[_0x7c18('0x57')]['id']}})['then'](handleEntityNotFound(_0x3df78d,null))[_0x7c18('0x20')](function(_0x1ef77f){if(_0x1ef77f){_0x1b00c6[_0x7c18('0x44')]=_[_0x7c18('0x47')](db[_0x7c18('0x68')][_0x7c18('0x40')]);_0x1b00c6[_0x7c18('0x46')]=_[_0x7c18('0x47')](_0x524d3f['query']);_0x1b00c6['filters']=_[_0x7c18('0x49')](_0x1b00c6[_0x7c18('0x44')],_0x1b00c6[_0x7c18('0x46')]);_0x59e2ed[_0x7c18('0x4b')]=_['intersection'](_0x1b00c6[_0x7c18('0x44')],qs['fields'](_0x524d3f['query'][_0x7c18('0x4a')]));_0x59e2ed[_0x7c18('0x4b')]=_0x59e2ed['attributes'][_0x7c18('0x4c')]?_0x59e2ed[_0x7c18('0x4b')]:_0x1b00c6[_0x7c18('0x44')];if(!_0x524d3f['query']['hasOwnProperty'](_0x7c18('0x4d'))){_0x59e2ed[_0x7c18('0x32')]=qs['limit'](_0x524d3f['query'][_0x7c18('0x32')]);_0x59e2ed[_0x7c18('0x31')]=qs[_0x7c18('0x31')](_0x524d3f[_0x7c18('0x46')][_0x7c18('0x31')]);}_0x59e2ed[_0x7c18('0x4e')]=qs[_0x7c18('0x4f')](_0x524d3f[_0x7c18('0x46')][_0x7c18('0x4f')]);_0x59e2ed[_0x7c18('0x50')]=qs[_0x7c18('0x48')](_[_0x7c18('0x51')](_0x524d3f[_0x7c18('0x46')],_0x1b00c6[_0x7c18('0x48')]));_0x59e2ed[_0x7c18('0x50')]['SmsAccountId']=_0x1ef77f['id'];if(_0x524d3f[_0x7c18('0x46')]['filter']){_0x59e2ed[_0x7c18('0x50')]=_['merge'](_0x59e2ed[_0x7c18('0x50')],{'$or':_['map'](_0x59e2ed[_0x7c18('0x4b')],function(_0x128d84){var _0x3702d3={};_0x3702d3[_0x128d84]={'$like':'%'+_0x524d3f['query'][_0x7c18('0x52')]+'%'};return _0x3702d3;})});}_0x59e2ed=_[_0x7c18('0x53')]({},_0x59e2ed,_0x524d3f[_0x7c18('0x59')]);return db['Disposition'][_0x7c18('0x30')]({'where':_0x59e2ed[_0x7c18('0x50')]})['then'](function(_0x4c30a2){_0x1036a5[_0x7c18('0x30')]=_0x4c30a2;if(_0x524d3f[_0x7c18('0x46')][_0x7c18('0x55')]){_0x59e2ed['include']=[{'all':!![]}];}return db[_0x7c18('0x68')][_0x7c18('0x56')](_0x59e2ed);})['then'](function(_0xb722e5){_0x1036a5[_0x7c18('0x6b')]=_0xb722e5;return _0x1036a5;});}})[_0x7c18('0x20')](respondWithFilteredResult(_0x3df78d,_0x59e2ed))['catch'](handleError(_0x3df78d,null));};exports[_0x7c18('0x6c')]=function(_0x2197fa,_0xbd8e11,_0xc1cf51){return db[_0x7c18('0x3f')][_0x7c18('0x5a')]({'where':{'id':_0x2197fa[_0x7c18('0x57')]['id']}})[_0x7c18('0x20')](handleEntityNotFound(_0xbd8e11,null))[_0x7c18('0x20')](function(_0x492357){if(_0x492357){return _0x492357[_0x7c18('0x6c')](_0x2197fa[_0x7c18('0x46')][_0x7c18('0x6d')]);}})[_0x7c18('0x20')](respondWithStatusCode(_0xbd8e11,null))[_0x7c18('0x2b')](handleError(_0xbd8e11,null));};exports['addAnswer']=function(_0x3bd0a7,_0x72403f,_0x2eb4ee){if(_0x3bd0a7[_0x7c18('0x5c')]['id']){delete _0x3bd0a7[_0x7c18('0x5c')]['id'];}return db['SmsAccount'][_0x7c18('0x5a')]({'where':{'id':_0x3bd0a7[_0x7c18('0x57')]['id']}})[_0x7c18('0x20')](handleEntityNotFound(_0x72403f,null))[_0x7c18('0x20')](function(_0x3eba40){if(_0x3eba40){_0x3bd0a7[_0x7c18('0x5c')][_0x7c18('0x67')]=_0x3eba40['id'];return db[_0x7c18('0x6e')][_0x7c18('0x5b')](_0x3bd0a7['body']);}})[_0x7c18('0x20')](respondWithResult(_0x72403f,null))[_0x7c18('0x2b')](handleError(_0x72403f,null));};exports[_0x7c18('0x6f')]=function(_0x167e30,_0xb30dfc,_0x298abc){var _0x49af51={'raw':![],'where':{}};var _0x259cb6={};var _0x1c67a0={'count':0x0,'rows':[]};return db[_0x7c18('0x3f')][_0x7c18('0x6a')]({'where':{'id':_0x167e30['params']['id']}})['then'](handleEntityNotFound(_0xb30dfc,null))[_0x7c18('0x20')](function(_0x28bf21){if(_0x28bf21){_0x259cb6[_0x7c18('0x44')]=_[_0x7c18('0x47')](db['CannedAnswer'][_0x7c18('0x40')]);_0x259cb6[_0x7c18('0x46')]=_[_0x7c18('0x47')](_0x167e30['query']);_0x259cb6[_0x7c18('0x48')]=_[_0x7c18('0x49')](_0x259cb6[_0x7c18('0x44')],_0x259cb6[_0x7c18('0x46')]);_0x49af51['attributes']=_[_0x7c18('0x49')](_0x259cb6[_0x7c18('0x44')],qs['fields'](_0x167e30[_0x7c18('0x46')]['fields']));_0x49af51[_0x7c18('0x4b')]=_0x49af51['attributes'][_0x7c18('0x4c')]?_0x49af51[_0x7c18('0x4b')]:_0x259cb6['model'];if(!_0x167e30[_0x7c18('0x46')]['hasOwnProperty'](_0x7c18('0x4d'))){_0x49af51['limit']=qs[_0x7c18('0x32')](_0x167e30[_0x7c18('0x46')][_0x7c18('0x32')]);_0x49af51['offset']=qs['offset'](_0x167e30[_0x7c18('0x46')]['offset']);}_0x49af51[_0x7c18('0x4e')]=qs[_0x7c18('0x4f')](_0x167e30[_0x7c18('0x46')][_0x7c18('0x4f')]);_0x49af51['where']=qs[_0x7c18('0x48')](_['pick'](_0x167e30[_0x7c18('0x46')],_0x259cb6[_0x7c18('0x48')]));_0x49af51[_0x7c18('0x50')][_0x7c18('0x67')]=_0x28bf21['id'];if(_0x167e30[_0x7c18('0x46')][_0x7c18('0x52')]){_0x49af51['where']=_[_0x7c18('0x53')](_0x49af51[_0x7c18('0x50')],{'$or':_[_0x7c18('0x45')](_0x49af51[_0x7c18('0x4b')],function(_0x11bf85){var _0x256fc8={};_0x256fc8[_0x11bf85]={'$like':'%'+_0x167e30['query'][_0x7c18('0x52')]+'%'};return _0x256fc8;})});}_0x49af51=_[_0x7c18('0x53')]({},_0x49af51,_0x167e30[_0x7c18('0x59')]);return db['CannedAnswer']['count']({'where':_0x49af51[_0x7c18('0x50')]})['then'](function(_0x17bfeb){_0x1c67a0['count']=_0x17bfeb;if(_0x167e30['query']['includeAll']){_0x49af51['include']=[{'all':!![]}];}return db[_0x7c18('0x6e')][_0x7c18('0x56')](_0x49af51);})[_0x7c18('0x20')](function(_0x53fbe4){_0x1c67a0[_0x7c18('0x6b')]=_0x53fbe4;return _0x1c67a0;});}})['then'](respondWithFilteredResult(_0xb30dfc,_0x49af51))[_0x7c18('0x2b')](handleError(_0xb30dfc,null));};exports['removeAnswers']=function(_0x28a267,_0x55b0bd,_0x2fc1e4){return db[_0x7c18('0x3f')][_0x7c18('0x5a')]({'where':{'id':_0x28a267[_0x7c18('0x57')]['id']}})[_0x7c18('0x20')](handleEntityNotFound(_0x55b0bd,null))[_0x7c18('0x20')](function(_0x4df3c5){if(_0x4df3c5){return _0x4df3c5['removeAnswers'](_0x28a267[_0x7c18('0x46')][_0x7c18('0x6d')]);}})['then'](respondWithStatusCode(_0x55b0bd,null))[_0x7c18('0x2b')](handleError(_0x55b0bd,null));};exports['notify']=function(_0x3a23b1,_0x3ba2dd,_0x36d11c){var _0x2e1998={'channel':'sms'};var _0x2b673f=[];var _0x286f16=[];var _0x2417da={};return db['SmsAccount'][_0x7c18('0x5a')]({'where':{'id':_0x3a23b1[_0x7c18('0x57')]['id']},'include':[{'model':db['SmsApplication'],'as':_0x7c18('0x70')}]})[_0x7c18('0x20')](handleEntityNotFound(_0x3ba2dd,null))['then'](function(_0x4f0d2d){_0x2e1998['account']=_0x4f0d2d;_0x2e1998['applications']=_[_0x7c18('0x71')](_0x4f0d2d[_0x7c18('0x70')],[_0x7c18('0x72')],['asc']);if(_0x2e1998[_0x7c18('0x73')][_0x7c18('0x70')]){delete _0x2e1998[_0x7c18('0x73')][_0x7c18('0x70')];}return db[_0x7c18('0x74')][_0x7c18('0x65')]();})['then'](function(_0x16d8e6){if(!_0x16d8e6){throw new db[(_0x7c18('0x75'))][(_0x7c18('0x76'))](_0x7c18('0x77'));}_0x2b673f=_['difference'](_[_0x7c18('0x47')](_0x16d8e6),['createdAt',_0x7c18('0x78')]);_0x286f16=_['difference'](_[_0x7c18('0x47')](_0x16d8e6),[_0x7c18('0x79'),_0x7c18('0x78'),_0x7c18('0x7a'),_0x7c18('0x7b')]);_0x2e1998[_0x7c18('0x5c')]={'mapKey':_0x7c18('0x7c')};if(_0x2e1998[_0x7c18('0x73')][_0x7c18('0x42')]){switch(_0x2e1998['account'][_0x7c18('0x42')]){case _0x7c18('0x7d'):_0x2e1998['body'][_0x7c18('0x7e')]=_0x3a23b1[_0x7c18('0x5c')][_0x7c18('0x7f')];_0x2e1998['body'][_0x7c18('0x5c')]=_0x3a23b1[_0x7c18('0x5c')][_0x7c18('0x80')];_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x81')]=_0x3a23b1['body']['MessageSid'];break;case _0x7c18('0x82'):_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x7e')]='+'+_0x3a23b1['body'][_0x7c18('0x83')];_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x5c')]=_0x3a23b1[_0x7c18('0x5c')][_0x7c18('0x84')];break;case _0x7c18('0x85'):_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x7e')]=_0x3a23b1[_0x7c18('0x5c')][_0x7c18('0x7e')];_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x5c')]=_0x3a23b1[_0x7c18('0x5c')]['message'];break;case _0x7c18('0x86'):_0x2e1998['body'][_0x7c18('0x7e')]=_0x3a23b1[_0x7c18('0x5c')][_0x7c18('0x7e')];_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x5c')]=_0x3a23b1[_0x7c18('0x5c')][_0x7c18('0x5c')];_0x2e1998['body'][_0x7c18('0x81')]=_0x3a23b1['body'][_0x7c18('0x87')];break;case _0x7c18('0x88'):_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x7e')]=_0x3a23b1[_0x7c18('0x5c')][_0x7c18('0x7f')];_0x2e1998['body'][_0x7c18('0x5c')]=_0x3a23b1[_0x7c18('0x5c')]['Text'];_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x81')]=_0x3a23b1['body'][_0x7c18('0x89')];break;case _0x7c18('0x8a'):_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x7e')]='+'+_0x3a23b1[_0x7c18('0x5c')]['results'][0x0][_0x7c18('0x7e')];_0x2e1998[_0x7c18('0x5c')]['body']=_0x3a23b1[_0x7c18('0x5c')][_0x7c18('0x8b')][0x0][_0x7c18('0x84')];_0x2e1998[_0x7c18('0x5c')]['messageId']=_0x3a23b1[_0x7c18('0x5c')][_0x7c18('0x8b')][0x0][_0x7c18('0x81')];break;case _0x7c18('0x8c'):_0x2e1998['body'][_0x7c18('0x7e')]=_0x3a23b1[_0x7c18('0x5c')][_0x7c18('0x8d')];_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x5c')]=_0x3a23b1[_0x7c18('0x5c')][_0x7c18('0x8e')]['message'];break;case'clickatell':_0x2e1998[_0x7c18('0x5c')]['from']=_0x3a23b1['body']['fromNumber'];_0x2e1998[_0x7c18('0x5c')]['body']=_0x3a23b1[_0x7c18('0x5c')]['text'];_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x81')]=_0x3a23b1[_0x7c18('0x5c')][_0x7c18('0x8f')];break;case'bandwidth':_0x2e1998['body'][_0x7c18('0x81')]=_0x3a23b1['body'][0x0][_0x7c18('0x29')]['id'];_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x7e')]=_0x3a23b1['body'][0x0][_0x7c18('0x29')][_0x7c18('0x7e')];_0x2e1998[_0x7c18('0x5c')]['body']=_0x3a23b1[_0x7c18('0x5c')][0x0]['message'][_0x7c18('0x84')];break;case _0x7c18('0x90'):_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x7e')]=_0x3a23b1[_0x7c18('0x5c')][_0x7c18('0x7e')];_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x5c')]=_0x3a23b1[_0x7c18('0x5c')][_0x7c18('0x29')];_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x81')]=_0x3a23b1[_0x7c18('0x5c')][_0x7c18('0x91')];break;}}if(_0x2e1998[_0x7c18('0x5c')]['id']){delete _0x2e1998[_0x7c18('0x5c')]['id'];}if(_[_0x7c18('0x92')](_0x2e1998['body'][_0x7c18('0x7e')])){throw new db[(_0x7c18('0x75'))][(_0x7c18('0x76'))](_0x7c18('0x93'));}if(_[_0x7c18('0x92')](_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x5c')])||_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x5c')]===''){throw new db[(_0x7c18('0x75'))][(_0x7c18('0x76'))](_0x7c18('0x94'));}if(_['isNil'](_0x2e1998[_0x7c18('0x5c')]['mapKey'])){throw new db[(_0x7c18('0x75'))]['ValidationError']('mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x286f16);}if(!_['includes'](_0x286f16,_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x95')])){throw new db[(_0x7c18('0x75'))][(_0x7c18('0x76'))]('mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x286f16);}_0x2417da[_0x2e1998['body']['mapKey']]=_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x7e')];return db[_0x7c18('0x96')][_0x7c18('0x5a')]({'where':{'id':_0x2e1998[_0x7c18('0x73')][_0x7c18('0x7b')]},'include':[{'model':db[_0x7c18('0x74')],'as':'Contacts','where':_0x2417da,'limit':0x1,'order':[[_0x7c18('0x78'),_0x7c18('0x97')]]}]});})['then'](handleEntityNotFound(_0x3ba2dd,null))[_0x7c18('0x20')](function(_0x21a758){if(_0x21a758){_0x2e1998['list']=_[_0x7c18('0x98')](_0x21a758,[_0x7c18('0x99')]);if(_0x21a758[_0x7c18('0x99')][_0x7c18('0x4c')]){return _0x21a758[_0x7c18('0x99')][0x0];}var _0x171d46=_[_0x7c18('0x18')](_0x2e1998[_0x7c18('0x5c')],{'firstName':_0x2e1998[_0x7c18('0x5c')]['from'],'ListId':_0x21a758['id']});_0x171d46[_0x2e1998[_0x7c18('0x5c')]['mapKey']]=_0x2e1998[_0x7c18('0x5c')]['from'];return db[_0x7c18('0x74')][_0x7c18('0x5b')](_0x171d46,{'fields':_0x2b673f,'raw':!![]});}})['then'](handleEntityNotFound(_0x3ba2dd,null))[_0x7c18('0x20')](function(_0x56d259){if(_0x56d259){_0x2e1998[_0x7c18('0x9a')]=_0x56d259;var _0x27d5c1={'ContactId':_0x56d259['id'],'phone':_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x7e')],'SmsAccountId':_0x3a23b1[_0x7c18('0x57')]['id']};var _0x593165={'ContactId':_0x56d259['id'],'SmsAccountId':_0x3a23b1[_0x7c18('0x57')]['id'],'closed':![]};return db['SmsInteraction'][_0x7c18('0x5a')]({'where':_0x593165})[_0x7c18('0x20')](function(_0x48c763){if(_0x48c763){return[_0x48c763,![]];}return db['SmsInteraction'][_0x7c18('0x5b')](_0x27d5c1)[_0x7c18('0x20')](function(_0x4fcad7){return[_0x4fcad7,!![]];});});}})['spread'](function(_0x3fb410,_0x4d51f0){_0x2e1998[_0x7c18('0x9b')]=_0x3fb410[_0x7c18('0x60')]({'plain':!![]});_0x2e1998[_0x7c18('0x9b')]['created']=![];if(_0x4d51f0){if(_0x2e1998[_0x7c18('0x73')][_0x7c18('0x9c')]){_0x2e1998['applications'][_0x7c18('0x9d')]({'id':0x0,'priority':_0x2e1998['applications']['length']+0x1,'app':_0x7c18('0x9e'),'appdata':_0x7c18('0x9f'),'interval':'*,*,*,*'});}_0x2e1998[_0x7c18('0x9b')][_0x7c18('0xa0')]=!![];}return db[_0x7c18('0xa1')][_0x7c18('0x5b')]({'phone':_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x7e')],'messageId':_0x2e1998[_0x7c18('0x5c')]['messageId'],'body':_0x2e1998[_0x7c18('0x5c')][_0x7c18('0x5c')],'SmsAccountId':_0x3a23b1['params']['id'],'SmsInteractionId':_0x3fb410['id'],'direction':'in','ContactId':_0x3fb410['ContactId'],'AttachmentId':_0x2e1998['body']['AttachmentId']});})[_0x7c18('0x20')](function(_0x2e0aac){_0x2e1998[_0x7c18('0x29')]=_0x2e0aac;if(_0x2e1998[_0x7c18('0x9b')][_0x7c18('0xa2')]){return db[_0x7c18('0xa3')][_0x7c18('0x5a')]({'attributes':['id','name'],'where':{'id':_0x2e1998['interaction'][_0x7c18('0xa2')]}})[_0x7c18('0x20')](function(_0x33b059){if(_0x33b059){_0x2e1998['applications'][_0x7c18('0xa4')]({'id':0x0,'priority':0x0,'app':_0x7c18('0xa5'),'appdata':_0x33b059[_0x7c18('0x3c')]+','+(_0x2e1998[_0x7c18('0x73')][_0x7c18('0xa6')]||0xa),'interval':_0x7c18('0xa7')});}return respondWithRpcPromise('Start',_0x7c18('0xa8'),_0x2e1998);});}return respondWithRpcPromise('Start',_0x7c18('0xa8'),_0x2e1998);})['then'](function(_0x442a96){if(_0x442a96){var _0x12f0c3=0xc8;var _0xd4120e='receiveMessage';logger[_0x7c18('0x21')](_0x7c18('0x24'),_0xd4120e,_0x12f0c3,_0x7c18('0xa9'));logger[_0x7c18('0x23')](_0x7c18('0xaa'),_0xd4120e,_0x12f0c3,'entity\x20found',JSON[_0x7c18('0x26')](_0x442a96));if(_0x2e1998[_0x7c18('0x73')][_0x7c18('0x42')]===_0x7c18('0x7d')){return _0x3ba2dd[_0x7c18('0x2c')](_0x12f0c3)[_0x7c18('0xab')](_0x7c18('0xac'),_0x7c18('0xad'))[_0x7c18('0xae')]('<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>');}else{return _0x3ba2dd['status'](_0x12f0c3)[_0x7c18('0x2e')](_0x442a96);}}})['catch'](handleError(_0x3ba2dd,null));};exports[_0x7c18('0xaf')]=function(_0x30b0af,_0x1db888){var _0xe6bff1=_0x30b0af['params']['id'];var _0x29d187=_0x30b0af[_0x7c18('0x5c')];var _0xce10a4=0xc8;var _0x45bc56=null;return db[_0x7c18('0xb0')][_0x7c18('0xb1')]({'isolationLevel':db[_0x7c18('0xb0')][_0x7c18('0xb2')][_0x7c18('0xb3')][_0x7c18('0xb4')]},function(_0x9c041a){return db[_0x7c18('0x3f')][_0x7c18('0x6a')]({'where':{'id':_0xe6bff1},'transaction':_0x9c041a})[_0x7c18('0x20')](function(_0xb5e290){if(_0xb5e290){return db[_0x7c18('0xb5')][_0x7c18('0x39')]({'where':{'SmsAccountId':_0xe6bff1},'transaction':_0x9c041a})[_0x7c18('0x20')](function(){var _0x46ae10=_[_0x7c18('0x45')](_0x29d187,function(_0x47b38a){_0x47b38a[_0x7c18('0x67')]=_0xe6bff1;return _0x47b38a;});return db[_0x7c18('0xb5')][_0x7c18('0xb6')](_0x46ae10,{'transaction':_0x9c041a});});}else{_0xce10a4=0x194;_0x45bc56=[];}});})[_0x7c18('0x20')](function(){if(_0xce10a4!==0x194){return db[_0x7c18('0xb5')][_0x7c18('0xb7')]({'where':{'SmsAccountId':_0xe6bff1},'order':_0x7c18('0x72')})[_0x7c18('0x20')](function(_0x4dd304){_0x45bc56=_0x4dd304;});}})[_0x7c18('0x2b')](function(_0x1b3a8a){_0xce10a4=0x1f4;logger[_0x7c18('0x27')](_0x1b3a8a['stack']);if(_0x1b3a8a[_0x7c18('0x3c')]){delete _0x1b3a8a[_0x7c18('0x3c')];}_0x45bc56=_0x1b3a8a;})[_0x7c18('0xb8')](function(){if(_0x45bc56===null){_0x1db888[_0x7c18('0x3a')](_0xce10a4);}else{if(_0xce10a4===0x1f4){_0x1db888[_0x7c18('0x2c')](_0xce10a4)[_0x7c18('0xae')](_0x45bc56);}else{_0x1db888[_0x7c18('0x2c')](_0xce10a4)['json'](_0x45bc56);}}});};exports[_0x7c18('0xb9')]=function(_0x29d806,_0x5bd608,_0x41a068){var _0x52a649={};var _0x1e605f={};var _0x73397;var _0x51279c;return db[_0x7c18('0x3f')]['findOne']({'where':{'id':_0x29d806[_0x7c18('0x57')]['id']}})[_0x7c18('0x20')](handleEntityNotFound(_0x5bd608,null))[_0x7c18('0x20')](function(_0x56b44c){if(_0x56b44c){_0x73397=_0x56b44c;_0x1e605f['model']=_[_0x7c18('0x47')](db[_0x7c18('0xb5')]['rawAttributes']);_0x1e605f[_0x7c18('0x46')]=_[_0x7c18('0x47')](_0x29d806[_0x7c18('0x46')]);_0x1e605f[_0x7c18('0x48')]=_['intersection'](_0x1e605f[_0x7c18('0x44')],_0x1e605f[_0x7c18('0x46')]);_0x52a649['attributes']=_['intersection'](_0x1e605f[_0x7c18('0x44')],qs[_0x7c18('0x4a')](_0x29d806[_0x7c18('0x46')]['fields']));_0x52a649[_0x7c18('0x4b')]=_0x52a649['attributes'][_0x7c18('0x4c')]?_0x52a649[_0x7c18('0x4b')]:_0x1e605f['model'];_0x52a649[_0x7c18('0x4e')]=qs['sort'](_0x29d806['query'][_0x7c18('0x4f')]);_0x52a649[_0x7c18('0x50')]=qs[_0x7c18('0x48')](_['pick'](_0x29d806['query'],_0x1e605f[_0x7c18('0x48')]));if(_0x29d806[_0x7c18('0x46')][_0x7c18('0x52')]){_0x52a649['where']=_['merge'](_0x52a649[_0x7c18('0x50')],{'$or':_[_0x7c18('0x45')](_0x52a649['attributes'],function(_0x5b0287){var _0x587acb={};_0x587acb[_0x5b0287]={'$like':'%'+_0x29d806[_0x7c18('0x46')][_0x7c18('0x52')]+'%'};return _0x587acb;})});}_0x52a649=_['merge']({},_0x52a649,_0x29d806[_0x7c18('0x59')]);return _0x73397[_0x7c18('0xb9')](_0x52a649);}})[_0x7c18('0x20')](function(_0x5f3bac){if(_0x5f3bac){_0x51279c=_0x5f3bac[_0x7c18('0x4c')];if(!_0x29d806[_0x7c18('0x46')][_0x7c18('0xba')](_0x7c18('0x4d'))){_0x52a649['limit']=qs['limit'](_0x29d806['query'][_0x7c18('0x32')]);_0x52a649[_0x7c18('0x31')]=qs[_0x7c18('0x31')](_0x29d806[_0x7c18('0x46')][_0x7c18('0x31')]);}return _0x73397['getApplications'](_0x52a649);}})[_0x7c18('0x20')](function(_0x409d4e){if(_0x409d4e){return _0x409d4e?{'count':_0x51279c,'rows':_0x409d4e}:null;}})[_0x7c18('0x20')](respondWithResult(_0x5bd608,null))[_0x7c18('0x2b')](handleError(_0x5bd608,null));};exports['getInteractions']=function(_0x44e45d,_0x12d652,_0x60ddd2){var _0xf27d02={'raw':![],'where':{}};var _0x413574={};var _0x1d0ce2={'count':0x0,'rows':[]};return db[_0x7c18('0x3f')][_0x7c18('0x6a')]({'where':{'id':_0x44e45d[_0x7c18('0x57')]['id']}})['then'](handleEntityNotFound(_0x12d652,null))['then'](function(_0x1d8e3a){if(_0x1d8e3a){_0x413574['model']=_['keys'](db[_0x7c18('0xbb')][_0x7c18('0x40')]);_0x413574[_0x7c18('0x46')]=_[_0x7c18('0x47')](_0x44e45d[_0x7c18('0x46')]);_0x413574['filters']=_[_0x7c18('0x49')](_0x413574['model'],_0x413574[_0x7c18('0x46')]);_0xf27d02['attributes']=_[_0x7c18('0x49')](_0x413574[_0x7c18('0x44')],qs['fields'](_0x44e45d[_0x7c18('0x46')]['fields']));_0xf27d02['attributes']=_0xf27d02[_0x7c18('0x4b')]['length']?_0xf27d02[_0x7c18('0x4b')]:_0x413574[_0x7c18('0x44')];if(!_0x44e45d[_0x7c18('0x46')][_0x7c18('0xba')](_0x7c18('0x4d'))){_0xf27d02['limit']=qs[_0x7c18('0x32')](_0x44e45d['query'][_0x7c18('0x32')]);_0xf27d02[_0x7c18('0x31')]=qs[_0x7c18('0x31')](_0x44e45d['query'][_0x7c18('0x31')]);}_0xf27d02[_0x7c18('0x4e')]=qs['sort'](_0x44e45d[_0x7c18('0x46')][_0x7c18('0x4f')]);_0xf27d02[_0x7c18('0x50')]=qs['filters'](_[_0x7c18('0x51')](_0x44e45d[_0x7c18('0x46')],_0x413574[_0x7c18('0x48')]));_0xf27d02[_0x7c18('0x50')][_0x7c18('0x67')]=_0x1d8e3a['id'];if(_0x44e45d[_0x7c18('0x46')][_0x7c18('0x52')]){_0xf27d02[_0x7c18('0x50')]=_[_0x7c18('0x53')](_0xf27d02[_0x7c18('0x50')],{'$or':_[_0x7c18('0x45')](_0xf27d02[_0x7c18('0x4b')],function(_0x137cdd){var _0x390f77={};_0x390f77[_0x137cdd]={'$like':'%'+_0x44e45d[_0x7c18('0x46')][_0x7c18('0x52')]+'%'};return _0x390f77;})});}_0xf27d02=_['merge']({},_0xf27d02,_0x44e45d[_0x7c18('0x59')]);return db[_0x7c18('0xbb')][_0x7c18('0x30')]({'where':_0xf27d02[_0x7c18('0x50')]})['then'](function(_0x6bf5af){_0x1d0ce2['count']=_0x6bf5af;if(_0x44e45d['query'][_0x7c18('0x55')]){_0xf27d02['include']=[{'model':db[_0x7c18('0x74')],'as':_0x7c18('0xbc'),'required':![]},{'model':db[_0x7c18('0xa3')],'as':_0x7c18('0xbd'),'attributes':['name','fullname',_0x7c18('0xbe')],'required':![]},{'model':db[_0x7c18('0xbf')],'as':_0x7c18('0xc0'),'attributes':['id',_0x7c18('0x3c'),_0x7c18('0xc1')],'where':_0x44e45d['query']['tag']?{'id':_0x44e45d[_0x7c18('0x46')][_0x7c18('0xc2')]}:undefined,'required':_0x44e45d['query'][_0x7c18('0xc2')]?!![]:![]}];}return db['SmsInteraction'][_0x7c18('0x56')](_0xf27d02);})['then'](function(_0x2ed688){_0x1d0ce2[_0x7c18('0x6b')]=_0x2ed688;return _0x1d0ce2;});}})[_0x7c18('0x20')](respondWithFilteredResult(_0x12d652,_0xf27d02))[_0x7c18('0x2b')](handleError(_0x12d652,null));};exports['send']=function(_0x4da01a,_0x367445,_0x1dc3c5){var _0xaa69fc,_0x1d826b,_0x4e8b3c;if(_['isNil'](_0x4da01a['body']['body'])||_0x4da01a[_0x7c18('0x5c')][_0x7c18('0x5c')]===''){throw new db[(_0x7c18('0x75'))]['ValidationError'](_0x7c18('0x94'));}if(_['isNil'](_0x4da01a[_0x7c18('0x5c')]['to'])){throw new db[(_0x7c18('0x75'))][(_0x7c18('0x76'))](_0x7c18('0xc3'));}_0xaa69fc=_0x4da01a['body']['to'];return db[_0x7c18('0x3f')][_0x7c18('0x5a')]({'where':{'id':_0x4da01a['params']['id']},'include':[{'model':db[_0x7c18('0x96')],'as':_0x7c18('0xc4'),'include':[{'model':db['CmContact'],'as':'Contacts','where':{'mobile':_0xaa69fc},'limit':0x1,'order':[['updatedAt','DESC']]}]}]})[_0x7c18('0x20')](handleEntityNotFound(_0x367445,null))[_0x7c18('0x20')](function(_0x299727){if(_0x299727&&_0x299727[_0x7c18('0xc4')]){_0x1d826b=_0x299727[_0x7c18('0x60')]({'plain':!![]});if(_0x1d826b['List']&&_0x1d826b[_0x7c18('0xc4')]['Contacts']['length']){return _0x1d826b[_0x7c18('0xc4')][_0x7c18('0x99')][0x0];}return db['CmContact'][_0x7c18('0x5b')](_['defaults'](_0x4da01a[_0x7c18('0x5c')],{'firstName':_0xaa69fc,'mobile':_0xaa69fc,'phone':_0xaa69fc,'ListId':_0x1d826b[_0x7c18('0x7b')]}));}})['then'](handleEntityNotFound(_0x367445,null))[_0x7c18('0x20')](function(_0x434096){if(_0x434096){_0x4e8b3c=_0x434096;return db['SmsInteraction'][_0x7c18('0x5a')]({'where':{'ContactId':_0x4e8b3c['id'],'closed':![],'SmsAccountId':_0x1d826b['id']}})[_0x7c18('0x20')](function(_0x42c1c2){if(_0x42c1c2){return[_0x42c1c2,![]];}return db[_0x7c18('0xbb')][_0x7c18('0x5b')]({'UserId':_0x4da01a[_0x7c18('0x5d')]['id'],'ContactId':_0x4e8b3c['id'],'SmsAccountId':_0x1d826b['id'],'phone':_0xaa69fc,'firstMsgDirection':'out','Messages':[_['merge'](_0x4da01a[_0x7c18('0x5c')],{'read':![],'body':_0x4da01a[_0x7c18('0x5c')][_0x7c18('0x5c')],'phone':_0xaa69fc,'SmsAccountId':_0x1d826b['id'],'UserId':_0x4da01a[_0x7c18('0x5d')]['id'],'ContactId':_0x4e8b3c['id']})]},{'include':[{'model':db[_0x7c18('0xa1')],'as':_0x7c18('0xc5')}]})[_0x7c18('0x20')](function(_0x1bcb1f){return[_0x1bcb1f,!![]];});});}})['spread'](function(_0x567d13,_0x11447e){if(_0x11447e){return _0x567d13;}return db['SmsMessage']['create'](_['merge'](_0x4da01a[_0x7c18('0x5c')],{'read':![],'body':_0x4da01a[_0x7c18('0x5c')][_0x7c18('0x5c')],'phone':_0xaa69fc,'SmsAccountId':_0x1d826b['id'],'SmsInteractionId':_0x567d13['id'],'UserId':_0x4da01a['user']['id'],'ContactId':_0x4e8b3c['id']}))[_0x7c18('0x20')](function(_0x279eae){_0x567d13[_0x7c18('0xc6')]['Messages']=[];_0x567d13['dataValues'][_0x7c18('0xc5')][_0x7c18('0x9d')](_0x279eae[_0x7c18('0xc6')]);return _0x567d13;});})[_0x7c18('0x20')](respondWithResult(_0x367445,null))[_0x7c18('0x2b')](handleError(_0x367445,null));};exports[_0x7c18('0x2c')]=function(_0x587a28,_0x2c0b7d,_0x19f7a0){if(_0x587a28['body']['id']){delete _0x587a28[_0x7c18('0x5c')]['id'];}var _0x4db0c2,_0x4f2e7b,_0x447dca;return db['SmsAccount'][_0x7c18('0x5a')]({'where':{'id':_0x587a28[_0x7c18('0x57')]['id']}})[_0x7c18('0x20')](handleEntityNotFound(_0x2c0b7d,null))[_0x7c18('0x20')](function(_0x4cde19){if(_0x4cde19){_0x447dca=_0x4cde19;logger[_0x7c18('0x23')](_0x7c18('0x24'),_0x7c18('0x2c'),_0x7c18('0xc7'),_0x4cde19[_0x7c18('0x42')],util[_0x7c18('0xc8')](_0x587a28[_0x7c18('0x5c')],{'showHidden':![],'depth':null}));switch(_0x4cde19['type']){case'skebby':if(_0x587a28[_0x7c18('0x5c')][_0x7c18('0xc9')]&&_0x587a28['body'][_0x7c18('0x2c')]){_0x4f2e7b=_0x587a28[_0x7c18('0x5c')]['status'];return db['SmsMessage'][_0x7c18('0x5a')]({'where':{'messageId':_0x587a28[_0x7c18('0x5c')][_0x7c18('0xc9')]}});}break;case'connectel':if(_0x587a28[_0x7c18('0x5c')][_0x7c18('0xca')]&&_0x587a28[_0x7c18('0x5c')][_0x7c18('0xcb')]){_0x4f2e7b=_0x587a28[_0x7c18('0x5c')]['statusInt'];return db[_0x7c18('0xa1')][_0x7c18('0x5a')]({'where':{'messageId':_0x587a28[_0x7c18('0x5c')][_0x7c18('0xca')]}});}break;case _0x7c18('0x86'):if(_0x587a28[_0x7c18('0x5c')]['message_id']&&_0x587a28[_0x7c18('0x5c')][_0x7c18('0xcc')]){_0x4f2e7b=_0x587a28[_0x7c18('0x5c')]['status_code'];return db['SmsMessage'][_0x7c18('0x5a')]({'where':{'messageId':_0x587a28['body'][_0x7c18('0x87')]}});}break;case _0x7c18('0x8a'):var _0x6a452e=_0x587a28[_0x7c18('0x5c')]['results'][0x0];if(_0x6a452e['messageId']&&_0x6a452e[_0x7c18('0x2c')][_0x7c18('0xcd')]===_0x7c18('0xce')){_0x4f2e7b=_0x6a452e[_0x7c18('0x2c')][_0x7c18('0xcd')];return db[_0x7c18('0xa1')][_0x7c18('0x5a')]({'where':{'messageId':_0x6a452e[_0x7c18('0x81')]}});}break;case _0x7c18('0xcf'):if(_0x587a28['body']['messageId']&&_0x587a28['body'][_0x7c18('0x2c')]){_0x4f2e7b=_0x587a28[_0x7c18('0x5c')][_0x7c18('0x2c')];return db['SmsMessage'][_0x7c18('0x5a')]({'where':{'messageId':_0x587a28['body'][_0x7c18('0x81')]}});}break;case _0x7c18('0xd0'):if(_0x587a28[_0x7c18('0x5c')][0x0][_0x7c18('0x29')]['id']){_0x4f2e7b=_0x587a28[_0x7c18('0x5c')][0x0][_0x7c18('0x42')];return db[_0x7c18('0xa1')][_0x7c18('0x5a')]({'where':{'messageId':_0x587a28['body'][0x0][_0x7c18('0x29')]['id']}});}break;case _0x7c18('0x90'):if(_0x587a28[_0x7c18('0x5c')]['redif']&&_0x587a28[_0x7c18('0x5c')][_0x7c18('0x2c')]){_0x4f2e7b=_0x587a28['body'][_0x7c18('0x2c')];return db[_0x7c18('0xa1')][_0x7c18('0x5a')]({'where':{'messageId':_0x587a28[_0x7c18('0x5c')]['redif']}});}break;}}})['then'](handleEntityNotFound(_0x2c0b7d,null))['then'](function(_0x416b66){if(_0x416b66){_0x4db0c2=_0x416b66;switch(_0x447dca[_0x7c18('0x42')]){case'skebby':if(_0x4f2e7b===_0x7c18('0xce')){return _0x4db0c2[_0x7c18('0x36')]({'read':!![]});}else{logger[_0x7c18('0x27')](_0x7c18('0x24'),_0x7c18('0x2c'),_0x7c18('0x82'),util['inspect'](_0x587a28[_0x7c18('0x5c')],{'showHidden':![],'depth':null}));}break;case _0x7c18('0x85'):if(_0x4f2e7b==='1'){return _0x4db0c2[_0x7c18('0x36')]({'read':!![]});}else{logger[_0x7c18('0x27')](_0x7c18('0x24'),_0x7c18('0x2c'),_0x7c18('0x82'),util['inspect'](_0x587a28[_0x7c18('0x5c')],{'showHidden':![],'depth':null}));}break;case'clicksend':if(!_0x587a28[_0x7c18('0x5c')][_0x7c18('0xd1')]&&_0x4f2e7b>=0xc8&&_0x4f2e7b<=0xce){return _0x4db0c2[_0x7c18('0x36')]({'read':!![]});}else{logger[_0x7c18('0x27')](_0x7c18('0x24'),_0x7c18('0x2c'),'clicksend',util[_0x7c18('0xc8')](_0x587a28[_0x7c18('0x5c')],{'showHidden':![],'depth':null}));}break;case _0x7c18('0x8a'):var _0x5d74d5=_0x587a28[_0x7c18('0x5c')][_0x7c18('0x8b')][0x0];if(_0x5d74d5[_0x7c18('0x2c')]['groupName']===_0x7c18('0xce')){return _0x4db0c2[_0x7c18('0x36')]({'read':!![]});}else{logger[_0x7c18('0x27')](_0x7c18('0x24'),'status',_0x7c18('0x8a'),util[_0x7c18('0xc8')](_0x587a28[_0x7c18('0x5c')],{'showHidden':![],'depth':null}));}break;case _0x7c18('0xcf'):if(_0x4f2e7b=='DELIVERED_TO_GATEWAY'||_0x4f2e7b==_0x7c18('0xd2')){return _0x4db0c2[_0x7c18('0x36')]({'read':!![]});}else{logger[_0x7c18('0x27')](_0x7c18('0x24'),'status','clickatell',util['inspect'](_0x587a28[_0x7c18('0x5c')],{'showHidden':![],'depth':null}));}break;case'bandwidth':if(_0x4f2e7b=='message-delivered'){return _0x4db0c2[_0x7c18('0x36')]({'read':!![]});}else{logger[_0x7c18('0x27')](_0x7c18('0x24'),_0x7c18('0x2c'),_0x7c18('0xd0'),util['inspect'](_0x587a28[_0x7c18('0x5c')],{'showHidden':![],'depth':null}));}break;case'intelepeer':if(_0x4f2e7b===_0x7c18('0xd3')||_0x4f2e7b===_0x7c18('0xd4')){return _0x4db0c2[_0x7c18('0x36')]({'read':!![]});}else{logger[_0x7c18('0x27')](_0x7c18('0x24'),_0x7c18('0x2c'),_0x7c18('0x90'),util[_0x7c18('0xc8')](_0x587a28['body'],{'showHidden':![],'depth':null}));}break;}return _0x4db0c2;}})[_0x7c18('0x20')](respondWithResult(_0x2c0b7d,null))[_0x7c18('0x2b')](handleError(_0x2c0b7d,null));};exports[_0x7c18('0xd5')]=function(_0x10c911,_0x1de22d,_0x3379ce){var _0x46475f,_0x2a511e,_0x2e7728;return db[_0x7c18('0x3f')]['find']({'where':{'id':_0x10c911['params']['id']}})['then'](handleEntityNotFound(_0x1de22d,null))[_0x7c18('0x20')](function(_0x2f877a){if(_0x2f877a){_0x2e7728=_0x2f877a;logger[_0x7c18('0x23')]('SmsAccount,\x20%s,\x20%s,\x20%s','status',_0x7c18('0xc7'),_0x2f877a[_0x7c18('0x42')],util[_0x7c18('0xc8')](_0x10c911['query'],{'showHidden':![],'depth':null}));switch(_0x2f877a[_0x7c18('0x42')]){case _0x7c18('0x8c'):if(_0x10c911[_0x7c18('0x46')][_0x7c18('0xd6')]&&_0x10c911['query'][_0x7c18('0xd7')]){_0x2a511e=_0x10c911[_0x7c18('0x46')][_0x7c18('0xd7')];return db[_0x7c18('0xa1')][_0x7c18('0x5a')]({'where':{'messageId':_0x10c911['query']['message-id']}});}break;}}})[_0x7c18('0x20')](handleEntityNotFound(_0x1de22d,null))[_0x7c18('0x20')](function(_0x1558b7){if(_0x1558b7){_0x46475f=_0x1558b7;switch(_0x2e7728[_0x7c18('0x42')]){case _0x7c18('0x8c'):if(_0x2a511e==='2'||_0x2a511e==='6'){return _0x46475f[_0x7c18('0x36')]({'read':!![]});}else{logger[_0x7c18('0x27')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x7c18('0x2c'),'csc',util[_0x7c18('0xc8')](_0x10c911[_0x7c18('0x46')],{'showHidden':![],'depth':null}));};break;}return _0x46475f;}})[_0x7c18('0x20')](respondWithResult(_0x1de22d,null))[_0x7c18('0x2b')](handleError(_0x1de22d,null));};exports['addAgents']=function(_0x2bbdec,_0x460845,_0x303fe0){return db[_0x7c18('0x3f')][_0x7c18('0x5a')]({'where':{'id':_0x2bbdec['params']['id']}})[_0x7c18('0x20')](handleEntityNotFound(_0x460845,null))[_0x7c18('0x20')](function(_0x5b2967){if(_0x5b2967){return _0x5b2967['addAgents'](_0x2bbdec[_0x7c18('0x5c')]['ids'],_['omit'](_0x2bbdec[_0x7c18('0x5c')],[_0x7c18('0x6d'),'id'])||{})['spread'](function(_0x29b804){for(var _0x349fed=0x0;_0x349fed<_0x2bbdec['body'][_0x7c18('0x6d')][_0x7c18('0x4c')];_0x349fed+=0x1){socket[_0x7c18('0xd8')](_0x7c18('0xd9'),{'UserId':Number(_0x2bbdec[_0x7c18('0x5c')]['ids'][_0x349fed]),'SmsAccountId':Number(_0x2bbdec[_0x7c18('0x57')]['id'])});}return _0x29b804;});}})[_0x7c18('0x20')](respondWithResult(_0x460845,null))['catch'](handleError(_0x460845,null));};exports['removeAgents']=function(_0x3f8324,_0x2fc528,_0x5f3f5f){return db['SmsAccount']['find']({'where':{'id':_0x3f8324[_0x7c18('0x57')]['id']}})['then'](handleEntityNotFound(_0x2fc528,null))[_0x7c18('0x20')](function(_0x3151c6){if(_0x3151c6){return _0x3151c6['removeAgents'](_0x3f8324[_0x7c18('0x46')][_0x7c18('0x6d')])[_0x7c18('0x20')](function(){if(_[_0x7c18('0xda')](_0x3f8324[_0x7c18('0x46')][_0x7c18('0x6d')])){for(var _0x38ac71=0x0;_0x38ac71<_0x3f8324[_0x7c18('0x46')][_0x7c18('0x6d')]['length'];_0x38ac71+=0x1){socket[_0x7c18('0xd8')](_0x7c18('0xdb'),{'UserId':Number(_0x3f8324[_0x7c18('0x46')][_0x7c18('0x6d')][_0x38ac71]),'SmsAccountId':Number(_0x3f8324[_0x7c18('0x57')]['id'])});}}else{socket[_0x7c18('0xd8')](_0x7c18('0xdb'),{'UserId':Number(_0x3f8324[_0x7c18('0x46')][_0x7c18('0x6d')]),'SmsAccountId':Number(_0x3f8324[_0x7c18('0x57')]['id'])});}});}})[_0x7c18('0x20')](respondWithStatusCode(_0x2fc528,null))['catch'](handleError(_0x2fc528,null));};exports[_0x7c18('0xdc')]=function(_0x14a645,_0x509e36,_0x38b943){var _0xbbeeb8={};var _0x2ad05f={};var _0x54ad7a;var _0x1c484d;return db[_0x7c18('0x3f')][_0x7c18('0x6a')]({'where':{'id':_0x14a645['params']['id']}})[_0x7c18('0x20')](handleEntityNotFound(_0x509e36,null))[_0x7c18('0x20')](function(_0x14ce8d){if(_0x14ce8d){_0x54ad7a=_0x14ce8d;_0x2ad05f[_0x7c18('0x44')]=_['keys'](db['User']['rawAttributes']);_0x2ad05f['query']=_['keys'](_0x14a645['query']);_0x2ad05f[_0x7c18('0x48')]=_['intersection'](_0x2ad05f[_0x7c18('0x44')],_0x2ad05f['query']);_0xbbeeb8[_0x7c18('0x4b')]=_[_0x7c18('0x49')](_0x2ad05f[_0x7c18('0x44')],qs['fields'](_0x14a645[_0x7c18('0x46')][_0x7c18('0x4a')]));_0xbbeeb8['attributes']=_0xbbeeb8[_0x7c18('0x4b')][_0x7c18('0x4c')]?_0xbbeeb8[_0x7c18('0x4b')]:_0x2ad05f[_0x7c18('0x44')];_0xbbeeb8['order']=qs['sort'](_0x14a645[_0x7c18('0x46')]['sort']);_0xbbeeb8[_0x7c18('0x50')]=qs['filters'](_[_0x7c18('0x51')](_0x14a645[_0x7c18('0x46')],_0x2ad05f[_0x7c18('0x48')]));if(_0x14a645[_0x7c18('0x46')][_0x7c18('0x52')]){_0xbbeeb8[_0x7c18('0x50')]=_[_0x7c18('0x53')](_0xbbeeb8[_0x7c18('0x50')],{'$or':_[_0x7c18('0x45')](_0xbbeeb8[_0x7c18('0x4b')],function(_0x5d61f8){var _0xbc237a={};_0xbc237a[_0x5d61f8]={'$like':'%'+_0x14a645[_0x7c18('0x46')][_0x7c18('0x52')]+'%'};return _0xbc237a;})});}_0xbbeeb8=_[_0x7c18('0x53')]({},_0xbbeeb8,_0x14a645[_0x7c18('0x59')]);return _0x54ad7a['getAgents'](_0xbbeeb8);}})[_0x7c18('0x20')](function(_0x40922a){if(_0x40922a){_0x1c484d=_0x40922a[_0x7c18('0x4c')];if(!_0x14a645[_0x7c18('0x46')]['hasOwnProperty'](_0x7c18('0x4d'))){_0xbbeeb8['limit']=qs[_0x7c18('0x32')](_0x14a645[_0x7c18('0x46')][_0x7c18('0x32')]);_0xbbeeb8[_0x7c18('0x31')]=qs[_0x7c18('0x31')](_0x14a645[_0x7c18('0x46')][_0x7c18('0x31')]);}return _0x54ad7a[_0x7c18('0xdc')](_0xbbeeb8);}})[_0x7c18('0x20')](function(_0x9d54d2){if(_0x9d54d2){return _0x9d54d2?{'count':_0x1c484d,'rows':_0x9d54d2}:null;}})[_0x7c18('0x20')](respondWithResult(_0x509e36,null))[_0x7c18('0x2b')](handleError(_0x509e36,null));};
\ No newline at end of file