Built motion from commit 1ea47bf4.|2.6.34
[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 _0x384f=['destroy','get','SmsAccounts','stack','name','send','Pause','mandatoryDispositionPause','map','SmsAccount','rawAttributes','fieldName','type','key','query','keys','filters','intersection','model','attributes','fields','hasOwnProperty','nolimit','sort','pick','merge','VIRTUAL','filter','where','includeAll','findAll','rows','length','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileResource','params','describe','addDisposition','SmsAccountId','getDispositions','Disposition','order','options','include','removeDispositions','ids','addAnswer','getAnswers','findOne','CannedAnswer','removeAnswers','notify','SmsApplication','account','orderBy','Applications','priority','asc','CmContact','Sequelize','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','mobile','twilio','from','From','Body','MessageSid','text','connectel','messageId','message_id','Text','MessageUUID','infobip','results','csc','originatingAddress','segmentedMessage','clickatell','fromNumber','replyMessageId','bandwidth','intelepeer','refid','isNil','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','mapKey','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','ListId','Contacts','DESC','list','omit','contact','SmsInteraction','spread','interaction','created','applications','push','close','unmanaged','*,*,*,*','SmsMessage','ContactId','User','UserId','agent','waitForTheAssignedAgent','SmsQueue','queueId','queue','waitForTheAssignedQueue','startRouting','receiveMessage','SmsAccount,\x20%s,\x20%s,\x20%s','entity\x20found','stringify','set','<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>','json','addApplications','sequelize','transaction','Transaction','ISOLATION_LEVELS','READ_COMMITTED','bulkCreate','findAndCountAll','finally','getApplications','getInteractions','Owner','fullname','Tag','Tags','color','tag','List','out','Messages','dataValues','received\x20delivery\x20report\x20from','inspect','skebby_dispatch_id','statusInt','requestid','status_code','groupName','redif','skebby','error_code','clicksend','DELIVERED','DELIVRD','ACCEPTD','statusGet','message-id','state','addAgents','emit','userSmsAccount:save','removeAgents','isArray','userSmsAccount:remove','getAgents','eml-format','rimraf','fast-json-patch','request-promise','bluebird','mustache','util','path','to-csv','ejs','fs-extra','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/license/util','redis','defaults','localhost','socket.io-emitter','./smsAccount.socket','register','jayson/promise','client','http','request','then','info','SmsAccount,\x20%s,\x20%s','request\x20sent','debug','error','code','message','result','catch','sendStatus','status','end','offset','undefined','limit','count','Content-Range','apply','reject','save','update'];(function(_0x2427e8,_0x4f7a0c){var _0x4a5c34=function(_0xdb17ab){while(--_0xdb17ab){_0x2427e8['push'](_0x2427e8['shift']());}};_0x4a5c34(++_0x4f7a0c);}(_0x384f,0xb1));var _0xf384=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x384f[_0x3dd15e];return _0x231fd0;};'use strict';var emlformat=require(_0xf384('0x0'));var rimraf=require(_0xf384('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xf384('0x2'));var rp=require(_0xf384('0x3'));var moment=require('moment');var BPromise=require(_0xf384('0x4'));var Mustache=require(_0xf384('0x5'));var util=require(_0xf384('0x6'));var path=require(_0xf384('0x7'));var sox=require('sox');var csv=require(_0xf384('0x8'));var ejs=require(_0xf384('0x9'));var fs=require('fs');var fs_extra=require(_0xf384('0xa'));var _=require('lodash');var squel=require('squel');var crypto=require(_0xf384('0xb'));var jsforce=require(_0xf384('0xc'));var deskjs=require(_0xf384('0xd'));var toCsv=require(_0xf384('0x8'));var querystring=require('querystring');var Papa=require(_0xf384('0xe'));var Redis=require(_0xf384('0xf'));var authService=require(_0xf384('0x10'));var qs=require(_0xf384('0x11'));var as=require(_0xf384('0x12'));var hardwareService=require(_0xf384('0x13'));var logger=require(_0xf384('0x14'))(_0xf384('0x15'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0xf384('0x16'));var db=require('../../mysqldb')['db'];config[_0xf384('0x17')]=_[_0xf384('0x18')](config['redis'],{'host':_0xf384('0x19'),'port':0x18eb});var socket=require(_0xf384('0x1a'))(new Redis(config['redis']));require(_0xf384('0x1b'))[_0xf384('0x1c')](socket);var jayson=require(_0xf384('0x1d'));var client=jayson[_0xf384('0x1e')][_0xf384('0x1f')]({'port':0x232c});function respondWithRpcPromise(_0x374413,_0xd06948,_0x121e64,_0x3c8c66){return new BPromise(function(_0x253707,_0x1a6083){var _0x2fe346=_0x3c8c66||client;return _0x2fe346[_0xf384('0x20')](_0x374413,_0x121e64)[_0xf384('0x21')](function(_0x3875f6){logger[_0xf384('0x22')](_0xf384('0x23'),_0xd06948,_0xf384('0x24'));logger[_0xf384('0x25')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0xd06948,_0xf384('0x24'),JSON['stringify'](_0x3875f6));if(_0x3875f6[_0xf384('0x26')]){if(_0x3875f6[_0xf384('0x26')][_0xf384('0x27')]===0x1f4){logger[_0xf384('0x26')](_0xf384('0x23'),_0xd06948,_0x3875f6[_0xf384('0x26')][_0xf384('0x28')]);return _0x1a6083(_0x3875f6[_0xf384('0x26')]['message']);}logger['error'](_0xf384('0x23'),_0xd06948,_0x3875f6[_0xf384('0x26')][_0xf384('0x28')]);return _0x253707(_0x3875f6[_0xf384('0x26')][_0xf384('0x28')]);}else{logger[_0xf384('0x22')]('SmsAccount,\x20%s,\x20%s',_0xd06948,_0xf384('0x24'));_0x253707(_0x3875f6[_0xf384('0x29')][_0xf384('0x28')]);}})[_0xf384('0x2a')](function(_0xd8daff){logger[_0xf384('0x26')]('SmsAccount,\x20%s,\x20%s',_0xd06948,_0xd8daff);_0x1a6083(_0xd8daff);});});}function respondWithStatusCode(_0xcef116,_0x3a802a){_0x3a802a=_0x3a802a||0xcc;return function(_0xff543e){if(_0xff543e){return _0xcef116[_0xf384('0x2b')](_0x3a802a);}return _0xcef116[_0xf384('0x2c')](_0x3a802a)[_0xf384('0x2d')]();};}function respondWithResult(_0x2720e1,_0x4bab68){_0x4bab68=_0x4bab68||0xc8;return function(_0x1df5d4){if(_0x1df5d4){return _0x2720e1['status'](_0x4bab68)['json'](_0x1df5d4);}};}function respondWithFilteredResult(_0x520e7d,_0x3fae86){return function(_0x9a25fc){if(_0x9a25fc){var _0x2b140d=typeof _0x3fae86[_0xf384('0x2e')]===_0xf384('0x2f')&&typeof _0x3fae86[_0xf384('0x30')]===_0xf384('0x2f');var _0x4d12cc=_0x9a25fc[_0xf384('0x31')];var _0x2a1792=_0x2b140d?0x0:_0x3fae86[_0xf384('0x2e')];var _0x1a8033=_0x2b140d?_0x9a25fc[_0xf384('0x31')]:_0x3fae86[_0xf384('0x2e')]+_0x3fae86[_0xf384('0x30')];var _0x524086;if(_0x1a8033>=_0x4d12cc){_0x1a8033=_0x4d12cc;_0x524086=0xc8;}else{_0x524086=0xce;}_0x520e7d[_0xf384('0x2c')](_0x524086);return _0x520e7d['set'](_0xf384('0x32'),_0x2a1792+'-'+_0x1a8033+'/'+_0x4d12cc)['json'](_0x9a25fc);}return null;};}function patchUpdates(_0x49af7d){return function(_0x2332fb){try{jsonpatch[_0xf384('0x33')](_0x2332fb,_0x49af7d,!![]);}catch(_0x417d3d){return BPromise[_0xf384('0x34')](_0x417d3d);}return _0x2332fb[_0xf384('0x35')]();};}function saveUpdates(_0x1adc68,_0x54ecaa){return function(_0x34e489){if(_0x34e489){return _0x34e489[_0xf384('0x36')](_0x1adc68)[_0xf384('0x21')](function(_0x3cf1e2){return _0x3cf1e2;});}return null;};}function removeEntity(_0x2182e2,_0x30b9de){return function(_0x1e83a5){if(_0x1e83a5){return _0x1e83a5[_0xf384('0x37')]()[_0xf384('0x21')](function(){var _0x18d914=_0x1e83a5[_0xf384('0x38')]({'plain':!![]});var _0x56ae2d=_0xf384('0x39');return db['UserProfileResource'][_0xf384('0x37')]({'where':{'type':_0x56ae2d,'resourceId':_0x18d914['id']}})[_0xf384('0x21')](function(){return _0x1e83a5;});})['then'](function(){_0x2182e2[_0xf384('0x2c')](0xcc)[_0xf384('0x2d')]();});}};}function handleEntityNotFound(_0x1f3408,_0x86205b){return function(_0x2214d6){if(!_0x2214d6){_0x1f3408[_0xf384('0x2b')](0x194);}return _0x2214d6;};}function handleError(_0x255512,_0x4f5126){_0x4f5126=_0x4f5126||0x1f4;return function(_0x222f91){logger[_0xf384('0x26')](_0x222f91[_0xf384('0x3a')]);if(_0x222f91[_0xf384('0x3b')]){delete _0x222f91[_0xf384('0x3b')];}_0x255512[_0xf384('0x2c')](_0x4f5126)[_0xf384('0x3c')](_0x222f91);};}exports['index']=function(_0x427646,_0x50461b){var _0x226ec8={'include':[{'model':db[_0xf384('0x3d')],'as':_0xf384('0x3e')}]},_0x5017d7={},_0x36a647={'count':0x0,'rows':[]};var _0x502d98=_[_0xf384('0x3f')](db[_0xf384('0x40')][_0xf384('0x41')],function(_0x1e89ce){return{'name':_0x1e89ce[_0xf384('0x42')],'type':_0x1e89ce[_0xf384('0x43')][_0xf384('0x44')]};});_0x5017d7['model']=_['map'](_0x502d98,_0xf384('0x3b'));_0x5017d7[_0xf384('0x45')]=_[_0xf384('0x46')](_0x427646[_0xf384('0x45')]);_0x5017d7[_0xf384('0x47')]=_[_0xf384('0x48')](_0x5017d7[_0xf384('0x49')],_0x5017d7[_0xf384('0x45')]);_0x226ec8[_0xf384('0x4a')]=_[_0xf384('0x48')](_0x5017d7['model'],qs[_0xf384('0x4b')](_0x427646[_0xf384('0x45')][_0xf384('0x4b')]));_0x226ec8[_0xf384('0x4a')]=_0x226ec8[_0xf384('0x4a')]['length']?_0x226ec8['attributes']:_0x5017d7[_0xf384('0x49')];if(!_0x427646[_0xf384('0x45')][_0xf384('0x4c')](_0xf384('0x4d'))){_0x226ec8['limit']=qs['limit'](_0x427646[_0xf384('0x45')][_0xf384('0x30')]);_0x226ec8['offset']=qs[_0xf384('0x2e')](_0x427646[_0xf384('0x45')]['offset']);}_0x226ec8['order']=qs['sort'](_0x427646[_0xf384('0x45')][_0xf384('0x4e')]);_0x226ec8['where']=qs[_0xf384('0x47')](_[_0xf384('0x4f')](_0x427646['query'],_0x5017d7[_0xf384('0x47')]),_0x502d98);if(_0x427646[_0xf384('0x45')]['filter']){_0x226ec8['where']=_[_0xf384('0x50')](_0x226ec8['where'],{'$or':_[_0xf384('0x3f')](_0x502d98,function(_0xfff8f8){if(_0xfff8f8[_0xf384('0x43')]!==_0xf384('0x51')){var _0x1e0f77={};_0x1e0f77[_0xfff8f8[_0xf384('0x3b')]]={'$like':'%'+_0x427646['query'][_0xf384('0x52')]+'%'};return _0x1e0f77;}})});}_0x226ec8=_[_0xf384('0x50')]({},_0x226ec8,_0x427646['options']);var _0x3cec5c={'where':_0x226ec8[_0xf384('0x53')]};return db[_0xf384('0x40')][_0xf384('0x31')](_0x3cec5c)[_0xf384('0x21')](function(_0x4d8da8){_0x36a647[_0xf384('0x31')]=_0x4d8da8;if(_0x427646[_0xf384('0x45')][_0xf384('0x54')]){_0x226ec8['include']=[{'all':!![]}];}return db[_0xf384('0x40')][_0xf384('0x55')](_0x226ec8);})[_0xf384('0x21')](function(_0x3d8100){_0x36a647[_0xf384('0x56')]=_0x3d8100;return _0x36a647;})[_0xf384('0x21')](respondWithFilteredResult(_0x50461b,_0x226ec8))[_0xf384('0x2a')](handleError(_0x50461b,null));};exports['show']=function(_0x146c60,_0x542123){var _0x46dc50={'raw':![],'where':{'id':_0x146c60['params']['id']},'include':[{'model':db['Pause'],'as':_0xf384('0x3e')}]},_0x386395={};_0x386395[_0xf384('0x49')]=_[_0xf384('0x46')](db[_0xf384('0x40')][_0xf384('0x41')]);_0x386395[_0xf384('0x45')]=_['keys'](_0x146c60['query']);_0x386395[_0xf384('0x47')]=_[_0xf384('0x48')](_0x386395[_0xf384('0x49')],_0x386395['query']);_0x46dc50[_0xf384('0x4a')]=_[_0xf384('0x48')](_0x386395['model'],qs[_0xf384('0x4b')](_0x146c60[_0xf384('0x45')][_0xf384('0x4b')]));_0x46dc50[_0xf384('0x4a')]=_0x46dc50[_0xf384('0x4a')][_0xf384('0x57')]?_0x46dc50[_0xf384('0x4a')]:_0x386395[_0xf384('0x49')];if(_0x146c60[_0xf384('0x45')]['includeAll']){_0x46dc50['include']=[{'all':!![]}];}_0x46dc50=_[_0xf384('0x50')]({},_0x46dc50,_0x146c60['options']);return db['SmsAccount'][_0xf384('0x58')](_0x46dc50)[_0xf384('0x21')](handleEntityNotFound(_0x542123,null))['then'](respondWithResult(_0x542123,null))['catch'](handleError(_0x542123,null));};exports[_0xf384('0x59')]=function(_0x390f53,_0x436023){return db[_0xf384('0x40')][_0xf384('0x59')](_0x390f53[_0xf384('0x5a')],{})[_0xf384('0x21')](function(_0x56e4de){var _0x438805=_0x390f53[_0xf384('0x5b')]['get']({'plain':!![]});if(!_0x438805)throw new Error(_0xf384('0x5c'));if(_0x438805['role']===_0xf384('0x5b')){var _0x3cf1d9=_0x56e4de[_0xf384('0x38')]({'plain':!![]});var _0x483021=_0xf384('0x39');return db['UserProfileSection'][_0xf384('0x58')]({'where':{'name':_0x483021,'userProfileId':_0x438805['userProfileId']},'raw':!![]})[_0xf384('0x21')](function(_0x357c4e){if(_0x357c4e&&_0x357c4e['autoAssociation']===0x0){return db[_0xf384('0x5d')]['create']({'name':_0x3cf1d9[_0xf384('0x3b')],'resourceId':_0x3cf1d9['id'],'type':_0x357c4e[_0xf384('0x3b')],'sectionId':_0x357c4e['id']},{})[_0xf384('0x21')](function(){return _0x56e4de;});}else{return _0x56e4de;}})[_0xf384('0x2a')](function(_0x140acf){logger['error']('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x140acf);throw _0x140acf;});}return _0x56e4de;})[_0xf384('0x21')](respondWithResult(_0x436023,0xc9))[_0xf384('0x2a')](handleError(_0x436023,null));};exports[_0xf384('0x36')]=function(_0xa560e1,_0x2cec35){if(_0xa560e1[_0xf384('0x5a')]['id']){delete _0xa560e1['body']['id'];}return db['SmsAccount'][_0xf384('0x58')]({'where':{'id':_0xa560e1[_0xf384('0x5e')]['id']},'include':[{'model':db[_0xf384('0x3d')],'as':_0xf384('0x3e')}]})[_0xf384('0x21')](handleEntityNotFound(_0x2cec35,null))['then'](saveUpdates(_0xa560e1['body'],null))[_0xf384('0x21')](respondWithResult(_0x2cec35,null))[_0xf384('0x2a')](handleError(_0x2cec35,null));};exports[_0xf384('0x37')]=function(_0x1c3979,_0x3dff7d){return db[_0xf384('0x40')][_0xf384('0x58')]({'where':{'id':_0x1c3979[_0xf384('0x5e')]['id']}})[_0xf384('0x21')](handleEntityNotFound(_0x3dff7d,null))['then'](removeEntity(_0x3dff7d,null))[_0xf384('0x2a')](handleError(_0x3dff7d,null));};exports[_0xf384('0x5f')]=function(_0x140183,_0x3301f7){return db[_0xf384('0x40')][_0xf384('0x5f')]()[_0xf384('0x21')](respondWithResult(_0x3301f7,null))[_0xf384('0x2a')](handleError(_0x3301f7,null));};exports[_0xf384('0x60')]=function(_0x5bce18,_0x1c44bc,_0x5a6dc8){if(_0x5bce18[_0xf384('0x5a')]['id']){delete _0x5bce18[_0xf384('0x5a')]['id'];}return db['SmsAccount'][_0xf384('0x58')]({'where':{'id':_0x5bce18[_0xf384('0x5e')]['id']}})[_0xf384('0x21')](handleEntityNotFound(_0x1c44bc,null))['then'](function(_0x56620c){if(_0x56620c){_0x5bce18[_0xf384('0x5a')][_0xf384('0x61')]=_0x56620c['id'];return db['Disposition']['create'](_0x5bce18[_0xf384('0x5a')]);}})[_0xf384('0x21')](respondWithResult(_0x1c44bc,null))[_0xf384('0x2a')](handleError(_0x1c44bc,null));};exports[_0xf384('0x62')]=function(_0x103e8e,_0x4cc4f9,_0x587f25){var _0x5525c4={'raw':![],'where':{}};var _0x309b61={};var _0x1119e9={'count':0x0,'rows':[]};return db[_0xf384('0x40')]['findOne']({'where':{'id':_0x103e8e[_0xf384('0x5e')]['id']}})['then'](handleEntityNotFound(_0x4cc4f9,null))[_0xf384('0x21')](function(_0x37c2fa){if(_0x37c2fa){_0x309b61[_0xf384('0x49')]=_[_0xf384('0x46')](db[_0xf384('0x63')][_0xf384('0x41')]);_0x309b61[_0xf384('0x45')]=_['keys'](_0x103e8e['query']);_0x309b61[_0xf384('0x47')]=_[_0xf384('0x48')](_0x309b61[_0xf384('0x49')],_0x309b61[_0xf384('0x45')]);_0x5525c4[_0xf384('0x4a')]=_[_0xf384('0x48')](_0x309b61['model'],qs[_0xf384('0x4b')](_0x103e8e[_0xf384('0x45')][_0xf384('0x4b')]));_0x5525c4[_0xf384('0x4a')]=_0x5525c4[_0xf384('0x4a')][_0xf384('0x57')]?_0x5525c4[_0xf384('0x4a')]:_0x309b61[_0xf384('0x49')];if(!_0x103e8e[_0xf384('0x45')][_0xf384('0x4c')]('nolimit')){_0x5525c4[_0xf384('0x30')]=qs[_0xf384('0x30')](_0x103e8e[_0xf384('0x45')][_0xf384('0x30')]);_0x5525c4['offset']=qs[_0xf384('0x2e')](_0x103e8e[_0xf384('0x45')]['offset']);}_0x5525c4[_0xf384('0x64')]=qs[_0xf384('0x4e')](_0x103e8e['query']['sort']);_0x5525c4[_0xf384('0x53')]=qs[_0xf384('0x47')](_[_0xf384('0x4f')](_0x103e8e[_0xf384('0x45')],_0x309b61[_0xf384('0x47')]));_0x5525c4[_0xf384('0x53')][_0xf384('0x61')]=_0x37c2fa['id'];if(_0x103e8e[_0xf384('0x45')][_0xf384('0x52')]){_0x5525c4[_0xf384('0x53')]=_[_0xf384('0x50')](_0x5525c4[_0xf384('0x53')],{'$or':_['map'](_0x5525c4['attributes'],function(_0x7ce195){var _0x112e86={};_0x112e86[_0x7ce195]={'$like':'%'+_0x103e8e[_0xf384('0x45')][_0xf384('0x52')]+'%'};return _0x112e86;})});}_0x5525c4=_[_0xf384('0x50')]({},_0x5525c4,_0x103e8e[_0xf384('0x65')]);return db[_0xf384('0x63')][_0xf384('0x31')]({'where':_0x5525c4['where']})[_0xf384('0x21')](function(_0x1883cd){_0x1119e9['count']=_0x1883cd;if(_0x103e8e[_0xf384('0x45')][_0xf384('0x54')]){_0x5525c4[_0xf384('0x66')]=[{'all':!![]}];}return db[_0xf384('0x63')]['findAll'](_0x5525c4);})['then'](function(_0x16311a){_0x1119e9['rows']=_0x16311a;return _0x1119e9;});}})[_0xf384('0x21')](respondWithFilteredResult(_0x4cc4f9,_0x5525c4))[_0xf384('0x2a')](handleError(_0x4cc4f9,null));};exports['removeDispositions']=function(_0xa6bd6e,_0xa9032f,_0x567f93){return db[_0xf384('0x40')]['find']({'where':{'id':_0xa6bd6e[_0xf384('0x5e')]['id']}})[_0xf384('0x21')](handleEntityNotFound(_0xa9032f,null))[_0xf384('0x21')](function(_0x5e2266){if(_0x5e2266){return _0x5e2266[_0xf384('0x67')](_0xa6bd6e['query'][_0xf384('0x68')]);}})[_0xf384('0x21')](respondWithStatusCode(_0xa9032f,null))[_0xf384('0x2a')](handleError(_0xa9032f,null));};exports[_0xf384('0x69')]=function(_0x1e57a0,_0x403cfe,_0x364525){if(_0x1e57a0[_0xf384('0x5a')]['id']){delete _0x1e57a0['body']['id'];}return db[_0xf384('0x40')][_0xf384('0x58')]({'where':{'id':_0x1e57a0[_0xf384('0x5e')]['id']}})['then'](handleEntityNotFound(_0x403cfe,null))[_0xf384('0x21')](function(_0x1b8cac){if(_0x1b8cac){_0x1e57a0[_0xf384('0x5a')][_0xf384('0x61')]=_0x1b8cac['id'];return db['CannedAnswer']['create'](_0x1e57a0['body']);}})['then'](respondWithResult(_0x403cfe,null))['catch'](handleError(_0x403cfe,null));};exports[_0xf384('0x6a')]=function(_0x26bd9d,_0x36f96d,_0x5c109a){var _0x45a19e={'raw':![],'where':{}};var _0x356235={};var _0x24393c={'count':0x0,'rows':[]};return db[_0xf384('0x40')][_0xf384('0x6b')]({'where':{'id':_0x26bd9d[_0xf384('0x5e')]['id']}})[_0xf384('0x21')](handleEntityNotFound(_0x36f96d,null))[_0xf384('0x21')](function(_0x186524){if(_0x186524){_0x356235['model']=_['keys'](db[_0xf384('0x6c')][_0xf384('0x41')]);_0x356235[_0xf384('0x45')]=_[_0xf384('0x46')](_0x26bd9d['query']);_0x356235[_0xf384('0x47')]=_[_0xf384('0x48')](_0x356235[_0xf384('0x49')],_0x356235[_0xf384('0x45')]);_0x45a19e[_0xf384('0x4a')]=_[_0xf384('0x48')](_0x356235[_0xf384('0x49')],qs[_0xf384('0x4b')](_0x26bd9d['query'][_0xf384('0x4b')]));_0x45a19e[_0xf384('0x4a')]=_0x45a19e[_0xf384('0x4a')][_0xf384('0x57')]?_0x45a19e['attributes']:_0x356235[_0xf384('0x49')];if(!_0x26bd9d['query'][_0xf384('0x4c')](_0xf384('0x4d'))){_0x45a19e['limit']=qs[_0xf384('0x30')](_0x26bd9d[_0xf384('0x45')]['limit']);_0x45a19e['offset']=qs[_0xf384('0x2e')](_0x26bd9d['query']['offset']);}_0x45a19e[_0xf384('0x64')]=qs[_0xf384('0x4e')](_0x26bd9d['query'][_0xf384('0x4e')]);_0x45a19e[_0xf384('0x53')]=qs[_0xf384('0x47')](_[_0xf384('0x4f')](_0x26bd9d[_0xf384('0x45')],_0x356235['filters']));_0x45a19e['where']['SmsAccountId']=_0x186524['id'];if(_0x26bd9d[_0xf384('0x45')]['filter']){_0x45a19e[_0xf384('0x53')]=_[_0xf384('0x50')](_0x45a19e['where'],{'$or':_[_0xf384('0x3f')](_0x45a19e[_0xf384('0x4a')],function(_0x1579a7){var _0x120a4e={};_0x120a4e[_0x1579a7]={'$like':'%'+_0x26bd9d[_0xf384('0x45')][_0xf384('0x52')]+'%'};return _0x120a4e;})});}_0x45a19e=_[_0xf384('0x50')]({},_0x45a19e,_0x26bd9d[_0xf384('0x65')]);return db[_0xf384('0x6c')][_0xf384('0x31')]({'where':_0x45a19e[_0xf384('0x53')]})[_0xf384('0x21')](function(_0x35a1e0){_0x24393c[_0xf384('0x31')]=_0x35a1e0;if(_0x26bd9d[_0xf384('0x45')][_0xf384('0x54')]){_0x45a19e['include']=[{'all':!![]}];}return db['CannedAnswer'][_0xf384('0x55')](_0x45a19e);})[_0xf384('0x21')](function(_0x377cc0){_0x24393c[_0xf384('0x56')]=_0x377cc0;return _0x24393c;});}})[_0xf384('0x21')](respondWithFilteredResult(_0x36f96d,_0x45a19e))[_0xf384('0x2a')](handleError(_0x36f96d,null));};exports[_0xf384('0x6d')]=function(_0x4dbb17,_0x3499ac,_0x12ba04){return db[_0xf384('0x40')]['find']({'where':{'id':_0x4dbb17[_0xf384('0x5e')]['id']}})[_0xf384('0x21')](handleEntityNotFound(_0x3499ac,null))['then'](function(_0x20e927){if(_0x20e927){return _0x20e927[_0xf384('0x6d')](_0x4dbb17[_0xf384('0x45')][_0xf384('0x68')]);}})[_0xf384('0x21')](respondWithStatusCode(_0x3499ac,null))[_0xf384('0x2a')](handleError(_0x3499ac,null));};exports[_0xf384('0x6e')]=function(_0x8e720a,_0x11a36d,_0x16dd82){var _0xfa32f4={'channel':'sms'};var _0x125d95=[];var _0x215642=[];var _0x1c2d87={};return db[_0xf384('0x40')][_0xf384('0x58')]({'where':{'id':_0x8e720a[_0xf384('0x5e')]['id']},'include':[{'model':db[_0xf384('0x6f')],'as':'Applications'}]})['then'](handleEntityNotFound(_0x11a36d,null))[_0xf384('0x21')](function(_0x34b0cf){_0xfa32f4[_0xf384('0x70')]=_0x34b0cf;_0xfa32f4['applications']=_[_0xf384('0x71')](_0x34b0cf[_0xf384('0x72')],[_0xf384('0x73')],[_0xf384('0x74')]);if(_0xfa32f4['account'][_0xf384('0x72')]){delete _0xfa32f4[_0xf384('0x70')]['Applications'];}return db[_0xf384('0x75')][_0xf384('0x5f')]();})[_0xf384('0x21')](function(_0x3304f4){if(!_0x3304f4){throw new db[(_0xf384('0x76'))][(_0xf384('0x77'))](_0xf384('0x78'));}_0x125d95=_[_0xf384('0x79')](_[_0xf384('0x46')](_0x3304f4),[_0xf384('0x7a'),_0xf384('0x7b')]);_0x215642=_[_0xf384('0x79')](_[_0xf384('0x46')](_0x3304f4),[_0xf384('0x7a'),_0xf384('0x7b'),'CompanyId','ListId']);_0xfa32f4[_0xf384('0x5a')]={'mapKey':_0xf384('0x7c')};if(_0xfa32f4[_0xf384('0x70')][_0xf384('0x43')]){switch(_0xfa32f4['account'][_0xf384('0x43')]){case _0xf384('0x7d'):_0xfa32f4[_0xf384('0x5a')][_0xf384('0x7e')]=_0x8e720a[_0xf384('0x5a')][_0xf384('0x7f')];_0xfa32f4['body'][_0xf384('0x5a')]=_0x8e720a[_0xf384('0x5a')][_0xf384('0x80')];_0xfa32f4[_0xf384('0x5a')]['messageId']=_0x8e720a[_0xf384('0x5a')][_0xf384('0x81')];break;case'skebby':_0xfa32f4[_0xf384('0x5a')][_0xf384('0x7e')]='+'+_0x8e720a[_0xf384('0x5a')]['sender'];_0xfa32f4['body']['body']=_0x8e720a[_0xf384('0x5a')][_0xf384('0x82')];break;case _0xf384('0x83'):_0xfa32f4[_0xf384('0x5a')][_0xf384('0x7e')]=_0x8e720a[_0xf384('0x5a')][_0xf384('0x7e')];_0xfa32f4['body'][_0xf384('0x5a')]=_0x8e720a[_0xf384('0x5a')]['message'];break;case'clicksend':_0xfa32f4['body'][_0xf384('0x7e')]=_0x8e720a[_0xf384('0x5a')][_0xf384('0x7e')];_0xfa32f4['body']['body']=_0x8e720a[_0xf384('0x5a')][_0xf384('0x5a')];_0xfa32f4[_0xf384('0x5a')][_0xf384('0x84')]=_0x8e720a['body'][_0xf384('0x85')];break;case'plivo':_0xfa32f4[_0xf384('0x5a')][_0xf384('0x7e')]=_0x8e720a[_0xf384('0x5a')][_0xf384('0x7f')];_0xfa32f4[_0xf384('0x5a')]['body']=_0x8e720a['body'][_0xf384('0x86')];_0xfa32f4[_0xf384('0x5a')][_0xf384('0x84')]=_0x8e720a[_0xf384('0x5a')][_0xf384('0x87')];break;case _0xf384('0x88'):_0xfa32f4[_0xf384('0x5a')][_0xf384('0x7e')]='+'+_0x8e720a['body'][_0xf384('0x89')][0x0][_0xf384('0x7e')];_0xfa32f4[_0xf384('0x5a')][_0xf384('0x5a')]=_0x8e720a['body'][_0xf384('0x89')][0x0][_0xf384('0x82')];_0xfa32f4[_0xf384('0x5a')][_0xf384('0x84')]=_0x8e720a['body'][_0xf384('0x89')][0x0]['messageId'];break;case _0xf384('0x8a'):_0xfa32f4[_0xf384('0x5a')][_0xf384('0x7e')]=_0x8e720a[_0xf384('0x5a')][_0xf384('0x8b')];_0xfa32f4[_0xf384('0x5a')][_0xf384('0x5a')]=_0x8e720a[_0xf384('0x5a')][_0xf384('0x8c')]['message'];break;case _0xf384('0x8d'):_0xfa32f4[_0xf384('0x5a')][_0xf384('0x7e')]=_0x8e720a['body'][_0xf384('0x8e')];_0xfa32f4[_0xf384('0x5a')][_0xf384('0x5a')]=_0x8e720a[_0xf384('0x5a')]['text'];_0xfa32f4[_0xf384('0x5a')]['messageId']=_0x8e720a['body'][_0xf384('0x8f')];break;case _0xf384('0x90'):_0xfa32f4[_0xf384('0x5a')][_0xf384('0x84')]=_0x8e720a[_0xf384('0x5a')][0x0]['message']['id'];_0xfa32f4['body'][_0xf384('0x7e')]=_0x8e720a['body'][0x0][_0xf384('0x28')][_0xf384('0x7e')];_0xfa32f4[_0xf384('0x5a')][_0xf384('0x5a')]=_0x8e720a[_0xf384('0x5a')][0x0][_0xf384('0x28')][_0xf384('0x82')];break;case _0xf384('0x91'):_0xfa32f4[_0xf384('0x5a')]['from']=_0x8e720a[_0xf384('0x5a')]['from'];_0xfa32f4[_0xf384('0x5a')][_0xf384('0x5a')]=_0x8e720a[_0xf384('0x5a')]['message'];_0xfa32f4[_0xf384('0x5a')]['messageId']=_0x8e720a[_0xf384('0x5a')][_0xf384('0x92')];break;}}if(_0xfa32f4[_0xf384('0x5a')]['id']){delete _0xfa32f4[_0xf384('0x5a')]['id'];}if(_[_0xf384('0x93')](_0xfa32f4[_0xf384('0x5a')][_0xf384('0x7e')])){throw new db[(_0xf384('0x76'))][(_0xf384('0x77'))]('from\x20is\x20mandatory');}if(_[_0xf384('0x93')](_0xfa32f4[_0xf384('0x5a')][_0xf384('0x5a')])||_0xfa32f4[_0xf384('0x5a')][_0xf384('0x5a')]===''){throw new db['Sequelize']['ValidationError'](_0xf384('0x94'));}if(_[_0xf384('0x93')](_0xfa32f4['body']['mapKey'])){throw new db[(_0xf384('0x76'))][(_0xf384('0x77'))](_0xf384('0x95')+_0x215642);}if(!_[_0xf384('0x96')](_0x215642,_0xfa32f4[_0xf384('0x5a')][_0xf384('0x97')])){throw new db[(_0xf384('0x76'))][(_0xf384('0x77'))](_0xf384('0x98')+_0x215642);}_0x1c2d87[_0xfa32f4['body'][_0xf384('0x97')]]=_0xfa32f4[_0xf384('0x5a')]['from'];return db[_0xf384('0x99')]['find']({'where':{'id':_0xfa32f4[_0xf384('0x70')][_0xf384('0x9a')]},'include':[{'model':db[_0xf384('0x75')],'as':_0xf384('0x9b'),'where':_0x1c2d87,'limit':0x1,'order':[[_0xf384('0x7b'),_0xf384('0x9c')]]}]});})[_0xf384('0x21')](handleEntityNotFound(_0x11a36d,null))[_0xf384('0x21')](function(_0x2db34a){if(_0x2db34a){_0xfa32f4[_0xf384('0x9d')]=_[_0xf384('0x9e')](_0x2db34a,['Contacts']);if(_0x2db34a[_0xf384('0x9b')][_0xf384('0x57')]){return _0x2db34a[_0xf384('0x9b')][0x0];}var _0xe63a8d=_[_0xf384('0x18')](_0xfa32f4[_0xf384('0x5a')],{'firstName':_0xfa32f4[_0xf384('0x5a')][_0xf384('0x7e')],'ListId':_0x2db34a['id']});_0xe63a8d[_0xfa32f4[_0xf384('0x5a')][_0xf384('0x97')]]=_0xfa32f4['body'][_0xf384('0x7e')];return db[_0xf384('0x75')]['create'](_0xe63a8d,{'fields':_0x125d95,'raw':!![]});}})['then'](handleEntityNotFound(_0x11a36d,null))[_0xf384('0x21')](function(_0x3a005f){if(_0x3a005f){_0xfa32f4[_0xf384('0x9f')]=_0x3a005f;var _0x13de4f={'ContactId':_0x3a005f['id'],'phone':_0xfa32f4[_0xf384('0x5a')][_0xf384('0x7e')],'SmsAccountId':_0x8e720a['params']['id']};var _0x34449d={'ContactId':_0x3a005f['id'],'SmsAccountId':_0x8e720a[_0xf384('0x5e')]['id'],'closed':![]};return db[_0xf384('0xa0')]['find']({'where':_0x34449d})[_0xf384('0x21')](function(_0x41778f){if(_0x41778f){return[_0x41778f,![]];}return db[_0xf384('0xa0')]['create'](_0x13de4f)[_0xf384('0x21')](function(_0x340913){return[_0x340913,!![]];});});}})[_0xf384('0xa1')](function(_0x3577ef,_0xcc5541){_0xfa32f4['interaction']=_0x3577ef[_0xf384('0x38')]({'plain':!![]});_0xfa32f4[_0xf384('0xa2')][_0xf384('0xa3')]=![];if(_0xcc5541){if(_0xfa32f4[_0xf384('0x70')]['autoclose']){_0xfa32f4[_0xf384('0xa4')][_0xf384('0xa5')]({'id':0x0,'priority':_0xfa32f4[_0xf384('0xa4')][_0xf384('0x57')]+0x1,'app':_0xf384('0xa6'),'appdata':_0xf384('0xa7'),'interval':_0xf384('0xa8')});}_0xfa32f4['interaction'][_0xf384('0xa3')]=!![];}return db[_0xf384('0xa9')]['create']({'phone':_0xfa32f4[_0xf384('0x5a')]['from'],'messageId':_0xfa32f4[_0xf384('0x5a')][_0xf384('0x84')],'body':_0xfa32f4[_0xf384('0x5a')][_0xf384('0x5a')],'SmsAccountId':_0x8e720a[_0xf384('0x5e')]['id'],'SmsInteractionId':_0x3577ef['id'],'direction':'in','ContactId':_0x3577ef[_0xf384('0xaa')],'AttachmentId':_0xfa32f4['body']['AttachmentId']});})[_0xf384('0x21')](function(_0x149e00){_0xfa32f4[_0xf384('0x28')]=_0x149e00;if(!_0xfa32f4['interaction']['UserId'])return;return db[_0xf384('0xab')][_0xf384('0x58')]({'attributes':['id',_0xf384('0x3b')],'where':{'id':_0xfa32f4[_0xf384('0xa2')][_0xf384('0xac')]}});})[_0xf384('0x21')](function(_0x3b9885){if(_0x3b9885){_0xfa32f4[_0xf384('0xa4')]['unshift']({'id':0x0,'priority':0x0,'app':_0xf384('0xad'),'appdata':_0x3b9885[_0xf384('0x3b')]+','+(_0xfa32f4[_0xf384('0x70')][_0xf384('0xae')]||0xa),'interval':_0xf384('0xa8')});}if(!_0xfa32f4[_0xf384('0xa2')]['queueId'])return;return db[_0xf384('0xaf')]['find']({'attributes':['id','name'],'where':{'id':_0xfa32f4[_0xf384('0xa2')][_0xf384('0xb0')]}});})[_0xf384('0x21')](function(_0x511775){if(_0x511775){_0xfa32f4[_0xf384('0xa4')]['unshift']({'id':0x0,'priority':0x1,'app':_0xf384('0xb1'),'appdata':_0x511775[_0xf384('0x3b')]+','+(_0xfa32f4[_0xf384('0x70')][_0xf384('0xb2')]||0x12c),'interval':_0xf384('0xa8')});}return respondWithRpcPromise('Start',_0xf384('0xb3'),_0xfa32f4);})[_0xf384('0x21')](function(_0x5bcae2){if(_0x5bcae2){var _0xbb02cd=0xc8;var _0xf0a033=_0xf384('0xb4');logger[_0xf384('0x22')](_0xf384('0xb5'),_0xf0a033,_0xbb02cd,_0xf384('0xb6'));logger[_0xf384('0x25')]('SmsAccount,\x20%s,\x20%s,\x20%s,\x20%s',_0xf0a033,_0xbb02cd,_0xf384('0xb6'),JSON[_0xf384('0xb7')](_0x5bcae2));if(_0xfa32f4[_0xf384('0x70')][_0xf384('0x43')]===_0xf384('0x7d')){return _0x11a36d[_0xf384('0x2c')](_0xbb02cd)[_0xf384('0xb8')]('Content-Type','text/xml')[_0xf384('0x3c')](_0xf384('0xb9'));}else{return _0x11a36d[_0xf384('0x2c')](_0xbb02cd)[_0xf384('0xba')](_0x5bcae2);}}})[_0xf384('0x2a')](handleError(_0x11a36d,null));};exports[_0xf384('0xbb')]=function(_0x2f7e22,_0x3dec3e){var _0x200de8=_0x2f7e22[_0xf384('0x5e')]['id'];var _0xc6ba1f=_0x2f7e22[_0xf384('0x5a')];var _0x1ec342=0xc8;var _0x3e26fb=null;return db[_0xf384('0xbc')][_0xf384('0xbd')]({'isolationLevel':db['sequelize'][_0xf384('0xbe')][_0xf384('0xbf')][_0xf384('0xc0')]},function(_0x370aa4){return db['SmsAccount'][_0xf384('0x6b')]({'where':{'id':_0x200de8},'transaction':_0x370aa4})[_0xf384('0x21')](function(_0x150bcf){if(_0x150bcf){return db['SmsApplication']['destroy']({'where':{'SmsAccountId':_0x200de8},'transaction':_0x370aa4})[_0xf384('0x21')](function(){var _0x357c3b=_['map'](_0xc6ba1f,function(_0x506da5){_0x506da5['SmsAccountId']=_0x200de8;return _0x506da5;});return db[_0xf384('0x6f')][_0xf384('0xc1')](_0x357c3b,{'transaction':_0x370aa4});});}else{_0x1ec342=0x194;_0x3e26fb=[];}});})[_0xf384('0x21')](function(){if(_0x1ec342!==0x194){return db[_0xf384('0x6f')][_0xf384('0xc2')]({'where':{'SmsAccountId':_0x200de8},'order':_0xf384('0x73')})[_0xf384('0x21')](function(_0x2bffd5){_0x3e26fb=_0x2bffd5;});}})[_0xf384('0x2a')](function(_0x99b15f){_0x1ec342=0x1f4;logger[_0xf384('0x26')](_0x99b15f[_0xf384('0x3a')]);if(_0x99b15f['name']){delete _0x99b15f[_0xf384('0x3b')];}_0x3e26fb=_0x99b15f;})[_0xf384('0xc3')](function(){if(_0x3e26fb===null){_0x3dec3e[_0xf384('0x2b')](_0x1ec342);}else{if(_0x1ec342===0x1f4){_0x3dec3e['status'](_0x1ec342)[_0xf384('0x3c')](_0x3e26fb);}else{_0x3dec3e[_0xf384('0x2c')](_0x1ec342)[_0xf384('0xba')](_0x3e26fb);}}});};exports['getApplications']=function(_0x24b0a3,_0x17ffa1,_0x5ee1c9){var _0x3930f7={};var _0x149197={};var _0x4ae467;var _0x17e3f3;return db[_0xf384('0x40')][_0xf384('0x6b')]({'where':{'id':_0x24b0a3['params']['id']}})['then'](handleEntityNotFound(_0x17ffa1,null))[_0xf384('0x21')](function(_0x155351){if(_0x155351){_0x4ae467=_0x155351;_0x149197[_0xf384('0x49')]=_[_0xf384('0x46')](db['SmsApplication'][_0xf384('0x41')]);_0x149197[_0xf384('0x45')]=_[_0xf384('0x46')](_0x24b0a3[_0xf384('0x45')]);_0x149197[_0xf384('0x47')]=_['intersection'](_0x149197[_0xf384('0x49')],_0x149197[_0xf384('0x45')]);_0x3930f7[_0xf384('0x4a')]=_[_0xf384('0x48')](_0x149197[_0xf384('0x49')],qs[_0xf384('0x4b')](_0x24b0a3['query'][_0xf384('0x4b')]));_0x3930f7[_0xf384('0x4a')]=_0x3930f7[_0xf384('0x4a')][_0xf384('0x57')]?_0x3930f7['attributes']:_0x149197[_0xf384('0x49')];_0x3930f7[_0xf384('0x64')]=qs['sort'](_0x24b0a3[_0xf384('0x45')][_0xf384('0x4e')]);_0x3930f7['where']=qs[_0xf384('0x47')](_[_0xf384('0x4f')](_0x24b0a3[_0xf384('0x45')],_0x149197[_0xf384('0x47')]));if(_0x24b0a3[_0xf384('0x45')][_0xf384('0x52')]){_0x3930f7[_0xf384('0x53')]=_[_0xf384('0x50')](_0x3930f7[_0xf384('0x53')],{'$or':_['map'](_0x3930f7['attributes'],function(_0x237588){var _0x3ba75d={};_0x3ba75d[_0x237588]={'$like':'%'+_0x24b0a3[_0xf384('0x45')][_0xf384('0x52')]+'%'};return _0x3ba75d;})});}_0x3930f7=_[_0xf384('0x50')]({},_0x3930f7,_0x24b0a3[_0xf384('0x65')]);return _0x4ae467[_0xf384('0xc4')](_0x3930f7);}})[_0xf384('0x21')](function(_0x3dc055){if(_0x3dc055){_0x17e3f3=_0x3dc055['length'];if(!_0x24b0a3['query']['hasOwnProperty'](_0xf384('0x4d'))){_0x3930f7[_0xf384('0x30')]=qs['limit'](_0x24b0a3[_0xf384('0x45')][_0xf384('0x30')]);_0x3930f7[_0xf384('0x2e')]=qs['offset'](_0x24b0a3['query']['offset']);}return _0x4ae467[_0xf384('0xc4')](_0x3930f7);}})[_0xf384('0x21')](function(_0x44b2d5){if(_0x44b2d5){return _0x44b2d5?{'count':_0x17e3f3,'rows':_0x44b2d5}:null;}})['then'](respondWithResult(_0x17ffa1,null))['catch'](handleError(_0x17ffa1,null));};exports[_0xf384('0xc5')]=function(_0x1bc779,_0x1130db,_0x279caf){var _0x3eba98={'raw':![],'where':{}};var _0x2f0a52={};var _0x55b6aa={'count':0x0,'rows':[]};return db[_0xf384('0x40')][_0xf384('0x6b')]({'where':{'id':_0x1bc779['params']['id']}})[_0xf384('0x21')](handleEntityNotFound(_0x1130db,null))[_0xf384('0x21')](function(_0x4b78ba){if(_0x4b78ba){_0x2f0a52['model']=_[_0xf384('0x46')](db[_0xf384('0xa0')]['rawAttributes']);_0x2f0a52['query']=_[_0xf384('0x46')](_0x1bc779[_0xf384('0x45')]);_0x2f0a52['filters']=_[_0xf384('0x48')](_0x2f0a52[_0xf384('0x49')],_0x2f0a52[_0xf384('0x45')]);_0x3eba98[_0xf384('0x4a')]=_[_0xf384('0x48')](_0x2f0a52[_0xf384('0x49')],qs[_0xf384('0x4b')](_0x1bc779['query'][_0xf384('0x4b')]));_0x3eba98[_0xf384('0x4a')]=_0x3eba98[_0xf384('0x4a')][_0xf384('0x57')]?_0x3eba98['attributes']:_0x2f0a52['model'];if(!_0x1bc779[_0xf384('0x45')][_0xf384('0x4c')](_0xf384('0x4d'))){_0x3eba98['limit']=qs[_0xf384('0x30')](_0x1bc779[_0xf384('0x45')][_0xf384('0x30')]);_0x3eba98[_0xf384('0x2e')]=qs[_0xf384('0x2e')](_0x1bc779[_0xf384('0x45')][_0xf384('0x2e')]);}_0x3eba98['order']=qs[_0xf384('0x4e')](_0x1bc779['query'][_0xf384('0x4e')]);_0x3eba98[_0xf384('0x53')]=qs[_0xf384('0x47')](_['pick'](_0x1bc779[_0xf384('0x45')],_0x2f0a52['filters']));_0x3eba98[_0xf384('0x53')][_0xf384('0x61')]=_0x4b78ba['id'];if(_0x1bc779[_0xf384('0x45')]['filter']){_0x3eba98[_0xf384('0x53')]=_[_0xf384('0x50')](_0x3eba98['where'],{'$or':_[_0xf384('0x3f')](_0x3eba98[_0xf384('0x4a')],function(_0x1dafc6){var _0x520b37={};_0x520b37[_0x1dafc6]={'$like':'%'+_0x1bc779[_0xf384('0x45')][_0xf384('0x52')]+'%'};return _0x520b37;})});}_0x3eba98=_['merge']({},_0x3eba98,_0x1bc779['options']);return db[_0xf384('0xa0')]['count']({'where':_0x3eba98['where']})[_0xf384('0x21')](function(_0xcd6dcd){_0x55b6aa[_0xf384('0x31')]=_0xcd6dcd;if(_0x1bc779['query'][_0xf384('0x54')]){_0x3eba98[_0xf384('0x66')]=[{'model':db[_0xf384('0x75')],'as':'Contact','required':![]},{'model':db[_0xf384('0xab')],'as':_0xf384('0xc6'),'attributes':[_0xf384('0x3b'),_0xf384('0xc7'),'internal'],'required':![]},{'model':db[_0xf384('0xc8')],'as':_0xf384('0xc9'),'attributes':['id',_0xf384('0x3b'),_0xf384('0xca')],'where':_0x1bc779[_0xf384('0x45')][_0xf384('0xcb')]?{'id':_0x1bc779[_0xf384('0x45')]['tag']}:undefined,'required':_0x1bc779['query']['tag']?!![]:![]}];}return db[_0xf384('0xa0')][_0xf384('0x55')](_0x3eba98);})[_0xf384('0x21')](function(_0x56de21){_0x55b6aa[_0xf384('0x56')]=_0x56de21;return _0x55b6aa;});}})[_0xf384('0x21')](respondWithFilteredResult(_0x1130db,_0x3eba98))[_0xf384('0x2a')](handleError(_0x1130db,null));};exports[_0xf384('0x3c')]=function(_0x1df6db,_0x2ea33b,_0x588108){var _0x1628a4,_0x2ed4ae,_0xbd948;if(_[_0xf384('0x93')](_0x1df6db[_0xf384('0x5a')][_0xf384('0x5a')])||_0x1df6db[_0xf384('0x5a')][_0xf384('0x5a')]===''){throw new db[(_0xf384('0x76'))][(_0xf384('0x77'))](_0xf384('0x94'));}if(_['isNil'](_0x1df6db['body']['to'])){throw new db[(_0xf384('0x76'))][(_0xf384('0x77'))]('to\x20is\x20mandatory');}_0x1628a4=_0x1df6db[_0xf384('0x5a')]['to'];return db[_0xf384('0x40')][_0xf384('0x58')]({'where':{'id':_0x1df6db[_0xf384('0x5e')]['id']},'include':[{'model':db[_0xf384('0x99')],'as':_0xf384('0xcc'),'include':[{'model':db['CmContact'],'as':_0xf384('0x9b'),'where':{'mobile':_0x1628a4},'limit':0x1,'order':[[_0xf384('0x7b'),_0xf384('0x9c')]]}]}]})['then'](handleEntityNotFound(_0x2ea33b,null))['then'](function(_0x1d1d3f){if(_0x1d1d3f&&_0x1d1d3f[_0xf384('0xcc')]){_0x2ed4ae=_0x1d1d3f['get']({'plain':!![]});if(_0x2ed4ae[_0xf384('0xcc')]&&_0x2ed4ae['List'][_0xf384('0x9b')]['length']){return _0x2ed4ae['List'][_0xf384('0x9b')][0x0];}return db[_0xf384('0x75')][_0xf384('0x59')](_['defaults'](_0x1df6db[_0xf384('0x5a')],{'firstName':_0x1628a4,'mobile':_0x1628a4,'phone':_0x1628a4,'ListId':_0x2ed4ae[_0xf384('0x9a')]}));}})[_0xf384('0x21')](handleEntityNotFound(_0x2ea33b,null))[_0xf384('0x21')](function(_0x50bbed){if(_0x50bbed){_0xbd948=_0x50bbed;return db[_0xf384('0xa0')][_0xf384('0x58')]({'where':{'ContactId':_0xbd948['id'],'closed':![],'SmsAccountId':_0x2ed4ae['id']}})['then'](function(_0x12e9a7){if(_0x12e9a7){return[_0x12e9a7,![]];}return db[_0xf384('0xa0')][_0xf384('0x59')]({'UserId':_0x1df6db[_0xf384('0x5b')]['id'],'ContactId':_0xbd948['id'],'SmsAccountId':_0x2ed4ae['id'],'phone':_0x1628a4,'firstMsgDirection':_0xf384('0xcd'),'Messages':[_[_0xf384('0x50')](_0x1df6db[_0xf384('0x5a')],{'read':![],'body':_0x1df6db['body']['body'],'phone':_0x1628a4,'SmsAccountId':_0x2ed4ae['id'],'UserId':_0x1df6db[_0xf384('0x5b')]['id'],'ContactId':_0xbd948['id']})]},{'include':[{'model':db[_0xf384('0xa9')],'as':_0xf384('0xce')}]})[_0xf384('0x21')](function(_0x25a50d){return[_0x25a50d,!![]];});});}})[_0xf384('0xa1')](function(_0x5294d4,_0x4d6c2a){if(_0x4d6c2a){return _0x5294d4;}return db[_0xf384('0xa9')][_0xf384('0x59')](_['merge'](_0x1df6db[_0xf384('0x5a')],{'read':![],'body':_0x1df6db[_0xf384('0x5a')][_0xf384('0x5a')],'phone':_0x1628a4,'SmsAccountId':_0x2ed4ae['id'],'SmsInteractionId':_0x5294d4['id'],'UserId':_0x1df6db[_0xf384('0x5b')]['id'],'ContactId':_0xbd948['id']}))[_0xf384('0x21')](function(_0x24fc83){_0x5294d4['dataValues'][_0xf384('0xce')]=[];_0x5294d4[_0xf384('0xcf')]['Messages'][_0xf384('0xa5')](_0x24fc83[_0xf384('0xcf')]);return _0x5294d4;});})[_0xf384('0x21')](respondWithResult(_0x2ea33b,null))[_0xf384('0x2a')](handleError(_0x2ea33b,null));};exports[_0xf384('0x2c')]=function(_0x4d5c78,_0x2ab160,_0x34ada3){if(_0x4d5c78['body']['id']){delete _0x4d5c78[_0xf384('0x5a')]['id'];}var _0x14bef5,_0x58510c,_0x2ce598;return db[_0xf384('0x40')]['find']({'where':{'id':_0x4d5c78['params']['id']}})['then'](handleEntityNotFound(_0x2ab160,null))[_0xf384('0x21')](function(_0x13540d){if(_0x13540d){_0x2ce598=_0x13540d;logger[_0xf384('0x25')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0xf384('0x2c'),_0xf384('0xd0'),_0x13540d[_0xf384('0x43')],util[_0xf384('0xd1')](_0x4d5c78['body'],{'showHidden':![],'depth':null}));switch(_0x13540d[_0xf384('0x43')]){case'skebby':if(_0x4d5c78[_0xf384('0x5a')]['skebby_dispatch_id']&&_0x4d5c78[_0xf384('0x5a')][_0xf384('0x2c')]){_0x58510c=_0x4d5c78[_0xf384('0x5a')][_0xf384('0x2c')];return db[_0xf384('0xa9')]['find']({'where':{'messageId':_0x4d5c78[_0xf384('0x5a')][_0xf384('0xd2')]}});}break;case _0xf384('0x83'):if(_0x4d5c78[_0xf384('0x5a')]['requestid']&&_0x4d5c78[_0xf384('0x5a')][_0xf384('0xd3')]){_0x58510c=_0x4d5c78[_0xf384('0x5a')][_0xf384('0xd3')];return db['SmsMessage'][_0xf384('0x58')]({'where':{'messageId':_0x4d5c78[_0xf384('0x5a')][_0xf384('0xd4')]}});}break;case'clicksend':if(_0x4d5c78['body'][_0xf384('0x85')]&&_0x4d5c78[_0xf384('0x5a')][_0xf384('0xd5')]){_0x58510c=_0x4d5c78[_0xf384('0x5a')][_0xf384('0xd5')];return db['SmsMessage'][_0xf384('0x58')]({'where':{'messageId':_0x4d5c78['body'][_0xf384('0x85')]}});}break;case _0xf384('0x88'):var _0x5e5117=_0x4d5c78['body'][_0xf384('0x89')][0x0];if(_0x5e5117[_0xf384('0x84')]&&_0x5e5117['status'][_0xf384('0xd6')]==='DELIVERED'){_0x58510c=_0x5e5117[_0xf384('0x2c')]['groupName'];return db[_0xf384('0xa9')][_0xf384('0x58')]({'where':{'messageId':_0x5e5117[_0xf384('0x84')]}});}break;case'clickatell':if(_0x4d5c78[_0xf384('0x5a')][_0xf384('0x84')]&&_0x4d5c78[_0xf384('0x5a')][_0xf384('0x2c')]){_0x58510c=_0x4d5c78[_0xf384('0x5a')][_0xf384('0x2c')];return db[_0xf384('0xa9')]['find']({'where':{'messageId':_0x4d5c78[_0xf384('0x5a')][_0xf384('0x84')]}});}break;case _0xf384('0x90'):if(_0x4d5c78[_0xf384('0x5a')][0x0]['message']['id']){_0x58510c=_0x4d5c78[_0xf384('0x5a')][0x0][_0xf384('0x43')];return db[_0xf384('0xa9')][_0xf384('0x58')]({'where':{'messageId':_0x4d5c78[_0xf384('0x5a')][0x0][_0xf384('0x28')]['id']}});}break;case _0xf384('0x91'):if(_0x4d5c78[_0xf384('0x5a')]['redif']&&_0x4d5c78[_0xf384('0x5a')][_0xf384('0x2c')]){_0x58510c=_0x4d5c78[_0xf384('0x5a')][_0xf384('0x2c')];return db['SmsMessage'][_0xf384('0x58')]({'where':{'messageId':_0x4d5c78[_0xf384('0x5a')][_0xf384('0xd7')]}});}break;}}})['then'](handleEntityNotFound(_0x2ab160,null))['then'](function(_0x47a2bb){if(_0x47a2bb){_0x14bef5=_0x47a2bb;switch(_0x2ce598[_0xf384('0x43')]){case _0xf384('0xd8'):if(_0x58510c==='DELIVERED'){return _0x14bef5[_0xf384('0x36')]({'read':!![]});}else{logger[_0xf384('0x26')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0xf384('0x2c'),_0xf384('0xd8'),util[_0xf384('0xd1')](_0x4d5c78[_0xf384('0x5a')],{'showHidden':![],'depth':null}));}break;case _0xf384('0x83'):if(_0x58510c==='1'){return _0x14bef5[_0xf384('0x36')]({'read':!![]});}else{logger[_0xf384('0x26')](_0xf384('0xb5'),'status',_0xf384('0xd8'),util[_0xf384('0xd1')](_0x4d5c78[_0xf384('0x5a')],{'showHidden':![],'depth':null}));}break;case'clicksend':if(!_0x4d5c78[_0xf384('0x5a')][_0xf384('0xd9')]&&_0x58510c>=0xc8&&_0x58510c<=0xce){return _0x14bef5[_0xf384('0x36')]({'read':!![]});}else{logger[_0xf384('0x26')](_0xf384('0xb5'),'status',_0xf384('0xda'),util['inspect'](_0x4d5c78[_0xf384('0x5a')],{'showHidden':![],'depth':null}));}break;case _0xf384('0x88'):var _0x280570=_0x4d5c78[_0xf384('0x5a')][_0xf384('0x89')][0x0];if(_0x280570['status'][_0xf384('0xd6')]===_0xf384('0xdb')){return _0x14bef5['update']({'read':!![]});}else{logger[_0xf384('0x26')](_0xf384('0xb5'),_0xf384('0x2c'),'infobip',util[_0xf384('0xd1')](_0x4d5c78[_0xf384('0x5a')],{'showHidden':![],'depth':null}));}break;case _0xf384('0x8d'):if(_0x58510c=='DELIVERED_TO_GATEWAY'||_0x58510c=='RECEIVED_BY_RECIPIENT'){return _0x14bef5[_0xf384('0x36')]({'read':!![]});}else{logger['error']('SmsAccount,\x20%s,\x20%s,\x20%s','status','clickatell',util[_0xf384('0xd1')](_0x4d5c78[_0xf384('0x5a')],{'showHidden':![],'depth':null}));}break;case _0xf384('0x90'):if(_0x58510c=='message-delivered'){return _0x14bef5['update']({'read':!![]});}else{logger[_0xf384('0x26')](_0xf384('0xb5'),_0xf384('0x2c'),_0xf384('0x90'),util[_0xf384('0xd1')](_0x4d5c78[_0xf384('0x5a')],{'showHidden':![],'depth':null}));}break;case _0xf384('0x91'):if(_0x58510c===_0xf384('0xdc')||_0x58510c===_0xf384('0xdd')){return _0x14bef5[_0xf384('0x36')]({'read':!![]});}else{logger[_0xf384('0x26')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0xf384('0x2c'),_0xf384('0x91'),util[_0xf384('0xd1')](_0x4d5c78[_0xf384('0x5a')],{'showHidden':![],'depth':null}));}break;}return _0x14bef5;}})[_0xf384('0x21')](respondWithResult(_0x2ab160,null))[_0xf384('0x2a')](handleError(_0x2ab160,null));};exports[_0xf384('0xde')]=function(_0x33c9b8,_0x550e55,_0x4dba45){var _0x239a46,_0x2ab884,_0x5884ef;return db[_0xf384('0x40')][_0xf384('0x58')]({'where':{'id':_0x33c9b8[_0xf384('0x5e')]['id']}})['then'](handleEntityNotFound(_0x550e55,null))['then'](function(_0x427101){if(_0x427101){_0x5884ef=_0x427101;logger[_0xf384('0x25')](_0xf384('0xb5'),_0xf384('0x2c'),'received\x20delivery\x20report\x20from',_0x427101['type'],util['inspect'](_0x33c9b8[_0xf384('0x45')],{'showHidden':![],'depth':null}));switch(_0x427101[_0xf384('0x43')]){case _0xf384('0x8a'):if(_0x33c9b8[_0xf384('0x45')][_0xf384('0xdf')]&&_0x33c9b8[_0xf384('0x45')][_0xf384('0xe0')]){_0x2ab884=_0x33c9b8[_0xf384('0x45')][_0xf384('0xe0')];return db[_0xf384('0xa9')]['find']({'where':{'messageId':_0x33c9b8[_0xf384('0x45')][_0xf384('0xdf')]}});}break;}}})['then'](handleEntityNotFound(_0x550e55,null))[_0xf384('0x21')](function(_0x4557dc){if(_0x4557dc){_0x239a46=_0x4557dc;switch(_0x5884ef[_0xf384('0x43')]){case'csc':if(_0x2ab884==='2'||_0x2ab884==='6'){return _0x239a46['update']({'read':!![]});}else{logger['error']('SmsAccount,\x20%s,\x20%s,\x20%s',_0xf384('0x2c'),_0xf384('0x8a'),util[_0xf384('0xd1')](_0x33c9b8[_0xf384('0x45')],{'showHidden':![],'depth':null}));};break;}return _0x239a46;}})['then'](respondWithResult(_0x550e55,null))[_0xf384('0x2a')](handleError(_0x550e55,null));};exports[_0xf384('0xe1')]=function(_0x577413,_0x38b10a,_0x5415d9){return db['SmsAccount']['find']({'where':{'id':_0x577413['params']['id']}})[_0xf384('0x21')](handleEntityNotFound(_0x38b10a,null))[_0xf384('0x21')](function(_0x4a0010){if(_0x4a0010){return _0x4a0010[_0xf384('0xe1')](_0x577413[_0xf384('0x5a')][_0xf384('0x68')],_[_0xf384('0x9e')](_0x577413[_0xf384('0x5a')],[_0xf384('0x68'),'id'])||{})[_0xf384('0xa1')](function(_0x2c2a2f){for(var _0x134b4f=0x0;_0x134b4f<_0x577413[_0xf384('0x5a')][_0xf384('0x68')][_0xf384('0x57')];_0x134b4f+=0x1){socket[_0xf384('0xe2')](_0xf384('0xe3'),{'UserId':Number(_0x577413[_0xf384('0x5a')][_0xf384('0x68')][_0x134b4f]),'SmsAccountId':Number(_0x577413['params']['id'])});}return _0x2c2a2f;});}})[_0xf384('0x21')](respondWithResult(_0x38b10a,null))[_0xf384('0x2a')](handleError(_0x38b10a,null));};exports[_0xf384('0xe4')]=function(_0x4b7e61,_0x1a81cc,_0x1070c0){return db[_0xf384('0x40')][_0xf384('0x58')]({'where':{'id':_0x4b7e61[_0xf384('0x5e')]['id']}})['then'](handleEntityNotFound(_0x1a81cc,null))[_0xf384('0x21')](function(_0x3de270){if(_0x3de270){return _0x3de270['removeAgents'](_0x4b7e61['query'][_0xf384('0x68')])[_0xf384('0x21')](function(){if(_[_0xf384('0xe5')](_0x4b7e61[_0xf384('0x45')]['ids'])){for(var _0x50acc7=0x0;_0x50acc7<_0x4b7e61[_0xf384('0x45')][_0xf384('0x68')][_0xf384('0x57')];_0x50acc7+=0x1){socket[_0xf384('0xe2')]('userSmsAccount:remove',{'UserId':Number(_0x4b7e61[_0xf384('0x45')][_0xf384('0x68')][_0x50acc7]),'SmsAccountId':Number(_0x4b7e61['params']['id'])});}}else{socket[_0xf384('0xe2')](_0xf384('0xe6'),{'UserId':Number(_0x4b7e61[_0xf384('0x45')][_0xf384('0x68')]),'SmsAccountId':Number(_0x4b7e61[_0xf384('0x5e')]['id'])});}});}})[_0xf384('0x21')](respondWithStatusCode(_0x1a81cc,null))[_0xf384('0x2a')](handleError(_0x1a81cc,null));};exports['getAgents']=function(_0x5bc344,_0x205c4a,_0x2742a0){var _0x4f2808={};var _0x41a26c={};var _0x55abaa;var _0x921067;return db[_0xf384('0x40')][_0xf384('0x6b')]({'where':{'id':_0x5bc344[_0xf384('0x5e')]['id']}})['then'](handleEntityNotFound(_0x205c4a,null))[_0xf384('0x21')](function(_0x2e5267){if(_0x2e5267){_0x55abaa=_0x2e5267;_0x41a26c[_0xf384('0x49')]=_[_0xf384('0x46')](db[_0xf384('0xab')][_0xf384('0x41')]);_0x41a26c[_0xf384('0x45')]=_[_0xf384('0x46')](_0x5bc344[_0xf384('0x45')]);_0x41a26c['filters']=_[_0xf384('0x48')](_0x41a26c['model'],_0x41a26c[_0xf384('0x45')]);_0x4f2808[_0xf384('0x4a')]=_['intersection'](_0x41a26c[_0xf384('0x49')],qs[_0xf384('0x4b')](_0x5bc344['query']['fields']));_0x4f2808[_0xf384('0x4a')]=_0x4f2808['attributes'][_0xf384('0x57')]?_0x4f2808[_0xf384('0x4a')]:_0x41a26c[_0xf384('0x49')];_0x4f2808[_0xf384('0x64')]=qs[_0xf384('0x4e')](_0x5bc344[_0xf384('0x45')]['sort']);_0x4f2808[_0xf384('0x53')]=qs[_0xf384('0x47')](_[_0xf384('0x4f')](_0x5bc344[_0xf384('0x45')],_0x41a26c[_0xf384('0x47')]));if(_0x5bc344['query']['filter']){_0x4f2808[_0xf384('0x53')]=_[_0xf384('0x50')](_0x4f2808[_0xf384('0x53')],{'$or':_[_0xf384('0x3f')](_0x4f2808[_0xf384('0x4a')],function(_0x56df9b){var _0x5d8539={};_0x5d8539[_0x56df9b]={'$like':'%'+_0x5bc344[_0xf384('0x45')][_0xf384('0x52')]+'%'};return _0x5d8539;})});}_0x4f2808=_['merge']({},_0x4f2808,_0x5bc344[_0xf384('0x65')]);return _0x55abaa[_0xf384('0xe7')](_0x4f2808);}})['then'](function(_0x30040f){if(_0x30040f){_0x921067=_0x30040f[_0xf384('0x57')];if(!_0x5bc344[_0xf384('0x45')][_0xf384('0x4c')]('nolimit')){_0x4f2808['limit']=qs[_0xf384('0x30')](_0x5bc344[_0xf384('0x45')][_0xf384('0x30')]);_0x4f2808[_0xf384('0x2e')]=qs['offset'](_0x5bc344[_0xf384('0x45')][_0xf384('0x2e')]);}return _0x55abaa[_0xf384('0xe7')](_0x4f2808);}})['then'](function(_0x12d4f4){if(_0x12d4f4){return _0x12d4f4?{'count':_0x921067,'rows':_0x12d4f4}:null;}})['then'](respondWithResult(_0x205c4a,null))[_0xf384('0x2a')](handleError(_0x205c4a,null));};