Built motion from commit 97153652.|2.6.26
[motion2.git] / server / api / chatMessage / chatMessage.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 _0x8fc5=['status','end','json','undefined','count','offset','limit','set','Content-Range','apply','reject','save','destroy','stack','name','send','index','map','ChatMessage','rawAttributes','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','pick','filter','merge','where','type','VIRTUAL','options','includeAll','include','findAll','rows','show','params','find','create','update','body','describe','chat-interactions','accept','chat','readAt','format','YYYY-MM-DD\x20HH:mm:ss','UserId','user','agent','get','ChatInteractionId','isNil','read1stAt','interaction','[CHATMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','null','AcceptMessage','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','sequelize','Sequelize','QueryTypes','SELECT','User','fullname','email','internal','channel','motionChannel','EventManager','acceptmessage','formData','[CHATMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','stringify','RejectMessage','rejectMessage','ContactId','interface','event','rejectmessage','parse','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','sox','fs-extra','lodash','squel','jsforce','desk.js','to-csv','querystring','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','redis','localhost','socket.io-emitter','./chatMessage.socket','register','jayson/promise','http','client','then','ChatMessage,\x20%s,\x20%s','request\x20sent','debug','ChatMessage,\x20%s,\x20%s,\x20%s','error','message','info','result','catch','sendStatus'];(function(_0xe786c2,_0x360b22){var _0x4a1d36=function(_0x4210c5){while(--_0x4210c5){_0xe786c2['push'](_0xe786c2['shift']());}};_0x4a1d36(++_0x360b22);}(_0x8fc5,0xe4));var _0x58fc=function(_0x410be1,_0x468d62){_0x410be1=_0x410be1-0x0;var _0x4406b1=_0x8fc5[_0x410be1];return _0x4406b1;};'use strict';var emlformat=require(_0x58fc('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x58fc('0x1'));var jsonpatch=require(_0x58fc('0x2'));var rp=require(_0x58fc('0x3'));var moment=require(_0x58fc('0x4'));var BPromise=require(_0x58fc('0x5'));var Mustache=require('mustache');var util=require(_0x58fc('0x6'));var path=require(_0x58fc('0x7'));var sox=require(_0x58fc('0x8'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x58fc('0x9'));var _=require(_0x58fc('0xa'));var squel=require(_0x58fc('0xb'));var crypto=require('crypto');var jsforce=require(_0x58fc('0xc'));var deskjs=require(_0x58fc('0xd'));var toCsv=require(_0x58fc('0xe'));var querystring=require(_0x58fc('0xf'));var Papa=require('papaparse');var Redis=require(_0x58fc('0x10'));var authService=require(_0x58fc('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0x58fc('0x12'));var hardwareService=require(_0x58fc('0x13'));var logger=require(_0x58fc('0x14'))(_0x58fc('0x15'));var utils=require(_0x58fc('0x16'));var config=require('../../config/environment');var licenseUtil=require(_0x58fc('0x17'));var db=require(_0x58fc('0x18'))['db'];config[_0x58fc('0x19')]=_['defaults'](config[_0x58fc('0x19')],{'host':_0x58fc('0x1a'),'port':0x18eb});var socket=require(_0x58fc('0x1b'))(new Redis(config[_0x58fc('0x19')]));require(_0x58fc('0x1c'))[_0x58fc('0x1d')](socket);var jayson=require(_0x58fc('0x1e'));var client=jayson['client'][_0x58fc('0x1f')]({'port':0x232c});var client9002=jayson[_0x58fc('0x20')][_0x58fc('0x1f')]({'port':0x232a});function respondWithRpcPromise(_0x139e0c,_0x88bb3d,_0x2b020b,_0x44900f){return new BPromise(function(_0xa7598f,_0x3e6765){var _0xbf133e=_0x44900f||client;return _0xbf133e['request'](_0x139e0c,_0x2b020b)[_0x58fc('0x21')](function(_0x390f84){logger['info'](_0x58fc('0x22'),_0x88bb3d,_0x58fc('0x23'));logger[_0x58fc('0x24')](_0x58fc('0x25'),_0x88bb3d,_0x58fc('0x23'),JSON['stringify'](_0x390f84));if(_0x390f84[_0x58fc('0x26')]){if(_0x390f84[_0x58fc('0x26')]['code']===0x1f4){logger[_0x58fc('0x26')](_0x58fc('0x22'),_0x88bb3d,_0x390f84[_0x58fc('0x26')][_0x58fc('0x27')]);return _0x3e6765(_0x390f84[_0x58fc('0x26')][_0x58fc('0x27')]);}logger[_0x58fc('0x26')]('ChatMessage,\x20%s,\x20%s',_0x88bb3d,_0x390f84[_0x58fc('0x26')][_0x58fc('0x27')]);return _0xa7598f(_0x390f84['error'][_0x58fc('0x27')]);}else{logger[_0x58fc('0x28')](_0x58fc('0x22'),_0x88bb3d,_0x58fc('0x23'));_0xa7598f(_0x390f84[_0x58fc('0x29')][_0x58fc('0x27')]);}})[_0x58fc('0x2a')](function(_0x1e6a51){logger[_0x58fc('0x26')](_0x58fc('0x22'),_0x88bb3d,_0x1e6a51);_0x3e6765(_0x1e6a51);});});}function respondWithStatusCode(_0xc334fc,_0x54d6db){_0x54d6db=_0x54d6db||0xcc;return function(_0x36220f){if(_0x36220f){return _0xc334fc[_0x58fc('0x2b')](_0x54d6db);}return _0xc334fc[_0x58fc('0x2c')](_0x54d6db)[_0x58fc('0x2d')]();};}function respondWithResult(_0x1b1117,_0x4f0ed3){_0x4f0ed3=_0x4f0ed3||0xc8;return function(_0x3d170c){if(_0x3d170c){return _0x1b1117[_0x58fc('0x2c')](_0x4f0ed3)[_0x58fc('0x2e')](_0x3d170c);}};}function respondWithFilteredResult(_0x4e5772,_0x411839){return function(_0x27702f){if(_0x27702f){var _0x37cdc1=typeof _0x411839['offset']===_0x58fc('0x2f')&&typeof _0x411839['limit']===_0x58fc('0x2f');var _0x40a16b=_0x27702f[_0x58fc('0x30')];var _0x578ee2=_0x37cdc1?0x0:_0x411839[_0x58fc('0x31')];var _0x3db4e4=_0x37cdc1?_0x27702f['count']:_0x411839[_0x58fc('0x31')]+_0x411839[_0x58fc('0x32')];var _0x5d24d7;if(_0x3db4e4>=_0x40a16b){_0x3db4e4=_0x40a16b;_0x5d24d7=0xc8;}else{_0x5d24d7=0xce;}_0x4e5772[_0x58fc('0x2c')](_0x5d24d7);return _0x4e5772[_0x58fc('0x33')](_0x58fc('0x34'),_0x578ee2+'-'+_0x3db4e4+'/'+_0x40a16b)[_0x58fc('0x2e')](_0x27702f);}return null;};}function patchUpdates(_0x341603){return function(_0x1d5104){try{jsonpatch[_0x58fc('0x35')](_0x1d5104,_0x341603,!![]);}catch(_0x161943){return BPromise[_0x58fc('0x36')](_0x161943);}return _0x1d5104[_0x58fc('0x37')]();};}function saveUpdates(_0x377d41,_0x592abe){return function(_0x23f2a3){if(_0x23f2a3){return _0x23f2a3['update'](_0x377d41)['then'](function(_0x388dc3){return _0x388dc3;});}return null;};}function removeEntity(_0x1c5095,_0x489539){return function(_0x3111f8){if(_0x3111f8){return _0x3111f8[_0x58fc('0x38')]()[_0x58fc('0x21')](function(){_0x1c5095[_0x58fc('0x2c')](0xcc)['end']();});}};}function handleEntityNotFound(_0x2fbcde,_0x1f155e){return function(_0x1f623c){if(!_0x1f623c){_0x2fbcde['sendStatus'](0x194);}return _0x1f623c;};}function handleError(_0x488201,_0x1bce27){_0x1bce27=_0x1bce27||0x1f4;return function(_0x4590a9){logger[_0x58fc('0x26')](_0x4590a9[_0x58fc('0x39')]);if(_0x4590a9[_0x58fc('0x3a')]){delete _0x4590a9[_0x58fc('0x3a')];}_0x488201[_0x58fc('0x2c')](_0x1bce27)[_0x58fc('0x3b')](_0x4590a9);};}exports[_0x58fc('0x3c')]=function(_0x4780dc,_0x397e7e){var _0x3292d4={},_0x3a4932={},_0x44f708={'count':0x0,'rows':[]};var _0x48dacb=_[_0x58fc('0x3d')](db[_0x58fc('0x3e')][_0x58fc('0x3f')],function(_0x4f4af9){return{'name':_0x4f4af9['fieldName'],'type':_0x4f4af9['type']['key']};});_0x3a4932[_0x58fc('0x40')]=_['map'](_0x48dacb,_0x58fc('0x3a'));_0x3a4932[_0x58fc('0x41')]=_[_0x58fc('0x42')](_0x4780dc[_0x58fc('0x41')]);_0x3a4932[_0x58fc('0x43')]=_[_0x58fc('0x44')](_0x3a4932['model'],_0x3a4932[_0x58fc('0x41')]);_0x3292d4[_0x58fc('0x45')]=_[_0x58fc('0x44')](_0x3a4932[_0x58fc('0x40')],qs[_0x58fc('0x46')](_0x4780dc[_0x58fc('0x41')][_0x58fc('0x46')]));_0x3292d4[_0x58fc('0x45')]=_0x3292d4[_0x58fc('0x45')][_0x58fc('0x47')]?_0x3292d4[_0x58fc('0x45')]:_0x3a4932[_0x58fc('0x40')];if(!_0x4780dc[_0x58fc('0x41')][_0x58fc('0x48')](_0x58fc('0x49'))){_0x3292d4[_0x58fc('0x32')]=qs[_0x58fc('0x32')](_0x4780dc[_0x58fc('0x41')][_0x58fc('0x32')]);_0x3292d4[_0x58fc('0x31')]=qs[_0x58fc('0x31')](_0x4780dc['query'][_0x58fc('0x31')]);}_0x3292d4[_0x58fc('0x4a')]=qs[_0x58fc('0x4b')](_0x4780dc['query'][_0x58fc('0x4b')]);_0x3292d4['where']=qs[_0x58fc('0x43')](_[_0x58fc('0x4c')](_0x4780dc[_0x58fc('0x41')],_0x3a4932[_0x58fc('0x43')]),_0x48dacb);if(_0x4780dc['query'][_0x58fc('0x4d')]){_0x3292d4['where']=_[_0x58fc('0x4e')](_0x3292d4[_0x58fc('0x4f')],{'$or':_[_0x58fc('0x3d')](_0x48dacb,function(_0x57deff){if(_0x57deff[_0x58fc('0x50')]!==_0x58fc('0x51')){var _0x54b093={};_0x54b093[_0x57deff['name']]={'$like':'%'+_0x4780dc[_0x58fc('0x41')][_0x58fc('0x4d')]+'%'};return _0x54b093;}})});}_0x3292d4=_[_0x58fc('0x4e')]({},_0x3292d4,_0x4780dc[_0x58fc('0x52')]);var _0x5986a5={'where':_0x3292d4[_0x58fc('0x4f')]};return db[_0x58fc('0x3e')][_0x58fc('0x30')](_0x5986a5)['then'](function(_0x8dd09d){_0x44f708[_0x58fc('0x30')]=_0x8dd09d;if(_0x4780dc[_0x58fc('0x41')][_0x58fc('0x53')]){_0x3292d4[_0x58fc('0x54')]=[{'all':!![]}];}return db[_0x58fc('0x3e')][_0x58fc('0x55')](_0x3292d4);})[_0x58fc('0x21')](function(_0x28733b){_0x44f708[_0x58fc('0x56')]=_0x28733b;return _0x44f708;})[_0x58fc('0x21')](respondWithFilteredResult(_0x397e7e,_0x3292d4))['catch'](handleError(_0x397e7e,null));};exports[_0x58fc('0x57')]=function(_0x5da06d,_0x3cbddf){var _0x897f90={'raw':!![],'where':{'id':_0x5da06d[_0x58fc('0x58')]['id']}},_0x56b50c={};_0x56b50c['model']=_[_0x58fc('0x42')](db[_0x58fc('0x3e')][_0x58fc('0x3f')]);_0x56b50c['query']=_[_0x58fc('0x42')](_0x5da06d[_0x58fc('0x41')]);_0x56b50c[_0x58fc('0x43')]=_[_0x58fc('0x44')](_0x56b50c[_0x58fc('0x40')],_0x56b50c[_0x58fc('0x41')]);_0x897f90[_0x58fc('0x45')]=_[_0x58fc('0x44')](_0x56b50c['model'],qs[_0x58fc('0x46')](_0x5da06d['query'][_0x58fc('0x46')]));_0x897f90[_0x58fc('0x45')]=_0x897f90[_0x58fc('0x45')][_0x58fc('0x47')]?_0x897f90[_0x58fc('0x45')]:_0x56b50c[_0x58fc('0x40')];if(_0x5da06d[_0x58fc('0x41')][_0x58fc('0x53')]){_0x897f90[_0x58fc('0x54')]=[{'all':!![]}];}_0x897f90=_['merge']({},_0x897f90,_0x5da06d[_0x58fc('0x52')]);return db[_0x58fc('0x3e')][_0x58fc('0x59')](_0x897f90)['then'](handleEntityNotFound(_0x3cbddf,null))[_0x58fc('0x21')](respondWithResult(_0x3cbddf,null))[_0x58fc('0x2a')](handleError(_0x3cbddf,null));};exports[_0x58fc('0x5a')]=function(_0x182114,_0x56fa06){return db['ChatMessage'][_0x58fc('0x5a')](_0x182114['body'],{})[_0x58fc('0x21')](respondWithResult(_0x56fa06,0xc9))['catch'](handleError(_0x56fa06,null));};exports[_0x58fc('0x5b')]=function(_0x4da317,_0x15b092){if(_0x4da317[_0x58fc('0x5c')]['id']){delete _0x4da317[_0x58fc('0x5c')]['id'];}return db[_0x58fc('0x3e')]['find']({'where':{'id':_0x4da317['params']['id']}})[_0x58fc('0x21')](handleEntityNotFound(_0x15b092,null))[_0x58fc('0x21')](saveUpdates(_0x4da317[_0x58fc('0x5c')],null))[_0x58fc('0x21')](respondWithResult(_0x15b092,null))[_0x58fc('0x2a')](handleError(_0x15b092,null));};exports['destroy']=function(_0x5cd6c6,_0xb477c){return db[_0x58fc('0x3e')][_0x58fc('0x59')]({'where':{'id':_0x5cd6c6['params']['id']}})[_0x58fc('0x21')](handleEntityNotFound(_0xb477c,null))[_0x58fc('0x21')](removeEntity(_0xb477c,null))[_0x58fc('0x2a')](handleError(_0xb477c,null));};exports[_0x58fc('0x5d')]=function(_0x16b1a1,_0x3280dc){return db[_0x58fc('0x3e')][_0x58fc('0x5d')]()[_0x58fc('0x21')](respondWithResult(_0x3280dc,null))[_0x58fc('0x2a')](handleError(_0x3280dc,null));};var interaction_log=require(_0x58fc('0x14'))(_0x58fc('0x5e'));exports[_0x58fc('0x5f')]=function(_0x1ccd86,_0x1d32be,_0x380775){var _0x3956e4={'agent':{},'channel':_0x58fc('0x60')};if(_0x1ccd86[_0x58fc('0x5c')]['id']){delete _0x1ccd86['body']['id'];}_0x1ccd86['body']['read']=!![];_0x1ccd86['body'][_0x58fc('0x61')]=moment()[_0x58fc('0x62')](_0x58fc('0x63'));_0x1ccd86['body'][_0x58fc('0x64')]=_0x1ccd86[_0x58fc('0x5c')][_0x58fc('0x64')]||_0x1ccd86[_0x58fc('0x65')]['id'];_0x3956e4[_0x58fc('0x66')]['id']=_0x1ccd86['body'][_0x58fc('0x64')];return db[_0x58fc('0x3e')][_0x58fc('0x59')]({'where':{'id':_0x1ccd86[_0x58fc('0x58')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0x1d32be,null))['then'](saveUpdates(_0x1ccd86[_0x58fc('0x5c')],null))[_0x58fc('0x21')](function(_0x540b30){if(_0x540b30){_0x3956e4[_0x58fc('0x27')]=_0x540b30[_0x58fc('0x67')]({'plain':!![]});return db['ChatInteraction'][_0x58fc('0x59')]({'where':{'id':_0x540b30[_0x58fc('0x68')]}});}return null;})[_0x58fc('0x21')](handleEntityNotFound(_0x1d32be,null))[_0x58fc('0x21')](function(_0x232ff7){if(_0x232ff7){return _0x232ff7[_0x58fc('0x5b')]({'UserId':_0x1ccd86['body'][_0x58fc('0x64')],'read1stAt':_[_0x58fc('0x69')](_0x232ff7[_0x58fc('0x6a')])?moment()[_0x58fc('0x62')](_0x58fc('0x63')):undefined});}return null;})[_0x58fc('0x21')](function(_0x442f69){if(_0x442f69){_0x3956e4[_0x58fc('0x6b')]=_0x442f69[_0x58fc('0x67')]({'plain':!![]});interaction_log[_0x58fc('0x28')](_0x58fc('0x6c'),_0x1ccd86[_0x58fc('0x65')]['id'],_0x1ccd86[_0x58fc('0x65')][_0x58fc('0x3a')],_0x1ccd86[_0x58fc('0x65')][_0x58fc('0x6d')],_0x3956e4['interaction']['id'],_0x1ccd86[_0x58fc('0x5c')]?JSON['stringify'](_0x1ccd86['body']):_0x58fc('0x6e'));return respondWithRpcPromise(_0x58fc('0x6f'),_0x58fc('0x70'),_0x3956e4);}return null;})[_0x58fc('0x21')](function(_0xc62c7a){var _0x5071e8=_0x58fc('0x71')+_0xc62c7a['message']['ContactId'];return db[_0x58fc('0x72')][_0x58fc('0x41')](_0x5071e8,{'type':db[_0x58fc('0x73')][_0x58fc('0x74')][_0x58fc('0x75')],'raw':!![]})[_0x58fc('0x21')](function(_0x21d239){return _0x21d239;});})[_0x58fc('0x21')](function(_0x5f2e72){if(_0x5f2e72){_0x3956e4[_0x58fc('0x27')]['contact']=_0x5f2e72[0x0];if(!_0x1ccd86[_0x58fc('0x5c')][_0x58fc('0x64')])return;return db[_0x58fc('0x76')][_0x58fc('0x59')]({'where':{'id':_0x1ccd86[_0x58fc('0x5c')][_0x58fc('0x64')],'role':_0x58fc('0x66')},'attributes':['id',_0x58fc('0x3a'),_0x58fc('0x77'),_0x58fc('0x78'),_0x58fc('0x79')],'raw':!![]});}return null;})[_0x58fc('0x21')](function(_0x363bf5){if(!_0x363bf5)return null;_0x3956e4[_0x58fc('0x27')][_0x58fc('0x66')]=_0x363bf5;return _0x3956e4;})[_0x58fc('0x21')](function(_0x4ce671){if(_0x4ce671){if(_0x1ccd86['body']['manual']){_0x3956e4[_0x58fc('0x27')]['interface']=util['format']('SIP/%s',_0x1ccd86[_0x58fc('0x65')][_0x58fc('0x3a')]);_0x3956e4['message'][_0x58fc('0x7a')]=_0x3956e4[_0x58fc('0x7a')];_0x3956e4[_0x58fc('0x27')][_0x58fc('0x7b')]=_0x3956e4['channel'];_0x3956e4[_0x58fc('0x27')]['event']=_0x58fc('0x5f');return respondWithRpcPromise(_0x58fc('0x7c'),_0x58fc('0x7c'),{'event':_0x58fc('0x7d'),'message':_[_0x58fc('0x4e')](_0x3956e4['message'],JSON['parse'](_0x3956e4[_0x58fc('0x6b')][_0x58fc('0x7e')]))},client9002)[_0x58fc('0x21')](function(){return _0x3956e4;});}return _0x3956e4;}return null;})[_0x58fc('0x21')](respondWithResult(_0x1d32be,null))[_0x58fc('0x2a')](handleError(_0x1d32be,null));};var interaction_log=require('../../config/logger')(_0x58fc('0x5e'));exports[_0x58fc('0x36')]=function(_0xf5ba7d,_0x266812,_0x35ec1c){var _0x330943={'agent':{},'channel':_0x58fc('0x60')};if(_0xf5ba7d[_0x58fc('0x5c')]['id']){delete _0xf5ba7d[_0x58fc('0x5c')]['id'];}_0xf5ba7d[_0x58fc('0x5c')][_0x58fc('0x64')]=_0xf5ba7d['body'][_0x58fc('0x64')]||_0xf5ba7d[_0x58fc('0x65')]['id'];_0x330943['agent']['id']=_0xf5ba7d[_0x58fc('0x5c')][_0x58fc('0x64')];return db[_0x58fc('0x3e')][_0x58fc('0x59')]({'where':{'id':_0xf5ba7d[_0x58fc('0x58')]['id'],'UserId':null}})[_0x58fc('0x21')](handleEntityNotFound(_0x266812,null))[_0x58fc('0x21')](function(_0xe4633a){if(_0xe4633a){_0x330943[_0x58fc('0x27')]=_0xe4633a[_0x58fc('0x67')]({'plain':!![]});return db['ChatInteraction'][_0x58fc('0x59')]({'where':{'id':_0xe4633a['ChatInteractionId']}});}return null;})[_0x58fc('0x21')](handleEntityNotFound(_0x266812,null))[_0x58fc('0x21')](function(_0xe65984){if(_0xe65984){_0x330943['interaction']=_0xe65984[_0x58fc('0x67')]({'plain':!![]});interaction_log[_0x58fc('0x28')](_0x58fc('0x7f'),_0xf5ba7d[_0x58fc('0x65')]['id'],_0xf5ba7d['user'][_0x58fc('0x3a')],_0xf5ba7d[_0x58fc('0x65')][_0x58fc('0x6d')],_0x330943[_0x58fc('0x6b')]['id'],_0xf5ba7d[_0x58fc('0x5c')]?JSON[_0x58fc('0x80')](_0xf5ba7d[_0x58fc('0x5c')]):'null');return respondWithRpcPromise(_0x58fc('0x81'),_0x58fc('0x82'),_0x330943);}return null;})[_0x58fc('0x21')](function(_0x20e930){var _0x1ccb9b=_0x58fc('0x71')+_0x20e930[_0x58fc('0x27')][_0x58fc('0x83')];return db['sequelize'][_0x58fc('0x41')](_0x1ccb9b,{'type':db[_0x58fc('0x73')]['QueryTypes'][_0x58fc('0x75')],'raw':!![]})['then'](function(_0x3547d2){return _0x3547d2;});})[_0x58fc('0x21')](function(_0x51cc66){if(_0x51cc66){_0x330943[_0x58fc('0x27')]['contact']=_0x51cc66[0x0];if(!_0xf5ba7d[_0x58fc('0x5c')][_0x58fc('0x64')])return;return db[_0x58fc('0x76')]['find']({'where':{'id':_0xf5ba7d[_0x58fc('0x5c')][_0x58fc('0x64')],'role':'agent'},'attributes':['id','name',_0x58fc('0x77'),_0x58fc('0x78'),_0x58fc('0x79')],'raw':!![]});}return null;})['then'](function(_0x504cee){if(!_0x504cee)return null;_0x330943[_0x58fc('0x27')][_0x58fc('0x66')]=_0x504cee;return _0x330943;})[_0x58fc('0x21')](function(_0x595f6b){if(_0x595f6b){_0x595f6b[_0x58fc('0x27')][_0x58fc('0x84')]=util[_0x58fc('0x62')]('SIP/%s',_0xf5ba7d['user'][_0x58fc('0x3a')]);_0x595f6b[_0x58fc('0x27')][_0x58fc('0x7a')]=_0x330943['channel'];_0x595f6b[_0x58fc('0x27')]['motionChannel']=_0x330943[_0x58fc('0x7a')];_0x595f6b[_0x58fc('0x27')][_0x58fc('0x85')]=_0x58fc('0x36');respondWithRpcPromise(_0x58fc('0x7c'),_0x58fc('0x7c'),{'event':_0x58fc('0x86'),'message':_[_0x58fc('0x4e')](_0x330943['message'],JSON[_0x58fc('0x87')](_0x330943['interaction'][_0x58fc('0x7e')]))},client9002);return _0x330943;}return null;})['then'](respondWithResult(_0x266812,null))[_0x58fc('0x2a')](handleError(_0x266812,null));};