Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / server / api / smsAccount / smsAccount.controller.js
index aac8fe2..49b005a 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xa78f=['getInteractions','Contact','Owner','internal','Tag','Tags','color','tag','send','List','user','Messages','dataValues','received\x20delivery\x20report\x20from','inspect','skebby_dispatch_id','connectel','requestid','message_id','status_code','groupName','clickatell','intelepeer','redif','DELIVERED','error_code','infobip','DELIVERED_TO_GATEWAY','RECEIVED_BY_RECIPIENT','message-delivered','DELIVRD','statusGet','message-id','state','addAgents','userSmsAccount:save','removeAgents','emit','userSmsAccount:remove','getAgents','hasOwnProperty','html-pdf','eml-format','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','to-csv','lodash','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','defaults','./smsAccount.socket','client','http','then','info','request\x20sent','SmsAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','SmsAccount,\x20%s,\x20%s','message','result','catch','sendStatus','status','end','json','count','offset','Content-Range','reject','save','SmsAccounts','UserProfileResource','stack','name','index','Pause','mandatoryDispositionPause','SmsAccount','rawAttributes','fieldName','key','model','map','query','keys','filters','intersection','attributes','fields','length','limit','sort','where','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','show','params','find','create','body','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','destroy','describe','addDisposition','SmsAccountId','findOne','nolimit','pick','Disposition','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','order','removeAnswers','sms','SmsApplication','Applications','applications','orderBy','asc','account','CmContact','ValidationError','difference','createdAt','updatedAt','CompanyId','mobile','type','from','From','MessageSid','skebby','sender','text','clicksend','messageId','plivo','results','csc','originatingAddress','segmentedMessage','fromNumber','replyMessageId','bandwidth','refid','isNil','Sequelize','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','ListId','Contacts','DESC','omit','SmsInteraction','spread','interaction','autoclose','push','unmanaged','*,*,*,*','created','SmsMessage','ContactId','AttachmentId','User','UserId','unshift','agent','waitForTheAssignedAgent','Start','startRouting','entity\x20found','debug','twilio','set','Content-Type','text/xml','addApplications','sequelize','transaction','bulkCreate','priority','getApplications'];(function(_0x3e7471,_0x40c833){var _0x5571cc=function(_0x2a2000){while(--_0x2a2000){_0x3e7471['push'](_0x3e7471['shift']());}};_0x5571cc(++_0x40c833);}(_0xa78f,0x10a));var _0xfa78=function(_0x261873,_0x2b134f){_0x261873=_0x261873-0x0;var _0x30b6d0=_0xa78f[_0x261873];return _0x30b6d0;};'use strict';var pdf=require(_0xfa78('0x0'));var emlformat=require(_0xfa78('0x1'));var rimraf=require('rimraf');var zipdir=require(_0xfa78('0x2'));var jsonpatch=require(_0xfa78('0x3'));var rp=require(_0xfa78('0x4'));var moment=require('moment');var BPromise=require(_0xfa78('0x5'));var Mustache=require(_0xfa78('0x6'));var util=require(_0xfa78('0x7'));var path=require(_0xfa78('0x8'));var sox=require(_0xfa78('0x9'));var csv=require(_0xfa78('0xa'));var ejs=require('ejs');var fs=require('fs');var _=require(_0xfa78('0xb'));var squel=require('squel');var crypto=require(_0xfa78('0xc'));var jsforce=require('jsforce');var deskjs=require(_0xfa78('0xd'));var toCsv=require(_0xfa78('0xa'));var querystring=require(_0xfa78('0xe'));var Papa=require(_0xfa78('0xf'));var Redis=require(_0xfa78('0x10'));var authService=require(_0xfa78('0x11'));var qs=require(_0xfa78('0x12'));var as=require(_0xfa78('0x13'));var hardwareService=require(_0xfa78('0x14'));var logger=require(_0xfa78('0x15'))(_0xfa78('0x16'));var utils=require(_0xfa78('0x17'));var config=require(_0xfa78('0x18'));var licenseUtil=require(_0xfa78('0x19'));var db=require(_0xfa78('0x1a'))['db'];config[_0xfa78('0x1b')]=_[_0xfa78('0x1c')](config[_0xfa78('0x1b')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xfa78('0x1b')]));require(_0xfa78('0x1d'))['register'](socket);var jayson=require('jayson/promise');var client=jayson[_0xfa78('0x1e')][_0xfa78('0x1f')]({'port':0x232c});function respondWithRpcPromise(_0x2ee810,_0x382f70,_0x3a0e68,_0x2a509f){return new BPromise(function(_0x2d1ef9,_0x5ca268){var _0x4dac88=_0x2a509f||client;return _0x4dac88['request'](_0x2ee810,_0x3a0e68)[_0xfa78('0x20')](function(_0x3225fe){logger[_0xfa78('0x21')]('SmsAccount,\x20%s,\x20%s',_0x382f70,_0xfa78('0x22'));logger['debug'](_0xfa78('0x23'),_0x382f70,_0xfa78('0x22'),JSON[_0xfa78('0x24')](_0x3225fe));if(_0x3225fe[_0xfa78('0x25')]){if(_0x3225fe[_0xfa78('0x25')][_0xfa78('0x26')]===0x1f4){logger['error'](_0xfa78('0x27'),_0x382f70,_0x3225fe['error']['message']);return _0x5ca268(_0x3225fe[_0xfa78('0x25')][_0xfa78('0x28')]);}logger[_0xfa78('0x25')](_0xfa78('0x27'),_0x382f70,_0x3225fe[_0xfa78('0x25')][_0xfa78('0x28')]);return _0x2d1ef9(_0x3225fe[_0xfa78('0x25')][_0xfa78('0x28')]);}else{logger['info'](_0xfa78('0x27'),_0x382f70,'request\x20sent');_0x2d1ef9(_0x3225fe[_0xfa78('0x29')]['message']);}})[_0xfa78('0x2a')](function(_0x348d98){logger[_0xfa78('0x25')](_0xfa78('0x27'),_0x382f70,_0x348d98);_0x5ca268(_0x348d98);});});}function respondWithStatusCode(_0xdd123,_0x30430c){_0x30430c=_0x30430c||0xcc;return function(_0x1df472){if(_0x1df472){return _0xdd123[_0xfa78('0x2b')](_0x30430c);}return _0xdd123[_0xfa78('0x2c')](_0x30430c)[_0xfa78('0x2d')]();};}function respondWithResult(_0x2fced8,_0x3baa13){_0x3baa13=_0x3baa13||0xc8;return function(_0x550421){if(_0x550421){return _0x2fced8['status'](_0x3baa13)[_0xfa78('0x2e')](_0x550421);}};}function respondWithFilteredResult(_0x1ec2fc,_0x3ffeb0){return function(_0x5bf41b){if(_0x5bf41b){var _0x7aae5a=_0x5bf41b[_0xfa78('0x2f')],_0x583764=_0x3ffeb0[_0xfa78('0x30')],_0x58ffc8=_0x3ffeb0['offset']+_0x3ffeb0['limit'],_0x51bb43;if(_0x58ffc8>=_0x7aae5a){_0x58ffc8=_0x7aae5a;_0x51bb43=0xc8;}else{_0x51bb43=0xce;}_0x1ec2fc[_0xfa78('0x2c')](_0x51bb43);return _0x1ec2fc['set'](_0xfa78('0x31'),_0x583764+'-'+_0x58ffc8+'/'+_0x7aae5a)['json'](_0x5bf41b);}return null;};}function patchUpdates(_0x175762){return function(_0x357ca4){try{jsonpatch['apply'](_0x357ca4,_0x175762,!![]);}catch(_0x1f14b3){return BPromise[_0xfa78('0x32')](_0x1f14b3);}return _0x357ca4[_0xfa78('0x33')]();};}function saveUpdates(_0x45402b,_0x54ea0e){return function(_0x4780a6){if(_0x4780a6){return _0x4780a6['update'](_0x45402b)['then'](function(_0x571132){return _0x571132;});}return null;};}function removeEntity(_0x371816,_0x1fce06){return function(_0x408f3f){if(_0x408f3f){return _0x408f3f['destroy']()['then'](function(){var _0x1fe931=_0x408f3f['get']({'plain':!![]});var _0x4bd753=_0xfa78('0x34');return db[_0xfa78('0x35')]['destroy']({'where':{'type':_0x4bd753,'resourceId':_0x1fe931['id']}})[_0xfa78('0x20')](function(){return _0x408f3f;});})[_0xfa78('0x20')](function(){_0x371816[_0xfa78('0x2c')](0xcc)[_0xfa78('0x2d')]();});}};}function handleEntityNotFound(_0x5467f8,_0xd0e138){return function(_0x58692f){if(!_0x58692f){_0x5467f8[_0xfa78('0x2b')](0x194);}return _0x58692f;};}function handleError(_0x55d116,_0xec14bd){_0xec14bd=_0xec14bd||0x1f4;return function(_0x10c3b6){logger[_0xfa78('0x25')](_0x10c3b6[_0xfa78('0x36')]);if(_0x10c3b6[_0xfa78('0x37')]){delete _0x10c3b6[_0xfa78('0x37')];}_0x55d116['status'](_0xec14bd)['send'](_0x10c3b6);};}exports[_0xfa78('0x38')]=function(_0x33364c,_0xcc6d4f){var _0x89f2a3={'include':[{'model':db[_0xfa78('0x39')],'as':_0xfa78('0x3a')}]},_0xa93553={},_0x59531a={'count':0x0,'rows':[]};var _0x28b773=_['map'](db[_0xfa78('0x3b')][_0xfa78('0x3c')],function(_0x4eeb71){return{'name':_0x4eeb71[_0xfa78('0x3d')],'type':_0x4eeb71['type'][_0xfa78('0x3e')]};});_0xa93553[_0xfa78('0x3f')]=_[_0xfa78('0x40')](_0x28b773,_0xfa78('0x37'));_0xa93553[_0xfa78('0x41')]=_[_0xfa78('0x42')](_0x33364c[_0xfa78('0x41')]);_0xa93553[_0xfa78('0x43')]=_[_0xfa78('0x44')](_0xa93553[_0xfa78('0x3f')],_0xa93553[_0xfa78('0x41')]);_0x89f2a3[_0xfa78('0x45')]=_[_0xfa78('0x44')](_0xa93553[_0xfa78('0x3f')],qs['fields'](_0x33364c[_0xfa78('0x41')][_0xfa78('0x46')]));_0x89f2a3['attributes']=_0x89f2a3['attributes'][_0xfa78('0x47')]?_0x89f2a3[_0xfa78('0x45')]:_0xa93553['model'];if(!_0x33364c[_0xfa78('0x41')]['hasOwnProperty']('nolimit')){_0x89f2a3[_0xfa78('0x48')]=qs[_0xfa78('0x48')](_0x33364c['query'][_0xfa78('0x48')]);_0x89f2a3['offset']=qs[_0xfa78('0x30')](_0x33364c[_0xfa78('0x41')][_0xfa78('0x30')]);}_0x89f2a3['order']=qs[_0xfa78('0x49')](_0x33364c[_0xfa78('0x41')][_0xfa78('0x49')]);_0x89f2a3[_0xfa78('0x4a')]=qs[_0xfa78('0x43')](_['pick'](_0x33364c['query'],_0xa93553[_0xfa78('0x43')]),_0x28b773);if(_0x33364c[_0xfa78('0x41')][_0xfa78('0x4b')]){_0x89f2a3[_0xfa78('0x4a')]=_[_0xfa78('0x4c')](_0x89f2a3['where'],{'$or':_[_0xfa78('0x40')](_0x28b773,function(_0x184f1b){if(_0x184f1b['type']!==_0xfa78('0x4d')){var _0x261113={};_0x261113[_0x184f1b[_0xfa78('0x37')]]={'$like':'%'+_0x33364c[_0xfa78('0x41')][_0xfa78('0x4b')]+'%'};return _0x261113;}})});}_0x89f2a3=_[_0xfa78('0x4c')]({},_0x89f2a3,_0x33364c[_0xfa78('0x4e')]);var _0x4cdb14={'where':_0x89f2a3[_0xfa78('0x4a')]};return db[_0xfa78('0x3b')]['count'](_0x4cdb14)['then'](function(_0x54ba15){_0x59531a[_0xfa78('0x2f')]=_0x54ba15;if(_0x33364c['query'][_0xfa78('0x4f')]){_0x89f2a3[_0xfa78('0x50')]=[{'all':!![]}];}return db[_0xfa78('0x3b')][_0xfa78('0x51')](_0x89f2a3);})[_0xfa78('0x20')](function(_0x2dcb38){_0x59531a[_0xfa78('0x52')]=_0x2dcb38;return _0x59531a;})[_0xfa78('0x20')](respondWithFilteredResult(_0xcc6d4f,_0x89f2a3))[_0xfa78('0x2a')](handleError(_0xcc6d4f,null));};exports[_0xfa78('0x53')]=function(_0x17dafd,_0x4bfba6){var _0x28eb04={'raw':![],'where':{'id':_0x17dafd[_0xfa78('0x54')]['id']},'include':[{'model':db['Pause'],'as':_0xfa78('0x3a')}]},_0x4fc2a6={};_0x4fc2a6[_0xfa78('0x3f')]=_['keys'](db['SmsAccount'][_0xfa78('0x3c')]);_0x4fc2a6[_0xfa78('0x41')]=_['keys'](_0x17dafd[_0xfa78('0x41')]);_0x4fc2a6['filters']=_['intersection'](_0x4fc2a6[_0xfa78('0x3f')],_0x4fc2a6[_0xfa78('0x41')]);_0x28eb04['attributes']=_[_0xfa78('0x44')](_0x4fc2a6[_0xfa78('0x3f')],qs[_0xfa78('0x46')](_0x17dafd[_0xfa78('0x41')][_0xfa78('0x46')]));_0x28eb04[_0xfa78('0x45')]=_0x28eb04[_0xfa78('0x45')][_0xfa78('0x47')]?_0x28eb04[_0xfa78('0x45')]:_0x4fc2a6[_0xfa78('0x3f')];if(_0x17dafd['query'][_0xfa78('0x4f')]){_0x28eb04['include']=[{'all':!![]}];}_0x28eb04=_[_0xfa78('0x4c')]({},_0x28eb04,_0x17dafd['options']);return db[_0xfa78('0x3b')][_0xfa78('0x55')](_0x28eb04)[_0xfa78('0x20')](handleEntityNotFound(_0x4bfba6,null))[_0xfa78('0x20')](respondWithResult(_0x4bfba6,null))[_0xfa78('0x2a')](handleError(_0x4bfba6,null));};exports['create']=function(_0x3f5ebb,_0x213195){return db[_0xfa78('0x3b')][_0xfa78('0x56')](_0x3f5ebb[_0xfa78('0x57')],{})[_0xfa78('0x20')](function(_0x36a658){var _0x2ae654=_0x3f5ebb['user'][_0xfa78('0x58')]({'plain':!![]});if(!_0x2ae654)throw new Error(_0xfa78('0x59'));if(_0x2ae654[_0xfa78('0x5a')]==='user'){var _0x18ef95=_0x36a658[_0xfa78('0x58')]({'plain':!![]});var _0x56a510=_0xfa78('0x34');return db[_0xfa78('0x5b')]['find']({'where':{'name':_0x56a510,'userProfileId':_0x2ae654[_0xfa78('0x5c')]},'raw':!![]})[_0xfa78('0x20')](function(_0x68d9ff){if(_0x68d9ff&&_0x68d9ff[_0xfa78('0x5d')]===0x0){return db[_0xfa78('0x35')][_0xfa78('0x56')]({'name':_0x18ef95['name'],'resourceId':_0x18ef95['id'],'type':_0x68d9ff['name'],'sectionId':_0x68d9ff['id']},{})['then'](function(){return _0x36a658;});}else{return _0x36a658;}})[_0xfa78('0x2a')](function(_0x4fa378){logger[_0xfa78('0x25')](_0xfa78('0x5e'),_0x4fa378);throw _0x4fa378;});}return _0x36a658;})[_0xfa78('0x20')](respondWithResult(_0x213195,0xc9))[_0xfa78('0x2a')](handleError(_0x213195,null));};exports[_0xfa78('0x5f')]=function(_0x1c0114,_0x7061bd){if(_0x1c0114[_0xfa78('0x57')]['id']){delete _0x1c0114[_0xfa78('0x57')]['id'];}return db['SmsAccount'][_0xfa78('0x55')]({'where':{'id':_0x1c0114[_0xfa78('0x54')]['id']},'include':[{'model':db[_0xfa78('0x39')],'as':_0xfa78('0x3a')}]})['then'](handleEntityNotFound(_0x7061bd,null))[_0xfa78('0x20')](saveUpdates(_0x1c0114['body'],null))[_0xfa78('0x20')](respondWithResult(_0x7061bd,null))[_0xfa78('0x2a')](handleError(_0x7061bd,null));};exports[_0xfa78('0x60')]=function(_0x38f2ba,_0x1d4359){return db[_0xfa78('0x3b')][_0xfa78('0x55')]({'where':{'id':_0x38f2ba['params']['id']}})[_0xfa78('0x20')](handleEntityNotFound(_0x1d4359,null))[_0xfa78('0x20')](removeEntity(_0x1d4359,null))[_0xfa78('0x2a')](handleError(_0x1d4359,null));};exports['describe']=function(_0x57c5c2,_0x2956a5){return db[_0xfa78('0x3b')][_0xfa78('0x61')]()[_0xfa78('0x20')](respondWithResult(_0x2956a5,null))[_0xfa78('0x2a')](handleError(_0x2956a5,null));};exports[_0xfa78('0x62')]=function(_0x39da17,_0x22fe24,_0xe942c8){if(_0x39da17['body']['id']){delete _0x39da17[_0xfa78('0x57')]['id'];}return db[_0xfa78('0x3b')]['find']({'where':{'id':_0x39da17[_0xfa78('0x54')]['id']}})[_0xfa78('0x20')](handleEntityNotFound(_0x22fe24,null))[_0xfa78('0x20')](function(_0x297f9a){if(_0x297f9a){_0x39da17[_0xfa78('0x57')][_0xfa78('0x63')]=_0x297f9a['id'];return db['Disposition'][_0xfa78('0x56')](_0x39da17[_0xfa78('0x57')]);}})[_0xfa78('0x20')](respondWithResult(_0x22fe24,null))[_0xfa78('0x2a')](handleError(_0x22fe24,null));};exports['getDispositions']=function(_0x52c405,_0x12729b,_0x1f0673){var _0x4b9d7d={'raw':![],'where':{}};var _0x537976={};var _0x37a24a={'count':0x0,'rows':[]};return db[_0xfa78('0x3b')][_0xfa78('0x64')]({'where':{'id':_0x52c405[_0xfa78('0x54')]['id']}})[_0xfa78('0x20')](handleEntityNotFound(_0x12729b,null))[_0xfa78('0x20')](function(_0x1a2e8e){if(_0x1a2e8e){_0x537976[_0xfa78('0x3f')]=_[_0xfa78('0x42')](db['Disposition'][_0xfa78('0x3c')]);_0x537976[_0xfa78('0x41')]=_['keys'](_0x52c405[_0xfa78('0x41')]);_0x537976[_0xfa78('0x43')]=_[_0xfa78('0x44')](_0x537976[_0xfa78('0x3f')],_0x537976['query']);_0x4b9d7d[_0xfa78('0x45')]=_[_0xfa78('0x44')](_0x537976[_0xfa78('0x3f')],qs[_0xfa78('0x46')](_0x52c405[_0xfa78('0x41')][_0xfa78('0x46')]));_0x4b9d7d[_0xfa78('0x45')]=_0x4b9d7d['attributes'][_0xfa78('0x47')]?_0x4b9d7d[_0xfa78('0x45')]:_0x537976['model'];if(!_0x52c405[_0xfa78('0x41')]['hasOwnProperty'](_0xfa78('0x65'))){_0x4b9d7d[_0xfa78('0x48')]=qs['limit'](_0x52c405[_0xfa78('0x41')][_0xfa78('0x48')]);_0x4b9d7d[_0xfa78('0x30')]=qs[_0xfa78('0x30')](_0x52c405[_0xfa78('0x41')][_0xfa78('0x30')]);}_0x4b9d7d['order']=qs[_0xfa78('0x49')](_0x52c405[_0xfa78('0x41')]['sort']);_0x4b9d7d['where']=qs[_0xfa78('0x43')](_[_0xfa78('0x66')](_0x52c405[_0xfa78('0x41')],_0x537976[_0xfa78('0x43')]));_0x4b9d7d['where'][_0xfa78('0x63')]=_0x1a2e8e['id'];if(_0x52c405[_0xfa78('0x41')][_0xfa78('0x4b')]){_0x4b9d7d[_0xfa78('0x4a')]=_[_0xfa78('0x4c')](_0x4b9d7d[_0xfa78('0x4a')],{'$or':_[_0xfa78('0x40')](_0x4b9d7d['attributes'],function(_0x55590a){var _0x51bb9e={};_0x51bb9e[_0x55590a]={'$like':'%'+_0x52c405[_0xfa78('0x41')]['filter']+'%'};return _0x51bb9e;})});}_0x4b9d7d=_[_0xfa78('0x4c')]({},_0x4b9d7d,_0x52c405[_0xfa78('0x4e')]);return db[_0xfa78('0x67')]['count']({'where':_0x4b9d7d['where']})[_0xfa78('0x20')](function(_0x5ec4e4){_0x37a24a['count']=_0x5ec4e4;if(_0x52c405[_0xfa78('0x41')][_0xfa78('0x4f')]){_0x4b9d7d[_0xfa78('0x50')]=[{'all':!![]}];}return db[_0xfa78('0x67')][_0xfa78('0x51')](_0x4b9d7d);})[_0xfa78('0x20')](function(_0x1b661d){_0x37a24a[_0xfa78('0x52')]=_0x1b661d;return _0x37a24a;});}})[_0xfa78('0x20')](respondWithFilteredResult(_0x12729b,_0x4b9d7d))['catch'](handleError(_0x12729b,null));};exports['removeDispositions']=function(_0x1b50c9,_0x407f37,_0x35e5ec){return db[_0xfa78('0x3b')]['find']({'where':{'id':_0x1b50c9[_0xfa78('0x54')]['id']}})['then'](handleEntityNotFound(_0x407f37,null))[_0xfa78('0x20')](function(_0x19a86b){if(_0x19a86b){return _0x19a86b[_0xfa78('0x68')](_0x1b50c9['query'][_0xfa78('0x69')]);}})[_0xfa78('0x20')](respondWithStatusCode(_0x407f37,null))[_0xfa78('0x2a')](handleError(_0x407f37,null));};exports[_0xfa78('0x6a')]=function(_0x209bcb,_0x312392,_0x4da928){if(_0x209bcb[_0xfa78('0x57')]['id']){delete _0x209bcb[_0xfa78('0x57')]['id'];}return db[_0xfa78('0x3b')][_0xfa78('0x55')]({'where':{'id':_0x209bcb[_0xfa78('0x54')]['id']}})[_0xfa78('0x20')](handleEntityNotFound(_0x312392,null))['then'](function(_0x3f7e82){if(_0x3f7e82){_0x209bcb['body'][_0xfa78('0x63')]=_0x3f7e82['id'];return db[_0xfa78('0x6b')][_0xfa78('0x56')](_0x209bcb[_0xfa78('0x57')]);}})['then'](respondWithResult(_0x312392,null))['catch'](handleError(_0x312392,null));};exports[_0xfa78('0x6c')]=function(_0x486e5f,_0x4933dd,_0x3bf1a7){var _0x29b2c0={'raw':![],'where':{}};var _0x4b81ec={};var _0x317ed6={'count':0x0,'rows':[]};return db[_0xfa78('0x3b')][_0xfa78('0x64')]({'where':{'id':_0x486e5f[_0xfa78('0x54')]['id']}})[_0xfa78('0x20')](handleEntityNotFound(_0x4933dd,null))['then'](function(_0x3fb6c9){if(_0x3fb6c9){_0x4b81ec[_0xfa78('0x3f')]=_[_0xfa78('0x42')](db[_0xfa78('0x6b')][_0xfa78('0x3c')]);_0x4b81ec[_0xfa78('0x41')]=_[_0xfa78('0x42')](_0x486e5f[_0xfa78('0x41')]);_0x4b81ec['filters']=_[_0xfa78('0x44')](_0x4b81ec['model'],_0x4b81ec[_0xfa78('0x41')]);_0x29b2c0['attributes']=_[_0xfa78('0x44')](_0x4b81ec[_0xfa78('0x3f')],qs[_0xfa78('0x46')](_0x486e5f[_0xfa78('0x41')][_0xfa78('0x46')]));_0x29b2c0['attributes']=_0x29b2c0[_0xfa78('0x45')][_0xfa78('0x47')]?_0x29b2c0[_0xfa78('0x45')]:_0x4b81ec['model'];if(!_0x486e5f[_0xfa78('0x41')]['hasOwnProperty']('nolimit')){_0x29b2c0[_0xfa78('0x48')]=qs[_0xfa78('0x48')](_0x486e5f['query'][_0xfa78('0x48')]);_0x29b2c0[_0xfa78('0x30')]=qs[_0xfa78('0x30')](_0x486e5f[_0xfa78('0x41')][_0xfa78('0x30')]);}_0x29b2c0[_0xfa78('0x6d')]=qs[_0xfa78('0x49')](_0x486e5f['query'][_0xfa78('0x49')]);_0x29b2c0['where']=qs[_0xfa78('0x43')](_[_0xfa78('0x66')](_0x486e5f[_0xfa78('0x41')],_0x4b81ec[_0xfa78('0x43')]));_0x29b2c0[_0xfa78('0x4a')]['SmsAccountId']=_0x3fb6c9['id'];if(_0x486e5f['query'][_0xfa78('0x4b')]){_0x29b2c0[_0xfa78('0x4a')]=_[_0xfa78('0x4c')](_0x29b2c0['where'],{'$or':_[_0xfa78('0x40')](_0x29b2c0['attributes'],function(_0xa5e958){var _0x58fca3={};_0x58fca3[_0xa5e958]={'$like':'%'+_0x486e5f[_0xfa78('0x41')]['filter']+'%'};return _0x58fca3;})});}_0x29b2c0=_['merge']({},_0x29b2c0,_0x486e5f[_0xfa78('0x4e')]);return db[_0xfa78('0x6b')][_0xfa78('0x2f')]({'where':_0x29b2c0['where']})[_0xfa78('0x20')](function(_0x4c93f2){_0x317ed6[_0xfa78('0x2f')]=_0x4c93f2;if(_0x486e5f['query'][_0xfa78('0x4f')]){_0x29b2c0['include']=[{'all':!![]}];}return db[_0xfa78('0x6b')][_0xfa78('0x51')](_0x29b2c0);})[_0xfa78('0x20')](function(_0x4ca22a){_0x317ed6[_0xfa78('0x52')]=_0x4ca22a;return _0x317ed6;});}})[_0xfa78('0x20')](respondWithFilteredResult(_0x4933dd,_0x29b2c0))[_0xfa78('0x2a')](handleError(_0x4933dd,null));};exports['removeAnswers']=function(_0x293045,_0x57fb43,_0x11d124){return db[_0xfa78('0x3b')][_0xfa78('0x55')]({'where':{'id':_0x293045[_0xfa78('0x54')]['id']}})[_0xfa78('0x20')](handleEntityNotFound(_0x57fb43,null))[_0xfa78('0x20')](function(_0x834253){if(_0x834253){return _0x834253[_0xfa78('0x6e')](_0x293045['query'][_0xfa78('0x69')]);}})[_0xfa78('0x20')](respondWithStatusCode(_0x57fb43,null))['catch'](handleError(_0x57fb43,null));};exports['notify']=function(_0x1566d1,_0x541e01,_0x37a730){var _0x51330a={'channel':_0xfa78('0x6f')};var _0x4ff995=[];var _0xd35383=[];var _0xfa7e76={};return db[_0xfa78('0x3b')][_0xfa78('0x55')]({'where':{'id':_0x1566d1[_0xfa78('0x54')]['id']},'include':[{'model':db[_0xfa78('0x70')],'as':_0xfa78('0x71')}]})['then'](handleEntityNotFound(_0x541e01,null))[_0xfa78('0x20')](function(_0x5ce1e2){_0x51330a['account']=_0x5ce1e2;_0x51330a[_0xfa78('0x72')]=_[_0xfa78('0x73')](_0x5ce1e2[_0xfa78('0x71')],['priority'],[_0xfa78('0x74')]);if(_0x51330a[_0xfa78('0x75')][_0xfa78('0x71')]){delete _0x51330a[_0xfa78('0x75')][_0xfa78('0x71')];}return db[_0xfa78('0x76')]['describe']();})[_0xfa78('0x20')](function(_0x1fd2b9){if(!_0x1fd2b9){throw new db['Sequelize'][(_0xfa78('0x77'))]('no\x20available\x20attributes');}_0x4ff995=_[_0xfa78('0x78')](_[_0xfa78('0x42')](_0x1fd2b9),[_0xfa78('0x79'),_0xfa78('0x7a')]);_0xd35383=_[_0xfa78('0x78')](_['keys'](_0x1fd2b9),['createdAt','updatedAt',_0xfa78('0x7b'),'ListId']);_0x51330a[_0xfa78('0x57')]={'mapKey':_0xfa78('0x7c')};if(_0x51330a[_0xfa78('0x75')][_0xfa78('0x7d')]){switch(_0x51330a[_0xfa78('0x75')][_0xfa78('0x7d')]){case'twilio':_0x51330a[_0xfa78('0x57')][_0xfa78('0x7e')]=_0x1566d1[_0xfa78('0x57')][_0xfa78('0x7f')];_0x51330a['body']['body']=_0x1566d1[_0xfa78('0x57')]['Body'];_0x51330a[_0xfa78('0x57')]['messageId']=_0x1566d1[_0xfa78('0x57')][_0xfa78('0x80')];break;case _0xfa78('0x81'):_0x51330a[_0xfa78('0x57')]['from']='+'+_0x1566d1[_0xfa78('0x57')][_0xfa78('0x82')];_0x51330a[_0xfa78('0x57')][_0xfa78('0x57')]=_0x1566d1[_0xfa78('0x57')][_0xfa78('0x83')];break;case'connectel':_0x51330a[_0xfa78('0x57')]['from']=_0x1566d1[_0xfa78('0x57')][_0xfa78('0x7e')];_0x51330a['body']['body']=_0x1566d1[_0xfa78('0x57')][_0xfa78('0x28')];break;case _0xfa78('0x84'):_0x51330a[_0xfa78('0x57')][_0xfa78('0x7e')]=_0x1566d1['body'][_0xfa78('0x7e')];_0x51330a[_0xfa78('0x57')][_0xfa78('0x57')]=_0x1566d1['body']['body'];_0x51330a[_0xfa78('0x57')][_0xfa78('0x85')]=_0x1566d1[_0xfa78('0x57')]['message_id'];break;case _0xfa78('0x86'):_0x51330a['body'][_0xfa78('0x7e')]=_0x1566d1['body'][_0xfa78('0x7f')];_0x51330a[_0xfa78('0x57')][_0xfa78('0x57')]=_0x1566d1[_0xfa78('0x57')]['Text'];_0x51330a[_0xfa78('0x57')]['messageId']=_0x1566d1[_0xfa78('0x57')]['MessageUUID'];break;case'infobip':_0x51330a[_0xfa78('0x57')]['from']='+'+_0x1566d1[_0xfa78('0x57')][_0xfa78('0x87')][0x0][_0xfa78('0x7e')];_0x51330a['body'][_0xfa78('0x57')]=_0x1566d1[_0xfa78('0x57')][_0xfa78('0x87')][0x0][_0xfa78('0x83')];_0x51330a['body'][_0xfa78('0x85')]=_0x1566d1[_0xfa78('0x57')][_0xfa78('0x87')][0x0]['messageId'];break;case _0xfa78('0x88'):_0x51330a[_0xfa78('0x57')]['from']=_0x1566d1[_0xfa78('0x57')][_0xfa78('0x89')];_0x51330a[_0xfa78('0x57')]['body']=_0x1566d1[_0xfa78('0x57')][_0xfa78('0x8a')][_0xfa78('0x28')];break;case'clickatell':_0x51330a[_0xfa78('0x57')][_0xfa78('0x7e')]=_0x1566d1['body'][_0xfa78('0x8b')];_0x51330a['body'][_0xfa78('0x57')]=_0x1566d1['body'][_0xfa78('0x83')];_0x51330a[_0xfa78('0x57')][_0xfa78('0x85')]=_0x1566d1[_0xfa78('0x57')][_0xfa78('0x8c')];break;case _0xfa78('0x8d'):_0x51330a['body'][_0xfa78('0x85')]=_0x1566d1[_0xfa78('0x57')][0x0][_0xfa78('0x28')]['id'];_0x51330a[_0xfa78('0x57')][_0xfa78('0x7e')]=_0x1566d1[_0xfa78('0x57')][0x0][_0xfa78('0x28')][_0xfa78('0x7e')];_0x51330a[_0xfa78('0x57')][_0xfa78('0x57')]=_0x1566d1[_0xfa78('0x57')][0x0][_0xfa78('0x28')][_0xfa78('0x83')];break;case'intelepeer':_0x51330a[_0xfa78('0x57')][_0xfa78('0x7e')]=_0x1566d1[_0xfa78('0x57')][_0xfa78('0x7e')];_0x51330a[_0xfa78('0x57')][_0xfa78('0x57')]=_0x1566d1[_0xfa78('0x57')][_0xfa78('0x28')];_0x51330a[_0xfa78('0x57')][_0xfa78('0x85')]=_0x1566d1['body'][_0xfa78('0x8e')];break;}}if(_0x51330a['body']['id']){delete _0x51330a[_0xfa78('0x57')]['id'];}if(_[_0xfa78('0x8f')](_0x51330a[_0xfa78('0x57')][_0xfa78('0x7e')])){throw new db[(_0xfa78('0x90'))][(_0xfa78('0x77'))]('from\x20is\x20mandatory');}if(_[_0xfa78('0x8f')](_0x51330a[_0xfa78('0x57')]['body'])||_0x51330a[_0xfa78('0x57')][_0xfa78('0x57')]===''){throw new db[(_0xfa78('0x90'))][(_0xfa78('0x77'))](_0xfa78('0x91'));}if(_['isNil'](_0x51330a[_0xfa78('0x57')][_0xfa78('0x92')])){throw new db[(_0xfa78('0x90'))][(_0xfa78('0x77'))]('mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0xd35383);}if(!_[_0xfa78('0x93')](_0xd35383,_0x51330a[_0xfa78('0x57')][_0xfa78('0x92')])){throw new db[(_0xfa78('0x90'))]['ValidationError'](_0xfa78('0x94')+_0xd35383);}_0xfa7e76[_0x51330a['body']['mapKey']]=_0x51330a[_0xfa78('0x57')][_0xfa78('0x7e')];return db[_0xfa78('0x95')]['find']({'where':{'id':_0x51330a[_0xfa78('0x75')][_0xfa78('0x96')]},'include':[{'model':db['CmContact'],'as':_0xfa78('0x97'),'where':_0xfa7e76,'limit':0x1,'order':[[_0xfa78('0x7a'),_0xfa78('0x98')]]}]});})['then'](handleEntityNotFound(_0x541e01,null))['then'](function(_0x76c05a){if(_0x76c05a){_0x51330a['list']=_[_0xfa78('0x99')](_0x76c05a,[_0xfa78('0x97')]);if(_0x76c05a['Contacts'][_0xfa78('0x47')]){return _0x76c05a[_0xfa78('0x97')][0x0];}var _0x1faca=_[_0xfa78('0x1c')](_0x51330a['body'],{'firstName':_0x51330a[_0xfa78('0x57')][_0xfa78('0x7e')],'ListId':_0x76c05a['id']});_0x1faca[_0x51330a['body']['mapKey']]=_0x51330a[_0xfa78('0x57')]['from'];return db[_0xfa78('0x76')]['create'](_0x1faca,{'fields':_0x4ff995,'raw':!![]});}})[_0xfa78('0x20')](handleEntityNotFound(_0x541e01,null))[_0xfa78('0x20')](function(_0x149c1a){if(_0x149c1a){_0x51330a['contact']=_0x149c1a;var _0x39065b={'ContactId':_0x149c1a['id'],'phone':_0x51330a[_0xfa78('0x57')]['from'],'SmsAccountId':_0x1566d1[_0xfa78('0x54')]['id']};var _0x5a598b={'ContactId':_0x149c1a['id'],'SmsAccountId':_0x1566d1[_0xfa78('0x54')]['id'],'closed':![]};return db[_0xfa78('0x9a')]['find']({'where':_0x5a598b})[_0xfa78('0x20')](function(_0x416c0a){if(_0x416c0a){return[_0x416c0a,![]];}return db[_0xfa78('0x9a')][_0xfa78('0x56')](_0x39065b)[_0xfa78('0x20')](function(_0x68d222){return[_0x68d222,!![]];});});}})[_0xfa78('0x9b')](function(_0x48f008,_0x2cb5f1){_0x51330a[_0xfa78('0x9c')]=_0x48f008[_0xfa78('0x58')]({'plain':!![]});_0x51330a[_0xfa78('0x9c')]['created']=![];if(_0x2cb5f1){if(_0x51330a[_0xfa78('0x75')][_0xfa78('0x9d')]){_0x51330a[_0xfa78('0x72')][_0xfa78('0x9e')]({'id':0x0,'priority':_0x51330a[_0xfa78('0x72')][_0xfa78('0x47')]+0x1,'app':'close','appdata':_0xfa78('0x9f'),'interval':_0xfa78('0xa0')});}_0x51330a[_0xfa78('0x9c')][_0xfa78('0xa1')]=!![];}return db[_0xfa78('0xa2')]['create']({'phone':_0x51330a[_0xfa78('0x57')][_0xfa78('0x7e')],'messageId':_0x51330a[_0xfa78('0x57')][_0xfa78('0x85')],'body':_0x51330a[_0xfa78('0x57')][_0xfa78('0x57')],'SmsAccountId':_0x1566d1[_0xfa78('0x54')]['id'],'SmsInteractionId':_0x48f008['id'],'direction':'in','ContactId':_0x48f008[_0xfa78('0xa3')],'AttachmentId':_0x51330a[_0xfa78('0x57')][_0xfa78('0xa4')]});})[_0xfa78('0x20')](function(_0x3847d1){_0x51330a['message']=_0x3847d1;if(_0x51330a[_0xfa78('0x9c')]['UserId']){return db[_0xfa78('0xa5')][_0xfa78('0x55')]({'attributes':['id',_0xfa78('0x37')],'where':{'id':_0x51330a[_0xfa78('0x9c')][_0xfa78('0xa6')]}})['then'](function(_0x2b1758){if(_0x2b1758){_0x51330a[_0xfa78('0x72')][_0xfa78('0xa7')]({'id':0x0,'priority':0x0,'app':_0xfa78('0xa8'),'appdata':_0x2b1758['name']+','+(_0x51330a[_0xfa78('0x75')][_0xfa78('0xa9')]||0xa),'interval':_0xfa78('0xa0')});}return respondWithRpcPromise(_0xfa78('0xaa'),_0xfa78('0xab'),_0x51330a);});}return respondWithRpcPromise('Start',_0xfa78('0xab'),_0x51330a);})['then'](function(_0x19497b){if(_0x19497b){var _0x454123=0xc8;var _0x23a9ad='receiveMessage';logger[_0xfa78('0x21')](_0xfa78('0x23'),_0x23a9ad,_0x454123,_0xfa78('0xac'));logger[_0xfa78('0xad')]('SmsAccount,\x20%s,\x20%s,\x20%s,\x20%s',_0x23a9ad,_0x454123,_0xfa78('0xac'),JSON[_0xfa78('0x24')](_0x19497b));if(_0x51330a[_0xfa78('0x75')][_0xfa78('0x7d')]===_0xfa78('0xae')){return _0x541e01[_0xfa78('0x2c')](_0x454123)[_0xfa78('0xaf')](_0xfa78('0xb0'),_0xfa78('0xb1'))['send']('<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>');}else{return _0x541e01[_0xfa78('0x2c')](_0x454123)[_0xfa78('0x2e')](_0x19497b);}}})[_0xfa78('0x2a')](handleError(_0x541e01,null));};exports[_0xfa78('0xb2')]=function(_0x3c49b0,_0x18dc7e,_0xa5d53a){return db[_0xfa78('0x3b')][_0xfa78('0x64')]({'where':{'id':_0x3c49b0[_0xfa78('0x54')]['id']}})[_0xfa78('0x20')](handleEntityNotFound(_0x18dc7e,null))[_0xfa78('0x20')](function(_0x4a5321){if(_0x4a5321){return db[_0xfa78('0xb3')][_0xfa78('0xb4')](function(_0x1c7d3a){return db[_0xfa78('0x70')][_0xfa78('0x60')]({'where':{'SmsAccountId':_0x3c49b0[_0xfa78('0x54')]['id']},'transaction':_0x1c7d3a})['then'](function(_0x2b6f51){var _0x4b0a36=_['map'](_0x3c49b0[_0xfa78('0x57')],function(_0x530f62){_0x530f62[_0xfa78('0x63')]=_0x3c49b0[_0xfa78('0x54')]['id'];return _0x530f62;});return db[_0xfa78('0x70')][_0xfa78('0xb5')](_0x4b0a36,{'transaction':_0x1c7d3a});});})[_0xfa78('0x20')](function(){return db[_0xfa78('0x70')]['findAndCountAll']({'where':{'SmsAccountId':_0x3c49b0['params']['id']},'order':_0xfa78('0xb6')});});}})[_0xfa78('0x20')](respondWithResult(_0x18dc7e,null))[_0xfa78('0x2a')](handleError(_0x18dc7e,null));};exports['getApplications']=function(_0x30ff06,_0x38803a,_0x5bb31c){var _0x3e174f={};var _0x336182={};var _0x1e45a3;var _0x51df4b;return db[_0xfa78('0x3b')]['findOne']({'where':{'id':_0x30ff06[_0xfa78('0x54')]['id']}})[_0xfa78('0x20')](handleEntityNotFound(_0x38803a,null))['then'](function(_0x42edca){if(_0x42edca){_0x1e45a3=_0x42edca;_0x336182[_0xfa78('0x3f')]=_[_0xfa78('0x42')](db[_0xfa78('0x70')][_0xfa78('0x3c')]);_0x336182[_0xfa78('0x41')]=_['keys'](_0x30ff06['query']);_0x336182[_0xfa78('0x43')]=_[_0xfa78('0x44')](_0x336182[_0xfa78('0x3f')],_0x336182['query']);_0x3e174f['attributes']=_[_0xfa78('0x44')](_0x336182[_0xfa78('0x3f')],qs[_0xfa78('0x46')](_0x30ff06[_0xfa78('0x41')][_0xfa78('0x46')]));_0x3e174f[_0xfa78('0x45')]=_0x3e174f[_0xfa78('0x45')][_0xfa78('0x47')]?_0x3e174f[_0xfa78('0x45')]:_0x336182[_0xfa78('0x3f')];_0x3e174f['order']=qs[_0xfa78('0x49')](_0x30ff06[_0xfa78('0x41')][_0xfa78('0x49')]);_0x3e174f[_0xfa78('0x4a')]=qs[_0xfa78('0x43')](_[_0xfa78('0x66')](_0x30ff06[_0xfa78('0x41')],_0x336182[_0xfa78('0x43')]));if(_0x30ff06['query'][_0xfa78('0x4b')]){_0x3e174f['where']=_[_0xfa78('0x4c')](_0x3e174f[_0xfa78('0x4a')],{'$or':_[_0xfa78('0x40')](_0x3e174f[_0xfa78('0x45')],function(_0xb7df9e){var _0x4d01da={};_0x4d01da[_0xb7df9e]={'$like':'%'+_0x30ff06[_0xfa78('0x41')][_0xfa78('0x4b')]+'%'};return _0x4d01da;})});}_0x3e174f=_[_0xfa78('0x4c')]({},_0x3e174f,_0x30ff06[_0xfa78('0x4e')]);return _0x1e45a3[_0xfa78('0xb7')](_0x3e174f);}})[_0xfa78('0x20')](function(_0x102d8e){if(_0x102d8e){_0x51df4b=_0x102d8e['length'];if(!_0x30ff06[_0xfa78('0x41')]['hasOwnProperty'](_0xfa78('0x65'))){_0x3e174f[_0xfa78('0x48')]=qs[_0xfa78('0x48')](_0x30ff06[_0xfa78('0x41')][_0xfa78('0x48')]);_0x3e174f[_0xfa78('0x30')]=qs[_0xfa78('0x30')](_0x30ff06[_0xfa78('0x41')][_0xfa78('0x30')]);}return _0x1e45a3[_0xfa78('0xb7')](_0x3e174f);}})[_0xfa78('0x20')](function(_0x3de445){if(_0x3de445){return _0x3de445?{'count':_0x51df4b,'rows':_0x3de445}:null;}})[_0xfa78('0x20')](respondWithResult(_0x38803a,null))[_0xfa78('0x2a')](handleError(_0x38803a,null));};exports[_0xfa78('0xb8')]=function(_0x36c580,_0x59a6e7,_0x80d4da){var _0x1129cd={'raw':![],'where':{}};var _0xdb2ed6={};var _0x31f5d8={'count':0x0,'rows':[]};return db[_0xfa78('0x3b')][_0xfa78('0x64')]({'where':{'id':_0x36c580[_0xfa78('0x54')]['id']}})['then'](handleEntityNotFound(_0x59a6e7,null))[_0xfa78('0x20')](function(_0x2359df){if(_0x2359df){_0xdb2ed6[_0xfa78('0x3f')]=_[_0xfa78('0x42')](db[_0xfa78('0x9a')][_0xfa78('0x3c')]);_0xdb2ed6[_0xfa78('0x41')]=_[_0xfa78('0x42')](_0x36c580['query']);_0xdb2ed6[_0xfa78('0x43')]=_[_0xfa78('0x44')](_0xdb2ed6[_0xfa78('0x3f')],_0xdb2ed6[_0xfa78('0x41')]);_0x1129cd[_0xfa78('0x45')]=_[_0xfa78('0x44')](_0xdb2ed6[_0xfa78('0x3f')],qs['fields'](_0x36c580[_0xfa78('0x41')][_0xfa78('0x46')]));_0x1129cd[_0xfa78('0x45')]=_0x1129cd[_0xfa78('0x45')]['length']?_0x1129cd[_0xfa78('0x45')]:_0xdb2ed6['model'];if(!_0x36c580[_0xfa78('0x41')]['hasOwnProperty'](_0xfa78('0x65'))){_0x1129cd['limit']=qs[_0xfa78('0x48')](_0x36c580['query'][_0xfa78('0x48')]);_0x1129cd[_0xfa78('0x30')]=qs[_0xfa78('0x30')](_0x36c580['query'][_0xfa78('0x30')]);}_0x1129cd[_0xfa78('0x6d')]=qs[_0xfa78('0x49')](_0x36c580[_0xfa78('0x41')][_0xfa78('0x49')]);_0x1129cd[_0xfa78('0x4a')]=qs[_0xfa78('0x43')](_[_0xfa78('0x66')](_0x36c580[_0xfa78('0x41')],_0xdb2ed6[_0xfa78('0x43')]));_0x1129cd[_0xfa78('0x4a')][_0xfa78('0x63')]=_0x2359df['id'];if(_0x36c580[_0xfa78('0x41')][_0xfa78('0x4b')]){_0x1129cd[_0xfa78('0x4a')]=_['merge'](_0x1129cd[_0xfa78('0x4a')],{'$or':_[_0xfa78('0x40')](_0x1129cd['attributes'],function(_0x3116b6){var _0x2d7f1f={};_0x2d7f1f[_0x3116b6]={'$like':'%'+_0x36c580[_0xfa78('0x41')][_0xfa78('0x4b')]+'%'};return _0x2d7f1f;})});}_0x1129cd=_['merge']({},_0x1129cd,_0x36c580[_0xfa78('0x4e')]);return db['SmsInteraction'][_0xfa78('0x2f')]({'where':_0x1129cd['where']})[_0xfa78('0x20')](function(_0x1b86e8){_0x31f5d8['count']=_0x1b86e8;if(_0x36c580['query']['includeAll']){_0x1129cd[_0xfa78('0x50')]=[{'model':db[_0xfa78('0x76')],'as':_0xfa78('0xb9'),'required':![]},{'model':db[_0xfa78('0xa5')],'as':_0xfa78('0xba'),'attributes':[_0xfa78('0x37'),'fullname',_0xfa78('0xbb')],'required':![]},{'model':db[_0xfa78('0xbc')],'as':_0xfa78('0xbd'),'attributes':['id',_0xfa78('0x37'),_0xfa78('0xbe')],'where':_0x36c580[_0xfa78('0x41')][_0xfa78('0xbf')]?{'id':_0x36c580[_0xfa78('0x41')][_0xfa78('0xbf')]}:undefined,'required':_0x36c580[_0xfa78('0x41')][_0xfa78('0xbf')]?!![]:![]}];}return db[_0xfa78('0x9a')][_0xfa78('0x51')](_0x1129cd);})[_0xfa78('0x20')](function(_0x5df938){_0x31f5d8[_0xfa78('0x52')]=_0x5df938;return _0x31f5d8;});}})[_0xfa78('0x20')](respondWithFilteredResult(_0x59a6e7,_0x1129cd))[_0xfa78('0x2a')](handleError(_0x59a6e7,null));};exports[_0xfa78('0xc0')]=function(_0x52fdb6,_0x101660,_0xe6653){var _0x381725,_0x347b0a,_0x1d4453;if(_['isNil'](_0x52fdb6['body'][_0xfa78('0x57')])||_0x52fdb6[_0xfa78('0x57')][_0xfa78('0x57')]===''){throw new db[(_0xfa78('0x90'))][(_0xfa78('0x77'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0xfa78('0x8f')](_0x52fdb6[_0xfa78('0x57')]['to'])){throw new db[(_0xfa78('0x90'))][(_0xfa78('0x77'))]('to\x20is\x20mandatory');}_0x381725=_0x52fdb6[_0xfa78('0x57')]['to'];return db['SmsAccount'][_0xfa78('0x55')]({'where':{'id':_0x52fdb6[_0xfa78('0x54')]['id']},'include':[{'model':db[_0xfa78('0x95')],'as':_0xfa78('0xc1'),'include':[{'model':db[_0xfa78('0x76')],'as':_0xfa78('0x97'),'where':{'mobile':_0x381725},'limit':0x1,'order':[['updatedAt',_0xfa78('0x98')]]}]}]})[_0xfa78('0x20')](handleEntityNotFound(_0x101660,null))[_0xfa78('0x20')](function(_0x35a16a){if(_0x35a16a&&_0x35a16a[_0xfa78('0xc1')]){_0x347b0a=_0x35a16a[_0xfa78('0x58')]({'plain':!![]});if(_0x347b0a['List']&&_0x347b0a[_0xfa78('0xc1')][_0xfa78('0x97')]['length']){return _0x347b0a['List'][_0xfa78('0x97')][0x0];}return db[_0xfa78('0x76')][_0xfa78('0x56')](_['defaults'](_0x52fdb6[_0xfa78('0x57')],{'firstName':_0x381725,'mobile':_0x381725,'phone':_0x381725,'ListId':_0x347b0a['ListId']}));}})[_0xfa78('0x20')](handleEntityNotFound(_0x101660,null))[_0xfa78('0x20')](function(_0x4138a6){if(_0x4138a6){_0x1d4453=_0x4138a6;return db['SmsInteraction'][_0xfa78('0x55')]({'where':{'ContactId':_0x1d4453['id'],'closed':![],'SmsAccountId':_0x347b0a['id']}})[_0xfa78('0x20')](function(_0x942e36){if(_0x942e36){return[_0x942e36,![]];}return db[_0xfa78('0x9a')]['create']({'UserId':_0x52fdb6['user']['id'],'ContactId':_0x1d4453['id'],'SmsAccountId':_0x347b0a['id'],'phone':_0x381725,'firstMsgDirection':'out','Messages':[_[_0xfa78('0x4c')](_0x52fdb6[_0xfa78('0x57')],{'read':![],'body':_0x52fdb6[_0xfa78('0x57')][_0xfa78('0x57')],'phone':_0x381725,'SmsAccountId':_0x347b0a['id'],'UserId':_0x52fdb6[_0xfa78('0xc2')]['id'],'ContactId':_0x1d4453['id']})]},{'include':[{'model':db['SmsMessage'],'as':_0xfa78('0xc3')}]})[_0xfa78('0x20')](function(_0x3e4406){return[_0x3e4406,!![]];});});}})['spread'](function(_0x5ee5b7,_0x941698){if(_0x941698){return _0x5ee5b7;}return db[_0xfa78('0xa2')][_0xfa78('0x56')](_[_0xfa78('0x4c')](_0x52fdb6[_0xfa78('0x57')],{'read':![],'body':_0x52fdb6[_0xfa78('0x57')][_0xfa78('0x57')],'phone':_0x381725,'SmsAccountId':_0x347b0a['id'],'SmsInteractionId':_0x5ee5b7['id'],'UserId':_0x52fdb6[_0xfa78('0xc2')]['id'],'ContactId':_0x1d4453['id']}))[_0xfa78('0x20')](function(_0x95bc72){_0x5ee5b7[_0xfa78('0xc4')]['Messages']=[];_0x5ee5b7[_0xfa78('0xc4')]['Messages'][_0xfa78('0x9e')](_0x95bc72[_0xfa78('0xc4')]);return _0x5ee5b7;});})['then'](respondWithResult(_0x101660,null))['catch'](handleError(_0x101660,null));};exports[_0xfa78('0x2c')]=function(_0x3a5ab4,_0x3ca1c6,_0x3edd95){if(_0x3a5ab4[_0xfa78('0x57')]['id']){delete _0x3a5ab4[_0xfa78('0x57')]['id'];}var _0xa368fe,_0xad228,_0x58549a;return db[_0xfa78('0x3b')][_0xfa78('0x55')]({'where':{'id':_0x3a5ab4[_0xfa78('0x54')]['id']}})[_0xfa78('0x20')](handleEntityNotFound(_0x3ca1c6,null))['then'](function(_0x4b338e){if(_0x4b338e){_0x58549a=_0x4b338e;logger[_0xfa78('0xad')](_0xfa78('0x23'),'status',_0xfa78('0xc5'),_0x4b338e[_0xfa78('0x7d')],util[_0xfa78('0xc6')](_0x3a5ab4[_0xfa78('0x57')],{'showHidden':![],'depth':null}));switch(_0x4b338e[_0xfa78('0x7d')]){case'skebby':if(_0x3a5ab4[_0xfa78('0x57')][_0xfa78('0xc7')]&&_0x3a5ab4[_0xfa78('0x57')][_0xfa78('0x2c')]){_0xad228=_0x3a5ab4[_0xfa78('0x57')][_0xfa78('0x2c')];return db[_0xfa78('0xa2')][_0xfa78('0x55')]({'where':{'messageId':_0x3a5ab4[_0xfa78('0x57')]['skebby_dispatch_id']}});}break;case _0xfa78('0xc8'):if(_0x3a5ab4['body'][_0xfa78('0xc9')]&&_0x3a5ab4[_0xfa78('0x57')]['statusInt']){_0xad228=_0x3a5ab4[_0xfa78('0x57')]['statusInt'];return db[_0xfa78('0xa2')]['find']({'where':{'messageId':_0x3a5ab4[_0xfa78('0x57')][_0xfa78('0xc9')]}});}break;case _0xfa78('0x84'):if(_0x3a5ab4[_0xfa78('0x57')][_0xfa78('0xca')]&&_0x3a5ab4[_0xfa78('0x57')][_0xfa78('0xcb')]){_0xad228=_0x3a5ab4[_0xfa78('0x57')][_0xfa78('0xcb')];return db[_0xfa78('0xa2')][_0xfa78('0x55')]({'where':{'messageId':_0x3a5ab4['body'][_0xfa78('0xca')]}});}break;case'infobip':var _0x35d700=_0x3a5ab4['body'][_0xfa78('0x87')][0x0];if(_0x35d700['messageId']&&_0x35d700[_0xfa78('0x2c')][_0xfa78('0xcc')]==='DELIVERED'){_0xad228=_0x35d700['status'][_0xfa78('0xcc')];return db[_0xfa78('0xa2')][_0xfa78('0x55')]({'where':{'messageId':_0x35d700[_0xfa78('0x85')]}});}break;case _0xfa78('0xcd'):if(_0x3a5ab4[_0xfa78('0x57')][_0xfa78('0x85')]&&_0x3a5ab4[_0xfa78('0x57')]['status']){_0xad228=_0x3a5ab4[_0xfa78('0x57')][_0xfa78('0x2c')];return db[_0xfa78('0xa2')]['find']({'where':{'messageId':_0x3a5ab4[_0xfa78('0x57')][_0xfa78('0x85')]}});}break;case _0xfa78('0x8d'):if(_0x3a5ab4[_0xfa78('0x57')][0x0][_0xfa78('0x28')]['id']){_0xad228=_0x3a5ab4['body'][0x0][_0xfa78('0x7d')];return db[_0xfa78('0xa2')][_0xfa78('0x55')]({'where':{'messageId':_0x3a5ab4[_0xfa78('0x57')][0x0]['message']['id']}});}break;case _0xfa78('0xce'):if(_0x3a5ab4[_0xfa78('0x57')][_0xfa78('0xcf')]&&_0x3a5ab4[_0xfa78('0x57')]['status']){_0xad228=_0x3a5ab4[_0xfa78('0x57')][_0xfa78('0x2c')];return db[_0xfa78('0xa2')]['find']({'where':{'messageId':_0x3a5ab4[_0xfa78('0x57')][_0xfa78('0xcf')]}});}break;}}})['then'](handleEntityNotFound(_0x3ca1c6,null))['then'](function(_0x33767e){if(_0x33767e){_0xa368fe=_0x33767e;switch(_0x58549a['type']){case'skebby':if(_0xad228===_0xfa78('0xd0')){return _0xa368fe['update']({'read':!![]});}else{logger[_0xfa78('0x25')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0xfa78('0x2c'),'skebby',util[_0xfa78('0xc6')](_0x3a5ab4['body'],{'showHidden':![],'depth':null}));}break;case _0xfa78('0xc8'):if(_0xad228==='1'){return _0xa368fe[_0xfa78('0x5f')]({'read':!![]});}else{logger[_0xfa78('0x25')]('SmsAccount,\x20%s,\x20%s,\x20%s','status',_0xfa78('0x81'),util[_0xfa78('0xc6')](_0x3a5ab4['body'],{'showHidden':![],'depth':null}));}break;case _0xfa78('0x84'):if(!_0x3a5ab4[_0xfa78('0x57')][_0xfa78('0xd1')]&&_0xad228>=0xc8&&_0xad228<=0xce){return _0xa368fe[_0xfa78('0x5f')]({'read':!![]});}else{logger[_0xfa78('0x25')](_0xfa78('0x23'),_0xfa78('0x2c'),_0xfa78('0x84'),util[_0xfa78('0xc6')](_0x3a5ab4['body'],{'showHidden':![],'depth':null}));}break;case _0xfa78('0xd2'):var _0x2a9e00=_0x3a5ab4[_0xfa78('0x57')][_0xfa78('0x87')][0x0];if(_0x2a9e00[_0xfa78('0x2c')][_0xfa78('0xcc')]===_0xfa78('0xd0')){return _0xa368fe['update']({'read':!![]});}else{logger['error']('SmsAccount,\x20%s,\x20%s,\x20%s',_0xfa78('0x2c'),'infobip',util[_0xfa78('0xc6')](_0x3a5ab4[_0xfa78('0x57')],{'showHidden':![],'depth':null}));}break;case _0xfa78('0xcd'):if(_0xad228==_0xfa78('0xd3')||_0xad228==_0xfa78('0xd4')){return _0xa368fe[_0xfa78('0x5f')]({'read':!![]});}else{logger[_0xfa78('0x25')](_0xfa78('0x23'),_0xfa78('0x2c'),_0xfa78('0xcd'),util['inspect'](_0x3a5ab4[_0xfa78('0x57')],{'showHidden':![],'depth':null}));}break;case'bandwidth':if(_0xad228==_0xfa78('0xd5')){return _0xa368fe[_0xfa78('0x5f')]({'read':!![]});}else{logger['error'](_0xfa78('0x23'),_0xfa78('0x2c'),'bandwidth',util['inspect'](_0x3a5ab4[_0xfa78('0x57')],{'showHidden':![],'depth':null}));}break;case _0xfa78('0xce'):if(_0xad228===_0xfa78('0xd6')||_0xad228==='ACCEPTD'){return _0xa368fe[_0xfa78('0x5f')]({'read':!![]});}else{logger[_0xfa78('0x25')](_0xfa78('0x23'),_0xfa78('0x2c'),_0xfa78('0xce'),util['inspect'](_0x3a5ab4[_0xfa78('0x57')],{'showHidden':![],'depth':null}));}break;}return _0xa368fe;}})[_0xfa78('0x20')](respondWithResult(_0x3ca1c6,null))['catch'](handleError(_0x3ca1c6,null));};exports[_0xfa78('0xd7')]=function(_0x74d977,_0x15ef71,_0x1b5752){var _0x537484,_0x6741d3,_0x4301be;return db['SmsAccount']['find']({'where':{'id':_0x74d977[_0xfa78('0x54')]['id']}})['then'](handleEntityNotFound(_0x15ef71,null))[_0xfa78('0x20')](function(_0x2b32fc){if(_0x2b32fc){_0x4301be=_0x2b32fc;logger[_0xfa78('0xad')](_0xfa78('0x23'),_0xfa78('0x2c'),_0xfa78('0xc5'),_0x2b32fc[_0xfa78('0x7d')],util[_0xfa78('0xc6')](_0x74d977[_0xfa78('0x41')],{'showHidden':![],'depth':null}));switch(_0x2b32fc['type']){case _0xfa78('0x88'):if(_0x74d977['query'][_0xfa78('0xd8')]&&_0x74d977[_0xfa78('0x41')][_0xfa78('0xd9')]){_0x6741d3=_0x74d977[_0xfa78('0x41')][_0xfa78('0xd9')];return db[_0xfa78('0xa2')][_0xfa78('0x55')]({'where':{'messageId':_0x74d977[_0xfa78('0x41')]['message-id']}});}break;}}})[_0xfa78('0x20')](handleEntityNotFound(_0x15ef71,null))[_0xfa78('0x20')](function(_0x1161de){if(_0x1161de){_0x537484=_0x1161de;switch(_0x4301be[_0xfa78('0x7d')]){case _0xfa78('0x88'):if(_0x6741d3==='2'||_0x6741d3==='6'){return _0x537484['update']({'read':!![]});}else{logger[_0xfa78('0x25')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0xfa78('0x2c'),'csc',util['inspect'](_0x74d977[_0xfa78('0x41')],{'showHidden':![],'depth':null}));};break;}return _0x537484;}})[_0xfa78('0x20')](respondWithResult(_0x15ef71,null))['catch'](handleError(_0x15ef71,null));};exports[_0xfa78('0xda')]=function(_0x42df15,_0x1e49a5,_0xe6ed3c){return db['SmsAccount']['find']({'where':{'id':_0x42df15[_0xfa78('0x54')]['id']}})[_0xfa78('0x20')](handleEntityNotFound(_0x1e49a5,null))[_0xfa78('0x20')](function(_0x436d2a){if(_0x436d2a){return _0x436d2a['addAgents'](_0x42df15[_0xfa78('0x57')]['ids'],_['omit'](_0x42df15[_0xfa78('0x57')],[_0xfa78('0x69'),'id'])||{})[_0xfa78('0x9b')](function(_0x3a051b){for(var _0x5ce525=0x0;_0x5ce525<_0x42df15[_0xfa78('0x57')]['ids'][_0xfa78('0x47')];_0x5ce525+=0x1){socket['emit'](_0xfa78('0xdb'),{'UserId':_0x42df15[_0xfa78('0x57')][_0xfa78('0x69')][_0x5ce525],'SmsAccountId':_0x42df15[_0xfa78('0x54')]['id']});}return _0x3a051b;});}})[_0xfa78('0x20')](respondWithResult(_0x1e49a5,null))[_0xfa78('0x2a')](handleError(_0x1e49a5,null));};exports[_0xfa78('0xdc')]=function(_0x1299df,_0x3aa46e,_0x169aaa){return db[_0xfa78('0x3b')][_0xfa78('0x55')]({'where':{'id':_0x1299df[_0xfa78('0x54')]['id']}})[_0xfa78('0x20')](handleEntityNotFound(_0x3aa46e,null))['then'](function(_0x306258){if(_0x306258){return _0x306258['removeAgents'](_0x1299df[_0xfa78('0x41')]['ids'])[_0xfa78('0x20')](function(){if(_['isArray'](_0x1299df[_0xfa78('0x41')][_0xfa78('0x69')])){for(var _0x32dafa=0x0;_0x32dafa<_0x1299df[_0xfa78('0x41')][_0xfa78('0x69')]['length'];_0x32dafa+=0x1){socket[_0xfa78('0xdd')](_0xfa78('0xde'),{'UserId':Number(_0x1299df[_0xfa78('0x41')][_0xfa78('0x69')][_0x32dafa]),'SmsAccountId':Number(_0x1299df['params']['id'])});}}else{socket['emit'](_0xfa78('0xde'),{'UserId':Number(_0x1299df[_0xfa78('0x41')]['ids']),'SmsAccountId':Number(_0x1299df[_0xfa78('0x54')]['id'])});}});}})['then'](respondWithStatusCode(_0x3aa46e,null))[_0xfa78('0x2a')](handleError(_0x3aa46e,null));};exports['getAgents']=function(_0xa420dc,_0x38c150,_0x123e83){var _0x199484={};var _0x7f4efd={};var _0x544308;var _0x5688ea;return db[_0xfa78('0x3b')][_0xfa78('0x64')]({'where':{'id':_0xa420dc[_0xfa78('0x54')]['id']}})[_0xfa78('0x20')](handleEntityNotFound(_0x38c150,null))[_0xfa78('0x20')](function(_0x37e2f9){if(_0x37e2f9){_0x544308=_0x37e2f9;_0x7f4efd[_0xfa78('0x3f')]=_[_0xfa78('0x42')](db[_0xfa78('0xa5')]['rawAttributes']);_0x7f4efd['query']=_[_0xfa78('0x42')](_0xa420dc[_0xfa78('0x41')]);_0x7f4efd['filters']=_['intersection'](_0x7f4efd[_0xfa78('0x3f')],_0x7f4efd[_0xfa78('0x41')]);_0x199484[_0xfa78('0x45')]=_[_0xfa78('0x44')](_0x7f4efd[_0xfa78('0x3f')],qs[_0xfa78('0x46')](_0xa420dc[_0xfa78('0x41')][_0xfa78('0x46')]));_0x199484[_0xfa78('0x45')]=_0x199484[_0xfa78('0x45')][_0xfa78('0x47')]?_0x199484[_0xfa78('0x45')]:_0x7f4efd[_0xfa78('0x3f')];_0x199484[_0xfa78('0x6d')]=qs[_0xfa78('0x49')](_0xa420dc[_0xfa78('0x41')]['sort']);_0x199484[_0xfa78('0x4a')]=qs[_0xfa78('0x43')](_[_0xfa78('0x66')](_0xa420dc['query'],_0x7f4efd[_0xfa78('0x43')]));if(_0xa420dc['query'][_0xfa78('0x4b')]){_0x199484[_0xfa78('0x4a')]=_[_0xfa78('0x4c')](_0x199484[_0xfa78('0x4a')],{'$or':_[_0xfa78('0x40')](_0x199484[_0xfa78('0x45')],function(_0x53fe4c){var _0xd3edf6={};_0xd3edf6[_0x53fe4c]={'$like':'%'+_0xa420dc[_0xfa78('0x41')]['filter']+'%'};return _0xd3edf6;})});}_0x199484=_[_0xfa78('0x4c')]({},_0x199484,_0xa420dc['options']);return _0x544308[_0xfa78('0xdf')](_0x199484);}})[_0xfa78('0x20')](function(_0x5531ca){if(_0x5531ca){_0x5688ea=_0x5531ca[_0xfa78('0x47')];if(!_0xa420dc[_0xfa78('0x41')][_0xfa78('0xe0')](_0xfa78('0x65'))){_0x199484[_0xfa78('0x48')]=qs[_0xfa78('0x48')](_0xa420dc[_0xfa78('0x41')][_0xfa78('0x48')]);_0x199484[_0xfa78('0x30')]=qs[_0xfa78('0x30')](_0xa420dc[_0xfa78('0x41')]['offset']);}return _0x544308[_0xfa78('0xdf')](_0x199484);}})[_0xfa78('0x20')](function(_0xc9c024){if(_0xc9c024){return _0xc9c024?{'count':_0x5688ea,'rows':_0xc9c024}:null;}})[_0xfa78('0x20')](respondWithResult(_0x38c150,null))[_0xfa78('0x2a')](handleError(_0x38c150,null));};
\ No newline at end of file
+var _0xeb45=['clicksend','message_id','plivo','Text','MessageUUID','infobip','results','csc','originatingAddress','segmentedMessage','clickatell','fromNumber','intelepeer','isNil','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','CmList','CmContact','DESC','list','omit','Contacts','contact','SmsInteraction','spread','interaction','created','autoclose','push','unmanaged','*,*,*,*','SmsMessage','ContactId','UserId','unshift','waitForTheAssignedAgent','Start','startRouting','SmsAccount,\x20%s,\x20%s,\x20%s','entity\x20found','SmsAccount,\x20%s,\x20%s,\x20%s,\x20%s','twilio','set','Content-Type','send','<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>','addApplications','sequelize','Transaction','SmsApplication','bulkCreate','findAndCountAll','priority','getApplications','nolimit','getInteractions','Contact','User','Owner','Tag','Tags','tag','to\x20is\x20mandatory','List','out','dataValues','Messages','received\x20delivery\x20report\x20from','inspect','skebby_dispatch_id','requestid','statusInt','status_code','groupName','DELIVERED','bandwidth','redif','error_code','DELIVERED_TO_GATEWAY','RECEIVED_BY_RECIPIENT','message-delivered','DELIVRD','ACCEPTD','statusGet','message-id','state','addAgents','emit','userSmsAccount:save','removeAgents','isArray','userSmsAccount:remove','getAgents','eml-format','rimraf','zip-dir','fast-json-patch','moment','mustache','util','path','to-csv','ejs','lodash','squel','jsforce','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/license/util','redis','defaults','socket.io-emitter','./smsAccount.socket','register','jayson/promise','http','request','then','info','SmsAccount,\x20%s,\x20%s','request\x20sent','debug','stringify','error','code','message','result','catch','sendStatus','status','end','json','limit','undefined','count','offset','Content-Range','apply','reject','save','update','get','SmsAccounts','UserProfileResource','destroy','stack','name','Pause','mandatoryDispositionPause','map','rawAttributes','fieldName','type','key','model','query','keys','filters','attributes','intersection','length','hasOwnProperty','sort','where','pick','merge','VIRTUAL','filter','SmsAccount','includeAll','include','rows','show','params','fields','options','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','find','describe','addDisposition','SmsAccountId','getDispositions','findOne','Disposition','order','findAll','removeDispositions','ids','addAnswer','CannedAnswer','removeAnswers','sms','account','applications','orderBy','Applications','asc','Sequelize','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','ListId','from','From','Body','messageId','MessageSid','skebby','sender','text','connectel'];(function(_0x2c16d9,_0xd68b7){var _0x3e81b1=function(_0x242700){while(--_0x242700){_0x2c16d9['push'](_0x2c16d9['shift']());}};_0x3e81b1(++_0xd68b7);}(_0xeb45,0x142));var _0x5eb4=function(_0x5daea7,_0x352f72){_0x5daea7=_0x5daea7-0x0;var _0x8d8b63=_0xeb45[_0x5daea7];return _0x8d8b63;};'use strict';var emlformat=require(_0x5eb4('0x0'));var rimraf=require(_0x5eb4('0x1'));var zipdir=require(_0x5eb4('0x2'));var jsonpatch=require(_0x5eb4('0x3'));var rp=require('request-promise');var moment=require(_0x5eb4('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x5eb4('0x5'));var util=require(_0x5eb4('0x6'));var path=require(_0x5eb4('0x7'));var sox=require('sox');var csv=require(_0x5eb4('0x8'));var ejs=require(_0x5eb4('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x5eb4('0xa'));var squel=require(_0x5eb4('0xb'));var crypto=require('crypto');var jsforce=require(_0x5eb4('0xc'));var deskjs=require('desk.js');var toCsv=require(_0x5eb4('0x8'));var querystring=require('querystring');var Papa=require(_0x5eb4('0xd'));var Redis=require(_0x5eb4('0xe'));var authService=require(_0x5eb4('0xf'));var qs=require(_0x5eb4('0x10'));var as=require(_0x5eb4('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x5eb4('0x12'))('api');var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x5eb4('0x13'));var db=require('../../mysqldb')['db'];config[_0x5eb4('0x14')]=_[_0x5eb4('0x15')](config[_0x5eb4('0x14')],{'host':'localhost','port':0x18eb});var socket=require(_0x5eb4('0x16'))(new Redis(config[_0x5eb4('0x14')]));require(_0x5eb4('0x17'))[_0x5eb4('0x18')](socket);var jayson=require(_0x5eb4('0x19'));var client=jayson['client'][_0x5eb4('0x1a')]({'port':0x232c});function respondWithRpcPromise(_0x12aba2,_0x2d96dc,_0x58652b,_0x42c7b9){return new BPromise(function(_0x2da6d7,_0x46712e){var _0x4d0b66=_0x42c7b9||client;return _0x4d0b66[_0x5eb4('0x1b')](_0x12aba2,_0x58652b)[_0x5eb4('0x1c')](function(_0x373274){logger[_0x5eb4('0x1d')](_0x5eb4('0x1e'),_0x2d96dc,_0x5eb4('0x1f'));logger[_0x5eb4('0x20')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x2d96dc,'request\x20sent',JSON[_0x5eb4('0x21')](_0x373274));if(_0x373274[_0x5eb4('0x22')]){if(_0x373274['error'][_0x5eb4('0x23')]===0x1f4){logger[_0x5eb4('0x22')](_0x5eb4('0x1e'),_0x2d96dc,_0x373274[_0x5eb4('0x22')][_0x5eb4('0x24')]);return _0x46712e(_0x373274[_0x5eb4('0x22')][_0x5eb4('0x24')]);}logger['error']('SmsAccount,\x20%s,\x20%s',_0x2d96dc,_0x373274['error']['message']);return _0x2da6d7(_0x373274[_0x5eb4('0x22')][_0x5eb4('0x24')]);}else{logger['info'](_0x5eb4('0x1e'),_0x2d96dc,_0x5eb4('0x1f'));_0x2da6d7(_0x373274[_0x5eb4('0x25')][_0x5eb4('0x24')]);}})[_0x5eb4('0x26')](function(_0x549c58){logger['error']('SmsAccount,\x20%s,\x20%s',_0x2d96dc,_0x549c58);_0x46712e(_0x549c58);});});}function respondWithStatusCode(_0xac5f03,_0x193915){_0x193915=_0x193915||0xcc;return function(_0xf3bbfb){if(_0xf3bbfb){return _0xac5f03[_0x5eb4('0x27')](_0x193915);}return _0xac5f03[_0x5eb4('0x28')](_0x193915)[_0x5eb4('0x29')]();};}function respondWithResult(_0x5bbe90,_0x44ced1){_0x44ced1=_0x44ced1||0xc8;return function(_0x280806){if(_0x280806){return _0x5bbe90[_0x5eb4('0x28')](_0x44ced1)[_0x5eb4('0x2a')](_0x280806);}};}function respondWithFilteredResult(_0x50b42b,_0x260814){return function(_0x5221ee){if(_0x5221ee){var _0x2e27db=typeof _0x260814['offset']==='undefined'&&typeof _0x260814[_0x5eb4('0x2b')]===_0x5eb4('0x2c');var _0x3180ba=_0x5221ee[_0x5eb4('0x2d')];var _0x5c497f=_0x2e27db?0x0:_0x260814[_0x5eb4('0x2e')];var _0x51f42c=_0x2e27db?_0x5221ee[_0x5eb4('0x2d')]:_0x260814[_0x5eb4('0x2e')]+_0x260814[_0x5eb4('0x2b')];var _0x1e3068;if(_0x51f42c>=_0x3180ba){_0x51f42c=_0x3180ba;_0x1e3068=0xc8;}else{_0x1e3068=0xce;}_0x50b42b['status'](_0x1e3068);return _0x50b42b['set'](_0x5eb4('0x2f'),_0x5c497f+'-'+_0x51f42c+'/'+_0x3180ba)[_0x5eb4('0x2a')](_0x5221ee);}return null;};}function patchUpdates(_0x159bb5){return function(_0x49e85f){try{jsonpatch[_0x5eb4('0x30')](_0x49e85f,_0x159bb5,!![]);}catch(_0x476118){return BPromise[_0x5eb4('0x31')](_0x476118);}return _0x49e85f[_0x5eb4('0x32')]();};}function saveUpdates(_0x4bd65f,_0x5ed8f2){return function(_0x14d762){if(_0x14d762){return _0x14d762[_0x5eb4('0x33')](_0x4bd65f)['then'](function(_0x13e4ad){return _0x13e4ad;});}return null;};}function removeEntity(_0x3c8c44,_0x5ea823){return function(_0x407468){if(_0x407468){return _0x407468['destroy']()[_0x5eb4('0x1c')](function(){var _0x5235bb=_0x407468[_0x5eb4('0x34')]({'plain':!![]});var _0x49d808=_0x5eb4('0x35');return db[_0x5eb4('0x36')][_0x5eb4('0x37')]({'where':{'type':_0x49d808,'resourceId':_0x5235bb['id']}})[_0x5eb4('0x1c')](function(){return _0x407468;});})[_0x5eb4('0x1c')](function(){_0x3c8c44[_0x5eb4('0x28')](0xcc)[_0x5eb4('0x29')]();});}};}function handleEntityNotFound(_0x4db594,_0x68c913){return function(_0x36a9eb){if(!_0x36a9eb){_0x4db594['sendStatus'](0x194);}return _0x36a9eb;};}function handleError(_0x1c763b,_0x44e294){_0x44e294=_0x44e294||0x1f4;return function(_0x5ad95b){logger[_0x5eb4('0x22')](_0x5ad95b[_0x5eb4('0x38')]);if(_0x5ad95b[_0x5eb4('0x39')]){delete _0x5ad95b[_0x5eb4('0x39')];}_0x1c763b['status'](_0x44e294)['send'](_0x5ad95b);};}exports['index']=function(_0x5e8094,_0x50dcab){var _0x265a2a={'include':[{'model':db[_0x5eb4('0x3a')],'as':_0x5eb4('0x3b')}]},_0x28a4d2={},_0x5e9282={'count':0x0,'rows':[]};var _0x2b04ea=_[_0x5eb4('0x3c')](db['SmsAccount'][_0x5eb4('0x3d')],function(_0x19e3a2){return{'name':_0x19e3a2[_0x5eb4('0x3e')],'type':_0x19e3a2[_0x5eb4('0x3f')][_0x5eb4('0x40')]};});_0x28a4d2[_0x5eb4('0x41')]=_['map'](_0x2b04ea,'name');_0x28a4d2[_0x5eb4('0x42')]=_[_0x5eb4('0x43')](_0x5e8094[_0x5eb4('0x42')]);_0x28a4d2[_0x5eb4('0x44')]=_['intersection'](_0x28a4d2[_0x5eb4('0x41')],_0x28a4d2[_0x5eb4('0x42')]);_0x265a2a[_0x5eb4('0x45')]=_[_0x5eb4('0x46')](_0x28a4d2[_0x5eb4('0x41')],qs['fields'](_0x5e8094[_0x5eb4('0x42')]['fields']));_0x265a2a[_0x5eb4('0x45')]=_0x265a2a[_0x5eb4('0x45')][_0x5eb4('0x47')]?_0x265a2a[_0x5eb4('0x45')]:_0x28a4d2[_0x5eb4('0x41')];if(!_0x5e8094[_0x5eb4('0x42')][_0x5eb4('0x48')]('nolimit')){_0x265a2a[_0x5eb4('0x2b')]=qs[_0x5eb4('0x2b')](_0x5e8094[_0x5eb4('0x42')][_0x5eb4('0x2b')]);_0x265a2a[_0x5eb4('0x2e')]=qs[_0x5eb4('0x2e')](_0x5e8094[_0x5eb4('0x42')][_0x5eb4('0x2e')]);}_0x265a2a['order']=qs[_0x5eb4('0x49')](_0x5e8094[_0x5eb4('0x42')][_0x5eb4('0x49')]);_0x265a2a[_0x5eb4('0x4a')]=qs[_0x5eb4('0x44')](_[_0x5eb4('0x4b')](_0x5e8094[_0x5eb4('0x42')],_0x28a4d2[_0x5eb4('0x44')]),_0x2b04ea);if(_0x5e8094[_0x5eb4('0x42')]['filter']){_0x265a2a['where']=_[_0x5eb4('0x4c')](_0x265a2a[_0x5eb4('0x4a')],{'$or':_[_0x5eb4('0x3c')](_0x2b04ea,function(_0x2372b6){if(_0x2372b6['type']!==_0x5eb4('0x4d')){var _0x20025e={};_0x20025e[_0x2372b6[_0x5eb4('0x39')]]={'$like':'%'+_0x5e8094[_0x5eb4('0x42')][_0x5eb4('0x4e')]+'%'};return _0x20025e;}})});}_0x265a2a=_['merge']({},_0x265a2a,_0x5e8094['options']);var _0x186250={'where':_0x265a2a[_0x5eb4('0x4a')]};return db[_0x5eb4('0x4f')][_0x5eb4('0x2d')](_0x186250)[_0x5eb4('0x1c')](function(_0x420224){_0x5e9282[_0x5eb4('0x2d')]=_0x420224;if(_0x5e8094['query'][_0x5eb4('0x50')]){_0x265a2a[_0x5eb4('0x51')]=[{'all':!![]}];}return db[_0x5eb4('0x4f')]['findAll'](_0x265a2a);})[_0x5eb4('0x1c')](function(_0x4813f4){_0x5e9282[_0x5eb4('0x52')]=_0x4813f4;return _0x5e9282;})[_0x5eb4('0x1c')](respondWithFilteredResult(_0x50dcab,_0x265a2a))[_0x5eb4('0x26')](handleError(_0x50dcab,null));};exports[_0x5eb4('0x53')]=function(_0x110ed9,_0x421682){var _0x21c103={'raw':![],'where':{'id':_0x110ed9[_0x5eb4('0x54')]['id']},'include':[{'model':db['Pause'],'as':_0x5eb4('0x3b')}]},_0x906068={};_0x906068['model']=_[_0x5eb4('0x43')](db[_0x5eb4('0x4f')][_0x5eb4('0x3d')]);_0x906068[_0x5eb4('0x42')]=_[_0x5eb4('0x43')](_0x110ed9['query']);_0x906068['filters']=_[_0x5eb4('0x46')](_0x906068['model'],_0x906068[_0x5eb4('0x42')]);_0x21c103[_0x5eb4('0x45')]=_[_0x5eb4('0x46')](_0x906068[_0x5eb4('0x41')],qs[_0x5eb4('0x55')](_0x110ed9[_0x5eb4('0x42')]['fields']));_0x21c103[_0x5eb4('0x45')]=_0x21c103['attributes'][_0x5eb4('0x47')]?_0x21c103[_0x5eb4('0x45')]:_0x906068[_0x5eb4('0x41')];if(_0x110ed9['query'][_0x5eb4('0x50')]){_0x21c103[_0x5eb4('0x51')]=[{'all':!![]}];}_0x21c103=_[_0x5eb4('0x4c')]({},_0x21c103,_0x110ed9[_0x5eb4('0x56')]);return db[_0x5eb4('0x4f')]['find'](_0x21c103)[_0x5eb4('0x1c')](handleEntityNotFound(_0x421682,null))[_0x5eb4('0x1c')](respondWithResult(_0x421682,null))[_0x5eb4('0x26')](handleError(_0x421682,null));};exports['create']=function(_0x4a9069,_0x5116fe){return db[_0x5eb4('0x4f')][_0x5eb4('0x57')](_0x4a9069['body'],{})[_0x5eb4('0x1c')](function(_0x2f30ce){var _0x4133a3=_0x4a9069[_0x5eb4('0x58')][_0x5eb4('0x34')]({'plain':!![]});if(!_0x4133a3)throw new Error(_0x5eb4('0x59'));if(_0x4133a3['role']===_0x5eb4('0x58')){var _0x52de6b=_0x2f30ce[_0x5eb4('0x34')]({'plain':!![]});var _0x498cf5=_0x5eb4('0x35');return db['UserProfileSection']['find']({'where':{'name':_0x498cf5,'userProfileId':_0x4133a3[_0x5eb4('0x5a')]},'raw':!![]})[_0x5eb4('0x1c')](function(_0x534fb6){if(_0x534fb6&&_0x534fb6[_0x5eb4('0x5b')]===0x0){return db['UserProfileResource'][_0x5eb4('0x57')]({'name':_0x52de6b['name'],'resourceId':_0x52de6b['id'],'type':_0x534fb6[_0x5eb4('0x39')],'sectionId':_0x534fb6['id']},{})['then'](function(){return _0x2f30ce;});}else{return _0x2f30ce;}})[_0x5eb4('0x26')](function(_0x5b299c){logger[_0x5eb4('0x22')](_0x5eb4('0x5c'),_0x5b299c);throw _0x5b299c;});}return _0x2f30ce;})[_0x5eb4('0x1c')](respondWithResult(_0x5116fe,0xc9))[_0x5eb4('0x26')](handleError(_0x5116fe,null));};exports[_0x5eb4('0x33')]=function(_0xa93da8,_0x456e24){if(_0xa93da8[_0x5eb4('0x5d')]['id']){delete _0xa93da8[_0x5eb4('0x5d')]['id'];}return db[_0x5eb4('0x4f')][_0x5eb4('0x5e')]({'where':{'id':_0xa93da8[_0x5eb4('0x54')]['id']},'include':[{'model':db[_0x5eb4('0x3a')],'as':_0x5eb4('0x3b')}]})[_0x5eb4('0x1c')](handleEntityNotFound(_0x456e24,null))['then'](saveUpdates(_0xa93da8[_0x5eb4('0x5d')],null))['then'](respondWithResult(_0x456e24,null))[_0x5eb4('0x26')](handleError(_0x456e24,null));};exports[_0x5eb4('0x37')]=function(_0x2a7a84,_0x19f48b){return db['SmsAccount'][_0x5eb4('0x5e')]({'where':{'id':_0x2a7a84['params']['id']}})[_0x5eb4('0x1c')](handleEntityNotFound(_0x19f48b,null))['then'](removeEntity(_0x19f48b,null))['catch'](handleError(_0x19f48b,null));};exports[_0x5eb4('0x5f')]=function(_0x5c5c5e,_0x5cae2c){return db[_0x5eb4('0x4f')][_0x5eb4('0x5f')]()[_0x5eb4('0x1c')](respondWithResult(_0x5cae2c,null))[_0x5eb4('0x26')](handleError(_0x5cae2c,null));};exports[_0x5eb4('0x60')]=function(_0x4e5ead,_0xe5cbd4,_0x406a4b){if(_0x4e5ead[_0x5eb4('0x5d')]['id']){delete _0x4e5ead[_0x5eb4('0x5d')]['id'];}return db[_0x5eb4('0x4f')][_0x5eb4('0x5e')]({'where':{'id':_0x4e5ead['params']['id']}})[_0x5eb4('0x1c')](handleEntityNotFound(_0xe5cbd4,null))['then'](function(_0x4bbe7a){if(_0x4bbe7a){_0x4e5ead[_0x5eb4('0x5d')][_0x5eb4('0x61')]=_0x4bbe7a['id'];return db['Disposition'][_0x5eb4('0x57')](_0x4e5ead[_0x5eb4('0x5d')]);}})[_0x5eb4('0x1c')](respondWithResult(_0xe5cbd4,null))['catch'](handleError(_0xe5cbd4,null));};exports[_0x5eb4('0x62')]=function(_0x5cd6f4,_0x4a1df8,_0x426316){var _0x343c57={'raw':![],'where':{}};var _0x5e2d29={};var _0x554d9d={'count':0x0,'rows':[]};return db[_0x5eb4('0x4f')][_0x5eb4('0x63')]({'where':{'id':_0x5cd6f4[_0x5eb4('0x54')]['id']}})[_0x5eb4('0x1c')](handleEntityNotFound(_0x4a1df8,null))[_0x5eb4('0x1c')](function(_0x3144e0){if(_0x3144e0){_0x5e2d29[_0x5eb4('0x41')]=_[_0x5eb4('0x43')](db[_0x5eb4('0x64')]['rawAttributes']);_0x5e2d29[_0x5eb4('0x42')]=_[_0x5eb4('0x43')](_0x5cd6f4['query']);_0x5e2d29[_0x5eb4('0x44')]=_['intersection'](_0x5e2d29['model'],_0x5e2d29[_0x5eb4('0x42')]);_0x343c57[_0x5eb4('0x45')]=_[_0x5eb4('0x46')](_0x5e2d29[_0x5eb4('0x41')],qs[_0x5eb4('0x55')](_0x5cd6f4[_0x5eb4('0x42')][_0x5eb4('0x55')]));_0x343c57[_0x5eb4('0x45')]=_0x343c57[_0x5eb4('0x45')][_0x5eb4('0x47')]?_0x343c57[_0x5eb4('0x45')]:_0x5e2d29[_0x5eb4('0x41')];if(!_0x5cd6f4[_0x5eb4('0x42')][_0x5eb4('0x48')]('nolimit')){_0x343c57[_0x5eb4('0x2b')]=qs[_0x5eb4('0x2b')](_0x5cd6f4[_0x5eb4('0x42')][_0x5eb4('0x2b')]);_0x343c57[_0x5eb4('0x2e')]=qs[_0x5eb4('0x2e')](_0x5cd6f4[_0x5eb4('0x42')][_0x5eb4('0x2e')]);}_0x343c57[_0x5eb4('0x65')]=qs['sort'](_0x5cd6f4[_0x5eb4('0x42')]['sort']);_0x343c57[_0x5eb4('0x4a')]=qs['filters'](_[_0x5eb4('0x4b')](_0x5cd6f4[_0x5eb4('0x42')],_0x5e2d29[_0x5eb4('0x44')]));_0x343c57[_0x5eb4('0x4a')][_0x5eb4('0x61')]=_0x3144e0['id'];if(_0x5cd6f4[_0x5eb4('0x42')]['filter']){_0x343c57[_0x5eb4('0x4a')]=_[_0x5eb4('0x4c')](_0x343c57[_0x5eb4('0x4a')],{'$or':_['map'](_0x343c57[_0x5eb4('0x45')],function(_0x9cad79){var _0x5b7fcf={};_0x5b7fcf[_0x9cad79]={'$like':'%'+_0x5cd6f4['query'][_0x5eb4('0x4e')]+'%'};return _0x5b7fcf;})});}_0x343c57=_[_0x5eb4('0x4c')]({},_0x343c57,_0x5cd6f4[_0x5eb4('0x56')]);return db[_0x5eb4('0x64')][_0x5eb4('0x2d')]({'where':_0x343c57['where']})[_0x5eb4('0x1c')](function(_0x3d891a){_0x554d9d['count']=_0x3d891a;if(_0x5cd6f4[_0x5eb4('0x42')][_0x5eb4('0x50')]){_0x343c57[_0x5eb4('0x51')]=[{'all':!![]}];}return db[_0x5eb4('0x64')][_0x5eb4('0x66')](_0x343c57);})['then'](function(_0x3d0c19){_0x554d9d['rows']=_0x3d0c19;return _0x554d9d;});}})['then'](respondWithFilteredResult(_0x4a1df8,_0x343c57))[_0x5eb4('0x26')](handleError(_0x4a1df8,null));};exports['removeDispositions']=function(_0x4a2323,_0x170c59,_0x45034c){return db[_0x5eb4('0x4f')]['find']({'where':{'id':_0x4a2323[_0x5eb4('0x54')]['id']}})['then'](handleEntityNotFound(_0x170c59,null))[_0x5eb4('0x1c')](function(_0x4a644f){if(_0x4a644f){return _0x4a644f[_0x5eb4('0x67')](_0x4a2323[_0x5eb4('0x42')][_0x5eb4('0x68')]);}})['then'](respondWithStatusCode(_0x170c59,null))[_0x5eb4('0x26')](handleError(_0x170c59,null));};exports[_0x5eb4('0x69')]=function(_0x454e5c,_0x26060c,_0x3c3e18){if(_0x454e5c[_0x5eb4('0x5d')]['id']){delete _0x454e5c[_0x5eb4('0x5d')]['id'];}return db['SmsAccount'][_0x5eb4('0x5e')]({'where':{'id':_0x454e5c['params']['id']}})[_0x5eb4('0x1c')](handleEntityNotFound(_0x26060c,null))[_0x5eb4('0x1c')](function(_0xa9fb69){if(_0xa9fb69){_0x454e5c[_0x5eb4('0x5d')][_0x5eb4('0x61')]=_0xa9fb69['id'];return db[_0x5eb4('0x6a')][_0x5eb4('0x57')](_0x454e5c[_0x5eb4('0x5d')]);}})[_0x5eb4('0x1c')](respondWithResult(_0x26060c,null))[_0x5eb4('0x26')](handleError(_0x26060c,null));};exports['getAnswers']=function(_0x209c39,_0x506097,_0x15ef73){var _0x285848={'raw':![],'where':{}};var _0x24ad00={};var _0x226f17={'count':0x0,'rows':[]};return db[_0x5eb4('0x4f')][_0x5eb4('0x63')]({'where':{'id':_0x209c39[_0x5eb4('0x54')]['id']}})[_0x5eb4('0x1c')](handleEntityNotFound(_0x506097,null))[_0x5eb4('0x1c')](function(_0x16df61){if(_0x16df61){_0x24ad00[_0x5eb4('0x41')]=_[_0x5eb4('0x43')](db[_0x5eb4('0x6a')][_0x5eb4('0x3d')]);_0x24ad00[_0x5eb4('0x42')]=_[_0x5eb4('0x43')](_0x209c39['query']);_0x24ad00[_0x5eb4('0x44')]=_[_0x5eb4('0x46')](_0x24ad00[_0x5eb4('0x41')],_0x24ad00[_0x5eb4('0x42')]);_0x285848[_0x5eb4('0x45')]=_[_0x5eb4('0x46')](_0x24ad00[_0x5eb4('0x41')],qs[_0x5eb4('0x55')](_0x209c39['query'][_0x5eb4('0x55')]));_0x285848[_0x5eb4('0x45')]=_0x285848[_0x5eb4('0x45')][_0x5eb4('0x47')]?_0x285848[_0x5eb4('0x45')]:_0x24ad00[_0x5eb4('0x41')];if(!_0x209c39[_0x5eb4('0x42')][_0x5eb4('0x48')]('nolimit')){_0x285848[_0x5eb4('0x2b')]=qs[_0x5eb4('0x2b')](_0x209c39[_0x5eb4('0x42')][_0x5eb4('0x2b')]);_0x285848[_0x5eb4('0x2e')]=qs[_0x5eb4('0x2e')](_0x209c39[_0x5eb4('0x42')]['offset']);}_0x285848[_0x5eb4('0x65')]=qs[_0x5eb4('0x49')](_0x209c39[_0x5eb4('0x42')][_0x5eb4('0x49')]);_0x285848['where']=qs[_0x5eb4('0x44')](_['pick'](_0x209c39[_0x5eb4('0x42')],_0x24ad00['filters']));_0x285848[_0x5eb4('0x4a')]['SmsAccountId']=_0x16df61['id'];if(_0x209c39[_0x5eb4('0x42')]['filter']){_0x285848['where']=_[_0x5eb4('0x4c')](_0x285848[_0x5eb4('0x4a')],{'$or':_[_0x5eb4('0x3c')](_0x285848[_0x5eb4('0x45')],function(_0x994737){var _0xff8392={};_0xff8392[_0x994737]={'$like':'%'+_0x209c39[_0x5eb4('0x42')][_0x5eb4('0x4e')]+'%'};return _0xff8392;})});}_0x285848=_[_0x5eb4('0x4c')]({},_0x285848,_0x209c39['options']);return db[_0x5eb4('0x6a')][_0x5eb4('0x2d')]({'where':_0x285848[_0x5eb4('0x4a')]})[_0x5eb4('0x1c')](function(_0x5985a4){_0x226f17[_0x5eb4('0x2d')]=_0x5985a4;if(_0x209c39['query'][_0x5eb4('0x50')]){_0x285848[_0x5eb4('0x51')]=[{'all':!![]}];}return db[_0x5eb4('0x6a')][_0x5eb4('0x66')](_0x285848);})[_0x5eb4('0x1c')](function(_0x59dfd1){_0x226f17[_0x5eb4('0x52')]=_0x59dfd1;return _0x226f17;});}})[_0x5eb4('0x1c')](respondWithFilteredResult(_0x506097,_0x285848))['catch'](handleError(_0x506097,null));};exports['removeAnswers']=function(_0x38e1da,_0x56f35d,_0x2c8d9b){return db[_0x5eb4('0x4f')][_0x5eb4('0x5e')]({'where':{'id':_0x38e1da['params']['id']}})[_0x5eb4('0x1c')](handleEntityNotFound(_0x56f35d,null))[_0x5eb4('0x1c')](function(_0x3333ab){if(_0x3333ab){return _0x3333ab[_0x5eb4('0x6b')](_0x38e1da[_0x5eb4('0x42')][_0x5eb4('0x68')]);}})[_0x5eb4('0x1c')](respondWithStatusCode(_0x56f35d,null))[_0x5eb4('0x26')](handleError(_0x56f35d,null));};exports['notify']=function(_0x310d90,_0x258130,_0x13cac2){var _0x510c6c={'channel':_0x5eb4('0x6c')};var _0x13bc4c=[];var _0x38a108=[];var _0x4cb719={};return db['SmsAccount'][_0x5eb4('0x5e')]({'where':{'id':_0x310d90[_0x5eb4('0x54')]['id']},'include':[{'model':db['SmsApplication'],'as':'Applications'}]})[_0x5eb4('0x1c')](handleEntityNotFound(_0x258130,null))[_0x5eb4('0x1c')](function(_0x54e5d2){_0x510c6c[_0x5eb4('0x6d')]=_0x54e5d2;_0x510c6c[_0x5eb4('0x6e')]=_[_0x5eb4('0x6f')](_0x54e5d2[_0x5eb4('0x70')],['priority'],[_0x5eb4('0x71')]);if(_0x510c6c[_0x5eb4('0x6d')][_0x5eb4('0x70')]){delete _0x510c6c[_0x5eb4('0x6d')]['Applications'];}return db['CmContact']['describe']();})[_0x5eb4('0x1c')](function(_0x46fec2){if(!_0x46fec2){throw new db[(_0x5eb4('0x72'))][(_0x5eb4('0x73'))](_0x5eb4('0x74'));}_0x13bc4c=_[_0x5eb4('0x75')](_[_0x5eb4('0x43')](_0x46fec2),[_0x5eb4('0x76'),_0x5eb4('0x77')]);_0x38a108=_[_0x5eb4('0x75')](_[_0x5eb4('0x43')](_0x46fec2),[_0x5eb4('0x76'),_0x5eb4('0x77'),'CompanyId',_0x5eb4('0x78')]);_0x510c6c[_0x5eb4('0x5d')]={'mapKey':'mobile'};if(_0x510c6c[_0x5eb4('0x6d')][_0x5eb4('0x3f')]){switch(_0x510c6c[_0x5eb4('0x6d')]['type']){case'twilio':_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x79')]=_0x310d90[_0x5eb4('0x5d')][_0x5eb4('0x7a')];_0x510c6c['body'][_0x5eb4('0x5d')]=_0x310d90[_0x5eb4('0x5d')][_0x5eb4('0x7b')];_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x7c')]=_0x310d90[_0x5eb4('0x5d')][_0x5eb4('0x7d')];break;case _0x5eb4('0x7e'):_0x510c6c['body'][_0x5eb4('0x79')]='+'+_0x310d90[_0x5eb4('0x5d')][_0x5eb4('0x7f')];_0x510c6c['body'][_0x5eb4('0x5d')]=_0x310d90[_0x5eb4('0x5d')][_0x5eb4('0x80')];break;case _0x5eb4('0x81'):_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x79')]=_0x310d90[_0x5eb4('0x5d')][_0x5eb4('0x79')];_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x5d')]=_0x310d90[_0x5eb4('0x5d')]['message'];break;case _0x5eb4('0x82'):_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x79')]=_0x310d90[_0x5eb4('0x5d')][_0x5eb4('0x79')];_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x5d')]=_0x310d90['body'][_0x5eb4('0x5d')];_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x7c')]=_0x310d90[_0x5eb4('0x5d')][_0x5eb4('0x83')];break;case _0x5eb4('0x84'):_0x510c6c['body'][_0x5eb4('0x79')]=_0x310d90[_0x5eb4('0x5d')][_0x5eb4('0x7a')];_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x5d')]=_0x310d90['body'][_0x5eb4('0x85')];_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x7c')]=_0x310d90['body'][_0x5eb4('0x86')];break;case _0x5eb4('0x87'):_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x79')]='+'+_0x310d90['body'][_0x5eb4('0x88')][0x0]['from'];_0x510c6c['body'][_0x5eb4('0x5d')]=_0x310d90[_0x5eb4('0x5d')][_0x5eb4('0x88')][0x0][_0x5eb4('0x80')];_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x7c')]=_0x310d90[_0x5eb4('0x5d')]['results'][0x0]['messageId'];break;case _0x5eb4('0x89'):_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x79')]=_0x310d90[_0x5eb4('0x5d')][_0x5eb4('0x8a')];_0x510c6c['body']['body']=_0x310d90[_0x5eb4('0x5d')][_0x5eb4('0x8b')][_0x5eb4('0x24')];break;case _0x5eb4('0x8c'):_0x510c6c['body']['from']=_0x310d90['body'][_0x5eb4('0x8d')];_0x510c6c[_0x5eb4('0x5d')]['body']=_0x310d90[_0x5eb4('0x5d')][_0x5eb4('0x80')];_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x7c')]=_0x310d90[_0x5eb4('0x5d')]['replyMessageId'];break;case'bandwidth':_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x7c')]=_0x310d90[_0x5eb4('0x5d')][0x0][_0x5eb4('0x24')]['id'];_0x510c6c[_0x5eb4('0x5d')]['from']=_0x310d90[_0x5eb4('0x5d')][0x0]['message'][_0x5eb4('0x79')];_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x5d')]=_0x310d90['body'][0x0][_0x5eb4('0x24')]['text'];break;case _0x5eb4('0x8e'):_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x79')]=_0x310d90[_0x5eb4('0x5d')][_0x5eb4('0x79')];_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x5d')]=_0x310d90['body'][_0x5eb4('0x24')];_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x7c')]=_0x310d90[_0x5eb4('0x5d')]['refid'];break;}}if(_0x510c6c[_0x5eb4('0x5d')]['id']){delete _0x510c6c[_0x5eb4('0x5d')]['id'];}if(_[_0x5eb4('0x8f')](_0x510c6c['body']['from'])){throw new db[(_0x5eb4('0x72'))]['ValidationError'](_0x5eb4('0x90'));}if(_[_0x5eb4('0x8f')](_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x5d')])||_0x510c6c['body'][_0x5eb4('0x5d')]===''){throw new db[(_0x5eb4('0x72'))][(_0x5eb4('0x73'))](_0x5eb4('0x91'));}if(_[_0x5eb4('0x8f')](_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x92')])){throw new db[(_0x5eb4('0x72'))][(_0x5eb4('0x73'))](_0x5eb4('0x93')+_0x38a108);}if(!_[_0x5eb4('0x94')](_0x38a108,_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x92')])){throw new db[(_0x5eb4('0x72'))]['ValidationError']('mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x38a108);}_0x4cb719[_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x92')]]=_0x510c6c['body'][_0x5eb4('0x79')];return db[_0x5eb4('0x95')][_0x5eb4('0x5e')]({'where':{'id':_0x510c6c[_0x5eb4('0x6d')]['ListId']},'include':[{'model':db[_0x5eb4('0x96')],'as':'Contacts','where':_0x4cb719,'limit':0x1,'order':[['updatedAt',_0x5eb4('0x97')]]}]});})[_0x5eb4('0x1c')](handleEntityNotFound(_0x258130,null))[_0x5eb4('0x1c')](function(_0x155cd5){if(_0x155cd5){_0x510c6c[_0x5eb4('0x98')]=_[_0x5eb4('0x99')](_0x155cd5,[_0x5eb4('0x9a')]);if(_0x155cd5['Contacts'][_0x5eb4('0x47')]){return _0x155cd5[_0x5eb4('0x9a')][0x0];}var _0x16ca4c=_[_0x5eb4('0x15')](_0x510c6c[_0x5eb4('0x5d')],{'firstName':_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x79')],'ListId':_0x155cd5['id']});_0x16ca4c[_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x92')]]=_0x510c6c[_0x5eb4('0x5d')]['from'];return db['CmContact'][_0x5eb4('0x57')](_0x16ca4c,{'fields':_0x13bc4c,'raw':!![]});}})[_0x5eb4('0x1c')](handleEntityNotFound(_0x258130,null))['then'](function(_0x4378d7){if(_0x4378d7){_0x510c6c[_0x5eb4('0x9b')]=_0x4378d7;var _0x10cdf5={'ContactId':_0x4378d7['id'],'phone':_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x79')],'SmsAccountId':_0x310d90[_0x5eb4('0x54')]['id']};var _0x586a66={'ContactId':_0x4378d7['id'],'SmsAccountId':_0x310d90[_0x5eb4('0x54')]['id'],'closed':![]};return db[_0x5eb4('0x9c')][_0x5eb4('0x5e')]({'where':_0x586a66})[_0x5eb4('0x1c')](function(_0x22b447){if(_0x22b447){return[_0x22b447,![]];}return db['SmsInteraction'][_0x5eb4('0x57')](_0x10cdf5)[_0x5eb4('0x1c')](function(_0x33d164){return[_0x33d164,!![]];});});}})[_0x5eb4('0x9d')](function(_0x36adff,_0x59483e){_0x510c6c[_0x5eb4('0x9e')]=_0x36adff['get']({'plain':!![]});_0x510c6c[_0x5eb4('0x9e')][_0x5eb4('0x9f')]=![];if(_0x59483e){if(_0x510c6c['account'][_0x5eb4('0xa0')]){_0x510c6c[_0x5eb4('0x6e')][_0x5eb4('0xa1')]({'id':0x0,'priority':_0x510c6c['applications']['length']+0x1,'app':'close','appdata':_0x5eb4('0xa2'),'interval':_0x5eb4('0xa3')});}_0x510c6c[_0x5eb4('0x9e')]['created']=!![];}return db[_0x5eb4('0xa4')][_0x5eb4('0x57')]({'phone':_0x510c6c['body'][_0x5eb4('0x79')],'messageId':_0x510c6c[_0x5eb4('0x5d')]['messageId'],'body':_0x510c6c[_0x5eb4('0x5d')][_0x5eb4('0x5d')],'SmsAccountId':_0x310d90['params']['id'],'SmsInteractionId':_0x36adff['id'],'direction':'in','ContactId':_0x36adff[_0x5eb4('0xa5')],'AttachmentId':_0x510c6c['body']['AttachmentId']});})['then'](function(_0x14affd){_0x510c6c[_0x5eb4('0x24')]=_0x14affd;if(_0x510c6c[_0x5eb4('0x9e')][_0x5eb4('0xa6')]){return db['User'][_0x5eb4('0x5e')]({'attributes':['id',_0x5eb4('0x39')],'where':{'id':_0x510c6c[_0x5eb4('0x9e')]['UserId']}})[_0x5eb4('0x1c')](function(_0x174b53){if(_0x174b53){_0x510c6c['applications'][_0x5eb4('0xa7')]({'id':0x0,'priority':0x0,'app':'agent','appdata':_0x174b53[_0x5eb4('0x39')]+','+(_0x510c6c[_0x5eb4('0x6d')][_0x5eb4('0xa8')]||0xa),'interval':_0x5eb4('0xa3')});}return respondWithRpcPromise(_0x5eb4('0xa9'),_0x5eb4('0xaa'),_0x510c6c);});}return respondWithRpcPromise(_0x5eb4('0xa9'),_0x5eb4('0xaa'),_0x510c6c);})[_0x5eb4('0x1c')](function(_0x2ab94b){if(_0x2ab94b){var _0x30c4e4=0xc8;var _0x1159b0='receiveMessage';logger['info'](_0x5eb4('0xab'),_0x1159b0,_0x30c4e4,_0x5eb4('0xac'));logger[_0x5eb4('0x20')](_0x5eb4('0xad'),_0x1159b0,_0x30c4e4,'entity\x20found',JSON[_0x5eb4('0x21')](_0x2ab94b));if(_0x510c6c[_0x5eb4('0x6d')][_0x5eb4('0x3f')]===_0x5eb4('0xae')){return _0x258130[_0x5eb4('0x28')](_0x30c4e4)[_0x5eb4('0xaf')](_0x5eb4('0xb0'),'text/xml')[_0x5eb4('0xb1')](_0x5eb4('0xb2'));}else{return _0x258130[_0x5eb4('0x28')](_0x30c4e4)[_0x5eb4('0x2a')](_0x2ab94b);}}})[_0x5eb4('0x26')](handleError(_0x258130,null));};exports[_0x5eb4('0xb3')]=function(_0x59802e,_0x5d07c5){var _0x3312d9=_0x59802e[_0x5eb4('0x54')]['id'];var _0xdde899=_0x59802e[_0x5eb4('0x5d')];var _0xf60907=0xc8;var _0x351b0f=null;return db[_0x5eb4('0xb4')]['transaction']({'isolationLevel':db[_0x5eb4('0xb4')][_0x5eb4('0xb5')]['ISOLATION_LEVELS']['READ_COMMITTED']},function(_0x4b3b8c){return db[_0x5eb4('0x4f')]['findOne']({'where':{'id':_0x3312d9},'transaction':_0x4b3b8c})['then'](function(_0x99bce2){if(_0x99bce2){return db[_0x5eb4('0xb6')][_0x5eb4('0x37')]({'where':{'SmsAccountId':_0x3312d9},'transaction':_0x4b3b8c})[_0x5eb4('0x1c')](function(){var _0x14ef5b=_['map'](_0xdde899,function(_0xa822d8){_0xa822d8[_0x5eb4('0x61')]=_0x3312d9;return _0xa822d8;});return db[_0x5eb4('0xb6')][_0x5eb4('0xb7')](_0x14ef5b,{'transaction':_0x4b3b8c});});}else{_0xf60907=0x194;_0x351b0f=[];}});})[_0x5eb4('0x1c')](function(){if(_0xf60907!==0x194){return db[_0x5eb4('0xb6')][_0x5eb4('0xb8')]({'where':{'SmsAccountId':_0x3312d9},'order':_0x5eb4('0xb9')})[_0x5eb4('0x1c')](function(_0x14c150){_0x351b0f=_0x14c150;});}})[_0x5eb4('0x26')](function(_0x5a7988){_0xf60907=0x1f4;logger['error'](_0x5a7988[_0x5eb4('0x38')]);if(_0x5a7988[_0x5eb4('0x39')]){delete _0x5a7988[_0x5eb4('0x39')];}_0x351b0f=_0x5a7988;})['finally'](function(){if(_0x351b0f===null){_0x5d07c5[_0x5eb4('0x27')](_0xf60907);}else{if(_0xf60907===0x1f4){_0x5d07c5[_0x5eb4('0x28')](_0xf60907)[_0x5eb4('0xb1')](_0x351b0f);}else{_0x5d07c5[_0x5eb4('0x28')](_0xf60907)[_0x5eb4('0x2a')](_0x351b0f);}}});};exports[_0x5eb4('0xba')]=function(_0x1c2c55,_0x16413b,_0x1cfd6e){var _0x3dfe9d={};var _0xf81a43={};var _0x45909c;var _0x18e074;return db[_0x5eb4('0x4f')][_0x5eb4('0x63')]({'where':{'id':_0x1c2c55[_0x5eb4('0x54')]['id']}})[_0x5eb4('0x1c')](handleEntityNotFound(_0x16413b,null))[_0x5eb4('0x1c')](function(_0x5f0eb8){if(_0x5f0eb8){_0x45909c=_0x5f0eb8;_0xf81a43['model']=_[_0x5eb4('0x43')](db[_0x5eb4('0xb6')]['rawAttributes']);_0xf81a43['query']=_[_0x5eb4('0x43')](_0x1c2c55[_0x5eb4('0x42')]);_0xf81a43[_0x5eb4('0x44')]=_[_0x5eb4('0x46')](_0xf81a43['model'],_0xf81a43[_0x5eb4('0x42')]);_0x3dfe9d['attributes']=_[_0x5eb4('0x46')](_0xf81a43[_0x5eb4('0x41')],qs[_0x5eb4('0x55')](_0x1c2c55[_0x5eb4('0x42')][_0x5eb4('0x55')]));_0x3dfe9d[_0x5eb4('0x45')]=_0x3dfe9d[_0x5eb4('0x45')][_0x5eb4('0x47')]?_0x3dfe9d[_0x5eb4('0x45')]:_0xf81a43['model'];_0x3dfe9d['order']=qs[_0x5eb4('0x49')](_0x1c2c55[_0x5eb4('0x42')][_0x5eb4('0x49')]);_0x3dfe9d[_0x5eb4('0x4a')]=qs[_0x5eb4('0x44')](_[_0x5eb4('0x4b')](_0x1c2c55['query'],_0xf81a43[_0x5eb4('0x44')]));if(_0x1c2c55[_0x5eb4('0x42')][_0x5eb4('0x4e')]){_0x3dfe9d[_0x5eb4('0x4a')]=_['merge'](_0x3dfe9d[_0x5eb4('0x4a')],{'$or':_[_0x5eb4('0x3c')](_0x3dfe9d[_0x5eb4('0x45')],function(_0x38ad9a){var _0x1eb0c8={};_0x1eb0c8[_0x38ad9a]={'$like':'%'+_0x1c2c55['query'][_0x5eb4('0x4e')]+'%'};return _0x1eb0c8;})});}_0x3dfe9d=_['merge']({},_0x3dfe9d,_0x1c2c55['options']);return _0x45909c[_0x5eb4('0xba')](_0x3dfe9d);}})[_0x5eb4('0x1c')](function(_0x5aad46){if(_0x5aad46){_0x18e074=_0x5aad46[_0x5eb4('0x47')];if(!_0x1c2c55[_0x5eb4('0x42')][_0x5eb4('0x48')](_0x5eb4('0xbb'))){_0x3dfe9d[_0x5eb4('0x2b')]=qs[_0x5eb4('0x2b')](_0x1c2c55['query'][_0x5eb4('0x2b')]);_0x3dfe9d[_0x5eb4('0x2e')]=qs[_0x5eb4('0x2e')](_0x1c2c55[_0x5eb4('0x42')][_0x5eb4('0x2e')]);}return _0x45909c[_0x5eb4('0xba')](_0x3dfe9d);}})[_0x5eb4('0x1c')](function(_0x1d80e5){if(_0x1d80e5){return _0x1d80e5?{'count':_0x18e074,'rows':_0x1d80e5}:null;}})['then'](respondWithResult(_0x16413b,null))[_0x5eb4('0x26')](handleError(_0x16413b,null));};exports[_0x5eb4('0xbc')]=function(_0x370d88,_0xe988c,_0x4ccae9){var _0x522bab={'raw':![],'where':{}};var _0x2e0b57={};var _0x188d18={'count':0x0,'rows':[]};return db['SmsAccount'][_0x5eb4('0x63')]({'where':{'id':_0x370d88[_0x5eb4('0x54')]['id']}})[_0x5eb4('0x1c')](handleEntityNotFound(_0xe988c,null))[_0x5eb4('0x1c')](function(_0x58a951){if(_0x58a951){_0x2e0b57[_0x5eb4('0x41')]=_[_0x5eb4('0x43')](db[_0x5eb4('0x9c')]['rawAttributes']);_0x2e0b57['query']=_['keys'](_0x370d88['query']);_0x2e0b57['filters']=_[_0x5eb4('0x46')](_0x2e0b57[_0x5eb4('0x41')],_0x2e0b57['query']);_0x522bab['attributes']=_['intersection'](_0x2e0b57[_0x5eb4('0x41')],qs[_0x5eb4('0x55')](_0x370d88[_0x5eb4('0x42')][_0x5eb4('0x55')]));_0x522bab[_0x5eb4('0x45')]=_0x522bab[_0x5eb4('0x45')][_0x5eb4('0x47')]?_0x522bab[_0x5eb4('0x45')]:_0x2e0b57['model'];if(!_0x370d88[_0x5eb4('0x42')]['hasOwnProperty']('nolimit')){_0x522bab[_0x5eb4('0x2b')]=qs[_0x5eb4('0x2b')](_0x370d88[_0x5eb4('0x42')][_0x5eb4('0x2b')]);_0x522bab[_0x5eb4('0x2e')]=qs['offset'](_0x370d88[_0x5eb4('0x42')][_0x5eb4('0x2e')]);}_0x522bab[_0x5eb4('0x65')]=qs[_0x5eb4('0x49')](_0x370d88['query'][_0x5eb4('0x49')]);_0x522bab[_0x5eb4('0x4a')]=qs['filters'](_['pick'](_0x370d88[_0x5eb4('0x42')],_0x2e0b57['filters']));_0x522bab[_0x5eb4('0x4a')][_0x5eb4('0x61')]=_0x58a951['id'];if(_0x370d88[_0x5eb4('0x42')]['filter']){_0x522bab[_0x5eb4('0x4a')]=_[_0x5eb4('0x4c')](_0x522bab[_0x5eb4('0x4a')],{'$or':_[_0x5eb4('0x3c')](_0x522bab[_0x5eb4('0x45')],function(_0x3f0b49){var _0x5c04b9={};_0x5c04b9[_0x3f0b49]={'$like':'%'+_0x370d88['query'][_0x5eb4('0x4e')]+'%'};return _0x5c04b9;})});}_0x522bab=_[_0x5eb4('0x4c')]({},_0x522bab,_0x370d88[_0x5eb4('0x56')]);return db[_0x5eb4('0x9c')][_0x5eb4('0x2d')]({'where':_0x522bab[_0x5eb4('0x4a')]})[_0x5eb4('0x1c')](function(_0x355085){_0x188d18[_0x5eb4('0x2d')]=_0x355085;if(_0x370d88[_0x5eb4('0x42')][_0x5eb4('0x50')]){_0x522bab['include']=[{'model':db[_0x5eb4('0x96')],'as':_0x5eb4('0xbd'),'required':![]},{'model':db[_0x5eb4('0xbe')],'as':_0x5eb4('0xbf'),'attributes':[_0x5eb4('0x39'),'fullname','internal'],'required':![]},{'model':db[_0x5eb4('0xc0')],'as':_0x5eb4('0xc1'),'attributes':['id',_0x5eb4('0x39'),'color'],'where':_0x370d88[_0x5eb4('0x42')]['tag']?{'id':_0x370d88[_0x5eb4('0x42')][_0x5eb4('0xc2')]}:undefined,'required':_0x370d88[_0x5eb4('0x42')][_0x5eb4('0xc2')]?!![]:![]}];}return db['SmsInteraction'][_0x5eb4('0x66')](_0x522bab);})['then'](function(_0x142b00){_0x188d18[_0x5eb4('0x52')]=_0x142b00;return _0x188d18;});}})[_0x5eb4('0x1c')](respondWithFilteredResult(_0xe988c,_0x522bab))['catch'](handleError(_0xe988c,null));};exports[_0x5eb4('0xb1')]=function(_0x3c2668,_0x258d11,_0x2dee31){var _0x17db79,_0x1113c5,_0x2e7212;if(_[_0x5eb4('0x8f')](_0x3c2668[_0x5eb4('0x5d')][_0x5eb4('0x5d')])||_0x3c2668[_0x5eb4('0x5d')]['body']===''){throw new db['Sequelize'][(_0x5eb4('0x73'))](_0x5eb4('0x91'));}if(_['isNil'](_0x3c2668[_0x5eb4('0x5d')]['to'])){throw new db[(_0x5eb4('0x72'))][(_0x5eb4('0x73'))](_0x5eb4('0xc3'));}_0x17db79=_0x3c2668[_0x5eb4('0x5d')]['to'];return db[_0x5eb4('0x4f')][_0x5eb4('0x5e')]({'where':{'id':_0x3c2668[_0x5eb4('0x54')]['id']},'include':[{'model':db[_0x5eb4('0x95')],'as':_0x5eb4('0xc4'),'include':[{'model':db[_0x5eb4('0x96')],'as':'Contacts','where':{'mobile':_0x17db79},'limit':0x1,'order':[[_0x5eb4('0x77'),_0x5eb4('0x97')]]}]}]})[_0x5eb4('0x1c')](handleEntityNotFound(_0x258d11,null))[_0x5eb4('0x1c')](function(_0x359e94){if(_0x359e94&&_0x359e94[_0x5eb4('0xc4')]){_0x1113c5=_0x359e94[_0x5eb4('0x34')]({'plain':!![]});if(_0x1113c5[_0x5eb4('0xc4')]&&_0x1113c5[_0x5eb4('0xc4')][_0x5eb4('0x9a')]['length']){return _0x1113c5[_0x5eb4('0xc4')][_0x5eb4('0x9a')][0x0];}return db[_0x5eb4('0x96')][_0x5eb4('0x57')](_[_0x5eb4('0x15')](_0x3c2668[_0x5eb4('0x5d')],{'firstName':_0x17db79,'mobile':_0x17db79,'phone':_0x17db79,'ListId':_0x1113c5[_0x5eb4('0x78')]}));}})['then'](handleEntityNotFound(_0x258d11,null))[_0x5eb4('0x1c')](function(_0x3a6a1f){if(_0x3a6a1f){_0x2e7212=_0x3a6a1f;return db[_0x5eb4('0x9c')][_0x5eb4('0x5e')]({'where':{'ContactId':_0x2e7212['id'],'closed':![],'SmsAccountId':_0x1113c5['id']}})[_0x5eb4('0x1c')](function(_0x288a3e){if(_0x288a3e){return[_0x288a3e,![]];}return db[_0x5eb4('0x9c')][_0x5eb4('0x57')]({'UserId':_0x3c2668['user']['id'],'ContactId':_0x2e7212['id'],'SmsAccountId':_0x1113c5['id'],'phone':_0x17db79,'firstMsgDirection':_0x5eb4('0xc5'),'Messages':[_[_0x5eb4('0x4c')](_0x3c2668['body'],{'read':![],'body':_0x3c2668[_0x5eb4('0x5d')][_0x5eb4('0x5d')],'phone':_0x17db79,'SmsAccountId':_0x1113c5['id'],'UserId':_0x3c2668[_0x5eb4('0x58')]['id'],'ContactId':_0x2e7212['id']})]},{'include':[{'model':db[_0x5eb4('0xa4')],'as':'Messages'}]})['then'](function(_0x3647d6){return[_0x3647d6,!![]];});});}})[_0x5eb4('0x9d')](function(_0x2abe2a,_0x5382e4){if(_0x5382e4){return _0x2abe2a;}return db['SmsMessage']['create'](_[_0x5eb4('0x4c')](_0x3c2668[_0x5eb4('0x5d')],{'read':![],'body':_0x3c2668[_0x5eb4('0x5d')][_0x5eb4('0x5d')],'phone':_0x17db79,'SmsAccountId':_0x1113c5['id'],'SmsInteractionId':_0x2abe2a['id'],'UserId':_0x3c2668['user']['id'],'ContactId':_0x2e7212['id']}))['then'](function(_0x5bebd0){_0x2abe2a[_0x5eb4('0xc6')][_0x5eb4('0xc7')]=[];_0x2abe2a[_0x5eb4('0xc6')]['Messages'][_0x5eb4('0xa1')](_0x5bebd0[_0x5eb4('0xc6')]);return _0x2abe2a;});})[_0x5eb4('0x1c')](respondWithResult(_0x258d11,null))[_0x5eb4('0x26')](handleError(_0x258d11,null));};exports['status']=function(_0x3ccbd9,_0xef6c11,_0xf02862){if(_0x3ccbd9['body']['id']){delete _0x3ccbd9['body']['id'];}var _0x404920,_0x1f145d,_0x194fee;return db[_0x5eb4('0x4f')]['find']({'where':{'id':_0x3ccbd9[_0x5eb4('0x54')]['id']}})[_0x5eb4('0x1c')](handleEntityNotFound(_0xef6c11,null))[_0x5eb4('0x1c')](function(_0x5ecf99){if(_0x5ecf99){_0x194fee=_0x5ecf99;logger[_0x5eb4('0x20')](_0x5eb4('0xab'),_0x5eb4('0x28'),_0x5eb4('0xc8'),_0x5ecf99[_0x5eb4('0x3f')],util[_0x5eb4('0xc9')](_0x3ccbd9[_0x5eb4('0x5d')],{'showHidden':![],'depth':null}));switch(_0x5ecf99[_0x5eb4('0x3f')]){case _0x5eb4('0x7e'):if(_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0xca')]&&_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0x28')]){_0x1f145d=_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0x28')];return db[_0x5eb4('0xa4')][_0x5eb4('0x5e')]({'where':{'messageId':_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0xca')]}});}break;case _0x5eb4('0x81'):if(_0x3ccbd9['body'][_0x5eb4('0xcb')]&&_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0xcc')]){_0x1f145d=_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0xcc')];return db[_0x5eb4('0xa4')][_0x5eb4('0x5e')]({'where':{'messageId':_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0xcb')]}});}break;case'clicksend':if(_0x3ccbd9['body']['message_id']&&_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0xcd')]){_0x1f145d=_0x3ccbd9['body'][_0x5eb4('0xcd')];return db[_0x5eb4('0xa4')][_0x5eb4('0x5e')]({'where':{'messageId':_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0x83')]}});}break;case'infobip':var _0x32ea00=_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0x88')][0x0];if(_0x32ea00['messageId']&&_0x32ea00[_0x5eb4('0x28')][_0x5eb4('0xce')]===_0x5eb4('0xcf')){_0x1f145d=_0x32ea00['status'][_0x5eb4('0xce')];return db['SmsMessage'][_0x5eb4('0x5e')]({'where':{'messageId':_0x32ea00[_0x5eb4('0x7c')]}});}break;case _0x5eb4('0x8c'):if(_0x3ccbd9[_0x5eb4('0x5d')]['messageId']&&_0x3ccbd9['body']['status']){_0x1f145d=_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0x28')];return db[_0x5eb4('0xa4')][_0x5eb4('0x5e')]({'where':{'messageId':_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0x7c')]}});}break;case _0x5eb4('0xd0'):if(_0x3ccbd9[_0x5eb4('0x5d')][0x0][_0x5eb4('0x24')]['id']){_0x1f145d=_0x3ccbd9[_0x5eb4('0x5d')][0x0][_0x5eb4('0x3f')];return db[_0x5eb4('0xa4')][_0x5eb4('0x5e')]({'where':{'messageId':_0x3ccbd9[_0x5eb4('0x5d')][0x0]['message']['id']}});}break;case _0x5eb4('0x8e'):if(_0x3ccbd9['body'][_0x5eb4('0xd1')]&&_0x3ccbd9[_0x5eb4('0x5d')]['status']){_0x1f145d=_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0x28')];return db[_0x5eb4('0xa4')]['find']({'where':{'messageId':_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0xd1')]}});}break;}}})[_0x5eb4('0x1c')](handleEntityNotFound(_0xef6c11,null))[_0x5eb4('0x1c')](function(_0x5e1774){if(_0x5e1774){_0x404920=_0x5e1774;switch(_0x194fee['type']){case _0x5eb4('0x7e'):if(_0x1f145d===_0x5eb4('0xcf')){return _0x404920['update']({'read':!![]});}else{logger[_0x5eb4('0x22')](_0x5eb4('0xab'),_0x5eb4('0x28'),_0x5eb4('0x7e'),util[_0x5eb4('0xc9')](_0x3ccbd9[_0x5eb4('0x5d')],{'showHidden':![],'depth':null}));}break;case'connectel':if(_0x1f145d==='1'){return _0x404920[_0x5eb4('0x33')]({'read':!![]});}else{logger[_0x5eb4('0x22')](_0x5eb4('0xab'),'status',_0x5eb4('0x7e'),util['inspect'](_0x3ccbd9[_0x5eb4('0x5d')],{'showHidden':![],'depth':null}));}break;case _0x5eb4('0x82'):if(!_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0xd2')]&&_0x1f145d>=0xc8&&_0x1f145d<=0xce){return _0x404920[_0x5eb4('0x33')]({'read':!![]});}else{logger[_0x5eb4('0x22')](_0x5eb4('0xab'),'status','clicksend',util[_0x5eb4('0xc9')](_0x3ccbd9[_0x5eb4('0x5d')],{'showHidden':![],'depth':null}));}break;case'infobip':var _0x222b4c=_0x3ccbd9[_0x5eb4('0x5d')][_0x5eb4('0x88')][0x0];if(_0x222b4c[_0x5eb4('0x28')][_0x5eb4('0xce')]===_0x5eb4('0xcf')){return _0x404920[_0x5eb4('0x33')]({'read':!![]});}else{logger[_0x5eb4('0x22')](_0x5eb4('0xab'),_0x5eb4('0x28'),_0x5eb4('0x87'),util['inspect'](_0x3ccbd9[_0x5eb4('0x5d')],{'showHidden':![],'depth':null}));}break;case _0x5eb4('0x8c'):if(_0x1f145d==_0x5eb4('0xd3')||_0x1f145d==_0x5eb4('0xd4')){return _0x404920[_0x5eb4('0x33')]({'read':!![]});}else{logger[_0x5eb4('0x22')](_0x5eb4('0xab'),_0x5eb4('0x28'),_0x5eb4('0x8c'),util[_0x5eb4('0xc9')](_0x3ccbd9[_0x5eb4('0x5d')],{'showHidden':![],'depth':null}));}break;case _0x5eb4('0xd0'):if(_0x1f145d==_0x5eb4('0xd5')){return _0x404920[_0x5eb4('0x33')]({'read':!![]});}else{logger[_0x5eb4('0x22')](_0x5eb4('0xab'),_0x5eb4('0x28'),_0x5eb4('0xd0'),util[_0x5eb4('0xc9')](_0x3ccbd9[_0x5eb4('0x5d')],{'showHidden':![],'depth':null}));}break;case _0x5eb4('0x8e'):if(_0x1f145d===_0x5eb4('0xd6')||_0x1f145d===_0x5eb4('0xd7')){return _0x404920[_0x5eb4('0x33')]({'read':!![]});}else{logger['error'](_0x5eb4('0xab'),'status',_0x5eb4('0x8e'),util[_0x5eb4('0xc9')](_0x3ccbd9[_0x5eb4('0x5d')],{'showHidden':![],'depth':null}));}break;}return _0x404920;}})[_0x5eb4('0x1c')](respondWithResult(_0xef6c11,null))['catch'](handleError(_0xef6c11,null));};exports[_0x5eb4('0xd8')]=function(_0x1b013f,_0x1e649f,_0x3cd88a){var _0x1e461d,_0x2528ab,_0x72f797;return db[_0x5eb4('0x4f')][_0x5eb4('0x5e')]({'where':{'id':_0x1b013f[_0x5eb4('0x54')]['id']}})[_0x5eb4('0x1c')](handleEntityNotFound(_0x1e649f,null))[_0x5eb4('0x1c')](function(_0x176083){if(_0x176083){_0x72f797=_0x176083;logger[_0x5eb4('0x20')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x5eb4('0x28'),_0x5eb4('0xc8'),_0x176083['type'],util[_0x5eb4('0xc9')](_0x1b013f['query'],{'showHidden':![],'depth':null}));switch(_0x176083[_0x5eb4('0x3f')]){case _0x5eb4('0x89'):if(_0x1b013f['query'][_0x5eb4('0xd9')]&&_0x1b013f[_0x5eb4('0x42')][_0x5eb4('0xda')]){_0x2528ab=_0x1b013f['query'][_0x5eb4('0xda')];return db['SmsMessage'][_0x5eb4('0x5e')]({'where':{'messageId':_0x1b013f[_0x5eb4('0x42')][_0x5eb4('0xd9')]}});}break;}}})[_0x5eb4('0x1c')](handleEntityNotFound(_0x1e649f,null))[_0x5eb4('0x1c')](function(_0x136657){if(_0x136657){_0x1e461d=_0x136657;switch(_0x72f797[_0x5eb4('0x3f')]){case _0x5eb4('0x89'):if(_0x2528ab==='2'||_0x2528ab==='6'){return _0x1e461d[_0x5eb4('0x33')]({'read':!![]});}else{logger[_0x5eb4('0x22')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x5eb4('0x28'),_0x5eb4('0x89'),util['inspect'](_0x1b013f['query'],{'showHidden':![],'depth':null}));};break;}return _0x1e461d;}})['then'](respondWithResult(_0x1e649f,null))['catch'](handleError(_0x1e649f,null));};exports[_0x5eb4('0xdb')]=function(_0x32f8a3,_0x41a416,_0x36d17b){return db[_0x5eb4('0x4f')][_0x5eb4('0x5e')]({'where':{'id':_0x32f8a3['params']['id']}})[_0x5eb4('0x1c')](handleEntityNotFound(_0x41a416,null))['then'](function(_0x513fb6){if(_0x513fb6){return _0x513fb6['addAgents'](_0x32f8a3['body'][_0x5eb4('0x68')],_[_0x5eb4('0x99')](_0x32f8a3[_0x5eb4('0x5d')],[_0x5eb4('0x68'),'id'])||{})['spread'](function(_0x237ec1){for(var _0x1fff38=0x0;_0x1fff38<_0x32f8a3['body'][_0x5eb4('0x68')][_0x5eb4('0x47')];_0x1fff38+=0x1){socket[_0x5eb4('0xdc')](_0x5eb4('0xdd'),{'UserId':Number(_0x32f8a3[_0x5eb4('0x5d')][_0x5eb4('0x68')][_0x1fff38]),'SmsAccountId':Number(_0x32f8a3[_0x5eb4('0x54')]['id'])});}return _0x237ec1;});}})[_0x5eb4('0x1c')](respondWithResult(_0x41a416,null))[_0x5eb4('0x26')](handleError(_0x41a416,null));};exports[_0x5eb4('0xde')]=function(_0xb2ec0b,_0xb4d50c,_0x20f89e){return db[_0x5eb4('0x4f')][_0x5eb4('0x5e')]({'where':{'id':_0xb2ec0b[_0x5eb4('0x54')]['id']}})['then'](handleEntityNotFound(_0xb4d50c,null))['then'](function(_0x20e9af){if(_0x20e9af){return _0x20e9af[_0x5eb4('0xde')](_0xb2ec0b[_0x5eb4('0x42')][_0x5eb4('0x68')])[_0x5eb4('0x1c')](function(){if(_[_0x5eb4('0xdf')](_0xb2ec0b[_0x5eb4('0x42')][_0x5eb4('0x68')])){for(var _0x2ef2b7=0x0;_0x2ef2b7<_0xb2ec0b[_0x5eb4('0x42')][_0x5eb4('0x68')][_0x5eb4('0x47')];_0x2ef2b7+=0x1){socket[_0x5eb4('0xdc')]('userSmsAccount:remove',{'UserId':Number(_0xb2ec0b[_0x5eb4('0x42')][_0x5eb4('0x68')][_0x2ef2b7]),'SmsAccountId':Number(_0xb2ec0b[_0x5eb4('0x54')]['id'])});}}else{socket['emit'](_0x5eb4('0xe0'),{'UserId':Number(_0xb2ec0b[_0x5eb4('0x42')][_0x5eb4('0x68')]),'SmsAccountId':Number(_0xb2ec0b[_0x5eb4('0x54')]['id'])});}});}})[_0x5eb4('0x1c')](respondWithStatusCode(_0xb4d50c,null))['catch'](handleError(_0xb4d50c,null));};exports[_0x5eb4('0xe1')]=function(_0x25b2c7,_0x27cc7b,_0x2d411c){var _0x38026c={};var _0x462e2b={};var _0x2f6078;var _0x2908b4;return db[_0x5eb4('0x4f')]['findOne']({'where':{'id':_0x25b2c7[_0x5eb4('0x54')]['id']}})['then'](handleEntityNotFound(_0x27cc7b,null))[_0x5eb4('0x1c')](function(_0x514b7c){if(_0x514b7c){_0x2f6078=_0x514b7c;_0x462e2b[_0x5eb4('0x41')]=_[_0x5eb4('0x43')](db['User']['rawAttributes']);_0x462e2b[_0x5eb4('0x42')]=_[_0x5eb4('0x43')](_0x25b2c7[_0x5eb4('0x42')]);_0x462e2b[_0x5eb4('0x44')]=_['intersection'](_0x462e2b[_0x5eb4('0x41')],_0x462e2b[_0x5eb4('0x42')]);_0x38026c[_0x5eb4('0x45')]=_[_0x5eb4('0x46')](_0x462e2b[_0x5eb4('0x41')],qs['fields'](_0x25b2c7[_0x5eb4('0x42')][_0x5eb4('0x55')]));_0x38026c[_0x5eb4('0x45')]=_0x38026c['attributes'][_0x5eb4('0x47')]?_0x38026c[_0x5eb4('0x45')]:_0x462e2b[_0x5eb4('0x41')];_0x38026c[_0x5eb4('0x65')]=qs[_0x5eb4('0x49')](_0x25b2c7[_0x5eb4('0x42')][_0x5eb4('0x49')]);_0x38026c[_0x5eb4('0x4a')]=qs[_0x5eb4('0x44')](_[_0x5eb4('0x4b')](_0x25b2c7['query'],_0x462e2b[_0x5eb4('0x44')]));if(_0x25b2c7[_0x5eb4('0x42')]['filter']){_0x38026c['where']=_[_0x5eb4('0x4c')](_0x38026c[_0x5eb4('0x4a')],{'$or':_['map'](_0x38026c[_0x5eb4('0x45')],function(_0x559903){var _0x1441bf={};_0x1441bf[_0x559903]={'$like':'%'+_0x25b2c7['query'][_0x5eb4('0x4e')]+'%'};return _0x1441bf;})});}_0x38026c=_['merge']({},_0x38026c,_0x25b2c7[_0x5eb4('0x56')]);return _0x2f6078[_0x5eb4('0xe1')](_0x38026c);}})[_0x5eb4('0x1c')](function(_0x57ab24){if(_0x57ab24){_0x2908b4=_0x57ab24[_0x5eb4('0x47')];if(!_0x25b2c7['query'][_0x5eb4('0x48')](_0x5eb4('0xbb'))){_0x38026c['limit']=qs[_0x5eb4('0x2b')](_0x25b2c7[_0x5eb4('0x42')]['limit']);_0x38026c[_0x5eb4('0x2e')]=qs[_0x5eb4('0x2e')](_0x25b2c7['query'][_0x5eb4('0x2e')]);}return _0x2f6078[_0x5eb4('0xe1')](_0x38026c);}})['then'](function(_0xcdb696){if(_0xcdb696){return _0xcdb696?{'count':_0x2908b4,'rows':_0xcdb696}:null;}})['then'](respondWithResult(_0x27cc7b,null))[_0x5eb4('0x26')](handleError(_0x27cc7b,null));};
\ No newline at end of file