4ab3c1db98dece740526387673d0614f2f3f35df
[motion2.git] / server / api / smsAccount / smsAccount.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xc53f=['addAnswer','CannedAnswer','getAnswers','removeAnswers','notify','SmsApplication','Applications','account','applications','orderBy','priority','asc','CmContact','Sequelize','no\x20available\x20attributes','difference','createdAt','updatedAt','CompanyId','Body','MessageSid','skebby','from','connectel','clicksend','messageId','message_id','plivo','From','MessageUUID','results','text','csc','originatingAddress','segmentedMessage','clickatell','fromNumber','replyMessageId','bandwidth','intelepeer','refid','ValidationError','from\x20is\x20mandatory','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','mapKey','CmList','Contacts','DESC','list','omit','contact','SmsInteraction','spread','interaction','created','autoclose','push','close','unmanaged','SmsMessage','ContactId','UserId','User','unshift','waitForTheAssignedAgent','*,*,*,*','Start','startRouting','receiveMessage','entity\x20found','SmsAccount,\x20%s,\x20%s,\x20%s,\x20%s','twilio','Content-Type','addApplications','sequelize','transaction','bulkCreate','findAndCountAll','getApplications','getInteractions','Contact','Owner','fullname','internal','Tags','tag','isNil','body\x20is\x20mandatory\x20and\x20not\x20empty','to\x20is\x20mandatory','List','defaults','ListId','out','Messages','dataValues','skebby_dispatch_id','requestid','status_code','infobip','groupName','DELIVERED','redif','error_code','inspect','DELIVERED_TO_GATEWAY','RECEIVED_BY_RECIPIENT','message-delivered','DELIVRD','ACCEPTD','statusGet','received\x20delivery\x20report\x20from','message-id','state','addAgents','emit','userSmsAccount:save','removeAgents','isArray','getAgents','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','util','path','sox','to-csv','ejs','fs-extra','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','localhost','socket.io-emitter','./smsAccount.socket','register','jayson/promise','client','http','then','info','SmsAccount,\x20%s,\x20%s','debug','SmsAccount,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','sendStatus','status','json','offset','undefined','limit','count','set','Content-Range','reject','save','update','destroy','SmsAccounts','UserProfileResource','end','stack','name','send','Pause','mandatoryDispositionPause','map','rawAttributes','type','key','model','keys','filters','query','intersection','fields','length','attributes','hasOwnProperty','order','sort','where','filter','VIRTUAL','options','SmsAccount','include','rows','catch','show','params','includeAll','merge','create','body','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','find','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','addDisposition','SmsAccountId','Disposition','getDispositions','findOne','nolimit','pick','findAll','removeDispositions','ids'];(function(_0x10ae24,_0x3c9d3e){var _0x591ab4=function(_0x263931){while(--_0x263931){_0x10ae24['push'](_0x10ae24['shift']());}};_0x591ab4(++_0x3c9d3e);}(_0xc53f,0x77));var _0xfc53=function(_0xa464c9,_0x7c86d8){_0xa464c9=_0xa464c9-0x0;var _0x3d73c4=_0xc53f[_0xa464c9];return _0x3d73c4;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xfc53('0x0'));var zipdir=require(_0xfc53('0x1'));var jsonpatch=require(_0xfc53('0x2'));var rp=require(_0xfc53('0x3'));var moment=require('moment');var BPromise=require(_0xfc53('0x4'));var Mustache=require('mustache');var util=require(_0xfc53('0x5'));var path=require(_0xfc53('0x6'));var sox=require(_0xfc53('0x7'));var csv=require(_0xfc53('0x8'));var ejs=require(_0xfc53('0x9'));var fs=require('fs');var fs_extra=require(_0xfc53('0xa'));var _=require('lodash');var squel=require('squel');var crypto=require(_0xfc53('0xb'));var jsforce=require(_0xfc53('0xc'));var deskjs=require(_0xfc53('0xd'));var toCsv=require(_0xfc53('0x8'));var querystring=require(_0xfc53('0xe'));var Papa=require(_0xfc53('0xf'));var Redis=require('ioredis');var authService=require(_0xfc53('0x10'));var qs=require('../../components/parsers/qs');var as=require(_0xfc53('0x11'));var hardwareService=require(_0xfc53('0x12'));var logger=require(_0xfc53('0x13'))(_0xfc53('0x14'));var utils=require(_0xfc53('0x15'));var config=require(_0xfc53('0x16'));var licenseUtil=require(_0xfc53('0x17'));var db=require(_0xfc53('0x18'))['db'];config[_0xfc53('0x19')]=_['defaults'](config['redis'],{'host':_0xfc53('0x1a'),'port':0x18eb});var socket=require(_0xfc53('0x1b'))(new Redis(config[_0xfc53('0x19')]));require(_0xfc53('0x1c'))[_0xfc53('0x1d')](socket);var jayson=require(_0xfc53('0x1e'));var client=jayson[_0xfc53('0x1f')][_0xfc53('0x20')]({'port':0x232c});function respondWithRpcPromise(_0x3286a3,_0x164fb2,_0x5f54b8,_0x25b44d){return new BPromise(function(_0x341c18,_0x511727){var _0x215dd2=_0x25b44d||client;return _0x215dd2['request'](_0x3286a3,_0x5f54b8)[_0xfc53('0x21')](function(_0x500c72){logger[_0xfc53('0x22')](_0xfc53('0x23'),_0x164fb2,'request\x20sent');logger[_0xfc53('0x24')](_0xfc53('0x25'),_0x164fb2,_0xfc53('0x26'),JSON[_0xfc53('0x27')](_0x500c72));if(_0x500c72[_0xfc53('0x28')]){if(_0x500c72[_0xfc53('0x28')][_0xfc53('0x29')]===0x1f4){logger[_0xfc53('0x28')]('SmsAccount,\x20%s,\x20%s',_0x164fb2,_0x500c72[_0xfc53('0x28')][_0xfc53('0x2a')]);return _0x511727(_0x500c72[_0xfc53('0x28')][_0xfc53('0x2a')]);}logger[_0xfc53('0x28')]('SmsAccount,\x20%s,\x20%s',_0x164fb2,_0x500c72[_0xfc53('0x28')][_0xfc53('0x2a')]);return _0x341c18(_0x500c72[_0xfc53('0x28')][_0xfc53('0x2a')]);}else{logger['info'](_0xfc53('0x23'),_0x164fb2,_0xfc53('0x26'));_0x341c18(_0x500c72['result'][_0xfc53('0x2a')]);}})['catch'](function(_0x562779){logger[_0xfc53('0x28')](_0xfc53('0x23'),_0x164fb2,_0x562779);_0x511727(_0x562779);});});}function respondWithStatusCode(_0x1172ad,_0x11d2c4){_0x11d2c4=_0x11d2c4||0xcc;return function(_0xc6e4c0){if(_0xc6e4c0){return _0x1172ad[_0xfc53('0x2b')](_0x11d2c4);}return _0x1172ad[_0xfc53('0x2c')](_0x11d2c4)['end']();};}function respondWithResult(_0x12e0f7,_0x1c3bfa){_0x1c3bfa=_0x1c3bfa||0xc8;return function(_0x5e6e84){if(_0x5e6e84){return _0x12e0f7[_0xfc53('0x2c')](_0x1c3bfa)[_0xfc53('0x2d')](_0x5e6e84);}};}function respondWithFilteredResult(_0x1f52c4,_0x1a2a9c){return function(_0x5b3341){if(_0x5b3341){var _0x5651c5=typeof _0x1a2a9c[_0xfc53('0x2e')]===_0xfc53('0x2f')&&typeof _0x1a2a9c[_0xfc53('0x30')]==='undefined';var _0x28d9ca=_0x5b3341[_0xfc53('0x31')];var _0x558f98=_0x5651c5?0x0:_0x1a2a9c[_0xfc53('0x2e')];var _0x3c5403=_0x5651c5?_0x5b3341['count']:_0x1a2a9c[_0xfc53('0x2e')]+_0x1a2a9c[_0xfc53('0x30')];var _0x4a3b1c;if(_0x3c5403>=_0x28d9ca){_0x3c5403=_0x28d9ca;_0x4a3b1c=0xc8;}else{_0x4a3b1c=0xce;}_0x1f52c4['status'](_0x4a3b1c);return _0x1f52c4[_0xfc53('0x32')](_0xfc53('0x33'),_0x558f98+'-'+_0x3c5403+'/'+_0x28d9ca)[_0xfc53('0x2d')](_0x5b3341);}return null;};}function patchUpdates(_0x1809ac){return function(_0x3e5a0b){try{jsonpatch['apply'](_0x3e5a0b,_0x1809ac,!![]);}catch(_0x54123b){return BPromise[_0xfc53('0x34')](_0x54123b);}return _0x3e5a0b[_0xfc53('0x35')]();};}function saveUpdates(_0x23777b,_0x1bb60e){return function(_0x4a0272){if(_0x4a0272){return _0x4a0272[_0xfc53('0x36')](_0x23777b)['then'](function(_0x1ec267){return _0x1ec267;});}return null;};}function removeEntity(_0x1201fd,_0x2f33b5){return function(_0x39714e){if(_0x39714e){return _0x39714e[_0xfc53('0x37')]()[_0xfc53('0x21')](function(){var _0x4b01b7=_0x39714e['get']({'plain':!![]});var _0x29764c=_0xfc53('0x38');return db[_0xfc53('0x39')][_0xfc53('0x37')]({'where':{'type':_0x29764c,'resourceId':_0x4b01b7['id']}})[_0xfc53('0x21')](function(){return _0x39714e;});})[_0xfc53('0x21')](function(){_0x1201fd[_0xfc53('0x2c')](0xcc)[_0xfc53('0x3a')]();});}};}function handleEntityNotFound(_0x530250,_0x4486ba){return function(_0x142040){if(!_0x142040){_0x530250[_0xfc53('0x2b')](0x194);}return _0x142040;};}function handleError(_0x3a86fd,_0x50e7a0){_0x50e7a0=_0x50e7a0||0x1f4;return function(_0x324cfb){logger[_0xfc53('0x28')](_0x324cfb[_0xfc53('0x3b')]);if(_0x324cfb[_0xfc53('0x3c')]){delete _0x324cfb[_0xfc53('0x3c')];}_0x3a86fd[_0xfc53('0x2c')](_0x50e7a0)[_0xfc53('0x3d')](_0x324cfb);};}exports['index']=function(_0xb1595,_0x4ec138){var _0x293f6a={'include':[{'model':db[_0xfc53('0x3e')],'as':_0xfc53('0x3f')}]},_0x12257d={},_0x2a52fa={'count':0x0,'rows':[]};var _0x2155de=_[_0xfc53('0x40')](db['SmsAccount'][_0xfc53('0x41')],function(_0x1b0729){return{'name':_0x1b0729['fieldName'],'type':_0x1b0729[_0xfc53('0x42')][_0xfc53('0x43')]};});_0x12257d[_0xfc53('0x44')]=_[_0xfc53('0x40')](_0x2155de,_0xfc53('0x3c'));_0x12257d['query']=_[_0xfc53('0x45')](_0xb1595['query']);_0x12257d[_0xfc53('0x46')]=_['intersection'](_0x12257d['model'],_0x12257d[_0xfc53('0x47')]);_0x293f6a['attributes']=_[_0xfc53('0x48')](_0x12257d[_0xfc53('0x44')],qs[_0xfc53('0x49')](_0xb1595[_0xfc53('0x47')]['fields']));_0x293f6a['attributes']=_0x293f6a['attributes'][_0xfc53('0x4a')]?_0x293f6a[_0xfc53('0x4b')]:_0x12257d['model'];if(!_0xb1595['query'][_0xfc53('0x4c')]('nolimit')){_0x293f6a['limit']=qs['limit'](_0xb1595['query'][_0xfc53('0x30')]);_0x293f6a[_0xfc53('0x2e')]=qs['offset'](_0xb1595[_0xfc53('0x47')]['offset']);}_0x293f6a[_0xfc53('0x4d')]=qs[_0xfc53('0x4e')](_0xb1595[_0xfc53('0x47')][_0xfc53('0x4e')]);_0x293f6a[_0xfc53('0x4f')]=qs['filters'](_['pick'](_0xb1595[_0xfc53('0x47')],_0x12257d[_0xfc53('0x46')]),_0x2155de);if(_0xb1595['query'][_0xfc53('0x50')]){_0x293f6a[_0xfc53('0x4f')]=_['merge'](_0x293f6a[_0xfc53('0x4f')],{'$or':_[_0xfc53('0x40')](_0x2155de,function(_0x5dd544){if(_0x5dd544['type']!==_0xfc53('0x51')){var _0xac25de={};_0xac25de[_0x5dd544[_0xfc53('0x3c')]]={'$like':'%'+_0xb1595[_0xfc53('0x47')][_0xfc53('0x50')]+'%'};return _0xac25de;}})});}_0x293f6a=_['merge']({},_0x293f6a,_0xb1595[_0xfc53('0x52')]);var _0x5ef4a0={'where':_0x293f6a[_0xfc53('0x4f')]};return db[_0xfc53('0x53')][_0xfc53('0x31')](_0x5ef4a0)[_0xfc53('0x21')](function(_0x52fb9e){_0x2a52fa[_0xfc53('0x31')]=_0x52fb9e;if(_0xb1595[_0xfc53('0x47')]['includeAll']){_0x293f6a[_0xfc53('0x54')]=[{'all':!![]}];}return db[_0xfc53('0x53')]['findAll'](_0x293f6a);})['then'](function(_0x3720e8){_0x2a52fa[_0xfc53('0x55')]=_0x3720e8;return _0x2a52fa;})[_0xfc53('0x21')](respondWithFilteredResult(_0x4ec138,_0x293f6a))[_0xfc53('0x56')](handleError(_0x4ec138,null));};exports[_0xfc53('0x57')]=function(_0x4c6219,_0x9631d3){var _0x4b973f={'raw':![],'where':{'id':_0x4c6219[_0xfc53('0x58')]['id']},'include':[{'model':db[_0xfc53('0x3e')],'as':_0xfc53('0x3f')}]},_0x4bc3e6={};_0x4bc3e6['model']=_[_0xfc53('0x45')](db[_0xfc53('0x53')][_0xfc53('0x41')]);_0x4bc3e6['query']=_[_0xfc53('0x45')](_0x4c6219[_0xfc53('0x47')]);_0x4bc3e6[_0xfc53('0x46')]=_[_0xfc53('0x48')](_0x4bc3e6[_0xfc53('0x44')],_0x4bc3e6[_0xfc53('0x47')]);_0x4b973f[_0xfc53('0x4b')]=_[_0xfc53('0x48')](_0x4bc3e6[_0xfc53('0x44')],qs['fields'](_0x4c6219[_0xfc53('0x47')][_0xfc53('0x49')]));_0x4b973f[_0xfc53('0x4b')]=_0x4b973f[_0xfc53('0x4b')]['length']?_0x4b973f['attributes']:_0x4bc3e6[_0xfc53('0x44')];if(_0x4c6219[_0xfc53('0x47')][_0xfc53('0x59')]){_0x4b973f[_0xfc53('0x54')]=[{'all':!![]}];}_0x4b973f=_[_0xfc53('0x5a')]({},_0x4b973f,_0x4c6219[_0xfc53('0x52')]);return db[_0xfc53('0x53')]['find'](_0x4b973f)[_0xfc53('0x21')](handleEntityNotFound(_0x9631d3,null))[_0xfc53('0x21')](respondWithResult(_0x9631d3,null))[_0xfc53('0x56')](handleError(_0x9631d3,null));};exports[_0xfc53('0x5b')]=function(_0x12a8a9,_0x3f4ac5){return db['SmsAccount'][_0xfc53('0x5b')](_0x12a8a9[_0xfc53('0x5c')],{})[_0xfc53('0x21')](function(_0x1d7757){var _0x1bb37e=_0x12a8a9[_0xfc53('0x5d')][_0xfc53('0x5e')]({'plain':!![]});if(!_0x1bb37e)throw new Error(_0xfc53('0x5f'));if(_0x1bb37e[_0xfc53('0x60')]===_0xfc53('0x5d')){var _0x74d8d5=_0x1d7757[_0xfc53('0x5e')]({'plain':!![]});var _0x220359=_0xfc53('0x38');return db[_0xfc53('0x61')][_0xfc53('0x62')]({'where':{'name':_0x220359,'userProfileId':_0x1bb37e[_0xfc53('0x63')]},'raw':!![]})[_0xfc53('0x21')](function(_0xe4d471){if(_0xe4d471&&_0xe4d471[_0xfc53('0x64')]===0x0){return db['UserProfileResource'][_0xfc53('0x5b')]({'name':_0x74d8d5['name'],'resourceId':_0x74d8d5['id'],'type':_0xe4d471[_0xfc53('0x3c')],'sectionId':_0xe4d471['id']},{})[_0xfc53('0x21')](function(){return _0x1d7757;});}else{return _0x1d7757;}})[_0xfc53('0x56')](function(_0x28079f){logger[_0xfc53('0x28')](_0xfc53('0x65'),_0x28079f);throw _0x28079f;});}return _0x1d7757;})['then'](respondWithResult(_0x3f4ac5,0xc9))[_0xfc53('0x56')](handleError(_0x3f4ac5,null));};exports[_0xfc53('0x36')]=function(_0xda06ca,_0x228929){if(_0xda06ca['body']['id']){delete _0xda06ca['body']['id'];}return db[_0xfc53('0x53')]['find']({'where':{'id':_0xda06ca[_0xfc53('0x58')]['id']},'include':[{'model':db[_0xfc53('0x3e')],'as':_0xfc53('0x3f')}]})['then'](handleEntityNotFound(_0x228929,null))[_0xfc53('0x21')](saveUpdates(_0xda06ca[_0xfc53('0x5c')],null))[_0xfc53('0x21')](respondWithResult(_0x228929,null))['catch'](handleError(_0x228929,null));};exports['destroy']=function(_0xf0373d,_0x151b2d){return db['SmsAccount'][_0xfc53('0x62')]({'where':{'id':_0xf0373d['params']['id']}})[_0xfc53('0x21')](handleEntityNotFound(_0x151b2d,null))[_0xfc53('0x21')](removeEntity(_0x151b2d,null))[_0xfc53('0x56')](handleError(_0x151b2d,null));};exports[_0xfc53('0x66')]=function(_0x2a098a,_0x301a6c){return db[_0xfc53('0x53')][_0xfc53('0x66')]()[_0xfc53('0x21')](respondWithResult(_0x301a6c,null))['catch'](handleError(_0x301a6c,null));};exports[_0xfc53('0x67')]=function(_0x3011d8,_0xeb24a2,_0x486576){if(_0x3011d8[_0xfc53('0x5c')]['id']){delete _0x3011d8[_0xfc53('0x5c')]['id'];}return db[_0xfc53('0x53')][_0xfc53('0x62')]({'where':{'id':_0x3011d8[_0xfc53('0x58')]['id']}})[_0xfc53('0x21')](handleEntityNotFound(_0xeb24a2,null))['then'](function(_0x5716c5){if(_0x5716c5){_0x3011d8[_0xfc53('0x5c')][_0xfc53('0x68')]=_0x5716c5['id'];return db[_0xfc53('0x69')]['create'](_0x3011d8[_0xfc53('0x5c')]);}})[_0xfc53('0x21')](respondWithResult(_0xeb24a2,null))['catch'](handleError(_0xeb24a2,null));};exports[_0xfc53('0x6a')]=function(_0x2f528f,_0x3c88ba,_0x3ac58a){var _0x20e780={'raw':![],'where':{}};var _0x585f54={};var _0x59d6a3={'count':0x0,'rows':[]};return db[_0xfc53('0x53')][_0xfc53('0x6b')]({'where':{'id':_0x2f528f[_0xfc53('0x58')]['id']}})[_0xfc53('0x21')](handleEntityNotFound(_0x3c88ba,null))['then'](function(_0x52f7c6){if(_0x52f7c6){_0x585f54[_0xfc53('0x44')]=_[_0xfc53('0x45')](db['Disposition'][_0xfc53('0x41')]);_0x585f54[_0xfc53('0x47')]=_[_0xfc53('0x45')](_0x2f528f['query']);_0x585f54[_0xfc53('0x46')]=_[_0xfc53('0x48')](_0x585f54[_0xfc53('0x44')],_0x585f54[_0xfc53('0x47')]);_0x20e780[_0xfc53('0x4b')]=_[_0xfc53('0x48')](_0x585f54['model'],qs[_0xfc53('0x49')](_0x2f528f['query'][_0xfc53('0x49')]));_0x20e780[_0xfc53('0x4b')]=_0x20e780[_0xfc53('0x4b')][_0xfc53('0x4a')]?_0x20e780[_0xfc53('0x4b')]:_0x585f54[_0xfc53('0x44')];if(!_0x2f528f[_0xfc53('0x47')][_0xfc53('0x4c')](_0xfc53('0x6c'))){_0x20e780[_0xfc53('0x30')]=qs[_0xfc53('0x30')](_0x2f528f[_0xfc53('0x47')][_0xfc53('0x30')]);_0x20e780[_0xfc53('0x2e')]=qs['offset'](_0x2f528f['query']['offset']);}_0x20e780[_0xfc53('0x4d')]=qs[_0xfc53('0x4e')](_0x2f528f[_0xfc53('0x47')][_0xfc53('0x4e')]);_0x20e780['where']=qs['filters'](_[_0xfc53('0x6d')](_0x2f528f[_0xfc53('0x47')],_0x585f54['filters']));_0x20e780['where'][_0xfc53('0x68')]=_0x52f7c6['id'];if(_0x2f528f[_0xfc53('0x47')][_0xfc53('0x50')]){_0x20e780[_0xfc53('0x4f')]=_[_0xfc53('0x5a')](_0x20e780[_0xfc53('0x4f')],{'$or':_[_0xfc53('0x40')](_0x20e780['attributes'],function(_0xec3024){var _0x2730d9={};_0x2730d9[_0xec3024]={'$like':'%'+_0x2f528f[_0xfc53('0x47')]['filter']+'%'};return _0x2730d9;})});}_0x20e780=_[_0xfc53('0x5a')]({},_0x20e780,_0x2f528f[_0xfc53('0x52')]);return db[_0xfc53('0x69')]['count']({'where':_0x20e780[_0xfc53('0x4f')]})[_0xfc53('0x21')](function(_0x1cc080){_0x59d6a3[_0xfc53('0x31')]=_0x1cc080;if(_0x2f528f[_0xfc53('0x47')][_0xfc53('0x59')]){_0x20e780[_0xfc53('0x54')]=[{'all':!![]}];}return db[_0xfc53('0x69')][_0xfc53('0x6e')](_0x20e780);})[_0xfc53('0x21')](function(_0x2a1690){_0x59d6a3[_0xfc53('0x55')]=_0x2a1690;return _0x59d6a3;});}})[_0xfc53('0x21')](respondWithFilteredResult(_0x3c88ba,_0x20e780))[_0xfc53('0x56')](handleError(_0x3c88ba,null));};exports[_0xfc53('0x6f')]=function(_0x1b9686,_0xef0a0d,_0x331071){return db['SmsAccount'][_0xfc53('0x62')]({'where':{'id':_0x1b9686[_0xfc53('0x58')]['id']}})['then'](handleEntityNotFound(_0xef0a0d,null))[_0xfc53('0x21')](function(_0x4b50af){if(_0x4b50af){return _0x4b50af[_0xfc53('0x6f')](_0x1b9686[_0xfc53('0x47')][_0xfc53('0x70')]);}})['then'](respondWithStatusCode(_0xef0a0d,null))[_0xfc53('0x56')](handleError(_0xef0a0d,null));};exports[_0xfc53('0x71')]=function(_0x1fd5a8,_0xb263b9,_0xba9c98){if(_0x1fd5a8[_0xfc53('0x5c')]['id']){delete _0x1fd5a8[_0xfc53('0x5c')]['id'];}return db[_0xfc53('0x53')][_0xfc53('0x62')]({'where':{'id':_0x1fd5a8[_0xfc53('0x58')]['id']}})[_0xfc53('0x21')](handleEntityNotFound(_0xb263b9,null))['then'](function(_0x5933d9){if(_0x5933d9){_0x1fd5a8[_0xfc53('0x5c')][_0xfc53('0x68')]=_0x5933d9['id'];return db[_0xfc53('0x72')][_0xfc53('0x5b')](_0x1fd5a8[_0xfc53('0x5c')]);}})[_0xfc53('0x21')](respondWithResult(_0xb263b9,null))[_0xfc53('0x56')](handleError(_0xb263b9,null));};exports[_0xfc53('0x73')]=function(_0x39cdbf,_0x335171,_0x588ccb){var _0x229455={'raw':![],'where':{}};var _0x4ce4e3={};var _0x55fa8b={'count':0x0,'rows':[]};return db['SmsAccount'][_0xfc53('0x6b')]({'where':{'id':_0x39cdbf['params']['id']}})[_0xfc53('0x21')](handleEntityNotFound(_0x335171,null))[_0xfc53('0x21')](function(_0x4e75b3){if(_0x4e75b3){_0x4ce4e3['model']=_[_0xfc53('0x45')](db[_0xfc53('0x72')]['rawAttributes']);_0x4ce4e3[_0xfc53('0x47')]=_[_0xfc53('0x45')](_0x39cdbf[_0xfc53('0x47')]);_0x4ce4e3[_0xfc53('0x46')]=_[_0xfc53('0x48')](_0x4ce4e3['model'],_0x4ce4e3[_0xfc53('0x47')]);_0x229455['attributes']=_[_0xfc53('0x48')](_0x4ce4e3[_0xfc53('0x44')],qs[_0xfc53('0x49')](_0x39cdbf['query'][_0xfc53('0x49')]));_0x229455[_0xfc53('0x4b')]=_0x229455[_0xfc53('0x4b')][_0xfc53('0x4a')]?_0x229455[_0xfc53('0x4b')]:_0x4ce4e3[_0xfc53('0x44')];if(!_0x39cdbf[_0xfc53('0x47')]['hasOwnProperty']('nolimit')){_0x229455[_0xfc53('0x30')]=qs['limit'](_0x39cdbf[_0xfc53('0x47')][_0xfc53('0x30')]);_0x229455[_0xfc53('0x2e')]=qs['offset'](_0x39cdbf[_0xfc53('0x47')]['offset']);}_0x229455[_0xfc53('0x4d')]=qs[_0xfc53('0x4e')](_0x39cdbf[_0xfc53('0x47')][_0xfc53('0x4e')]);_0x229455[_0xfc53('0x4f')]=qs['filters'](_['pick'](_0x39cdbf[_0xfc53('0x47')],_0x4ce4e3[_0xfc53('0x46')]));_0x229455[_0xfc53('0x4f')][_0xfc53('0x68')]=_0x4e75b3['id'];if(_0x39cdbf[_0xfc53('0x47')]['filter']){_0x229455['where']=_['merge'](_0x229455[_0xfc53('0x4f')],{'$or':_['map'](_0x229455[_0xfc53('0x4b')],function(_0x190670){var _0x25cb25={};_0x25cb25[_0x190670]={'$like':'%'+_0x39cdbf[_0xfc53('0x47')][_0xfc53('0x50')]+'%'};return _0x25cb25;})});}_0x229455=_['merge']({},_0x229455,_0x39cdbf['options']);return db[_0xfc53('0x72')][_0xfc53('0x31')]({'where':_0x229455['where']})[_0xfc53('0x21')](function(_0x1f8508){_0x55fa8b[_0xfc53('0x31')]=_0x1f8508;if(_0x39cdbf[_0xfc53('0x47')][_0xfc53('0x59')]){_0x229455['include']=[{'all':!![]}];}return db[_0xfc53('0x72')][_0xfc53('0x6e')](_0x229455);})[_0xfc53('0x21')](function(_0x358958){_0x55fa8b[_0xfc53('0x55')]=_0x358958;return _0x55fa8b;});}})[_0xfc53('0x21')](respondWithFilteredResult(_0x335171,_0x229455))['catch'](handleError(_0x335171,null));};exports[_0xfc53('0x74')]=function(_0x2dfdfa,_0x30f1d9,_0x57f8cc){return db[_0xfc53('0x53')][_0xfc53('0x62')]({'where':{'id':_0x2dfdfa[_0xfc53('0x58')]['id']}})['then'](handleEntityNotFound(_0x30f1d9,null))['then'](function(_0x20818d){if(_0x20818d){return _0x20818d[_0xfc53('0x74')](_0x2dfdfa[_0xfc53('0x47')]['ids']);}})[_0xfc53('0x21')](respondWithStatusCode(_0x30f1d9,null))[_0xfc53('0x56')](handleError(_0x30f1d9,null));};exports[_0xfc53('0x75')]=function(_0xad0593,_0x52a5f4,_0x278783){var _0x1537ba={'channel':'sms'};var _0x2237c9=[];var _0x15b316=[];var _0x14c7bd={};return db[_0xfc53('0x53')][_0xfc53('0x62')]({'where':{'id':_0xad0593[_0xfc53('0x58')]['id']},'include':[{'model':db[_0xfc53('0x76')],'as':_0xfc53('0x77')}]})[_0xfc53('0x21')](handleEntityNotFound(_0x52a5f4,null))[_0xfc53('0x21')](function(_0x4b106b){_0x1537ba[_0xfc53('0x78')]=_0x4b106b;_0x1537ba[_0xfc53('0x79')]=_[_0xfc53('0x7a')](_0x4b106b[_0xfc53('0x77')],[_0xfc53('0x7b')],[_0xfc53('0x7c')]);if(_0x1537ba[_0xfc53('0x78')][_0xfc53('0x77')]){delete _0x1537ba[_0xfc53('0x78')]['Applications'];}return db[_0xfc53('0x7d')][_0xfc53('0x66')]();})[_0xfc53('0x21')](function(_0x3535a7){if(!_0x3535a7){throw new db[(_0xfc53('0x7e'))]['ValidationError'](_0xfc53('0x7f'));}_0x2237c9=_[_0xfc53('0x80')](_[_0xfc53('0x45')](_0x3535a7),[_0xfc53('0x81'),_0xfc53('0x82')]);_0x15b316=_[_0xfc53('0x80')](_[_0xfc53('0x45')](_0x3535a7),[_0xfc53('0x81'),_0xfc53('0x82'),_0xfc53('0x83'),'ListId']);_0x1537ba[_0xfc53('0x5c')]={'mapKey':'mobile'};if(_0x1537ba[_0xfc53('0x78')]['type']){switch(_0x1537ba[_0xfc53('0x78')][_0xfc53('0x42')]){case'twilio':_0x1537ba[_0xfc53('0x5c')]['from']=_0xad0593[_0xfc53('0x5c')]['From'];_0x1537ba[_0xfc53('0x5c')][_0xfc53('0x5c')]=_0xad0593[_0xfc53('0x5c')][_0xfc53('0x84')];_0x1537ba[_0xfc53('0x5c')]['messageId']=_0xad0593[_0xfc53('0x5c')][_0xfc53('0x85')];break;case _0xfc53('0x86'):_0x1537ba[_0xfc53('0x5c')][_0xfc53('0x87')]='+'+_0xad0593[_0xfc53('0x5c')]['sender'];_0x1537ba[_0xfc53('0x5c')][_0xfc53('0x5c')]=_0xad0593[_0xfc53('0x5c')]['text'];break;case _0xfc53('0x88'):_0x1537ba[_0xfc53('0x5c')][_0xfc53('0x87')]=_0xad0593['body'][_0xfc53('0x87')];_0x1537ba[_0xfc53('0x5c')][_0xfc53('0x5c')]=_0xad0593[_0xfc53('0x5c')]['message'];break;case _0xfc53('0x89'):_0x1537ba[_0xfc53('0x5c')][_0xfc53('0x87')]=_0xad0593[_0xfc53('0x5c')][_0xfc53('0x87')];_0x1537ba[_0xfc53('0x5c')]['body']=_0xad0593['body']['body'];_0x1537ba[_0xfc53('0x5c')][_0xfc53('0x8a')]=_0xad0593[_0xfc53('0x5c')][_0xfc53('0x8b')];break;case _0xfc53('0x8c'):_0x1537ba[_0xfc53('0x5c')][_0xfc53('0x87')]=_0xad0593[_0xfc53('0x5c')][_0xfc53('0x8d')];_0x1537ba[_0xfc53('0x5c')][_0xfc53('0x5c')]=_0xad0593[_0xfc53('0x5c')]['Text'];_0x1537ba[_0xfc53('0x5c')][_0xfc53('0x8a')]=_0xad0593['body'][_0xfc53('0x8e')];break;case'infobip':_0x1537ba['body']['from']='+'+_0xad0593[_0xfc53('0x5c')][_0xfc53('0x8f')][0x0]['from'];_0x1537ba[_0xfc53('0x5c')][_0xfc53('0x5c')]=_0xad0593['body'][_0xfc53('0x8f')][0x0][_0xfc53('0x90')];_0x1537ba[_0xfc53('0x5c')][_0xfc53('0x8a')]=_0xad0593['body'][_0xfc53('0x8f')][0x0][_0xfc53('0x8a')];break;case _0xfc53('0x91'):_0x1537ba[_0xfc53('0x5c')][_0xfc53('0x87')]=_0xad0593[_0xfc53('0x5c')][_0xfc53('0x92')];_0x1537ba[_0xfc53('0x5c')][_0xfc53('0x5c')]=_0xad0593['body'][_0xfc53('0x93')][_0xfc53('0x2a')];break;case _0xfc53('0x94'):_0x1537ba[_0xfc53('0x5c')][_0xfc53('0x87')]=_0xad0593[_0xfc53('0x5c')][_0xfc53('0x95')];_0x1537ba[_0xfc53('0x5c')][_0xfc53('0x5c')]=_0xad0593[_0xfc53('0x5c')][_0xfc53('0x90')];_0x1537ba[_0xfc53('0x5c')]['messageId']=_0xad0593[_0xfc53('0x5c')][_0xfc53('0x96')];break;case _0xfc53('0x97'):_0x1537ba[_0xfc53('0x5c')][_0xfc53('0x8a')]=_0xad0593[_0xfc53('0x5c')][0x0][_0xfc53('0x2a')]['id'];_0x1537ba[_0xfc53('0x5c')][_0xfc53('0x87')]=_0xad0593[_0xfc53('0x5c')][0x0][_0xfc53('0x2a')]['from'];_0x1537ba[_0xfc53('0x5c')][_0xfc53('0x5c')]=_0xad0593['body'][0x0][_0xfc53('0x2a')][_0xfc53('0x90')];break;case _0xfc53('0x98'):_0x1537ba['body'][_0xfc53('0x87')]=_0xad0593[_0xfc53('0x5c')][_0xfc53('0x87')];_0x1537ba[_0xfc53('0x5c')][_0xfc53('0x5c')]=_0xad0593[_0xfc53('0x5c')][_0xfc53('0x2a')];_0x1537ba['body']['messageId']=_0xad0593[_0xfc53('0x5c')][_0xfc53('0x99')];break;}}if(_0x1537ba[_0xfc53('0x5c')]['id']){delete _0x1537ba[_0xfc53('0x5c')]['id'];}if(_['isNil'](_0x1537ba[_0xfc53('0x5c')][_0xfc53('0x87')])){throw new db[(_0xfc53('0x7e'))][(_0xfc53('0x9a'))](_0xfc53('0x9b'));}if(_['isNil'](_0x1537ba['body']['body'])||_0x1537ba[_0xfc53('0x5c')][_0xfc53('0x5c')]===''){throw new db[(_0xfc53('0x7e'))][(_0xfc53('0x9a'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');}if(_['isNil'](_0x1537ba[_0xfc53('0x5c')]['mapKey'])){throw new db['Sequelize'][(_0xfc53('0x9a'))](_0xfc53('0x9c')+_0x15b316);}if(!_['includes'](_0x15b316,_0x1537ba[_0xfc53('0x5c')][_0xfc53('0x9d')])){throw new db[(_0xfc53('0x7e'))]['ValidationError']('mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x15b316);}_0x14c7bd[_0x1537ba[_0xfc53('0x5c')][_0xfc53('0x9d')]]=_0x1537ba['body'][_0xfc53('0x87')];return db[_0xfc53('0x9e')][_0xfc53('0x62')]({'where':{'id':_0x1537ba[_0xfc53('0x78')]['ListId']},'include':[{'model':db[_0xfc53('0x7d')],'as':_0xfc53('0x9f'),'where':_0x14c7bd,'limit':0x1,'order':[[_0xfc53('0x82'),_0xfc53('0xa0')]]}]});})['then'](handleEntityNotFound(_0x52a5f4,null))[_0xfc53('0x21')](function(_0x5aae0c){if(_0x5aae0c){_0x1537ba[_0xfc53('0xa1')]=_[_0xfc53('0xa2')](_0x5aae0c,[_0xfc53('0x9f')]);if(_0x5aae0c[_0xfc53('0x9f')][_0xfc53('0x4a')]){return _0x5aae0c['Contacts'][0x0];}var _0x511462=_['defaults'](_0x1537ba[_0xfc53('0x5c')],{'firstName':_0x1537ba[_0xfc53('0x5c')][_0xfc53('0x87')],'ListId':_0x5aae0c['id']});_0x511462[_0x1537ba[_0xfc53('0x5c')][_0xfc53('0x9d')]]=_0x1537ba['body'][_0xfc53('0x87')];return db[_0xfc53('0x7d')][_0xfc53('0x5b')](_0x511462,{'fields':_0x2237c9,'raw':!![]});}})[_0xfc53('0x21')](handleEntityNotFound(_0x52a5f4,null))['then'](function(_0x122acd){if(_0x122acd){_0x1537ba[_0xfc53('0xa3')]=_0x122acd;var _0x3bfc9f={'ContactId':_0x122acd['id'],'phone':_0x1537ba['body'][_0xfc53('0x87')],'SmsAccountId':_0xad0593[_0xfc53('0x58')]['id']};var _0x417559={'ContactId':_0x122acd['id'],'SmsAccountId':_0xad0593[_0xfc53('0x58')]['id'],'closed':![]};return db[_0xfc53('0xa4')][_0xfc53('0x62')]({'where':_0x417559})[_0xfc53('0x21')](function(_0x16a446){if(_0x16a446){return[_0x16a446,![]];}return db[_0xfc53('0xa4')]['create'](_0x3bfc9f)['then'](function(_0x177730){return[_0x177730,!![]];});});}})[_0xfc53('0xa5')](function(_0x4b92c9,_0x4809c9){_0x1537ba[_0xfc53('0xa6')]=_0x4b92c9[_0xfc53('0x5e')]({'plain':!![]});_0x1537ba[_0xfc53('0xa6')][_0xfc53('0xa7')]=![];if(_0x4809c9){if(_0x1537ba[_0xfc53('0x78')][_0xfc53('0xa8')]){_0x1537ba['applications'][_0xfc53('0xa9')]({'id':0x0,'priority':_0x1537ba[_0xfc53('0x79')][_0xfc53('0x4a')]+0x1,'app':_0xfc53('0xaa'),'appdata':_0xfc53('0xab'),'interval':'*,*,*,*'});}_0x1537ba[_0xfc53('0xa6')][_0xfc53('0xa7')]=!![];}return db[_0xfc53('0xac')][_0xfc53('0x5b')]({'phone':_0x1537ba[_0xfc53('0x5c')][_0xfc53('0x87')],'messageId':_0x1537ba[_0xfc53('0x5c')]['messageId'],'body':_0x1537ba['body'][_0xfc53('0x5c')],'SmsAccountId':_0xad0593[_0xfc53('0x58')]['id'],'SmsInteractionId':_0x4b92c9['id'],'direction':'in','ContactId':_0x4b92c9[_0xfc53('0xad')],'AttachmentId':_0x1537ba[_0xfc53('0x5c')]['AttachmentId']});})[_0xfc53('0x21')](function(_0xafd9f){_0x1537ba[_0xfc53('0x2a')]=_0xafd9f;if(_0x1537ba[_0xfc53('0xa6')][_0xfc53('0xae')]){return db[_0xfc53('0xaf')][_0xfc53('0x62')]({'attributes':['id',_0xfc53('0x3c')],'where':{'id':_0x1537ba[_0xfc53('0xa6')][_0xfc53('0xae')]}})[_0xfc53('0x21')](function(_0x5b067b){if(_0x5b067b){_0x1537ba[_0xfc53('0x79')][_0xfc53('0xb0')]({'id':0x0,'priority':0x0,'app':'agent','appdata':_0x5b067b[_0xfc53('0x3c')]+','+(_0x1537ba[_0xfc53('0x78')][_0xfc53('0xb1')]||0xa),'interval':_0xfc53('0xb2')});}return respondWithRpcPromise(_0xfc53('0xb3'),'startRouting',_0x1537ba);});}return respondWithRpcPromise('Start',_0xfc53('0xb4'),_0x1537ba);})['then'](function(_0x22fef9){if(_0x22fef9){var _0x13f57c=0xc8;var _0x1f9294=_0xfc53('0xb5');logger[_0xfc53('0x22')](_0xfc53('0x25'),_0x1f9294,_0x13f57c,_0xfc53('0xb6'));logger[_0xfc53('0x24')](_0xfc53('0xb7'),_0x1f9294,_0x13f57c,_0xfc53('0xb6'),JSON[_0xfc53('0x27')](_0x22fef9));if(_0x1537ba[_0xfc53('0x78')][_0xfc53('0x42')]===_0xfc53('0xb8')){return _0x52a5f4[_0xfc53('0x2c')](_0x13f57c)[_0xfc53('0x32')](_0xfc53('0xb9'),'text/xml')[_0xfc53('0x3d')]('<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>');}else{return _0x52a5f4[_0xfc53('0x2c')](_0x13f57c)[_0xfc53('0x2d')](_0x22fef9);}}})[_0xfc53('0x56')](handleError(_0x52a5f4,null));};exports[_0xfc53('0xba')]=function(_0x3f0dc9,_0x31e0cc,_0x5c5504){return db[_0xfc53('0x53')][_0xfc53('0x6b')]({'where':{'id':_0x3f0dc9[_0xfc53('0x58')]['id']}})['then'](handleEntityNotFound(_0x31e0cc,null))[_0xfc53('0x21')](function(_0x2363d7){if(_0x2363d7){return db[_0xfc53('0xbb')][_0xfc53('0xbc')](function(_0x243dd1){return db[_0xfc53('0x76')][_0xfc53('0x37')]({'where':{'SmsAccountId':_0x3f0dc9['params']['id']},'transaction':_0x243dd1})['then'](function(_0x3a2981){var _0x11457c=_['map'](_0x3f0dc9[_0xfc53('0x5c')],function(_0x1ec036){_0x1ec036[_0xfc53('0x68')]=_0x3f0dc9['params']['id'];return _0x1ec036;});return db['SmsApplication'][_0xfc53('0xbd')](_0x11457c,{'transaction':_0x243dd1});});})[_0xfc53('0x21')](function(){return db[_0xfc53('0x76')][_0xfc53('0xbe')]({'where':{'SmsAccountId':_0x3f0dc9[_0xfc53('0x58')]['id']},'order':_0xfc53('0x7b')});});}})['then'](respondWithResult(_0x31e0cc,null))[_0xfc53('0x56')](handleError(_0x31e0cc,null));};exports[_0xfc53('0xbf')]=function(_0x14eb1a,_0x2e6b50,_0x33614d){var _0x4fe43f={};var _0x5ab67f={};var _0xd9bfe3;var _0x5ec025;return db[_0xfc53('0x53')][_0xfc53('0x6b')]({'where':{'id':_0x14eb1a['params']['id']}})[_0xfc53('0x21')](handleEntityNotFound(_0x2e6b50,null))['then'](function(_0x5bc999){if(_0x5bc999){_0xd9bfe3=_0x5bc999;_0x5ab67f[_0xfc53('0x44')]=_[_0xfc53('0x45')](db['SmsApplication'][_0xfc53('0x41')]);_0x5ab67f[_0xfc53('0x47')]=_[_0xfc53('0x45')](_0x14eb1a[_0xfc53('0x47')]);_0x5ab67f[_0xfc53('0x46')]=_['intersection'](_0x5ab67f['model'],_0x5ab67f['query']);_0x4fe43f[_0xfc53('0x4b')]=_['intersection'](_0x5ab67f[_0xfc53('0x44')],qs[_0xfc53('0x49')](_0x14eb1a[_0xfc53('0x47')][_0xfc53('0x49')]));_0x4fe43f[_0xfc53('0x4b')]=_0x4fe43f[_0xfc53('0x4b')][_0xfc53('0x4a')]?_0x4fe43f['attributes']:_0x5ab67f[_0xfc53('0x44')];_0x4fe43f[_0xfc53('0x4d')]=qs[_0xfc53('0x4e')](_0x14eb1a[_0xfc53('0x47')]['sort']);_0x4fe43f['where']=qs['filters'](_[_0xfc53('0x6d')](_0x14eb1a[_0xfc53('0x47')],_0x5ab67f[_0xfc53('0x46')]));if(_0x14eb1a[_0xfc53('0x47')]['filter']){_0x4fe43f[_0xfc53('0x4f')]=_[_0xfc53('0x5a')](_0x4fe43f[_0xfc53('0x4f')],{'$or':_['map'](_0x4fe43f[_0xfc53('0x4b')],function(_0x5a29cb){var _0x3576f9={};_0x3576f9[_0x5a29cb]={'$like':'%'+_0x14eb1a[_0xfc53('0x47')][_0xfc53('0x50')]+'%'};return _0x3576f9;})});}_0x4fe43f=_['merge']({},_0x4fe43f,_0x14eb1a['options']);return _0xd9bfe3[_0xfc53('0xbf')](_0x4fe43f);}})['then'](function(_0x3b8158){if(_0x3b8158){_0x5ec025=_0x3b8158[_0xfc53('0x4a')];if(!_0x14eb1a[_0xfc53('0x47')]['hasOwnProperty'](_0xfc53('0x6c'))){_0x4fe43f[_0xfc53('0x30')]=qs[_0xfc53('0x30')](_0x14eb1a['query'][_0xfc53('0x30')]);_0x4fe43f[_0xfc53('0x2e')]=qs[_0xfc53('0x2e')](_0x14eb1a[_0xfc53('0x47')][_0xfc53('0x2e')]);}return _0xd9bfe3[_0xfc53('0xbf')](_0x4fe43f);}})[_0xfc53('0x21')](function(_0x2b94a8){if(_0x2b94a8){return _0x2b94a8?{'count':_0x5ec025,'rows':_0x2b94a8}:null;}})[_0xfc53('0x21')](respondWithResult(_0x2e6b50,null))[_0xfc53('0x56')](handleError(_0x2e6b50,null));};exports[_0xfc53('0xc0')]=function(_0x5b2aa5,_0x596c8c,_0x37ab6a){var _0x307c84={'raw':![],'where':{}};var _0xe6a00a={};var _0x5d3661={'count':0x0,'rows':[]};return db[_0xfc53('0x53')][_0xfc53('0x6b')]({'where':{'id':_0x5b2aa5['params']['id']}})[_0xfc53('0x21')](handleEntityNotFound(_0x596c8c,null))[_0xfc53('0x21')](function(_0x547d9f){if(_0x547d9f){_0xe6a00a['model']=_['keys'](db[_0xfc53('0xa4')][_0xfc53('0x41')]);_0xe6a00a['query']=_[_0xfc53('0x45')](_0x5b2aa5['query']);_0xe6a00a[_0xfc53('0x46')]=_['intersection'](_0xe6a00a[_0xfc53('0x44')],_0xe6a00a[_0xfc53('0x47')]);_0x307c84[_0xfc53('0x4b')]=_[_0xfc53('0x48')](_0xe6a00a[_0xfc53('0x44')],qs['fields'](_0x5b2aa5['query'][_0xfc53('0x49')]));_0x307c84['attributes']=_0x307c84[_0xfc53('0x4b')][_0xfc53('0x4a')]?_0x307c84[_0xfc53('0x4b')]:_0xe6a00a['model'];if(!_0x5b2aa5[_0xfc53('0x47')][_0xfc53('0x4c')]('nolimit')){_0x307c84[_0xfc53('0x30')]=qs[_0xfc53('0x30')](_0x5b2aa5[_0xfc53('0x47')][_0xfc53('0x30')]);_0x307c84[_0xfc53('0x2e')]=qs[_0xfc53('0x2e')](_0x5b2aa5['query'][_0xfc53('0x2e')]);}_0x307c84['order']=qs[_0xfc53('0x4e')](_0x5b2aa5[_0xfc53('0x47')][_0xfc53('0x4e')]);_0x307c84[_0xfc53('0x4f')]=qs[_0xfc53('0x46')](_[_0xfc53('0x6d')](_0x5b2aa5['query'],_0xe6a00a[_0xfc53('0x46')]));_0x307c84[_0xfc53('0x4f')][_0xfc53('0x68')]=_0x547d9f['id'];if(_0x5b2aa5[_0xfc53('0x47')][_0xfc53('0x50')]){_0x307c84['where']=_[_0xfc53('0x5a')](_0x307c84['where'],{'$or':_[_0xfc53('0x40')](_0x307c84[_0xfc53('0x4b')],function(_0x5a1b7d){var _0x278888={};_0x278888[_0x5a1b7d]={'$like':'%'+_0x5b2aa5[_0xfc53('0x47')][_0xfc53('0x50')]+'%'};return _0x278888;})});}_0x307c84=_[_0xfc53('0x5a')]({},_0x307c84,_0x5b2aa5[_0xfc53('0x52')]);return db[_0xfc53('0xa4')][_0xfc53('0x31')]({'where':_0x307c84['where']})[_0xfc53('0x21')](function(_0x10ceca){_0x5d3661['count']=_0x10ceca;if(_0x5b2aa5['query'][_0xfc53('0x59')]){_0x307c84['include']=[{'model':db[_0xfc53('0x7d')],'as':_0xfc53('0xc1'),'required':![]},{'model':db[_0xfc53('0xaf')],'as':_0xfc53('0xc2'),'attributes':[_0xfc53('0x3c'),_0xfc53('0xc3'),_0xfc53('0xc4')],'required':![]},{'model':db['Tag'],'as':_0xfc53('0xc5'),'attributes':['id',_0xfc53('0x3c'),'color'],'where':_0x5b2aa5[_0xfc53('0x47')][_0xfc53('0xc6')]?{'id':_0x5b2aa5[_0xfc53('0x47')][_0xfc53('0xc6')]}:undefined,'required':_0x5b2aa5[_0xfc53('0x47')][_0xfc53('0xc6')]?!![]:![]}];}return db[_0xfc53('0xa4')]['findAll'](_0x307c84);})['then'](function(_0x2e4b40){_0x5d3661['rows']=_0x2e4b40;return _0x5d3661;});}})['then'](respondWithFilteredResult(_0x596c8c,_0x307c84))[_0xfc53('0x56')](handleError(_0x596c8c,null));};exports[_0xfc53('0x3d')]=function(_0x15e1b1,_0x58ba24,_0x73b7c5){var _0x2360d4,_0x1fdcc9,_0x31ae2d;if(_[_0xfc53('0xc7')](_0x15e1b1[_0xfc53('0x5c')]['body'])||_0x15e1b1['body'][_0xfc53('0x5c')]===''){throw new db[(_0xfc53('0x7e'))][(_0xfc53('0x9a'))](_0xfc53('0xc8'));}if(_['isNil'](_0x15e1b1[_0xfc53('0x5c')]['to'])){throw new db[(_0xfc53('0x7e'))]['ValidationError'](_0xfc53('0xc9'));}_0x2360d4=_0x15e1b1[_0xfc53('0x5c')]['to'];return db[_0xfc53('0x53')][_0xfc53('0x62')]({'where':{'id':_0x15e1b1['params']['id']},'include':[{'model':db[_0xfc53('0x9e')],'as':_0xfc53('0xca'),'include':[{'model':db[_0xfc53('0x7d')],'as':_0xfc53('0x9f'),'where':{'mobile':_0x2360d4},'limit':0x1,'order':[['updatedAt',_0xfc53('0xa0')]]}]}]})[_0xfc53('0x21')](handleEntityNotFound(_0x58ba24,null))[_0xfc53('0x21')](function(_0x34a954){if(_0x34a954&&_0x34a954[_0xfc53('0xca')]){_0x1fdcc9=_0x34a954[_0xfc53('0x5e')]({'plain':!![]});if(_0x1fdcc9['List']&&_0x1fdcc9[_0xfc53('0xca')]['Contacts']['length']){return _0x1fdcc9[_0xfc53('0xca')][_0xfc53('0x9f')][0x0];}return db['CmContact'][_0xfc53('0x5b')](_[_0xfc53('0xcb')](_0x15e1b1[_0xfc53('0x5c')],{'firstName':_0x2360d4,'mobile':_0x2360d4,'phone':_0x2360d4,'ListId':_0x1fdcc9[_0xfc53('0xcc')]}));}})[_0xfc53('0x21')](handleEntityNotFound(_0x58ba24,null))[_0xfc53('0x21')](function(_0x13ec99){if(_0x13ec99){_0x31ae2d=_0x13ec99;return db['SmsInteraction'][_0xfc53('0x62')]({'where':{'ContactId':_0x31ae2d['id'],'closed':![],'SmsAccountId':_0x1fdcc9['id']}})[_0xfc53('0x21')](function(_0x32de1c){if(_0x32de1c){return[_0x32de1c,![]];}return db['SmsInteraction']['create']({'UserId':_0x15e1b1['user']['id'],'ContactId':_0x31ae2d['id'],'SmsAccountId':_0x1fdcc9['id'],'phone':_0x2360d4,'firstMsgDirection':_0xfc53('0xcd'),'Messages':[_[_0xfc53('0x5a')](_0x15e1b1[_0xfc53('0x5c')],{'read':![],'body':_0x15e1b1['body'][_0xfc53('0x5c')],'phone':_0x2360d4,'SmsAccountId':_0x1fdcc9['id'],'UserId':_0x15e1b1[_0xfc53('0x5d')]['id'],'ContactId':_0x31ae2d['id']})]},{'include':[{'model':db[_0xfc53('0xac')],'as':_0xfc53('0xce')}]})[_0xfc53('0x21')](function(_0x1cfa05){return[_0x1cfa05,!![]];});});}})[_0xfc53('0xa5')](function(_0x32f1f3,_0xa602ae){if(_0xa602ae){return _0x32f1f3;}return db['SmsMessage']['create'](_[_0xfc53('0x5a')](_0x15e1b1['body'],{'read':![],'body':_0x15e1b1[_0xfc53('0x5c')][_0xfc53('0x5c')],'phone':_0x2360d4,'SmsAccountId':_0x1fdcc9['id'],'SmsInteractionId':_0x32f1f3['id'],'UserId':_0x15e1b1[_0xfc53('0x5d')]['id'],'ContactId':_0x31ae2d['id']}))[_0xfc53('0x21')](function(_0x58734c){_0x32f1f3[_0xfc53('0xcf')][_0xfc53('0xce')]=[];_0x32f1f3[_0xfc53('0xcf')][_0xfc53('0xce')][_0xfc53('0xa9')](_0x58734c[_0xfc53('0xcf')]);return _0x32f1f3;});})[_0xfc53('0x21')](respondWithResult(_0x58ba24,null))[_0xfc53('0x56')](handleError(_0x58ba24,null));};exports[_0xfc53('0x2c')]=function(_0x47f496,_0xed8d15,_0x553c6e){if(_0x47f496['body']['id']){delete _0x47f496[_0xfc53('0x5c')]['id'];}var _0x43375d,_0x44fe6f,_0x1e5035;return db[_0xfc53('0x53')][_0xfc53('0x62')]({'where':{'id':_0x47f496[_0xfc53('0x58')]['id']}})[_0xfc53('0x21')](handleEntityNotFound(_0xed8d15,null))['then'](function(_0x26bed8){if(_0x26bed8){_0x1e5035=_0x26bed8;logger[_0xfc53('0x24')](_0xfc53('0x25'),'status','received\x20delivery\x20report\x20from',_0x26bed8['type'],util['inspect'](_0x47f496[_0xfc53('0x5c')],{'showHidden':![],'depth':null}));switch(_0x26bed8['type']){case _0xfc53('0x86'):if(_0x47f496[_0xfc53('0x5c')][_0xfc53('0xd0')]&&_0x47f496[_0xfc53('0x5c')][_0xfc53('0x2c')]){_0x44fe6f=_0x47f496[_0xfc53('0x5c')][_0xfc53('0x2c')];return db['SmsMessage']['find']({'where':{'messageId':_0x47f496[_0xfc53('0x5c')][_0xfc53('0xd0')]}});}break;case _0xfc53('0x88'):if(_0x47f496[_0xfc53('0x5c')][_0xfc53('0xd1')]&&_0x47f496[_0xfc53('0x5c')]['statusInt']){_0x44fe6f=_0x47f496['body']['statusInt'];return db[_0xfc53('0xac')][_0xfc53('0x62')]({'where':{'messageId':_0x47f496[_0xfc53('0x5c')][_0xfc53('0xd1')]}});}break;case _0xfc53('0x89'):if(_0x47f496[_0xfc53('0x5c')][_0xfc53('0x8b')]&&_0x47f496[_0xfc53('0x5c')][_0xfc53('0xd2')]){_0x44fe6f=_0x47f496[_0xfc53('0x5c')][_0xfc53('0xd2')];return db['SmsMessage']['find']({'where':{'messageId':_0x47f496[_0xfc53('0x5c')]['message_id']}});}break;case _0xfc53('0xd3'):var _0x37dfa3=_0x47f496[_0xfc53('0x5c')][_0xfc53('0x8f')][0x0];if(_0x37dfa3[_0xfc53('0x8a')]&&_0x37dfa3[_0xfc53('0x2c')][_0xfc53('0xd4')]===_0xfc53('0xd5')){_0x44fe6f=_0x37dfa3['status'][_0xfc53('0xd4')];return db[_0xfc53('0xac')][_0xfc53('0x62')]({'where':{'messageId':_0x37dfa3[_0xfc53('0x8a')]}});}break;case'clickatell':if(_0x47f496[_0xfc53('0x5c')][_0xfc53('0x8a')]&&_0x47f496['body']['status']){_0x44fe6f=_0x47f496[_0xfc53('0x5c')][_0xfc53('0x2c')];return db['SmsMessage'][_0xfc53('0x62')]({'where':{'messageId':_0x47f496[_0xfc53('0x5c')]['messageId']}});}break;case _0xfc53('0x97'):if(_0x47f496[_0xfc53('0x5c')][0x0]['message']['id']){_0x44fe6f=_0x47f496[_0xfc53('0x5c')][0x0][_0xfc53('0x42')];return db[_0xfc53('0xac')]['find']({'where':{'messageId':_0x47f496['body'][0x0]['message']['id']}});}break;case _0xfc53('0x98'):if(_0x47f496['body'][_0xfc53('0xd6')]&&_0x47f496['body'][_0xfc53('0x2c')]){_0x44fe6f=_0x47f496[_0xfc53('0x5c')][_0xfc53('0x2c')];return db[_0xfc53('0xac')][_0xfc53('0x62')]({'where':{'messageId':_0x47f496[_0xfc53('0x5c')][_0xfc53('0xd6')]}});}break;}}})[_0xfc53('0x21')](handleEntityNotFound(_0xed8d15,null))[_0xfc53('0x21')](function(_0xa45a64){if(_0xa45a64){_0x43375d=_0xa45a64;switch(_0x1e5035[_0xfc53('0x42')]){case _0xfc53('0x86'):if(_0x44fe6f===_0xfc53('0xd5')){return _0x43375d[_0xfc53('0x36')]({'read':!![]});}else{logger[_0xfc53('0x28')](_0xfc53('0x25'),_0xfc53('0x2c'),_0xfc53('0x86'),util['inspect'](_0x47f496[_0xfc53('0x5c')],{'showHidden':![],'depth':null}));}break;case _0xfc53('0x88'):if(_0x44fe6f==='1'){return _0x43375d[_0xfc53('0x36')]({'read':!![]});}else{logger['error'](_0xfc53('0x25'),_0xfc53('0x2c'),_0xfc53('0x86'),util['inspect'](_0x47f496['body'],{'showHidden':![],'depth':null}));}break;case'clicksend':if(!_0x47f496['body'][_0xfc53('0xd7')]&&_0x44fe6f>=0xc8&&_0x44fe6f<=0xce){return _0x43375d[_0xfc53('0x36')]({'read':!![]});}else{logger['error'](_0xfc53('0x25'),_0xfc53('0x2c'),'clicksend',util[_0xfc53('0xd8')](_0x47f496[_0xfc53('0x5c')],{'showHidden':![],'depth':null}));}break;case _0xfc53('0xd3'):var _0x221200=_0x47f496['body'][_0xfc53('0x8f')][0x0];if(_0x221200[_0xfc53('0x2c')]['groupName']===_0xfc53('0xd5')){return _0x43375d[_0xfc53('0x36')]({'read':!![]});}else{logger['error'](_0xfc53('0x25'),_0xfc53('0x2c'),_0xfc53('0xd3'),util[_0xfc53('0xd8')](_0x47f496[_0xfc53('0x5c')],{'showHidden':![],'depth':null}));}break;case _0xfc53('0x94'):if(_0x44fe6f==_0xfc53('0xd9')||_0x44fe6f==_0xfc53('0xda')){return _0x43375d[_0xfc53('0x36')]({'read':!![]});}else{logger['error'](_0xfc53('0x25'),'status',_0xfc53('0x94'),util[_0xfc53('0xd8')](_0x47f496[_0xfc53('0x5c')],{'showHidden':![],'depth':null}));}break;case'bandwidth':if(_0x44fe6f==_0xfc53('0xdb')){return _0x43375d[_0xfc53('0x36')]({'read':!![]});}else{logger[_0xfc53('0x28')](_0xfc53('0x25'),'status',_0xfc53('0x97'),util[_0xfc53('0xd8')](_0x47f496[_0xfc53('0x5c')],{'showHidden':![],'depth':null}));}break;case _0xfc53('0x98'):if(_0x44fe6f===_0xfc53('0xdc')||_0x44fe6f===_0xfc53('0xdd')){return _0x43375d['update']({'read':!![]});}else{logger[_0xfc53('0x28')](_0xfc53('0x25'),'status','intelepeer',util[_0xfc53('0xd8')](_0x47f496[_0xfc53('0x5c')],{'showHidden':![],'depth':null}));}break;}return _0x43375d;}})[_0xfc53('0x21')](respondWithResult(_0xed8d15,null))[_0xfc53('0x56')](handleError(_0xed8d15,null));};exports[_0xfc53('0xde')]=function(_0x36527f,_0x41a9a0,_0x572447){var _0x1a89d7,_0x4245b2,_0x1cacb7;return db[_0xfc53('0x53')]['find']({'where':{'id':_0x36527f['params']['id']}})[_0xfc53('0x21')](handleEntityNotFound(_0x41a9a0,null))[_0xfc53('0x21')](function(_0x5e0ac2){if(_0x5e0ac2){_0x1cacb7=_0x5e0ac2;logger[_0xfc53('0x24')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0xfc53('0x2c'),_0xfc53('0xdf'),_0x5e0ac2[_0xfc53('0x42')],util['inspect'](_0x36527f['query'],{'showHidden':![],'depth':null}));switch(_0x5e0ac2[_0xfc53('0x42')]){case'csc':if(_0x36527f[_0xfc53('0x47')][_0xfc53('0xe0')]&&_0x36527f['query']['state']){_0x4245b2=_0x36527f[_0xfc53('0x47')][_0xfc53('0xe1')];return db[_0xfc53('0xac')][_0xfc53('0x62')]({'where':{'messageId':_0x36527f['query'][_0xfc53('0xe0')]}});}break;}}})[_0xfc53('0x21')](handleEntityNotFound(_0x41a9a0,null))[_0xfc53('0x21')](function(_0x56e127){if(_0x56e127){_0x1a89d7=_0x56e127;switch(_0x1cacb7[_0xfc53('0x42')]){case _0xfc53('0x91'):if(_0x4245b2==='2'||_0x4245b2==='6'){return _0x1a89d7[_0xfc53('0x36')]({'read':!![]});}else{logger['error'](_0xfc53('0x25'),_0xfc53('0x2c'),'csc',util[_0xfc53('0xd8')](_0x36527f[_0xfc53('0x47')],{'showHidden':![],'depth':null}));};break;}return _0x1a89d7;}})['then'](respondWithResult(_0x41a9a0,null))[_0xfc53('0x56')](handleError(_0x41a9a0,null));};exports[_0xfc53('0xe2')]=function(_0x5d3cc1,_0x5ec72c,_0x2b18f3){return db['SmsAccount'][_0xfc53('0x62')]({'where':{'id':_0x5d3cc1[_0xfc53('0x58')]['id']}})[_0xfc53('0x21')](handleEntityNotFound(_0x5ec72c,null))['then'](function(_0x80653b){if(_0x80653b){return _0x80653b[_0xfc53('0xe2')](_0x5d3cc1['body'][_0xfc53('0x70')],_[_0xfc53('0xa2')](_0x5d3cc1[_0xfc53('0x5c')],[_0xfc53('0x70'),'id'])||{})[_0xfc53('0xa5')](function(_0x418d28){for(var _0x4c1196=0x0;_0x4c1196<_0x5d3cc1['body'][_0xfc53('0x70')][_0xfc53('0x4a')];_0x4c1196+=0x1){socket[_0xfc53('0xe3')](_0xfc53('0xe4'),{'UserId':Number(_0x5d3cc1['body']['ids'][_0x4c1196]),'SmsAccountId':Number(_0x5d3cc1[_0xfc53('0x58')]['id'])});}return _0x418d28;});}})[_0xfc53('0x21')](respondWithResult(_0x5ec72c,null))[_0xfc53('0x56')](handleError(_0x5ec72c,null));};exports[_0xfc53('0xe5')]=function(_0x445c44,_0x2b335f,_0x28fe53){return db['SmsAccount']['find']({'where':{'id':_0x445c44['params']['id']}})[_0xfc53('0x21')](handleEntityNotFound(_0x2b335f,null))[_0xfc53('0x21')](function(_0x3d922c){if(_0x3d922c){return _0x3d922c[_0xfc53('0xe5')](_0x445c44[_0xfc53('0x47')]['ids'])[_0xfc53('0x21')](function(){if(_[_0xfc53('0xe6')](_0x445c44[_0xfc53('0x47')]['ids'])){for(var _0xf552e2=0x0;_0xf552e2<_0x445c44['query']['ids'][_0xfc53('0x4a')];_0xf552e2+=0x1){socket['emit']('userSmsAccount:remove',{'UserId':Number(_0x445c44[_0xfc53('0x47')][_0xfc53('0x70')][_0xf552e2]),'SmsAccountId':Number(_0x445c44['params']['id'])});}}else{socket['emit']('userSmsAccount:remove',{'UserId':Number(_0x445c44[_0xfc53('0x47')][_0xfc53('0x70')]),'SmsAccountId':Number(_0x445c44[_0xfc53('0x58')]['id'])});}});}})[_0xfc53('0x21')](respondWithStatusCode(_0x2b335f,null))[_0xfc53('0x56')](handleError(_0x2b335f,null));};exports['getAgents']=function(_0x1dd1af,_0x3e46b3,_0x1c2f41){var _0x3f0454={};var _0x20eea5={};var _0x442193;var _0x49dc6c;return db[_0xfc53('0x53')]['findOne']({'where':{'id':_0x1dd1af[_0xfc53('0x58')]['id']}})['then'](handleEntityNotFound(_0x3e46b3,null))[_0xfc53('0x21')](function(_0x28f3be){if(_0x28f3be){_0x442193=_0x28f3be;_0x20eea5[_0xfc53('0x44')]=_[_0xfc53('0x45')](db[_0xfc53('0xaf')][_0xfc53('0x41')]);_0x20eea5[_0xfc53('0x47')]=_[_0xfc53('0x45')](_0x1dd1af[_0xfc53('0x47')]);_0x20eea5['filters']=_[_0xfc53('0x48')](_0x20eea5[_0xfc53('0x44')],_0x20eea5[_0xfc53('0x47')]);_0x3f0454[_0xfc53('0x4b')]=_[_0xfc53('0x48')](_0x20eea5[_0xfc53('0x44')],qs['fields'](_0x1dd1af[_0xfc53('0x47')][_0xfc53('0x49')]));_0x3f0454[_0xfc53('0x4b')]=_0x3f0454[_0xfc53('0x4b')][_0xfc53('0x4a')]?_0x3f0454[_0xfc53('0x4b')]:_0x20eea5[_0xfc53('0x44')];_0x3f0454[_0xfc53('0x4d')]=qs['sort'](_0x1dd1af[_0xfc53('0x47')][_0xfc53('0x4e')]);_0x3f0454[_0xfc53('0x4f')]=qs[_0xfc53('0x46')](_[_0xfc53('0x6d')](_0x1dd1af[_0xfc53('0x47')],_0x20eea5[_0xfc53('0x46')]));if(_0x1dd1af[_0xfc53('0x47')][_0xfc53('0x50')]){_0x3f0454['where']=_[_0xfc53('0x5a')](_0x3f0454['where'],{'$or':_[_0xfc53('0x40')](_0x3f0454[_0xfc53('0x4b')],function(_0x4a2c44){var _0x4d79fe={};_0x4d79fe[_0x4a2c44]={'$like':'%'+_0x1dd1af['query'][_0xfc53('0x50')]+'%'};return _0x4d79fe;})});}_0x3f0454=_[_0xfc53('0x5a')]({},_0x3f0454,_0x1dd1af['options']);return _0x442193[_0xfc53('0xe7')](_0x3f0454);}})[_0xfc53('0x21')](function(_0x239f5b){if(_0x239f5b){_0x49dc6c=_0x239f5b[_0xfc53('0x4a')];if(!_0x1dd1af['query'][_0xfc53('0x4c')](_0xfc53('0x6c'))){_0x3f0454['limit']=qs[_0xfc53('0x30')](_0x1dd1af[_0xfc53('0x47')][_0xfc53('0x30')]);_0x3f0454['offset']=qs['offset'](_0x1dd1af['query'][_0xfc53('0x2e')]);}return _0x442193[_0xfc53('0xe7')](_0x3f0454);}})[_0xfc53('0x21')](function(_0x448619){if(_0x448619){return _0x448619?{'count':_0x49dc6c,'rows':_0x448619}:null;}})[_0xfc53('0x21')](respondWithResult(_0x3e46b3,null))['catch'](handleError(_0x3e46b3,null));};