Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / server / api / smsAccount / smsAccount.controller.js
index 192a377..49b005a 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x7a54=['findAndCountAll','getApplications','getInteractions','Contact','fullname','internal','Tag','color','tag','to\x20is\x20mandatory','DESC','List','out','Messages','spread','dataValues','push','log','skebby_dispatch_id','statusInt','requestid','clicksend','status_code','groupName','DELIVERED','redif','inspect','error_code','DELIVERED_TO_GATEWAY','RECEIVED_BY_RECIPIENT','DELIVRD','ACCEPTD','statusGet','received\x20delivery\x20report\x20from','message-id','state','addAgents','omit','emit','userSmsAccount:save','removeAgents','isArray','userSmsAccount:remove','getAgents','html-pdf','eml-format','rimraf','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','ejs','squel','crypto','desk.js','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','api','../../config/utils','../../config/environment','../../mysqldb','redis','defaults','socket.io-emitter','./smsAccount.socket','register','jayson/promise','client','http','test','Sequelize','ValidationError','request','then','info','SmsAccount,\x20%s,\x20%s','request\x20sent','SmsAccount,\x20%s,\x20%s,\x20%s','error','code','message','sendStatus','status','end','json','offset','limit','reject','update','destroy','get','UserProfileResource','stack','name','send','index','Pause','SmsAccount','fieldName','type','key','model','map','query','keys','filters','intersection','attributes','fields','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','count','includeAll','include','findAll','rows','catch','show','params','mandatoryDispositionPause','rawAttributes','length','find','create','user','role','SmsAccounts','UserProfileSection','autoAssociation','body','describe','addDisposition','SmsAccountId','Disposition','getDispositions','removeDispositions','ids','addAnswer','CannedAnswer','findOne','removeAnswers','notify','SmsApplication','Applications','account','priority','CmContact','no\x20available\x20attributes','difference','createdAt','updatedAt','ListId','From','Body','messageId','skebby','from','connectel','message_id','plivo','Text','MessageUUID','infobip','results','csc','originatingAddress','segmentedMessage','clickatell','fromNumber','text','replyMessageId','intelepeer','isNil','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','Contacts','contact','SmsInteraction','interaction','applications','close','unmanaged','SmsMessage','ContactId','AttachmentId','User','unshift','agent','waitForTheAssignedAgent','*,*,*,*','Start','startRouting','receiveMessage','entity\x20found','debug','SmsAccount,\x20%s,\x20%s,\x20%s,\x20%s','set','Content-Type','<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>','addApplications','sequelize','bulkCreate'];(function(_0x1f143f,_0x1b71c7){var _0x32c93e=function(_0x25d58e){while(--_0x25d58e){_0x1f143f['push'](_0x1f143f['shift']());}};_0x32c93e(++_0x1b71c7);}(_0x7a54,0x106));var _0x47a5=function(_0x4d0d86,_0x12c7ba){_0x4d0d86=_0x4d0d86-0x0;var _0x54039f=_0x7a54[_0x4d0d86];return _0x54039f;};'use strict';var pdf=require(_0x47a5('0x0'));var emlformat=require(_0x47a5('0x1'));var rimraf=require(_0x47a5('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0x47a5('0x3'));var rp=require(_0x47a5('0x4'));var moment=require('moment');var BPromise=require(_0x47a5('0x5'));var Mustache=require(_0x47a5('0x6'));var util=require(_0x47a5('0x7'));var path=require(_0x47a5('0x8'));var sox=require(_0x47a5('0x9'));var csv=require('to-csv');var ejs=require(_0x47a5('0xa'));var fs=require('fs');var _=require('lodash');var squel=require(_0x47a5('0xb'));var crypto=require(_0x47a5('0xc'));var jsforce=require('jsforce');var deskjs=require(_0x47a5('0xd'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x47a5('0xe'));var authService=require(_0x47a5('0xf'));var qs=require('../../components/parsers/qs');var as=require(_0x47a5('0x10'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x47a5('0x11'));var utils=require(_0x47a5('0x12'));var config=require(_0x47a5('0x13'));var db=require(_0x47a5('0x14'))['db'];config[_0x47a5('0x15')]=_[_0x47a5('0x16')](config[_0x47a5('0x15')],{'host':'localhost','port':0x18eb});var socket=require(_0x47a5('0x17'))(new Redis(config[_0x47a5('0x15')]));require(_0x47a5('0x18'))[_0x47a5('0x19')](socket);var jayson=require(_0x47a5('0x1a'));var client=jayson[_0x47a5('0x1b')][_0x47a5('0x1c')]({'port':0x232c});function checkPasswordPattern(_0x190faa,_0x4e99a8,_0x362359){if(_0x362359){var _0x11faf5=new RegExp(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[?!@#\$%\^&\*~\-_=+[{\]\}])(?=.{8,})/);if(_0x11faf5[_0x47a5('0x1d')](_0x4e99a8)){return _0x190faa;}else{throw new db[(_0x47a5('0x1e'))][(_0x47a5('0x1f'))]('The\x20password\x20must\x20be\x20at\x20least\x208\x20characters\x20long\x20and\x20have\x201\x20lowercase\x20character,\x201\x20uppercase\x20character,\x201\x20number\x20and\x201\x20special\x20character\x20~!@#$%^&-_=+[{]}.');}}else{return _0x190faa;}}function respondWithRpcPromise(_0x549de3,_0x138bc0,_0x4b966e,_0x5247fd){return new BPromise(function(_0x423a81,_0xaf70a6){var _0x2ce454=_0x5247fd||client;return _0x2ce454[_0x47a5('0x20')](_0x549de3,_0x4b966e)[_0x47a5('0x21')](function(_0x12b98e){logger[_0x47a5('0x22')](_0x47a5('0x23'),_0x138bc0,_0x47a5('0x24'));logger['debug'](_0x47a5('0x25'),_0x138bc0,_0x47a5('0x24'),JSON['stringify'](_0x12b98e));if(_0x12b98e[_0x47a5('0x26')]){if(_0x12b98e[_0x47a5('0x26')][_0x47a5('0x27')]===0x1f4){logger['error'](_0x47a5('0x23'),_0x138bc0,_0x12b98e[_0x47a5('0x26')][_0x47a5('0x28')]);return _0xaf70a6(_0x12b98e[_0x47a5('0x26')]['message']);}logger[_0x47a5('0x26')](_0x47a5('0x23'),_0x138bc0,_0x12b98e['error'][_0x47a5('0x28')]);return _0x423a81(_0x12b98e[_0x47a5('0x26')][_0x47a5('0x28')]);}else{logger[_0x47a5('0x22')](_0x47a5('0x23'),_0x138bc0,'request\x20sent');_0x423a81(_0x12b98e['result'][_0x47a5('0x28')]);}})['catch'](function(_0x1ea9c8){logger['error'](_0x47a5('0x23'),_0x138bc0,_0x1ea9c8);_0xaf70a6(_0x1ea9c8);});});}function respondWithStatusCode(_0x378208,_0x36ad34){_0x36ad34=_0x36ad34||0xcc;return function(_0x1dac65){if(_0x1dac65){return _0x378208[_0x47a5('0x29')](_0x36ad34);}return _0x378208[_0x47a5('0x2a')](_0x36ad34)[_0x47a5('0x2b')]();};}function respondWithResult(_0x136b14,_0x16631f){_0x16631f=_0x16631f||0xc8;return function(_0x361bfa){if(_0x361bfa){return _0x136b14[_0x47a5('0x2a')](_0x16631f)[_0x47a5('0x2c')](_0x361bfa);}};}function respondWithFilteredResult(_0x3ad507,_0x528582){return function(_0x243210){if(_0x243210){var _0x51833b=_0x243210['count'],_0x2ef875=_0x528582[_0x47a5('0x2d')],_0x9ac908=_0x528582[_0x47a5('0x2d')]+_0x528582[_0x47a5('0x2e')],_0x16901f;if(_0x9ac908>=_0x51833b){_0x9ac908=_0x51833b;_0x16901f=0xc8;}else{_0x16901f=0xce;}_0x3ad507[_0x47a5('0x2a')](_0x16901f);return _0x3ad507['set']('Content-Range',_0x2ef875+'-'+_0x9ac908+'/'+_0x51833b)[_0x47a5('0x2c')](_0x243210);}return null;};}function patchUpdates(_0xfb5ddb){return function(_0x5bd7eb){try{jsonpatch['apply'](_0x5bd7eb,_0xfb5ddb,!![]);}catch(_0x836303){return BPromise[_0x47a5('0x2f')](_0x836303);}return _0x5bd7eb['save']();};}function saveUpdates(_0x42f70c,_0x53119b){return function(_0x122ed6){if(_0x122ed6){return _0x122ed6[_0x47a5('0x30')](_0x42f70c)['then'](function(_0x4843c0){return _0x4843c0;});}return null;};}function removeEntity(_0x274e34,_0x5910bb){return function(_0x403028){if(_0x403028){return _0x403028[_0x47a5('0x31')]()[_0x47a5('0x21')](function(){var _0x52749b=_0x403028[_0x47a5('0x32')]({'plain':!![]});var _0x50c086='SmsAccounts';return db[_0x47a5('0x33')]['destroy']({'where':{'type':_0x50c086,'resourceId':_0x52749b['id']}})[_0x47a5('0x21')](function(){return _0x403028;});})['then'](function(){_0x274e34[_0x47a5('0x2a')](0xcc)[_0x47a5('0x2b')]();});}};}function handleEntityNotFound(_0x38c8d4,_0x199698){return function(_0x36add5){if(!_0x36add5){_0x38c8d4[_0x47a5('0x29')](0x194);}return _0x36add5;};}function handleError(_0xee582c,_0x452be5){_0x452be5=_0x452be5||0x1f4;return function(_0x1a0d23){logger['error'](_0x1a0d23[_0x47a5('0x34')]);if(_0x1a0d23[_0x47a5('0x35')]){delete _0x1a0d23['name'];}_0xee582c[_0x47a5('0x2a')](_0x452be5)[_0x47a5('0x36')](_0x1a0d23);};}exports[_0x47a5('0x37')]=function(_0x49c4b5,_0x101f70){var _0x10f660={'include':[{'model':db[_0x47a5('0x38')],'as':'mandatoryDispositionPause'}]},_0x596097={},_0x2ebba0={'count':0x0,'rows':[]};var _0x55c5eb=_['map'](db[_0x47a5('0x39')]['rawAttributes'],function(_0x9b5eaf){return{'name':_0x9b5eaf[_0x47a5('0x3a')],'type':_0x9b5eaf[_0x47a5('0x3b')][_0x47a5('0x3c')]};});_0x596097[_0x47a5('0x3d')]=_[_0x47a5('0x3e')](_0x55c5eb,_0x47a5('0x35'));_0x596097[_0x47a5('0x3f')]=_[_0x47a5('0x40')](_0x49c4b5[_0x47a5('0x3f')]);_0x596097[_0x47a5('0x41')]=_[_0x47a5('0x42')](_0x596097[_0x47a5('0x3d')],_0x596097['query']);_0x10f660[_0x47a5('0x43')]=_[_0x47a5('0x42')](_0x596097[_0x47a5('0x3d')],qs[_0x47a5('0x44')](_0x49c4b5['query'][_0x47a5('0x44')]));_0x10f660['attributes']=_0x10f660['attributes']['length']?_0x10f660['attributes']:_0x596097[_0x47a5('0x3d')];if(!_0x49c4b5['query'][_0x47a5('0x45')](_0x47a5('0x46'))){_0x10f660[_0x47a5('0x2e')]=qs['limit'](_0x49c4b5[_0x47a5('0x3f')][_0x47a5('0x2e')]);_0x10f660['offset']=qs['offset'](_0x49c4b5[_0x47a5('0x3f')]['offset']);}_0x10f660[_0x47a5('0x47')]=qs[_0x47a5('0x48')](_0x49c4b5[_0x47a5('0x3f')][_0x47a5('0x48')]);_0x10f660[_0x47a5('0x49')]=qs[_0x47a5('0x41')](_[_0x47a5('0x4a')](_0x49c4b5[_0x47a5('0x3f')],_0x596097[_0x47a5('0x41')]),_0x55c5eb);if(_0x49c4b5[_0x47a5('0x3f')][_0x47a5('0x4b')]){_0x10f660[_0x47a5('0x49')]=_[_0x47a5('0x4c')](_0x10f660[_0x47a5('0x49')],{'$or':_[_0x47a5('0x3e')](_0x55c5eb,function(_0x3a2b38){if(_0x3a2b38['type']!==_0x47a5('0x4d')){var _0x23bb04={};_0x23bb04[_0x3a2b38['name']]={'$like':'%'+_0x49c4b5['query'][_0x47a5('0x4b')]+'%'};return _0x23bb04;}})});}_0x10f660=_['merge']({},_0x10f660,_0x49c4b5[_0x47a5('0x4e')]);var _0xd93e37={'where':_0x10f660['where']};return db['SmsAccount'][_0x47a5('0x4f')](_0xd93e37)['then'](function(_0x2d147c){_0x2ebba0[_0x47a5('0x4f')]=_0x2d147c;if(_0x49c4b5[_0x47a5('0x3f')][_0x47a5('0x50')]){_0x10f660[_0x47a5('0x51')]=[{'all':!![]}];}return db[_0x47a5('0x39')][_0x47a5('0x52')](_0x10f660);})['then'](function(_0x48a0ef){_0x2ebba0[_0x47a5('0x53')]=_0x48a0ef;return _0x2ebba0;})[_0x47a5('0x21')](respondWithFilteredResult(_0x101f70,_0x10f660))[_0x47a5('0x54')](handleError(_0x101f70,null));};exports[_0x47a5('0x55')]=function(_0x2c7020,_0x2c0c86){var _0x249de5={'raw':![],'where':{'id':_0x2c7020[_0x47a5('0x56')]['id']},'include':[{'model':db[_0x47a5('0x38')],'as':_0x47a5('0x57')}]},_0x492cf7={};_0x492cf7['model']=_[_0x47a5('0x40')](db['SmsAccount'][_0x47a5('0x58')]);_0x492cf7[_0x47a5('0x3f')]=_[_0x47a5('0x40')](_0x2c7020[_0x47a5('0x3f')]);_0x492cf7['filters']=_[_0x47a5('0x42')](_0x492cf7[_0x47a5('0x3d')],_0x492cf7[_0x47a5('0x3f')]);_0x249de5[_0x47a5('0x43')]=_[_0x47a5('0x42')](_0x492cf7[_0x47a5('0x3d')],qs[_0x47a5('0x44')](_0x2c7020['query'][_0x47a5('0x44')]));_0x249de5[_0x47a5('0x43')]=_0x249de5[_0x47a5('0x43')][_0x47a5('0x59')]?_0x249de5[_0x47a5('0x43')]:_0x492cf7[_0x47a5('0x3d')];if(_0x2c7020['query'][_0x47a5('0x50')]){_0x249de5[_0x47a5('0x51')]=[{'all':!![]}];}_0x249de5=_[_0x47a5('0x4c')]({},_0x249de5,_0x2c7020['options']);return db[_0x47a5('0x39')][_0x47a5('0x5a')](_0x249de5)[_0x47a5('0x21')](handleEntityNotFound(_0x2c0c86,null))['then'](respondWithResult(_0x2c0c86,null))['catch'](handleError(_0x2c0c86,null));};exports[_0x47a5('0x5b')]=function(_0x376e1d,_0x4fa1da){return db['SmsAccount'][_0x47a5('0x5b')](_0x376e1d['body'],{})[_0x47a5('0x21')](function(_0x5d383d){var _0x482de6=_0x376e1d[_0x47a5('0x5c')][_0x47a5('0x32')]({'plain':!![]});if(!_0x482de6)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x482de6[_0x47a5('0x5d')]===_0x47a5('0x5c')){var _0x4b706a=_0x5d383d['get']({'plain':!![]});var _0x16b4fd=_0x47a5('0x5e');return db[_0x47a5('0x5f')][_0x47a5('0x5a')]({'where':{'name':_0x16b4fd,'userProfileId':_0x482de6['userProfileId']},'raw':!![]})[_0x47a5('0x21')](function(_0x2b4255){if(_0x2b4255&&_0x2b4255[_0x47a5('0x60')]===0x0){return db['UserProfileResource'][_0x47a5('0x5b')]({'name':_0x4b706a['name'],'resourceId':_0x4b706a['id'],'type':_0x2b4255[_0x47a5('0x35')],'sectionId':_0x2b4255['id']},{})[_0x47a5('0x21')](function(){return _0x5d383d;});}else{return _0x5d383d;}})[_0x47a5('0x54')](function(_0x1c485b){logger[_0x47a5('0x26')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x1c485b);throw _0x1c485b;});}return _0x5d383d;})[_0x47a5('0x21')](respondWithResult(_0x4fa1da,0xc9))['catch'](handleError(_0x4fa1da,null));};exports['update']=function(_0x5eb150,_0x4f8564){if(_0x5eb150[_0x47a5('0x61')]['id']){delete _0x5eb150[_0x47a5('0x61')]['id'];}return db[_0x47a5('0x39')]['find']({'where':{'id':_0x5eb150['params']['id']},'include':[{'model':db[_0x47a5('0x38')],'as':_0x47a5('0x57')}]})[_0x47a5('0x21')](handleEntityNotFound(_0x4f8564,null))[_0x47a5('0x21')](saveUpdates(_0x5eb150[_0x47a5('0x61')],null))['then'](respondWithResult(_0x4f8564,null))[_0x47a5('0x54')](handleError(_0x4f8564,null));};exports['destroy']=function(_0x22c886,_0x274d31){return db['SmsAccount'][_0x47a5('0x5a')]({'where':{'id':_0x22c886[_0x47a5('0x56')]['id']}})[_0x47a5('0x21')](handleEntityNotFound(_0x274d31,null))[_0x47a5('0x21')](removeEntity(_0x274d31,null))[_0x47a5('0x54')](handleError(_0x274d31,null));};exports[_0x47a5('0x62')]=function(_0x35cca8,_0x3ac38c){return db['SmsAccount'][_0x47a5('0x62')]()[_0x47a5('0x21')](respondWithResult(_0x3ac38c,null))[_0x47a5('0x54')](handleError(_0x3ac38c,null));};exports[_0x47a5('0x63')]=function(_0x396cb0,_0x4bbe14,_0xbec033){if(_0x396cb0[_0x47a5('0x61')]['id']){delete _0x396cb0[_0x47a5('0x61')]['id'];}return db[_0x47a5('0x39')][_0x47a5('0x5a')]({'where':{'id':_0x396cb0[_0x47a5('0x56')]['id']}})[_0x47a5('0x21')](handleEntityNotFound(_0x4bbe14,null))[_0x47a5('0x21')](function(_0x350af8){if(_0x350af8){_0x396cb0[_0x47a5('0x61')][_0x47a5('0x64')]=_0x350af8['id'];return db[_0x47a5('0x65')][_0x47a5('0x5b')](_0x396cb0[_0x47a5('0x61')]);}})[_0x47a5('0x21')](respondWithResult(_0x4bbe14,null))['catch'](handleError(_0x4bbe14,null));};exports[_0x47a5('0x66')]=function(_0x284fb8,_0x30504e,_0x4b42f3){var _0x37ac59={'raw':![],'where':{}};var _0x2e46af={};var _0x36c67={'count':0x0,'rows':[]};return db[_0x47a5('0x39')]['findOne']({'where':{'id':_0x284fb8[_0x47a5('0x56')]['id']}})['then'](handleEntityNotFound(_0x30504e,null))[_0x47a5('0x21')](function(_0x487e21){if(_0x487e21){_0x2e46af[_0x47a5('0x3d')]=_['keys'](db[_0x47a5('0x65')][_0x47a5('0x58')]);_0x2e46af[_0x47a5('0x3f')]=_['keys'](_0x284fb8['query']);_0x2e46af['filters']=_[_0x47a5('0x42')](_0x2e46af[_0x47a5('0x3d')],_0x2e46af[_0x47a5('0x3f')]);_0x37ac59[_0x47a5('0x43')]=_['intersection'](_0x2e46af[_0x47a5('0x3d')],qs[_0x47a5('0x44')](_0x284fb8[_0x47a5('0x3f')][_0x47a5('0x44')]));_0x37ac59[_0x47a5('0x43')]=_0x37ac59[_0x47a5('0x43')][_0x47a5('0x59')]?_0x37ac59[_0x47a5('0x43')]:_0x2e46af[_0x47a5('0x3d')];if(!_0x284fb8[_0x47a5('0x3f')][_0x47a5('0x45')](_0x47a5('0x46'))){_0x37ac59['limit']=qs[_0x47a5('0x2e')](_0x284fb8['query'][_0x47a5('0x2e')]);_0x37ac59[_0x47a5('0x2d')]=qs[_0x47a5('0x2d')](_0x284fb8[_0x47a5('0x3f')][_0x47a5('0x2d')]);}_0x37ac59[_0x47a5('0x47')]=qs[_0x47a5('0x48')](_0x284fb8[_0x47a5('0x3f')][_0x47a5('0x48')]);_0x37ac59[_0x47a5('0x49')]=qs[_0x47a5('0x41')](_[_0x47a5('0x4a')](_0x284fb8[_0x47a5('0x3f')],_0x2e46af[_0x47a5('0x41')]));_0x37ac59[_0x47a5('0x49')]['SmsAccountId']=_0x487e21['id'];if(_0x284fb8['query']['filter']){_0x37ac59['where']=_[_0x47a5('0x4c')](_0x37ac59[_0x47a5('0x49')],{'$or':_['map'](_0x37ac59[_0x47a5('0x43')],function(_0x44dda2){var _0x1baa5a={};_0x1baa5a[_0x44dda2]={'$like':'%'+_0x284fb8[_0x47a5('0x3f')][_0x47a5('0x4b')]+'%'};return _0x1baa5a;})});}_0x37ac59=_[_0x47a5('0x4c')]({},_0x37ac59,_0x284fb8[_0x47a5('0x4e')]);return db[_0x47a5('0x65')][_0x47a5('0x4f')]({'where':_0x37ac59[_0x47a5('0x49')]})[_0x47a5('0x21')](function(_0x5e5f16){_0x36c67[_0x47a5('0x4f')]=_0x5e5f16;if(_0x284fb8[_0x47a5('0x3f')][_0x47a5('0x50')]){_0x37ac59['include']=[{'all':!![]}];}return db[_0x47a5('0x65')][_0x47a5('0x52')](_0x37ac59);})[_0x47a5('0x21')](function(_0x5d41d8){_0x36c67[_0x47a5('0x53')]=_0x5d41d8;return _0x36c67;});}})['then'](respondWithFilteredResult(_0x30504e,_0x37ac59))['catch'](handleError(_0x30504e,null));};exports[_0x47a5('0x67')]=function(_0x292d9c,_0x277486,_0x27333e){return db[_0x47a5('0x39')][_0x47a5('0x5a')]({'where':{'id':_0x292d9c['params']['id']}})['then'](handleEntityNotFound(_0x277486,null))[_0x47a5('0x21')](function(_0x4f2361){if(_0x4f2361){return _0x4f2361[_0x47a5('0x67')](_0x292d9c[_0x47a5('0x3f')][_0x47a5('0x68')]);}})[_0x47a5('0x21')](respondWithStatusCode(_0x277486,null))['catch'](handleError(_0x277486,null));};exports[_0x47a5('0x69')]=function(_0x550bde,_0x5f3a04,_0x139c79){if(_0x550bde[_0x47a5('0x61')]['id']){delete _0x550bde['body']['id'];}return db[_0x47a5('0x39')][_0x47a5('0x5a')]({'where':{'id':_0x550bde[_0x47a5('0x56')]['id']}})['then'](handleEntityNotFound(_0x5f3a04,null))[_0x47a5('0x21')](function(_0x578e27){if(_0x578e27){_0x550bde[_0x47a5('0x61')][_0x47a5('0x64')]=_0x578e27['id'];return db[_0x47a5('0x6a')]['create'](_0x550bde[_0x47a5('0x61')]);}})[_0x47a5('0x21')](respondWithResult(_0x5f3a04,null))[_0x47a5('0x54')](handleError(_0x5f3a04,null));};exports['getAnswers']=function(_0x3525e7,_0x4f2fbb,_0x3c012b){var _0x491bb4={'raw':![],'where':{}};var _0x135d2e={};var _0x20d8bd={'count':0x0,'rows':[]};return db[_0x47a5('0x39')][_0x47a5('0x6b')]({'where':{'id':_0x3525e7['params']['id']}})[_0x47a5('0x21')](handleEntityNotFound(_0x4f2fbb,null))[_0x47a5('0x21')](function(_0x23c393){if(_0x23c393){_0x135d2e[_0x47a5('0x3d')]=_[_0x47a5('0x40')](db['CannedAnswer']['rawAttributes']);_0x135d2e[_0x47a5('0x3f')]=_['keys'](_0x3525e7[_0x47a5('0x3f')]);_0x135d2e[_0x47a5('0x41')]=_[_0x47a5('0x42')](_0x135d2e['model'],_0x135d2e[_0x47a5('0x3f')]);_0x491bb4[_0x47a5('0x43')]=_['intersection'](_0x135d2e[_0x47a5('0x3d')],qs[_0x47a5('0x44')](_0x3525e7[_0x47a5('0x3f')][_0x47a5('0x44')]));_0x491bb4['attributes']=_0x491bb4['attributes'][_0x47a5('0x59')]?_0x491bb4[_0x47a5('0x43')]:_0x135d2e['model'];if(!_0x3525e7[_0x47a5('0x3f')][_0x47a5('0x45')]('nolimit')){_0x491bb4[_0x47a5('0x2e')]=qs[_0x47a5('0x2e')](_0x3525e7[_0x47a5('0x3f')]['limit']);_0x491bb4[_0x47a5('0x2d')]=qs['offset'](_0x3525e7[_0x47a5('0x3f')]['offset']);}_0x491bb4[_0x47a5('0x47')]=qs[_0x47a5('0x48')](_0x3525e7['query'][_0x47a5('0x48')]);_0x491bb4['where']=qs[_0x47a5('0x41')](_[_0x47a5('0x4a')](_0x3525e7[_0x47a5('0x3f')],_0x135d2e[_0x47a5('0x41')]));_0x491bb4['where'][_0x47a5('0x64')]=_0x23c393['id'];if(_0x3525e7['query']['filter']){_0x491bb4[_0x47a5('0x49')]=_[_0x47a5('0x4c')](_0x491bb4[_0x47a5('0x49')],{'$or':_[_0x47a5('0x3e')](_0x491bb4[_0x47a5('0x43')],function(_0x5b1f5e){var _0x1522a6={};_0x1522a6[_0x5b1f5e]={'$like':'%'+_0x3525e7[_0x47a5('0x3f')][_0x47a5('0x4b')]+'%'};return _0x1522a6;})});}_0x491bb4=_[_0x47a5('0x4c')]({},_0x491bb4,_0x3525e7['options']);return db[_0x47a5('0x6a')]['count']({'where':_0x491bb4[_0x47a5('0x49')]})[_0x47a5('0x21')](function(_0x3f93f0){_0x20d8bd[_0x47a5('0x4f')]=_0x3f93f0;if(_0x3525e7[_0x47a5('0x3f')][_0x47a5('0x50')]){_0x491bb4[_0x47a5('0x51')]=[{'all':!![]}];}return db[_0x47a5('0x6a')][_0x47a5('0x52')](_0x491bb4);})['then'](function(_0x36796e){_0x20d8bd[_0x47a5('0x53')]=_0x36796e;return _0x20d8bd;});}})['then'](respondWithFilteredResult(_0x4f2fbb,_0x491bb4))[_0x47a5('0x54')](handleError(_0x4f2fbb,null));};exports[_0x47a5('0x6c')]=function(_0x6d6a5,_0x5b85cd,_0x4bf1f5){return db[_0x47a5('0x39')][_0x47a5('0x5a')]({'where':{'id':_0x6d6a5['params']['id']}})['then'](handleEntityNotFound(_0x5b85cd,null))[_0x47a5('0x21')](function(_0x17f82d){if(_0x17f82d){return _0x17f82d['removeAnswers'](_0x6d6a5[_0x47a5('0x3f')][_0x47a5('0x68')]);}})['then'](respondWithStatusCode(_0x5b85cd,null))[_0x47a5('0x54')](handleError(_0x5b85cd,null));};exports[_0x47a5('0x6d')]=function(_0x109805,_0x70c8a6,_0x364bb0){var _0x1371e4={'channel':'sms'};var _0x4c9894=[];var _0x5bd86e=[];var _0x133b7a={};return db[_0x47a5('0x39')]['find']({'where':{'id':_0x109805[_0x47a5('0x56')]['id']},'include':[{'model':db[_0x47a5('0x6e')],'as':_0x47a5('0x6f')}]})[_0x47a5('0x21')](handleEntityNotFound(_0x70c8a6,null))[_0x47a5('0x21')](function(_0x5084d6){_0x1371e4[_0x47a5('0x70')]=_0x5084d6;_0x1371e4['applications']=_['orderBy'](_0x5084d6['Applications'],[_0x47a5('0x71')],['asc']);if(_0x1371e4[_0x47a5('0x70')][_0x47a5('0x6f')]){delete _0x1371e4[_0x47a5('0x70')]['Applications'];}return db[_0x47a5('0x72')][_0x47a5('0x62')]();})[_0x47a5('0x21')](function(_0x121750){if(!_0x121750){throw new db[(_0x47a5('0x1e'))]['ValidationError'](_0x47a5('0x73'));}_0x4c9894=_[_0x47a5('0x74')](_['keys'](_0x121750),[_0x47a5('0x75'),_0x47a5('0x76')]);_0x5bd86e=_[_0x47a5('0x74')](_[_0x47a5('0x40')](_0x121750),[_0x47a5('0x75'),_0x47a5('0x76'),'CompanyId',_0x47a5('0x77')]);_0x1371e4[_0x47a5('0x61')]={'mapKey':'mobile'};if(_0x1371e4[_0x47a5('0x70')][_0x47a5('0x3b')]){switch(_0x1371e4[_0x47a5('0x70')][_0x47a5('0x3b')]){case'twilio':_0x1371e4['body']['from']=_0x109805['body'][_0x47a5('0x78')];_0x1371e4[_0x47a5('0x61')][_0x47a5('0x61')]=_0x109805[_0x47a5('0x61')][_0x47a5('0x79')];_0x1371e4[_0x47a5('0x61')][_0x47a5('0x7a')]=_0x109805[_0x47a5('0x61')]['MessageSid'];break;case _0x47a5('0x7b'):_0x1371e4[_0x47a5('0x61')][_0x47a5('0x7c')]='+'+_0x109805[_0x47a5('0x61')]['sender'];_0x1371e4['body'][_0x47a5('0x61')]=_0x109805['body']['text'];break;case _0x47a5('0x7d'):_0x1371e4[_0x47a5('0x61')]['from']=_0x109805[_0x47a5('0x61')][_0x47a5('0x7c')];_0x1371e4[_0x47a5('0x61')]['body']=_0x109805[_0x47a5('0x61')][_0x47a5('0x28')];break;case'clicksend':_0x1371e4[_0x47a5('0x61')][_0x47a5('0x7c')]=_0x109805[_0x47a5('0x61')][_0x47a5('0x7c')];_0x1371e4[_0x47a5('0x61')][_0x47a5('0x61')]=_0x109805['body'][_0x47a5('0x61')];_0x1371e4['body'][_0x47a5('0x7a')]=_0x109805[_0x47a5('0x61')][_0x47a5('0x7e')];break;case _0x47a5('0x7f'):_0x1371e4['body'][_0x47a5('0x7c')]=_0x109805[_0x47a5('0x61')][_0x47a5('0x78')];_0x1371e4[_0x47a5('0x61')][_0x47a5('0x61')]=_0x109805[_0x47a5('0x61')][_0x47a5('0x80')];_0x1371e4[_0x47a5('0x61')][_0x47a5('0x7a')]=_0x109805[_0x47a5('0x61')][_0x47a5('0x81')];break;case _0x47a5('0x82'):_0x1371e4['body'][_0x47a5('0x7c')]='+'+_0x109805[_0x47a5('0x61')]['results'][0x0][_0x47a5('0x7c')];_0x1371e4[_0x47a5('0x61')][_0x47a5('0x61')]=_0x109805[_0x47a5('0x61')][_0x47a5('0x83')][0x0]['text'];_0x1371e4[_0x47a5('0x61')][_0x47a5('0x7a')]=_0x109805[_0x47a5('0x61')][_0x47a5('0x83')][0x0][_0x47a5('0x7a')];break;case _0x47a5('0x84'):_0x1371e4[_0x47a5('0x61')]['from']=_0x109805['body'][_0x47a5('0x85')];_0x1371e4['body'][_0x47a5('0x61')]=_0x109805['body'][_0x47a5('0x86')][_0x47a5('0x28')];break;case _0x47a5('0x87'):_0x1371e4[_0x47a5('0x61')]['from']=_0x109805[_0x47a5('0x61')][_0x47a5('0x88')];_0x1371e4[_0x47a5('0x61')]['body']=_0x109805['body'][_0x47a5('0x89')];_0x1371e4[_0x47a5('0x61')][_0x47a5('0x7a')]=_0x109805[_0x47a5('0x61')][_0x47a5('0x8a')];break;case _0x47a5('0x8b'):_0x1371e4[_0x47a5('0x61')][_0x47a5('0x7c')]=_0x109805['body'][_0x47a5('0x7c')];_0x1371e4['body'][_0x47a5('0x61')]=_0x109805[_0x47a5('0x61')]['message'];_0x1371e4['body'][_0x47a5('0x7a')]=_0x109805[_0x47a5('0x61')]['refid'];break;}}if(_0x1371e4[_0x47a5('0x61')]['id']){delete _0x1371e4[_0x47a5('0x61')]['id'];}if(_[_0x47a5('0x8c')](_0x1371e4[_0x47a5('0x61')]['from'])){throw new db[(_0x47a5('0x1e'))]['ValidationError']('from\x20is\x20mandatory');}if(_['isNil'](_0x1371e4[_0x47a5('0x61')]['body'])||_0x1371e4[_0x47a5('0x61')][_0x47a5('0x61')]===''){throw new db[(_0x47a5('0x1e'))][(_0x47a5('0x1f'))](_0x47a5('0x8d'));}if(_[_0x47a5('0x8c')](_0x1371e4[_0x47a5('0x61')][_0x47a5('0x8e')])){throw new db[(_0x47a5('0x1e'))][(_0x47a5('0x1f'))](_0x47a5('0x8f')+_0x5bd86e);}if(!_[_0x47a5('0x90')](_0x5bd86e,_0x1371e4[_0x47a5('0x61')][_0x47a5('0x8e')])){throw new db[(_0x47a5('0x1e'))]['ValidationError'](_0x47a5('0x91')+_0x5bd86e);}_0x133b7a[_0x1371e4[_0x47a5('0x61')][_0x47a5('0x8e')]]=_0x1371e4[_0x47a5('0x61')]['from'];return db[_0x47a5('0x92')]['find']({'where':{'id':_0x1371e4[_0x47a5('0x70')]['ListId']},'include':[{'model':db[_0x47a5('0x72')],'as':_0x47a5('0x93'),'where':_0x133b7a,'limit':0x1,'order':[[_0x47a5('0x76'),'DESC']]}]});})[_0x47a5('0x21')](handleEntityNotFound(_0x70c8a6,null))[_0x47a5('0x21')](function(_0x14771b){if(_0x14771b){_0x1371e4['list']=_['omit'](_0x14771b,[_0x47a5('0x93')]);if(_0x14771b[_0x47a5('0x93')][_0x47a5('0x59')]){return _0x14771b[_0x47a5('0x93')][0x0];}var _0x204bd6=_['defaults'](_0x1371e4[_0x47a5('0x61')],{'firstName':_0x1371e4['body'][_0x47a5('0x7c')],'ListId':_0x14771b['id']});_0x204bd6[_0x1371e4[_0x47a5('0x61')][_0x47a5('0x8e')]]=_0x1371e4[_0x47a5('0x61')]['from'];return db['CmContact'][_0x47a5('0x5b')](_0x204bd6,{'fields':_0x4c9894,'raw':!![]});}})[_0x47a5('0x21')](handleEntityNotFound(_0x70c8a6,null))[_0x47a5('0x21')](function(_0x4339d4){if(_0x4339d4){_0x1371e4[_0x47a5('0x94')]=_0x4339d4;var _0x36a44c={'ContactId':_0x4339d4['id'],'phone':_0x1371e4[_0x47a5('0x61')][_0x47a5('0x7c')],'SmsAccountId':_0x109805[_0x47a5('0x56')]['id']};var _0x481bc3={'ContactId':_0x4339d4['id'],'SmsAccountId':_0x109805['params']['id'],'closed':![]};return db[_0x47a5('0x95')]['find']({'where':_0x481bc3})[_0x47a5('0x21')](function(_0x2d0b67){if(_0x2d0b67){return[_0x2d0b67,![]];}return db[_0x47a5('0x95')]['create'](_0x36a44c)[_0x47a5('0x21')](function(_0x26d629){return[_0x26d629,!![]];});});}})['spread'](function(_0xcb6714,_0x51f6cf){_0x1371e4[_0x47a5('0x96')]=_0xcb6714[_0x47a5('0x32')]({'plain':!![]});_0x1371e4[_0x47a5('0x96')]['created']=![];if(_0x51f6cf){if(_0x1371e4['account']['autoclose']){_0x1371e4['applications']['push']({'id':0x0,'priority':_0x1371e4[_0x47a5('0x97')]['length']+0x1,'app':_0x47a5('0x98'),'appdata':_0x47a5('0x99'),'interval':'*,*,*,*'});}_0x1371e4['interaction']['created']=!![];}return db[_0x47a5('0x9a')]['create']({'phone':_0x1371e4['body']['from'],'messageId':_0x1371e4[_0x47a5('0x61')][_0x47a5('0x7a')],'body':_0x1371e4[_0x47a5('0x61')][_0x47a5('0x61')],'SmsAccountId':_0x109805['params']['id'],'SmsInteractionId':_0xcb6714['id'],'direction':'in','ContactId':_0xcb6714[_0x47a5('0x9b')],'AttachmentId':_0x1371e4['body'][_0x47a5('0x9c')]});})['then'](function(_0x2de924){_0x1371e4[_0x47a5('0x28')]=_0x2de924;if(_0x1371e4[_0x47a5('0x96')]['UserId']){return db[_0x47a5('0x9d')][_0x47a5('0x5a')]({'attributes':['id',_0x47a5('0x35')],'where':{'id':_0x1371e4[_0x47a5('0x96')]['UserId']}})[_0x47a5('0x21')](function(_0x9a7edc){if(_0x9a7edc){_0x1371e4[_0x47a5('0x97')][_0x47a5('0x9e')]({'id':0x0,'priority':0x0,'app':_0x47a5('0x9f'),'appdata':_0x9a7edc[_0x47a5('0x35')]+','+(_0x1371e4['account'][_0x47a5('0xa0')]||0xa),'interval':_0x47a5('0xa1')});}return respondWithRpcPromise(_0x47a5('0xa2'),_0x47a5('0xa3'),_0x1371e4);});}return respondWithRpcPromise(_0x47a5('0xa2'),_0x47a5('0xa3'),_0x1371e4);})[_0x47a5('0x21')](function(_0x2697df){if(_0x2697df){var _0x408887=0xc8;var _0x34fde3=_0x47a5('0xa4');logger[_0x47a5('0x22')](_0x47a5('0x25'),_0x34fde3,_0x408887,_0x47a5('0xa5'));logger[_0x47a5('0xa6')](_0x47a5('0xa7'),_0x34fde3,_0x408887,_0x47a5('0xa5'),JSON['stringify'](_0x2697df));if(_0x1371e4[_0x47a5('0x70')]['type']==='twilio'){return _0x70c8a6[_0x47a5('0x2a')](_0x408887)[_0x47a5('0xa8')](_0x47a5('0xa9'),'text/xml')[_0x47a5('0x36')](_0x47a5('0xaa'));}else{return _0x70c8a6[_0x47a5('0x2a')](_0x408887)[_0x47a5('0x2c')](_0x2697df);}}})[_0x47a5('0x54')](handleError(_0x70c8a6,null));};exports[_0x47a5('0xab')]=function(_0x1b1f86,_0x46cb3a,_0x176e71){return db[_0x47a5('0x39')][_0x47a5('0x6b')]({'where':{'id':_0x1b1f86[_0x47a5('0x56')]['id']}})[_0x47a5('0x21')](handleEntityNotFound(_0x46cb3a,null))['then'](function(_0x4aad5f){if(_0x4aad5f){return db[_0x47a5('0xac')]['transaction'](function(_0x249339){return db[_0x47a5('0x6e')][_0x47a5('0x31')]({'where':{'SmsAccountId':_0x1b1f86[_0x47a5('0x56')]['id']},'transaction':_0x249339})[_0x47a5('0x21')](function(_0x3708ea){var _0x583b37=_[_0x47a5('0x3e')](_0x1b1f86[_0x47a5('0x61')],function(_0x380eca){_0x380eca['SmsAccountId']=_0x1b1f86[_0x47a5('0x56')]['id'];return _0x380eca;});return db[_0x47a5('0x6e')][_0x47a5('0xad')](_0x583b37,{'transaction':_0x249339});});})[_0x47a5('0x21')](function(){return db[_0x47a5('0x6e')][_0x47a5('0xae')]({'where':{'SmsAccountId':_0x1b1f86[_0x47a5('0x56')]['id']},'order':_0x47a5('0x71')});});}})[_0x47a5('0x21')](respondWithResult(_0x46cb3a,null))[_0x47a5('0x54')](handleError(_0x46cb3a,null));};exports[_0x47a5('0xaf')]=function(_0x40b7a5,_0x28e998,_0x2ac386){var _0x578983={};var _0x3f7fdc={};var _0x272cd0;var _0x150cff;return db[_0x47a5('0x39')][_0x47a5('0x6b')]({'where':{'id':_0x40b7a5[_0x47a5('0x56')]['id']}})[_0x47a5('0x21')](handleEntityNotFound(_0x28e998,null))['then'](function(_0x185104){if(_0x185104){_0x272cd0=_0x185104;_0x3f7fdc['model']=_[_0x47a5('0x40')](db[_0x47a5('0x6e')][_0x47a5('0x58')]);_0x3f7fdc[_0x47a5('0x3f')]=_[_0x47a5('0x40')](_0x40b7a5[_0x47a5('0x3f')]);_0x3f7fdc[_0x47a5('0x41')]=_[_0x47a5('0x42')](_0x3f7fdc['model'],_0x3f7fdc[_0x47a5('0x3f')]);_0x578983[_0x47a5('0x43')]=_[_0x47a5('0x42')](_0x3f7fdc['model'],qs[_0x47a5('0x44')](_0x40b7a5[_0x47a5('0x3f')][_0x47a5('0x44')]));_0x578983[_0x47a5('0x43')]=_0x578983['attributes'][_0x47a5('0x59')]?_0x578983[_0x47a5('0x43')]:_0x3f7fdc[_0x47a5('0x3d')];_0x578983[_0x47a5('0x47')]=qs['sort'](_0x40b7a5[_0x47a5('0x3f')]['sort']);_0x578983['where']=qs[_0x47a5('0x41')](_[_0x47a5('0x4a')](_0x40b7a5[_0x47a5('0x3f')],_0x3f7fdc[_0x47a5('0x41')]));if(_0x40b7a5['query'][_0x47a5('0x4b')]){_0x578983[_0x47a5('0x49')]=_[_0x47a5('0x4c')](_0x578983[_0x47a5('0x49')],{'$or':_[_0x47a5('0x3e')](_0x578983[_0x47a5('0x43')],function(_0x5eae8d){var _0x1da268={};_0x1da268[_0x5eae8d]={'$like':'%'+_0x40b7a5[_0x47a5('0x3f')][_0x47a5('0x4b')]+'%'};return _0x1da268;})});}_0x578983=_[_0x47a5('0x4c')]({},_0x578983,_0x40b7a5[_0x47a5('0x4e')]);return _0x272cd0['getApplications'](_0x578983);}})[_0x47a5('0x21')](function(_0x4c7627){if(_0x4c7627){_0x150cff=_0x4c7627[_0x47a5('0x59')];if(!_0x40b7a5['query'][_0x47a5('0x45')]('nolimit')){_0x578983['limit']=qs[_0x47a5('0x2e')](_0x40b7a5[_0x47a5('0x3f')]['limit']);_0x578983[_0x47a5('0x2d')]=qs[_0x47a5('0x2d')](_0x40b7a5['query'][_0x47a5('0x2d')]);}return _0x272cd0[_0x47a5('0xaf')](_0x578983);}})[_0x47a5('0x21')](function(_0x508622){if(_0x508622){return _0x508622?{'count':_0x150cff,'rows':_0x508622}:null;}})[_0x47a5('0x21')](respondWithResult(_0x28e998,null))[_0x47a5('0x54')](handleError(_0x28e998,null));};exports[_0x47a5('0xb0')]=function(_0x30b0f9,_0x37721c,_0x53cc9e){var _0x5973d4={'raw':![],'where':{}};var _0x2678cb={};var _0x56808d={'count':0x0,'rows':[]};return db[_0x47a5('0x39')][_0x47a5('0x6b')]({'where':{'id':_0x30b0f9['params']['id']}})['then'](handleEntityNotFound(_0x37721c,null))[_0x47a5('0x21')](function(_0x4997bc){if(_0x4997bc){_0x2678cb[_0x47a5('0x3d')]=_[_0x47a5('0x40')](db[_0x47a5('0x95')][_0x47a5('0x58')]);_0x2678cb[_0x47a5('0x3f')]=_[_0x47a5('0x40')](_0x30b0f9[_0x47a5('0x3f')]);_0x2678cb['filters']=_[_0x47a5('0x42')](_0x2678cb['model'],_0x2678cb[_0x47a5('0x3f')]);_0x5973d4[_0x47a5('0x43')]=_[_0x47a5('0x42')](_0x2678cb[_0x47a5('0x3d')],qs[_0x47a5('0x44')](_0x30b0f9[_0x47a5('0x3f')][_0x47a5('0x44')]));_0x5973d4[_0x47a5('0x43')]=_0x5973d4[_0x47a5('0x43')][_0x47a5('0x59')]?_0x5973d4[_0x47a5('0x43')]:_0x2678cb[_0x47a5('0x3d')];if(!_0x30b0f9['query'][_0x47a5('0x45')](_0x47a5('0x46'))){_0x5973d4[_0x47a5('0x2e')]=qs['limit'](_0x30b0f9[_0x47a5('0x3f')][_0x47a5('0x2e')]);_0x5973d4[_0x47a5('0x2d')]=qs[_0x47a5('0x2d')](_0x30b0f9[_0x47a5('0x3f')][_0x47a5('0x2d')]);}_0x5973d4['order']=qs[_0x47a5('0x48')](_0x30b0f9[_0x47a5('0x3f')][_0x47a5('0x48')]);_0x5973d4[_0x47a5('0x49')]=qs[_0x47a5('0x41')](_[_0x47a5('0x4a')](_0x30b0f9[_0x47a5('0x3f')],_0x2678cb[_0x47a5('0x41')]));_0x5973d4[_0x47a5('0x49')][_0x47a5('0x64')]=_0x4997bc['id'];if(_0x30b0f9['query']['filter']){_0x5973d4[_0x47a5('0x49')]=_[_0x47a5('0x4c')](_0x5973d4[_0x47a5('0x49')],{'$or':_['map'](_0x5973d4[_0x47a5('0x43')],function(_0x50b7fc){var _0x522345={};_0x522345[_0x50b7fc]={'$like':'%'+_0x30b0f9[_0x47a5('0x3f')][_0x47a5('0x4b')]+'%'};return _0x522345;})});}_0x5973d4=_[_0x47a5('0x4c')]({},_0x5973d4,_0x30b0f9[_0x47a5('0x4e')]);return db['SmsInteraction'][_0x47a5('0x4f')]({'where':_0x5973d4[_0x47a5('0x49')]})['then'](function(_0x59ba59){_0x56808d['count']=_0x59ba59;if(_0x30b0f9[_0x47a5('0x3f')][_0x47a5('0x50')]){_0x5973d4[_0x47a5('0x51')]=[{'model':db[_0x47a5('0x72')],'as':_0x47a5('0xb1'),'required':![]},{'model':db['User'],'as':'Owner','attributes':[_0x47a5('0x35'),_0x47a5('0xb2'),_0x47a5('0xb3')],'required':![]},{'model':db[_0x47a5('0xb4')],'as':'Tags','attributes':['id',_0x47a5('0x35'),_0x47a5('0xb5')],'where':_0x30b0f9[_0x47a5('0x3f')][_0x47a5('0xb6')]?{'id':_0x30b0f9['query']['tag']}:undefined,'required':_0x30b0f9['query'][_0x47a5('0xb6')]?!![]:![]}];}return db[_0x47a5('0x95')][_0x47a5('0x52')](_0x5973d4);})[_0x47a5('0x21')](function(_0x242006){_0x56808d[_0x47a5('0x53')]=_0x242006;return _0x56808d;});}})[_0x47a5('0x21')](respondWithFilteredResult(_0x37721c,_0x5973d4))[_0x47a5('0x54')](handleError(_0x37721c,null));};exports[_0x47a5('0x36')]=function(_0x5b48d0,_0x40fe75,_0x7b5348){var _0x50b482,_0x34ff37,_0x2bbf95;if(_[_0x47a5('0x8c')](_0x5b48d0[_0x47a5('0x61')]['body'])||_0x5b48d0[_0x47a5('0x61')][_0x47a5('0x61')]===''){throw new db[(_0x47a5('0x1e'))]['ValidationError']('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_[_0x47a5('0x8c')](_0x5b48d0['body']['to'])){throw new db[(_0x47a5('0x1e'))]['ValidationError'](_0x47a5('0xb7'));}_0x50b482=_0x5b48d0[_0x47a5('0x61')]['to'];return db[_0x47a5('0x39')][_0x47a5('0x5a')]({'where':{'id':_0x5b48d0[_0x47a5('0x56')]['id']},'include':[{'model':db['CmList'],'as':'List','include':[{'model':db[_0x47a5('0x72')],'as':_0x47a5('0x93'),'where':{'mobile':_0x50b482},'limit':0x1,'order':[[_0x47a5('0x76'),_0x47a5('0xb8')]]}]}]})['then'](handleEntityNotFound(_0x40fe75,null))['then'](function(_0x3222e4){if(_0x3222e4&&_0x3222e4['List']){_0x34ff37=_0x3222e4[_0x47a5('0x32')]({'plain':!![]});if(_0x34ff37['List']&&_0x34ff37[_0x47a5('0xb9')]['Contacts'][_0x47a5('0x59')]){return _0x34ff37[_0x47a5('0xb9')][_0x47a5('0x93')][0x0];}return db[_0x47a5('0x72')][_0x47a5('0x5b')](_[_0x47a5('0x16')](_0x5b48d0[_0x47a5('0x61')],{'firstName':_0x50b482,'mobile':_0x50b482,'phone':_0x50b482,'ListId':_0x34ff37[_0x47a5('0x77')]}));}})['then'](handleEntityNotFound(_0x40fe75,null))[_0x47a5('0x21')](function(_0x4394f0){if(_0x4394f0){_0x2bbf95=_0x4394f0;return db['SmsInteraction'][_0x47a5('0x5a')]({'where':{'ContactId':_0x2bbf95['id'],'closed':![],'SmsAccountId':_0x34ff37['id']}})[_0x47a5('0x21')](function(_0x54f283){if(_0x54f283){return[_0x54f283,![]];}return db['SmsInteraction'][_0x47a5('0x5b')]({'UserId':_0x5b48d0['user']['id'],'ContactId':_0x2bbf95['id'],'SmsAccountId':_0x34ff37['id'],'phone':_0x50b482,'firstMsgDirection':_0x47a5('0xba'),'Messages':[_[_0x47a5('0x4c')](_0x5b48d0[_0x47a5('0x61')],{'read':![],'body':_0x5b48d0['body'][_0x47a5('0x61')],'phone':_0x50b482,'SmsAccountId':_0x34ff37['id'],'UserId':_0x5b48d0[_0x47a5('0x5c')]['id'],'ContactId':_0x2bbf95['id']})]},{'include':[{'model':db[_0x47a5('0x9a')],'as':_0x47a5('0xbb')}]})[_0x47a5('0x21')](function(_0x454609){return[_0x454609,!![]];});});}})[_0x47a5('0xbc')](function(_0x5c4301,_0x2bc0d8){if(_0x2bc0d8){return _0x5c4301;}return db[_0x47a5('0x9a')][_0x47a5('0x5b')](_[_0x47a5('0x4c')](_0x5b48d0[_0x47a5('0x61')],{'read':![],'body':_0x5b48d0[_0x47a5('0x61')][_0x47a5('0x61')],'phone':_0x50b482,'SmsAccountId':_0x34ff37['id'],'SmsInteractionId':_0x5c4301['id'],'UserId':_0x5b48d0['user']['id'],'ContactId':_0x2bbf95['id']}))['then'](function(_0x11d87b){_0x5c4301[_0x47a5('0xbd')][_0x47a5('0xbb')]=[];_0x5c4301['dataValues']['Messages'][_0x47a5('0xbe')](_0x11d87b[_0x47a5('0xbd')]);return _0x5c4301;});})[_0x47a5('0x21')](respondWithResult(_0x40fe75,null))[_0x47a5('0x54')](handleError(_0x40fe75,null));};exports[_0x47a5('0x2a')]=function(_0x4121c1,_0x2e0add,_0x58e85b){if(_0x4121c1[_0x47a5('0x61')]['id']){delete _0x4121c1[_0x47a5('0x61')]['id'];}console[_0x47a5('0xbf')]('endpoint\x20/status\x20POST\x20/',_0x4121c1[_0x47a5('0x61')]);var _0x611b40,_0x144bc9,_0x278b42;return db[_0x47a5('0x39')][_0x47a5('0x5a')]({'where':{'id':_0x4121c1[_0x47a5('0x56')]['id']}})[_0x47a5('0x21')](handleEntityNotFound(_0x2e0add,null))[_0x47a5('0x21')](function(_0x9ced85){if(_0x9ced85){_0x278b42=_0x9ced85;logger[_0x47a5('0xa6')](_0x47a5('0x25'),_0x47a5('0x2a'),'received\x20delivery\x20report\x20from',_0x9ced85[_0x47a5('0x3b')],util['inspect'](_0x4121c1[_0x47a5('0x61')],{'showHidden':![],'depth':null}));switch(_0x9ced85['type']){case _0x47a5('0x7b'):if(_0x4121c1[_0x47a5('0x61')][_0x47a5('0xc0')]&&_0x4121c1['body'][_0x47a5('0x2a')]){_0x144bc9=_0x4121c1['body'][_0x47a5('0x2a')];return db[_0x47a5('0x9a')][_0x47a5('0x5a')]({'where':{'messageId':_0x4121c1[_0x47a5('0x61')]['skebby_dispatch_id']}});}break;case _0x47a5('0x7d'):if(_0x4121c1['body']['requestid']&&_0x4121c1[_0x47a5('0x61')][_0x47a5('0xc1')]){_0x144bc9=_0x4121c1[_0x47a5('0x61')][_0x47a5('0xc1')];return db[_0x47a5('0x9a')][_0x47a5('0x5a')]({'where':{'messageId':_0x4121c1[_0x47a5('0x61')][_0x47a5('0xc2')]}});}break;case _0x47a5('0xc3'):if(_0x4121c1['body']['message_id']&&_0x4121c1[_0x47a5('0x61')][_0x47a5('0xc4')]){_0x144bc9=_0x4121c1[_0x47a5('0x61')][_0x47a5('0xc4')];return db[_0x47a5('0x9a')]['find']({'where':{'messageId':_0x4121c1[_0x47a5('0x61')][_0x47a5('0x7e')]}});}break;case _0x47a5('0x82'):var _0x50ff41=_0x4121c1['body'][_0x47a5('0x83')][0x0];if(_0x50ff41[_0x47a5('0x7a')]&&_0x50ff41['status'][_0x47a5('0xc5')]===_0x47a5('0xc6')){_0x144bc9=_0x50ff41[_0x47a5('0x2a')]['groupName'];return db[_0x47a5('0x9a')][_0x47a5('0x5a')]({'where':{'messageId':_0x50ff41[_0x47a5('0x7a')]}});}break;case _0x47a5('0x87'):if(_0x4121c1[_0x47a5('0x61')]['messageId']&&_0x4121c1[_0x47a5('0x61')][_0x47a5('0x2a')]){_0x144bc9=_0x4121c1[_0x47a5('0x61')][_0x47a5('0x2a')];return db['SmsMessage']['find']({'where':{'messageId':_0x4121c1[_0x47a5('0x61')]['messageId']}});}break;case _0x47a5('0x8b'):if(_0x4121c1[_0x47a5('0x61')][_0x47a5('0xc7')]&&_0x4121c1[_0x47a5('0x61')][_0x47a5('0x2a')]){_0x144bc9=_0x4121c1[_0x47a5('0x61')]['status'];return db[_0x47a5('0x9a')][_0x47a5('0x5a')]({'where':{'messageId':_0x4121c1[_0x47a5('0x61')]['redif']}});}break;}}})['then'](handleEntityNotFound(_0x2e0add,null))[_0x47a5('0x21')](function(_0x4ebe30){if(_0x4ebe30){_0x611b40=_0x4ebe30;switch(_0x278b42[_0x47a5('0x3b')]){case _0x47a5('0x7b'):if(_0x144bc9===_0x47a5('0xc6')){return _0x611b40[_0x47a5('0x30')]({'read':!![]});}else{logger[_0x47a5('0x26')]('SmsAccount,\x20%s,\x20%s,\x20%s','status',_0x47a5('0x7b'),util[_0x47a5('0xc8')](_0x4121c1[_0x47a5('0x61')],{'showHidden':![],'depth':null}));}break;case _0x47a5('0x7d'):if(_0x144bc9==='1'){return _0x611b40[_0x47a5('0x30')]({'read':!![]});}else{logger['error'](_0x47a5('0x25'),_0x47a5('0x2a'),_0x47a5('0x7b'),util[_0x47a5('0xc8')](_0x4121c1[_0x47a5('0x61')],{'showHidden':![],'depth':null}));}break;case'clicksend':if(!_0x4121c1[_0x47a5('0x61')][_0x47a5('0xc9')]&&_0x144bc9>=0xc8&&_0x144bc9<=0xce){return _0x611b40[_0x47a5('0x30')]({'read':!![]});}else{logger[_0x47a5('0x26')](_0x47a5('0x25'),_0x47a5('0x2a'),_0x47a5('0xc3'),util[_0x47a5('0xc8')](_0x4121c1[_0x47a5('0x61')],{'showHidden':![],'depth':null}));}break;case _0x47a5('0x82'):var _0x2cc493=_0x4121c1['body'][_0x47a5('0x83')][0x0];if(_0x2cc493[_0x47a5('0x2a')][_0x47a5('0xc5')]===_0x47a5('0xc6')){return _0x611b40['update']({'read':!![]});}else{logger['error']('SmsAccount,\x20%s,\x20%s,\x20%s',_0x47a5('0x2a'),'infobip',util[_0x47a5('0xc8')](_0x4121c1[_0x47a5('0x61')],{'showHidden':![],'depth':null}));}break;case'clickatell':if(_0x144bc9==_0x47a5('0xca')||_0x144bc9==_0x47a5('0xcb')){return _0x611b40[_0x47a5('0x30')]({'read':!![]});}else{logger['error'](_0x47a5('0x25'),'status',_0x47a5('0x87'),util[_0x47a5('0xc8')](_0x4121c1[_0x47a5('0x61')],{'showHidden':![],'depth':null}));}break;case _0x47a5('0x8b'):if(_0x144bc9===_0x47a5('0xcc')||_0x144bc9===_0x47a5('0xcd')){return _0x611b40['update']({'read':!![]});}else{logger['error']('SmsAccount,\x20%s,\x20%s,\x20%s',_0x47a5('0x2a'),_0x47a5('0x8b'),util[_0x47a5('0xc8')](_0x4121c1[_0x47a5('0x61')],{'showHidden':![],'depth':null}));}break;}return _0x611b40;}})[_0x47a5('0x21')](respondWithResult(_0x2e0add,null))[_0x47a5('0x54')](handleError(_0x2e0add,null));};exports[_0x47a5('0xce')]=function(_0x138b92,_0x232c36,_0x25954e){var _0x277061,_0x3917e0,_0x1c7695;return db[_0x47a5('0x39')][_0x47a5('0x5a')]({'where':{'id':_0x138b92[_0x47a5('0x56')]['id']}})['then'](handleEntityNotFound(_0x232c36,null))[_0x47a5('0x21')](function(_0x46b82a){if(_0x46b82a){_0x1c7695=_0x46b82a;logger[_0x47a5('0xa6')](_0x47a5('0x25'),_0x47a5('0x2a'),_0x47a5('0xcf'),_0x46b82a[_0x47a5('0x3b')],util[_0x47a5('0xc8')](_0x138b92['query'],{'showHidden':![],'depth':null}));switch(_0x46b82a[_0x47a5('0x3b')]){case'csc':if(_0x138b92[_0x47a5('0x3f')][_0x47a5('0xd0')]&&_0x138b92['query'][_0x47a5('0xd1')]){_0x3917e0=_0x138b92['query'][_0x47a5('0xd1')];return db[_0x47a5('0x9a')][_0x47a5('0x5a')]({'where':{'messageId':_0x138b92[_0x47a5('0x3f')][_0x47a5('0xd0')]}});}break;}}})['then'](handleEntityNotFound(_0x232c36,null))[_0x47a5('0x21')](function(_0x9a2f87){if(_0x9a2f87){_0x277061=_0x9a2f87;switch(_0x1c7695[_0x47a5('0x3b')]){case'csc':if(_0x3917e0==='2'||_0x3917e0==='6'){return _0x277061['update']({'read':!![]});}else{logger[_0x47a5('0x26')](_0x47a5('0x25'),_0x47a5('0x2a'),'csc',util[_0x47a5('0xc8')](_0x138b92[_0x47a5('0x3f')],{'showHidden':![],'depth':null}));};break;}return _0x277061;}})[_0x47a5('0x21')](respondWithResult(_0x232c36,null))['catch'](handleError(_0x232c36,null));};exports[_0x47a5('0xd2')]=function(_0x3136f9,_0x3ecc43,_0xf4b1df){return db['SmsAccount'][_0x47a5('0x5a')]({'where':{'id':_0x3136f9['params']['id']}})[_0x47a5('0x21')](handleEntityNotFound(_0x3ecc43,null))[_0x47a5('0x21')](function(_0xdc5eac){if(_0xdc5eac){return _0xdc5eac[_0x47a5('0xd2')](_0x3136f9['body'][_0x47a5('0x68')],_[_0x47a5('0xd3')](_0x3136f9[_0x47a5('0x61')],[_0x47a5('0x68'),'id'])||{})[_0x47a5('0xbc')](function(_0x4c2b0c){for(var _0xbe3a38=0x0;_0xbe3a38<_0x3136f9[_0x47a5('0x61')][_0x47a5('0x68')][_0x47a5('0x59')];_0xbe3a38+=0x1){socket[_0x47a5('0xd4')](_0x47a5('0xd5'),{'UserId':_0x3136f9['body'][_0x47a5('0x68')][_0xbe3a38],'SmsAccountId':_0x3136f9[_0x47a5('0x56')]['id']});}return _0x4c2b0c;});}})['then'](respondWithResult(_0x3ecc43,null))['catch'](handleError(_0x3ecc43,null));};exports[_0x47a5('0xd6')]=function(_0x32d299,_0x20d99b,_0x3964f8){return db[_0x47a5('0x39')][_0x47a5('0x5a')]({'where':{'id':_0x32d299['params']['id']}})['then'](handleEntityNotFound(_0x20d99b,null))[_0x47a5('0x21')](function(_0xa3a516){if(_0xa3a516){return _0xa3a516['removeAgents'](_0x32d299[_0x47a5('0x3f')][_0x47a5('0x68')])['then'](function(){if(_[_0x47a5('0xd7')](_0x32d299['query']['ids'])){for(var _0x4aeaff=0x0;_0x4aeaff<_0x32d299[_0x47a5('0x3f')][_0x47a5('0x68')][_0x47a5('0x59')];_0x4aeaff+=0x1){socket['emit'](_0x47a5('0xd8'),{'UserId':Number(_0x32d299['query'][_0x47a5('0x68')][_0x4aeaff]),'SmsAccountId':Number(_0x32d299['params']['id'])});}}else{socket[_0x47a5('0xd4')](_0x47a5('0xd8'),{'UserId':Number(_0x32d299[_0x47a5('0x3f')][_0x47a5('0x68')]),'SmsAccountId':Number(_0x32d299[_0x47a5('0x56')]['id'])});}});}})[_0x47a5('0x21')](respondWithStatusCode(_0x20d99b,null))[_0x47a5('0x54')](handleError(_0x20d99b,null));};exports[_0x47a5('0xd9')]=function(_0x1396c2,_0x5c9091,_0x4f1e24){var _0x24c88e={};var _0xa859a={};var _0x5270cc;var _0x2a0f45;return db[_0x47a5('0x39')][_0x47a5('0x6b')]({'where':{'id':_0x1396c2[_0x47a5('0x56')]['id']}})[_0x47a5('0x21')](handleEntityNotFound(_0x5c9091,null))[_0x47a5('0x21')](function(_0x969d4b){if(_0x969d4b){_0x5270cc=_0x969d4b;_0xa859a[_0x47a5('0x3d')]=_[_0x47a5('0x40')](db[_0x47a5('0x9d')]['rawAttributes']);_0xa859a['query']=_['keys'](_0x1396c2['query']);_0xa859a[_0x47a5('0x41')]=_['intersection'](_0xa859a[_0x47a5('0x3d')],_0xa859a[_0x47a5('0x3f')]);_0x24c88e['attributes']=_[_0x47a5('0x42')](_0xa859a[_0x47a5('0x3d')],qs[_0x47a5('0x44')](_0x1396c2[_0x47a5('0x3f')][_0x47a5('0x44')]));_0x24c88e[_0x47a5('0x43')]=_0x24c88e['attributes'][_0x47a5('0x59')]?_0x24c88e[_0x47a5('0x43')]:_0xa859a['model'];_0x24c88e[_0x47a5('0x47')]=qs['sort'](_0x1396c2[_0x47a5('0x3f')][_0x47a5('0x48')]);_0x24c88e[_0x47a5('0x49')]=qs[_0x47a5('0x41')](_[_0x47a5('0x4a')](_0x1396c2[_0x47a5('0x3f')],_0xa859a[_0x47a5('0x41')]));if(_0x1396c2['query'][_0x47a5('0x4b')]){_0x24c88e[_0x47a5('0x49')]=_['merge'](_0x24c88e[_0x47a5('0x49')],{'$or':_[_0x47a5('0x3e')](_0x24c88e['attributes'],function(_0x14c968){var _0x5a7920={};_0x5a7920[_0x14c968]={'$like':'%'+_0x1396c2[_0x47a5('0x3f')][_0x47a5('0x4b')]+'%'};return _0x5a7920;})});}_0x24c88e=_[_0x47a5('0x4c')]({},_0x24c88e,_0x1396c2[_0x47a5('0x4e')]);return _0x5270cc[_0x47a5('0xd9')](_0x24c88e);}})['then'](function(_0x4b8b65){if(_0x4b8b65){_0x2a0f45=_0x4b8b65[_0x47a5('0x59')];if(!_0x1396c2['query']['hasOwnProperty']('nolimit')){_0x24c88e[_0x47a5('0x2e')]=qs['limit'](_0x1396c2[_0x47a5('0x3f')][_0x47a5('0x2e')]);_0x24c88e[_0x47a5('0x2d')]=qs['offset'](_0x1396c2['query'][_0x47a5('0x2d')]);}return _0x5270cc['getAgents'](_0x24c88e);}})['then'](function(_0xe87e6e){if(_0xe87e6e){return _0xe87e6e?{'count':_0x2a0f45,'rows':_0xe87e6e}:null;}})['then'](respondWithResult(_0x5c9091,null))['catch'](handleError(_0x5c9091,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