Built motion from commit (unavailable).|2.0.76
[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 _0x6e77=['entity\x20found','SmsAccount,\x20%s,\x20%s,\x20%s,\x20%s','Content-Type','text/xml','addApplications','sequelize','transaction','bulkCreate','findAndCountAll','getApplications','getInteractions','Contact','internal','Tag','Tags','tag','to\x20is\x20mandatory','List','get','out','user','Messages','dataValues','push','received\x20delivery\x20report\x20from','inspect','skebby','skebby_dispatch_id','SmsMessage','requestid','statusInt','clicksend','status_code','DELIVERED','error_code','emit','userSmsAccount:save','removeAgents','isArray','userSmsAccount:remove','getAgents','eml-format','fast-json-patch','request-promise','bluebird','mustache','util','to-csv','ejs','lodash','crypto','jsforce','desk.js','querystring','papaparse','../../config/logger','api','../../config/utils','../../config/environment','socket.io-emitter','localhost','./smsAccount.socket','register','jayson/promise','client','http','request','then','info','SmsAccount,\x20%s,\x20%s','request\x20sent','debug','SmsAccount,\x20%s,\x20%s,\x20%s','stringify','error','message','result','catch','status','end','json','count','offset','limit','set','Content-Range','apply','reject','save','update','destroy','sendStatus','stack','send','index','SmsAccount','model','keys','query','dateEnd','dateStart','filters','intersection','attributes','fields','length','hasOwnProperty','order','sort','where','pick','add','day','merge','filter','options','include','findAll','rows','show','params','rawAttributes','includeAll','create','body','find','describe','addDisposition','Disposition','getDispositions','nolimit','SmsAccountId','map','removeDispositions','ids','CannedAnswer','getAnswers','findOne','removeAnswers','sms','SmsApplication','Applications','account','applications','orderBy','priority','asc','CmContact','ValidationError','no\x20available\x20attributes','difference','createdAt','updatedAt','ListId','mobile','type','twilio','from','From','Body','messageId','MessageSid','sender','connectel','message_id','Text','MessageUUID','isNil','Sequelize','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','CmList','Contacts','DESC','list','omit','defaults','SmsInteraction','spread','interaction','created','autoclose','close','unmanaged','*,*,*,*','AttachmentId','UserId','User','name','unshift','agent','waitForTheAssignedAgent','startRouting','Start','receiveMessage'];(function(_0x52d6f4,_0x174ab4){var _0x210d77=function(_0x210549){while(--_0x210549){_0x52d6f4['push'](_0x52d6f4['shift']());}};_0x210d77(++_0x174ab4);}(_0x6e77,0xef));var _0x76e7=function(_0x2c6bad,_0x29ffed){_0x2c6bad=_0x2c6bad-0x0;var _0x5f5435=_0x6e77[_0x2c6bad];return _0x5f5435;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x76e7('0x0'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x76e7('0x1'));var rp=require(_0x76e7('0x2'));var moment=require('moment');var BPromise=require(_0x76e7('0x3'));var Mustache=require(_0x76e7('0x4'));var util=require(_0x76e7('0x5'));var path=require('path');var sox=require('sox');var csv=require(_0x76e7('0x6'));var ejs=require(_0x76e7('0x7'));var fs=require('fs');var _=require(_0x76e7('0x8'));var squel=require('squel');var crypto=require(_0x76e7('0x9'));var jsforce=require(_0x76e7('0xa'));var deskjs=require(_0x76e7('0xb'));var toCsv=require('to-csv');var querystring=require(_0x76e7('0xc'));var Papa=require(_0x76e7('0xd'));var qs=require('../../components/parsers/qs');var logger=require(_0x76e7('0xe'))(_0x76e7('0xf'));var utils=require(_0x76e7('0x10'));var config=require(_0x76e7('0x11'));var db=require('../../mysqldb')['db'];var socket=require(_0x76e7('0x12'))({'host':_0x76e7('0x13'),'port':0x18eb});require(_0x76e7('0x14'))[_0x76e7('0x15')](socket);var jayson=require(_0x76e7('0x16'));var client=jayson[_0x76e7('0x17')][_0x76e7('0x18')]({'port':0x232c});function respondWithRpcPromise(_0x3d9466,_0xbe7174,_0x2670f6,_0x44c0b7){return new BPromise(function(_0x5b4fc5,_0x2661d2){var _0x4cc38c=_0x44c0b7||client;return _0x4cc38c[_0x76e7('0x19')](_0x3d9466,_0x2670f6)[_0x76e7('0x1a')](function(_0x52e19a){logger[_0x76e7('0x1b')](_0x76e7('0x1c'),_0xbe7174,_0x76e7('0x1d'));logger[_0x76e7('0x1e')](_0x76e7('0x1f'),_0xbe7174,_0x76e7('0x1d'),JSON[_0x76e7('0x20')](_0x52e19a));if(_0x52e19a['error']){if(_0x52e19a[_0x76e7('0x21')]['code']===0x1f4){logger[_0x76e7('0x21')](_0x76e7('0x1c'),_0xbe7174,_0x52e19a[_0x76e7('0x21')][_0x76e7('0x22')]);return _0x2661d2(_0x52e19a[_0x76e7('0x21')]['message']);}logger[_0x76e7('0x21')]('SmsAccount,\x20%s,\x20%s',_0xbe7174,_0x52e19a[_0x76e7('0x21')][_0x76e7('0x22')]);return _0x5b4fc5(_0x52e19a[_0x76e7('0x21')][_0x76e7('0x22')]);}else{logger[_0x76e7('0x1b')](_0x76e7('0x1c'),_0xbe7174,_0x76e7('0x1d'));_0x5b4fc5(_0x52e19a[_0x76e7('0x23')][_0x76e7('0x22')]);}})[_0x76e7('0x24')](function(_0x86f6f9){logger[_0x76e7('0x21')](_0x76e7('0x1c'),_0xbe7174,_0x86f6f9);_0x2661d2(_0x86f6f9);});});}function respondWithStatusCode(_0x92d883,_0x58061d){_0x58061d=_0x58061d||0xcc;return function(_0x11afe6){if(_0x11afe6){return _0x92d883['sendStatus'](_0x58061d);}return _0x92d883[_0x76e7('0x25')](_0x58061d)[_0x76e7('0x26')]();};}function respondWithResult(_0x39b3f8,_0x40b2b4){_0x40b2b4=_0x40b2b4||0xc8;return function(_0x4c1bf7){if(_0x4c1bf7){return _0x39b3f8[_0x76e7('0x25')](_0x40b2b4)[_0x76e7('0x27')](_0x4c1bf7);}};}function respondWithFilteredResult(_0x4efde8,_0x8ce9e3){return function(_0x353c24){if(_0x353c24){var _0x38238c=_0x353c24[_0x76e7('0x28')],_0x471830=_0x8ce9e3[_0x76e7('0x29')],_0x4a1f67=_0x8ce9e3[_0x76e7('0x29')]+_0x8ce9e3[_0x76e7('0x2a')],_0x3d2b3c;if(_0x4a1f67>=_0x38238c){_0x4a1f67=_0x38238c;_0x3d2b3c=0xc8;}else{_0x3d2b3c=0xce;}_0x4efde8[_0x76e7('0x25')](_0x3d2b3c);return _0x4efde8[_0x76e7('0x2b')](_0x76e7('0x2c'),_0x471830+'-'+_0x4a1f67+'/'+_0x38238c)[_0x76e7('0x27')](_0x353c24);}return null;};}function patchUpdates(_0x38ea19){return function(_0x5f2039){try{jsonpatch[_0x76e7('0x2d')](_0x5f2039,_0x38ea19,!![]);}catch(_0x501b19){return BPromise[_0x76e7('0x2e')](_0x501b19);}return _0x5f2039[_0x76e7('0x2f')]();};}function saveUpdates(_0x1f598b,_0x4dc336){return function(_0x33e06b){if(_0x33e06b){return _0x33e06b[_0x76e7('0x30')](_0x1f598b)['then'](function(_0x2e1df3){return _0x2e1df3;});}return null;};}function removeEntity(_0x330874,_0x51d6c1){return function(_0x203bc1){if(_0x203bc1){return _0x203bc1[_0x76e7('0x31')]()['then'](function(){_0x330874[_0x76e7('0x25')](0xcc)[_0x76e7('0x26')]();});}};}function handleEntityNotFound(_0x227050,_0x5942b3){return function(_0x14bc10){if(!_0x14bc10){_0x227050[_0x76e7('0x32')](0x194);}return _0x14bc10;};}function handleError(_0x496c76,_0x3c1797){_0x3c1797=_0x3c1797||0x1f4;return function(_0x5759a0){logger[_0x76e7('0x21')](_0x5759a0[_0x76e7('0x33')]);if(_0x5759a0['name']){delete _0x5759a0['name'];}_0x496c76[_0x76e7('0x25')](_0x3c1797)[_0x76e7('0x34')](_0x5759a0);};}exports[_0x76e7('0x35')]=function(_0x260beb,_0x15c6bf){var _0x377d56={},_0x34a98f={},_0x419ae9={'count':0x0,'rows':[]};var _0x45a8c7=db[_0x76e7('0x36')]['rawAttributes'];_0x34a98f[_0x76e7('0x37')]=_[_0x76e7('0x38')](_0x45a8c7);var _0x3df720={'dateStart':_0x260beb[_0x76e7('0x39')]['dateStart'],'dateEnd':_0x260beb['query'][_0x76e7('0x3a')]};delete _0x260beb[_0x76e7('0x39')][_0x76e7('0x3b')];delete _0x260beb[_0x76e7('0x39')][_0x76e7('0x3a')];_0x34a98f['query']=_[_0x76e7('0x38')](_0x260beb['query']);_0x34a98f[_0x76e7('0x3c')]=_[_0x76e7('0x3d')](_0x34a98f[_0x76e7('0x37')],_0x34a98f[_0x76e7('0x39')]);_0x377d56[_0x76e7('0x3e')]=_[_0x76e7('0x3d')](_0x34a98f[_0x76e7('0x37')],qs['fields'](_0x260beb[_0x76e7('0x39')][_0x76e7('0x3f')]));_0x377d56[_0x76e7('0x3e')]=_0x377d56['attributes'][_0x76e7('0x40')]?_0x377d56['attributes']:_0x34a98f['model'];if(!_0x260beb[_0x76e7('0x39')][_0x76e7('0x41')]('nolimit')){_0x377d56[_0x76e7('0x2a')]=qs[_0x76e7('0x2a')](_0x260beb[_0x76e7('0x39')][_0x76e7('0x2a')]);_0x377d56['offset']=qs[_0x76e7('0x29')](_0x260beb[_0x76e7('0x39')][_0x76e7('0x29')]);}_0x377d56[_0x76e7('0x42')]=qs[_0x76e7('0x43')](_0x260beb['query']['sort']);_0x377d56[_0x76e7('0x44')]=qs[_0x76e7('0x3c')](_[_0x76e7('0x45')](_0x260beb[_0x76e7('0x39')],_0x34a98f[_0x76e7('0x3c')]));if(_0x3df720[_0x76e7('0x3b')]){if(_0x3df720[_0x76e7('0x3a')]){_0x3df720['dateEnd']=moment(_0x3df720[_0x76e7('0x3a')])[_0x76e7('0x46')](0x1,_0x76e7('0x47'));}else{_0x3df720[_0x76e7('0x3a')]=moment(_0x3df720[_0x76e7('0x3b')])[_0x76e7('0x46')](0x1,_0x76e7('0x47'));}_[_0x76e7('0x48')](_0x377d56['where'],{'createdAt':{'$gte':_0x3df720[_0x76e7('0x3b')],'$lte':_0x3df720['dateEnd']}});}if(_0x260beb[_0x76e7('0x39')]['filter']){_0x377d56[_0x76e7('0x44')]=_[_0x76e7('0x48')](_0x377d56['where'],{'$or':_['map'](_0x377d56[_0x76e7('0x3e')],function(_0x23cdd8){var _0x4b11b3={};_0x4b11b3[_0x23cdd8]={'$like':'%'+_0x260beb[_0x76e7('0x39')][_0x76e7('0x49')]+'%'};return _0x4b11b3;})});}_0x377d56=_[_0x76e7('0x48')]({},_0x377d56,_0x260beb[_0x76e7('0x4a')]);var _0x5d2bc5={'where':_0x377d56[_0x76e7('0x44')]};return db[_0x76e7('0x36')][_0x76e7('0x28')](_0x5d2bc5)[_0x76e7('0x1a')](function(_0x4701cc){_0x419ae9[_0x76e7('0x28')]=_0x4701cc;if(_0x260beb[_0x76e7('0x39')]['includeAll']){_0x377d56[_0x76e7('0x4b')]=[{'all':!![]}];}return db[_0x76e7('0x36')][_0x76e7('0x4c')](_0x377d56);})[_0x76e7('0x1a')](function(_0x522104){_0x419ae9[_0x76e7('0x4d')]=_0x522104;return _0x419ae9;})[_0x76e7('0x1a')](respondWithFilteredResult(_0x15c6bf,_0x377d56))[_0x76e7('0x24')](handleError(_0x15c6bf,null));};exports[_0x76e7('0x4e')]=function(_0x27bfd5,_0x70ef1a){var _0x37c61e={'raw':![],'where':{'id':_0x27bfd5[_0x76e7('0x4f')]['id']}},_0xdf8216={};_0xdf8216['model']=_[_0x76e7('0x38')](db[_0x76e7('0x36')][_0x76e7('0x50')]);_0xdf8216[_0x76e7('0x39')]=_['keys'](_0x27bfd5['query']);_0xdf8216[_0x76e7('0x3c')]=_[_0x76e7('0x3d')](_0xdf8216[_0x76e7('0x37')],_0xdf8216['query']);_0x37c61e[_0x76e7('0x3e')]=_[_0x76e7('0x3d')](_0xdf8216[_0x76e7('0x37')],qs['fields'](_0x27bfd5[_0x76e7('0x39')][_0x76e7('0x3f')]));_0x37c61e[_0x76e7('0x3e')]=_0x37c61e[_0x76e7('0x3e')][_0x76e7('0x40')]?_0x37c61e[_0x76e7('0x3e')]:_0xdf8216[_0x76e7('0x37')];if(_0x27bfd5[_0x76e7('0x39')][_0x76e7('0x51')]){_0x37c61e['include']=[{'all':!![]}];}_0x37c61e=_[_0x76e7('0x48')]({},_0x37c61e,_0x27bfd5[_0x76e7('0x4a')]);return db[_0x76e7('0x36')]['find'](_0x37c61e)[_0x76e7('0x1a')](handleEntityNotFound(_0x70ef1a,null))[_0x76e7('0x1a')](respondWithResult(_0x70ef1a,null))[_0x76e7('0x24')](handleError(_0x70ef1a,null));};exports['create']=function(_0x7cac35,_0x45f0ad){return db[_0x76e7('0x36')][_0x76e7('0x52')](_0x7cac35['body'],{})[_0x76e7('0x1a')](respondWithResult(_0x45f0ad,0xc9))[_0x76e7('0x24')](handleError(_0x45f0ad,null));};exports[_0x76e7('0x30')]=function(_0x13eae2,_0x567bab){if(_0x13eae2[_0x76e7('0x53')]['id']){delete _0x13eae2[_0x76e7('0x53')]['id'];}return db[_0x76e7('0x36')][_0x76e7('0x54')]({'where':{'id':_0x13eae2[_0x76e7('0x4f')]['id']}})[_0x76e7('0x1a')](handleEntityNotFound(_0x567bab,null))[_0x76e7('0x1a')](saveUpdates(_0x13eae2[_0x76e7('0x53')],null))[_0x76e7('0x1a')](respondWithResult(_0x567bab,null))[_0x76e7('0x24')](handleError(_0x567bab,null));};exports[_0x76e7('0x31')]=function(_0x4e7d8b,_0xd2731){return db[_0x76e7('0x36')][_0x76e7('0x54')]({'where':{'id':_0x4e7d8b[_0x76e7('0x4f')]['id']}})[_0x76e7('0x1a')](handleEntityNotFound(_0xd2731,null))['then'](removeEntity(_0xd2731,null))[_0x76e7('0x24')](handleError(_0xd2731,null));};exports['describe']=function(_0x55df34,_0x3a5db0){return db['SmsAccount'][_0x76e7('0x55')]()[_0x76e7('0x1a')](respondWithResult(_0x3a5db0,null))[_0x76e7('0x24')](handleError(_0x3a5db0,null));};exports[_0x76e7('0x56')]=function(_0x643ddf,_0x4ed6ed,_0x253d07){if(_0x643ddf[_0x76e7('0x53')]['id']){delete _0x643ddf['body']['id'];}return db['SmsAccount']['find']({'where':{'id':_0x643ddf[_0x76e7('0x4f')]['id']}})[_0x76e7('0x1a')](handleEntityNotFound(_0x4ed6ed,null))[_0x76e7('0x1a')](function(_0x3bb4be){if(_0x3bb4be){_0x643ddf[_0x76e7('0x53')]['SmsAccountId']=_0x3bb4be['id'];return db[_0x76e7('0x57')][_0x76e7('0x52')](_0x643ddf['body']);}})['then'](respondWithResult(_0x4ed6ed,null))[_0x76e7('0x24')](handleError(_0x4ed6ed,null));};exports[_0x76e7('0x58')]=function(_0x2e46f5,_0x29e380,_0x3743c9){var _0x56eff7={'raw':![],'where':{}};var _0x53ed5b={};var _0x5c2f7e={'count':0x0,'rows':[]};return db[_0x76e7('0x36')]['findOne']({'where':{'id':_0x2e46f5[_0x76e7('0x4f')]['id']}})['then'](handleEntityNotFound(_0x29e380,null))[_0x76e7('0x1a')](function(_0x321084){if(_0x321084){_0x53ed5b['model']=_[_0x76e7('0x38')](db[_0x76e7('0x57')][_0x76e7('0x50')]);_0x53ed5b[_0x76e7('0x39')]=_['keys'](_0x2e46f5[_0x76e7('0x39')]);_0x53ed5b[_0x76e7('0x3c')]=_[_0x76e7('0x3d')](_0x53ed5b['model'],_0x53ed5b[_0x76e7('0x39')]);_0x56eff7[_0x76e7('0x3e')]=_[_0x76e7('0x3d')](_0x53ed5b['model'],qs[_0x76e7('0x3f')](_0x2e46f5[_0x76e7('0x39')]['fields']));_0x56eff7[_0x76e7('0x3e')]=_0x56eff7[_0x76e7('0x3e')]['length']?_0x56eff7[_0x76e7('0x3e')]:_0x53ed5b['model'];if(!_0x2e46f5[_0x76e7('0x39')]['hasOwnProperty'](_0x76e7('0x59'))){_0x56eff7[_0x76e7('0x2a')]=qs['limit'](_0x2e46f5['query'][_0x76e7('0x2a')]);_0x56eff7[_0x76e7('0x29')]=qs[_0x76e7('0x29')](_0x2e46f5[_0x76e7('0x39')][_0x76e7('0x29')]);}_0x56eff7[_0x76e7('0x42')]=qs[_0x76e7('0x43')](_0x2e46f5[_0x76e7('0x39')][_0x76e7('0x43')]);_0x56eff7[_0x76e7('0x44')]=qs[_0x76e7('0x3c')](_['pick'](_0x2e46f5[_0x76e7('0x39')],_0x53ed5b[_0x76e7('0x3c')]));_0x56eff7[_0x76e7('0x44')][_0x76e7('0x5a')]=_0x321084['id'];if(_0x2e46f5['query'][_0x76e7('0x49')]){_0x56eff7[_0x76e7('0x44')]=_['merge'](_0x56eff7[_0x76e7('0x44')],{'$or':_[_0x76e7('0x5b')](_0x56eff7[_0x76e7('0x3e')],function(_0x22ac59){var _0x58feb4={};_0x58feb4[_0x22ac59]={'$like':'%'+_0x2e46f5[_0x76e7('0x39')][_0x76e7('0x49')]+'%'};return _0x58feb4;})});}_0x56eff7=_['merge']({},_0x56eff7,_0x2e46f5[_0x76e7('0x4a')]);return db[_0x76e7('0x57')][_0x76e7('0x28')]({'where':_0x56eff7[_0x76e7('0x44')]})[_0x76e7('0x1a')](function(_0xd3a773){_0x5c2f7e[_0x76e7('0x28')]=_0xd3a773;if(_0x2e46f5['query'][_0x76e7('0x51')]){_0x56eff7[_0x76e7('0x4b')]=[{'all':!![]}];}return db[_0x76e7('0x57')][_0x76e7('0x4c')](_0x56eff7);})[_0x76e7('0x1a')](function(_0x3a4920){_0x5c2f7e[_0x76e7('0x4d')]=_0x3a4920;return _0x5c2f7e;});}})[_0x76e7('0x1a')](respondWithFilteredResult(_0x29e380,_0x56eff7))[_0x76e7('0x24')](handleError(_0x29e380,null));};exports[_0x76e7('0x5c')]=function(_0x133ea5,_0x633f71,_0xdd7d46){var _0x353a68;return db[_0x76e7('0x36')][_0x76e7('0x54')]({'where':{'id':_0x133ea5['params']['id']}})[_0x76e7('0x1a')](handleEntityNotFound(_0x633f71,null))[_0x76e7('0x1a')](function(_0x47db55){if(_0x47db55){return _0x47db55['removeDispositions'](_0x133ea5[_0x76e7('0x39')][_0x76e7('0x5d')]);}})[_0x76e7('0x1a')](respondWithStatusCode(_0x633f71,null))[_0x76e7('0x24')](handleError(_0x633f71,null));};exports['addAnswer']=function(_0x41ffc7,_0x2563e8,_0x4c0459){if(_0x41ffc7[_0x76e7('0x53')]['id']){delete _0x41ffc7[_0x76e7('0x53')]['id'];}return db[_0x76e7('0x36')][_0x76e7('0x54')]({'where':{'id':_0x41ffc7[_0x76e7('0x4f')]['id']}})[_0x76e7('0x1a')](handleEntityNotFound(_0x2563e8,null))[_0x76e7('0x1a')](function(_0x5140e2){if(_0x5140e2){_0x41ffc7['body']['SmsAccountId']=_0x5140e2['id'];return db[_0x76e7('0x5e')]['create'](_0x41ffc7[_0x76e7('0x53')]);}})[_0x76e7('0x1a')](respondWithResult(_0x2563e8,null))[_0x76e7('0x24')](handleError(_0x2563e8,null));};exports[_0x76e7('0x5f')]=function(_0xa1c5da,_0x40c685,_0x324568){var _0x328219={'raw':![],'where':{}};var _0x15c053={};var _0x2345be={'count':0x0,'rows':[]};return db['SmsAccount'][_0x76e7('0x60')]({'where':{'id':_0xa1c5da[_0x76e7('0x4f')]['id']}})[_0x76e7('0x1a')](handleEntityNotFound(_0x40c685,null))[_0x76e7('0x1a')](function(_0x4d56da){if(_0x4d56da){_0x15c053[_0x76e7('0x37')]=_['keys'](db[_0x76e7('0x5e')][_0x76e7('0x50')]);_0x15c053[_0x76e7('0x39')]=_[_0x76e7('0x38')](_0xa1c5da[_0x76e7('0x39')]);_0x15c053[_0x76e7('0x3c')]=_[_0x76e7('0x3d')](_0x15c053[_0x76e7('0x37')],_0x15c053[_0x76e7('0x39')]);_0x328219[_0x76e7('0x3e')]=_[_0x76e7('0x3d')](_0x15c053[_0x76e7('0x37')],qs[_0x76e7('0x3f')](_0xa1c5da['query'][_0x76e7('0x3f')]));_0x328219[_0x76e7('0x3e')]=_0x328219[_0x76e7('0x3e')][_0x76e7('0x40')]?_0x328219['attributes']:_0x15c053[_0x76e7('0x37')];if(!_0xa1c5da[_0x76e7('0x39')][_0x76e7('0x41')]('nolimit')){_0x328219[_0x76e7('0x2a')]=qs['limit'](_0xa1c5da[_0x76e7('0x39')][_0x76e7('0x2a')]);_0x328219[_0x76e7('0x29')]=qs[_0x76e7('0x29')](_0xa1c5da['query'][_0x76e7('0x29')]);}_0x328219['order']=qs[_0x76e7('0x43')](_0xa1c5da['query'][_0x76e7('0x43')]);_0x328219['where']=qs['filters'](_[_0x76e7('0x45')](_0xa1c5da[_0x76e7('0x39')],_0x15c053[_0x76e7('0x3c')]));_0x328219[_0x76e7('0x44')][_0x76e7('0x5a')]=_0x4d56da['id'];if(_0xa1c5da[_0x76e7('0x39')][_0x76e7('0x49')]){_0x328219[_0x76e7('0x44')]=_[_0x76e7('0x48')](_0x328219['where'],{'$or':_['map'](_0x328219['attributes'],function(_0x1dee9e){var _0x4c1f75={};_0x4c1f75[_0x1dee9e]={'$like':'%'+_0xa1c5da[_0x76e7('0x39')][_0x76e7('0x49')]+'%'};return _0x4c1f75;})});}_0x328219=_[_0x76e7('0x48')]({},_0x328219,_0xa1c5da[_0x76e7('0x4a')]);return db[_0x76e7('0x5e')][_0x76e7('0x28')]({'where':_0x328219[_0x76e7('0x44')]})[_0x76e7('0x1a')](function(_0x4ad1bf){_0x2345be[_0x76e7('0x28')]=_0x4ad1bf;if(_0xa1c5da[_0x76e7('0x39')][_0x76e7('0x51')]){_0x328219[_0x76e7('0x4b')]=[{'all':!![]}];}return db[_0x76e7('0x5e')][_0x76e7('0x4c')](_0x328219);})[_0x76e7('0x1a')](function(_0x341dae){_0x2345be[_0x76e7('0x4d')]=_0x341dae;return _0x2345be;});}})['then'](respondWithFilteredResult(_0x40c685,_0x328219))[_0x76e7('0x24')](handleError(_0x40c685,null));};exports[_0x76e7('0x61')]=function(_0x38dbb4,_0x29094d,_0xeedf47){var _0x37962b;return db[_0x76e7('0x36')][_0x76e7('0x54')]({'where':{'id':_0x38dbb4[_0x76e7('0x4f')]['id']}})[_0x76e7('0x1a')](handleEntityNotFound(_0x29094d,null))['then'](function(_0x35c3b0){if(_0x35c3b0){return _0x35c3b0[_0x76e7('0x61')](_0x38dbb4['query'][_0x76e7('0x5d')]);}})[_0x76e7('0x1a')](respondWithStatusCode(_0x29094d,null))['catch'](handleError(_0x29094d,null));};exports['notify']=function(_0x475f3e,_0x14c3aa,_0x3335a4){var _0x34db22={'channel':_0x76e7('0x62')};var _0x103d51=[];var _0x5c3f98=[];var _0x2cfeff={};return db[_0x76e7('0x36')][_0x76e7('0x54')]({'where':{'id':_0x475f3e[_0x76e7('0x4f')]['id']},'include':[{'model':db[_0x76e7('0x63')],'as':_0x76e7('0x64')}]})[_0x76e7('0x1a')](handleEntityNotFound(_0x14c3aa,null))['then'](function(_0xe6b7f){_0x34db22[_0x76e7('0x65')]=_0xe6b7f;_0x34db22[_0x76e7('0x66')]=_[_0x76e7('0x67')](_0xe6b7f[_0x76e7('0x64')],[_0x76e7('0x68')],[_0x76e7('0x69')]);if(_0x34db22[_0x76e7('0x65')][_0x76e7('0x64')]){delete _0x34db22['account'][_0x76e7('0x64')];}return db[_0x76e7('0x6a')]['describe']();})[_0x76e7('0x1a')](function(_0x5641fc){if(!_0x5641fc){throw new db['Sequelize'][(_0x76e7('0x6b'))](_0x76e7('0x6c'));}_0x103d51=_[_0x76e7('0x6d')](_[_0x76e7('0x38')](_0x5641fc),[_0x76e7('0x6e'),_0x76e7('0x6f')]);_0x5c3f98=_[_0x76e7('0x6d')](_[_0x76e7('0x38')](_0x5641fc),['createdAt','updatedAt','CompanyId',_0x76e7('0x70')]);_0x34db22[_0x76e7('0x53')]={'mapKey':_0x76e7('0x71')};if(_0x34db22[_0x76e7('0x65')]['type']){switch(_0x34db22[_0x76e7('0x65')][_0x76e7('0x72')]){case _0x76e7('0x73'):_0x34db22[_0x76e7('0x53')][_0x76e7('0x74')]=_0x475f3e[_0x76e7('0x53')][_0x76e7('0x75')];_0x34db22[_0x76e7('0x53')]['body']=_0x475f3e[_0x76e7('0x53')][_0x76e7('0x76')];_0x34db22['body'][_0x76e7('0x77')]=_0x475f3e['body'][_0x76e7('0x78')];break;case'skebby':_0x34db22[_0x76e7('0x53')][_0x76e7('0x74')]=_0x475f3e[_0x76e7('0x53')][_0x76e7('0x79')];_0x34db22['body'][_0x76e7('0x53')]=_0x475f3e['body']['text'];break;case _0x76e7('0x7a'):_0x34db22[_0x76e7('0x53')][_0x76e7('0x74')]=_0x475f3e[_0x76e7('0x53')][_0x76e7('0x74')];_0x34db22['body'][_0x76e7('0x53')]=_0x475f3e[_0x76e7('0x53')]['message'];break;case'clicksend':_0x34db22[_0x76e7('0x53')][_0x76e7('0x74')]=_0x475f3e[_0x76e7('0x53')]['from'];_0x34db22[_0x76e7('0x53')][_0x76e7('0x53')]=_0x475f3e['body'][_0x76e7('0x53')];_0x34db22[_0x76e7('0x53')][_0x76e7('0x77')]=_0x475f3e[_0x76e7('0x53')][_0x76e7('0x7b')];break;case'plivo':_0x34db22['body'][_0x76e7('0x74')]=_0x475f3e[_0x76e7('0x53')][_0x76e7('0x75')];_0x34db22[_0x76e7('0x53')][_0x76e7('0x53')]=_0x475f3e['body'][_0x76e7('0x7c')];_0x34db22[_0x76e7('0x53')][_0x76e7('0x77')]=_0x475f3e[_0x76e7('0x53')][_0x76e7('0x7d')];break;}}if(_0x34db22['body']['id']){delete _0x34db22['body']['id'];}if(_[_0x76e7('0x7e')](_0x34db22[_0x76e7('0x53')]['from'])){throw new db[(_0x76e7('0x7f'))]['ValidationError']('from\x20is\x20mandatory');}if(_['isNil'](_0x34db22[_0x76e7('0x53')][_0x76e7('0x53')])||_0x34db22[_0x76e7('0x53')][_0x76e7('0x53')]===''){throw new db[(_0x76e7('0x7f'))][(_0x76e7('0x6b'))](_0x76e7('0x80'));}if(_[_0x76e7('0x7e')](_0x34db22[_0x76e7('0x53')][_0x76e7('0x81')])){throw new db['Sequelize']['ValidationError'](_0x76e7('0x82')+_0x5c3f98);}if(!_[_0x76e7('0x83')](_0x5c3f98,_0x34db22[_0x76e7('0x53')][_0x76e7('0x81')])){throw new db[(_0x76e7('0x7f'))][(_0x76e7('0x6b'))](_0x76e7('0x84')+_0x5c3f98);}_0x2cfeff[_0x34db22[_0x76e7('0x53')][_0x76e7('0x81')]]=_0x34db22[_0x76e7('0x53')][_0x76e7('0x74')];return db[_0x76e7('0x85')][_0x76e7('0x54')]({'where':{'id':_0x34db22[_0x76e7('0x65')][_0x76e7('0x70')]},'include':[{'model':db[_0x76e7('0x6a')],'as':_0x76e7('0x86'),'where':_0x2cfeff,'limit':0x1,'order':[['updatedAt',_0x76e7('0x87')]]}]});})[_0x76e7('0x1a')](handleEntityNotFound(_0x14c3aa,null))[_0x76e7('0x1a')](function(_0x464d5b){if(_0x464d5b){_0x34db22[_0x76e7('0x88')]=_[_0x76e7('0x89')](_0x464d5b,['Contacts']);if(_0x464d5b['Contacts'][_0x76e7('0x40')]){return _0x464d5b['Contacts'][0x0];}var _0xea971a=_[_0x76e7('0x8a')](_0x34db22['body'],{'firstName':_0x34db22[_0x76e7('0x53')][_0x76e7('0x74')],'ListId':_0x464d5b['id']});_0xea971a[_0x34db22[_0x76e7('0x53')][_0x76e7('0x81')]]=_0x34db22[_0x76e7('0x53')][_0x76e7('0x74')];return db[_0x76e7('0x6a')][_0x76e7('0x52')](_0xea971a,{'fields':_0x103d51,'raw':!![]});}})['then'](handleEntityNotFound(_0x14c3aa,null))[_0x76e7('0x1a')](function(_0x94273){if(_0x94273){_0x34db22['contact']=_0x94273;var _0x443962={'ContactId':_0x94273['id'],'phone':_0x34db22['body'][_0x76e7('0x74')],'SmsAccountId':_0x475f3e['params']['id']};var _0x2d08ea={'ContactId':_0x94273['id'],'SmsAccountId':_0x475f3e[_0x76e7('0x4f')]['id'],'closed':![]};return db[_0x76e7('0x8b')][_0x76e7('0x54')]({'where':_0x2d08ea})[_0x76e7('0x1a')](function(_0x4be6bc){if(_0x4be6bc){return[_0x4be6bc,![]];}return db[_0x76e7('0x8b')]['create'](_0x443962)[_0x76e7('0x1a')](function(_0x1e12d5){return[_0x1e12d5,!![]];});});}})[_0x76e7('0x8c')](function(_0x55aa31,_0x2faa57){_0x34db22[_0x76e7('0x8d')]=_0x55aa31['get']({'plain':!![]});_0x34db22[_0x76e7('0x8d')][_0x76e7('0x8e')]=![];if(_0x2faa57){if(_0x34db22['account'][_0x76e7('0x8f')]){_0x34db22[_0x76e7('0x66')]['push']({'id':0x0,'priority':_0x34db22[_0x76e7('0x66')][_0x76e7('0x40')]+0x1,'app':_0x76e7('0x90'),'appdata':_0x76e7('0x91'),'interval':_0x76e7('0x92')});}_0x34db22['interaction']['created']=!![];}return db['SmsMessage'][_0x76e7('0x52')]({'phone':_0x34db22[_0x76e7('0x53')][_0x76e7('0x74')],'messageId':_0x34db22[_0x76e7('0x53')][_0x76e7('0x77')],'body':_0x34db22[_0x76e7('0x53')]['body'],'SmsAccountId':_0x475f3e['params']['id'],'SmsInteractionId':_0x55aa31['id'],'direction':'in','ContactId':_0x55aa31['ContactId'],'AttachmentId':_0x34db22[_0x76e7('0x53')][_0x76e7('0x93')]});})[_0x76e7('0x1a')](function(_0x1a24bf){_0x34db22['message']=_0x1a24bf;if(_0x34db22[_0x76e7('0x8d')][_0x76e7('0x94')]){return db[_0x76e7('0x95')][_0x76e7('0x54')]({'attributes':['id',_0x76e7('0x96')],'where':{'id':_0x34db22[_0x76e7('0x8d')]['UserId']}})[_0x76e7('0x1a')](function(_0x53e3c4){if(_0x53e3c4){_0x34db22[_0x76e7('0x66')][_0x76e7('0x97')]({'id':0x0,'priority':0x0,'app':_0x76e7('0x98'),'appdata':_0x53e3c4[_0x76e7('0x96')]+','+(_0x34db22[_0x76e7('0x65')][_0x76e7('0x99')]||0xa),'interval':_0x76e7('0x92')});}return respondWithRpcPromise('Start',_0x76e7('0x9a'),_0x34db22);});}return respondWithRpcPromise(_0x76e7('0x9b'),_0x76e7('0x9a'),_0x34db22);})[_0x76e7('0x1a')](function(_0x518859){if(_0x518859){var _0x4ec982=0xc8;var _0x1a62b6=_0x76e7('0x9c');logger[_0x76e7('0x1b')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0x1a62b6,_0x4ec982,_0x76e7('0x9d'));logger[_0x76e7('0x1e')](_0x76e7('0x9e'),_0x1a62b6,_0x4ec982,_0x76e7('0x9d'),JSON[_0x76e7('0x20')](_0x518859));if(_0x34db22[_0x76e7('0x65')]['type']==='twilio'){return _0x14c3aa[_0x76e7('0x25')](_0x4ec982)['set'](_0x76e7('0x9f'),_0x76e7('0xa0'))[_0x76e7('0x34')]('<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>');}else{return _0x14c3aa[_0x76e7('0x25')](_0x4ec982)[_0x76e7('0x27')](_0x518859);}}})['catch'](handleError(_0x14c3aa,null));};exports[_0x76e7('0xa1')]=function(_0x191fc5,_0x315088,_0x3d2b64){return db['SmsAccount'][_0x76e7('0x60')]({'where':{'id':_0x191fc5[_0x76e7('0x4f')]['id']}})[_0x76e7('0x1a')](handleEntityNotFound(_0x315088,null))['then'](function(_0x467be9){if(_0x467be9){return db[_0x76e7('0xa2')][_0x76e7('0xa3')](function(_0x315eb6){return db[_0x76e7('0x63')]['destroy']({'where':{'SmsAccountId':_0x191fc5[_0x76e7('0x4f')]['id']},'transaction':_0x315eb6})['then'](function(_0x224d0a){var _0x58f360=_[_0x76e7('0x5b')](_0x191fc5['body'],function(_0x3b4760){_0x3b4760[_0x76e7('0x5a')]=_0x191fc5['params']['id'];return _0x3b4760;});return db[_0x76e7('0x63')][_0x76e7('0xa4')](_0x58f360,{'transaction':_0x315eb6});});})[_0x76e7('0x1a')](function(){return db[_0x76e7('0x63')][_0x76e7('0xa5')]({'where':{'SmsAccountId':_0x191fc5[_0x76e7('0x4f')]['id']},'order':_0x76e7('0x68')});});}})[_0x76e7('0x1a')](respondWithResult(_0x315088,null))[_0x76e7('0x24')](handleError(_0x315088,null));};exports['getApplications']=function(_0xe3c0cf,_0x564c53,_0x43473d){var _0x503634={};var _0x51b31f={};var _0x2027c4;var _0x7f1e2b;return db[_0x76e7('0x36')][_0x76e7('0x60')]({'where':{'id':_0xe3c0cf['params']['id']}})[_0x76e7('0x1a')](handleEntityNotFound(_0x564c53,null))[_0x76e7('0x1a')](function(_0x3f29c1){if(_0x3f29c1){_0x2027c4=_0x3f29c1;_0x51b31f[_0x76e7('0x37')]=_[_0x76e7('0x38')](db['SmsApplication'][_0x76e7('0x50')]);_0x51b31f[_0x76e7('0x39')]=_[_0x76e7('0x38')](_0xe3c0cf[_0x76e7('0x39')]);_0x51b31f['filters']=_[_0x76e7('0x3d')](_0x51b31f['model'],_0x51b31f[_0x76e7('0x39')]);_0x503634['attributes']=_[_0x76e7('0x3d')](_0x51b31f['model'],qs[_0x76e7('0x3f')](_0xe3c0cf[_0x76e7('0x39')][_0x76e7('0x3f')]));_0x503634[_0x76e7('0x3e')]=_0x503634[_0x76e7('0x3e')]['length']?_0x503634['attributes']:_0x51b31f[_0x76e7('0x37')];_0x503634[_0x76e7('0x42')]=qs[_0x76e7('0x43')](_0xe3c0cf['query']['sort']);_0x503634[_0x76e7('0x44')]=qs['filters'](_[_0x76e7('0x45')](_0xe3c0cf[_0x76e7('0x39')],_0x51b31f['filters']));if(_0xe3c0cf['query'][_0x76e7('0x49')]){_0x503634['where']=_[_0x76e7('0x48')](_0x503634['where'],{'$or':_[_0x76e7('0x5b')](_0x503634[_0x76e7('0x3e')],function(_0x3ecea8){var _0x5d3b02={};_0x5d3b02[_0x3ecea8]={'$like':'%'+_0xe3c0cf['query'][_0x76e7('0x49')]+'%'};return _0x5d3b02;})});}_0x503634=_[_0x76e7('0x48')]({},_0x503634,_0xe3c0cf['options']);return _0x2027c4[_0x76e7('0xa6')](_0x503634);}})[_0x76e7('0x1a')](function(_0x4bf705){if(_0x4bf705){_0x7f1e2b=_0x4bf705[_0x76e7('0x40')];if(!_0xe3c0cf[_0x76e7('0x39')]['hasOwnProperty'](_0x76e7('0x59'))){_0x503634[_0x76e7('0x2a')]=qs[_0x76e7('0x2a')](_0xe3c0cf[_0x76e7('0x39')][_0x76e7('0x2a')]);_0x503634['offset']=qs[_0x76e7('0x29')](_0xe3c0cf[_0x76e7('0x39')][_0x76e7('0x29')]);}return _0x2027c4[_0x76e7('0xa6')](_0x503634);}})['then'](function(_0x40c1ef){if(_0x40c1ef){return _0x40c1ef?{'count':_0x7f1e2b,'rows':_0x40c1ef}:null;}})['then'](respondWithResult(_0x564c53,null))[_0x76e7('0x24')](handleError(_0x564c53,null));};exports[_0x76e7('0xa7')]=function(_0x4de722,_0x155002,_0x5648f8){var _0x53037a={'raw':![],'where':{}};var _0x595b94={};var _0x56bcbe={'count':0x0,'rows':[]};return db[_0x76e7('0x36')][_0x76e7('0x60')]({'where':{'id':_0x4de722[_0x76e7('0x4f')]['id']}})['then'](handleEntityNotFound(_0x155002,null))[_0x76e7('0x1a')](function(_0x1c06c8){if(_0x1c06c8){_0x595b94[_0x76e7('0x37')]=_[_0x76e7('0x38')](db['SmsInteraction'][_0x76e7('0x50')]);_0x595b94['query']=_['keys'](_0x4de722[_0x76e7('0x39')]);_0x595b94[_0x76e7('0x3c')]=_[_0x76e7('0x3d')](_0x595b94[_0x76e7('0x37')],_0x595b94['query']);_0x53037a[_0x76e7('0x3e')]=_[_0x76e7('0x3d')](_0x595b94[_0x76e7('0x37')],qs[_0x76e7('0x3f')](_0x4de722[_0x76e7('0x39')][_0x76e7('0x3f')]));_0x53037a[_0x76e7('0x3e')]=_0x53037a[_0x76e7('0x3e')]['length']?_0x53037a[_0x76e7('0x3e')]:_0x595b94['model'];if(!_0x4de722[_0x76e7('0x39')][_0x76e7('0x41')](_0x76e7('0x59'))){_0x53037a[_0x76e7('0x2a')]=qs['limit'](_0x4de722[_0x76e7('0x39')][_0x76e7('0x2a')]);_0x53037a['offset']=qs[_0x76e7('0x29')](_0x4de722[_0x76e7('0x39')][_0x76e7('0x29')]);}_0x53037a[_0x76e7('0x42')]=qs['sort'](_0x4de722[_0x76e7('0x39')][_0x76e7('0x43')]);_0x53037a[_0x76e7('0x44')]=qs[_0x76e7('0x3c')](_[_0x76e7('0x45')](_0x4de722[_0x76e7('0x39')],_0x595b94[_0x76e7('0x3c')]));_0x53037a['where'][_0x76e7('0x5a')]=_0x1c06c8['id'];if(_0x4de722[_0x76e7('0x39')][_0x76e7('0x49')]){_0x53037a['where']=_[_0x76e7('0x48')](_0x53037a[_0x76e7('0x44')],{'$or':_[_0x76e7('0x5b')](_0x53037a['attributes'],function(_0x26858d){var _0x5c1303={};_0x5c1303[_0x26858d]={'$like':'%'+_0x4de722[_0x76e7('0x39')][_0x76e7('0x49')]+'%'};return _0x5c1303;})});}_0x53037a=_[_0x76e7('0x48')]({},_0x53037a,_0x4de722[_0x76e7('0x4a')]);return db['SmsInteraction'][_0x76e7('0x28')]({'where':_0x53037a[_0x76e7('0x44')]})[_0x76e7('0x1a')](function(_0x447722){_0x56bcbe['count']=_0x447722;if(_0x4de722['query']['includeAll']){_0x53037a['include']=[{'model':db[_0x76e7('0x6a')],'as':_0x76e7('0xa8'),'required':![]},{'model':db['User'],'as':'Owner','attributes':[_0x76e7('0x96'),'fullname',_0x76e7('0xa9')],'required':![]},{'model':db[_0x76e7('0xaa')],'as':_0x76e7('0xab'),'attributes':['id',_0x76e7('0x96'),'color'],'where':_0x4de722[_0x76e7('0x39')][_0x76e7('0xac')]?{'id':_0x4de722[_0x76e7('0x39')]['tag']}:undefined,'required':_0x4de722['query'][_0x76e7('0xac')]?!![]:![]}];}return db[_0x76e7('0x8b')][_0x76e7('0x4c')](_0x53037a);})[_0x76e7('0x1a')](function(_0xe4ec56){_0x56bcbe[_0x76e7('0x4d')]=_0xe4ec56;return _0x56bcbe;});}})[_0x76e7('0x1a')](respondWithFilteredResult(_0x155002,_0x53037a))[_0x76e7('0x24')](handleError(_0x155002,null));};exports[_0x76e7('0x34')]=function(_0xb0601b,_0x27475e,_0xeb1eed){var _0x4d9e4d,_0x409175,_0x4288d2;if(_[_0x76e7('0x7e')](_0xb0601b[_0x76e7('0x53')]['body'])||_0xb0601b['body']['body']===''){throw new db[(_0x76e7('0x7f'))][(_0x76e7('0x6b'))](_0x76e7('0x80'));}if(_['isNil'](_0xb0601b['body']['to'])){throw new db['Sequelize'][(_0x76e7('0x6b'))](_0x76e7('0xad'));}_0x4d9e4d=_0xb0601b[_0x76e7('0x53')]['to'];return db['SmsAccount'][_0x76e7('0x54')]({'where':{'id':_0xb0601b[_0x76e7('0x4f')]['id']},'include':[{'model':db[_0x76e7('0x85')],'as':_0x76e7('0xae'),'include':[{'model':db[_0x76e7('0x6a')],'as':_0x76e7('0x86'),'where':{'mobile':_0x4d9e4d},'limit':0x1,'order':[[_0x76e7('0x6f'),_0x76e7('0x87')]]}]}]})[_0x76e7('0x1a')](handleEntityNotFound(_0x27475e,null))[_0x76e7('0x1a')](function(_0x235485){if(_0x235485&&_0x235485['List']){_0x409175=_0x235485[_0x76e7('0xaf')]({'plain':!![]});if(_0x409175[_0x76e7('0xae')]&&_0x409175[_0x76e7('0xae')]['Contacts'][_0x76e7('0x40')]){return _0x409175[_0x76e7('0xae')]['Contacts'][0x0];}return db[_0x76e7('0x6a')][_0x76e7('0x52')](_[_0x76e7('0x8a')](_0xb0601b[_0x76e7('0x53')],{'firstName':_0x4d9e4d,'mobile':_0x4d9e4d,'phone':_0x4d9e4d,'ListId':_0x409175[_0x76e7('0x70')]}));}})[_0x76e7('0x1a')](handleEntityNotFound(_0x27475e,null))[_0x76e7('0x1a')](function(_0x52b7d9){if(_0x52b7d9){_0x4288d2=_0x52b7d9;return db[_0x76e7('0x8b')]['find']({'where':{'ContactId':_0x4288d2['id'],'closed':![],'SmsAccountId':_0x409175['id']}})['then'](function(_0x5776aa){if(_0x5776aa){return[_0x5776aa,![]];}return db['SmsInteraction']['create']({'UserId':_0xb0601b['user']['id'],'ContactId':_0x4288d2['id'],'SmsAccountId':_0x409175['id'],'phone':_0x4d9e4d,'firstMsgDirection':_0x76e7('0xb0'),'Messages':[_[_0x76e7('0x48')](_0xb0601b[_0x76e7('0x53')],{'read':![],'body':_0xb0601b[_0x76e7('0x53')][_0x76e7('0x53')],'phone':_0x4d9e4d,'SmsAccountId':_0x409175['id'],'UserId':_0xb0601b[_0x76e7('0xb1')]['id'],'ContactId':_0x4288d2['id']})]},{'include':[{'model':db['SmsMessage'],'as':_0x76e7('0xb2')}]})[_0x76e7('0x1a')](function(_0x38b3c0){return[_0x38b3c0,!![]];});});}})[_0x76e7('0x8c')](function(_0x23fcb8,_0xed0cde){if(_0xed0cde){return _0x23fcb8;}return db['SmsMessage'][_0x76e7('0x52')](_[_0x76e7('0x48')](_0xb0601b[_0x76e7('0x53')],{'read':![],'body':_0xb0601b[_0x76e7('0x53')][_0x76e7('0x53')],'phone':_0x4d9e4d,'SmsAccountId':_0x409175['id'],'SmsInteractionId':_0x23fcb8['id'],'UserId':_0xb0601b[_0x76e7('0xb1')]['id'],'ContactId':_0x4288d2['id']}))['then'](function(_0x5d6d71){_0x23fcb8[_0x76e7('0xb3')][_0x76e7('0xb2')]=[];_0x23fcb8[_0x76e7('0xb3')][_0x76e7('0xb2')][_0x76e7('0xb4')](_0x5d6d71[_0x76e7('0xb3')]);return _0x23fcb8;});})[_0x76e7('0x1a')](respondWithResult(_0x27475e,null))['catch'](handleError(_0x27475e,null));};exports['status']=function(_0x83d048,_0x38810c,_0x2b38e6){if(_0x83d048[_0x76e7('0x53')]['id']){delete _0x83d048['body']['id'];}var _0x1029c3,_0xd86c36,_0x9d7216;return db[_0x76e7('0x36')][_0x76e7('0x54')]({'where':{'id':_0x83d048[_0x76e7('0x4f')]['id']}})[_0x76e7('0x1a')](handleEntityNotFound(_0x38810c,null))[_0x76e7('0x1a')](function(_0x3e8901){if(_0x3e8901){_0x9d7216=_0x3e8901;logger[_0x76e7('0x1e')](_0x76e7('0x1f'),'status',_0x76e7('0xb5'),_0x3e8901[_0x76e7('0x72')],util[_0x76e7('0xb6')](_0x83d048[_0x76e7('0x53')],{'showHidden':![],'depth':null}));switch(_0x3e8901[_0x76e7('0x72')]){case _0x76e7('0xb7'):if(_0x83d048['body'][_0x76e7('0xb8')]&&_0x83d048[_0x76e7('0x53')][_0x76e7('0x25')]){_0xd86c36=_0x83d048[_0x76e7('0x53')]['status'];return db[_0x76e7('0xb9')][_0x76e7('0x54')]({'where':{'messageId':_0x83d048[_0x76e7('0x53')]['skebby_dispatch_id']}});}break;case'connectel':if(_0x83d048[_0x76e7('0x53')][_0x76e7('0xba')]&&_0x83d048[_0x76e7('0x53')][_0x76e7('0xbb')]){_0xd86c36=_0x83d048['body']['statusInt'];return db[_0x76e7('0xb9')][_0x76e7('0x54')]({'where':{'messageId':_0x83d048['body'][_0x76e7('0xba')]}});}break;case _0x76e7('0xbc'):if(_0x83d048['body']['message_id']&&_0x83d048[_0x76e7('0x53')][_0x76e7('0xbd')]){_0xd86c36=_0x83d048[_0x76e7('0x53')][_0x76e7('0xbd')];return db['SmsMessage'][_0x76e7('0x54')]({'where':{'messageId':_0x83d048['body'][_0x76e7('0x7b')]}});}break;}}})[_0x76e7('0x1a')](handleEntityNotFound(_0x38810c,null))[_0x76e7('0x1a')](function(_0x179a90){if(_0x179a90){_0x1029c3=_0x179a90;switch(_0x9d7216[_0x76e7('0x72')]){case _0x76e7('0xb7'):if(_0xd86c36===_0x76e7('0xbe')){return _0x1029c3[_0x76e7('0x30')]({'read':!![]});}else{logger['error'](_0x76e7('0x1f'),_0x76e7('0x25'),_0x76e7('0xb7'),util[_0x76e7('0xb6')](_0x83d048[_0x76e7('0x53')],{'showHidden':![],'depth':null}));}break;case _0x76e7('0x7a'):if(_0xd86c36==='1'){return _0x1029c3['update']({'read':!![]});}else{logger[_0x76e7('0x21')](_0x76e7('0x1f'),_0x76e7('0x25'),_0x76e7('0xb7'),util['inspect'](_0x83d048['body'],{'showHidden':![],'depth':null}));}break;case _0x76e7('0xbc'):if(!_0x83d048[_0x76e7('0x53')][_0x76e7('0xbf')]&&_0xd86c36>=0xc8&&_0xd86c36<=0xce){return _0x1029c3[_0x76e7('0x30')]({'read':!![]});}else{logger[_0x76e7('0x21')](_0x76e7('0x1f'),_0x76e7('0x25'),_0x76e7('0xbc'),util[_0x76e7('0xb6')](_0x83d048[_0x76e7('0x53')],{'showHidden':![],'depth':null}));}break;}return _0x1029c3;}})[_0x76e7('0x1a')](respondWithResult(_0x38810c,null))[_0x76e7('0x24')](handleError(_0x38810c,null));};exports['addAgents']=function(_0xcea114,_0x401e96,_0x371847){return db['SmsAccount'][_0x76e7('0x54')]({'where':{'id':_0xcea114[_0x76e7('0x4f')]['id']}})['then'](handleEntityNotFound(_0x401e96,null))[_0x76e7('0x1a')](function(_0x3d16ec){if(_0x3d16ec){return _0x3d16ec['addAgents'](_0xcea114['body'][_0x76e7('0x5d')],_[_0x76e7('0x89')](_0xcea114['body'],[_0x76e7('0x5d'),'id'])||{})[_0x76e7('0x8c')](function(_0x2255e){for(var _0x2a704e=0x0;_0x2a704e<_0xcea114[_0x76e7('0x53')][_0x76e7('0x5d')][_0x76e7('0x40')];_0x2a704e+=0x1){socket[_0x76e7('0xc0')](_0x76e7('0xc1'),{'UserId':_0xcea114[_0x76e7('0x53')]['ids'][_0x2a704e],'SmsAccountId':_0xcea114[_0x76e7('0x4f')]['id']});}return _0x2255e;});}})[_0x76e7('0x1a')](respondWithResult(_0x401e96,null))[_0x76e7('0x24')](handleError(_0x401e96,null));};exports[_0x76e7('0xc2')]=function(_0x304cab,_0x2f3472,_0x11a8d9){var _0x5b2bea;return db[_0x76e7('0x36')][_0x76e7('0x54')]({'where':{'id':_0x304cab[_0x76e7('0x4f')]['id']}})[_0x76e7('0x1a')](handleEntityNotFound(_0x2f3472,null))[_0x76e7('0x1a')](function(_0x49678d){if(_0x49678d){return _0x49678d[_0x76e7('0xc2')](_0x304cab[_0x76e7('0x39')][_0x76e7('0x5d')])[_0x76e7('0x1a')](function(_0x5d8ecb){if(_[_0x76e7('0xc3')](_0x304cab[_0x76e7('0x39')][_0x76e7('0x5d')])){for(var _0xb71acb=0x0;_0xb71acb<_0x304cab[_0x76e7('0x39')]['ids'][_0x76e7('0x40')];_0xb71acb+=0x1){socket[_0x76e7('0xc0')](_0x76e7('0xc4'),{'UserId':_0x304cab['query']['ids'][_0xb71acb],'SmsAccountId':_0x304cab[_0x76e7('0x4f')]['id']});}}else{socket[_0x76e7('0xc0')](_0x76e7('0xc4'),{'UserId':_0x304cab['query'][_0x76e7('0x5d')],'SmsAccountId':_0x304cab[_0x76e7('0x4f')]['id']});}});}})[_0x76e7('0x1a')](respondWithStatusCode(_0x2f3472,null))[_0x76e7('0x24')](handleError(_0x2f3472,null));};exports[_0x76e7('0xc5')]=function(_0x5a6955,_0x25f579,_0x4af6e4){var _0x1afd7e={};var _0x1cbcbf={};var _0x2bec5;var _0x4eeefe;return db[_0x76e7('0x36')][_0x76e7('0x60')]({'where':{'id':_0x5a6955[_0x76e7('0x4f')]['id']}})[_0x76e7('0x1a')](handleEntityNotFound(_0x25f579,null))[_0x76e7('0x1a')](function(_0xc88862){if(_0xc88862){_0x2bec5=_0xc88862;_0x1cbcbf[_0x76e7('0x37')]=_['keys'](db[_0x76e7('0x95')][_0x76e7('0x50')]);_0x1cbcbf[_0x76e7('0x39')]=_[_0x76e7('0x38')](_0x5a6955[_0x76e7('0x39')]);_0x1cbcbf[_0x76e7('0x3c')]=_[_0x76e7('0x3d')](_0x1cbcbf[_0x76e7('0x37')],_0x1cbcbf[_0x76e7('0x39')]);_0x1afd7e[_0x76e7('0x3e')]=_[_0x76e7('0x3d')](_0x1cbcbf[_0x76e7('0x37')],qs[_0x76e7('0x3f')](_0x5a6955['query'][_0x76e7('0x3f')]));_0x1afd7e[_0x76e7('0x3e')]=_0x1afd7e[_0x76e7('0x3e')][_0x76e7('0x40')]?_0x1afd7e['attributes']:_0x1cbcbf[_0x76e7('0x37')];_0x1afd7e[_0x76e7('0x42')]=qs[_0x76e7('0x43')](_0x5a6955['query'][_0x76e7('0x43')]);_0x1afd7e[_0x76e7('0x44')]=qs[_0x76e7('0x3c')](_[_0x76e7('0x45')](_0x5a6955[_0x76e7('0x39')],_0x1cbcbf[_0x76e7('0x3c')]));if(_0x5a6955[_0x76e7('0x39')][_0x76e7('0x49')]){_0x1afd7e[_0x76e7('0x44')]=_[_0x76e7('0x48')](_0x1afd7e[_0x76e7('0x44')],{'$or':_['map'](_0x1afd7e['attributes'],function(_0x478a31){var _0x2febfa={};_0x2febfa[_0x478a31]={'$like':'%'+_0x5a6955['query']['filter']+'%'};return _0x2febfa;})});}_0x1afd7e=_[_0x76e7('0x48')]({},_0x1afd7e,_0x5a6955[_0x76e7('0x4a')]);return _0x2bec5[_0x76e7('0xc5')](_0x1afd7e);}})[_0x76e7('0x1a')](function(_0x3b6567){if(_0x3b6567){_0x4eeefe=_0x3b6567[_0x76e7('0x40')];if(!_0x5a6955[_0x76e7('0x39')]['hasOwnProperty'](_0x76e7('0x59'))){_0x1afd7e[_0x76e7('0x2a')]=qs[_0x76e7('0x2a')](_0x5a6955[_0x76e7('0x39')]['limit']);_0x1afd7e[_0x76e7('0x29')]=qs[_0x76e7('0x29')](_0x5a6955[_0x76e7('0x39')]['offset']);}return _0x2bec5[_0x76e7('0xc5')](_0x1afd7e);}})[_0x76e7('0x1a')](function(_0x4ffae9){if(_0x4ffae9){return _0x4ffae9?{'count':_0x4eeefe,'rows':_0x4ffae9}:null;}})[_0x76e7('0x1a')](respondWithResult(_0x25f579,null))['catch'](handleError(_0x25f579,null));};