Built motion from commit 14588770.|2.5.38
[motion2.git] / server / api / openchannelMessage / openchannelMessage.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 _0xf375=['read1stAt','interaction','[OPENCHANNELMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','AcceptMessage','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','sequelize','Sequelize','QueryTypes','SELECT','contact','User','fullname','internal','manual','channel','motionChannel','event','EventManager','acceptmessage','openchannel','OpenchannelInteraction','OpenchannelInteractionId','stringify','null','RejectMessage','email','interface','rejectmessage','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','jsforce','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','defaults','redis','localhost','socket.io-emitter','register','jayson/promise','client','http','request','then','info','OpenchannelMessage,\x20%s,\x20%s','debug','request\x20sent','error','message','result','catch','sendStatus','json','offset','undefined','count','limit','status','set','Content-Range','apply','reject','save','update','destroy','end','stack','name','send','index','map','OpenchannelMessage','rawAttributes','fieldName','type','key','model','query','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','sort','where','filter','merge','includeAll','include','findAll','rows','show','params','keys','find','create','body','describe','accept','read','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','user','agent','get','isNil'];(function(_0x7ab7c2,_0x314efb){var _0x74ee2a=function(_0x4bc70b){while(--_0x4bc70b){_0x7ab7c2['push'](_0x7ab7c2['shift']());}};_0x74ee2a(++_0x314efb);}(_0xf375,0x19f));var _0x5f37=function(_0x432682,_0x253044){_0x432682=_0x432682-0x0;var _0x463d05=_0xf375[_0x432682];return _0x463d05;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x5f37('0x0'));var rp=require(_0x5f37('0x1'));var moment=require(_0x5f37('0x2'));var BPromise=require(_0x5f37('0x3'));var Mustache=require(_0x5f37('0x4'));var util=require(_0x5f37('0x5'));var path=require(_0x5f37('0x6'));var sox=require(_0x5f37('0x7'));var csv=require(_0x5f37('0x8'));var ejs=require(_0x5f37('0x9'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x5f37('0xa'));var deskjs=require('desk.js');var toCsv=require(_0x5f37('0x8'));var querystring=require('querystring');var Papa=require(_0x5f37('0xb'));var Redis=require(_0x5f37('0xc'));var authService=require(_0x5f37('0xd'));var qs=require(_0x5f37('0xe'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x5f37('0xf'));var logger=require('../../config/logger')(_0x5f37('0x10'));var utils=require(_0x5f37('0x11'));var config=require(_0x5f37('0x12'));var licenseUtil=require(_0x5f37('0x13'));var db=require('../../mysqldb')['db'];config['redis']=_[_0x5f37('0x14')](config[_0x5f37('0x15')],{'host':_0x5f37('0x16'),'port':0x18eb});var socket=require(_0x5f37('0x17'))(new Redis(config['redis']));require('./openchannelMessage.socket')[_0x5f37('0x18')](socket);var jayson=require(_0x5f37('0x19'));var client=jayson[_0x5f37('0x1a')][_0x5f37('0x1b')]({'port':0x232c});var client9002=jayson[_0x5f37('0x1a')][_0x5f37('0x1b')]({'port':0x232a});function respondWithRpcPromise(_0x38e605,_0x3743be,_0x5ed808,_0x338933){return new BPromise(function(_0x698b46,_0x2c13ff){var _0x55c64c=_0x338933||client;return _0x55c64c[_0x5f37('0x1c')](_0x38e605,_0x5ed808)[_0x5f37('0x1d')](function(_0x926c1e){logger[_0x5f37('0x1e')](_0x5f37('0x1f'),_0x3743be,'request\x20sent');logger[_0x5f37('0x20')]('OpenchannelMessage,\x20%s,\x20%s,\x20%s',_0x3743be,_0x5f37('0x21'),JSON['stringify'](_0x926c1e));if(_0x926c1e[_0x5f37('0x22')]){if(_0x926c1e[_0x5f37('0x22')]['code']===0x1f4){logger[_0x5f37('0x22')](_0x5f37('0x1f'),_0x3743be,_0x926c1e[_0x5f37('0x22')][_0x5f37('0x23')]);return _0x2c13ff(_0x926c1e[_0x5f37('0x22')][_0x5f37('0x23')]);}logger[_0x5f37('0x22')](_0x5f37('0x1f'),_0x3743be,_0x926c1e[_0x5f37('0x22')][_0x5f37('0x23')]);return _0x698b46(_0x926c1e[_0x5f37('0x22')][_0x5f37('0x23')]);}else{logger[_0x5f37('0x1e')](_0x5f37('0x1f'),_0x3743be,'request\x20sent');_0x698b46(_0x926c1e[_0x5f37('0x24')][_0x5f37('0x23')]);}})[_0x5f37('0x25')](function(_0x15f90e){logger['error']('OpenchannelMessage,\x20%s,\x20%s',_0x3743be,_0x15f90e);_0x2c13ff(_0x15f90e);});});}function respondWithStatusCode(_0x47aa25,_0x4f5bdc){_0x4f5bdc=_0x4f5bdc||0xcc;return function(_0x190c48){if(_0x190c48){return _0x47aa25[_0x5f37('0x26')](_0x4f5bdc);}return _0x47aa25['status'](_0x4f5bdc)['end']();};}function respondWithResult(_0x4f8510,_0x4ec974){_0x4ec974=_0x4ec974||0xc8;return function(_0x30faf1){if(_0x30faf1){return _0x4f8510['status'](_0x4ec974)[_0x5f37('0x27')](_0x30faf1);}};}function respondWithFilteredResult(_0x5468ba,_0x193bfc){return function(_0x3133a5){if(_0x3133a5){var _0x343b76=typeof _0x193bfc[_0x5f37('0x28')]===_0x5f37('0x29')&&typeof _0x193bfc['limit']==='undefined';var _0x4bd717=_0x3133a5['count'];var _0x4d6713=_0x343b76?0x0:_0x193bfc['offset'];var _0x271e22=_0x343b76?_0x3133a5[_0x5f37('0x2a')]:_0x193bfc[_0x5f37('0x28')]+_0x193bfc[_0x5f37('0x2b')];var _0x53d666;if(_0x271e22>=_0x4bd717){_0x271e22=_0x4bd717;_0x53d666=0xc8;}else{_0x53d666=0xce;}_0x5468ba[_0x5f37('0x2c')](_0x53d666);return _0x5468ba[_0x5f37('0x2d')](_0x5f37('0x2e'),_0x4d6713+'-'+_0x271e22+'/'+_0x4bd717)[_0x5f37('0x27')](_0x3133a5);}return null;};}function patchUpdates(_0x53f1f2){return function(_0x1cc09a){try{jsonpatch[_0x5f37('0x2f')](_0x1cc09a,_0x53f1f2,!![]);}catch(_0x302e2c){return BPromise[_0x5f37('0x30')](_0x302e2c);}return _0x1cc09a[_0x5f37('0x31')]();};}function saveUpdates(_0x198183,_0x38b888){return function(_0x39cdfc){if(_0x39cdfc){return _0x39cdfc[_0x5f37('0x32')](_0x198183)[_0x5f37('0x1d')](function(_0x1c5e2b){return _0x1c5e2b;});}return null;};}function removeEntity(_0x3e7b8b,_0x286e8d){return function(_0x18c808){if(_0x18c808){return _0x18c808[_0x5f37('0x33')]()[_0x5f37('0x1d')](function(){_0x3e7b8b[_0x5f37('0x2c')](0xcc)[_0x5f37('0x34')]();});}};}function handleEntityNotFound(_0x132a31,_0x265ef2){return function(_0x5f3058){if(!_0x5f3058){_0x132a31[_0x5f37('0x26')](0x194);}return _0x5f3058;};}function handleError(_0x3c4346,_0xb21ee8){_0xb21ee8=_0xb21ee8||0x1f4;return function(_0x538ad8){logger[_0x5f37('0x22')](_0x538ad8[_0x5f37('0x35')]);if(_0x538ad8[_0x5f37('0x36')]){delete _0x538ad8[_0x5f37('0x36')];}_0x3c4346[_0x5f37('0x2c')](_0xb21ee8)[_0x5f37('0x37')](_0x538ad8);};}exports[_0x5f37('0x38')]=function(_0x3e41fc,_0x401eff){var _0x4c0dc4={},_0x5efcfa={},_0x17917a={'count':0x0,'rows':[]};var _0x26ff23=_[_0x5f37('0x39')](db[_0x5f37('0x3a')][_0x5f37('0x3b')],function(_0x5de503){return{'name':_0x5de503[_0x5f37('0x3c')],'type':_0x5de503[_0x5f37('0x3d')][_0x5f37('0x3e')]};});_0x5efcfa[_0x5f37('0x3f')]=_[_0x5f37('0x39')](_0x26ff23,_0x5f37('0x36'));_0x5efcfa[_0x5f37('0x40')]=_['keys'](_0x3e41fc['query']);_0x5efcfa[_0x5f37('0x41')]=_['intersection'](_0x5efcfa['model'],_0x5efcfa[_0x5f37('0x40')]);_0x4c0dc4[_0x5f37('0x42')]=_[_0x5f37('0x43')](_0x5efcfa[_0x5f37('0x3f')],qs['fields'](_0x3e41fc[_0x5f37('0x40')][_0x5f37('0x44')]));_0x4c0dc4['attributes']=_0x4c0dc4[_0x5f37('0x42')][_0x5f37('0x45')]?_0x4c0dc4[_0x5f37('0x42')]:_0x5efcfa[_0x5f37('0x3f')];if(!_0x3e41fc[_0x5f37('0x40')][_0x5f37('0x46')](_0x5f37('0x47'))){_0x4c0dc4['limit']=qs['limit'](_0x3e41fc[_0x5f37('0x40')]['limit']);_0x4c0dc4['offset']=qs[_0x5f37('0x28')](_0x3e41fc[_0x5f37('0x40')][_0x5f37('0x28')]);}_0x4c0dc4['order']=qs[_0x5f37('0x48')](_0x3e41fc[_0x5f37('0x40')]['sort']);_0x4c0dc4[_0x5f37('0x49')]=qs[_0x5f37('0x41')](_['pick'](_0x3e41fc['query'],_0x5efcfa[_0x5f37('0x41')]),_0x26ff23);if(_0x3e41fc['query'][_0x5f37('0x4a')]){_0x4c0dc4[_0x5f37('0x49')]=_[_0x5f37('0x4b')](_0x4c0dc4[_0x5f37('0x49')],{'$or':_['map'](_0x26ff23,function(_0x684f87){if(_0x684f87['type']!=='VIRTUAL'){var _0x4b19c3={};_0x4b19c3[_0x684f87['name']]={'$like':'%'+_0x3e41fc[_0x5f37('0x40')][_0x5f37('0x4a')]+'%'};return _0x4b19c3;}})});}_0x4c0dc4=_[_0x5f37('0x4b')]({},_0x4c0dc4,_0x3e41fc['options']);var _0x32e0c0={'where':_0x4c0dc4[_0x5f37('0x49')]};return db[_0x5f37('0x3a')][_0x5f37('0x2a')](_0x32e0c0)[_0x5f37('0x1d')](function(_0xaf15ae){_0x17917a[_0x5f37('0x2a')]=_0xaf15ae;if(_0x3e41fc[_0x5f37('0x40')][_0x5f37('0x4c')]){_0x4c0dc4[_0x5f37('0x4d')]=[{'all':!![]}];}return db[_0x5f37('0x3a')][_0x5f37('0x4e')](_0x4c0dc4);})[_0x5f37('0x1d')](function(_0x5a064d){_0x17917a[_0x5f37('0x4f')]=_0x5a064d;return _0x17917a;})['then'](respondWithFilteredResult(_0x401eff,_0x4c0dc4))[_0x5f37('0x25')](handleError(_0x401eff,null));};exports[_0x5f37('0x50')]=function(_0x508f8c,_0x1ff20f){var _0x3ecb14={'raw':!![],'where':{'id':_0x508f8c[_0x5f37('0x51')]['id']}},_0x181ffb={};_0x181ffb[_0x5f37('0x3f')]=_[_0x5f37('0x52')](db[_0x5f37('0x3a')][_0x5f37('0x3b')]);_0x181ffb[_0x5f37('0x40')]=_[_0x5f37('0x52')](_0x508f8c[_0x5f37('0x40')]);_0x181ffb[_0x5f37('0x41')]=_[_0x5f37('0x43')](_0x181ffb[_0x5f37('0x3f')],_0x181ffb[_0x5f37('0x40')]);_0x3ecb14['attributes']=_[_0x5f37('0x43')](_0x181ffb[_0x5f37('0x3f')],qs['fields'](_0x508f8c[_0x5f37('0x40')][_0x5f37('0x44')]));_0x3ecb14['attributes']=_0x3ecb14[_0x5f37('0x42')]['length']?_0x3ecb14[_0x5f37('0x42')]:_0x181ffb[_0x5f37('0x3f')];if(_0x508f8c[_0x5f37('0x40')][_0x5f37('0x4c')]){_0x3ecb14[_0x5f37('0x4d')]=[{'all':!![]}];}_0x3ecb14=_[_0x5f37('0x4b')]({},_0x3ecb14,_0x508f8c['options']);return db[_0x5f37('0x3a')][_0x5f37('0x53')](_0x3ecb14)[_0x5f37('0x1d')](handleEntityNotFound(_0x1ff20f,null))[_0x5f37('0x1d')](respondWithResult(_0x1ff20f,null))[_0x5f37('0x25')](handleError(_0x1ff20f,null));};exports[_0x5f37('0x54')]=function(_0x9b6ed7,_0x532c3d){return db[_0x5f37('0x3a')][_0x5f37('0x54')](_0x9b6ed7[_0x5f37('0x55')],{})[_0x5f37('0x1d')](respondWithResult(_0x532c3d,0xc9))[_0x5f37('0x25')](handleError(_0x532c3d,null));};exports['update']=function(_0x3d81ce,_0x13a5fd){if(_0x3d81ce[_0x5f37('0x55')]['id']){delete _0x3d81ce[_0x5f37('0x55')]['id'];}return db[_0x5f37('0x3a')]['find']({'where':{'id':_0x3d81ce['params']['id']}})[_0x5f37('0x1d')](handleEntityNotFound(_0x13a5fd,null))[_0x5f37('0x1d')](saveUpdates(_0x3d81ce[_0x5f37('0x55')],null))[_0x5f37('0x1d')](respondWithResult(_0x13a5fd,null))[_0x5f37('0x25')](handleError(_0x13a5fd,null));};exports[_0x5f37('0x33')]=function(_0x4ca1bc,_0x4b6b66){return db[_0x5f37('0x3a')]['find']({'where':{'id':_0x4ca1bc[_0x5f37('0x51')]['id']}})[_0x5f37('0x1d')](handleEntityNotFound(_0x4b6b66,null))[_0x5f37('0x1d')](removeEntity(_0x4b6b66,null))[_0x5f37('0x25')](handleError(_0x4b6b66,null));};exports[_0x5f37('0x56')]=function(_0x562119,_0x4001a7){return db[_0x5f37('0x3a')]['describe']()[_0x5f37('0x1d')](respondWithResult(_0x4001a7,null))['catch'](handleError(_0x4001a7,null));};var interaction_log=require('../../config/logger')('openchannel-interactions');exports[_0x5f37('0x57')]=function(_0x2cd3fc,_0x3e5a31,_0x5c5590){var _0x33065d={'agent':{},'channel':'openchannel'};if(_0x2cd3fc[_0x5f37('0x55')]['id']){delete _0x2cd3fc['body']['id'];}_0x2cd3fc['body'][_0x5f37('0x58')]=!![];_0x2cd3fc[_0x5f37('0x55')][_0x5f37('0x59')]=moment()[_0x5f37('0x5a')](_0x5f37('0x5b'));_0x2cd3fc[_0x5f37('0x55')][_0x5f37('0x5c')]=_0x2cd3fc[_0x5f37('0x55')]['UserId']||_0x2cd3fc[_0x5f37('0x5d')]['id'];_0x33065d[_0x5f37('0x5e')]['id']=_0x2cd3fc[_0x5f37('0x55')][_0x5f37('0x5c')];return db[_0x5f37('0x3a')][_0x5f37('0x53')]({'where':{'id':_0x2cd3fc[_0x5f37('0x51')]['id'],'UserId':null}})[_0x5f37('0x1d')](handleEntityNotFound(_0x3e5a31,null))[_0x5f37('0x1d')](saveUpdates(_0x2cd3fc[_0x5f37('0x55')],null))[_0x5f37('0x1d')](function(_0x1c0aba){if(_0x1c0aba){_0x33065d[_0x5f37('0x23')]=_0x1c0aba[_0x5f37('0x5f')]({'plain':!![]});return db['OpenchannelInteraction'][_0x5f37('0x53')]({'where':{'id':_0x1c0aba['OpenchannelInteractionId']}});}return null;})['then'](handleEntityNotFound(_0x3e5a31,null))['then'](function(_0x5bb9b3){if(_0x5bb9b3){return _0x5bb9b3[_0x5f37('0x32')]({'UserId':_0x2cd3fc[_0x5f37('0x55')][_0x5f37('0x5c')],'read1stAt':_[_0x5f37('0x60')](_0x5bb9b3[_0x5f37('0x61')])?moment()[_0x5f37('0x5a')](_0x5f37('0x5b')):undefined});}return null;})[_0x5f37('0x1d')](function(_0x82fd32){if(_0x82fd32){_0x33065d[_0x5f37('0x62')]=_0x82fd32[_0x5f37('0x5f')]({'plain':!![]});interaction_log[_0x5f37('0x1e')](_0x5f37('0x63'),_0x2cd3fc[_0x5f37('0x5d')]['id'],_0x2cd3fc[_0x5f37('0x5d')][_0x5f37('0x36')],_0x2cd3fc[_0x5f37('0x5d')][_0x5f37('0x64')],_0x33065d['interaction']['id'],_0x2cd3fc[_0x5f37('0x55')]?JSON['stringify'](_0x2cd3fc[_0x5f37('0x55')]):'null');return respondWithRpcPromise(_0x5f37('0x65'),_0x5f37('0x66'),_0x33065d);}return null;})[_0x5f37('0x1d')](function(_0x33d8a1){var _0x130b73=_0x5f37('0x67')+_0x33d8a1[_0x5f37('0x23')][_0x5f37('0x68')];return db[_0x5f37('0x69')][_0x5f37('0x40')](_0x130b73,{'type':db[_0x5f37('0x6a')][_0x5f37('0x6b')][_0x5f37('0x6c')],'raw':!![]})[_0x5f37('0x1d')](function(_0x345b2c){return _0x345b2c;});})['then'](function(_0x3b0a46){if(_0x3b0a46){_0x33065d['message'][_0x5f37('0x6d')]=_0x3b0a46[0x0];if(!_0x2cd3fc[_0x5f37('0x55')]['UserId'])return;return db[_0x5f37('0x6e')][_0x5f37('0x53')]({'where':{'id':_0x2cd3fc['body'][_0x5f37('0x5c')],'role':_0x5f37('0x5e')},'attributes':['id','name',_0x5f37('0x6f'),'email',_0x5f37('0x70')],'raw':!![]});}return null;})[_0x5f37('0x1d')](function(_0x549114){if(!_0x549114)return null;_0x33065d[_0x5f37('0x23')]['agent']=_0x549114;return _0x33065d;})[_0x5f37('0x1d')](function(_0x2c26d0){if(_0x2c26d0){if(_0x2cd3fc[_0x5f37('0x55')][_0x5f37('0x71')]){_0x33065d[_0x5f37('0x23')]['interface']=util[_0x5f37('0x5a')]('SIP/%s',_0x2cd3fc[_0x5f37('0x5d')]['name']);_0x33065d[_0x5f37('0x23')]['channel']=_0x33065d[_0x5f37('0x72')];_0x33065d[_0x5f37('0x23')][_0x5f37('0x73')]=_0x33065d['channel'];_0x33065d['message'][_0x5f37('0x74')]=_0x5f37('0x57');return respondWithRpcPromise(_0x5f37('0x75'),'EventManager',{'event':_0x5f37('0x76'),'message':_0x33065d[_0x5f37('0x23')]},client9002)[_0x5f37('0x1d')](function(){return _0x33065d;});}return _0x33065d;}return null;})[_0x5f37('0x1d')](respondWithResult(_0x3e5a31,null))[_0x5f37('0x25')](handleError(_0x3e5a31,null));};var interaction_log=require('../../config/logger')('openchannel-interactions');exports[_0x5f37('0x30')]=function(_0x5e0473,_0x4a6581,_0x40bf44){var _0x318f6a={'agent':{},'channel':_0x5f37('0x77')};if(_0x5e0473[_0x5f37('0x55')]['id']){delete _0x5e0473[_0x5f37('0x55')]['id'];}_0x5e0473[_0x5f37('0x55')][_0x5f37('0x5c')]=_0x5e0473['body'][_0x5f37('0x5c')]||_0x5e0473[_0x5f37('0x5d')]['id'];_0x318f6a['agent']['id']=_0x5e0473[_0x5f37('0x55')][_0x5f37('0x5c')];return db[_0x5f37('0x3a')]['find']({'where':{'id':_0x5e0473[_0x5f37('0x51')]['id'],'UserId':null}})[_0x5f37('0x1d')](handleEntityNotFound(_0x4a6581,null))[_0x5f37('0x1d')](function(_0xf991e4){if(_0xf991e4){_0x318f6a['message']=_0xf991e4[_0x5f37('0x5f')]({'plain':!![]});return db[_0x5f37('0x78')][_0x5f37('0x53')]({'where':{'id':_0xf991e4[_0x5f37('0x79')]}});}return null;})[_0x5f37('0x1d')](handleEntityNotFound(_0x4a6581,null))[_0x5f37('0x1d')](function(_0x2cc202){if(_0x2cc202){_0x318f6a[_0x5f37('0x62')]=_0x2cc202['get']({'plain':!![]});interaction_log[_0x5f37('0x1e')]('[OPENCHANNELMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x5e0473[_0x5f37('0x5d')]['id'],_0x5e0473[_0x5f37('0x5d')][_0x5f37('0x36')],_0x5e0473[_0x5f37('0x5d')]['role'],_0x318f6a[_0x5f37('0x62')]['id'],_0x5e0473['body']?JSON[_0x5f37('0x7a')](_0x5e0473[_0x5f37('0x55')]):_0x5f37('0x7b'));return respondWithRpcPromise(_0x5f37('0x7c'),'rejectMessage',_0x318f6a);}return null;})['then'](function(_0x3cf5ce){var _0x82f7a9=_0x5f37('0x67')+_0x3cf5ce[_0x5f37('0x23')][_0x5f37('0x68')];return db[_0x5f37('0x69')][_0x5f37('0x40')](_0x82f7a9,{'type':db[_0x5f37('0x6a')][_0x5f37('0x6b')][_0x5f37('0x6c')],'raw':!![]})[_0x5f37('0x1d')](function(_0x46a9f6){return _0x46a9f6;});})[_0x5f37('0x1d')](function(_0x344f44){if(_0x344f44){_0x318f6a[_0x5f37('0x23')][_0x5f37('0x6d')]=_0x344f44[0x0];if(!_0x5e0473[_0x5f37('0x55')][_0x5f37('0x5c')])return;return db[_0x5f37('0x6e')][_0x5f37('0x53')]({'where':{'id':_0x5e0473['body']['UserId'],'role':'agent'},'attributes':['id',_0x5f37('0x36'),_0x5f37('0x6f'),_0x5f37('0x7d'),_0x5f37('0x70')],'raw':!![]});}return null;})['then'](function(_0x230068){if(!_0x230068)return null;_0x318f6a['message'][_0x5f37('0x5e')]=_0x230068;return _0x318f6a;})[_0x5f37('0x1d')](function(_0x5aaf37){if(_0x5aaf37){_0x5aaf37['message'][_0x5f37('0x7e')]=util[_0x5f37('0x5a')]('SIP/%s',_0x5e0473[_0x5f37('0x5d')]['name']);_0x5aaf37[_0x5f37('0x23')][_0x5f37('0x72')]=_0x318f6a[_0x5f37('0x72')];_0x5aaf37[_0x5f37('0x23')]['motionChannel']=_0x318f6a[_0x5f37('0x72')];_0x5aaf37[_0x5f37('0x23')][_0x5f37('0x74')]=_0x5f37('0x30');respondWithRpcPromise(_0x5f37('0x75'),_0x5f37('0x75'),{'event':_0x5f37('0x7f'),'message':_0x5aaf37['message']},client9002);return _0x318f6a;}return null;})[_0x5f37('0x1d')](respondWithResult(_0x4a6581,null))['catch'](handleError(_0x4a6581,null));};