Built motion from commit (unavailable).|2.5.31
[motion2.git] / server / api / smsAccount / smsAccount.controller.js
index 95b818c..a21c65f 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xd45f=['emit','userSmsAccount:save','removeAgents','isArray','userSmsAccount:remove','getAgents','html-pdf','eml-format','zip-dir','fast-json-patch','mustache','util','path','sox','to-csv','ejs','squel','crypto','jsforce','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','redis','socket.io-emitter','./smsAccount.socket','register','request','then','info','SmsAccount,\x20%s,\x20%s','request\x20sent','debug','SmsAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','catch','end','status','json','offset','set','Content-Range','apply','reject','update','destroy','get','SmsAccounts','UserProfileResource','sendStatus','stack','name','send','Pause','mandatoryDispositionPause','map','SmsAccount','rawAttributes','fieldName','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','sort','where','filter','merge','type','VIRTUAL','count','includeAll','include','findAll','show','params','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','body','find','describe','addDisposition','SmsAccountId','Disposition','getDispositions','findOne','pick','options','rows','removeDispositions','ids','CannedAnswer','order','removeAnswers','notify','sms','SmsApplication','Applications','applications','orderBy','priority','asc','CmContact','Sequelize','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','CompanyId','ListId','mobile','account','From','Body','messageId','MessageSid','skebby','from','sender','text','connectel','clicksend','message_id','MessageUUID','infobip','results','csc','originatingAddress','segmentedMessage','replyMessageId','intelepeer','refid','isNil','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','includes','CmList','Contacts','DESC','list','omit','defaults','contact','SmsInteraction','spread','interaction','created','autoclose','push','close','unmanaged','*,*,*,*','SmsMessage','ContactId','AttachmentId','UserId','Start','startRouting','receiveMessage','entity\x20found','twilio','Content-Type','text/xml','<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>','findAndCountAll','getApplications','getInteractions','Contact','User','Owner','fullname','internal','Tag','color','tag','to\x20is\x20mandatory','List','out','Messages','dataValues','log','endpoint\x20/status\x20POST\x20/','received\x20delivery\x20report\x20from','requestid','statusInt','status_code','groupName','clickatell','redif','DELIVERED','error_code','inspect','DELIVERED_TO_GATEWAY','RECEIVED_BY_RECIPIENT','DELIVRD','statusGet','message-id','state','addAgents'];(function(_0x85a78a,_0x1896e0){var _0x3942ac=function(_0x3be30f){while(--_0x3be30f){_0x85a78a['push'](_0x85a78a['shift']());}};_0x3942ac(++_0x1896e0);}(_0xd45f,0xe0));var _0xfd45=function(_0x10f65d,_0x2279fd){_0x10f65d=_0x10f65d-0x0;var _0x641a7f=_0xd45f[_0x10f65d];return _0x641a7f;};'use strict';var pdf=require(_0xfd45('0x0'));var emlformat=require(_0xfd45('0x1'));var rimraf=require('rimraf');var zipdir=require(_0xfd45('0x2'));var jsonpatch=require(_0xfd45('0x3'));var rp=require('request-promise');var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0xfd45('0x4'));var util=require(_0xfd45('0x5'));var path=require(_0xfd45('0x6'));var sox=require(_0xfd45('0x7'));var csv=require(_0xfd45('0x8'));var ejs=require(_0xfd45('0x9'));var fs=require('fs');var _=require('lodash');var squel=require(_0xfd45('0xa'));var crypto=require(_0xfd45('0xb'));var jsforce=require(_0xfd45('0xc'));var deskjs=require('desk.js');var toCsv=require(_0xfd45('0x8'));var querystring=require(_0xfd45('0xd'));var Papa=require(_0xfd45('0xe'));var Redis=require(_0xfd45('0xf'));var authService=require('../../components/auth/service');var qs=require(_0xfd45('0x10'));var as=require(_0xfd45('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xfd45('0x12'))('api');var utils=require(_0xfd45('0x13'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];config[_0xfd45('0x14')]=_['defaults'](config[_0xfd45('0x14')],{'host':'localhost','port':0x18eb});var socket=require(_0xfd45('0x15'))(new Redis(config[_0xfd45('0x14')]));require(_0xfd45('0x16'))[_0xfd45('0x17')](socket);var jayson=require('jayson/promise');var client=jayson['client']['http']({'port':0x232c});function respondWithRpcPromise(_0x2eec3b,_0x4364ad,_0x5243c5,_0x2b663e){return new BPromise(function(_0x34858f,_0x58873b){var _0x2bce54=_0x2b663e||client;return _0x2bce54[_0xfd45('0x18')](_0x2eec3b,_0x5243c5)[_0xfd45('0x19')](function(_0x5e17da){logger[_0xfd45('0x1a')](_0xfd45('0x1b'),_0x4364ad,_0xfd45('0x1c'));logger[_0xfd45('0x1d')](_0xfd45('0x1e'),_0x4364ad,_0xfd45('0x1c'),JSON[_0xfd45('0x1f')](_0x5e17da));if(_0x5e17da['error']){if(_0x5e17da[_0xfd45('0x20')][_0xfd45('0x21')]===0x1f4){logger[_0xfd45('0x20')](_0xfd45('0x1b'),_0x4364ad,_0x5e17da[_0xfd45('0x20')][_0xfd45('0x22')]);return _0x58873b(_0x5e17da['error'][_0xfd45('0x22')]);}logger[_0xfd45('0x20')]('SmsAccount,\x20%s,\x20%s',_0x4364ad,_0x5e17da[_0xfd45('0x20')][_0xfd45('0x22')]);return _0x34858f(_0x5e17da[_0xfd45('0x20')]['message']);}else{logger[_0xfd45('0x1a')](_0xfd45('0x1b'),_0x4364ad,'request\x20sent');_0x34858f(_0x5e17da['result'][_0xfd45('0x22')]);}})[_0xfd45('0x23')](function(_0x5e6274){logger[_0xfd45('0x20')]('SmsAccount,\x20%s,\x20%s',_0x4364ad,_0x5e6274);_0x58873b(_0x5e6274);});});}function respondWithStatusCode(_0x12234f,_0x3d7666){_0x3d7666=_0x3d7666||0xcc;return function(_0x3dfe07){if(_0x3dfe07){return _0x12234f['sendStatus'](_0x3d7666);}return _0x12234f['status'](_0x3d7666)[_0xfd45('0x24')]();};}function respondWithResult(_0x3f04a7,_0x216eff){_0x216eff=_0x216eff||0xc8;return function(_0x51e98b){if(_0x51e98b){return _0x3f04a7[_0xfd45('0x25')](_0x216eff)[_0xfd45('0x26')](_0x51e98b);}};}function respondWithFilteredResult(_0x4ef515,_0xfc730a){return function(_0x257f91){if(_0x257f91){var _0x57c304=_0x257f91['count'],_0x52eaf3=_0xfc730a['offset'],_0x4c0004=_0xfc730a[_0xfd45('0x27')]+_0xfc730a['limit'],_0x1abcad;if(_0x4c0004>=_0x57c304){_0x4c0004=_0x57c304;_0x1abcad=0xc8;}else{_0x1abcad=0xce;}_0x4ef515['status'](_0x1abcad);return _0x4ef515[_0xfd45('0x28')](_0xfd45('0x29'),_0x52eaf3+'-'+_0x4c0004+'/'+_0x57c304)[_0xfd45('0x26')](_0x257f91);}return null;};}function patchUpdates(_0x11238b){return function(_0x427ae1){try{jsonpatch[_0xfd45('0x2a')](_0x427ae1,_0x11238b,!![]);}catch(_0x210686){return BPromise[_0xfd45('0x2b')](_0x210686);}return _0x427ae1['save']();};}function saveUpdates(_0x27cb12,_0x18a06e){return function(_0x4eb32e){if(_0x4eb32e){return _0x4eb32e[_0xfd45('0x2c')](_0x27cb12)[_0xfd45('0x19')](function(_0x1bd66d){return _0x1bd66d;});}return null;};}function removeEntity(_0x3c65c6,_0x3de21){return function(_0x365bdd){if(_0x365bdd){return _0x365bdd[_0xfd45('0x2d')]()[_0xfd45('0x19')](function(){var _0x48ab4b=_0x365bdd[_0xfd45('0x2e')]({'plain':!![]});var _0x4373a9=_0xfd45('0x2f');return db[_0xfd45('0x30')][_0xfd45('0x2d')]({'where':{'type':_0x4373a9,'resourceId':_0x48ab4b['id']}})[_0xfd45('0x19')](function(){return _0x365bdd;});})['then'](function(){_0x3c65c6[_0xfd45('0x25')](0xcc)[_0xfd45('0x24')]();});}};}function handleEntityNotFound(_0x1bacdd,_0x5ee612){return function(_0xd0f87e){if(!_0xd0f87e){_0x1bacdd[_0xfd45('0x31')](0x194);}return _0xd0f87e;};}function handleError(_0x20b517,_0x25c748){_0x25c748=_0x25c748||0x1f4;return function(_0x18ac80){logger[_0xfd45('0x20')](_0x18ac80[_0xfd45('0x32')]);if(_0x18ac80[_0xfd45('0x33')]){delete _0x18ac80[_0xfd45('0x33')];}_0x20b517['status'](_0x25c748)[_0xfd45('0x34')](_0x18ac80);};}exports['index']=function(_0x54913c,_0x3bfe39){var _0x274b38={'include':[{'model':db[_0xfd45('0x35')],'as':_0xfd45('0x36')}]},_0x556a5a={},_0x2e76eb={'count':0x0,'rows':[]};var _0xabba3f=_[_0xfd45('0x37')](db[_0xfd45('0x38')][_0xfd45('0x39')],function(_0x234bb4){return{'name':_0x234bb4[_0xfd45('0x3a')],'type':_0x234bb4['type'][_0xfd45('0x3b')]};});_0x556a5a[_0xfd45('0x3c')]=_['map'](_0xabba3f,_0xfd45('0x33'));_0x556a5a[_0xfd45('0x3d')]=_[_0xfd45('0x3e')](_0x54913c['query']);_0x556a5a[_0xfd45('0x3f')]=_[_0xfd45('0x40')](_0x556a5a[_0xfd45('0x3c')],_0x556a5a['query']);_0x274b38[_0xfd45('0x41')]=_['intersection'](_0x556a5a['model'],qs[_0xfd45('0x42')](_0x54913c['query'][_0xfd45('0x42')]));_0x274b38['attributes']=_0x274b38['attributes'][_0xfd45('0x43')]?_0x274b38[_0xfd45('0x41')]:_0x556a5a[_0xfd45('0x3c')];if(!_0x54913c[_0xfd45('0x3d')][_0xfd45('0x44')](_0xfd45('0x45'))){_0x274b38[_0xfd45('0x46')]=qs['limit'](_0x54913c[_0xfd45('0x3d')][_0xfd45('0x46')]);_0x274b38[_0xfd45('0x27')]=qs[_0xfd45('0x27')](_0x54913c['query'][_0xfd45('0x27')]);}_0x274b38['order']=qs[_0xfd45('0x47')](_0x54913c[_0xfd45('0x3d')][_0xfd45('0x47')]);_0x274b38[_0xfd45('0x48')]=qs[_0xfd45('0x3f')](_['pick'](_0x54913c['query'],_0x556a5a[_0xfd45('0x3f')]),_0xabba3f);if(_0x54913c[_0xfd45('0x3d')][_0xfd45('0x49')]){_0x274b38[_0xfd45('0x48')]=_[_0xfd45('0x4a')](_0x274b38['where'],{'$or':_[_0xfd45('0x37')](_0xabba3f,function(_0x232c33){if(_0x232c33[_0xfd45('0x4b')]!==_0xfd45('0x4c')){var _0x275ef={};_0x275ef[_0x232c33[_0xfd45('0x33')]]={'$like':'%'+_0x54913c['query'][_0xfd45('0x49')]+'%'};return _0x275ef;}})});}_0x274b38=_[_0xfd45('0x4a')]({},_0x274b38,_0x54913c['options']);var _0x9a0274={'where':_0x274b38[_0xfd45('0x48')]};return db[_0xfd45('0x38')][_0xfd45('0x4d')](_0x9a0274)[_0xfd45('0x19')](function(_0x54c735){_0x2e76eb[_0xfd45('0x4d')]=_0x54c735;if(_0x54913c[_0xfd45('0x3d')][_0xfd45('0x4e')]){_0x274b38[_0xfd45('0x4f')]=[{'all':!![]}];}return db[_0xfd45('0x38')][_0xfd45('0x50')](_0x274b38);})[_0xfd45('0x19')](function(_0x3473fd){_0x2e76eb['rows']=_0x3473fd;return _0x2e76eb;})[_0xfd45('0x19')](respondWithFilteredResult(_0x3bfe39,_0x274b38))[_0xfd45('0x23')](handleError(_0x3bfe39,null));};exports[_0xfd45('0x51')]=function(_0x387daf,_0x5048cd){var _0x6994ad={'raw':![],'where':{'id':_0x387daf[_0xfd45('0x52')]['id']},'include':[{'model':db[_0xfd45('0x35')],'as':'mandatoryDispositionPause'}]},_0x29cfbe={};_0x29cfbe[_0xfd45('0x3c')]=_[_0xfd45('0x3e')](db[_0xfd45('0x38')]['rawAttributes']);_0x29cfbe[_0xfd45('0x3d')]=_[_0xfd45('0x3e')](_0x387daf[_0xfd45('0x3d')]);_0x29cfbe[_0xfd45('0x3f')]=_[_0xfd45('0x40')](_0x29cfbe[_0xfd45('0x3c')],_0x29cfbe['query']);_0x6994ad[_0xfd45('0x41')]=_['intersection'](_0x29cfbe[_0xfd45('0x3c')],qs[_0xfd45('0x42')](_0x387daf[_0xfd45('0x3d')][_0xfd45('0x42')]));_0x6994ad[_0xfd45('0x41')]=_0x6994ad['attributes'][_0xfd45('0x43')]?_0x6994ad[_0xfd45('0x41')]:_0x29cfbe['model'];if(_0x387daf[_0xfd45('0x3d')][_0xfd45('0x4e')]){_0x6994ad[_0xfd45('0x4f')]=[{'all':!![]}];}_0x6994ad=_[_0xfd45('0x4a')]({},_0x6994ad,_0x387daf['options']);return db[_0xfd45('0x38')]['find'](_0x6994ad)[_0xfd45('0x19')](handleEntityNotFound(_0x5048cd,null))[_0xfd45('0x19')](respondWithResult(_0x5048cd,null))['catch'](handleError(_0x5048cd,null));};exports[_0xfd45('0x53')]=function(_0x61c6a,_0x54f7ba){return db[_0xfd45('0x38')][_0xfd45('0x53')](_0x61c6a['body'],{})[_0xfd45('0x19')](function(_0x323c08){var _0x175582=_0x61c6a[_0xfd45('0x54')]['get']({'plain':!![]});if(!_0x175582)throw new Error(_0xfd45('0x55'));if(_0x175582[_0xfd45('0x56')]==='user'){var _0x1745e8=_0x323c08[_0xfd45('0x2e')]({'plain':!![]});var _0x52fc4b=_0xfd45('0x2f');return db[_0xfd45('0x57')]['find']({'where':{'name':_0x52fc4b,'userProfileId':_0x175582[_0xfd45('0x58')]},'raw':!![]})[_0xfd45('0x19')](function(_0x52dd80){if(_0x52dd80&&_0x52dd80[_0xfd45('0x59')]===0x0){return db['UserProfileResource']['create']({'name':_0x1745e8['name'],'resourceId':_0x1745e8['id'],'type':_0x52dd80[_0xfd45('0x33')],'sectionId':_0x52dd80['id']},{})[_0xfd45('0x19')](function(){return _0x323c08;});}else{return _0x323c08;}})[_0xfd45('0x23')](function(_0x3db4cb){logger[_0xfd45('0x20')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x3db4cb);throw _0x3db4cb;});}return _0x323c08;})[_0xfd45('0x19')](respondWithResult(_0x54f7ba,0xc9))[_0xfd45('0x23')](handleError(_0x54f7ba,null));};exports['update']=function(_0x4d9f7f,_0x20748f){if(_0x4d9f7f['body']['id']){delete _0x4d9f7f[_0xfd45('0x5a')]['id'];}return db[_0xfd45('0x38')]['find']({'where':{'id':_0x4d9f7f[_0xfd45('0x52')]['id']},'include':[{'model':db[_0xfd45('0x35')],'as':_0xfd45('0x36')}]})['then'](handleEntityNotFound(_0x20748f,null))['then'](saveUpdates(_0x4d9f7f[_0xfd45('0x5a')],null))[_0xfd45('0x19')](respondWithResult(_0x20748f,null))['catch'](handleError(_0x20748f,null));};exports['destroy']=function(_0x5e4a5a,_0x526911){return db['SmsAccount'][_0xfd45('0x5b')]({'where':{'id':_0x5e4a5a[_0xfd45('0x52')]['id']}})[_0xfd45('0x19')](handleEntityNotFound(_0x526911,null))[_0xfd45('0x19')](removeEntity(_0x526911,null))['catch'](handleError(_0x526911,null));};exports['describe']=function(_0x46ba8d,_0x1c164d){return db[_0xfd45('0x38')][_0xfd45('0x5c')]()['then'](respondWithResult(_0x1c164d,null))[_0xfd45('0x23')](handleError(_0x1c164d,null));};exports[_0xfd45('0x5d')]=function(_0x85ee93,_0x15c7e4,_0x48fc9c){if(_0x85ee93[_0xfd45('0x5a')]['id']){delete _0x85ee93[_0xfd45('0x5a')]['id'];}return db[_0xfd45('0x38')][_0xfd45('0x5b')]({'where':{'id':_0x85ee93[_0xfd45('0x52')]['id']}})[_0xfd45('0x19')](handleEntityNotFound(_0x15c7e4,null))[_0xfd45('0x19')](function(_0x39567b){if(_0x39567b){_0x85ee93['body'][_0xfd45('0x5e')]=_0x39567b['id'];return db[_0xfd45('0x5f')][_0xfd45('0x53')](_0x85ee93[_0xfd45('0x5a')]);}})[_0xfd45('0x19')](respondWithResult(_0x15c7e4,null))[_0xfd45('0x23')](handleError(_0x15c7e4,null));};exports[_0xfd45('0x60')]=function(_0x13f721,_0x10146a,_0x126bb2){var _0x2ee75e={'raw':![],'where':{}};var _0x2772df={};var _0x5520d1={'count':0x0,'rows':[]};return db['SmsAccount'][_0xfd45('0x61')]({'where':{'id':_0x13f721[_0xfd45('0x52')]['id']}})[_0xfd45('0x19')](handleEntityNotFound(_0x10146a,null))[_0xfd45('0x19')](function(_0xec3c0){if(_0xec3c0){_0x2772df[_0xfd45('0x3c')]=_[_0xfd45('0x3e')](db['Disposition'][_0xfd45('0x39')]);_0x2772df[_0xfd45('0x3d')]=_['keys'](_0x13f721[_0xfd45('0x3d')]);_0x2772df[_0xfd45('0x3f')]=_[_0xfd45('0x40')](_0x2772df[_0xfd45('0x3c')],_0x2772df[_0xfd45('0x3d')]);_0x2ee75e[_0xfd45('0x41')]=_[_0xfd45('0x40')](_0x2772df[_0xfd45('0x3c')],qs['fields'](_0x13f721['query'][_0xfd45('0x42')]));_0x2ee75e[_0xfd45('0x41')]=_0x2ee75e[_0xfd45('0x41')][_0xfd45('0x43')]?_0x2ee75e[_0xfd45('0x41')]:_0x2772df[_0xfd45('0x3c')];if(!_0x13f721[_0xfd45('0x3d')]['hasOwnProperty'](_0xfd45('0x45'))){_0x2ee75e[_0xfd45('0x46')]=qs[_0xfd45('0x46')](_0x13f721['query']['limit']);_0x2ee75e[_0xfd45('0x27')]=qs[_0xfd45('0x27')](_0x13f721['query'][_0xfd45('0x27')]);}_0x2ee75e['order']=qs[_0xfd45('0x47')](_0x13f721[_0xfd45('0x3d')][_0xfd45('0x47')]);_0x2ee75e[_0xfd45('0x48')]=qs[_0xfd45('0x3f')](_[_0xfd45('0x62')](_0x13f721[_0xfd45('0x3d')],_0x2772df[_0xfd45('0x3f')]));_0x2ee75e[_0xfd45('0x48')][_0xfd45('0x5e')]=_0xec3c0['id'];if(_0x13f721[_0xfd45('0x3d')]['filter']){_0x2ee75e[_0xfd45('0x48')]=_[_0xfd45('0x4a')](_0x2ee75e[_0xfd45('0x48')],{'$or':_[_0xfd45('0x37')](_0x2ee75e[_0xfd45('0x41')],function(_0xdfb16d){var _0x4c1d12={};_0x4c1d12[_0xdfb16d]={'$like':'%'+_0x13f721[_0xfd45('0x3d')][_0xfd45('0x49')]+'%'};return _0x4c1d12;})});}_0x2ee75e=_['merge']({},_0x2ee75e,_0x13f721[_0xfd45('0x63')]);return db[_0xfd45('0x5f')][_0xfd45('0x4d')]({'where':_0x2ee75e['where']})['then'](function(_0x3b296e){_0x5520d1[_0xfd45('0x4d')]=_0x3b296e;if(_0x13f721['query'][_0xfd45('0x4e')]){_0x2ee75e[_0xfd45('0x4f')]=[{'all':!![]}];}return db[_0xfd45('0x5f')]['findAll'](_0x2ee75e);})[_0xfd45('0x19')](function(_0x41a62b){_0x5520d1[_0xfd45('0x64')]=_0x41a62b;return _0x5520d1;});}})[_0xfd45('0x19')](respondWithFilteredResult(_0x10146a,_0x2ee75e))[_0xfd45('0x23')](handleError(_0x10146a,null));};exports['removeDispositions']=function(_0x4a5ed8,_0x4f2faa,_0x4a59b9){return db['SmsAccount'][_0xfd45('0x5b')]({'where':{'id':_0x4a5ed8['params']['id']}})['then'](handleEntityNotFound(_0x4f2faa,null))['then'](function(_0x2a87a5){if(_0x2a87a5){return _0x2a87a5[_0xfd45('0x65')](_0x4a5ed8[_0xfd45('0x3d')][_0xfd45('0x66')]);}})['then'](respondWithStatusCode(_0x4f2faa,null))[_0xfd45('0x23')](handleError(_0x4f2faa,null));};exports['addAnswer']=function(_0x5dbdbd,_0x1b4897,_0x474017){if(_0x5dbdbd[_0xfd45('0x5a')]['id']){delete _0x5dbdbd[_0xfd45('0x5a')]['id'];}return db[_0xfd45('0x38')][_0xfd45('0x5b')]({'where':{'id':_0x5dbdbd['params']['id']}})[_0xfd45('0x19')](handleEntityNotFound(_0x1b4897,null))[_0xfd45('0x19')](function(_0xfa07a9){if(_0xfa07a9){_0x5dbdbd['body'][_0xfd45('0x5e')]=_0xfa07a9['id'];return db[_0xfd45('0x67')][_0xfd45('0x53')](_0x5dbdbd[_0xfd45('0x5a')]);}})['then'](respondWithResult(_0x1b4897,null))['catch'](handleError(_0x1b4897,null));};exports['getAnswers']=function(_0x3cd57d,_0x262e69,_0x39c4f1){var _0x303177={'raw':![],'where':{}};var _0x55e843={};var _0x3faf9c={'count':0x0,'rows':[]};return db[_0xfd45('0x38')]['findOne']({'where':{'id':_0x3cd57d[_0xfd45('0x52')]['id']}})['then'](handleEntityNotFound(_0x262e69,null))[_0xfd45('0x19')](function(_0x31740c){if(_0x31740c){_0x55e843['model']=_[_0xfd45('0x3e')](db['CannedAnswer'][_0xfd45('0x39')]);_0x55e843[_0xfd45('0x3d')]=_['keys'](_0x3cd57d['query']);_0x55e843[_0xfd45('0x3f')]=_[_0xfd45('0x40')](_0x55e843[_0xfd45('0x3c')],_0x55e843[_0xfd45('0x3d')]);_0x303177['attributes']=_[_0xfd45('0x40')](_0x55e843[_0xfd45('0x3c')],qs['fields'](_0x3cd57d[_0xfd45('0x3d')][_0xfd45('0x42')]));_0x303177[_0xfd45('0x41')]=_0x303177['attributes']['length']?_0x303177[_0xfd45('0x41')]:_0x55e843[_0xfd45('0x3c')];if(!_0x3cd57d[_0xfd45('0x3d')][_0xfd45('0x44')](_0xfd45('0x45'))){_0x303177['limit']=qs[_0xfd45('0x46')](_0x3cd57d[_0xfd45('0x3d')]['limit']);_0x303177[_0xfd45('0x27')]=qs[_0xfd45('0x27')](_0x3cd57d[_0xfd45('0x3d')][_0xfd45('0x27')]);}_0x303177[_0xfd45('0x68')]=qs[_0xfd45('0x47')](_0x3cd57d[_0xfd45('0x3d')][_0xfd45('0x47')]);_0x303177[_0xfd45('0x48')]=qs[_0xfd45('0x3f')](_[_0xfd45('0x62')](_0x3cd57d[_0xfd45('0x3d')],_0x55e843[_0xfd45('0x3f')]));_0x303177['where'][_0xfd45('0x5e')]=_0x31740c['id'];if(_0x3cd57d[_0xfd45('0x3d')]['filter']){_0x303177[_0xfd45('0x48')]=_[_0xfd45('0x4a')](_0x303177[_0xfd45('0x48')],{'$or':_[_0xfd45('0x37')](_0x303177[_0xfd45('0x41')],function(_0x5ea6a5){var _0x4940f6={};_0x4940f6[_0x5ea6a5]={'$like':'%'+_0x3cd57d[_0xfd45('0x3d')][_0xfd45('0x49')]+'%'};return _0x4940f6;})});}_0x303177=_['merge']({},_0x303177,_0x3cd57d[_0xfd45('0x63')]);return db['CannedAnswer'][_0xfd45('0x4d')]({'where':_0x303177[_0xfd45('0x48')]})[_0xfd45('0x19')](function(_0x32ff97){_0x3faf9c[_0xfd45('0x4d')]=_0x32ff97;if(_0x3cd57d[_0xfd45('0x3d')][_0xfd45('0x4e')]){_0x303177[_0xfd45('0x4f')]=[{'all':!![]}];}return db[_0xfd45('0x67')][_0xfd45('0x50')](_0x303177);})[_0xfd45('0x19')](function(_0x2ff7b6){_0x3faf9c[_0xfd45('0x64')]=_0x2ff7b6;return _0x3faf9c;});}})['then'](respondWithFilteredResult(_0x262e69,_0x303177))[_0xfd45('0x23')](handleError(_0x262e69,null));};exports[_0xfd45('0x69')]=function(_0x493cde,_0x1d0952,_0x9e55fe){return db[_0xfd45('0x38')]['find']({'where':{'id':_0x493cde['params']['id']}})[_0xfd45('0x19')](handleEntityNotFound(_0x1d0952,null))['then'](function(_0x4873cd){if(_0x4873cd){return _0x4873cd[_0xfd45('0x69')](_0x493cde['query']['ids']);}})['then'](respondWithStatusCode(_0x1d0952,null))['catch'](handleError(_0x1d0952,null));};exports[_0xfd45('0x6a')]=function(_0x535f90,_0x19f598,_0x51fe42){var _0x1f0259={'channel':_0xfd45('0x6b')};var _0x2e4fe3=[];var _0xb94736=[];var _0x3bc47f={};return db[_0xfd45('0x38')][_0xfd45('0x5b')]({'where':{'id':_0x535f90['params']['id']},'include':[{'model':db[_0xfd45('0x6c')],'as':_0xfd45('0x6d')}]})['then'](handleEntityNotFound(_0x19f598,null))['then'](function(_0x385b5b){_0x1f0259['account']=_0x385b5b;_0x1f0259[_0xfd45('0x6e')]=_[_0xfd45('0x6f')](_0x385b5b[_0xfd45('0x6d')],[_0xfd45('0x70')],[_0xfd45('0x71')]);if(_0x1f0259['account'][_0xfd45('0x6d')]){delete _0x1f0259['account']['Applications'];}return db[_0xfd45('0x72')]['describe']();})['then'](function(_0x2a5e9a){if(!_0x2a5e9a){throw new db[(_0xfd45('0x73'))][(_0xfd45('0x74'))](_0xfd45('0x75'));}_0x2e4fe3=_[_0xfd45('0x76')](_['keys'](_0x2a5e9a),[_0xfd45('0x77'),_0xfd45('0x78')]);_0xb94736=_[_0xfd45('0x76')](_['keys'](_0x2a5e9a),['createdAt',_0xfd45('0x78'),_0xfd45('0x79'),_0xfd45('0x7a')]);_0x1f0259['body']={'mapKey':_0xfd45('0x7b')};if(_0x1f0259[_0xfd45('0x7c')]['type']){switch(_0x1f0259[_0xfd45('0x7c')][_0xfd45('0x4b')]){case'twilio':_0x1f0259[_0xfd45('0x5a')]['from']=_0x535f90[_0xfd45('0x5a')][_0xfd45('0x7d')];_0x1f0259[_0xfd45('0x5a')][_0xfd45('0x5a')]=_0x535f90[_0xfd45('0x5a')][_0xfd45('0x7e')];_0x1f0259['body'][_0xfd45('0x7f')]=_0x535f90[_0xfd45('0x5a')][_0xfd45('0x80')];break;case _0xfd45('0x81'):_0x1f0259[_0xfd45('0x5a')][_0xfd45('0x82')]='+'+_0x535f90['body'][_0xfd45('0x83')];_0x1f0259['body']['body']=_0x535f90[_0xfd45('0x5a')][_0xfd45('0x84')];break;case _0xfd45('0x85'):_0x1f0259['body'][_0xfd45('0x82')]=_0x535f90[_0xfd45('0x5a')][_0xfd45('0x82')];_0x1f0259['body']['body']=_0x535f90[_0xfd45('0x5a')][_0xfd45('0x22')];break;case _0xfd45('0x86'):_0x1f0259[_0xfd45('0x5a')][_0xfd45('0x82')]=_0x535f90['body'][_0xfd45('0x82')];_0x1f0259[_0xfd45('0x5a')]['body']=_0x535f90['body'][_0xfd45('0x5a')];_0x1f0259['body']['messageId']=_0x535f90['body'][_0xfd45('0x87')];break;case'plivo':_0x1f0259[_0xfd45('0x5a')][_0xfd45('0x82')]=_0x535f90[_0xfd45('0x5a')][_0xfd45('0x7d')];_0x1f0259['body'][_0xfd45('0x5a')]=_0x535f90[_0xfd45('0x5a')]['Text'];_0x1f0259[_0xfd45('0x5a')]['messageId']=_0x535f90['body'][_0xfd45('0x88')];break;case _0xfd45('0x89'):_0x1f0259[_0xfd45('0x5a')]['from']='+'+_0x535f90['body'][_0xfd45('0x8a')][0x0]['from'];_0x1f0259[_0xfd45('0x5a')][_0xfd45('0x5a')]=_0x535f90[_0xfd45('0x5a')][_0xfd45('0x8a')][0x0][_0xfd45('0x84')];_0x1f0259[_0xfd45('0x5a')][_0xfd45('0x7f')]=_0x535f90['body']['results'][0x0][_0xfd45('0x7f')];break;case _0xfd45('0x8b'):_0x1f0259[_0xfd45('0x5a')]['from']=_0x535f90['body'][_0xfd45('0x8c')];_0x1f0259[_0xfd45('0x5a')][_0xfd45('0x5a')]=_0x535f90[_0xfd45('0x5a')][_0xfd45('0x8d')][_0xfd45('0x22')];break;case'clickatell':_0x1f0259['body'][_0xfd45('0x82')]=_0x535f90[_0xfd45('0x5a')]['fromNumber'];_0x1f0259['body'][_0xfd45('0x5a')]=_0x535f90[_0xfd45('0x5a')][_0xfd45('0x84')];_0x1f0259['body'][_0xfd45('0x7f')]=_0x535f90[_0xfd45('0x5a')][_0xfd45('0x8e')];break;case _0xfd45('0x8f'):_0x1f0259['body'][_0xfd45('0x82')]=_0x535f90[_0xfd45('0x5a')][_0xfd45('0x82')];_0x1f0259['body'][_0xfd45('0x5a')]=_0x535f90['body'][_0xfd45('0x22')];_0x1f0259['body'][_0xfd45('0x7f')]=_0x535f90[_0xfd45('0x5a')][_0xfd45('0x90')];break;}}if(_0x1f0259['body']['id']){delete _0x1f0259[_0xfd45('0x5a')]['id'];}if(_[_0xfd45('0x91')](_0x1f0259['body'][_0xfd45('0x82')])){throw new db[(_0xfd45('0x73'))]['ValidationError']('from\x20is\x20mandatory');}if(_[_0xfd45('0x91')](_0x1f0259[_0xfd45('0x5a')][_0xfd45('0x5a')])||_0x1f0259[_0xfd45('0x5a')][_0xfd45('0x5a')]===''){throw new db[(_0xfd45('0x73'))][(_0xfd45('0x74'))](_0xfd45('0x92'));}if(_[_0xfd45('0x91')](_0x1f0259['body'][_0xfd45('0x93')])){throw new db[(_0xfd45('0x73'))][(_0xfd45('0x74'))]('mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0xb94736);}if(!_[_0xfd45('0x94')](_0xb94736,_0x1f0259[_0xfd45('0x5a')][_0xfd45('0x93')])){throw new db[(_0xfd45('0x73'))][(_0xfd45('0x74'))]('mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0xb94736);}_0x3bc47f[_0x1f0259[_0xfd45('0x5a')][_0xfd45('0x93')]]=_0x1f0259[_0xfd45('0x5a')][_0xfd45('0x82')];return db[_0xfd45('0x95')]['find']({'where':{'id':_0x1f0259['account']['ListId']},'include':[{'model':db['CmContact'],'as':_0xfd45('0x96'),'where':_0x3bc47f,'limit':0x1,'order':[[_0xfd45('0x78'),_0xfd45('0x97')]]}]});})['then'](handleEntityNotFound(_0x19f598,null))[_0xfd45('0x19')](function(_0x57f5e4){if(_0x57f5e4){_0x1f0259[_0xfd45('0x98')]=_[_0xfd45('0x99')](_0x57f5e4,[_0xfd45('0x96')]);if(_0x57f5e4['Contacts'][_0xfd45('0x43')]){return _0x57f5e4[_0xfd45('0x96')][0x0];}var _0x54bef0=_[_0xfd45('0x9a')](_0x1f0259[_0xfd45('0x5a')],{'firstName':_0x1f0259[_0xfd45('0x5a')][_0xfd45('0x82')],'ListId':_0x57f5e4['id']});_0x54bef0[_0x1f0259[_0xfd45('0x5a')][_0xfd45('0x93')]]=_0x1f0259[_0xfd45('0x5a')]['from'];return db['CmContact'][_0xfd45('0x53')](_0x54bef0,{'fields':_0x2e4fe3,'raw':!![]});}})[_0xfd45('0x19')](handleEntityNotFound(_0x19f598,null))['then'](function(_0x5d53ad){if(_0x5d53ad){_0x1f0259[_0xfd45('0x9b')]=_0x5d53ad;var _0x2e6f16={'ContactId':_0x5d53ad['id'],'phone':_0x1f0259[_0xfd45('0x5a')][_0xfd45('0x82')],'SmsAccountId':_0x535f90[_0xfd45('0x52')]['id']};var _0x4c0fda={'ContactId':_0x5d53ad['id'],'SmsAccountId':_0x535f90[_0xfd45('0x52')]['id'],'closed':![]};return db[_0xfd45('0x9c')][_0xfd45('0x5b')]({'where':_0x4c0fda})[_0xfd45('0x19')](function(_0x3e1aea){if(_0x3e1aea){return[_0x3e1aea,![]];}return db[_0xfd45('0x9c')][_0xfd45('0x53')](_0x2e6f16)[_0xfd45('0x19')](function(_0xc6bbdd){return[_0xc6bbdd,!![]];});});}})[_0xfd45('0x9d')](function(_0x2b068f,_0x3c4eea){_0x1f0259[_0xfd45('0x9e')]=_0x2b068f['get']({'plain':!![]});_0x1f0259[_0xfd45('0x9e')][_0xfd45('0x9f')]=![];if(_0x3c4eea){if(_0x1f0259[_0xfd45('0x7c')][_0xfd45('0xa0')]){_0x1f0259['applications'][_0xfd45('0xa1')]({'id':0x0,'priority':_0x1f0259[_0xfd45('0x6e')]['length']+0x1,'app':_0xfd45('0xa2'),'appdata':_0xfd45('0xa3'),'interval':_0xfd45('0xa4')});}_0x1f0259[_0xfd45('0x9e')][_0xfd45('0x9f')]=!![];}return db[_0xfd45('0xa5')][_0xfd45('0x53')]({'phone':_0x1f0259[_0xfd45('0x5a')]['from'],'messageId':_0x1f0259[_0xfd45('0x5a')]['messageId'],'body':_0x1f0259[_0xfd45('0x5a')][_0xfd45('0x5a')],'SmsAccountId':_0x535f90[_0xfd45('0x52')]['id'],'SmsInteractionId':_0x2b068f['id'],'direction':'in','ContactId':_0x2b068f[_0xfd45('0xa6')],'AttachmentId':_0x1f0259['body'][_0xfd45('0xa7')]});})[_0xfd45('0x19')](function(_0x37bdda){_0x1f0259[_0xfd45('0x22')]=_0x37bdda;if(_0x1f0259[_0xfd45('0x9e')][_0xfd45('0xa8')]){return db['User']['find']({'attributes':['id',_0xfd45('0x33')],'where':{'id':_0x1f0259[_0xfd45('0x9e')][_0xfd45('0xa8')]}})[_0xfd45('0x19')](function(_0x35e477){if(_0x35e477){_0x1f0259[_0xfd45('0x6e')]['unshift']({'id':0x0,'priority':0x0,'app':'agent','appdata':_0x35e477[_0xfd45('0x33')]+','+(_0x1f0259[_0xfd45('0x7c')]['waitForTheAssignedAgent']||0xa),'interval':_0xfd45('0xa4')});}return respondWithRpcPromise(_0xfd45('0xa9'),_0xfd45('0xaa'),_0x1f0259);});}return respondWithRpcPromise(_0xfd45('0xa9'),_0xfd45('0xaa'),_0x1f0259);})[_0xfd45('0x19')](function(_0x5bea7f){if(_0x5bea7f){var _0x4b86c6=0xc8;var _0x8d92d5=_0xfd45('0xab');logger[_0xfd45('0x1a')](_0xfd45('0x1e'),_0x8d92d5,_0x4b86c6,_0xfd45('0xac'));logger[_0xfd45('0x1d')]('SmsAccount,\x20%s,\x20%s,\x20%s,\x20%s',_0x8d92d5,_0x4b86c6,'entity\x20found',JSON['stringify'](_0x5bea7f));if(_0x1f0259['account'][_0xfd45('0x4b')]===_0xfd45('0xad')){return _0x19f598[_0xfd45('0x25')](_0x4b86c6)[_0xfd45('0x28')](_0xfd45('0xae'),_0xfd45('0xaf'))[_0xfd45('0x34')](_0xfd45('0xb0'));}else{return _0x19f598[_0xfd45('0x25')](_0x4b86c6)[_0xfd45('0x26')](_0x5bea7f);}}})[_0xfd45('0x23')](handleError(_0x19f598,null));};exports['addApplications']=function(_0x548a66,_0x489826,_0x58a616){return db[_0xfd45('0x38')][_0xfd45('0x61')]({'where':{'id':_0x548a66['params']['id']}})[_0xfd45('0x19')](handleEntityNotFound(_0x489826,null))['then'](function(_0x3ea1ed){if(_0x3ea1ed){return db['sequelize']['transaction'](function(_0x2897c8){return db[_0xfd45('0x6c')][_0xfd45('0x2d')]({'where':{'SmsAccountId':_0x548a66[_0xfd45('0x52')]['id']},'transaction':_0x2897c8})[_0xfd45('0x19')](function(_0x7ddd23){var _0x3f3b6d=_[_0xfd45('0x37')](_0x548a66['body'],function(_0x520408){_0x520408[_0xfd45('0x5e')]=_0x548a66[_0xfd45('0x52')]['id'];return _0x520408;});return db['SmsApplication']['bulkCreate'](_0x3f3b6d,{'transaction':_0x2897c8});});})[_0xfd45('0x19')](function(){return db[_0xfd45('0x6c')][_0xfd45('0xb1')]({'where':{'SmsAccountId':_0x548a66[_0xfd45('0x52')]['id']},'order':_0xfd45('0x70')});});}})[_0xfd45('0x19')](respondWithResult(_0x489826,null))[_0xfd45('0x23')](handleError(_0x489826,null));};exports[_0xfd45('0xb2')]=function(_0x4ea217,_0x1c0bc2,_0x3131d4){var _0x2d1251={};var _0x45595d={};var _0x853a86;var _0xea5cf9;return db[_0xfd45('0x38')][_0xfd45('0x61')]({'where':{'id':_0x4ea217['params']['id']}})[_0xfd45('0x19')](handleEntityNotFound(_0x1c0bc2,null))[_0xfd45('0x19')](function(_0x52f8ae){if(_0x52f8ae){_0x853a86=_0x52f8ae;_0x45595d[_0xfd45('0x3c')]=_[_0xfd45('0x3e')](db[_0xfd45('0x6c')][_0xfd45('0x39')]);_0x45595d[_0xfd45('0x3d')]=_['keys'](_0x4ea217[_0xfd45('0x3d')]);_0x45595d[_0xfd45('0x3f')]=_['intersection'](_0x45595d[_0xfd45('0x3c')],_0x45595d[_0xfd45('0x3d')]);_0x2d1251['attributes']=_[_0xfd45('0x40')](_0x45595d[_0xfd45('0x3c')],qs[_0xfd45('0x42')](_0x4ea217[_0xfd45('0x3d')][_0xfd45('0x42')]));_0x2d1251['attributes']=_0x2d1251[_0xfd45('0x41')][_0xfd45('0x43')]?_0x2d1251[_0xfd45('0x41')]:_0x45595d[_0xfd45('0x3c')];_0x2d1251[_0xfd45('0x68')]=qs[_0xfd45('0x47')](_0x4ea217['query'][_0xfd45('0x47')]);_0x2d1251[_0xfd45('0x48')]=qs['filters'](_[_0xfd45('0x62')](_0x4ea217[_0xfd45('0x3d')],_0x45595d[_0xfd45('0x3f')]));if(_0x4ea217[_0xfd45('0x3d')][_0xfd45('0x49')]){_0x2d1251[_0xfd45('0x48')]=_['merge'](_0x2d1251[_0xfd45('0x48')],{'$or':_['map'](_0x2d1251[_0xfd45('0x41')],function(_0x30adc2){var _0x435f20={};_0x435f20[_0x30adc2]={'$like':'%'+_0x4ea217['query']['filter']+'%'};return _0x435f20;})});}_0x2d1251=_['merge']({},_0x2d1251,_0x4ea217[_0xfd45('0x63')]);return _0x853a86['getApplications'](_0x2d1251);}})[_0xfd45('0x19')](function(_0x285831){if(_0x285831){_0xea5cf9=_0x285831[_0xfd45('0x43')];if(!_0x4ea217[_0xfd45('0x3d')][_0xfd45('0x44')](_0xfd45('0x45'))){_0x2d1251['limit']=qs[_0xfd45('0x46')](_0x4ea217['query'][_0xfd45('0x46')]);_0x2d1251[_0xfd45('0x27')]=qs[_0xfd45('0x27')](_0x4ea217[_0xfd45('0x3d')][_0xfd45('0x27')]);}return _0x853a86['getApplications'](_0x2d1251);}})[_0xfd45('0x19')](function(_0x21df1d){if(_0x21df1d){return _0x21df1d?{'count':_0xea5cf9,'rows':_0x21df1d}:null;}})[_0xfd45('0x19')](respondWithResult(_0x1c0bc2,null))[_0xfd45('0x23')](handleError(_0x1c0bc2,null));};exports[_0xfd45('0xb3')]=function(_0x219a3b,_0xdb55c0,_0x19031b){var _0x431429={'raw':![],'where':{}};var _0x9c3e04={};var _0x4c5af9={'count':0x0,'rows':[]};return db[_0xfd45('0x38')][_0xfd45('0x61')]({'where':{'id':_0x219a3b[_0xfd45('0x52')]['id']}})[_0xfd45('0x19')](handleEntityNotFound(_0xdb55c0,null))['then'](function(_0x3f10ba){if(_0x3f10ba){_0x9c3e04[_0xfd45('0x3c')]=_[_0xfd45('0x3e')](db[_0xfd45('0x9c')][_0xfd45('0x39')]);_0x9c3e04[_0xfd45('0x3d')]=_[_0xfd45('0x3e')](_0x219a3b[_0xfd45('0x3d')]);_0x9c3e04[_0xfd45('0x3f')]=_[_0xfd45('0x40')](_0x9c3e04['model'],_0x9c3e04[_0xfd45('0x3d')]);_0x431429[_0xfd45('0x41')]=_['intersection'](_0x9c3e04[_0xfd45('0x3c')],qs[_0xfd45('0x42')](_0x219a3b[_0xfd45('0x3d')]['fields']));_0x431429[_0xfd45('0x41')]=_0x431429[_0xfd45('0x41')][_0xfd45('0x43')]?_0x431429['attributes']:_0x9c3e04[_0xfd45('0x3c')];if(!_0x219a3b[_0xfd45('0x3d')][_0xfd45('0x44')](_0xfd45('0x45'))){_0x431429[_0xfd45('0x46')]=qs[_0xfd45('0x46')](_0x219a3b[_0xfd45('0x3d')][_0xfd45('0x46')]);_0x431429[_0xfd45('0x27')]=qs[_0xfd45('0x27')](_0x219a3b[_0xfd45('0x3d')][_0xfd45('0x27')]);}_0x431429[_0xfd45('0x68')]=qs[_0xfd45('0x47')](_0x219a3b[_0xfd45('0x3d')][_0xfd45('0x47')]);_0x431429[_0xfd45('0x48')]=qs[_0xfd45('0x3f')](_[_0xfd45('0x62')](_0x219a3b['query'],_0x9c3e04['filters']));_0x431429[_0xfd45('0x48')][_0xfd45('0x5e')]=_0x3f10ba['id'];if(_0x219a3b[_0xfd45('0x3d')]['filter']){_0x431429[_0xfd45('0x48')]=_[_0xfd45('0x4a')](_0x431429[_0xfd45('0x48')],{'$or':_['map'](_0x431429[_0xfd45('0x41')],function(_0x55d1ff){var _0x4fa154={};_0x4fa154[_0x55d1ff]={'$like':'%'+_0x219a3b[_0xfd45('0x3d')][_0xfd45('0x49')]+'%'};return _0x4fa154;})});}_0x431429=_[_0xfd45('0x4a')]({},_0x431429,_0x219a3b[_0xfd45('0x63')]);return db[_0xfd45('0x9c')][_0xfd45('0x4d')]({'where':_0x431429[_0xfd45('0x48')]})[_0xfd45('0x19')](function(_0x3c705d){_0x4c5af9[_0xfd45('0x4d')]=_0x3c705d;if(_0x219a3b[_0xfd45('0x3d')][_0xfd45('0x4e')]){_0x431429[_0xfd45('0x4f')]=[{'model':db[_0xfd45('0x72')],'as':_0xfd45('0xb4'),'required':![]},{'model':db[_0xfd45('0xb5')],'as':_0xfd45('0xb6'),'attributes':[_0xfd45('0x33'),_0xfd45('0xb7'),_0xfd45('0xb8')],'required':![]},{'model':db[_0xfd45('0xb9')],'as':'Tags','attributes':['id',_0xfd45('0x33'),_0xfd45('0xba')],'where':_0x219a3b[_0xfd45('0x3d')]['tag']?{'id':_0x219a3b[_0xfd45('0x3d')]['tag']}:undefined,'required':_0x219a3b[_0xfd45('0x3d')][_0xfd45('0xbb')]?!![]:![]}];}return db[_0xfd45('0x9c')][_0xfd45('0x50')](_0x431429);})[_0xfd45('0x19')](function(_0x138f80){_0x4c5af9[_0xfd45('0x64')]=_0x138f80;return _0x4c5af9;});}})[_0xfd45('0x19')](respondWithFilteredResult(_0xdb55c0,_0x431429))[_0xfd45('0x23')](handleError(_0xdb55c0,null));};exports['send']=function(_0x20bfa1,_0x26c4c3,_0x173552){var _0x3d3c2c,_0x1eb10c,_0x1e5e25;if(_[_0xfd45('0x91')](_0x20bfa1['body']['body'])||_0x20bfa1[_0xfd45('0x5a')][_0xfd45('0x5a')]===''){throw new db[(_0xfd45('0x73'))][(_0xfd45('0x74'))](_0xfd45('0x92'));}if(_['isNil'](_0x20bfa1[_0xfd45('0x5a')]['to'])){throw new db[(_0xfd45('0x73'))][(_0xfd45('0x74'))](_0xfd45('0xbc'));}_0x3d3c2c=_0x20bfa1[_0xfd45('0x5a')]['to'];return db['SmsAccount'][_0xfd45('0x5b')]({'where':{'id':_0x20bfa1[_0xfd45('0x52')]['id']},'include':[{'model':db[_0xfd45('0x95')],'as':_0xfd45('0xbd'),'include':[{'model':db[_0xfd45('0x72')],'as':_0xfd45('0x96'),'where':{'mobile':_0x3d3c2c},'limit':0x1,'order':[[_0xfd45('0x78'),_0xfd45('0x97')]]}]}]})[_0xfd45('0x19')](handleEntityNotFound(_0x26c4c3,null))[_0xfd45('0x19')](function(_0x80c27e){if(_0x80c27e&&_0x80c27e[_0xfd45('0xbd')]){_0x1eb10c=_0x80c27e['get']({'plain':!![]});if(_0x1eb10c[_0xfd45('0xbd')]&&_0x1eb10c['List'][_0xfd45('0x96')][_0xfd45('0x43')]){return _0x1eb10c[_0xfd45('0xbd')][_0xfd45('0x96')][0x0];}return db[_0xfd45('0x72')]['create'](_['defaults'](_0x20bfa1[_0xfd45('0x5a')],{'firstName':_0x3d3c2c,'mobile':_0x3d3c2c,'phone':_0x3d3c2c,'ListId':_0x1eb10c[_0xfd45('0x7a')]}));}})['then'](handleEntityNotFound(_0x26c4c3,null))[_0xfd45('0x19')](function(_0x12d50c){if(_0x12d50c){_0x1e5e25=_0x12d50c;return db[_0xfd45('0x9c')]['find']({'where':{'ContactId':_0x1e5e25['id'],'closed':![],'SmsAccountId':_0x1eb10c['id']}})['then'](function(_0x300686){if(_0x300686){return[_0x300686,![]];}return db[_0xfd45('0x9c')][_0xfd45('0x53')]({'UserId':_0x20bfa1[_0xfd45('0x54')]['id'],'ContactId':_0x1e5e25['id'],'SmsAccountId':_0x1eb10c['id'],'phone':_0x3d3c2c,'firstMsgDirection':_0xfd45('0xbe'),'Messages':[_[_0xfd45('0x4a')](_0x20bfa1[_0xfd45('0x5a')],{'read':![],'body':_0x20bfa1[_0xfd45('0x5a')][_0xfd45('0x5a')],'phone':_0x3d3c2c,'SmsAccountId':_0x1eb10c['id'],'UserId':_0x20bfa1[_0xfd45('0x54')]['id'],'ContactId':_0x1e5e25['id']})]},{'include':[{'model':db[_0xfd45('0xa5')],'as':_0xfd45('0xbf')}]})[_0xfd45('0x19')](function(_0xc04242){return[_0xc04242,!![]];});});}})['spread'](function(_0x55bb16,_0x298b9b){if(_0x298b9b){return _0x55bb16;}return db[_0xfd45('0xa5')]['create'](_[_0xfd45('0x4a')](_0x20bfa1[_0xfd45('0x5a')],{'read':![],'body':_0x20bfa1['body']['body'],'phone':_0x3d3c2c,'SmsAccountId':_0x1eb10c['id'],'SmsInteractionId':_0x55bb16['id'],'UserId':_0x20bfa1[_0xfd45('0x54')]['id'],'ContactId':_0x1e5e25['id']}))['then'](function(_0x1e61a3){_0x55bb16[_0xfd45('0xc0')]['Messages']=[];_0x55bb16[_0xfd45('0xc0')][_0xfd45('0xbf')][_0xfd45('0xa1')](_0x1e61a3['dataValues']);return _0x55bb16;});})[_0xfd45('0x19')](respondWithResult(_0x26c4c3,null))[_0xfd45('0x23')](handleError(_0x26c4c3,null));};exports[_0xfd45('0x25')]=function(_0x5332eb,_0x1629a0,_0x5cb474){if(_0x5332eb[_0xfd45('0x5a')]['id']){delete _0x5332eb[_0xfd45('0x5a')]['id'];}console[_0xfd45('0xc1')](_0xfd45('0xc2'),_0x5332eb['body']);var _0x4f60f7,_0x1e8eb1,_0x297c8e;return db['SmsAccount'][_0xfd45('0x5b')]({'where':{'id':_0x5332eb[_0xfd45('0x52')]['id']}})['then'](handleEntityNotFound(_0x1629a0,null))[_0xfd45('0x19')](function(_0x13ff14){if(_0x13ff14){_0x297c8e=_0x13ff14;logger['debug']('SmsAccount,\x20%s,\x20%s,\x20%s',_0xfd45('0x25'),_0xfd45('0xc3'),_0x13ff14['type'],util['inspect'](_0x5332eb[_0xfd45('0x5a')],{'showHidden':![],'depth':null}));switch(_0x13ff14[_0xfd45('0x4b')]){case _0xfd45('0x81'):if(_0x5332eb[_0xfd45('0x5a')]['skebby_dispatch_id']&&_0x5332eb[_0xfd45('0x5a')]['status']){_0x1e8eb1=_0x5332eb[_0xfd45('0x5a')][_0xfd45('0x25')];return db[_0xfd45('0xa5')]['find']({'where':{'messageId':_0x5332eb[_0xfd45('0x5a')]['skebby_dispatch_id']}});}break;case _0xfd45('0x85'):if(_0x5332eb[_0xfd45('0x5a')][_0xfd45('0xc4')]&&_0x5332eb[_0xfd45('0x5a')]['statusInt']){_0x1e8eb1=_0x5332eb[_0xfd45('0x5a')][_0xfd45('0xc5')];return db[_0xfd45('0xa5')]['find']({'where':{'messageId':_0x5332eb[_0xfd45('0x5a')][_0xfd45('0xc4')]}});}break;case _0xfd45('0x86'):if(_0x5332eb[_0xfd45('0x5a')][_0xfd45('0x87')]&&_0x5332eb[_0xfd45('0x5a')][_0xfd45('0xc6')]){_0x1e8eb1=_0x5332eb[_0xfd45('0x5a')][_0xfd45('0xc6')];return db[_0xfd45('0xa5')]['find']({'where':{'messageId':_0x5332eb['body'][_0xfd45('0x87')]}});}break;case _0xfd45('0x89'):var _0x5ef678=_0x5332eb[_0xfd45('0x5a')][_0xfd45('0x8a')][0x0];if(_0x5ef678[_0xfd45('0x7f')]&&_0x5ef678[_0xfd45('0x25')][_0xfd45('0xc7')]==='DELIVERED'){_0x1e8eb1=_0x5ef678[_0xfd45('0x25')][_0xfd45('0xc7')];return db[_0xfd45('0xa5')][_0xfd45('0x5b')]({'where':{'messageId':_0x5ef678[_0xfd45('0x7f')]}});}break;case _0xfd45('0xc8'):if(_0x5332eb[_0xfd45('0x5a')]['messageId']&&_0x5332eb[_0xfd45('0x5a')]['status']){_0x1e8eb1=_0x5332eb[_0xfd45('0x5a')][_0xfd45('0x25')];return db[_0xfd45('0xa5')]['find']({'where':{'messageId':_0x5332eb[_0xfd45('0x5a')]['messageId']}});}break;case _0xfd45('0x8f'):if(_0x5332eb[_0xfd45('0x5a')][_0xfd45('0xc9')]&&_0x5332eb[_0xfd45('0x5a')][_0xfd45('0x25')]){_0x1e8eb1=_0x5332eb[_0xfd45('0x5a')][_0xfd45('0x25')];return db['SmsMessage'][_0xfd45('0x5b')]({'where':{'messageId':_0x5332eb[_0xfd45('0x5a')][_0xfd45('0xc9')]}});}break;}}})[_0xfd45('0x19')](handleEntityNotFound(_0x1629a0,null))[_0xfd45('0x19')](function(_0x3ddd81){if(_0x3ddd81){_0x4f60f7=_0x3ddd81;switch(_0x297c8e[_0xfd45('0x4b')]){case'skebby':if(_0x1e8eb1===_0xfd45('0xca')){return _0x4f60f7[_0xfd45('0x2c')]({'read':!![]});}else{logger[_0xfd45('0x20')](_0xfd45('0x1e'),_0xfd45('0x25'),_0xfd45('0x81'),util['inspect'](_0x5332eb[_0xfd45('0x5a')],{'showHidden':![],'depth':null}));}break;case _0xfd45('0x85'):if(_0x1e8eb1==='1'){return _0x4f60f7[_0xfd45('0x2c')]({'read':!![]});}else{logger[_0xfd45('0x20')](_0xfd45('0x1e'),_0xfd45('0x25'),_0xfd45('0x81'),util['inspect'](_0x5332eb[_0xfd45('0x5a')],{'showHidden':![],'depth':null}));}break;case _0xfd45('0x86'):if(!_0x5332eb[_0xfd45('0x5a')][_0xfd45('0xcb')]&&_0x1e8eb1>=0xc8&&_0x1e8eb1<=0xce){return _0x4f60f7[_0xfd45('0x2c')]({'read':!![]});}else{logger[_0xfd45('0x20')](_0xfd45('0x1e'),_0xfd45('0x25'),_0xfd45('0x86'),util[_0xfd45('0xcc')](_0x5332eb['body'],{'showHidden':![],'depth':null}));}break;case _0xfd45('0x89'):var _0x80edbf=_0x5332eb[_0xfd45('0x5a')]['results'][0x0];if(_0x80edbf[_0xfd45('0x25')][_0xfd45('0xc7')]===_0xfd45('0xca')){return _0x4f60f7[_0xfd45('0x2c')]({'read':!![]});}else{logger[_0xfd45('0x20')]('SmsAccount,\x20%s,\x20%s,\x20%s','status',_0xfd45('0x89'),util['inspect'](_0x5332eb[_0xfd45('0x5a')],{'showHidden':![],'depth':null}));}break;case _0xfd45('0xc8'):if(_0x1e8eb1==_0xfd45('0xcd')||_0x1e8eb1==_0xfd45('0xce')){return _0x4f60f7['update']({'read':!![]});}else{logger[_0xfd45('0x20')](_0xfd45('0x1e'),_0xfd45('0x25'),_0xfd45('0xc8'),util[_0xfd45('0xcc')](_0x5332eb[_0xfd45('0x5a')],{'showHidden':![],'depth':null}));}break;case _0xfd45('0x8f'):if(_0x1e8eb1===_0xfd45('0xcf')||_0x1e8eb1==='ACCEPTD'){return _0x4f60f7[_0xfd45('0x2c')]({'read':!![]});}else{logger[_0xfd45('0x20')](_0xfd45('0x1e'),_0xfd45('0x25'),_0xfd45('0x8f'),util[_0xfd45('0xcc')](_0x5332eb['body'],{'showHidden':![],'depth':null}));}break;}return _0x4f60f7;}})[_0xfd45('0x19')](respondWithResult(_0x1629a0,null))[_0xfd45('0x23')](handleError(_0x1629a0,null));};exports[_0xfd45('0xd0')]=function(_0x2ae012,_0x19a5e8,_0x49df75){var _0x1838d0,_0x22986d,_0x522f25;return db[_0xfd45('0x38')]['find']({'where':{'id':_0x2ae012[_0xfd45('0x52')]['id']}})['then'](handleEntityNotFound(_0x19a5e8,null))[_0xfd45('0x19')](function(_0x128afb){if(_0x128afb){_0x522f25=_0x128afb;logger['debug']('SmsAccount,\x20%s,\x20%s,\x20%s','status',_0xfd45('0xc3'),_0x128afb[_0xfd45('0x4b')],util['inspect'](_0x2ae012[_0xfd45('0x3d')],{'showHidden':![],'depth':null}));switch(_0x128afb[_0xfd45('0x4b')]){case _0xfd45('0x8b'):if(_0x2ae012[_0xfd45('0x3d')][_0xfd45('0xd1')]&&_0x2ae012[_0xfd45('0x3d')][_0xfd45('0xd2')]){_0x22986d=_0x2ae012[_0xfd45('0x3d')][_0xfd45('0xd2')];return db[_0xfd45('0xa5')][_0xfd45('0x5b')]({'where':{'messageId':_0x2ae012[_0xfd45('0x3d')][_0xfd45('0xd1')]}});}break;}}})['then'](handleEntityNotFound(_0x19a5e8,null))['then'](function(_0x1ca2ba){if(_0x1ca2ba){_0x1838d0=_0x1ca2ba;switch(_0x522f25[_0xfd45('0x4b')]){case _0xfd45('0x8b'):if(_0x22986d==='2'||_0x22986d==='6'){return _0x1838d0[_0xfd45('0x2c')]({'read':!![]});}else{logger['error'](_0xfd45('0x1e'),_0xfd45('0x25'),'csc',util[_0xfd45('0xcc')](_0x2ae012[_0xfd45('0x3d')],{'showHidden':![],'depth':null}));};break;}return _0x1838d0;}})[_0xfd45('0x19')](respondWithResult(_0x19a5e8,null))[_0xfd45('0x23')](handleError(_0x19a5e8,null));};exports['addAgents']=function(_0x25a640,_0x100a16,_0x3df219){return db[_0xfd45('0x38')][_0xfd45('0x5b')]({'where':{'id':_0x25a640[_0xfd45('0x52')]['id']}})[_0xfd45('0x19')](handleEntityNotFound(_0x100a16,null))[_0xfd45('0x19')](function(_0xdbf20e){if(_0xdbf20e){return _0xdbf20e[_0xfd45('0xd3')](_0x25a640[_0xfd45('0x5a')]['ids'],_[_0xfd45('0x99')](_0x25a640['body'],[_0xfd45('0x66'),'id'])||{})[_0xfd45('0x9d')](function(_0x2866c1){for(var _0x29ac97=0x0;_0x29ac97<_0x25a640[_0xfd45('0x5a')][_0xfd45('0x66')][_0xfd45('0x43')];_0x29ac97+=0x1){socket[_0xfd45('0xd4')](_0xfd45('0xd5'),{'UserId':_0x25a640[_0xfd45('0x5a')]['ids'][_0x29ac97],'SmsAccountId':_0x25a640[_0xfd45('0x52')]['id']});}return _0x2866c1;});}})[_0xfd45('0x19')](respondWithResult(_0x100a16,null))[_0xfd45('0x23')](handleError(_0x100a16,null));};exports[_0xfd45('0xd6')]=function(_0x27680e,_0x1815d2,_0x104f0f){return db['SmsAccount'][_0xfd45('0x5b')]({'where':{'id':_0x27680e[_0xfd45('0x52')]['id']}})[_0xfd45('0x19')](handleEntityNotFound(_0x1815d2,null))[_0xfd45('0x19')](function(_0x21c6ae){if(_0x21c6ae){return _0x21c6ae[_0xfd45('0xd6')](_0x27680e[_0xfd45('0x3d')][_0xfd45('0x66')])['then'](function(){if(_[_0xfd45('0xd7')](_0x27680e[_0xfd45('0x3d')][_0xfd45('0x66')])){for(var _0x104c66=0x0;_0x104c66<_0x27680e[_0xfd45('0x3d')]['ids'][_0xfd45('0x43')];_0x104c66+=0x1){socket[_0xfd45('0xd4')](_0xfd45('0xd8'),{'UserId':Number(_0x27680e['query'][_0xfd45('0x66')][_0x104c66]),'SmsAccountId':Number(_0x27680e[_0xfd45('0x52')]['id'])});}}else{socket[_0xfd45('0xd4')](_0xfd45('0xd8'),{'UserId':Number(_0x27680e[_0xfd45('0x3d')][_0xfd45('0x66')]),'SmsAccountId':Number(_0x27680e[_0xfd45('0x52')]['id'])});}});}})[_0xfd45('0x19')](respondWithStatusCode(_0x1815d2,null))[_0xfd45('0x23')](handleError(_0x1815d2,null));};exports[_0xfd45('0xd9')]=function(_0x28979c,_0x30c91a,_0x377276){var _0x2b5538={};var _0x5290b7={};var _0x18c115;var _0x48129a;return db['SmsAccount'][_0xfd45('0x61')]({'where':{'id':_0x28979c[_0xfd45('0x52')]['id']}})[_0xfd45('0x19')](handleEntityNotFound(_0x30c91a,null))[_0xfd45('0x19')](function(_0x1906a3){if(_0x1906a3){_0x18c115=_0x1906a3;_0x5290b7[_0xfd45('0x3c')]=_[_0xfd45('0x3e')](db[_0xfd45('0xb5')]['rawAttributes']);_0x5290b7['query']=_[_0xfd45('0x3e')](_0x28979c[_0xfd45('0x3d')]);_0x5290b7[_0xfd45('0x3f')]=_[_0xfd45('0x40')](_0x5290b7['model'],_0x5290b7['query']);_0x2b5538[_0xfd45('0x41')]=_[_0xfd45('0x40')](_0x5290b7[_0xfd45('0x3c')],qs['fields'](_0x28979c[_0xfd45('0x3d')][_0xfd45('0x42')]));_0x2b5538[_0xfd45('0x41')]=_0x2b5538[_0xfd45('0x41')]['length']?_0x2b5538[_0xfd45('0x41')]:_0x5290b7['model'];_0x2b5538['order']=qs['sort'](_0x28979c['query'][_0xfd45('0x47')]);_0x2b5538[_0xfd45('0x48')]=qs['filters'](_['pick'](_0x28979c[_0xfd45('0x3d')],_0x5290b7['filters']));if(_0x28979c[_0xfd45('0x3d')]['filter']){_0x2b5538[_0xfd45('0x48')]=_[_0xfd45('0x4a')](_0x2b5538[_0xfd45('0x48')],{'$or':_[_0xfd45('0x37')](_0x2b5538[_0xfd45('0x41')],function(_0x2a745a){var _0x3a87fa={};_0x3a87fa[_0x2a745a]={'$like':'%'+_0x28979c[_0xfd45('0x3d')][_0xfd45('0x49')]+'%'};return _0x3a87fa;})});}_0x2b5538=_[_0xfd45('0x4a')]({},_0x2b5538,_0x28979c[_0xfd45('0x63')]);return _0x18c115[_0xfd45('0xd9')](_0x2b5538);}})[_0xfd45('0x19')](function(_0x19d190){if(_0x19d190){_0x48129a=_0x19d190[_0xfd45('0x43')];if(!_0x28979c[_0xfd45('0x3d')][_0xfd45('0x44')](_0xfd45('0x45'))){_0x2b5538[_0xfd45('0x46')]=qs[_0xfd45('0x46')](_0x28979c[_0xfd45('0x3d')][_0xfd45('0x46')]);_0x2b5538[_0xfd45('0x27')]=qs['offset'](_0x28979c[_0xfd45('0x3d')][_0xfd45('0x27')]);}return _0x18c115[_0xfd45('0xd9')](_0x2b5538);}})[_0xfd45('0x19')](function(_0x4e244f){if(_0x4e244f){return _0x4e244f?{'count':_0x48129a,'rows':_0x4e244f}:null;}})[_0xfd45('0x19')](respondWithResult(_0x30c91a,null))['catch'](handleError(_0x30c91a,null));};
\ No newline at end of file
+var _0x6bd6=['ejs','fs-extra','lodash','jsforce','to-csv','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','localhost','register','jayson/promise','client','http','then','info','request\x20sent','debug','SmsAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','SmsAccount,\x20%s,\x20%s','message','result','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','destroy','UserProfileResource','stack','name','send','Pause','map','SmsAccount','fieldName','type','key','model','keys','query','filters','intersection','attributes','fields','hasOwnProperty','nolimit','order','sort','pick','where','merge','filter','include','findAll','rows','catch','show','mandatoryDispositionPause','rawAttributes','length','create','body','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','SmsAccounts','UserProfileSection','find','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','describe','addDisposition','Disposition','getDispositions','findOne','SmsAccountId','options','removeDispositions','ids','addAnswer','CannedAnswer','removeAnswers','notify','sms','SmsApplication','Applications','account','applications','orderBy','priority','Sequelize','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','mobile','from','From','Body','skebby','text','connectel','messageId','message_id','plivo','MessageUUID','infobip','results','csc','originatingAddress','fromNumber','replyMessageId','bandwidth','intelepeer','refid','isNil','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','includes','mapKey','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','ListId','CmContact','Contacts','contact','SmsInteraction','spread','interaction','created','autoclose','push','close','unmanaged','*,*,*,*','SmsMessage','ContactId','AttachmentId','UserId','User','agent','startRouting','Start','receiveMessage','entity\x20found','SmsAccount,\x20%s,\x20%s,\x20%s,\x20%s','Content-Type','text/xml','<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>','addApplications','sequelize','transaction','findAndCountAll','getApplications','getInteractions','includeAll','Contact','Owner','internal','Tag','color','tag','DESC','List','defaults','dataValues','Messages','received\x20delivery\x20report\x20from','inspect','skebby_dispatch_id','requestid','statusInt','status_code','DELIVERED','groupName','clickatell','redif','clicksend','DELIVERED_TO_GATEWAY','RECEIVED_BY_RECIPIENT','message-delivered','DELIVRD','ACCEPTD','statusGet','message-id','state','addAgents','omit','userSmsAccount:save','removeAgents','emit','userSmsAccount:remove','getAgents','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','path'];(function(_0x39c734,_0x2f3e06){var _0xb2a2f9=function(_0x502f3f){while(--_0x502f3f){_0x39c734['push'](_0x39c734['shift']());}};_0xb2a2f9(++_0x2f3e06);}(_0x6bd6,0xda));var _0x66bd=function(_0xea81a1,_0xb28e9e){_0xea81a1=_0xea81a1-0x0;var _0x2cd030=_0x6bd6[_0xea81a1];return _0x2cd030;};'use strict';var emlformat=require(_0x66bd('0x0'));var rimraf=require(_0x66bd('0x1'));var zipdir=require(_0x66bd('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x66bd('0x3'));var moment=require(_0x66bd('0x4'));var BPromise=require(_0x66bd('0x5'));var Mustache=require(_0x66bd('0x6'));var util=require(_0x66bd('0x7'));var path=require(_0x66bd('0x8'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x66bd('0x9'));var fs=require('fs');var fs_extra=require(_0x66bd('0xa'));var _=require(_0x66bd('0xb'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x66bd('0xc'));var deskjs=require('desk.js');var toCsv=require(_0x66bd('0xd'));var querystring=require('querystring');var Papa=require(_0x66bd('0xe'));var Redis=require(_0x66bd('0xf'));var authService=require(_0x66bd('0x10'));var qs=require(_0x66bd('0x11'));var as=require(_0x66bd('0x12'));var hardwareService=require(_0x66bd('0x13'));var logger=require(_0x66bd('0x14'))('api');var utils=require(_0x66bd('0x15'));var config=require(_0x66bd('0x16'));var licenseUtil=require(_0x66bd('0x17'));var db=require(_0x66bd('0x18'))['db'];config['redis']=_['defaults'](config[_0x66bd('0x19')],{'host':_0x66bd('0x1a'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x66bd('0x19')]));require('./smsAccount.socket')[_0x66bd('0x1b')](socket);var jayson=require(_0x66bd('0x1c'));var client=jayson[_0x66bd('0x1d')][_0x66bd('0x1e')]({'port':0x232c});function respondWithRpcPromise(_0x1eb8ba,_0x327b14,_0x4ed1a7,_0x15b087){return new BPromise(function(_0xe96ffe,_0x466ac7){var _0x3e4b74=_0x15b087||client;return _0x3e4b74['request'](_0x1eb8ba,_0x4ed1a7)[_0x66bd('0x1f')](function(_0xedba23){logger[_0x66bd('0x20')]('SmsAccount,\x20%s,\x20%s',_0x327b14,_0x66bd('0x21'));logger[_0x66bd('0x22')](_0x66bd('0x23'),_0x327b14,_0x66bd('0x21'),JSON[_0x66bd('0x24')](_0xedba23));if(_0xedba23[_0x66bd('0x25')]){if(_0xedba23[_0x66bd('0x25')][_0x66bd('0x26')]===0x1f4){logger[_0x66bd('0x25')](_0x66bd('0x27'),_0x327b14,_0xedba23[_0x66bd('0x25')]['message']);return _0x466ac7(_0xedba23[_0x66bd('0x25')][_0x66bd('0x28')]);}logger[_0x66bd('0x25')]('SmsAccount,\x20%s,\x20%s',_0x327b14,_0xedba23[_0x66bd('0x25')][_0x66bd('0x28')]);return _0xe96ffe(_0xedba23[_0x66bd('0x25')][_0x66bd('0x28')]);}else{logger[_0x66bd('0x20')]('SmsAccount,\x20%s,\x20%s',_0x327b14,_0x66bd('0x21'));_0xe96ffe(_0xedba23[_0x66bd('0x29')][_0x66bd('0x28')]);}})['catch'](function(_0x3d3cfb){logger[_0x66bd('0x25')](_0x66bd('0x27'),_0x327b14,_0x3d3cfb);_0x466ac7(_0x3d3cfb);});});}function respondWithStatusCode(_0x38fd52,_0x4bc7cd){_0x4bc7cd=_0x4bc7cd||0xcc;return function(_0x59ed24){if(_0x59ed24){return _0x38fd52[_0x66bd('0x2a')](_0x4bc7cd);}return _0x38fd52[_0x66bd('0x2b')](_0x4bc7cd)[_0x66bd('0x2c')]();};}function respondWithResult(_0x236a30,_0x2023ed){_0x2023ed=_0x2023ed||0xc8;return function(_0x35c49d){if(_0x35c49d){return _0x236a30[_0x66bd('0x2b')](_0x2023ed)[_0x66bd('0x2d')](_0x35c49d);}};}function respondWithFilteredResult(_0x685c87,_0x46bafb){return function(_0x4b32bd){if(_0x4b32bd){var _0x19b428=typeof _0x46bafb[_0x66bd('0x2e')]===_0x66bd('0x2f')&&typeof _0x46bafb[_0x66bd('0x30')]===_0x66bd('0x2f');var _0xe24c69=_0x4b32bd['count'];var _0x57ccee=_0x19b428?0x0:_0x46bafb[_0x66bd('0x2e')];var _0x50744b=_0x19b428?_0x4b32bd[_0x66bd('0x31')]:_0x46bafb[_0x66bd('0x2e')]+_0x46bafb[_0x66bd('0x30')];var _0xd5e7dc;if(_0x50744b>=_0xe24c69){_0x50744b=_0xe24c69;_0xd5e7dc=0xc8;}else{_0xd5e7dc=0xce;}_0x685c87['status'](_0xd5e7dc);return _0x685c87[_0x66bd('0x32')](_0x66bd('0x33'),_0x57ccee+'-'+_0x50744b+'/'+_0xe24c69)[_0x66bd('0x2d')](_0x4b32bd);}return null;};}function patchUpdates(_0x356118){return function(_0x2f14e5){try{jsonpatch[_0x66bd('0x34')](_0x2f14e5,_0x356118,!![]);}catch(_0x92203a){return BPromise[_0x66bd('0x35')](_0x92203a);}return _0x2f14e5[_0x66bd('0x36')]();};}function saveUpdates(_0x56a28d,_0x18c645){return function(_0x540486){if(_0x540486){return _0x540486[_0x66bd('0x37')](_0x56a28d)[_0x66bd('0x1f')](function(_0x343757){return _0x343757;});}return null;};}function removeEntity(_0x283cf7,_0x39c5fe){return function(_0x3aa5b6){if(_0x3aa5b6){return _0x3aa5b6[_0x66bd('0x38')]()[_0x66bd('0x1f')](function(){var _0x856ca5=_0x3aa5b6['get']({'plain':!![]});var _0xa8a195='SmsAccounts';return db[_0x66bd('0x39')][_0x66bd('0x38')]({'where':{'type':_0xa8a195,'resourceId':_0x856ca5['id']}})[_0x66bd('0x1f')](function(){return _0x3aa5b6;});})[_0x66bd('0x1f')](function(){_0x283cf7[_0x66bd('0x2b')](0xcc)[_0x66bd('0x2c')]();});}};}function handleEntityNotFound(_0x4c42,_0x35e1ba){return function(_0x403c1c){if(!_0x403c1c){_0x4c42['sendStatus'](0x194);}return _0x403c1c;};}function handleError(_0x566ece,_0x588082){_0x588082=_0x588082||0x1f4;return function(_0x20c686){logger[_0x66bd('0x25')](_0x20c686[_0x66bd('0x3a')]);if(_0x20c686[_0x66bd('0x3b')]){delete _0x20c686[_0x66bd('0x3b')];}_0x566ece[_0x66bd('0x2b')](_0x588082)[_0x66bd('0x3c')](_0x20c686);};}exports['index']=function(_0x585201,_0x477e78){var _0x16eb0c={'include':[{'model':db[_0x66bd('0x3d')],'as':'mandatoryDispositionPause'}]},_0x1a9585={},_0x43f3af={'count':0x0,'rows':[]};var _0x9e6b20=_[_0x66bd('0x3e')](db[_0x66bd('0x3f')]['rawAttributes'],function(_0x49d7b0){return{'name':_0x49d7b0[_0x66bd('0x40')],'type':_0x49d7b0[_0x66bd('0x41')][_0x66bd('0x42')]};});_0x1a9585[_0x66bd('0x43')]=_[_0x66bd('0x3e')](_0x9e6b20,_0x66bd('0x3b'));_0x1a9585['query']=_[_0x66bd('0x44')](_0x585201[_0x66bd('0x45')]);_0x1a9585[_0x66bd('0x46')]=_[_0x66bd('0x47')](_0x1a9585[_0x66bd('0x43')],_0x1a9585[_0x66bd('0x45')]);_0x16eb0c[_0x66bd('0x48')]=_[_0x66bd('0x47')](_0x1a9585[_0x66bd('0x43')],qs[_0x66bd('0x49')](_0x585201[_0x66bd('0x45')][_0x66bd('0x49')]));_0x16eb0c[_0x66bd('0x48')]=_0x16eb0c[_0x66bd('0x48')]['length']?_0x16eb0c[_0x66bd('0x48')]:_0x1a9585[_0x66bd('0x43')];if(!_0x585201[_0x66bd('0x45')][_0x66bd('0x4a')](_0x66bd('0x4b'))){_0x16eb0c[_0x66bd('0x30')]=qs[_0x66bd('0x30')](_0x585201[_0x66bd('0x45')][_0x66bd('0x30')]);_0x16eb0c['offset']=qs[_0x66bd('0x2e')](_0x585201[_0x66bd('0x45')]['offset']);}_0x16eb0c[_0x66bd('0x4c')]=qs[_0x66bd('0x4d')](_0x585201[_0x66bd('0x45')][_0x66bd('0x4d')]);_0x16eb0c['where']=qs['filters'](_[_0x66bd('0x4e')](_0x585201['query'],_0x1a9585['filters']),_0x9e6b20);if(_0x585201[_0x66bd('0x45')]['filter']){_0x16eb0c[_0x66bd('0x4f')]=_[_0x66bd('0x50')](_0x16eb0c[_0x66bd('0x4f')],{'$or':_[_0x66bd('0x3e')](_0x9e6b20,function(_0x4be6f9){if(_0x4be6f9[_0x66bd('0x41')]!=='VIRTUAL'){var _0x417a3a={};_0x417a3a[_0x4be6f9['name']]={'$like':'%'+_0x585201['query'][_0x66bd('0x51')]+'%'};return _0x417a3a;}})});}_0x16eb0c=_['merge']({},_0x16eb0c,_0x585201['options']);var _0x4d23ad={'where':_0x16eb0c[_0x66bd('0x4f')]};return db[_0x66bd('0x3f')]['count'](_0x4d23ad)[_0x66bd('0x1f')](function(_0x324584){_0x43f3af[_0x66bd('0x31')]=_0x324584;if(_0x585201[_0x66bd('0x45')]['includeAll']){_0x16eb0c[_0x66bd('0x52')]=[{'all':!![]}];}return db['SmsAccount'][_0x66bd('0x53')](_0x16eb0c);})[_0x66bd('0x1f')](function(_0x5e05e6){_0x43f3af[_0x66bd('0x54')]=_0x5e05e6;return _0x43f3af;})['then'](respondWithFilteredResult(_0x477e78,_0x16eb0c))[_0x66bd('0x55')](handleError(_0x477e78,null));};exports[_0x66bd('0x56')]=function(_0x59875a,_0x5d3eef){var _0x3e1819={'raw':![],'where':{'id':_0x59875a['params']['id']},'include':[{'model':db[_0x66bd('0x3d')],'as':_0x66bd('0x57')}]},_0x44bc15={};_0x44bc15[_0x66bd('0x43')]=_[_0x66bd('0x44')](db['SmsAccount'][_0x66bd('0x58')]);_0x44bc15[_0x66bd('0x45')]=_[_0x66bd('0x44')](_0x59875a[_0x66bd('0x45')]);_0x44bc15[_0x66bd('0x46')]=_[_0x66bd('0x47')](_0x44bc15[_0x66bd('0x43')],_0x44bc15['query']);_0x3e1819[_0x66bd('0x48')]=_[_0x66bd('0x47')](_0x44bc15[_0x66bd('0x43')],qs[_0x66bd('0x49')](_0x59875a[_0x66bd('0x45')][_0x66bd('0x49')]));_0x3e1819['attributes']=_0x3e1819['attributes'][_0x66bd('0x59')]?_0x3e1819[_0x66bd('0x48')]:_0x44bc15[_0x66bd('0x43')];if(_0x59875a[_0x66bd('0x45')]['includeAll']){_0x3e1819[_0x66bd('0x52')]=[{'all':!![]}];}_0x3e1819=_['merge']({},_0x3e1819,_0x59875a['options']);return db[_0x66bd('0x3f')]['find'](_0x3e1819)[_0x66bd('0x1f')](handleEntityNotFound(_0x5d3eef,null))['then'](respondWithResult(_0x5d3eef,null))['catch'](handleError(_0x5d3eef,null));};exports['create']=function(_0x574504,_0x24f76a){return db[_0x66bd('0x3f')][_0x66bd('0x5a')](_0x574504[_0x66bd('0x5b')],{})[_0x66bd('0x1f')](function(_0x5c2076){var _0x3040d8=_0x574504[_0x66bd('0x5c')][_0x66bd('0x5d')]({'plain':!![]});if(!_0x3040d8)throw new Error(_0x66bd('0x5e'));if(_0x3040d8[_0x66bd('0x5f')]===_0x66bd('0x5c')){var _0x55a5c4=_0x5c2076[_0x66bd('0x5d')]({'plain':!![]});var _0x4c087a=_0x66bd('0x60');return db[_0x66bd('0x61')][_0x66bd('0x62')]({'where':{'name':_0x4c087a,'userProfileId':_0x3040d8[_0x66bd('0x63')]},'raw':!![]})[_0x66bd('0x1f')](function(_0x18b769){if(_0x18b769&&_0x18b769[_0x66bd('0x64')]===0x0){return db['UserProfileResource'][_0x66bd('0x5a')]({'name':_0x55a5c4['name'],'resourceId':_0x55a5c4['id'],'type':_0x18b769[_0x66bd('0x3b')],'sectionId':_0x18b769['id']},{})[_0x66bd('0x1f')](function(){return _0x5c2076;});}else{return _0x5c2076;}})[_0x66bd('0x55')](function(_0x483fc8){logger['error'](_0x66bd('0x65'),_0x483fc8);throw _0x483fc8;});}return _0x5c2076;})[_0x66bd('0x1f')](respondWithResult(_0x24f76a,0xc9))[_0x66bd('0x55')](handleError(_0x24f76a,null));};exports['update']=function(_0x1a64cc,_0x34aaa0){if(_0x1a64cc[_0x66bd('0x5b')]['id']){delete _0x1a64cc['body']['id'];}return db[_0x66bd('0x3f')][_0x66bd('0x62')]({'where':{'id':_0x1a64cc[_0x66bd('0x66')]['id']},'include':[{'model':db[_0x66bd('0x3d')],'as':_0x66bd('0x57')}]})[_0x66bd('0x1f')](handleEntityNotFound(_0x34aaa0,null))[_0x66bd('0x1f')](saveUpdates(_0x1a64cc['body'],null))['then'](respondWithResult(_0x34aaa0,null))[_0x66bd('0x55')](handleError(_0x34aaa0,null));};exports[_0x66bd('0x38')]=function(_0x44e835,_0x579c25){return db['SmsAccount'][_0x66bd('0x62')]({'where':{'id':_0x44e835[_0x66bd('0x66')]['id']}})['then'](handleEntityNotFound(_0x579c25,null))[_0x66bd('0x1f')](removeEntity(_0x579c25,null))['catch'](handleError(_0x579c25,null));};exports['describe']=function(_0x2f00ef,_0x2be71c){return db[_0x66bd('0x3f')][_0x66bd('0x67')]()['then'](respondWithResult(_0x2be71c,null))['catch'](handleError(_0x2be71c,null));};exports[_0x66bd('0x68')]=function(_0x4f2618,_0x4e4af4,_0x1e15dc){if(_0x4f2618[_0x66bd('0x5b')]['id']){delete _0x4f2618[_0x66bd('0x5b')]['id'];}return db[_0x66bd('0x3f')][_0x66bd('0x62')]({'where':{'id':_0x4f2618[_0x66bd('0x66')]['id']}})[_0x66bd('0x1f')](handleEntityNotFound(_0x4e4af4,null))['then'](function(_0x10f296){if(_0x10f296){_0x4f2618[_0x66bd('0x5b')]['SmsAccountId']=_0x10f296['id'];return db[_0x66bd('0x69')][_0x66bd('0x5a')](_0x4f2618[_0x66bd('0x5b')]);}})['then'](respondWithResult(_0x4e4af4,null))['catch'](handleError(_0x4e4af4,null));};exports[_0x66bd('0x6a')]=function(_0x2b3a6d,_0x49d131,_0x28e502){var _0x18fa73={'raw':![],'where':{}};var _0x52d930={};var _0x4a7ff4={'count':0x0,'rows':[]};return db[_0x66bd('0x3f')][_0x66bd('0x6b')]({'where':{'id':_0x2b3a6d[_0x66bd('0x66')]['id']}})[_0x66bd('0x1f')](handleEntityNotFound(_0x49d131,null))[_0x66bd('0x1f')](function(_0x18ed8a){if(_0x18ed8a){_0x52d930['model']=_[_0x66bd('0x44')](db[_0x66bd('0x69')][_0x66bd('0x58')]);_0x52d930[_0x66bd('0x45')]=_[_0x66bd('0x44')](_0x2b3a6d['query']);_0x52d930[_0x66bd('0x46')]=_['intersection'](_0x52d930[_0x66bd('0x43')],_0x52d930['query']);_0x18fa73[_0x66bd('0x48')]=_['intersection'](_0x52d930[_0x66bd('0x43')],qs['fields'](_0x2b3a6d['query'][_0x66bd('0x49')]));_0x18fa73['attributes']=_0x18fa73[_0x66bd('0x48')]['length']?_0x18fa73[_0x66bd('0x48')]:_0x52d930[_0x66bd('0x43')];if(!_0x2b3a6d[_0x66bd('0x45')]['hasOwnProperty'](_0x66bd('0x4b'))){_0x18fa73[_0x66bd('0x30')]=qs[_0x66bd('0x30')](_0x2b3a6d[_0x66bd('0x45')][_0x66bd('0x30')]);_0x18fa73[_0x66bd('0x2e')]=qs['offset'](_0x2b3a6d[_0x66bd('0x45')]['offset']);}_0x18fa73[_0x66bd('0x4c')]=qs[_0x66bd('0x4d')](_0x2b3a6d[_0x66bd('0x45')][_0x66bd('0x4d')]);_0x18fa73[_0x66bd('0x4f')]=qs[_0x66bd('0x46')](_['pick'](_0x2b3a6d[_0x66bd('0x45')],_0x52d930[_0x66bd('0x46')]));_0x18fa73[_0x66bd('0x4f')][_0x66bd('0x6c')]=_0x18ed8a['id'];if(_0x2b3a6d[_0x66bd('0x45')][_0x66bd('0x51')]){_0x18fa73[_0x66bd('0x4f')]=_['merge'](_0x18fa73[_0x66bd('0x4f')],{'$or':_[_0x66bd('0x3e')](_0x18fa73[_0x66bd('0x48')],function(_0x5cc03c){var _0x3af3a1={};_0x3af3a1[_0x5cc03c]={'$like':'%'+_0x2b3a6d[_0x66bd('0x45')]['filter']+'%'};return _0x3af3a1;})});}_0x18fa73=_[_0x66bd('0x50')]({},_0x18fa73,_0x2b3a6d[_0x66bd('0x6d')]);return db[_0x66bd('0x69')][_0x66bd('0x31')]({'where':_0x18fa73[_0x66bd('0x4f')]})[_0x66bd('0x1f')](function(_0x41c9bc){_0x4a7ff4[_0x66bd('0x31')]=_0x41c9bc;if(_0x2b3a6d['query']['includeAll']){_0x18fa73[_0x66bd('0x52')]=[{'all':!![]}];}return db[_0x66bd('0x69')]['findAll'](_0x18fa73);})[_0x66bd('0x1f')](function(_0x537cc2){_0x4a7ff4[_0x66bd('0x54')]=_0x537cc2;return _0x4a7ff4;});}})[_0x66bd('0x1f')](respondWithFilteredResult(_0x49d131,_0x18fa73))[_0x66bd('0x55')](handleError(_0x49d131,null));};exports[_0x66bd('0x6e')]=function(_0x3907cd,_0x3d240c,_0x253cbb){return db[_0x66bd('0x3f')][_0x66bd('0x62')]({'where':{'id':_0x3907cd['params']['id']}})[_0x66bd('0x1f')](handleEntityNotFound(_0x3d240c,null))['then'](function(_0x1d8a8d){if(_0x1d8a8d){return _0x1d8a8d[_0x66bd('0x6e')](_0x3907cd['query'][_0x66bd('0x6f')]);}})[_0x66bd('0x1f')](respondWithStatusCode(_0x3d240c,null))[_0x66bd('0x55')](handleError(_0x3d240c,null));};exports[_0x66bd('0x70')]=function(_0x473086,_0x571457,_0x243e72){if(_0x473086['body']['id']){delete _0x473086[_0x66bd('0x5b')]['id'];}return db[_0x66bd('0x3f')][_0x66bd('0x62')]({'where':{'id':_0x473086[_0x66bd('0x66')]['id']}})['then'](handleEntityNotFound(_0x571457,null))['then'](function(_0x2f66e0){if(_0x2f66e0){_0x473086[_0x66bd('0x5b')][_0x66bd('0x6c')]=_0x2f66e0['id'];return db[_0x66bd('0x71')]['create'](_0x473086[_0x66bd('0x5b')]);}})[_0x66bd('0x1f')](respondWithResult(_0x571457,null))[_0x66bd('0x55')](handleError(_0x571457,null));};exports['getAnswers']=function(_0x479a8e,_0xe20b1e,_0x152897){var _0x213bbc={'raw':![],'where':{}};var _0x1a67dc={};var _0x1d467c={'count':0x0,'rows':[]};return db['SmsAccount'][_0x66bd('0x6b')]({'where':{'id':_0x479a8e[_0x66bd('0x66')]['id']}})[_0x66bd('0x1f')](handleEntityNotFound(_0xe20b1e,null))[_0x66bd('0x1f')](function(_0x41f414){if(_0x41f414){_0x1a67dc[_0x66bd('0x43')]=_[_0x66bd('0x44')](db['CannedAnswer'][_0x66bd('0x58')]);_0x1a67dc[_0x66bd('0x45')]=_[_0x66bd('0x44')](_0x479a8e['query']);_0x1a67dc[_0x66bd('0x46')]=_[_0x66bd('0x47')](_0x1a67dc[_0x66bd('0x43')],_0x1a67dc['query']);_0x213bbc[_0x66bd('0x48')]=_[_0x66bd('0x47')](_0x1a67dc[_0x66bd('0x43')],qs[_0x66bd('0x49')](_0x479a8e[_0x66bd('0x45')][_0x66bd('0x49')]));_0x213bbc['attributes']=_0x213bbc[_0x66bd('0x48')][_0x66bd('0x59')]?_0x213bbc[_0x66bd('0x48')]:_0x1a67dc[_0x66bd('0x43')];if(!_0x479a8e['query'][_0x66bd('0x4a')](_0x66bd('0x4b'))){_0x213bbc[_0x66bd('0x30')]=qs['limit'](_0x479a8e[_0x66bd('0x45')][_0x66bd('0x30')]);_0x213bbc[_0x66bd('0x2e')]=qs[_0x66bd('0x2e')](_0x479a8e[_0x66bd('0x45')][_0x66bd('0x2e')]);}_0x213bbc['order']=qs[_0x66bd('0x4d')](_0x479a8e['query'][_0x66bd('0x4d')]);_0x213bbc[_0x66bd('0x4f')]=qs[_0x66bd('0x46')](_['pick'](_0x479a8e[_0x66bd('0x45')],_0x1a67dc[_0x66bd('0x46')]));_0x213bbc[_0x66bd('0x4f')][_0x66bd('0x6c')]=_0x41f414['id'];if(_0x479a8e[_0x66bd('0x45')][_0x66bd('0x51')]){_0x213bbc[_0x66bd('0x4f')]=_[_0x66bd('0x50')](_0x213bbc['where'],{'$or':_[_0x66bd('0x3e')](_0x213bbc[_0x66bd('0x48')],function(_0x2372d9){var _0x1095c8={};_0x1095c8[_0x2372d9]={'$like':'%'+_0x479a8e[_0x66bd('0x45')][_0x66bd('0x51')]+'%'};return _0x1095c8;})});}_0x213bbc=_[_0x66bd('0x50')]({},_0x213bbc,_0x479a8e[_0x66bd('0x6d')]);return db[_0x66bd('0x71')]['count']({'where':_0x213bbc['where']})[_0x66bd('0x1f')](function(_0x3a64d1){_0x1d467c[_0x66bd('0x31')]=_0x3a64d1;if(_0x479a8e['query']['includeAll']){_0x213bbc[_0x66bd('0x52')]=[{'all':!![]}];}return db['CannedAnswer']['findAll'](_0x213bbc);})[_0x66bd('0x1f')](function(_0x24e2ff){_0x1d467c['rows']=_0x24e2ff;return _0x1d467c;});}})[_0x66bd('0x1f')](respondWithFilteredResult(_0xe20b1e,_0x213bbc))[_0x66bd('0x55')](handleError(_0xe20b1e,null));};exports[_0x66bd('0x72')]=function(_0x13e000,_0x285015,_0x2a66e0){return db['SmsAccount'][_0x66bd('0x62')]({'where':{'id':_0x13e000['params']['id']}})[_0x66bd('0x1f')](handleEntityNotFound(_0x285015,null))[_0x66bd('0x1f')](function(_0x4b4c05){if(_0x4b4c05){return _0x4b4c05[_0x66bd('0x72')](_0x13e000['query'][_0x66bd('0x6f')]);}})[_0x66bd('0x1f')](respondWithStatusCode(_0x285015,null))[_0x66bd('0x55')](handleError(_0x285015,null));};exports[_0x66bd('0x73')]=function(_0x1a2894,_0x509d5e,_0x32d989){var _0x3b02f2={'channel':_0x66bd('0x74')};var _0x182054=[];var _0x4818fd=[];var _0x29bc16={};return db['SmsAccount'][_0x66bd('0x62')]({'where':{'id':_0x1a2894[_0x66bd('0x66')]['id']},'include':[{'model':db[_0x66bd('0x75')],'as':_0x66bd('0x76')}]})['then'](handleEntityNotFound(_0x509d5e,null))['then'](function(_0x3f4475){_0x3b02f2[_0x66bd('0x77')]=_0x3f4475;_0x3b02f2[_0x66bd('0x78')]=_[_0x66bd('0x79')](_0x3f4475[_0x66bd('0x76')],[_0x66bd('0x7a')],['asc']);if(_0x3b02f2[_0x66bd('0x77')][_0x66bd('0x76')]){delete _0x3b02f2[_0x66bd('0x77')][_0x66bd('0x76')];}return db['CmContact'][_0x66bd('0x67')]();})[_0x66bd('0x1f')](function(_0x983900){if(!_0x983900){throw new db[(_0x66bd('0x7b'))][(_0x66bd('0x7c'))](_0x66bd('0x7d'));}_0x182054=_[_0x66bd('0x7e')](_[_0x66bd('0x44')](_0x983900),[_0x66bd('0x7f'),_0x66bd('0x80')]);_0x4818fd=_[_0x66bd('0x7e')](_['keys'](_0x983900),[_0x66bd('0x7f'),_0x66bd('0x80'),'CompanyId','ListId']);_0x3b02f2[_0x66bd('0x5b')]={'mapKey':_0x66bd('0x81')};if(_0x3b02f2[_0x66bd('0x77')][_0x66bd('0x41')]){switch(_0x3b02f2[_0x66bd('0x77')][_0x66bd('0x41')]){case'twilio':_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x82')]=_0x1a2894[_0x66bd('0x5b')][_0x66bd('0x83')];_0x3b02f2['body'][_0x66bd('0x5b')]=_0x1a2894[_0x66bd('0x5b')][_0x66bd('0x84')];_0x3b02f2[_0x66bd('0x5b')]['messageId']=_0x1a2894[_0x66bd('0x5b')]['MessageSid'];break;case _0x66bd('0x85'):_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x82')]='+'+_0x1a2894[_0x66bd('0x5b')]['sender'];_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x5b')]=_0x1a2894[_0x66bd('0x5b')][_0x66bd('0x86')];break;case _0x66bd('0x87'):_0x3b02f2[_0x66bd('0x5b')]['from']=_0x1a2894[_0x66bd('0x5b')][_0x66bd('0x82')];_0x3b02f2['body'][_0x66bd('0x5b')]=_0x1a2894[_0x66bd('0x5b')]['message'];break;case'clicksend':_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x82')]=_0x1a2894[_0x66bd('0x5b')]['from'];_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x5b')]=_0x1a2894[_0x66bd('0x5b')][_0x66bd('0x5b')];_0x3b02f2['body'][_0x66bd('0x88')]=_0x1a2894[_0x66bd('0x5b')][_0x66bd('0x89')];break;case _0x66bd('0x8a'):_0x3b02f2[_0x66bd('0x5b')]['from']=_0x1a2894[_0x66bd('0x5b')][_0x66bd('0x83')];_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x5b')]=_0x1a2894[_0x66bd('0x5b')]['Text'];_0x3b02f2[_0x66bd('0x5b')]['messageId']=_0x1a2894['body'][_0x66bd('0x8b')];break;case _0x66bd('0x8c'):_0x3b02f2[_0x66bd('0x5b')]['from']='+'+_0x1a2894[_0x66bd('0x5b')][_0x66bd('0x8d')][0x0][_0x66bd('0x82')];_0x3b02f2[_0x66bd('0x5b')]['body']=_0x1a2894[_0x66bd('0x5b')][_0x66bd('0x8d')][0x0]['text'];_0x3b02f2['body'][_0x66bd('0x88')]=_0x1a2894[_0x66bd('0x5b')][_0x66bd('0x8d')][0x0][_0x66bd('0x88')];break;case _0x66bd('0x8e'):_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x82')]=_0x1a2894[_0x66bd('0x5b')][_0x66bd('0x8f')];_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x5b')]=_0x1a2894[_0x66bd('0x5b')]['segmentedMessage'][_0x66bd('0x28')];break;case'clickatell':_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x82')]=_0x1a2894['body'][_0x66bd('0x90')];_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x5b')]=_0x1a2894[_0x66bd('0x5b')][_0x66bd('0x86')];_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x88')]=_0x1a2894[_0x66bd('0x5b')][_0x66bd('0x91')];break;case _0x66bd('0x92'):_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x88')]=_0x1a2894[_0x66bd('0x5b')][0x0]['message']['id'];_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x82')]=_0x1a2894[_0x66bd('0x5b')][0x0][_0x66bd('0x28')][_0x66bd('0x82')];_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x5b')]=_0x1a2894[_0x66bd('0x5b')][0x0][_0x66bd('0x28')]['text'];break;case _0x66bd('0x93'):_0x3b02f2['body']['from']=_0x1a2894['body']['from'];_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x5b')]=_0x1a2894[_0x66bd('0x5b')]['message'];_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x88')]=_0x1a2894[_0x66bd('0x5b')][_0x66bd('0x94')];break;}}if(_0x3b02f2['body']['id']){delete _0x3b02f2['body']['id'];}if(_[_0x66bd('0x95')](_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x82')])){throw new db[(_0x66bd('0x7b'))][(_0x66bd('0x7c'))](_0x66bd('0x96'));}if(_['isNil'](_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x5b')])||_0x3b02f2['body'][_0x66bd('0x5b')]===''){throw new db['Sequelize'][(_0x66bd('0x7c'))](_0x66bd('0x97'));}if(_[_0x66bd('0x95')](_0x3b02f2[_0x66bd('0x5b')]['mapKey'])){throw new db[(_0x66bd('0x7b'))]['ValidationError']('mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x4818fd);}if(!_[_0x66bd('0x98')](_0x4818fd,_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x99')])){throw new db[(_0x66bd('0x7b'))]['ValidationError'](_0x66bd('0x9a')+_0x4818fd);}_0x29bc16[_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x99')]]=_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x82')];return db[_0x66bd('0x9b')]['find']({'where':{'id':_0x3b02f2[_0x66bd('0x77')][_0x66bd('0x9c')]},'include':[{'model':db[_0x66bd('0x9d')],'as':_0x66bd('0x9e'),'where':_0x29bc16,'limit':0x1,'order':[[_0x66bd('0x80'),'DESC']]}]});})[_0x66bd('0x1f')](handleEntityNotFound(_0x509d5e,null))['then'](function(_0x5bb1d2){if(_0x5bb1d2){_0x3b02f2['list']=_['omit'](_0x5bb1d2,['Contacts']);if(_0x5bb1d2['Contacts']['length']){return _0x5bb1d2[_0x66bd('0x9e')][0x0];}var _0x24a129=_['defaults'](_0x3b02f2['body'],{'firstName':_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x82')],'ListId':_0x5bb1d2['id']});_0x24a129[_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x99')]]=_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x82')];return db[_0x66bd('0x9d')][_0x66bd('0x5a')](_0x24a129,{'fields':_0x182054,'raw':!![]});}})[_0x66bd('0x1f')](handleEntityNotFound(_0x509d5e,null))[_0x66bd('0x1f')](function(_0x1decfb){if(_0x1decfb){_0x3b02f2[_0x66bd('0x9f')]=_0x1decfb;var _0x27d5af={'ContactId':_0x1decfb['id'],'phone':_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x82')],'SmsAccountId':_0x1a2894['params']['id']};var _0x2ca589={'ContactId':_0x1decfb['id'],'SmsAccountId':_0x1a2894[_0x66bd('0x66')]['id'],'closed':![]};return db[_0x66bd('0xa0')][_0x66bd('0x62')]({'where':_0x2ca589})[_0x66bd('0x1f')](function(_0x41b882){if(_0x41b882){return[_0x41b882,![]];}return db['SmsInteraction']['create'](_0x27d5af)[_0x66bd('0x1f')](function(_0x2b5a67){return[_0x2b5a67,!![]];});});}})[_0x66bd('0xa1')](function(_0x4d0061,_0x17a9b3){_0x3b02f2[_0x66bd('0xa2')]=_0x4d0061[_0x66bd('0x5d')]({'plain':!![]});_0x3b02f2[_0x66bd('0xa2')][_0x66bd('0xa3')]=![];if(_0x17a9b3){if(_0x3b02f2['account'][_0x66bd('0xa4')]){_0x3b02f2[_0x66bd('0x78')][_0x66bd('0xa5')]({'id':0x0,'priority':_0x3b02f2[_0x66bd('0x78')][_0x66bd('0x59')]+0x1,'app':_0x66bd('0xa6'),'appdata':_0x66bd('0xa7'),'interval':_0x66bd('0xa8')});}_0x3b02f2[_0x66bd('0xa2')][_0x66bd('0xa3')]=!![];}return db[_0x66bd('0xa9')][_0x66bd('0x5a')]({'phone':_0x3b02f2['body'][_0x66bd('0x82')],'messageId':_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x88')],'body':_0x3b02f2[_0x66bd('0x5b')][_0x66bd('0x5b')],'SmsAccountId':_0x1a2894[_0x66bd('0x66')]['id'],'SmsInteractionId':_0x4d0061['id'],'direction':'in','ContactId':_0x4d0061[_0x66bd('0xaa')],'AttachmentId':_0x3b02f2['body'][_0x66bd('0xab')]});})['then'](function(_0x1db80a){_0x3b02f2[_0x66bd('0x28')]=_0x1db80a;if(_0x3b02f2[_0x66bd('0xa2')][_0x66bd('0xac')]){return db[_0x66bd('0xad')][_0x66bd('0x62')]({'attributes':['id',_0x66bd('0x3b')],'where':{'id':_0x3b02f2[_0x66bd('0xa2')][_0x66bd('0xac')]}})[_0x66bd('0x1f')](function(_0x4d0fd5){if(_0x4d0fd5){_0x3b02f2['applications']['unshift']({'id':0x0,'priority':0x0,'app':_0x66bd('0xae'),'appdata':_0x4d0fd5[_0x66bd('0x3b')]+','+(_0x3b02f2[_0x66bd('0x77')]['waitForTheAssignedAgent']||0xa),'interval':_0x66bd('0xa8')});}return respondWithRpcPromise('Start',_0x66bd('0xaf'),_0x3b02f2);});}return respondWithRpcPromise(_0x66bd('0xb0'),_0x66bd('0xaf'),_0x3b02f2);})[_0x66bd('0x1f')](function(_0x113f62){if(_0x113f62){var _0x1233a4=0xc8;var _0x39dcfe=_0x66bd('0xb1');logger[_0x66bd('0x20')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x39dcfe,_0x1233a4,_0x66bd('0xb2'));logger[_0x66bd('0x22')](_0x66bd('0xb3'),_0x39dcfe,_0x1233a4,_0x66bd('0xb2'),JSON[_0x66bd('0x24')](_0x113f62));if(_0x3b02f2[_0x66bd('0x77')][_0x66bd('0x41')]==='twilio'){return _0x509d5e[_0x66bd('0x2b')](_0x1233a4)['set'](_0x66bd('0xb4'),_0x66bd('0xb5'))[_0x66bd('0x3c')](_0x66bd('0xb6'));}else{return _0x509d5e[_0x66bd('0x2b')](_0x1233a4)['json'](_0x113f62);}}})[_0x66bd('0x55')](handleError(_0x509d5e,null));};exports[_0x66bd('0xb7')]=function(_0x2ac93d,_0x2b1552,_0x2503b6){return db['SmsAccount'][_0x66bd('0x6b')]({'where':{'id':_0x2ac93d[_0x66bd('0x66')]['id']}})['then'](handleEntityNotFound(_0x2b1552,null))['then'](function(_0x5e0ecf){if(_0x5e0ecf){return db[_0x66bd('0xb8')][_0x66bd('0xb9')](function(_0x47b95c){return db[_0x66bd('0x75')][_0x66bd('0x38')]({'where':{'SmsAccountId':_0x2ac93d['params']['id']},'transaction':_0x47b95c})[_0x66bd('0x1f')](function(_0x3b87c0){var _0x200da8=_[_0x66bd('0x3e')](_0x2ac93d['body'],function(_0x28f933){_0x28f933['SmsAccountId']=_0x2ac93d[_0x66bd('0x66')]['id'];return _0x28f933;});return db[_0x66bd('0x75')]['bulkCreate'](_0x200da8,{'transaction':_0x47b95c});});})['then'](function(){return db[_0x66bd('0x75')][_0x66bd('0xba')]({'where':{'SmsAccountId':_0x2ac93d['params']['id']},'order':_0x66bd('0x7a')});});}})['then'](respondWithResult(_0x2b1552,null))[_0x66bd('0x55')](handleError(_0x2b1552,null));};exports[_0x66bd('0xbb')]=function(_0x28e593,_0xadc1b4,_0x49ff48){var _0x382808={};var _0x16ef6a={};var _0x8d1086;var _0x49f000;return db[_0x66bd('0x3f')]['findOne']({'where':{'id':_0x28e593['params']['id']}})[_0x66bd('0x1f')](handleEntityNotFound(_0xadc1b4,null))[_0x66bd('0x1f')](function(_0x25e03d){if(_0x25e03d){_0x8d1086=_0x25e03d;_0x16ef6a['model']=_[_0x66bd('0x44')](db[_0x66bd('0x75')][_0x66bd('0x58')]);_0x16ef6a[_0x66bd('0x45')]=_[_0x66bd('0x44')](_0x28e593['query']);_0x16ef6a[_0x66bd('0x46')]=_['intersection'](_0x16ef6a[_0x66bd('0x43')],_0x16ef6a[_0x66bd('0x45')]);_0x382808[_0x66bd('0x48')]=_[_0x66bd('0x47')](_0x16ef6a['model'],qs[_0x66bd('0x49')](_0x28e593[_0x66bd('0x45')][_0x66bd('0x49')]));_0x382808[_0x66bd('0x48')]=_0x382808['attributes']['length']?_0x382808[_0x66bd('0x48')]:_0x16ef6a['model'];_0x382808[_0x66bd('0x4c')]=qs['sort'](_0x28e593[_0x66bd('0x45')][_0x66bd('0x4d')]);_0x382808[_0x66bd('0x4f')]=qs['filters'](_['pick'](_0x28e593['query'],_0x16ef6a[_0x66bd('0x46')]));if(_0x28e593[_0x66bd('0x45')][_0x66bd('0x51')]){_0x382808[_0x66bd('0x4f')]=_[_0x66bd('0x50')](_0x382808['where'],{'$or':_[_0x66bd('0x3e')](_0x382808['attributes'],function(_0x237488){var _0x6da74c={};_0x6da74c[_0x237488]={'$like':'%'+_0x28e593[_0x66bd('0x45')][_0x66bd('0x51')]+'%'};return _0x6da74c;})});}_0x382808=_[_0x66bd('0x50')]({},_0x382808,_0x28e593['options']);return _0x8d1086[_0x66bd('0xbb')](_0x382808);}})[_0x66bd('0x1f')](function(_0x2ae45a){if(_0x2ae45a){_0x49f000=_0x2ae45a[_0x66bd('0x59')];if(!_0x28e593[_0x66bd('0x45')][_0x66bd('0x4a')](_0x66bd('0x4b'))){_0x382808[_0x66bd('0x30')]=qs[_0x66bd('0x30')](_0x28e593[_0x66bd('0x45')][_0x66bd('0x30')]);_0x382808['offset']=qs[_0x66bd('0x2e')](_0x28e593[_0x66bd('0x45')][_0x66bd('0x2e')]);}return _0x8d1086['getApplications'](_0x382808);}})['then'](function(_0x2217b7){if(_0x2217b7){return _0x2217b7?{'count':_0x49f000,'rows':_0x2217b7}:null;}})[_0x66bd('0x1f')](respondWithResult(_0xadc1b4,null))['catch'](handleError(_0xadc1b4,null));};exports[_0x66bd('0xbc')]=function(_0x2feb25,_0x1e03cb,_0x5b9631){var _0x309050={'raw':![],'where':{}};var _0x12c3ba={};var _0x5a22ab={'count':0x0,'rows':[]};return db[_0x66bd('0x3f')][_0x66bd('0x6b')]({'where':{'id':_0x2feb25[_0x66bd('0x66')]['id']}})[_0x66bd('0x1f')](handleEntityNotFound(_0x1e03cb,null))[_0x66bd('0x1f')](function(_0x4d3914){if(_0x4d3914){_0x12c3ba[_0x66bd('0x43')]=_[_0x66bd('0x44')](db[_0x66bd('0xa0')]['rawAttributes']);_0x12c3ba[_0x66bd('0x45')]=_['keys'](_0x2feb25[_0x66bd('0x45')]);_0x12c3ba['filters']=_['intersection'](_0x12c3ba['model'],_0x12c3ba['query']);_0x309050[_0x66bd('0x48')]=_[_0x66bd('0x47')](_0x12c3ba['model'],qs[_0x66bd('0x49')](_0x2feb25['query'][_0x66bd('0x49')]));_0x309050['attributes']=_0x309050[_0x66bd('0x48')][_0x66bd('0x59')]?_0x309050[_0x66bd('0x48')]:_0x12c3ba[_0x66bd('0x43')];if(!_0x2feb25['query']['hasOwnProperty'](_0x66bd('0x4b'))){_0x309050[_0x66bd('0x30')]=qs[_0x66bd('0x30')](_0x2feb25['query'][_0x66bd('0x30')]);_0x309050['offset']=qs[_0x66bd('0x2e')](_0x2feb25[_0x66bd('0x45')][_0x66bd('0x2e')]);}_0x309050[_0x66bd('0x4c')]=qs[_0x66bd('0x4d')](_0x2feb25[_0x66bd('0x45')][_0x66bd('0x4d')]);_0x309050[_0x66bd('0x4f')]=qs[_0x66bd('0x46')](_[_0x66bd('0x4e')](_0x2feb25[_0x66bd('0x45')],_0x12c3ba[_0x66bd('0x46')]));_0x309050[_0x66bd('0x4f')][_0x66bd('0x6c')]=_0x4d3914['id'];if(_0x2feb25[_0x66bd('0x45')][_0x66bd('0x51')]){_0x309050[_0x66bd('0x4f')]=_[_0x66bd('0x50')](_0x309050[_0x66bd('0x4f')],{'$or':_['map'](_0x309050[_0x66bd('0x48')],function(_0x333d83){var _0x3467ee={};_0x3467ee[_0x333d83]={'$like':'%'+_0x2feb25['query'][_0x66bd('0x51')]+'%'};return _0x3467ee;})});}_0x309050=_[_0x66bd('0x50')]({},_0x309050,_0x2feb25[_0x66bd('0x6d')]);return db['SmsInteraction'][_0x66bd('0x31')]({'where':_0x309050[_0x66bd('0x4f')]})[_0x66bd('0x1f')](function(_0x9bc3b6){_0x5a22ab[_0x66bd('0x31')]=_0x9bc3b6;if(_0x2feb25[_0x66bd('0x45')][_0x66bd('0xbd')]){_0x309050[_0x66bd('0x52')]=[{'model':db[_0x66bd('0x9d')],'as':_0x66bd('0xbe'),'required':![]},{'model':db[_0x66bd('0xad')],'as':_0x66bd('0xbf'),'attributes':[_0x66bd('0x3b'),'fullname',_0x66bd('0xc0')],'required':![]},{'model':db[_0x66bd('0xc1')],'as':'Tags','attributes':['id',_0x66bd('0x3b'),_0x66bd('0xc2')],'where':_0x2feb25['query'][_0x66bd('0xc3')]?{'id':_0x2feb25[_0x66bd('0x45')][_0x66bd('0xc3')]}:undefined,'required':_0x2feb25['query'][_0x66bd('0xc3')]?!![]:![]}];}return db['SmsInteraction'][_0x66bd('0x53')](_0x309050);})[_0x66bd('0x1f')](function(_0x1e988c){_0x5a22ab[_0x66bd('0x54')]=_0x1e988c;return _0x5a22ab;});}})[_0x66bd('0x1f')](respondWithFilteredResult(_0x1e03cb,_0x309050))['catch'](handleError(_0x1e03cb,null));};exports[_0x66bd('0x3c')]=function(_0x3cc19f,_0x58d867,_0xb431a){var _0xd1b890,_0x11bdd2,_0x42c297;if(_[_0x66bd('0x95')](_0x3cc19f['body'][_0x66bd('0x5b')])||_0x3cc19f[_0x66bd('0x5b')][_0x66bd('0x5b')]===''){throw new db['Sequelize'][(_0x66bd('0x7c'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_['isNil'](_0x3cc19f[_0x66bd('0x5b')]['to'])){throw new db[(_0x66bd('0x7b'))][(_0x66bd('0x7c'))]('to\x20is\x20mandatory');}_0xd1b890=_0x3cc19f[_0x66bd('0x5b')]['to'];return db[_0x66bd('0x3f')][_0x66bd('0x62')]({'where':{'id':_0x3cc19f[_0x66bd('0x66')]['id']},'include':[{'model':db[_0x66bd('0x9b')],'as':'List','include':[{'model':db['CmContact'],'as':_0x66bd('0x9e'),'where':{'mobile':_0xd1b890},'limit':0x1,'order':[['updatedAt',_0x66bd('0xc4')]]}]}]})[_0x66bd('0x1f')](handleEntityNotFound(_0x58d867,null))[_0x66bd('0x1f')](function(_0x218461){if(_0x218461&&_0x218461[_0x66bd('0xc5')]){_0x11bdd2=_0x218461['get']({'plain':!![]});if(_0x11bdd2[_0x66bd('0xc5')]&&_0x11bdd2[_0x66bd('0xc5')][_0x66bd('0x9e')]['length']){return _0x11bdd2[_0x66bd('0xc5')][_0x66bd('0x9e')][0x0];}return db['CmContact'][_0x66bd('0x5a')](_[_0x66bd('0xc6')](_0x3cc19f[_0x66bd('0x5b')],{'firstName':_0xd1b890,'mobile':_0xd1b890,'phone':_0xd1b890,'ListId':_0x11bdd2[_0x66bd('0x9c')]}));}})['then'](handleEntityNotFound(_0x58d867,null))[_0x66bd('0x1f')](function(_0xafda4c){if(_0xafda4c){_0x42c297=_0xafda4c;return db[_0x66bd('0xa0')][_0x66bd('0x62')]({'where':{'ContactId':_0x42c297['id'],'closed':![],'SmsAccountId':_0x11bdd2['id']}})[_0x66bd('0x1f')](function(_0x331a82){if(_0x331a82){return[_0x331a82,![]];}return db[_0x66bd('0xa0')][_0x66bd('0x5a')]({'UserId':_0x3cc19f[_0x66bd('0x5c')]['id'],'ContactId':_0x42c297['id'],'SmsAccountId':_0x11bdd2['id'],'phone':_0xd1b890,'firstMsgDirection':'out','Messages':[_[_0x66bd('0x50')](_0x3cc19f[_0x66bd('0x5b')],{'read':![],'body':_0x3cc19f[_0x66bd('0x5b')]['body'],'phone':_0xd1b890,'SmsAccountId':_0x11bdd2['id'],'UserId':_0x3cc19f['user']['id'],'ContactId':_0x42c297['id']})]},{'include':[{'model':db[_0x66bd('0xa9')],'as':'Messages'}]})[_0x66bd('0x1f')](function(_0x11be90){return[_0x11be90,!![]];});});}})[_0x66bd('0xa1')](function(_0x45fea7,_0xde6a1c){if(_0xde6a1c){return _0x45fea7;}return db[_0x66bd('0xa9')][_0x66bd('0x5a')](_[_0x66bd('0x50')](_0x3cc19f[_0x66bd('0x5b')],{'read':![],'body':_0x3cc19f['body']['body'],'phone':_0xd1b890,'SmsAccountId':_0x11bdd2['id'],'SmsInteractionId':_0x45fea7['id'],'UserId':_0x3cc19f[_0x66bd('0x5c')]['id'],'ContactId':_0x42c297['id']}))[_0x66bd('0x1f')](function(_0x5c5e1e){_0x45fea7[_0x66bd('0xc7')][_0x66bd('0xc8')]=[];_0x45fea7[_0x66bd('0xc7')][_0x66bd('0xc8')][_0x66bd('0xa5')](_0x5c5e1e[_0x66bd('0xc7')]);return _0x45fea7;});})[_0x66bd('0x1f')](respondWithResult(_0x58d867,null))[_0x66bd('0x55')](handleError(_0x58d867,null));};exports[_0x66bd('0x2b')]=function(_0x56ec3d,_0x2e95b0,_0x45cf34){if(_0x56ec3d[_0x66bd('0x5b')]['id']){delete _0x56ec3d[_0x66bd('0x5b')]['id'];}var _0x567a2f,_0x5bf30f,_0x1ceea0;return db['SmsAccount'][_0x66bd('0x62')]({'where':{'id':_0x56ec3d['params']['id']}})['then'](handleEntityNotFound(_0x2e95b0,null))[_0x66bd('0x1f')](function(_0x47901e){if(_0x47901e){_0x1ceea0=_0x47901e;logger[_0x66bd('0x22')](_0x66bd('0x23'),_0x66bd('0x2b'),_0x66bd('0xc9'),_0x47901e[_0x66bd('0x41')],util[_0x66bd('0xca')](_0x56ec3d[_0x66bd('0x5b')],{'showHidden':![],'depth':null}));switch(_0x47901e[_0x66bd('0x41')]){case'skebby':if(_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0xcb')]&&_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0x2b')]){_0x5bf30f=_0x56ec3d[_0x66bd('0x5b')]['status'];return db[_0x66bd('0xa9')][_0x66bd('0x62')]({'where':{'messageId':_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0xcb')]}});}break;case'connectel':if(_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0xcc')]&&_0x56ec3d['body'][_0x66bd('0xcd')]){_0x5bf30f=_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0xcd')];return db[_0x66bd('0xa9')][_0x66bd('0x62')]({'where':{'messageId':_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0xcc')]}});}break;case'clicksend':if(_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0x89')]&&_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0xce')]){_0x5bf30f=_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0xce')];return db[_0x66bd('0xa9')][_0x66bd('0x62')]({'where':{'messageId':_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0x89')]}});}break;case _0x66bd('0x8c'):var _0xe62c9a=_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0x8d')][0x0];if(_0xe62c9a[_0x66bd('0x88')]&&_0xe62c9a[_0x66bd('0x2b')]['groupName']===_0x66bd('0xcf')){_0x5bf30f=_0xe62c9a['status'][_0x66bd('0xd0')];return db[_0x66bd('0xa9')]['find']({'where':{'messageId':_0xe62c9a['messageId']}});}break;case _0x66bd('0xd1'):if(_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0x88')]&&_0x56ec3d[_0x66bd('0x5b')]['status']){_0x5bf30f=_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0x2b')];return db[_0x66bd('0xa9')][_0x66bd('0x62')]({'where':{'messageId':_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0x88')]}});}break;case _0x66bd('0x92'):if(_0x56ec3d[_0x66bd('0x5b')][0x0][_0x66bd('0x28')]['id']){_0x5bf30f=_0x56ec3d['body'][0x0][_0x66bd('0x41')];return db[_0x66bd('0xa9')][_0x66bd('0x62')]({'where':{'messageId':_0x56ec3d['body'][0x0][_0x66bd('0x28')]['id']}});}break;case _0x66bd('0x93'):if(_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0xd2')]&&_0x56ec3d[_0x66bd('0x5b')]['status']){_0x5bf30f=_0x56ec3d['body'][_0x66bd('0x2b')];return db[_0x66bd('0xa9')][_0x66bd('0x62')]({'where':{'messageId':_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0xd2')]}});}break;}}})['then'](handleEntityNotFound(_0x2e95b0,null))[_0x66bd('0x1f')](function(_0x56a9dc){if(_0x56a9dc){_0x567a2f=_0x56a9dc;switch(_0x1ceea0[_0x66bd('0x41')]){case _0x66bd('0x85'):if(_0x5bf30f===_0x66bd('0xcf')){return _0x567a2f['update']({'read':!![]});}else{logger[_0x66bd('0x25')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x66bd('0x2b'),_0x66bd('0x85'),util['inspect'](_0x56ec3d[_0x66bd('0x5b')],{'showHidden':![],'depth':null}));}break;case _0x66bd('0x87'):if(_0x5bf30f==='1'){return _0x567a2f[_0x66bd('0x37')]({'read':!![]});}else{logger['error']('SmsAccount,\x20%s,\x20%s,\x20%s',_0x66bd('0x2b'),_0x66bd('0x85'),util[_0x66bd('0xca')](_0x56ec3d['body'],{'showHidden':![],'depth':null}));}break;case _0x66bd('0xd3'):if(!_0x56ec3d[_0x66bd('0x5b')]['error_code']&&_0x5bf30f>=0xc8&&_0x5bf30f<=0xce){return _0x567a2f[_0x66bd('0x37')]({'read':!![]});}else{logger[_0x66bd('0x25')]('SmsAccount,\x20%s,\x20%s,\x20%s','status',_0x66bd('0xd3'),util[_0x66bd('0xca')](_0x56ec3d[_0x66bd('0x5b')],{'showHidden':![],'depth':null}));}break;case _0x66bd('0x8c'):var _0x5b3880=_0x56ec3d[_0x66bd('0x5b')][_0x66bd('0x8d')][0x0];if(_0x5b3880[_0x66bd('0x2b')]['groupName']===_0x66bd('0xcf')){return _0x567a2f[_0x66bd('0x37')]({'read':!![]});}else{logger['error']('SmsAccount,\x20%s,\x20%s,\x20%s',_0x66bd('0x2b'),_0x66bd('0x8c'),util[_0x66bd('0xca')](_0x56ec3d[_0x66bd('0x5b')],{'showHidden':![],'depth':null}));}break;case _0x66bd('0xd1'):if(_0x5bf30f==_0x66bd('0xd4')||_0x5bf30f==_0x66bd('0xd5')){return _0x567a2f[_0x66bd('0x37')]({'read':!![]});}else{logger[_0x66bd('0x25')](_0x66bd('0x23'),_0x66bd('0x2b'),_0x66bd('0xd1'),util['inspect'](_0x56ec3d['body'],{'showHidden':![],'depth':null}));}break;case'bandwidth':if(_0x5bf30f==_0x66bd('0xd6')){return _0x567a2f[_0x66bd('0x37')]({'read':!![]});}else{logger['error'](_0x66bd('0x23'),'status','bandwidth',util['inspect'](_0x56ec3d['body'],{'showHidden':![],'depth':null}));}break;case'intelepeer':if(_0x5bf30f===_0x66bd('0xd7')||_0x5bf30f===_0x66bd('0xd8')){return _0x567a2f[_0x66bd('0x37')]({'read':!![]});}else{logger[_0x66bd('0x25')](_0x66bd('0x23'),'status',_0x66bd('0x93'),util[_0x66bd('0xca')](_0x56ec3d[_0x66bd('0x5b')],{'showHidden':![],'depth':null}));}break;}return _0x567a2f;}})[_0x66bd('0x1f')](respondWithResult(_0x2e95b0,null))[_0x66bd('0x55')](handleError(_0x2e95b0,null));};exports[_0x66bd('0xd9')]=function(_0x2d8e34,_0x3bed58,_0x3b2fa0){var _0x378682,_0x384409,_0xfdae5a;return db[_0x66bd('0x3f')][_0x66bd('0x62')]({'where':{'id':_0x2d8e34[_0x66bd('0x66')]['id']}})['then'](handleEntityNotFound(_0x3bed58,null))[_0x66bd('0x1f')](function(_0x12a982){if(_0x12a982){_0xfdae5a=_0x12a982;logger['debug'](_0x66bd('0x23'),_0x66bd('0x2b'),_0x66bd('0xc9'),_0x12a982[_0x66bd('0x41')],util[_0x66bd('0xca')](_0x2d8e34[_0x66bd('0x45')],{'showHidden':![],'depth':null}));switch(_0x12a982['type']){case'csc':if(_0x2d8e34[_0x66bd('0x45')][_0x66bd('0xda')]&&_0x2d8e34['query'][_0x66bd('0xdb')]){_0x384409=_0x2d8e34['query'][_0x66bd('0xdb')];return db['SmsMessage'][_0x66bd('0x62')]({'where':{'messageId':_0x2d8e34[_0x66bd('0x45')][_0x66bd('0xda')]}});}break;}}})['then'](handleEntityNotFound(_0x3bed58,null))[_0x66bd('0x1f')](function(_0x2153a8){if(_0x2153a8){_0x378682=_0x2153a8;switch(_0xfdae5a[_0x66bd('0x41')]){case _0x66bd('0x8e'):if(_0x384409==='2'||_0x384409==='6'){return _0x378682[_0x66bd('0x37')]({'read':!![]});}else{logger['error'](_0x66bd('0x23'),_0x66bd('0x2b'),_0x66bd('0x8e'),util[_0x66bd('0xca')](_0x2d8e34[_0x66bd('0x45')],{'showHidden':![],'depth':null}));};break;}return _0x378682;}})[_0x66bd('0x1f')](respondWithResult(_0x3bed58,null))['catch'](handleError(_0x3bed58,null));};exports[_0x66bd('0xdc')]=function(_0x368971,_0x4514b9,_0x3a2f59){return db['SmsAccount'][_0x66bd('0x62')]({'where':{'id':_0x368971[_0x66bd('0x66')]['id']}})[_0x66bd('0x1f')](handleEntityNotFound(_0x4514b9,null))['then'](function(_0xae76b6){if(_0xae76b6){return _0xae76b6[_0x66bd('0xdc')](_0x368971[_0x66bd('0x5b')]['ids'],_[_0x66bd('0xdd')](_0x368971[_0x66bd('0x5b')],[_0x66bd('0x6f'),'id'])||{})[_0x66bd('0xa1')](function(_0x315fa2){for(var _0x45902a=0x0;_0x45902a<_0x368971[_0x66bd('0x5b')][_0x66bd('0x6f')][_0x66bd('0x59')];_0x45902a+=0x1){socket['emit'](_0x66bd('0xde'),{'UserId':_0x368971[_0x66bd('0x5b')][_0x66bd('0x6f')][_0x45902a],'SmsAccountId':_0x368971[_0x66bd('0x66')]['id']});}return _0x315fa2;});}})[_0x66bd('0x1f')](respondWithResult(_0x4514b9,null))[_0x66bd('0x55')](handleError(_0x4514b9,null));};exports['removeAgents']=function(_0x5dbd01,_0x390b9b,_0x49959e){return db[_0x66bd('0x3f')][_0x66bd('0x62')]({'where':{'id':_0x5dbd01['params']['id']}})[_0x66bd('0x1f')](handleEntityNotFound(_0x390b9b,null))[_0x66bd('0x1f')](function(_0x8a5623){if(_0x8a5623){return _0x8a5623[_0x66bd('0xdf')](_0x5dbd01[_0x66bd('0x45')]['ids'])[_0x66bd('0x1f')](function(){if(_['isArray'](_0x5dbd01['query'][_0x66bd('0x6f')])){for(var _0x1516da=0x0;_0x1516da<_0x5dbd01['query'][_0x66bd('0x6f')][_0x66bd('0x59')];_0x1516da+=0x1){socket[_0x66bd('0xe0')](_0x66bd('0xe1'),{'UserId':Number(_0x5dbd01['query'][_0x66bd('0x6f')][_0x1516da]),'SmsAccountId':Number(_0x5dbd01['params']['id'])});}}else{socket[_0x66bd('0xe0')]('userSmsAccount:remove',{'UserId':Number(_0x5dbd01['query']['ids']),'SmsAccountId':Number(_0x5dbd01[_0x66bd('0x66')]['id'])});}});}})[_0x66bd('0x1f')](respondWithStatusCode(_0x390b9b,null))[_0x66bd('0x55')](handleError(_0x390b9b,null));};exports[_0x66bd('0xe2')]=function(_0x3db265,_0x49bd6c,_0x9de193){var _0x46c4ae={};var _0x4a11d9={};var _0xd02b55;var _0x23448f;return db[_0x66bd('0x3f')][_0x66bd('0x6b')]({'where':{'id':_0x3db265['params']['id']}})[_0x66bd('0x1f')](handleEntityNotFound(_0x49bd6c,null))[_0x66bd('0x1f')](function(_0xc4ad71){if(_0xc4ad71){_0xd02b55=_0xc4ad71;_0x4a11d9[_0x66bd('0x43')]=_[_0x66bd('0x44')](db['User'][_0x66bd('0x58')]);_0x4a11d9[_0x66bd('0x45')]=_[_0x66bd('0x44')](_0x3db265['query']);_0x4a11d9[_0x66bd('0x46')]=_[_0x66bd('0x47')](_0x4a11d9[_0x66bd('0x43')],_0x4a11d9[_0x66bd('0x45')]);_0x46c4ae['attributes']=_[_0x66bd('0x47')](_0x4a11d9[_0x66bd('0x43')],qs[_0x66bd('0x49')](_0x3db265[_0x66bd('0x45')][_0x66bd('0x49')]));_0x46c4ae[_0x66bd('0x48')]=_0x46c4ae[_0x66bd('0x48')][_0x66bd('0x59')]?_0x46c4ae[_0x66bd('0x48')]:_0x4a11d9[_0x66bd('0x43')];_0x46c4ae[_0x66bd('0x4c')]=qs[_0x66bd('0x4d')](_0x3db265['query'][_0x66bd('0x4d')]);_0x46c4ae[_0x66bd('0x4f')]=qs[_0x66bd('0x46')](_[_0x66bd('0x4e')](_0x3db265['query'],_0x4a11d9[_0x66bd('0x46')]));if(_0x3db265['query'][_0x66bd('0x51')]){_0x46c4ae[_0x66bd('0x4f')]=_['merge'](_0x46c4ae[_0x66bd('0x4f')],{'$or':_[_0x66bd('0x3e')](_0x46c4ae[_0x66bd('0x48')],function(_0x5f4aa6){var _0x4ce74d={};_0x4ce74d[_0x5f4aa6]={'$like':'%'+_0x3db265['query'][_0x66bd('0x51')]+'%'};return _0x4ce74d;})});}_0x46c4ae=_[_0x66bd('0x50')]({},_0x46c4ae,_0x3db265[_0x66bd('0x6d')]);return _0xd02b55[_0x66bd('0xe2')](_0x46c4ae);}})[_0x66bd('0x1f')](function(_0x167e24){if(_0x167e24){_0x23448f=_0x167e24[_0x66bd('0x59')];if(!_0x3db265[_0x66bd('0x45')][_0x66bd('0x4a')](_0x66bd('0x4b'))){_0x46c4ae[_0x66bd('0x30')]=qs[_0x66bd('0x30')](_0x3db265['query'][_0x66bd('0x30')]);_0x46c4ae['offset']=qs[_0x66bd('0x2e')](_0x3db265['query'][_0x66bd('0x2e')]);}return _0xd02b55['getAgents'](_0x46c4ae);}})['then'](function(_0x275c14){if(_0x275c14){return _0x275c14?{'count':_0x23448f,'rows':_0x275c14}:null;}})['then'](respondWithResult(_0x49bd6c,null))[_0x66bd('0x55')](handleError(_0x49bd6c,null));};
\ No newline at end of file