Built motion from commit 3770a7bd.|2.6.29
[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 _0x5d1e=['code','message','SmsAccount,\x20%s,\x20%s','info','catch','sendStatus','status','end','json','offset','undefined','limit','set','Content-Range','apply','reject','save','update','destroy','get','SmsAccounts','UserProfileResource','stack','name','Pause','mandatoryDispositionPause','map','SmsAccount','rawAttributes','fieldName','type','key','model','keys','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','pick','filter','where','VIRTUAL','merge','count','includeAll','include','findAll','rows','params','options','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','autoAssociation','describe','addDisposition','SmsAccountId','getDispositions','findOne','Disposition','removeDispositions','ids','addAnswer','CannedAnswer','removeAnswers','notify','sms','SmsApplication','Applications','orderBy','priority','asc','account','CmContact','Sequelize','ValidationError','difference','createdAt','updatedAt','CompanyId','ListId','mobile','twilio','from','From','Body','messageId','sender','text','connectel','clicksend','message_id','Text','MessageUUID','infobip','results','csc','segmentedMessage','clickatell','fromNumber','bandwidth','intelepeer','refid','isNil','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','mapKey','omit','Contacts','SmsInteraction','spread','interaction','created','autoclose','applications','push','close','*,*,*,*','SmsMessage','ContactId','UserId','User','agent','waitForTheAssignedAgent','queueId','SmsQueue','unshift','waitForTheAssignedQueue','Start','startRouting','receiveMessage','entity\x20found','SmsAccount,\x20%s,\x20%s,\x20%s,\x20%s','Content-Type','sequelize','transaction','Transaction','ISOLATION_LEVELS','READ_COMMITTED','bulkCreate','findAndCountAll','finally','send','getInteractions','Contact','Owner','fullname','Tag','Tags','color','tag','to\x20is\x20mandatory','CmList','DESC','List','out','dataValues','Messages','inspect','skebby','skebby_dispatch_id','requestid','statusInt','status_code','groupName','error_code','DELIVERED','DELIVERED_TO_GATEWAY','RECEIVED_BY_RECIPIENT','message-delivered','DELIVRD','statusGet','message-id','state','addAgents','emit','userSmsAccount:save','removeAgents','userSmsAccount:remove','getAgents','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','fs-extra','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/environment','../../mysqldb','redis','defaults','localhost','./smsAccount.socket','register','jayson/promise','client','http','request','then','debug','SmsAccount,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error'];(function(_0x504d70,_0x143d63){var _0x102fe8=function(_0x5ef594){while(--_0x5ef594){_0x504d70['push'](_0x504d70['shift']());}};_0x102fe8(++_0x143d63);}(_0x5d1e,0xc0));var _0xe5d1=function(_0xd90cdf,_0x1bc824){_0xd90cdf=_0xd90cdf-0x0;var _0x40df86=_0x5d1e[_0xd90cdf];return _0x40df86;};'use strict';var emlformat=require(_0xe5d1('0x0'));var rimraf=require(_0xe5d1('0x1'));var zipdir=require(_0xe5d1('0x2'));var jsonpatch=require(_0xe5d1('0x3'));var rp=require(_0xe5d1('0x4'));var moment=require('moment');var BPromise=require(_0xe5d1('0x5'));var Mustache=require(_0xe5d1('0x6'));var util=require(_0xe5d1('0x7'));var path=require(_0xe5d1('0x8'));var sox=require('sox');var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xe5d1('0x9'));var _=require(_0xe5d1('0xa'));var squel=require(_0xe5d1('0xb'));var crypto=require(_0xe5d1('0xc'));var jsforce=require(_0xe5d1('0xd'));var deskjs=require(_0xe5d1('0xe'));var toCsv=require(_0xe5d1('0xf'));var querystring=require(_0xe5d1('0x10'));var Papa=require('papaparse');var Redis=require(_0xe5d1('0x11'));var authService=require(_0xe5d1('0x12'));var qs=require(_0xe5d1('0x13'));var as=require(_0xe5d1('0x14'));var hardwareService=require(_0xe5d1('0x15'));var logger=require('../../config/logger')('api');var utils=require('../../config/utils');var config=require(_0xe5d1('0x16'));var licenseUtil=require('../../config/license/util');var db=require(_0xe5d1('0x17'))['db'];config[_0xe5d1('0x18')]=_[_0xe5d1('0x19')](config[_0xe5d1('0x18')],{'host':_0xe5d1('0x1a'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xe5d1('0x18')]));require(_0xe5d1('0x1b'))[_0xe5d1('0x1c')](socket);var jayson=require(_0xe5d1('0x1d'));var client=jayson[_0xe5d1('0x1e')][_0xe5d1('0x1f')]({'port':0x232c});function respondWithRpcPromise(_0x417404,_0x5a8dbc,_0xda5231,_0x5b0689){return new BPromise(function(_0x2d3667,_0x430232){var _0x9ef2fa=_0x5b0689||client;return _0x9ef2fa[_0xe5d1('0x20')](_0x417404,_0xda5231)[_0xe5d1('0x21')](function(_0x1f38fc){logger['info']('SmsAccount,\x20%s,\x20%s',_0x5a8dbc,'request\x20sent');logger[_0xe5d1('0x22')](_0xe5d1('0x23'),_0x5a8dbc,_0xe5d1('0x24'),JSON[_0xe5d1('0x25')](_0x1f38fc));if(_0x1f38fc[_0xe5d1('0x26')]){if(_0x1f38fc['error'][_0xe5d1('0x27')]===0x1f4){logger[_0xe5d1('0x26')]('SmsAccount,\x20%s,\x20%s',_0x5a8dbc,_0x1f38fc['error'][_0xe5d1('0x28')]);return _0x430232(_0x1f38fc[_0xe5d1('0x26')][_0xe5d1('0x28')]);}logger['error'](_0xe5d1('0x29'),_0x5a8dbc,_0x1f38fc[_0xe5d1('0x26')][_0xe5d1('0x28')]);return _0x2d3667(_0x1f38fc[_0xe5d1('0x26')][_0xe5d1('0x28')]);}else{logger[_0xe5d1('0x2a')](_0xe5d1('0x29'),_0x5a8dbc,'request\x20sent');_0x2d3667(_0x1f38fc['result']['message']);}})[_0xe5d1('0x2b')](function(_0x267697){logger[_0xe5d1('0x26')]('SmsAccount,\x20%s,\x20%s',_0x5a8dbc,_0x267697);_0x430232(_0x267697);});});}function respondWithStatusCode(_0x24569f,_0x1014fc){_0x1014fc=_0x1014fc||0xcc;return function(_0x20852b){if(_0x20852b){return _0x24569f[_0xe5d1('0x2c')](_0x1014fc);}return _0x24569f[_0xe5d1('0x2d')](_0x1014fc)[_0xe5d1('0x2e')]();};}function respondWithResult(_0x1c08c1,_0x17f2b6){_0x17f2b6=_0x17f2b6||0xc8;return function(_0x669ddf){if(_0x669ddf){return _0x1c08c1[_0xe5d1('0x2d')](_0x17f2b6)[_0xe5d1('0x2f')](_0x669ddf);}};}function respondWithFilteredResult(_0x7b3c2d,_0x4da6dc){return function(_0x25bca3){if(_0x25bca3){var _0x365a44=typeof _0x4da6dc[_0xe5d1('0x30')]===_0xe5d1('0x31')&&typeof _0x4da6dc[_0xe5d1('0x32')]==='undefined';var _0x5c061c=_0x25bca3['count'];var _0x3933db=_0x365a44?0x0:_0x4da6dc[_0xe5d1('0x30')];var _0x12480d=_0x365a44?_0x25bca3['count']:_0x4da6dc[_0xe5d1('0x30')]+_0x4da6dc['limit'];var _0x287efd;if(_0x12480d>=_0x5c061c){_0x12480d=_0x5c061c;_0x287efd=0xc8;}else{_0x287efd=0xce;}_0x7b3c2d['status'](_0x287efd);return _0x7b3c2d[_0xe5d1('0x33')](_0xe5d1('0x34'),_0x3933db+'-'+_0x12480d+'/'+_0x5c061c)[_0xe5d1('0x2f')](_0x25bca3);}return null;};}function patchUpdates(_0x5e4f93){return function(_0x44cbc5){try{jsonpatch[_0xe5d1('0x35')](_0x44cbc5,_0x5e4f93,!![]);}catch(_0x200947){return BPromise[_0xe5d1('0x36')](_0x200947);}return _0x44cbc5[_0xe5d1('0x37')]();};}function saveUpdates(_0x504961,_0x306acf){return function(_0x280509){if(_0x280509){return _0x280509[_0xe5d1('0x38')](_0x504961)[_0xe5d1('0x21')](function(_0x5c691e){return _0x5c691e;});}return null;};}function removeEntity(_0x2ef517,_0x498f06){return function(_0x5256ae){if(_0x5256ae){return _0x5256ae[_0xe5d1('0x39')]()[_0xe5d1('0x21')](function(){var _0x3f75d9=_0x5256ae[_0xe5d1('0x3a')]({'plain':!![]});var _0x525a3b=_0xe5d1('0x3b');return db[_0xe5d1('0x3c')][_0xe5d1('0x39')]({'where':{'type':_0x525a3b,'resourceId':_0x3f75d9['id']}})[_0xe5d1('0x21')](function(){return _0x5256ae;});})['then'](function(){_0x2ef517[_0xe5d1('0x2d')](0xcc)['end']();});}};}function handleEntityNotFound(_0x4a2de0,_0x553bb8){return function(_0x52e92e){if(!_0x52e92e){_0x4a2de0[_0xe5d1('0x2c')](0x194);}return _0x52e92e;};}function handleError(_0x807981,_0x26c363){_0x26c363=_0x26c363||0x1f4;return function(_0x37e4f1){logger[_0xe5d1('0x26')](_0x37e4f1[_0xe5d1('0x3d')]);if(_0x37e4f1[_0xe5d1('0x3e')]){delete _0x37e4f1[_0xe5d1('0x3e')];}_0x807981[_0xe5d1('0x2d')](_0x26c363)['send'](_0x37e4f1);};}exports['index']=function(_0x361b6c,_0x558a05){var _0x2d3fe7={'include':[{'model':db[_0xe5d1('0x3f')],'as':_0xe5d1('0x40')}]},_0x10691f={},_0x25b9fc={'count':0x0,'rows':[]};var _0xad33d0=_[_0xe5d1('0x41')](db[_0xe5d1('0x42')][_0xe5d1('0x43')],function(_0x4b6fa7){return{'name':_0x4b6fa7[_0xe5d1('0x44')],'type':_0x4b6fa7[_0xe5d1('0x45')][_0xe5d1('0x46')]};});_0x10691f[_0xe5d1('0x47')]=_[_0xe5d1('0x41')](_0xad33d0,'name');_0x10691f['query']=_[_0xe5d1('0x48')](_0x361b6c[_0xe5d1('0x49')]);_0x10691f[_0xe5d1('0x4a')]=_[_0xe5d1('0x4b')](_0x10691f[_0xe5d1('0x47')],_0x10691f[_0xe5d1('0x49')]);_0x2d3fe7[_0xe5d1('0x4c')]=_[_0xe5d1('0x4b')](_0x10691f[_0xe5d1('0x47')],qs[_0xe5d1('0x4d')](_0x361b6c[_0xe5d1('0x49')][_0xe5d1('0x4d')]));_0x2d3fe7[_0xe5d1('0x4c')]=_0x2d3fe7[_0xe5d1('0x4c')][_0xe5d1('0x4e')]?_0x2d3fe7[_0xe5d1('0x4c')]:_0x10691f[_0xe5d1('0x47')];if(!_0x361b6c[_0xe5d1('0x49')][_0xe5d1('0x4f')](_0xe5d1('0x50'))){_0x2d3fe7['limit']=qs[_0xe5d1('0x32')](_0x361b6c[_0xe5d1('0x49')][_0xe5d1('0x32')]);_0x2d3fe7[_0xe5d1('0x30')]=qs[_0xe5d1('0x30')](_0x361b6c['query']['offset']);}_0x2d3fe7[_0xe5d1('0x51')]=qs[_0xe5d1('0x52')](_0x361b6c[_0xe5d1('0x49')][_0xe5d1('0x52')]);_0x2d3fe7['where']=qs[_0xe5d1('0x4a')](_[_0xe5d1('0x53')](_0x361b6c[_0xe5d1('0x49')],_0x10691f[_0xe5d1('0x4a')]),_0xad33d0);if(_0x361b6c[_0xe5d1('0x49')][_0xe5d1('0x54')]){_0x2d3fe7[_0xe5d1('0x55')]=_['merge'](_0x2d3fe7[_0xe5d1('0x55')],{'$or':_['map'](_0xad33d0,function(_0x4bbe9a){if(_0x4bbe9a[_0xe5d1('0x45')]!==_0xe5d1('0x56')){var _0x206ed3={};_0x206ed3[_0x4bbe9a['name']]={'$like':'%'+_0x361b6c[_0xe5d1('0x49')][_0xe5d1('0x54')]+'%'};return _0x206ed3;}})});}_0x2d3fe7=_[_0xe5d1('0x57')]({},_0x2d3fe7,_0x361b6c['options']);var _0x3650d8={'where':_0x2d3fe7[_0xe5d1('0x55')]};return db[_0xe5d1('0x42')]['count'](_0x3650d8)[_0xe5d1('0x21')](function(_0x4ef3f1){_0x25b9fc[_0xe5d1('0x58')]=_0x4ef3f1;if(_0x361b6c['query'][_0xe5d1('0x59')]){_0x2d3fe7[_0xe5d1('0x5a')]=[{'all':!![]}];}return db[_0xe5d1('0x42')][_0xe5d1('0x5b')](_0x2d3fe7);})['then'](function(_0x252da9){_0x25b9fc[_0xe5d1('0x5c')]=_0x252da9;return _0x25b9fc;})[_0xe5d1('0x21')](respondWithFilteredResult(_0x558a05,_0x2d3fe7))[_0xe5d1('0x2b')](handleError(_0x558a05,null));};exports['show']=function(_0x48bb1c,_0x9582f6){var _0x57add1={'raw':![],'where':{'id':_0x48bb1c[_0xe5d1('0x5d')]['id']},'include':[{'model':db['Pause'],'as':'mandatoryDispositionPause'}]},_0x592187={};_0x592187['model']=_[_0xe5d1('0x48')](db[_0xe5d1('0x42')][_0xe5d1('0x43')]);_0x592187['query']=_[_0xe5d1('0x48')](_0x48bb1c['query']);_0x592187[_0xe5d1('0x4a')]=_[_0xe5d1('0x4b')](_0x592187[_0xe5d1('0x47')],_0x592187[_0xe5d1('0x49')]);_0x57add1[_0xe5d1('0x4c')]=_[_0xe5d1('0x4b')](_0x592187[_0xe5d1('0x47')],qs[_0xe5d1('0x4d')](_0x48bb1c['query']['fields']));_0x57add1[_0xe5d1('0x4c')]=_0x57add1[_0xe5d1('0x4c')]['length']?_0x57add1[_0xe5d1('0x4c')]:_0x592187['model'];if(_0x48bb1c[_0xe5d1('0x49')][_0xe5d1('0x59')]){_0x57add1[_0xe5d1('0x5a')]=[{'all':!![]}];}_0x57add1=_[_0xe5d1('0x57')]({},_0x57add1,_0x48bb1c[_0xe5d1('0x5e')]);return db[_0xe5d1('0x42')][_0xe5d1('0x5f')](_0x57add1)['then'](handleEntityNotFound(_0x9582f6,null))[_0xe5d1('0x21')](respondWithResult(_0x9582f6,null))[_0xe5d1('0x2b')](handleError(_0x9582f6,null));};exports[_0xe5d1('0x60')]=function(_0x57a1ca,_0x149d1d){return db[_0xe5d1('0x42')][_0xe5d1('0x60')](_0x57a1ca[_0xe5d1('0x61')],{})['then'](function(_0xc76db0){var _0x5910ac=_0x57a1ca[_0xe5d1('0x62')][_0xe5d1('0x3a')]({'plain':!![]});if(!_0x5910ac)throw new Error(_0xe5d1('0x63'));if(_0x5910ac[_0xe5d1('0x64')]===_0xe5d1('0x62')){var _0x3fa39e=_0xc76db0['get']({'plain':!![]});var _0x4cb658='SmsAccounts';return db[_0xe5d1('0x65')][_0xe5d1('0x5f')]({'where':{'name':_0x4cb658,'userProfileId':_0x5910ac['userProfileId']},'raw':!![]})[_0xe5d1('0x21')](function(_0x38cd46){if(_0x38cd46&&_0x38cd46[_0xe5d1('0x66')]===0x0){return db['UserProfileResource']['create']({'name':_0x3fa39e[_0xe5d1('0x3e')],'resourceId':_0x3fa39e['id'],'type':_0x38cd46[_0xe5d1('0x3e')],'sectionId':_0x38cd46['id']},{})['then'](function(){return _0xc76db0;});}else{return _0xc76db0;}})[_0xe5d1('0x2b')](function(_0x446eca){logger[_0xe5d1('0x26')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x446eca);throw _0x446eca;});}return _0xc76db0;})[_0xe5d1('0x21')](respondWithResult(_0x149d1d,0xc9))[_0xe5d1('0x2b')](handleError(_0x149d1d,null));};exports[_0xe5d1('0x38')]=function(_0xe11d9a,_0x44b6f8){if(_0xe11d9a[_0xe5d1('0x61')]['id']){delete _0xe11d9a['body']['id'];}return db['SmsAccount'][_0xe5d1('0x5f')]({'where':{'id':_0xe11d9a['params']['id']},'include':[{'model':db[_0xe5d1('0x3f')],'as':_0xe5d1('0x40')}]})[_0xe5d1('0x21')](handleEntityNotFound(_0x44b6f8,null))[_0xe5d1('0x21')](saveUpdates(_0xe11d9a[_0xe5d1('0x61')],null))[_0xe5d1('0x21')](respondWithResult(_0x44b6f8,null))[_0xe5d1('0x2b')](handleError(_0x44b6f8,null));};exports[_0xe5d1('0x39')]=function(_0x54c340,_0x2fcb96){return db['SmsAccount']['find']({'where':{'id':_0x54c340[_0xe5d1('0x5d')]['id']}})['then'](handleEntityNotFound(_0x2fcb96,null))[_0xe5d1('0x21')](removeEntity(_0x2fcb96,null))[_0xe5d1('0x2b')](handleError(_0x2fcb96,null));};exports[_0xe5d1('0x67')]=function(_0xc16b52,_0x4029ba){return db[_0xe5d1('0x42')][_0xe5d1('0x67')]()[_0xe5d1('0x21')](respondWithResult(_0x4029ba,null))[_0xe5d1('0x2b')](handleError(_0x4029ba,null));};exports[_0xe5d1('0x68')]=function(_0x46a9d8,_0x2b9b30,_0x211c7d){if(_0x46a9d8[_0xe5d1('0x61')]['id']){delete _0x46a9d8[_0xe5d1('0x61')]['id'];}return db['SmsAccount'][_0xe5d1('0x5f')]({'where':{'id':_0x46a9d8[_0xe5d1('0x5d')]['id']}})[_0xe5d1('0x21')](handleEntityNotFound(_0x2b9b30,null))['then'](function(_0x4c2f05){if(_0x4c2f05){_0x46a9d8[_0xe5d1('0x61')][_0xe5d1('0x69')]=_0x4c2f05['id'];return db['Disposition'][_0xe5d1('0x60')](_0x46a9d8['body']);}})[_0xe5d1('0x21')](respondWithResult(_0x2b9b30,null))['catch'](handleError(_0x2b9b30,null));};exports[_0xe5d1('0x6a')]=function(_0x12587c,_0x336f18,_0x35cb98){var _0xc48b1b={'raw':![],'where':{}};var _0x571d65={};var _0xe09dd5={'count':0x0,'rows':[]};return db[_0xe5d1('0x42')][_0xe5d1('0x6b')]({'where':{'id':_0x12587c[_0xe5d1('0x5d')]['id']}})[_0xe5d1('0x21')](handleEntityNotFound(_0x336f18,null))[_0xe5d1('0x21')](function(_0x2928cc){if(_0x2928cc){_0x571d65[_0xe5d1('0x47')]=_[_0xe5d1('0x48')](db[_0xe5d1('0x6c')][_0xe5d1('0x43')]);_0x571d65[_0xe5d1('0x49')]=_[_0xe5d1('0x48')](_0x12587c[_0xe5d1('0x49')]);_0x571d65['filters']=_[_0xe5d1('0x4b')](_0x571d65[_0xe5d1('0x47')],_0x571d65[_0xe5d1('0x49')]);_0xc48b1b[_0xe5d1('0x4c')]=_[_0xe5d1('0x4b')](_0x571d65[_0xe5d1('0x47')],qs[_0xe5d1('0x4d')](_0x12587c[_0xe5d1('0x49')][_0xe5d1('0x4d')]));_0xc48b1b[_0xe5d1('0x4c')]=_0xc48b1b[_0xe5d1('0x4c')][_0xe5d1('0x4e')]?_0xc48b1b[_0xe5d1('0x4c')]:_0x571d65[_0xe5d1('0x47')];if(!_0x12587c[_0xe5d1('0x49')][_0xe5d1('0x4f')](_0xe5d1('0x50'))){_0xc48b1b['limit']=qs[_0xe5d1('0x32')](_0x12587c[_0xe5d1('0x49')]['limit']);_0xc48b1b[_0xe5d1('0x30')]=qs['offset'](_0x12587c[_0xe5d1('0x49')][_0xe5d1('0x30')]);}_0xc48b1b[_0xe5d1('0x51')]=qs[_0xe5d1('0x52')](_0x12587c[_0xe5d1('0x49')]['sort']);_0xc48b1b[_0xe5d1('0x55')]=qs[_0xe5d1('0x4a')](_[_0xe5d1('0x53')](_0x12587c[_0xe5d1('0x49')],_0x571d65[_0xe5d1('0x4a')]));_0xc48b1b[_0xe5d1('0x55')][_0xe5d1('0x69')]=_0x2928cc['id'];if(_0x12587c['query'][_0xe5d1('0x54')]){_0xc48b1b[_0xe5d1('0x55')]=_['merge'](_0xc48b1b[_0xe5d1('0x55')],{'$or':_['map'](_0xc48b1b[_0xe5d1('0x4c')],function(_0x4fc6eb){var _0x48c68d={};_0x48c68d[_0x4fc6eb]={'$like':'%'+_0x12587c[_0xe5d1('0x49')][_0xe5d1('0x54')]+'%'};return _0x48c68d;})});}_0xc48b1b=_[_0xe5d1('0x57')]({},_0xc48b1b,_0x12587c['options']);return db[_0xe5d1('0x6c')][_0xe5d1('0x58')]({'where':_0xc48b1b[_0xe5d1('0x55')]})[_0xe5d1('0x21')](function(_0x326e3a){_0xe09dd5[_0xe5d1('0x58')]=_0x326e3a;if(_0x12587c[_0xe5d1('0x49')][_0xe5d1('0x59')]){_0xc48b1b['include']=[{'all':!![]}];}return db['Disposition']['findAll'](_0xc48b1b);})[_0xe5d1('0x21')](function(_0xbd6e1){_0xe09dd5['rows']=_0xbd6e1;return _0xe09dd5;});}})[_0xe5d1('0x21')](respondWithFilteredResult(_0x336f18,_0xc48b1b))[_0xe5d1('0x2b')](handleError(_0x336f18,null));};exports[_0xe5d1('0x6d')]=function(_0x3a56b9,_0x6327b3,_0x7c0762){return db[_0xe5d1('0x42')][_0xe5d1('0x5f')]({'where':{'id':_0x3a56b9[_0xe5d1('0x5d')]['id']}})[_0xe5d1('0x21')](handleEntityNotFound(_0x6327b3,null))[_0xe5d1('0x21')](function(_0x5b4d8f){if(_0x5b4d8f){return _0x5b4d8f[_0xe5d1('0x6d')](_0x3a56b9[_0xe5d1('0x49')][_0xe5d1('0x6e')]);}})[_0xe5d1('0x21')](respondWithStatusCode(_0x6327b3,null))[_0xe5d1('0x2b')](handleError(_0x6327b3,null));};exports[_0xe5d1('0x6f')]=function(_0x14df3d,_0xa81fdd,_0x304d7d){if(_0x14df3d[_0xe5d1('0x61')]['id']){delete _0x14df3d[_0xe5d1('0x61')]['id'];}return db['SmsAccount']['find']({'where':{'id':_0x14df3d[_0xe5d1('0x5d')]['id']}})['then'](handleEntityNotFound(_0xa81fdd,null))['then'](function(_0x1dd688){if(_0x1dd688){_0x14df3d[_0xe5d1('0x61')][_0xe5d1('0x69')]=_0x1dd688['id'];return db['CannedAnswer']['create'](_0x14df3d[_0xe5d1('0x61')]);}})[_0xe5d1('0x21')](respondWithResult(_0xa81fdd,null))[_0xe5d1('0x2b')](handleError(_0xa81fdd,null));};exports['getAnswers']=function(_0xa1b497,_0xebbb5c,_0x3c53cf){var _0x34e2e5={'raw':![],'where':{}};var _0x1ad15b={};var _0x4b44e1={'count':0x0,'rows':[]};return db[_0xe5d1('0x42')]['findOne']({'where':{'id':_0xa1b497[_0xe5d1('0x5d')]['id']}})['then'](handleEntityNotFound(_0xebbb5c,null))['then'](function(_0x281165){if(_0x281165){_0x1ad15b[_0xe5d1('0x47')]=_[_0xe5d1('0x48')](db[_0xe5d1('0x70')][_0xe5d1('0x43')]);_0x1ad15b[_0xe5d1('0x49')]=_[_0xe5d1('0x48')](_0xa1b497[_0xe5d1('0x49')]);_0x1ad15b[_0xe5d1('0x4a')]=_[_0xe5d1('0x4b')](_0x1ad15b[_0xe5d1('0x47')],_0x1ad15b['query']);_0x34e2e5['attributes']=_['intersection'](_0x1ad15b[_0xe5d1('0x47')],qs[_0xe5d1('0x4d')](_0xa1b497[_0xe5d1('0x49')][_0xe5d1('0x4d')]));_0x34e2e5[_0xe5d1('0x4c')]=_0x34e2e5[_0xe5d1('0x4c')][_0xe5d1('0x4e')]?_0x34e2e5['attributes']:_0x1ad15b[_0xe5d1('0x47')];if(!_0xa1b497[_0xe5d1('0x49')][_0xe5d1('0x4f')](_0xe5d1('0x50'))){_0x34e2e5['limit']=qs[_0xe5d1('0x32')](_0xa1b497[_0xe5d1('0x49')][_0xe5d1('0x32')]);_0x34e2e5[_0xe5d1('0x30')]=qs['offset'](_0xa1b497['query'][_0xe5d1('0x30')]);}_0x34e2e5[_0xe5d1('0x51')]=qs[_0xe5d1('0x52')](_0xa1b497[_0xe5d1('0x49')][_0xe5d1('0x52')]);_0x34e2e5['where']=qs[_0xe5d1('0x4a')](_[_0xe5d1('0x53')](_0xa1b497[_0xe5d1('0x49')],_0x1ad15b['filters']));_0x34e2e5[_0xe5d1('0x55')][_0xe5d1('0x69')]=_0x281165['id'];if(_0xa1b497[_0xe5d1('0x49')][_0xe5d1('0x54')]){_0x34e2e5[_0xe5d1('0x55')]=_[_0xe5d1('0x57')](_0x34e2e5['where'],{'$or':_[_0xe5d1('0x41')](_0x34e2e5['attributes'],function(_0x22939a){var _0x33b739={};_0x33b739[_0x22939a]={'$like':'%'+_0xa1b497[_0xe5d1('0x49')][_0xe5d1('0x54')]+'%'};return _0x33b739;})});}_0x34e2e5=_[_0xe5d1('0x57')]({},_0x34e2e5,_0xa1b497[_0xe5d1('0x5e')]);return db[_0xe5d1('0x70')][_0xe5d1('0x58')]({'where':_0x34e2e5[_0xe5d1('0x55')]})[_0xe5d1('0x21')](function(_0x49bb35){_0x4b44e1[_0xe5d1('0x58')]=_0x49bb35;if(_0xa1b497[_0xe5d1('0x49')][_0xe5d1('0x59')]){_0x34e2e5[_0xe5d1('0x5a')]=[{'all':!![]}];}return db['CannedAnswer'][_0xe5d1('0x5b')](_0x34e2e5);})[_0xe5d1('0x21')](function(_0x563c9b){_0x4b44e1[_0xe5d1('0x5c')]=_0x563c9b;return _0x4b44e1;});}})[_0xe5d1('0x21')](respondWithFilteredResult(_0xebbb5c,_0x34e2e5))[_0xe5d1('0x2b')](handleError(_0xebbb5c,null));};exports[_0xe5d1('0x71')]=function(_0x79dde7,_0x4a7063,_0x45dc83){return db[_0xe5d1('0x42')]['find']({'where':{'id':_0x79dde7[_0xe5d1('0x5d')]['id']}})[_0xe5d1('0x21')](handleEntityNotFound(_0x4a7063,null))['then'](function(_0x5aba9a){if(_0x5aba9a){return _0x5aba9a['removeAnswers'](_0x79dde7[_0xe5d1('0x49')]['ids']);}})['then'](respondWithStatusCode(_0x4a7063,null))[_0xe5d1('0x2b')](handleError(_0x4a7063,null));};exports[_0xe5d1('0x72')]=function(_0x58eb88,_0x18c69d,_0x195a80){var _0x1099bc={'channel':_0xe5d1('0x73')};var _0x4fde26=[];var _0x2bbf9c=[];var _0x1f3372={};return db[_0xe5d1('0x42')][_0xe5d1('0x5f')]({'where':{'id':_0x58eb88[_0xe5d1('0x5d')]['id']},'include':[{'model':db[_0xe5d1('0x74')],'as':_0xe5d1('0x75')}]})[_0xe5d1('0x21')](handleEntityNotFound(_0x18c69d,null))[_0xe5d1('0x21')](function(_0x195199){_0x1099bc['account']=_0x195199;_0x1099bc['applications']=_[_0xe5d1('0x76')](_0x195199[_0xe5d1('0x75')],[_0xe5d1('0x77')],[_0xe5d1('0x78')]);if(_0x1099bc[_0xe5d1('0x79')]['Applications']){delete _0x1099bc['account'][_0xe5d1('0x75')];}return db[_0xe5d1('0x7a')][_0xe5d1('0x67')]();})[_0xe5d1('0x21')](function(_0x1048a2){if(!_0x1048a2){throw new db[(_0xe5d1('0x7b'))][(_0xe5d1('0x7c'))]('no\x20available\x20attributes');}_0x4fde26=_[_0xe5d1('0x7d')](_[_0xe5d1('0x48')](_0x1048a2),[_0xe5d1('0x7e'),_0xe5d1('0x7f')]);_0x2bbf9c=_[_0xe5d1('0x7d')](_['keys'](_0x1048a2),['createdAt',_0xe5d1('0x7f'),_0xe5d1('0x80'),_0xe5d1('0x81')]);_0x1099bc[_0xe5d1('0x61')]={'mapKey':_0xe5d1('0x82')};if(_0x1099bc[_0xe5d1('0x79')]['type']){switch(_0x1099bc[_0xe5d1('0x79')][_0xe5d1('0x45')]){case _0xe5d1('0x83'):_0x1099bc[_0xe5d1('0x61')][_0xe5d1('0x84')]=_0x58eb88[_0xe5d1('0x61')][_0xe5d1('0x85')];_0x1099bc['body'][_0xe5d1('0x61')]=_0x58eb88['body'][_0xe5d1('0x86')];_0x1099bc[_0xe5d1('0x61')][_0xe5d1('0x87')]=_0x58eb88[_0xe5d1('0x61')]['MessageSid'];break;case'skebby':_0x1099bc[_0xe5d1('0x61')]['from']='+'+_0x58eb88[_0xe5d1('0x61')][_0xe5d1('0x88')];_0x1099bc[_0xe5d1('0x61')][_0xe5d1('0x61')]=_0x58eb88['body'][_0xe5d1('0x89')];break;case _0xe5d1('0x8a'):_0x1099bc[_0xe5d1('0x61')][_0xe5d1('0x84')]=_0x58eb88[_0xe5d1('0x61')]['from'];_0x1099bc[_0xe5d1('0x61')][_0xe5d1('0x61')]=_0x58eb88[_0xe5d1('0x61')][_0xe5d1('0x28')];break;case _0xe5d1('0x8b'):_0x1099bc[_0xe5d1('0x61')][_0xe5d1('0x84')]=_0x58eb88['body'][_0xe5d1('0x84')];_0x1099bc[_0xe5d1('0x61')][_0xe5d1('0x61')]=_0x58eb88[_0xe5d1('0x61')][_0xe5d1('0x61')];_0x1099bc[_0xe5d1('0x61')][_0xe5d1('0x87')]=_0x58eb88['body'][_0xe5d1('0x8c')];break;case'plivo':_0x1099bc['body'][_0xe5d1('0x84')]=_0x58eb88[_0xe5d1('0x61')]['From'];_0x1099bc['body']['body']=_0x58eb88['body'][_0xe5d1('0x8d')];_0x1099bc['body'][_0xe5d1('0x87')]=_0x58eb88[_0xe5d1('0x61')][_0xe5d1('0x8e')];break;case _0xe5d1('0x8f'):_0x1099bc[_0xe5d1('0x61')][_0xe5d1('0x84')]='+'+_0x58eb88[_0xe5d1('0x61')][_0xe5d1('0x90')][0x0][_0xe5d1('0x84')];_0x1099bc[_0xe5d1('0x61')][_0xe5d1('0x61')]=_0x58eb88['body']['results'][0x0][_0xe5d1('0x89')];_0x1099bc[_0xe5d1('0x61')][_0xe5d1('0x87')]=_0x58eb88[_0xe5d1('0x61')][_0xe5d1('0x90')][0x0][_0xe5d1('0x87')];break;case _0xe5d1('0x91'):_0x1099bc[_0xe5d1('0x61')][_0xe5d1('0x84')]=_0x58eb88[_0xe5d1('0x61')]['originatingAddress'];_0x1099bc[_0xe5d1('0x61')][_0xe5d1('0x61')]=_0x58eb88[_0xe5d1('0x61')][_0xe5d1('0x92')][_0xe5d1('0x28')];break;case _0xe5d1('0x93'):_0x1099bc[_0xe5d1('0x61')][_0xe5d1('0x84')]=_0x58eb88['body'][_0xe5d1('0x94')];_0x1099bc['body'][_0xe5d1('0x61')]=_0x58eb88['body'][_0xe5d1('0x89')];_0x1099bc[_0xe5d1('0x61')][_0xe5d1('0x87')]=_0x58eb88['body']['replyMessageId'];break;case _0xe5d1('0x95'):_0x1099bc[_0xe5d1('0x61')][_0xe5d1('0x87')]=_0x58eb88[_0xe5d1('0x61')][0x0][_0xe5d1('0x28')]['id'];_0x1099bc['body'][_0xe5d1('0x84')]=_0x58eb88[_0xe5d1('0x61')][0x0]['message'][_0xe5d1('0x84')];_0x1099bc[_0xe5d1('0x61')][_0xe5d1('0x61')]=_0x58eb88['body'][0x0]['message'][_0xe5d1('0x89')];break;case _0xe5d1('0x96'):_0x1099bc['body'][_0xe5d1('0x84')]=_0x58eb88[_0xe5d1('0x61')][_0xe5d1('0x84')];_0x1099bc[_0xe5d1('0x61')][_0xe5d1('0x61')]=_0x58eb88[_0xe5d1('0x61')][_0xe5d1('0x28')];_0x1099bc[_0xe5d1('0x61')]['messageId']=_0x58eb88[_0xe5d1('0x61')][_0xe5d1('0x97')];break;}}if(_0x1099bc[_0xe5d1('0x61')]['id']){delete _0x1099bc[_0xe5d1('0x61')]['id'];}if(_[_0xe5d1('0x98')](_0x1099bc[_0xe5d1('0x61')][_0xe5d1('0x84')])){throw new db[(_0xe5d1('0x7b'))][(_0xe5d1('0x7c'))](_0xe5d1('0x99'));}if(_[_0xe5d1('0x98')](_0x1099bc[_0xe5d1('0x61')][_0xe5d1('0x61')])||_0x1099bc[_0xe5d1('0x61')]['body']===''){throw new db['Sequelize'][(_0xe5d1('0x7c'))](_0xe5d1('0x9a'));}if(_['isNil'](_0x1099bc[_0xe5d1('0x61')]['mapKey'])){throw new db['Sequelize']['ValidationError']('mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x2bbf9c);}if(!_[_0xe5d1('0x9b')](_0x2bbf9c,_0x1099bc[_0xe5d1('0x61')]['mapKey'])){throw new db[(_0xe5d1('0x7b'))][(_0xe5d1('0x7c'))](_0xe5d1('0x9c')+_0x2bbf9c);}_0x1f3372[_0x1099bc[_0xe5d1('0x61')][_0xe5d1('0x9d')]]=_0x1099bc[_0xe5d1('0x61')]['from'];return db['CmList'][_0xe5d1('0x5f')]({'where':{'id':_0x1099bc[_0xe5d1('0x79')][_0xe5d1('0x81')]},'include':[{'model':db[_0xe5d1('0x7a')],'as':'Contacts','where':_0x1f3372,'limit':0x1,'order':[['updatedAt','DESC']]}]});})['then'](handleEntityNotFound(_0x18c69d,null))[_0xe5d1('0x21')](function(_0x32466a){if(_0x32466a){_0x1099bc['list']=_[_0xe5d1('0x9e')](_0x32466a,[_0xe5d1('0x9f')]);if(_0x32466a[_0xe5d1('0x9f')]['length']){return _0x32466a[_0xe5d1('0x9f')][0x0];}var _0x5a5eba=_[_0xe5d1('0x19')](_0x1099bc[_0xe5d1('0x61')],{'firstName':_0x1099bc['body'][_0xe5d1('0x84')],'ListId':_0x32466a['id']});_0x5a5eba[_0x1099bc['body'][_0xe5d1('0x9d')]]=_0x1099bc['body'][_0xe5d1('0x84')];return db[_0xe5d1('0x7a')][_0xe5d1('0x60')](_0x5a5eba,{'fields':_0x4fde26,'raw':!![]});}})[_0xe5d1('0x21')](handleEntityNotFound(_0x18c69d,null))[_0xe5d1('0x21')](function(_0x2b6fec){if(_0x2b6fec){_0x1099bc['contact']=_0x2b6fec;var _0x5067f4={'ContactId':_0x2b6fec['id'],'phone':_0x1099bc[_0xe5d1('0x61')]['from'],'SmsAccountId':_0x58eb88[_0xe5d1('0x5d')]['id']};var _0x3705f6={'ContactId':_0x2b6fec['id'],'SmsAccountId':_0x58eb88[_0xe5d1('0x5d')]['id'],'closed':![]};return db[_0xe5d1('0xa0')][_0xe5d1('0x5f')]({'where':_0x3705f6})[_0xe5d1('0x21')](function(_0x4a8290){if(_0x4a8290){return[_0x4a8290,![]];}return db[_0xe5d1('0xa0')][_0xe5d1('0x60')](_0x5067f4)['then'](function(_0x232a1d){return[_0x232a1d,!![]];});});}})[_0xe5d1('0xa1')](function(_0x181e93,_0x2a8e23){_0x1099bc[_0xe5d1('0xa2')]=_0x181e93[_0xe5d1('0x3a')]({'plain':!![]});_0x1099bc[_0xe5d1('0xa2')][_0xe5d1('0xa3')]=![];if(_0x2a8e23){if(_0x1099bc[_0xe5d1('0x79')][_0xe5d1('0xa4')]){_0x1099bc[_0xe5d1('0xa5')][_0xe5d1('0xa6')]({'id':0x0,'priority':_0x1099bc['applications'][_0xe5d1('0x4e')]+0x1,'app':_0xe5d1('0xa7'),'appdata':'unmanaged','interval':_0xe5d1('0xa8')});}_0x1099bc['interaction']['created']=!![];}return db[_0xe5d1('0xa9')][_0xe5d1('0x60')]({'phone':_0x1099bc[_0xe5d1('0x61')][_0xe5d1('0x84')],'messageId':_0x1099bc[_0xe5d1('0x61')]['messageId'],'body':_0x1099bc[_0xe5d1('0x61')][_0xe5d1('0x61')],'SmsAccountId':_0x58eb88[_0xe5d1('0x5d')]['id'],'SmsInteractionId':_0x181e93['id'],'direction':'in','ContactId':_0x181e93[_0xe5d1('0xaa')],'AttachmentId':_0x1099bc[_0xe5d1('0x61')]['AttachmentId']});})['then'](function(_0x4dcf4d){_0x1099bc[_0xe5d1('0x28')]=_0x4dcf4d;if(!_0x1099bc[_0xe5d1('0xa2')][_0xe5d1('0xab')])return;return db[_0xe5d1('0xac')][_0xe5d1('0x5f')]({'attributes':['id',_0xe5d1('0x3e')],'where':{'id':_0x1099bc[_0xe5d1('0xa2')][_0xe5d1('0xab')]}});})[_0xe5d1('0x21')](function(_0x16e043){if(_0x16e043){_0x1099bc[_0xe5d1('0xa5')]['unshift']({'id':0x0,'priority':0x0,'app':_0xe5d1('0xad'),'appdata':_0x16e043[_0xe5d1('0x3e')]+','+(_0x1099bc[_0xe5d1('0x79')][_0xe5d1('0xae')]||0xa),'interval':_0xe5d1('0xa8')});}if(!_0x1099bc[_0xe5d1('0xa2')][_0xe5d1('0xaf')])return;return db[_0xe5d1('0xb0')][_0xe5d1('0x5f')]({'attributes':['id',_0xe5d1('0x3e')],'where':{'id':_0x1099bc[_0xe5d1('0xa2')]['queueId']}});})['then'](function(_0x5a029d){if(_0x5a029d){_0x1099bc[_0xe5d1('0xa5')][_0xe5d1('0xb1')]({'id':0x0,'priority':0x1,'app':'queue','appdata':_0x5a029d[_0xe5d1('0x3e')]+','+(_0x1099bc['account'][_0xe5d1('0xb2')]||0x12c),'interval':'*,*,*,*'});}return respondWithRpcPromise(_0xe5d1('0xb3'),_0xe5d1('0xb4'),_0x1099bc);})[_0xe5d1('0x21')](function(_0xe58949){if(_0xe58949){var _0x1f24dc=0xc8;var _0x37de3e=_0xe5d1('0xb5');logger['info'](_0xe5d1('0x23'),_0x37de3e,_0x1f24dc,_0xe5d1('0xb6'));logger[_0xe5d1('0x22')](_0xe5d1('0xb7'),_0x37de3e,_0x1f24dc,_0xe5d1('0xb6'),JSON['stringify'](_0xe58949));if(_0x1099bc['account'][_0xe5d1('0x45')]==='twilio'){return _0x18c69d[_0xe5d1('0x2d')](_0x1f24dc)[_0xe5d1('0x33')](_0xe5d1('0xb8'),'text/xml')['send']('<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>');}else{return _0x18c69d[_0xe5d1('0x2d')](_0x1f24dc)[_0xe5d1('0x2f')](_0xe58949);}}})[_0xe5d1('0x2b')](handleError(_0x18c69d,null));};exports['addApplications']=function(_0x2d8445,_0x496f3d){var _0x14fc02=_0x2d8445[_0xe5d1('0x5d')]['id'];var _0x5bc967=_0x2d8445[_0xe5d1('0x61')];var _0x564041=0xc8;var _0x496398=null;return db[_0xe5d1('0xb9')][_0xe5d1('0xba')]({'isolationLevel':db[_0xe5d1('0xb9')][_0xe5d1('0xbb')][_0xe5d1('0xbc')][_0xe5d1('0xbd')]},function(_0x7dcb55){return db[_0xe5d1('0x42')][_0xe5d1('0x6b')]({'where':{'id':_0x14fc02},'transaction':_0x7dcb55})[_0xe5d1('0x21')](function(_0x54d2e7){if(_0x54d2e7){return db[_0xe5d1('0x74')][_0xe5d1('0x39')]({'where':{'SmsAccountId':_0x14fc02},'transaction':_0x7dcb55})[_0xe5d1('0x21')](function(){var _0x1368e5=_[_0xe5d1('0x41')](_0x5bc967,function(_0x3f1971){_0x3f1971[_0xe5d1('0x69')]=_0x14fc02;return _0x3f1971;});return db[_0xe5d1('0x74')][_0xe5d1('0xbe')](_0x1368e5,{'transaction':_0x7dcb55});});}else{_0x564041=0x194;_0x496398=[];}});})[_0xe5d1('0x21')](function(){if(_0x564041!==0x194){return db[_0xe5d1('0x74')][_0xe5d1('0xbf')]({'where':{'SmsAccountId':_0x14fc02},'order':_0xe5d1('0x77')})[_0xe5d1('0x21')](function(_0x2c0e08){_0x496398=_0x2c0e08;});}})[_0xe5d1('0x2b')](function(_0x5af690){_0x564041=0x1f4;logger['error'](_0x5af690[_0xe5d1('0x3d')]);if(_0x5af690[_0xe5d1('0x3e')]){delete _0x5af690[_0xe5d1('0x3e')];}_0x496398=_0x5af690;})[_0xe5d1('0xc0')](function(){if(_0x496398===null){_0x496f3d[_0xe5d1('0x2c')](_0x564041);}else{if(_0x564041===0x1f4){_0x496f3d[_0xe5d1('0x2d')](_0x564041)[_0xe5d1('0xc1')](_0x496398);}else{_0x496f3d['status'](_0x564041)[_0xe5d1('0x2f')](_0x496398);}}});};exports['getApplications']=function(_0x50b0d5,_0x11fbf0,_0x34b98a){var _0x7b45bc={};var _0x9c0821={};var _0x2a0bad;var _0x5c09f0;return db[_0xe5d1('0x42')][_0xe5d1('0x6b')]({'where':{'id':_0x50b0d5['params']['id']}})[_0xe5d1('0x21')](handleEntityNotFound(_0x11fbf0,null))[_0xe5d1('0x21')](function(_0x40ba49){if(_0x40ba49){_0x2a0bad=_0x40ba49;_0x9c0821['model']=_[_0xe5d1('0x48')](db[_0xe5d1('0x74')][_0xe5d1('0x43')]);_0x9c0821['query']=_[_0xe5d1('0x48')](_0x50b0d5[_0xe5d1('0x49')]);_0x9c0821[_0xe5d1('0x4a')]=_[_0xe5d1('0x4b')](_0x9c0821['model'],_0x9c0821[_0xe5d1('0x49')]);_0x7b45bc[_0xe5d1('0x4c')]=_[_0xe5d1('0x4b')](_0x9c0821[_0xe5d1('0x47')],qs[_0xe5d1('0x4d')](_0x50b0d5[_0xe5d1('0x49')][_0xe5d1('0x4d')]));_0x7b45bc[_0xe5d1('0x4c')]=_0x7b45bc['attributes'][_0xe5d1('0x4e')]?_0x7b45bc[_0xe5d1('0x4c')]:_0x9c0821[_0xe5d1('0x47')];_0x7b45bc[_0xe5d1('0x51')]=qs[_0xe5d1('0x52')](_0x50b0d5[_0xe5d1('0x49')][_0xe5d1('0x52')]);_0x7b45bc['where']=qs[_0xe5d1('0x4a')](_['pick'](_0x50b0d5['query'],_0x9c0821['filters']));if(_0x50b0d5[_0xe5d1('0x49')][_0xe5d1('0x54')]){_0x7b45bc[_0xe5d1('0x55')]=_[_0xe5d1('0x57')](_0x7b45bc[_0xe5d1('0x55')],{'$or':_['map'](_0x7b45bc[_0xe5d1('0x4c')],function(_0x1b3d8b){var _0x5952bf={};_0x5952bf[_0x1b3d8b]={'$like':'%'+_0x50b0d5[_0xe5d1('0x49')][_0xe5d1('0x54')]+'%'};return _0x5952bf;})});}_0x7b45bc=_[_0xe5d1('0x57')]({},_0x7b45bc,_0x50b0d5['options']);return _0x2a0bad['getApplications'](_0x7b45bc);}})[_0xe5d1('0x21')](function(_0x630437){if(_0x630437){_0x5c09f0=_0x630437[_0xe5d1('0x4e')];if(!_0x50b0d5[_0xe5d1('0x49')]['hasOwnProperty']('nolimit')){_0x7b45bc[_0xe5d1('0x32')]=qs[_0xe5d1('0x32')](_0x50b0d5[_0xe5d1('0x49')][_0xe5d1('0x32')]);_0x7b45bc[_0xe5d1('0x30')]=qs[_0xe5d1('0x30')](_0x50b0d5['query'][_0xe5d1('0x30')]);}return _0x2a0bad['getApplications'](_0x7b45bc);}})[_0xe5d1('0x21')](function(_0x4acff0){if(_0x4acff0){return _0x4acff0?{'count':_0x5c09f0,'rows':_0x4acff0}:null;}})[_0xe5d1('0x21')](respondWithResult(_0x11fbf0,null))[_0xe5d1('0x2b')](handleError(_0x11fbf0,null));};exports[_0xe5d1('0xc2')]=function(_0x54245c,_0x1374ac,_0x333b7b){var _0x207648={'raw':![],'where':{}};var _0x175658={};var _0x43a7e6={'count':0x0,'rows':[]};return db[_0xe5d1('0x42')][_0xe5d1('0x6b')]({'where':{'id':_0x54245c['params']['id']}})[_0xe5d1('0x21')](handleEntityNotFound(_0x1374ac,null))[_0xe5d1('0x21')](function(_0x5ee939){if(_0x5ee939){_0x175658[_0xe5d1('0x47')]=_[_0xe5d1('0x48')](db[_0xe5d1('0xa0')]['rawAttributes']);_0x175658['query']=_[_0xe5d1('0x48')](_0x54245c[_0xe5d1('0x49')]);_0x175658['filters']=_[_0xe5d1('0x4b')](_0x175658['model'],_0x175658[_0xe5d1('0x49')]);_0x207648[_0xe5d1('0x4c')]=_[_0xe5d1('0x4b')](_0x175658[_0xe5d1('0x47')],qs[_0xe5d1('0x4d')](_0x54245c[_0xe5d1('0x49')][_0xe5d1('0x4d')]));_0x207648[_0xe5d1('0x4c')]=_0x207648['attributes'][_0xe5d1('0x4e')]?_0x207648[_0xe5d1('0x4c')]:_0x175658[_0xe5d1('0x47')];if(!_0x54245c[_0xe5d1('0x49')][_0xe5d1('0x4f')](_0xe5d1('0x50'))){_0x207648['limit']=qs[_0xe5d1('0x32')](_0x54245c[_0xe5d1('0x49')]['limit']);_0x207648['offset']=qs[_0xe5d1('0x30')](_0x54245c['query'][_0xe5d1('0x30')]);}_0x207648[_0xe5d1('0x51')]=qs[_0xe5d1('0x52')](_0x54245c[_0xe5d1('0x49')][_0xe5d1('0x52')]);_0x207648[_0xe5d1('0x55')]=qs[_0xe5d1('0x4a')](_[_0xe5d1('0x53')](_0x54245c[_0xe5d1('0x49')],_0x175658[_0xe5d1('0x4a')]));_0x207648['where'][_0xe5d1('0x69')]=_0x5ee939['id'];if(_0x54245c['query'][_0xe5d1('0x54')]){_0x207648[_0xe5d1('0x55')]=_[_0xe5d1('0x57')](_0x207648['where'],{'$or':_[_0xe5d1('0x41')](_0x207648[_0xe5d1('0x4c')],function(_0xe75366){var _0x95cb31={};_0x95cb31[_0xe75366]={'$like':'%'+_0x54245c['query'][_0xe5d1('0x54')]+'%'};return _0x95cb31;})});}_0x207648=_[_0xe5d1('0x57')]({},_0x207648,_0x54245c[_0xe5d1('0x5e')]);return db['SmsInteraction'][_0xe5d1('0x58')]({'where':_0x207648[_0xe5d1('0x55')]})['then'](function(_0x33837b){_0x43a7e6[_0xe5d1('0x58')]=_0x33837b;if(_0x54245c[_0xe5d1('0x49')][_0xe5d1('0x59')]){_0x207648[_0xe5d1('0x5a')]=[{'model':db[_0xe5d1('0x7a')],'as':_0xe5d1('0xc3'),'required':![]},{'model':db[_0xe5d1('0xac')],'as':_0xe5d1('0xc4'),'attributes':[_0xe5d1('0x3e'),_0xe5d1('0xc5'),'internal'],'required':![]},{'model':db[_0xe5d1('0xc6')],'as':_0xe5d1('0xc7'),'attributes':['id',_0xe5d1('0x3e'),_0xe5d1('0xc8')],'where':_0x54245c[_0xe5d1('0x49')][_0xe5d1('0xc9')]?{'id':_0x54245c[_0xe5d1('0x49')][_0xe5d1('0xc9')]}:undefined,'required':_0x54245c[_0xe5d1('0x49')][_0xe5d1('0xc9')]?!![]:![]}];}return db[_0xe5d1('0xa0')][_0xe5d1('0x5b')](_0x207648);})[_0xe5d1('0x21')](function(_0x3e8f39){_0x43a7e6[_0xe5d1('0x5c')]=_0x3e8f39;return _0x43a7e6;});}})['then'](respondWithFilteredResult(_0x1374ac,_0x207648))[_0xe5d1('0x2b')](handleError(_0x1374ac,null));};exports['send']=function(_0x1adeec,_0x10f986,_0x2a0c91){var _0xc17d7a,_0x2826c6,_0x446269;if(_[_0xe5d1('0x98')](_0x1adeec[_0xe5d1('0x61')][_0xe5d1('0x61')])||_0x1adeec['body'][_0xe5d1('0x61')]===''){throw new db[(_0xe5d1('0x7b'))][(_0xe5d1('0x7c'))](_0xe5d1('0x9a'));}if(_[_0xe5d1('0x98')](_0x1adeec['body']['to'])){throw new db[(_0xe5d1('0x7b'))][(_0xe5d1('0x7c'))](_0xe5d1('0xca'));}_0xc17d7a=_0x1adeec[_0xe5d1('0x61')]['to'];return db[_0xe5d1('0x42')][_0xe5d1('0x5f')]({'where':{'id':_0x1adeec['params']['id']},'include':[{'model':db[_0xe5d1('0xcb')],'as':'List','include':[{'model':db[_0xe5d1('0x7a')],'as':'Contacts','where':{'mobile':_0xc17d7a},'limit':0x1,'order':[[_0xe5d1('0x7f'),_0xe5d1('0xcc')]]}]}]})[_0xe5d1('0x21')](handleEntityNotFound(_0x10f986,null))['then'](function(_0x255b76){if(_0x255b76&&_0x255b76[_0xe5d1('0xcd')]){_0x2826c6=_0x255b76[_0xe5d1('0x3a')]({'plain':!![]});if(_0x2826c6['List']&&_0x2826c6[_0xe5d1('0xcd')][_0xe5d1('0x9f')][_0xe5d1('0x4e')]){return _0x2826c6[_0xe5d1('0xcd')][_0xe5d1('0x9f')][0x0];}return db[_0xe5d1('0x7a')]['create'](_[_0xe5d1('0x19')](_0x1adeec[_0xe5d1('0x61')],{'firstName':_0xc17d7a,'mobile':_0xc17d7a,'phone':_0xc17d7a,'ListId':_0x2826c6[_0xe5d1('0x81')]}));}})[_0xe5d1('0x21')](handleEntityNotFound(_0x10f986,null))[_0xe5d1('0x21')](function(_0x1cac1a){if(_0x1cac1a){_0x446269=_0x1cac1a;return db[_0xe5d1('0xa0')][_0xe5d1('0x5f')]({'where':{'ContactId':_0x446269['id'],'closed':![],'SmsAccountId':_0x2826c6['id']}})[_0xe5d1('0x21')](function(_0x5e943f){if(_0x5e943f){return[_0x5e943f,![]];}return db[_0xe5d1('0xa0')][_0xe5d1('0x60')]({'UserId':_0x1adeec[_0xe5d1('0x62')]['id'],'ContactId':_0x446269['id'],'SmsAccountId':_0x2826c6['id'],'phone':_0xc17d7a,'firstMsgDirection':_0xe5d1('0xce'),'Messages':[_[_0xe5d1('0x57')](_0x1adeec[_0xe5d1('0x61')],{'read':![],'body':_0x1adeec[_0xe5d1('0x61')][_0xe5d1('0x61')],'phone':_0xc17d7a,'SmsAccountId':_0x2826c6['id'],'UserId':_0x1adeec[_0xe5d1('0x62')]['id'],'ContactId':_0x446269['id']})]},{'include':[{'model':db['SmsMessage'],'as':'Messages'}]})[_0xe5d1('0x21')](function(_0x5b3b17){return[_0x5b3b17,!![]];});});}})['spread'](function(_0xefa135,_0x159a23){if(_0x159a23){return _0xefa135;}return db['SmsMessage']['create'](_[_0xe5d1('0x57')](_0x1adeec['body'],{'read':![],'body':_0x1adeec[_0xe5d1('0x61')][_0xe5d1('0x61')],'phone':_0xc17d7a,'SmsAccountId':_0x2826c6['id'],'SmsInteractionId':_0xefa135['id'],'UserId':_0x1adeec[_0xe5d1('0x62')]['id'],'ContactId':_0x446269['id']}))[_0xe5d1('0x21')](function(_0x38c548){_0xefa135[_0xe5d1('0xcf')][_0xe5d1('0xd0')]=[];_0xefa135[_0xe5d1('0xcf')]['Messages'][_0xe5d1('0xa6')](_0x38c548[_0xe5d1('0xcf')]);return _0xefa135;});})[_0xe5d1('0x21')](respondWithResult(_0x10f986,null))['catch'](handleError(_0x10f986,null));};exports[_0xe5d1('0x2d')]=function(_0x5aa8cc,_0x3efec3,_0x312d0a){if(_0x5aa8cc['body']['id']){delete _0x5aa8cc['body']['id'];}var _0x5be0e6,_0x9dcd3a,_0x486643;return db[_0xe5d1('0x42')][_0xe5d1('0x5f')]({'where':{'id':_0x5aa8cc['params']['id']}})[_0xe5d1('0x21')](handleEntityNotFound(_0x3efec3,null))['then'](function(_0x2e2ef7){if(_0x2e2ef7){_0x486643=_0x2e2ef7;logger[_0xe5d1('0x22')](_0xe5d1('0x23'),'status','received\x20delivery\x20report\x20from',_0x2e2ef7[_0xe5d1('0x45')],util[_0xe5d1('0xd1')](_0x5aa8cc['body'],{'showHidden':![],'depth':null}));switch(_0x2e2ef7[_0xe5d1('0x45')]){case _0xe5d1('0xd2'):if(_0x5aa8cc[_0xe5d1('0x61')][_0xe5d1('0xd3')]&&_0x5aa8cc['body'][_0xe5d1('0x2d')]){_0x9dcd3a=_0x5aa8cc[_0xe5d1('0x61')][_0xe5d1('0x2d')];return db[_0xe5d1('0xa9')][_0xe5d1('0x5f')]({'where':{'messageId':_0x5aa8cc[_0xe5d1('0x61')][_0xe5d1('0xd3')]}});}break;case _0xe5d1('0x8a'):if(_0x5aa8cc[_0xe5d1('0x61')][_0xe5d1('0xd4')]&&_0x5aa8cc[_0xe5d1('0x61')][_0xe5d1('0xd5')]){_0x9dcd3a=_0x5aa8cc['body']['statusInt'];return db[_0xe5d1('0xa9')][_0xe5d1('0x5f')]({'where':{'messageId':_0x5aa8cc[_0xe5d1('0x61')][_0xe5d1('0xd4')]}});}break;case'clicksend':if(_0x5aa8cc[_0xe5d1('0x61')][_0xe5d1('0x8c')]&&_0x5aa8cc['body']['status_code']){_0x9dcd3a=_0x5aa8cc[_0xe5d1('0x61')][_0xe5d1('0xd6')];return db[_0xe5d1('0xa9')]['find']({'where':{'messageId':_0x5aa8cc[_0xe5d1('0x61')][_0xe5d1('0x8c')]}});}break;case _0xe5d1('0x8f'):var _0x4f0ed0=_0x5aa8cc[_0xe5d1('0x61')][_0xe5d1('0x90')][0x0];if(_0x4f0ed0[_0xe5d1('0x87')]&&_0x4f0ed0['status'][_0xe5d1('0xd7')]==='DELIVERED'){_0x9dcd3a=_0x4f0ed0[_0xe5d1('0x2d')][_0xe5d1('0xd7')];return db[_0xe5d1('0xa9')]['find']({'where':{'messageId':_0x4f0ed0[_0xe5d1('0x87')]}});}break;case _0xe5d1('0x93'):if(_0x5aa8cc[_0xe5d1('0x61')][_0xe5d1('0x87')]&&_0x5aa8cc[_0xe5d1('0x61')]['status']){_0x9dcd3a=_0x5aa8cc[_0xe5d1('0x61')][_0xe5d1('0x2d')];return db['SmsMessage'][_0xe5d1('0x5f')]({'where':{'messageId':_0x5aa8cc['body'][_0xe5d1('0x87')]}});}break;case'bandwidth':if(_0x5aa8cc[_0xe5d1('0x61')][0x0]['message']['id']){_0x9dcd3a=_0x5aa8cc[_0xe5d1('0x61')][0x0]['type'];return db[_0xe5d1('0xa9')][_0xe5d1('0x5f')]({'where':{'messageId':_0x5aa8cc[_0xe5d1('0x61')][0x0][_0xe5d1('0x28')]['id']}});}break;case _0xe5d1('0x96'):if(_0x5aa8cc[_0xe5d1('0x61')]['redif']&&_0x5aa8cc[_0xe5d1('0x61')][_0xe5d1('0x2d')]){_0x9dcd3a=_0x5aa8cc[_0xe5d1('0x61')][_0xe5d1('0x2d')];return db[_0xe5d1('0xa9')]['find']({'where':{'messageId':_0x5aa8cc[_0xe5d1('0x61')]['redif']}});}break;}}})[_0xe5d1('0x21')](handleEntityNotFound(_0x3efec3,null))[_0xe5d1('0x21')](function(_0x166450){if(_0x166450){_0x5be0e6=_0x166450;switch(_0x486643[_0xe5d1('0x45')]){case _0xe5d1('0xd2'):if(_0x9dcd3a==='DELIVERED'){return _0x5be0e6['update']({'read':!![]});}else{logger['error'](_0xe5d1('0x23'),_0xe5d1('0x2d'),_0xe5d1('0xd2'),util[_0xe5d1('0xd1')](_0x5aa8cc[_0xe5d1('0x61')],{'showHidden':![],'depth':null}));}break;case _0xe5d1('0x8a'):if(_0x9dcd3a==='1'){return _0x5be0e6['update']({'read':!![]});}else{logger[_0xe5d1('0x26')](_0xe5d1('0x23'),_0xe5d1('0x2d'),_0xe5d1('0xd2'),util['inspect'](_0x5aa8cc[_0xe5d1('0x61')],{'showHidden':![],'depth':null}));}break;case _0xe5d1('0x8b'):if(!_0x5aa8cc[_0xe5d1('0x61')][_0xe5d1('0xd8')]&&_0x9dcd3a>=0xc8&&_0x9dcd3a<=0xce){return _0x5be0e6[_0xe5d1('0x38')]({'read':!![]});}else{logger[_0xe5d1('0x26')](_0xe5d1('0x23'),_0xe5d1('0x2d'),_0xe5d1('0x8b'),util['inspect'](_0x5aa8cc[_0xe5d1('0x61')],{'showHidden':![],'depth':null}));}break;case _0xe5d1('0x8f'):var _0x4fb536=_0x5aa8cc['body'][_0xe5d1('0x90')][0x0];if(_0x4fb536['status'][_0xe5d1('0xd7')]===_0xe5d1('0xd9')){return _0x5be0e6[_0xe5d1('0x38')]({'read':!![]});}else{logger[_0xe5d1('0x26')](_0xe5d1('0x23'),_0xe5d1('0x2d'),_0xe5d1('0x8f'),util[_0xe5d1('0xd1')](_0x5aa8cc[_0xe5d1('0x61')],{'showHidden':![],'depth':null}));}break;case _0xe5d1('0x93'):if(_0x9dcd3a==_0xe5d1('0xda')||_0x9dcd3a==_0xe5d1('0xdb')){return _0x5be0e6[_0xe5d1('0x38')]({'read':!![]});}else{logger[_0xe5d1('0x26')](_0xe5d1('0x23'),'status','clickatell',util['inspect'](_0x5aa8cc[_0xe5d1('0x61')],{'showHidden':![],'depth':null}));}break;case _0xe5d1('0x95'):if(_0x9dcd3a==_0xe5d1('0xdc')){return _0x5be0e6['update']({'read':!![]});}else{logger[_0xe5d1('0x26')](_0xe5d1('0x23'),_0xe5d1('0x2d'),_0xe5d1('0x95'),util[_0xe5d1('0xd1')](_0x5aa8cc[_0xe5d1('0x61')],{'showHidden':![],'depth':null}));}break;case _0xe5d1('0x96'):if(_0x9dcd3a===_0xe5d1('0xdd')||_0x9dcd3a==='ACCEPTD'){return _0x5be0e6['update']({'read':!![]});}else{logger[_0xe5d1('0x26')]('SmsAccount,\x20%s,\x20%s,\x20%s',_0xe5d1('0x2d'),_0xe5d1('0x96'),util[_0xe5d1('0xd1')](_0x5aa8cc[_0xe5d1('0x61')],{'showHidden':![],'depth':null}));}break;}return _0x5be0e6;}})['then'](respondWithResult(_0x3efec3,null))[_0xe5d1('0x2b')](handleError(_0x3efec3,null));};exports[_0xe5d1('0xde')]=function(_0x48fa02,_0x3cbe66,_0x5aa1ba){var _0x476608,_0x5d5e45,_0x293662;return db[_0xe5d1('0x42')][_0xe5d1('0x5f')]({'where':{'id':_0x48fa02[_0xe5d1('0x5d')]['id']}})[_0xe5d1('0x21')](handleEntityNotFound(_0x3cbe66,null))[_0xe5d1('0x21')](function(_0x534ccc){if(_0x534ccc){_0x293662=_0x534ccc;logger[_0xe5d1('0x22')](_0xe5d1('0x23'),_0xe5d1('0x2d'),'received\x20delivery\x20report\x20from',_0x534ccc[_0xe5d1('0x45')],util['inspect'](_0x48fa02[_0xe5d1('0x49')],{'showHidden':![],'depth':null}));switch(_0x534ccc[_0xe5d1('0x45')]){case _0xe5d1('0x91'):if(_0x48fa02['query'][_0xe5d1('0xdf')]&&_0x48fa02[_0xe5d1('0x49')][_0xe5d1('0xe0')]){_0x5d5e45=_0x48fa02['query'][_0xe5d1('0xe0')];return db[_0xe5d1('0xa9')]['find']({'where':{'messageId':_0x48fa02[_0xe5d1('0x49')][_0xe5d1('0xdf')]}});}break;}}})[_0xe5d1('0x21')](handleEntityNotFound(_0x3cbe66,null))[_0xe5d1('0x21')](function(_0x4af7b3){if(_0x4af7b3){_0x476608=_0x4af7b3;switch(_0x293662['type']){case _0xe5d1('0x91'):if(_0x5d5e45==='2'||_0x5d5e45==='6'){return _0x476608[_0xe5d1('0x38')]({'read':!![]});}else{logger[_0xe5d1('0x26')](_0xe5d1('0x23'),_0xe5d1('0x2d'),_0xe5d1('0x91'),util[_0xe5d1('0xd1')](_0x48fa02['query'],{'showHidden':![],'depth':null}));};break;}return _0x476608;}})[_0xe5d1('0x21')](respondWithResult(_0x3cbe66,null))[_0xe5d1('0x2b')](handleError(_0x3cbe66,null));};exports[_0xe5d1('0xe1')]=function(_0x252eb9,_0x586ae6,_0xf54be2){return db[_0xe5d1('0x42')][_0xe5d1('0x5f')]({'where':{'id':_0x252eb9[_0xe5d1('0x5d')]['id']}})[_0xe5d1('0x21')](handleEntityNotFound(_0x586ae6,null))[_0xe5d1('0x21')](function(_0x4a34e0){if(_0x4a34e0){return _0x4a34e0[_0xe5d1('0xe1')](_0x252eb9[_0xe5d1('0x61')][_0xe5d1('0x6e')],_[_0xe5d1('0x9e')](_0x252eb9['body'],[_0xe5d1('0x6e'),'id'])||{})[_0xe5d1('0xa1')](function(_0x3e05b1){for(var _0x376290=0x0;_0x376290<_0x252eb9[_0xe5d1('0x61')]['ids'][_0xe5d1('0x4e')];_0x376290+=0x1){socket[_0xe5d1('0xe2')](_0xe5d1('0xe3'),{'UserId':Number(_0x252eb9[_0xe5d1('0x61')][_0xe5d1('0x6e')][_0x376290]),'SmsAccountId':Number(_0x252eb9[_0xe5d1('0x5d')]['id'])});}return _0x3e05b1;});}})[_0xe5d1('0x21')](respondWithResult(_0x586ae6,null))[_0xe5d1('0x2b')](handleError(_0x586ae6,null));};exports[_0xe5d1('0xe4')]=function(_0x2b3d0b,_0x4c5e4a,_0x5c5f4b){return db[_0xe5d1('0x42')][_0xe5d1('0x5f')]({'where':{'id':_0x2b3d0b[_0xe5d1('0x5d')]['id']}})['then'](handleEntityNotFound(_0x4c5e4a,null))[_0xe5d1('0x21')](function(_0x38ed51){if(_0x38ed51){return _0x38ed51[_0xe5d1('0xe4')](_0x2b3d0b['query'][_0xe5d1('0x6e')])[_0xe5d1('0x21')](function(){if(_['isArray'](_0x2b3d0b[_0xe5d1('0x49')][_0xe5d1('0x6e')])){for(var _0x719326=0x0;_0x719326<_0x2b3d0b[_0xe5d1('0x49')][_0xe5d1('0x6e')][_0xe5d1('0x4e')];_0x719326+=0x1){socket[_0xe5d1('0xe2')](_0xe5d1('0xe5'),{'UserId':Number(_0x2b3d0b['query'][_0xe5d1('0x6e')][_0x719326]),'SmsAccountId':Number(_0x2b3d0b[_0xe5d1('0x5d')]['id'])});}}else{socket['emit'](_0xe5d1('0xe5'),{'UserId':Number(_0x2b3d0b[_0xe5d1('0x49')][_0xe5d1('0x6e')]),'SmsAccountId':Number(_0x2b3d0b[_0xe5d1('0x5d')]['id'])});}});}})['then'](respondWithStatusCode(_0x4c5e4a,null))[_0xe5d1('0x2b')](handleError(_0x4c5e4a,null));};exports[_0xe5d1('0xe6')]=function(_0x24bd76,_0x39e45f,_0x562853){var _0x5ee82c={};var _0x17fae3={};var _0x39f9c0;var _0x345569;return db[_0xe5d1('0x42')][_0xe5d1('0x6b')]({'where':{'id':_0x24bd76[_0xe5d1('0x5d')]['id']}})['then'](handleEntityNotFound(_0x39e45f,null))[_0xe5d1('0x21')](function(_0x1a796c){if(_0x1a796c){_0x39f9c0=_0x1a796c;_0x17fae3[_0xe5d1('0x47')]=_[_0xe5d1('0x48')](db[_0xe5d1('0xac')][_0xe5d1('0x43')]);_0x17fae3[_0xe5d1('0x49')]=_[_0xe5d1('0x48')](_0x24bd76[_0xe5d1('0x49')]);_0x17fae3[_0xe5d1('0x4a')]=_[_0xe5d1('0x4b')](_0x17fae3['model'],_0x17fae3[_0xe5d1('0x49')]);_0x5ee82c[_0xe5d1('0x4c')]=_[_0xe5d1('0x4b')](_0x17fae3[_0xe5d1('0x47')],qs[_0xe5d1('0x4d')](_0x24bd76[_0xe5d1('0x49')][_0xe5d1('0x4d')]));_0x5ee82c[_0xe5d1('0x4c')]=_0x5ee82c[_0xe5d1('0x4c')][_0xe5d1('0x4e')]?_0x5ee82c[_0xe5d1('0x4c')]:_0x17fae3[_0xe5d1('0x47')];_0x5ee82c[_0xe5d1('0x51')]=qs[_0xe5d1('0x52')](_0x24bd76['query'][_0xe5d1('0x52')]);_0x5ee82c[_0xe5d1('0x55')]=qs[_0xe5d1('0x4a')](_[_0xe5d1('0x53')](_0x24bd76['query'],_0x17fae3[_0xe5d1('0x4a')]));if(_0x24bd76['query'][_0xe5d1('0x54')]){_0x5ee82c[_0xe5d1('0x55')]=_['merge'](_0x5ee82c[_0xe5d1('0x55')],{'$or':_[_0xe5d1('0x41')](_0x5ee82c[_0xe5d1('0x4c')],function(_0x18c50f){var _0x2324a2={};_0x2324a2[_0x18c50f]={'$like':'%'+_0x24bd76[_0xe5d1('0x49')][_0xe5d1('0x54')]+'%'};return _0x2324a2;})});}_0x5ee82c=_[_0xe5d1('0x57')]({},_0x5ee82c,_0x24bd76[_0xe5d1('0x5e')]);return _0x39f9c0[_0xe5d1('0xe6')](_0x5ee82c);}})[_0xe5d1('0x21')](function(_0x25b020){if(_0x25b020){_0x345569=_0x25b020[_0xe5d1('0x4e')];if(!_0x24bd76[_0xe5d1('0x49')][_0xe5d1('0x4f')](_0xe5d1('0x50'))){_0x5ee82c['limit']=qs['limit'](_0x24bd76[_0xe5d1('0x49')]['limit']);_0x5ee82c[_0xe5d1('0x30')]=qs['offset'](_0x24bd76[_0xe5d1('0x49')][_0xe5d1('0x30')]);}return _0x39f9c0[_0xe5d1('0xe6')](_0x5ee82c);}})[_0xe5d1('0x21')](function(_0xba8b31){if(_0xba8b31){return _0xba8b31?{'count':_0x345569,'rows':_0xba8b31}:null;}})[_0xe5d1('0x21')](respondWithResult(_0x39e45f,null))[_0xe5d1('0x2b')](handleError(_0x39e45f,null));};