77d2d894141e9b59f1542f16adf1e9ae12d2658f
[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 _0x920b=['model','query','intersection','attributes','length','hasOwnProperty','order','sort','where','pick','filters','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','show','params','keys','fields','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','find','userProfileId','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','describe','addDisposition','SmsAccountId','Disposition','nolimit','removeDispositions','ids','addAnswer','CannedAnswer','getAnswers','findOne','removeAnswers','notify','sms','account','applications','orderBy','Applications','priority','asc','CmContact','Sequelize','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','ListId','mobile','twilio','from','From','Body','MessageSid','sender','text','connectel','message_id','plivo','Text','messageId','MessageUUID','infobip','results','originatingAddress','clickatell','fromNumber','bandwidth','intelepeer','refid','isNil','from\x20is\x20mandatory','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','Contacts','DESC','list','omit','defaults','SmsInteraction','spread','interaction','close','unmanaged','*,*,*,*','ContactId','UserId','unshift','agent','waitForTheAssignedAgent','Start','startRouting','receiveMessage','SmsAccount,\x20%s,\x20%s,\x20%s,\x20%s','entity\x20found','Content-Type','addApplications','sequelize','transaction','SmsApplication','findAndCountAll','getApplications','getInteractions','Owner','internal','Tag','Tags','color','tag','List','SmsMessage','Messages','dataValues','push','received\x20delivery\x20report\x20from','skebby','skebby_dispatch_id','requestid','statusInt','status_code','DELIVERED','redif','inspect','clicksend','error_code','groupName','DELIVERED_TO_GATEWAY','RECEIVED_BY_RECIPIENT','message-delivered','DELIVRD','ACCEPTD','statusGet','message-id','state','csc','addAgents','emit','userSmsAccount:save','removeAgents','userSmsAccount:remove','getAgents','User','rimraf','fast-json-patch','request-promise','mustache','sox','fs-extra','lodash','squel','jsforce','desk.js','to-csv','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','localhost','socket.io-emitter','register','jayson/promise','then','SmsAccount,\x20%s,\x20%s','request\x20sent','debug','SmsAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','end','status','count','offset','limit','set','json','apply','reject','save','update','destroy','get','SmsAccounts','sendStatus','name','send','index','Pause','mandatoryDispositionPause','map','SmsAccount','rawAttributes','fieldName','type'];(function(_0x49ca18,_0x5e6d05){var _0x145d54=function(_0x30b9be){while(--_0x30b9be){_0x49ca18['push'](_0x49ca18['shift']());}};_0x145d54(++_0x5e6d05);}(_0x920b,0x9e));var _0xb920=function(_0x54969a,_0x280d3e){_0x54969a=_0x54969a-0x0;var _0x49e1de=_0x920b[_0x54969a];return _0x49e1de;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xb920('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0xb920('0x1'));var rp=require(_0xb920('0x2'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0xb920('0x3'));var util=require('util');var path=require('path');var sox=require(_0xb920('0x4'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xb920('0x5'));var _=require(_0xb920('0x6'));var squel=require(_0xb920('0x7'));var crypto=require('crypto');var jsforce=require(_0xb920('0x8'));var deskjs=require(_0xb920('0x9'));var toCsv=require(_0xb920('0xa'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xb920('0xb'));var authService=require(_0xb920('0xc'));var qs=require(_0xb920('0xd'));var as=require(_0xb920('0xe'));var hardwareService=require(_0xb920('0xf'));var logger=require(_0xb920('0x10'))(_0xb920('0x11'));var utils=require(_0xb920('0x12'));var config=require(_0xb920('0x13'));var licenseUtil=require(_0xb920('0x14'));var db=require(_0xb920('0x15'))['db'];config[_0xb920('0x16')]=_['defaults'](config[_0xb920('0x16')],{'host':_0xb920('0x17'),'port':0x18eb});var socket=require(_0xb920('0x18'))(new Redis(config[_0xb920('0x16')]));require('./smsAccount.socket')[_0xb920('0x19')](socket);var jayson=require(_0xb920('0x1a'));var client=jayson['client']['http']({'port':0x232c});function respondWithRpcPromise(_0x7f72a6,_0x3b088c,_0xf910e7,_0x71da7c){return new BPromise(function(_0x326f17,_0x1275ad){var _0x1ff88b=_0x71da7c||client;return _0x1ff88b['request'](_0x7f72a6,_0xf910e7)[_0xb920('0x1b')](function(_0x3c0057){logger['info'](_0xb920('0x1c'),_0x3b088c,_0xb920('0x1d'));logger[_0xb920('0x1e')](_0xb920('0x1f'),_0x3b088c,_0xb920('0x1d'),JSON[_0xb920('0x20')](_0x3c0057));if(_0x3c0057['error']){if(_0x3c0057[_0xb920('0x21')][_0xb920('0x22')]===0x1f4){logger['error'](_0xb920('0x1c'),_0x3b088c,_0x3c0057[_0xb920('0x21')][_0xb920('0x23')]);return _0x1275ad(_0x3c0057[_0xb920('0x21')][_0xb920('0x23')]);}logger[_0xb920('0x21')](_0xb920('0x1c'),_0x3b088c,_0x3c0057[_0xb920('0x21')][_0xb920('0x23')]);return _0x326f17(_0x3c0057['error'][_0xb920('0x23')]);}else{logger['info'](_0xb920('0x1c'),_0x3b088c,'request\x20sent');_0x326f17(_0x3c0057[_0xb920('0x24')][_0xb920('0x23')]);}})[_0xb920('0x25')](function(_0x347c28){logger[_0xb920('0x21')](_0xb920('0x1c'),_0x3b088c,_0x347c28);_0x1275ad(_0x347c28);});});}function respondWithStatusCode(_0xfcf165,_0x2d2e66){_0x2d2e66=_0x2d2e66||0xcc;return function(_0x2bbebd){if(_0x2bbebd){return _0xfcf165['sendStatus'](_0x2d2e66);}return _0xfcf165['status'](_0x2d2e66)[_0xb920('0x26')]();};}function respondWithResult(_0x302f61,_0x83f655){_0x83f655=_0x83f655||0xc8;return function(_0x13cd1a){if(_0x13cd1a){return _0x302f61[_0xb920('0x27')](_0x83f655)['json'](_0x13cd1a);}};}function respondWithFilteredResult(_0x174195,_0x349da4){return function(_0x5dbb06){if(_0x5dbb06){var _0x47478c=_0x5dbb06[_0xb920('0x28')],_0x499145=_0x349da4[_0xb920('0x29')],_0x25c340=_0x349da4[_0xb920('0x29')]+_0x349da4[_0xb920('0x2a')],_0x3d8a17;if(_0x25c340>=_0x47478c){_0x25c340=_0x47478c;_0x3d8a17=0xc8;}else{_0x3d8a17=0xce;}_0x174195['status'](_0x3d8a17);return _0x174195[_0xb920('0x2b')]('Content-Range',_0x499145+'-'+_0x25c340+'/'+_0x47478c)[_0xb920('0x2c')](_0x5dbb06);}return null;};}function patchUpdates(_0x1ae5de){return function(_0xd2915f){try{jsonpatch[_0xb920('0x2d')](_0xd2915f,_0x1ae5de,!![]);}catch(_0x1f6616){return BPromise[_0xb920('0x2e')](_0x1f6616);}return _0xd2915f[_0xb920('0x2f')]();};}function saveUpdates(_0x686ff8,_0x10d1ef){return function(_0x585ae5){if(_0x585ae5){return _0x585ae5[_0xb920('0x30')](_0x686ff8)[_0xb920('0x1b')](function(_0x5d5491){return _0x5d5491;});}return null;};}function removeEntity(_0x40db30,_0x4cb37b){return function(_0xa35466){if(_0xa35466){return _0xa35466[_0xb920('0x31')]()['then'](function(){var _0xbf826b=_0xa35466[_0xb920('0x32')]({'plain':!![]});var _0x2d9933=_0xb920('0x33');return db['UserProfileResource'][_0xb920('0x31')]({'where':{'type':_0x2d9933,'resourceId':_0xbf826b['id']}})[_0xb920('0x1b')](function(){return _0xa35466;});})[_0xb920('0x1b')](function(){_0x40db30[_0xb920('0x27')](0xcc)[_0xb920('0x26')]();});}};}function handleEntityNotFound(_0x12010a,_0x260046){return function(_0x354de9){if(!_0x354de9){_0x12010a[_0xb920('0x34')](0x194);}return _0x354de9;};}function handleError(_0x2d5fc5,_0x1dc325){_0x1dc325=_0x1dc325||0x1f4;return function(_0x4b4ca3){logger[_0xb920('0x21')](_0x4b4ca3['stack']);if(_0x4b4ca3[_0xb920('0x35')]){delete _0x4b4ca3[_0xb920('0x35')];}_0x2d5fc5['status'](_0x1dc325)[_0xb920('0x36')](_0x4b4ca3);};}exports[_0xb920('0x37')]=function(_0x322185,_0x38d1a6){var _0x496aef={'include':[{'model':db[_0xb920('0x38')],'as':_0xb920('0x39')}]},_0x38b68d={},_0x459ed4={'count':0x0,'rows':[]};var _0x5ed5b2=_[_0xb920('0x3a')](db[_0xb920('0x3b')][_0xb920('0x3c')],function(_0x30b7b7){return{'name':_0x30b7b7[_0xb920('0x3d')],'type':_0x30b7b7[_0xb920('0x3e')]['key']};});_0x38b68d[_0xb920('0x3f')]=_[_0xb920('0x3a')](_0x5ed5b2,'name');_0x38b68d[_0xb920('0x40')]=_['keys'](_0x322185['query']);_0x38b68d['filters']=_[_0xb920('0x41')](_0x38b68d[_0xb920('0x3f')],_0x38b68d['query']);_0x496aef[_0xb920('0x42')]=_[_0xb920('0x41')](_0x38b68d['model'],qs['fields'](_0x322185[_0xb920('0x40')]['fields']));_0x496aef[_0xb920('0x42')]=_0x496aef[_0xb920('0x42')][_0xb920('0x43')]?_0x496aef['attributes']:_0x38b68d[_0xb920('0x3f')];if(!_0x322185[_0xb920('0x40')][_0xb920('0x44')]('nolimit')){_0x496aef[_0xb920('0x2a')]=qs['limit'](_0x322185[_0xb920('0x40')][_0xb920('0x2a')]);_0x496aef['offset']=qs[_0xb920('0x29')](_0x322185[_0xb920('0x40')][_0xb920('0x29')]);}_0x496aef[_0xb920('0x45')]=qs[_0xb920('0x46')](_0x322185[_0xb920('0x40')]['sort']);_0x496aef[_0xb920('0x47')]=qs['filters'](_[_0xb920('0x48')](_0x322185[_0xb920('0x40')],_0x38b68d[_0xb920('0x49')]),_0x5ed5b2);if(_0x322185[_0xb920('0x40')][_0xb920('0x4a')]){_0x496aef[_0xb920('0x47')]=_[_0xb920('0x4b')](_0x496aef[_0xb920('0x47')],{'$or':_[_0xb920('0x3a')](_0x5ed5b2,function(_0x2f0364){if(_0x2f0364['type']!==_0xb920('0x4c')){var _0x283cc8={};_0x283cc8[_0x2f0364['name']]={'$like':'%'+_0x322185[_0xb920('0x40')][_0xb920('0x4a')]+'%'};return _0x283cc8;}})});}_0x496aef=_[_0xb920('0x4b')]({},_0x496aef,_0x322185[_0xb920('0x4d')]);var _0x378098={'where':_0x496aef[_0xb920('0x47')]};return db[_0xb920('0x3b')][_0xb920('0x28')](_0x378098)[_0xb920('0x1b')](function(_0x5c6e2b){_0x459ed4['count']=_0x5c6e2b;if(_0x322185['query'][_0xb920('0x4e')]){_0x496aef[_0xb920('0x4f')]=[{'all':!![]}];}return db['SmsAccount'][_0xb920('0x50')](_0x496aef);})[_0xb920('0x1b')](function(_0x2da86e){_0x459ed4[_0xb920('0x51')]=_0x2da86e;return _0x459ed4;})[_0xb920('0x1b')](respondWithFilteredResult(_0x38d1a6,_0x496aef))[_0xb920('0x25')](handleError(_0x38d1a6,null));};exports[_0xb920('0x52')]=function(_0x3509f3,_0x5e4e58){var _0x3a3e11={'raw':![],'where':{'id':_0x3509f3[_0xb920('0x53')]['id']},'include':[{'model':db[_0xb920('0x38')],'as':_0xb920('0x39')}]},_0x4d8d05={};_0x4d8d05[_0xb920('0x3f')]=_[_0xb920('0x54')](db[_0xb920('0x3b')][_0xb920('0x3c')]);_0x4d8d05[_0xb920('0x40')]=_['keys'](_0x3509f3[_0xb920('0x40')]);_0x4d8d05[_0xb920('0x49')]=_['intersection'](_0x4d8d05[_0xb920('0x3f')],_0x4d8d05[_0xb920('0x40')]);_0x3a3e11[_0xb920('0x42')]=_[_0xb920('0x41')](_0x4d8d05[_0xb920('0x3f')],qs[_0xb920('0x55')](_0x3509f3[_0xb920('0x40')][_0xb920('0x55')]));_0x3a3e11[_0xb920('0x42')]=_0x3a3e11['attributes'][_0xb920('0x43')]?_0x3a3e11[_0xb920('0x42')]:_0x4d8d05['model'];if(_0x3509f3[_0xb920('0x40')][_0xb920('0x4e')]){_0x3a3e11[_0xb920('0x4f')]=[{'all':!![]}];}_0x3a3e11=_[_0xb920('0x4b')]({},_0x3a3e11,_0x3509f3[_0xb920('0x4d')]);return db[_0xb920('0x3b')]['find'](_0x3a3e11)[_0xb920('0x1b')](handleEntityNotFound(_0x5e4e58,null))[_0xb920('0x1b')](respondWithResult(_0x5e4e58,null))[_0xb920('0x25')](handleError(_0x5e4e58,null));};exports[_0xb920('0x56')]=function(_0x52e775,_0x4a99c2){return db[_0xb920('0x3b')][_0xb920('0x56')](_0x52e775[_0xb920('0x57')],{})[_0xb920('0x1b')](function(_0x28dbf1){var _0x1062a3=_0x52e775[_0xb920('0x58')][_0xb920('0x32')]({'plain':!![]});if(!_0x1062a3)throw new Error(_0xb920('0x59'));if(_0x1062a3[_0xb920('0x5a')]==='user'){var _0x46a583=_0x28dbf1[_0xb920('0x32')]({'plain':!![]});var _0x1ee0af=_0xb920('0x33');return db[_0xb920('0x5b')][_0xb920('0x5c')]({'where':{'name':_0x1ee0af,'userProfileId':_0x1062a3[_0xb920('0x5d')]},'raw':!![]})[_0xb920('0x1b')](function(_0x937141){if(_0x937141&&_0x937141['autoAssociation']===0x0){return db[_0xb920('0x5e')]['create']({'name':_0x46a583[_0xb920('0x35')],'resourceId':_0x46a583['id'],'type':_0x937141[_0xb920('0x35')],'sectionId':_0x937141['id']},{})['then'](function(){return _0x28dbf1;});}else{return _0x28dbf1;}})[_0xb920('0x25')](function(_0x43097){logger['error'](_0xb920('0x5f'),_0x43097);throw _0x43097;});}return _0x28dbf1;})[_0xb920('0x1b')](respondWithResult(_0x4a99c2,0xc9))[_0xb920('0x25')](handleError(_0x4a99c2,null));};exports[_0xb920('0x30')]=function(_0x3baae2,_0x1cdda7){if(_0x3baae2[_0xb920('0x57')]['id']){delete _0x3baae2['body']['id'];}return db[_0xb920('0x3b')]['find']({'where':{'id':_0x3baae2['params']['id']},'include':[{'model':db[_0xb920('0x38')],'as':_0xb920('0x39')}]})['then'](handleEntityNotFound(_0x1cdda7,null))['then'](saveUpdates(_0x3baae2[_0xb920('0x57')],null))[_0xb920('0x1b')](respondWithResult(_0x1cdda7,null))[_0xb920('0x25')](handleError(_0x1cdda7,null));};exports[_0xb920('0x31')]=function(_0x184876,_0x3fb959){return db['SmsAccount'][_0xb920('0x5c')]({'where':{'id':_0x184876[_0xb920('0x53')]['id']}})['then'](handleEntityNotFound(_0x3fb959,null))[_0xb920('0x1b')](removeEntity(_0x3fb959,null))[_0xb920('0x25')](handleError(_0x3fb959,null));};exports[_0xb920('0x60')]=function(_0x78f640,_0x5895a4){return db[_0xb920('0x3b')][_0xb920('0x60')]()[_0xb920('0x1b')](respondWithResult(_0x5895a4,null))[_0xb920('0x25')](handleError(_0x5895a4,null));};exports[_0xb920('0x61')]=function(_0x43f2c7,_0x10d888,_0x2fc4ae){if(_0x43f2c7[_0xb920('0x57')]['id']){delete _0x43f2c7[_0xb920('0x57')]['id'];}return db[_0xb920('0x3b')][_0xb920('0x5c')]({'where':{'id':_0x43f2c7[_0xb920('0x53')]['id']}})[_0xb920('0x1b')](handleEntityNotFound(_0x10d888,null))[_0xb920('0x1b')](function(_0x37dd4e){if(_0x37dd4e){_0x43f2c7['body'][_0xb920('0x62')]=_0x37dd4e['id'];return db[_0xb920('0x63')][_0xb920('0x56')](_0x43f2c7[_0xb920('0x57')]);}})[_0xb920('0x1b')](respondWithResult(_0x10d888,null))[_0xb920('0x25')](handleError(_0x10d888,null));};exports['getDispositions']=function(_0x47d1b8,_0x459208,_0x1890d1){var _0x571144={'raw':![],'where':{}};var _0xcd6522={};var _0x407698={'count':0x0,'rows':[]};return db[_0xb920('0x3b')]['findOne']({'where':{'id':_0x47d1b8[_0xb920('0x53')]['id']}})[_0xb920('0x1b')](handleEntityNotFound(_0x459208,null))[_0xb920('0x1b')](function(_0xd86f80){if(_0xd86f80){_0xcd6522[_0xb920('0x3f')]=_[_0xb920('0x54')](db[_0xb920('0x63')]['rawAttributes']);_0xcd6522[_0xb920('0x40')]=_['keys'](_0x47d1b8[_0xb920('0x40')]);_0xcd6522[_0xb920('0x49')]=_[_0xb920('0x41')](_0xcd6522[_0xb920('0x3f')],_0xcd6522['query']);_0x571144[_0xb920('0x42')]=_[_0xb920('0x41')](_0xcd6522[_0xb920('0x3f')],qs[_0xb920('0x55')](_0x47d1b8[_0xb920('0x40')]['fields']));_0x571144[_0xb920('0x42')]=_0x571144[_0xb920('0x42')][_0xb920('0x43')]?_0x571144[_0xb920('0x42')]:_0xcd6522[_0xb920('0x3f')];if(!_0x47d1b8['query'][_0xb920('0x44')](_0xb920('0x64'))){_0x571144['limit']=qs['limit'](_0x47d1b8[_0xb920('0x40')]['limit']);_0x571144['offset']=qs[_0xb920('0x29')](_0x47d1b8[_0xb920('0x40')][_0xb920('0x29')]);}_0x571144[_0xb920('0x45')]=qs['sort'](_0x47d1b8['query'][_0xb920('0x46')]);_0x571144[_0xb920('0x47')]=qs[_0xb920('0x49')](_[_0xb920('0x48')](_0x47d1b8['query'],_0xcd6522[_0xb920('0x49')]));_0x571144[_0xb920('0x47')][_0xb920('0x62')]=_0xd86f80['id'];if(_0x47d1b8[_0xb920('0x40')][_0xb920('0x4a')]){_0x571144['where']=_['merge'](_0x571144['where'],{'$or':_['map'](_0x571144[_0xb920('0x42')],function(_0x9f69cd){var _0x10ded0={};_0x10ded0[_0x9f69cd]={'$like':'%'+_0x47d1b8[_0xb920('0x40')][_0xb920('0x4a')]+'%'};return _0x10ded0;})});}_0x571144=_[_0xb920('0x4b')]({},_0x571144,_0x47d1b8['options']);return db[_0xb920('0x63')]['count']({'where':_0x571144[_0xb920('0x47')]})[_0xb920('0x1b')](function(_0x4e19e5){_0x407698[_0xb920('0x28')]=_0x4e19e5;if(_0x47d1b8[_0xb920('0x40')][_0xb920('0x4e')]){_0x571144[_0xb920('0x4f')]=[{'all':!![]}];}return db[_0xb920('0x63')][_0xb920('0x50')](_0x571144);})[_0xb920('0x1b')](function(_0x3dfa00){_0x407698[_0xb920('0x51')]=_0x3dfa00;return _0x407698;});}})[_0xb920('0x1b')](respondWithFilteredResult(_0x459208,_0x571144))[_0xb920('0x25')](handleError(_0x459208,null));};exports[_0xb920('0x65')]=function(_0x13bf43,_0x32ff8d,_0x1991bc){return db[_0xb920('0x3b')][_0xb920('0x5c')]({'where':{'id':_0x13bf43[_0xb920('0x53')]['id']}})[_0xb920('0x1b')](handleEntityNotFound(_0x32ff8d,null))[_0xb920('0x1b')](function(_0xe0982d){if(_0xe0982d){return _0xe0982d[_0xb920('0x65')](_0x13bf43[_0xb920('0x40')][_0xb920('0x66')]);}})[_0xb920('0x1b')](respondWithStatusCode(_0x32ff8d,null))[_0xb920('0x25')](handleError(_0x32ff8d,null));};exports[_0xb920('0x67')]=function(_0x280b99,_0x55b536,_0x1958db){if(_0x280b99['body']['id']){delete _0x280b99['body']['id'];}return db['SmsAccount'][_0xb920('0x5c')]({'where':{'id':_0x280b99[_0xb920('0x53')]['id']}})[_0xb920('0x1b')](handleEntityNotFound(_0x55b536,null))['then'](function(_0x77fbd7){if(_0x77fbd7){_0x280b99['body'][_0xb920('0x62')]=_0x77fbd7['id'];return db[_0xb920('0x68')]['create'](_0x280b99[_0xb920('0x57')]);}})[_0xb920('0x1b')](respondWithResult(_0x55b536,null))[_0xb920('0x25')](handleError(_0x55b536,null));};exports[_0xb920('0x69')]=function(_0x3c44ec,_0x19a60,_0x2b2e40){var _0x10dd5e={'raw':![],'where':{}};var _0x176c29={};var _0x3a83b5={'count':0x0,'rows':[]};return db[_0xb920('0x3b')][_0xb920('0x6a')]({'where':{'id':_0x3c44ec[_0xb920('0x53')]['id']}})[_0xb920('0x1b')](handleEntityNotFound(_0x19a60,null))[_0xb920('0x1b')](function(_0x5bcc93){if(_0x5bcc93){_0x176c29['model']=_[_0xb920('0x54')](db['CannedAnswer'][_0xb920('0x3c')]);_0x176c29['query']=_[_0xb920('0x54')](_0x3c44ec[_0xb920('0x40')]);_0x176c29['filters']=_['intersection'](_0x176c29[_0xb920('0x3f')],_0x176c29[_0xb920('0x40')]);_0x10dd5e[_0xb920('0x42')]=_[_0xb920('0x41')](_0x176c29[_0xb920('0x3f')],qs[_0xb920('0x55')](_0x3c44ec[_0xb920('0x40')][_0xb920('0x55')]));_0x10dd5e[_0xb920('0x42')]=_0x10dd5e[_0xb920('0x42')]['length']?_0x10dd5e[_0xb920('0x42')]:_0x176c29[_0xb920('0x3f')];if(!_0x3c44ec[_0xb920('0x40')][_0xb920('0x44')](_0xb920('0x64'))){_0x10dd5e[_0xb920('0x2a')]=qs['limit'](_0x3c44ec[_0xb920('0x40')][_0xb920('0x2a')]);_0x10dd5e[_0xb920('0x29')]=qs['offset'](_0x3c44ec['query'][_0xb920('0x29')]);}_0x10dd5e[_0xb920('0x45')]=qs[_0xb920('0x46')](_0x3c44ec[_0xb920('0x40')][_0xb920('0x46')]);_0x10dd5e[_0xb920('0x47')]=qs[_0xb920('0x49')](_[_0xb920('0x48')](_0x3c44ec[_0xb920('0x40')],_0x176c29['filters']));_0x10dd5e[_0xb920('0x47')][_0xb920('0x62')]=_0x5bcc93['id'];if(_0x3c44ec[_0xb920('0x40')][_0xb920('0x4a')]){_0x10dd5e[_0xb920('0x47')]=_[_0xb920('0x4b')](_0x10dd5e[_0xb920('0x47')],{'$or':_[_0xb920('0x3a')](_0x10dd5e[_0xb920('0x42')],function(_0x2e2896){var _0x440c2d={};_0x440c2d[_0x2e2896]={'$like':'%'+_0x3c44ec[_0xb920('0x40')]['filter']+'%'};return _0x440c2d;})});}_0x10dd5e=_[_0xb920('0x4b')]({},_0x10dd5e,_0x3c44ec[_0xb920('0x4d')]);return db['CannedAnswer'][_0xb920('0x28')]({'where':_0x10dd5e['where']})[_0xb920('0x1b')](function(_0x1578d2){_0x3a83b5[_0xb920('0x28')]=_0x1578d2;if(_0x3c44ec[_0xb920('0x40')]['includeAll']){_0x10dd5e[_0xb920('0x4f')]=[{'all':!![]}];}return db['CannedAnswer'][_0xb920('0x50')](_0x10dd5e);})[_0xb920('0x1b')](function(_0x2d347f){_0x3a83b5[_0xb920('0x51')]=_0x2d347f;return _0x3a83b5;});}})[_0xb920('0x1b')](respondWithFilteredResult(_0x19a60,_0x10dd5e))[_0xb920('0x25')](handleError(_0x19a60,null));};exports[_0xb920('0x6b')]=function(_0x2a04f7,_0x365446,_0x40587c){return db[_0xb920('0x3b')][_0xb920('0x5c')]({'where':{'id':_0x2a04f7[_0xb920('0x53')]['id']}})[_0xb920('0x1b')](handleEntityNotFound(_0x365446,null))[_0xb920('0x1b')](function(_0x4900ce){if(_0x4900ce){return _0x4900ce[_0xb920('0x6b')](_0x2a04f7['query'][_0xb920('0x66')]);}})['then'](respondWithStatusCode(_0x365446,null))[_0xb920('0x25')](handleError(_0x365446,null));};exports[_0xb920('0x6c')]=function(_0x1343e0,_0x510b7e,_0x32a575){var _0x52f33e={'channel':_0xb920('0x6d')};var _0x2b0b77=[];var _0x1bab38=[];var _0x2bcde3={};return db[_0xb920('0x3b')][_0xb920('0x5c')]({'where':{'id':_0x1343e0['params']['id']},'include':[{'model':db['SmsApplication'],'as':'Applications'}]})[_0xb920('0x1b')](handleEntityNotFound(_0x510b7e,null))[_0xb920('0x1b')](function(_0x18f1aa){_0x52f33e[_0xb920('0x6e')]=_0x18f1aa;_0x52f33e[_0xb920('0x6f')]=_[_0xb920('0x70')](_0x18f1aa[_0xb920('0x71')],[_0xb920('0x72')],[_0xb920('0x73')]);if(_0x52f33e[_0xb920('0x6e')][_0xb920('0x71')]){delete _0x52f33e['account'][_0xb920('0x71')];}return db[_0xb920('0x74')]['describe']();})['then'](function(_0x391702){if(!_0x391702){throw new db[(_0xb920('0x75'))][(_0xb920('0x76'))](_0xb920('0x77'));}_0x2b0b77=_[_0xb920('0x78')](_['keys'](_0x391702),[_0xb920('0x79'),_0xb920('0x7a')]);_0x1bab38=_['difference'](_['keys'](_0x391702),['createdAt',_0xb920('0x7a'),'CompanyId',_0xb920('0x7b')]);_0x52f33e[_0xb920('0x57')]={'mapKey':_0xb920('0x7c')};if(_0x52f33e[_0xb920('0x6e')][_0xb920('0x3e')]){switch(_0x52f33e[_0xb920('0x6e')]['type']){case _0xb920('0x7d'):_0x52f33e[_0xb920('0x57')][_0xb920('0x7e')]=_0x1343e0['body'][_0xb920('0x7f')];_0x52f33e['body'][_0xb920('0x57')]=_0x1343e0['body'][_0xb920('0x80')];_0x52f33e[_0xb920('0x57')]['messageId']=_0x1343e0[_0xb920('0x57')][_0xb920('0x81')];break;case'skebby':_0x52f33e[_0xb920('0x57')][_0xb920('0x7e')]='+'+_0x1343e0[_0xb920('0x57')][_0xb920('0x82')];_0x52f33e['body'][_0xb920('0x57')]=_0x1343e0[_0xb920('0x57')][_0xb920('0x83')];break;case _0xb920('0x84'):_0x52f33e['body']['from']=_0x1343e0[_0xb920('0x57')]['from'];_0x52f33e['body'][_0xb920('0x57')]=_0x1343e0[_0xb920('0x57')][_0xb920('0x23')];break;case'clicksend':_0x52f33e['body'][_0xb920('0x7e')]=_0x1343e0[_0xb920('0x57')][_0xb920('0x7e')];_0x52f33e[_0xb920('0x57')][_0xb920('0x57')]=_0x1343e0[_0xb920('0x57')][_0xb920('0x57')];_0x52f33e[_0xb920('0x57')]['messageId']=_0x1343e0[_0xb920('0x57')][_0xb920('0x85')];break;case _0xb920('0x86'):_0x52f33e[_0xb920('0x57')][_0xb920('0x7e')]=_0x1343e0[_0xb920('0x57')]['From'];_0x52f33e[_0xb920('0x57')]['body']=_0x1343e0[_0xb920('0x57')][_0xb920('0x87')];_0x52f33e[_0xb920('0x57')][_0xb920('0x88')]=_0x1343e0[_0xb920('0x57')][_0xb920('0x89')];break;case _0xb920('0x8a'):_0x52f33e['body'][_0xb920('0x7e')]='+'+_0x1343e0['body'][_0xb920('0x8b')][0x0]['from'];_0x52f33e[_0xb920('0x57')][_0xb920('0x57')]=_0x1343e0['body']['results'][0x0]['text'];_0x52f33e[_0xb920('0x57')][_0xb920('0x88')]=_0x1343e0[_0xb920('0x57')][_0xb920('0x8b')][0x0][_0xb920('0x88')];break;case'csc':_0x52f33e[_0xb920('0x57')][_0xb920('0x7e')]=_0x1343e0['body'][_0xb920('0x8c')];_0x52f33e[_0xb920('0x57')][_0xb920('0x57')]=_0x1343e0[_0xb920('0x57')]['segmentedMessage'][_0xb920('0x23')];break;case _0xb920('0x8d'):_0x52f33e[_0xb920('0x57')][_0xb920('0x7e')]=_0x1343e0[_0xb920('0x57')][_0xb920('0x8e')];_0x52f33e[_0xb920('0x57')][_0xb920('0x57')]=_0x1343e0['body'][_0xb920('0x83')];_0x52f33e['body'][_0xb920('0x88')]=_0x1343e0[_0xb920('0x57')]['replyMessageId'];break;case _0xb920('0x8f'):_0x52f33e[_0xb920('0x57')][_0xb920('0x88')]=_0x1343e0[_0xb920('0x57')][0x0][_0xb920('0x23')]['id'];_0x52f33e[_0xb920('0x57')][_0xb920('0x7e')]=_0x1343e0[_0xb920('0x57')][0x0]['message'][_0xb920('0x7e')];_0x52f33e[_0xb920('0x57')][_0xb920('0x57')]=_0x1343e0[_0xb920('0x57')][0x0][_0xb920('0x23')]['text'];break;case _0xb920('0x90'):_0x52f33e[_0xb920('0x57')][_0xb920('0x7e')]=_0x1343e0['body'][_0xb920('0x7e')];_0x52f33e['body'][_0xb920('0x57')]=_0x1343e0[_0xb920('0x57')]['message'];_0x52f33e['body'][_0xb920('0x88')]=_0x1343e0[_0xb920('0x57')][_0xb920('0x91')];break;}}if(_0x52f33e[_0xb920('0x57')]['id']){delete _0x52f33e['body']['id'];}if(_[_0xb920('0x92')](_0x52f33e[_0xb920('0x57')][_0xb920('0x7e')])){throw new db[(_0xb920('0x75'))]['ValidationError'](_0xb920('0x93'));}if(_['isNil'](_0x52f33e[_0xb920('0x57')]['body'])||_0x52f33e['body'][_0xb920('0x57')]===''){throw new db[(_0xb920('0x75'))]['ValidationError'](_0xb920('0x94'));}if(_['isNil'](_0x52f33e[_0xb920('0x57')][_0xb920('0x95')])){throw new db[(_0xb920('0x75'))]['ValidationError'](_0xb920('0x96')+_0x1bab38);}if(!_[_0xb920('0x97')](_0x1bab38,_0x52f33e[_0xb920('0x57')][_0xb920('0x95')])){throw new db['Sequelize']['ValidationError'](_0xb920('0x98')+_0x1bab38);}_0x2bcde3[_0x52f33e[_0xb920('0x57')][_0xb920('0x95')]]=_0x52f33e[_0xb920('0x57')][_0xb920('0x7e')];return db['CmList']['find']({'where':{'id':_0x52f33e['account']['ListId']},'include':[{'model':db[_0xb920('0x74')],'as':_0xb920('0x99'),'where':_0x2bcde3,'limit':0x1,'order':[['updatedAt',_0xb920('0x9a')]]}]});})[_0xb920('0x1b')](handleEntityNotFound(_0x510b7e,null))['then'](function(_0x206f6e){if(_0x206f6e){_0x52f33e[_0xb920('0x9b')]=_[_0xb920('0x9c')](_0x206f6e,[_0xb920('0x99')]);if(_0x206f6e[_0xb920('0x99')][_0xb920('0x43')]){return _0x206f6e['Contacts'][0x0];}var _0x26ebce=_[_0xb920('0x9d')](_0x52f33e['body'],{'firstName':_0x52f33e[_0xb920('0x57')]['from'],'ListId':_0x206f6e['id']});_0x26ebce[_0x52f33e[_0xb920('0x57')][_0xb920('0x95')]]=_0x52f33e[_0xb920('0x57')][_0xb920('0x7e')];return db[_0xb920('0x74')][_0xb920('0x56')](_0x26ebce,{'fields':_0x2b0b77,'raw':!![]});}})[_0xb920('0x1b')](handleEntityNotFound(_0x510b7e,null))[_0xb920('0x1b')](function(_0x129556){if(_0x129556){_0x52f33e['contact']=_0x129556;var _0x58b39c={'ContactId':_0x129556['id'],'phone':_0x52f33e[_0xb920('0x57')][_0xb920('0x7e')],'SmsAccountId':_0x1343e0[_0xb920('0x53')]['id']};var _0x97aeb0={'ContactId':_0x129556['id'],'SmsAccountId':_0x1343e0[_0xb920('0x53')]['id'],'closed':![]};return db[_0xb920('0x9e')][_0xb920('0x5c')]({'where':_0x97aeb0})['then'](function(_0x37c22d){if(_0x37c22d){return[_0x37c22d,![]];}return db[_0xb920('0x9e')]['create'](_0x58b39c)[_0xb920('0x1b')](function(_0x34e19f){return[_0x34e19f,!![]];});});}})[_0xb920('0x9f')](function(_0x207ea6,_0x3c1add){_0x52f33e[_0xb920('0xa0')]=_0x207ea6[_0xb920('0x32')]({'plain':!![]});_0x52f33e[_0xb920('0xa0')]['created']=![];if(_0x3c1add){if(_0x52f33e[_0xb920('0x6e')]['autoclose']){_0x52f33e[_0xb920('0x6f')]['push']({'id':0x0,'priority':_0x52f33e[_0xb920('0x6f')][_0xb920('0x43')]+0x1,'app':_0xb920('0xa1'),'appdata':_0xb920('0xa2'),'interval':_0xb920('0xa3')});}_0x52f33e['interaction']['created']=!![];}return db['SmsMessage']['create']({'phone':_0x52f33e[_0xb920('0x57')]['from'],'messageId':_0x52f33e['body'][_0xb920('0x88')],'body':_0x52f33e[_0xb920('0x57')][_0xb920('0x57')],'SmsAccountId':_0x1343e0[_0xb920('0x53')]['id'],'SmsInteractionId':_0x207ea6['id'],'direction':'in','ContactId':_0x207ea6[_0xb920('0xa4')],'AttachmentId':_0x52f33e['body']['AttachmentId']});})['then'](function(_0x59e16e){_0x52f33e['message']=_0x59e16e;if(_0x52f33e['interaction'][_0xb920('0xa5')]){return db['User'][_0xb920('0x5c')]({'attributes':['id',_0xb920('0x35')],'where':{'id':_0x52f33e['interaction'][_0xb920('0xa5')]}})[_0xb920('0x1b')](function(_0x4a871c){if(_0x4a871c){_0x52f33e[_0xb920('0x6f')][_0xb920('0xa6')]({'id':0x0,'priority':0x0,'app':_0xb920('0xa7'),'appdata':_0x4a871c[_0xb920('0x35')]+','+(_0x52f33e[_0xb920('0x6e')][_0xb920('0xa8')]||0xa),'interval':_0xb920('0xa3')});}return respondWithRpcPromise(_0xb920('0xa9'),'startRouting',_0x52f33e);});}return respondWithRpcPromise(_0xb920('0xa9'),_0xb920('0xaa'),_0x52f33e);})[_0xb920('0x1b')](function(_0x2ee842){if(_0x2ee842){var _0x1b8d70=0xc8;var _0x4262f4=_0xb920('0xab');logger['info'](_0xb920('0x1f'),_0x4262f4,_0x1b8d70,'entity\x20found');logger[_0xb920('0x1e')](_0xb920('0xac'),_0x4262f4,_0x1b8d70,_0xb920('0xad'),JSON[_0xb920('0x20')](_0x2ee842));if(_0x52f33e['account'][_0xb920('0x3e')]===_0xb920('0x7d')){return _0x510b7e[_0xb920('0x27')](_0x1b8d70)[_0xb920('0x2b')](_0xb920('0xae'),'text/xml')[_0xb920('0x36')]('<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>');}else{return _0x510b7e[_0xb920('0x27')](_0x1b8d70)[_0xb920('0x2c')](_0x2ee842);}}})[_0xb920('0x25')](handleError(_0x510b7e,null));};exports[_0xb920('0xaf')]=function(_0x13281f,_0x3872ee,_0x9c2879){return db['SmsAccount'][_0xb920('0x6a')]({'where':{'id':_0x13281f[_0xb920('0x53')]['id']}})[_0xb920('0x1b')](handleEntityNotFound(_0x3872ee,null))[_0xb920('0x1b')](function(_0x24e690){if(_0x24e690){return db[_0xb920('0xb0')][_0xb920('0xb1')](function(_0x5eafdd){return db['SmsApplication'][_0xb920('0x31')]({'where':{'SmsAccountId':_0x13281f[_0xb920('0x53')]['id']},'transaction':_0x5eafdd})[_0xb920('0x1b')](function(_0x2470e3){var _0x4a05fc=_[_0xb920('0x3a')](_0x13281f[_0xb920('0x57')],function(_0x5a7573){_0x5a7573['SmsAccountId']=_0x13281f[_0xb920('0x53')]['id'];return _0x5a7573;});return db['SmsApplication']['bulkCreate'](_0x4a05fc,{'transaction':_0x5eafdd});});})[_0xb920('0x1b')](function(){return db[_0xb920('0xb2')][_0xb920('0xb3')]({'where':{'SmsAccountId':_0x13281f['params']['id']},'order':_0xb920('0x72')});});}})['then'](respondWithResult(_0x3872ee,null))[_0xb920('0x25')](handleError(_0x3872ee,null));};exports[_0xb920('0xb4')]=function(_0x310305,_0x3828f7,_0x4a0da9){var _0x375fc8={};var _0x2c1890={};var _0x31301d;var _0x37210c;return db[_0xb920('0x3b')][_0xb920('0x6a')]({'where':{'id':_0x310305[_0xb920('0x53')]['id']}})[_0xb920('0x1b')](handleEntityNotFound(_0x3828f7,null))['then'](function(_0x4e6efa){if(_0x4e6efa){_0x31301d=_0x4e6efa;_0x2c1890[_0xb920('0x3f')]=_[_0xb920('0x54')](db[_0xb920('0xb2')]['rawAttributes']);_0x2c1890[_0xb920('0x40')]=_['keys'](_0x310305[_0xb920('0x40')]);_0x2c1890[_0xb920('0x49')]=_['intersection'](_0x2c1890['model'],_0x2c1890['query']);_0x375fc8[_0xb920('0x42')]=_[_0xb920('0x41')](_0x2c1890[_0xb920('0x3f')],qs['fields'](_0x310305[_0xb920('0x40')][_0xb920('0x55')]));_0x375fc8['attributes']=_0x375fc8[_0xb920('0x42')]['length']?_0x375fc8[_0xb920('0x42')]:_0x2c1890[_0xb920('0x3f')];_0x375fc8[_0xb920('0x45')]=qs[_0xb920('0x46')](_0x310305['query'][_0xb920('0x46')]);_0x375fc8[_0xb920('0x47')]=qs[_0xb920('0x49')](_['pick'](_0x310305['query'],_0x2c1890['filters']));if(_0x310305[_0xb920('0x40')][_0xb920('0x4a')]){_0x375fc8[_0xb920('0x47')]=_[_0xb920('0x4b')](_0x375fc8[_0xb920('0x47')],{'$or':_[_0xb920('0x3a')](_0x375fc8[_0xb920('0x42')],function(_0x361874){var _0x411847={};_0x411847[_0x361874]={'$like':'%'+_0x310305[_0xb920('0x40')]['filter']+'%'};return _0x411847;})});}_0x375fc8=_['merge']({},_0x375fc8,_0x310305['options']);return _0x31301d['getApplications'](_0x375fc8);}})['then'](function(_0x9d7123){if(_0x9d7123){_0x37210c=_0x9d7123['length'];if(!_0x310305['query'][_0xb920('0x44')](_0xb920('0x64'))){_0x375fc8['limit']=qs['limit'](_0x310305['query']['limit']);_0x375fc8[_0xb920('0x29')]=qs['offset'](_0x310305[_0xb920('0x40')][_0xb920('0x29')]);}return _0x31301d[_0xb920('0xb4')](_0x375fc8);}})[_0xb920('0x1b')](function(_0x1e77b0){if(_0x1e77b0){return _0x1e77b0?{'count':_0x37210c,'rows':_0x1e77b0}:null;}})['then'](respondWithResult(_0x3828f7,null))[_0xb920('0x25')](handleError(_0x3828f7,null));};exports[_0xb920('0xb5')]=function(_0x54a11f,_0x3c35d5,_0x5004d4){var _0x124ee3={'raw':![],'where':{}};var _0x167f84={};var _0x2c65e5={'count':0x0,'rows':[]};return db['SmsAccount'][_0xb920('0x6a')]({'where':{'id':_0x54a11f[_0xb920('0x53')]['id']}})[_0xb920('0x1b')](handleEntityNotFound(_0x3c35d5,null))[_0xb920('0x1b')](function(_0x438c51){if(_0x438c51){_0x167f84[_0xb920('0x3f')]=_[_0xb920('0x54')](db[_0xb920('0x9e')]['rawAttributes']);_0x167f84[_0xb920('0x40')]=_['keys'](_0x54a11f[_0xb920('0x40')]);_0x167f84[_0xb920('0x49')]=_['intersection'](_0x167f84[_0xb920('0x3f')],_0x167f84[_0xb920('0x40')]);_0x124ee3[_0xb920('0x42')]=_['intersection'](_0x167f84[_0xb920('0x3f')],qs['fields'](_0x54a11f[_0xb920('0x40')][_0xb920('0x55')]));_0x124ee3[_0xb920('0x42')]=_0x124ee3[_0xb920('0x42')][_0xb920('0x43')]?_0x124ee3[_0xb920('0x42')]:_0x167f84[_0xb920('0x3f')];if(!_0x54a11f['query'][_0xb920('0x44')]('nolimit')){_0x124ee3[_0xb920('0x2a')]=qs[_0xb920('0x2a')](_0x54a11f[_0xb920('0x40')][_0xb920('0x2a')]);_0x124ee3[_0xb920('0x29')]=qs[_0xb920('0x29')](_0x54a11f[_0xb920('0x40')]['offset']);}_0x124ee3[_0xb920('0x45')]=qs[_0xb920('0x46')](_0x54a11f[_0xb920('0x40')][_0xb920('0x46')]);_0x124ee3[_0xb920('0x47')]=qs[_0xb920('0x49')](_[_0xb920('0x48')](_0x54a11f[_0xb920('0x40')],_0x167f84[_0xb920('0x49')]));_0x124ee3[_0xb920('0x47')][_0xb920('0x62')]=_0x438c51['id'];if(_0x54a11f[_0xb920('0x40')][_0xb920('0x4a')]){_0x124ee3[_0xb920('0x47')]=_['merge'](_0x124ee3[_0xb920('0x47')],{'$or':_[_0xb920('0x3a')](_0x124ee3[_0xb920('0x42')],function(_0x93d059){var _0x31f3b7={};_0x31f3b7[_0x93d059]={'$like':'%'+_0x54a11f[_0xb920('0x40')][_0xb920('0x4a')]+'%'};return _0x31f3b7;})});}_0x124ee3=_[_0xb920('0x4b')]({},_0x124ee3,_0x54a11f[_0xb920('0x4d')]);return db[_0xb920('0x9e')][_0xb920('0x28')]({'where':_0x124ee3[_0xb920('0x47')]})['then'](function(_0x5089c1){_0x2c65e5[_0xb920('0x28')]=_0x5089c1;if(_0x54a11f['query'][_0xb920('0x4e')]){_0x124ee3['include']=[{'model':db['CmContact'],'as':'Contact','required':![]},{'model':db['User'],'as':_0xb920('0xb6'),'attributes':['name','fullname',_0xb920('0xb7')],'required':![]},{'model':db[_0xb920('0xb8')],'as':_0xb920('0xb9'),'attributes':['id',_0xb920('0x35'),_0xb920('0xba')],'where':_0x54a11f['query'][_0xb920('0xbb')]?{'id':_0x54a11f[_0xb920('0x40')][_0xb920('0xbb')]}:undefined,'required':_0x54a11f[_0xb920('0x40')][_0xb920('0xbb')]?!![]:![]}];}return db[_0xb920('0x9e')][_0xb920('0x50')](_0x124ee3);})[_0xb920('0x1b')](function(_0x3e6cb6){_0x2c65e5[_0xb920('0x51')]=_0x3e6cb6;return _0x2c65e5;});}})[_0xb920('0x1b')](respondWithFilteredResult(_0x3c35d5,_0x124ee3))[_0xb920('0x25')](handleError(_0x3c35d5,null));};exports['send']=function(_0x3ea74b,_0x55f93b,_0x3cfeb7){var _0x3d32d4,_0xa276d5,_0x2e1209;if(_[_0xb920('0x92')](_0x3ea74b[_0xb920('0x57')][_0xb920('0x57')])||_0x3ea74b[_0xb920('0x57')][_0xb920('0x57')]===''){throw new db[(_0xb920('0x75'))][(_0xb920('0x76'))](_0xb920('0x94'));}if(_[_0xb920('0x92')](_0x3ea74b[_0xb920('0x57')]['to'])){throw new db['Sequelize'][(_0xb920('0x76'))]('to\x20is\x20mandatory');}_0x3d32d4=_0x3ea74b[_0xb920('0x57')]['to'];return db[_0xb920('0x3b')][_0xb920('0x5c')]({'where':{'id':_0x3ea74b[_0xb920('0x53')]['id']},'include':[{'model':db['CmList'],'as':'List','include':[{'model':db[_0xb920('0x74')],'as':_0xb920('0x99'),'where':{'mobile':_0x3d32d4},'limit':0x1,'order':[[_0xb920('0x7a'),'DESC']]}]}]})[_0xb920('0x1b')](handleEntityNotFound(_0x55f93b,null))[_0xb920('0x1b')](function(_0x1ebd1f){if(_0x1ebd1f&&_0x1ebd1f['List']){_0xa276d5=_0x1ebd1f[_0xb920('0x32')]({'plain':!![]});if(_0xa276d5['List']&&_0xa276d5[_0xb920('0xbc')][_0xb920('0x99')][_0xb920('0x43')]){return _0xa276d5[_0xb920('0xbc')][_0xb920('0x99')][0x0];}return db['CmContact'][_0xb920('0x56')](_[_0xb920('0x9d')](_0x3ea74b[_0xb920('0x57')],{'firstName':_0x3d32d4,'mobile':_0x3d32d4,'phone':_0x3d32d4,'ListId':_0xa276d5[_0xb920('0x7b')]}));}})[_0xb920('0x1b')](handleEntityNotFound(_0x55f93b,null))[_0xb920('0x1b')](function(_0x46616d){if(_0x46616d){_0x2e1209=_0x46616d;return db[_0xb920('0x9e')][_0xb920('0x5c')]({'where':{'ContactId':_0x2e1209['id'],'closed':![],'SmsAccountId':_0xa276d5['id']}})[_0xb920('0x1b')](function(_0x4ef34c){if(_0x4ef34c){return[_0x4ef34c,![]];}return db[_0xb920('0x9e')][_0xb920('0x56')]({'UserId':_0x3ea74b[_0xb920('0x58')]['id'],'ContactId':_0x2e1209['id'],'SmsAccountId':_0xa276d5['id'],'phone':_0x3d32d4,'firstMsgDirection':'out','Messages':[_[_0xb920('0x4b')](_0x3ea74b[_0xb920('0x57')],{'read':![],'body':_0x3ea74b[_0xb920('0x57')][_0xb920('0x57')],'phone':_0x3d32d4,'SmsAccountId':_0xa276d5['id'],'UserId':_0x3ea74b[_0xb920('0x58')]['id'],'ContactId':_0x2e1209['id']})]},{'include':[{'model':db[_0xb920('0xbd')],'as':_0xb920('0xbe')}]})[_0xb920('0x1b')](function(_0x1c2afb){return[_0x1c2afb,!![]];});});}})[_0xb920('0x9f')](function(_0x324901,_0x1f0e88){if(_0x1f0e88){return _0x324901;}return db[_0xb920('0xbd')][_0xb920('0x56')](_['merge'](_0x3ea74b[_0xb920('0x57')],{'read':![],'body':_0x3ea74b[_0xb920('0x57')]['body'],'phone':_0x3d32d4,'SmsAccountId':_0xa276d5['id'],'SmsInteractionId':_0x324901['id'],'UserId':_0x3ea74b[_0xb920('0x58')]['id'],'ContactId':_0x2e1209['id']}))[_0xb920('0x1b')](function(_0x3ae48e){_0x324901['dataValues'][_0xb920('0xbe')]=[];_0x324901[_0xb920('0xbf')][_0xb920('0xbe')][_0xb920('0xc0')](_0x3ae48e[_0xb920('0xbf')]);return _0x324901;});})[_0xb920('0x1b')](respondWithResult(_0x55f93b,null))[_0xb920('0x25')](handleError(_0x55f93b,null));};exports[_0xb920('0x27')]=function(_0x4705da,_0x11bd8c,_0x269d2c){if(_0x4705da[_0xb920('0x57')]['id']){delete _0x4705da[_0xb920('0x57')]['id'];}var _0x2af394,_0x16e415,_0x1eeea1;return db[_0xb920('0x3b')]['find']({'where':{'id':_0x4705da[_0xb920('0x53')]['id']}})[_0xb920('0x1b')](handleEntityNotFound(_0x11bd8c,null))[_0xb920('0x1b')](function(_0x2ce930){if(_0x2ce930){_0x1eeea1=_0x2ce930;logger[_0xb920('0x1e')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0xb920('0x27'),_0xb920('0xc1'),_0x2ce930[_0xb920('0x3e')],util['inspect'](_0x4705da['body'],{'showHidden':![],'depth':null}));switch(_0x2ce930['type']){case _0xb920('0xc2'):if(_0x4705da[_0xb920('0x57')][_0xb920('0xc3')]&&_0x4705da['body'][_0xb920('0x27')]){_0x16e415=_0x4705da[_0xb920('0x57')][_0xb920('0x27')];return db[_0xb920('0xbd')]['find']({'where':{'messageId':_0x4705da['body'][_0xb920('0xc3')]}});}break;case _0xb920('0x84'):if(_0x4705da[_0xb920('0x57')][_0xb920('0xc4')]&&_0x4705da[_0xb920('0x57')][_0xb920('0xc5')]){_0x16e415=_0x4705da[_0xb920('0x57')][_0xb920('0xc5')];return db[_0xb920('0xbd')][_0xb920('0x5c')]({'where':{'messageId':_0x4705da['body'][_0xb920('0xc4')]}});}break;case'clicksend':if(_0x4705da['body']['message_id']&&_0x4705da[_0xb920('0x57')][_0xb920('0xc6')]){_0x16e415=_0x4705da['body'][_0xb920('0xc6')];return db[_0xb920('0xbd')][_0xb920('0x5c')]({'where':{'messageId':_0x4705da[_0xb920('0x57')][_0xb920('0x85')]}});}break;case'infobip':var _0x13b0f7=_0x4705da['body'][_0xb920('0x8b')][0x0];if(_0x13b0f7[_0xb920('0x88')]&&_0x13b0f7['status']['groupName']===_0xb920('0xc7')){_0x16e415=_0x13b0f7[_0xb920('0x27')]['groupName'];return db['SmsMessage'][_0xb920('0x5c')]({'where':{'messageId':_0x13b0f7[_0xb920('0x88')]}});}break;case _0xb920('0x8d'):if(_0x4705da[_0xb920('0x57')]['messageId']&&_0x4705da[_0xb920('0x57')][_0xb920('0x27')]){_0x16e415=_0x4705da['body']['status'];return db[_0xb920('0xbd')]['find']({'where':{'messageId':_0x4705da[_0xb920('0x57')][_0xb920('0x88')]}});}break;case _0xb920('0x8f'):if(_0x4705da[_0xb920('0x57')][0x0][_0xb920('0x23')]['id']){_0x16e415=_0x4705da['body'][0x0][_0xb920('0x3e')];return db[_0xb920('0xbd')][_0xb920('0x5c')]({'where':{'messageId':_0x4705da[_0xb920('0x57')][0x0]['message']['id']}});}break;case'intelepeer':if(_0x4705da[_0xb920('0x57')][_0xb920('0xc8')]&&_0x4705da[_0xb920('0x57')][_0xb920('0x27')]){_0x16e415=_0x4705da[_0xb920('0x57')][_0xb920('0x27')];return db[_0xb920('0xbd')][_0xb920('0x5c')]({'where':{'messageId':_0x4705da[_0xb920('0x57')][_0xb920('0xc8')]}});}break;}}})[_0xb920('0x1b')](handleEntityNotFound(_0x11bd8c,null))[_0xb920('0x1b')](function(_0x2d24f5){if(_0x2d24f5){_0x2af394=_0x2d24f5;switch(_0x1eeea1[_0xb920('0x3e')]){case _0xb920('0xc2'):if(_0x16e415===_0xb920('0xc7')){return _0x2af394[_0xb920('0x30')]({'read':!![]});}else{logger['error']('SmsAccount,\x20%s,\x20%s,\x20%s',_0xb920('0x27'),_0xb920('0xc2'),util[_0xb920('0xc9')](_0x4705da[_0xb920('0x57')],{'showHidden':![],'depth':null}));}break;case _0xb920('0x84'):if(_0x16e415==='1'){return _0x2af394['update']({'read':!![]});}else{logger[_0xb920('0x21')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0xb920('0x27'),_0xb920('0xc2'),util[_0xb920('0xc9')](_0x4705da['body'],{'showHidden':![],'depth':null}));}break;case _0xb920('0xca'):if(!_0x4705da[_0xb920('0x57')][_0xb920('0xcb')]&&_0x16e415>=0xc8&&_0x16e415<=0xce){return _0x2af394[_0xb920('0x30')]({'read':!![]});}else{logger[_0xb920('0x21')](_0xb920('0x1f'),_0xb920('0x27'),'clicksend',util[_0xb920('0xc9')](_0x4705da['body'],{'showHidden':![],'depth':null}));}break;case _0xb920('0x8a'):var _0x142a39=_0x4705da[_0xb920('0x57')][_0xb920('0x8b')][0x0];if(_0x142a39['status'][_0xb920('0xcc')]===_0xb920('0xc7')){return _0x2af394[_0xb920('0x30')]({'read':!![]});}else{logger[_0xb920('0x21')](_0xb920('0x1f'),_0xb920('0x27'),_0xb920('0x8a'),util['inspect'](_0x4705da['body'],{'showHidden':![],'depth':null}));}break;case'clickatell':if(_0x16e415==_0xb920('0xcd')||_0x16e415==_0xb920('0xce')){return _0x2af394['update']({'read':!![]});}else{logger[_0xb920('0x21')](_0xb920('0x1f'),_0xb920('0x27'),_0xb920('0x8d'),util['inspect'](_0x4705da[_0xb920('0x57')],{'showHidden':![],'depth':null}));}break;case'bandwidth':if(_0x16e415==_0xb920('0xcf')){return _0x2af394['update']({'read':!![]});}else{logger[_0xb920('0x21')](_0xb920('0x1f'),'status',_0xb920('0x8f'),util['inspect'](_0x4705da[_0xb920('0x57')],{'showHidden':![],'depth':null}));}break;case _0xb920('0x90'):if(_0x16e415===_0xb920('0xd0')||_0x16e415===_0xb920('0xd1')){return _0x2af394['update']({'read':!![]});}else{logger[_0xb920('0x21')](_0xb920('0x1f'),_0xb920('0x27'),'intelepeer',util[_0xb920('0xc9')](_0x4705da['body'],{'showHidden':![],'depth':null}));}break;}return _0x2af394;}})['then'](respondWithResult(_0x11bd8c,null))['catch'](handleError(_0x11bd8c,null));};exports[_0xb920('0xd2')]=function(_0x1f1d7a,_0x2854fc,_0x5b0611){var _0x43b0e5,_0x59eb52,_0x25029d;return db[_0xb920('0x3b')][_0xb920('0x5c')]({'where':{'id':_0x1f1d7a[_0xb920('0x53')]['id']}})[_0xb920('0x1b')](handleEntityNotFound(_0x2854fc,null))['then'](function(_0x2bcca0){if(_0x2bcca0){_0x25029d=_0x2bcca0;logger[_0xb920('0x1e')](_0xb920('0x1f'),_0xb920('0x27'),_0xb920('0xc1'),_0x2bcca0[_0xb920('0x3e')],util[_0xb920('0xc9')](_0x1f1d7a[_0xb920('0x40')],{'showHidden':![],'depth':null}));switch(_0x2bcca0[_0xb920('0x3e')]){case'csc':if(_0x1f1d7a[_0xb920('0x40')][_0xb920('0xd3')]&&_0x1f1d7a[_0xb920('0x40')][_0xb920('0xd4')]){_0x59eb52=_0x1f1d7a[_0xb920('0x40')][_0xb920('0xd4')];return db[_0xb920('0xbd')]['find']({'where':{'messageId':_0x1f1d7a[_0xb920('0x40')][_0xb920('0xd3')]}});}break;}}})[_0xb920('0x1b')](handleEntityNotFound(_0x2854fc,null))[_0xb920('0x1b')](function(_0x4fcd13){if(_0x4fcd13){_0x43b0e5=_0x4fcd13;switch(_0x25029d[_0xb920('0x3e')]){case _0xb920('0xd5'):if(_0x59eb52==='2'||_0x59eb52==='6'){return _0x43b0e5[_0xb920('0x30')]({'read':!![]});}else{logger[_0xb920('0x21')](_0xb920('0x1f'),'status','csc',util[_0xb920('0xc9')](_0x1f1d7a[_0xb920('0x40')],{'showHidden':![],'depth':null}));};break;}return _0x43b0e5;}})['then'](respondWithResult(_0x2854fc,null))[_0xb920('0x25')](handleError(_0x2854fc,null));};exports[_0xb920('0xd6')]=function(_0x97d318,_0xe28955,_0x3f3d30){return db[_0xb920('0x3b')]['find']({'where':{'id':_0x97d318[_0xb920('0x53')]['id']}})['then'](handleEntityNotFound(_0xe28955,null))[_0xb920('0x1b')](function(_0x324c4c){if(_0x324c4c){return _0x324c4c[_0xb920('0xd6')](_0x97d318['body'][_0xb920('0x66')],_[_0xb920('0x9c')](_0x97d318[_0xb920('0x57')],['ids','id'])||{})['spread'](function(_0x5e3888){for(var _0xcc5cc0=0x0;_0xcc5cc0<_0x97d318['body']['ids']['length'];_0xcc5cc0+=0x1){socket[_0xb920('0xd7')](_0xb920('0xd8'),{'UserId':_0x97d318[_0xb920('0x57')][_0xb920('0x66')][_0xcc5cc0],'SmsAccountId':_0x97d318[_0xb920('0x53')]['id']});}return _0x5e3888;});}})[_0xb920('0x1b')](respondWithResult(_0xe28955,null))[_0xb920('0x25')](handleError(_0xe28955,null));};exports[_0xb920('0xd9')]=function(_0x35c595,_0x1541b3,_0x547a89){return db[_0xb920('0x3b')]['find']({'where':{'id':_0x35c595[_0xb920('0x53')]['id']}})[_0xb920('0x1b')](handleEntityNotFound(_0x1541b3,null))[_0xb920('0x1b')](function(_0x2e38d2){if(_0x2e38d2){return _0x2e38d2[_0xb920('0xd9')](_0x35c595[_0xb920('0x40')][_0xb920('0x66')])['then'](function(){if(_['isArray'](_0x35c595[_0xb920('0x40')][_0xb920('0x66')])){for(var _0x4bfc22=0x0;_0x4bfc22<_0x35c595[_0xb920('0x40')][_0xb920('0x66')][_0xb920('0x43')];_0x4bfc22+=0x1){socket[_0xb920('0xd7')]('userSmsAccount:remove',{'UserId':Number(_0x35c595[_0xb920('0x40')][_0xb920('0x66')][_0x4bfc22]),'SmsAccountId':Number(_0x35c595[_0xb920('0x53')]['id'])});}}else{socket['emit'](_0xb920('0xda'),{'UserId':Number(_0x35c595['query'][_0xb920('0x66')]),'SmsAccountId':Number(_0x35c595['params']['id'])});}});}})[_0xb920('0x1b')](respondWithStatusCode(_0x1541b3,null))[_0xb920('0x25')](handleError(_0x1541b3,null));};exports[_0xb920('0xdb')]=function(_0x27a523,_0x29c413,_0x2172df){var _0x123a06={};var _0x16d7a8={};var _0x1202a4;var _0x49d755;return db[_0xb920('0x3b')][_0xb920('0x6a')]({'where':{'id':_0x27a523[_0xb920('0x53')]['id']}})[_0xb920('0x1b')](handleEntityNotFound(_0x29c413,null))[_0xb920('0x1b')](function(_0x2e9aeb){if(_0x2e9aeb){_0x1202a4=_0x2e9aeb;_0x16d7a8[_0xb920('0x3f')]=_[_0xb920('0x54')](db[_0xb920('0xdc')][_0xb920('0x3c')]);_0x16d7a8[_0xb920('0x40')]=_[_0xb920('0x54')](_0x27a523[_0xb920('0x40')]);_0x16d7a8['filters']=_['intersection'](_0x16d7a8[_0xb920('0x3f')],_0x16d7a8['query']);_0x123a06[_0xb920('0x42')]=_[_0xb920('0x41')](_0x16d7a8[_0xb920('0x3f')],qs['fields'](_0x27a523[_0xb920('0x40')][_0xb920('0x55')]));_0x123a06[_0xb920('0x42')]=_0x123a06[_0xb920('0x42')][_0xb920('0x43')]?_0x123a06[_0xb920('0x42')]:_0x16d7a8[_0xb920('0x3f')];_0x123a06[_0xb920('0x45')]=qs[_0xb920('0x46')](_0x27a523['query'][_0xb920('0x46')]);_0x123a06['where']=qs['filters'](_['pick'](_0x27a523[_0xb920('0x40')],_0x16d7a8[_0xb920('0x49')]));if(_0x27a523['query'][_0xb920('0x4a')]){_0x123a06[_0xb920('0x47')]=_[_0xb920('0x4b')](_0x123a06[_0xb920('0x47')],{'$or':_[_0xb920('0x3a')](_0x123a06[_0xb920('0x42')],function(_0x29af79){var _0xf81b62={};_0xf81b62[_0x29af79]={'$like':'%'+_0x27a523[_0xb920('0x40')]['filter']+'%'};return _0xf81b62;})});}_0x123a06=_[_0xb920('0x4b')]({},_0x123a06,_0x27a523['options']);return _0x1202a4[_0xb920('0xdb')](_0x123a06);}})[_0xb920('0x1b')](function(_0x1d21b0){if(_0x1d21b0){_0x49d755=_0x1d21b0[_0xb920('0x43')];if(!_0x27a523['query'][_0xb920('0x44')](_0xb920('0x64'))){_0x123a06['limit']=qs[_0xb920('0x2a')](_0x27a523[_0xb920('0x40')][_0xb920('0x2a')]);_0x123a06['offset']=qs[_0xb920('0x29')](_0x27a523[_0xb920('0x40')]['offset']);}return _0x1202a4[_0xb920('0xdb')](_0x123a06);}})['then'](function(_0x42d2ef){if(_0x42d2ef){return _0x42d2ef?{'count':_0x49d755,'rows':_0x42d2ef}:null;}})[_0xb920('0x1b')](respondWithResult(_0x29c413,null))['catch'](handleError(_0x29c413,null));};