6759db63d452b0f60dd8b22eca0ae663081f1545
[motion2.git] / server / api / rpc / rpc.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 _0x6940=['send','isNil','find','voiceChannels','VoiceChannels','query','catch','VoiceChannelMixMonitor','merge','params','voiceChannelStopMixMonitor','VoiceChannelStopMixMonitor','then','voiceQueues','VoiceQueues','updateVoiceQueue','body','VoiceQueuesPreview','voiceQueuesChannels','VoiceQueuesChannels','VoiceQueuesChannelHangup','voiceQueuesChannelRedirect','VoiceQueuesChannelRedirect','Outbound','outboundChannels','OutboundChannels','agents','Agents','agentCapacity','user','interaction','MemberReport','findAll','INTERACTION','length','format','YYYY-MM-DD\x20HH:mm:ss','updateAttributes','findOrCreate','SIP/%s','agent','internal','telephones','Telephones','trunks','Trunks','campaigns','ChatQueues','showChatQueues','MailQueues','showMailQueues','mailAccounts','MailAccounts','openchannelQueues','showOpenchannelQueues','smsQueues','SmsQueues','showWhatsappQueues','FaxQueues','faxAccounts','chatQueuesWaitingInteractions','ChatQueuesWaitingInteractions','mailQueuesWaitingInteractions','MailQueuesWaitingInteractions','openchannelQueuesWaitingInteractions','OpenchannelQueuesWaitingInteractions','openchannelQueuesIdWaitingInteractions','type','rows','filter','map','queue_id','uniq','value','indexOf','smsQueuesWaitingInteractions','SmsQueuesWaitingInteractions','WhatsappQueuesWaitingInteractions','faxQueuesWaitingInteractions','FaxQueuesWaitingInteractions','queueNotify','capitalize','chat','Website','Queue','findOne','\x20Queue\x20not\x20found','Message','messageId','Interaction','Account','update','queue','MessageId','From','QueueId','TransferReport','create','queueTransferTimeout','*,*,*,*','Channel\x20field\x20is\x20mandatory','channel','User','Agent\x20not\x20found','InteractionId','agentTransferTimeout','bluebird','lodash','util','../../mysqldb','../../config/logger','jayson/promise','client','http','request','error','code','message','result','status','sendStatus','name'];(function(_0x5223f0,_0x12c73c){var _0x55dd06=function(_0x4f8b1b){while(--_0x4f8b1b){_0x5223f0['push'](_0x5223f0['shift']());}};_0x55dd06(++_0x12c73c);}(_0x6940,0xe4));var _0x0694=function(_0x1db042,_0x497a84){_0x1db042=_0x1db042-0x0;var _0xa2f486=_0x6940[_0x1db042];return _0xa2f486;};'use strict';var BPromise=require(_0x0694('0x0'));var moment=require('moment');var _=require(_0x0694('0x1'));var util=require(_0x0694('0x2'));var db=require(_0x0694('0x3'))['db'];var logger=require(_0x0694('0x4'))('api');var jayson=require(_0x0694('0x5'));var amiClient=jayson[_0x0694('0x6')]['http']({'port':0x232a});var mailClient=jayson[_0x0694('0x6')][_0x0694('0x7')]({'port':0x232b});var routingClient=jayson[_0x0694('0x6')][_0x0694('0x7')]({'port':0x232c});function respondWithRpcPromise(_0xdf0cf2,_0x104b0d,_0x2fedcd){return new BPromise(function(_0x11de59,_0x45df54){var _0x6a129e=_0x2fedcd?_0x2fedcd:amiClient;return _0x6a129e[_0x0694('0x8')](_0xdf0cf2,_0x104b0d)['then'](function(_0x3f9a77){if(_0x3f9a77[_0x0694('0x9')]){if(_0x3f9a77['error'][_0x0694('0xa')]===0x1f4){return _0x45df54(_0x3f9a77[_0x0694('0x9')][_0x0694('0xb')]);}return _0x11de59(_0x3f9a77[_0x0694('0x9')][_0x0694('0xb')]);}else{_0x11de59(_0x3f9a77[_0x0694('0xc')]);}})['catch'](function(_0x58449a){_0x45df54(_0x58449a);});});}function respondWithResult(_0x3f8441,_0x3888ae){_0x3888ae=_0x3888ae||0xc8;return function(_0x43f5e0){if(_0x43f5e0){return _0x3f8441[_0x0694('0xd')](_0x3888ae)['json'](_0x43f5e0);}return _0x3f8441[_0x0694('0xe')](0x194);};}function handleError(_0x43fc6a,_0x533c05){_0x533c05=_0x533c05||0x1f4;return function(_0x461ff1){logger[_0x0694('0x9')](_0x461ff1['stack']);if(_0x461ff1[_0x0694('0xf')]){delete _0x461ff1[_0x0694('0xf')];}_0x43fc6a[_0x0694('0xd')](_0x533c05)[_0x0694('0x10')](_0x461ff1);};}function findById(_0x336b5e){return function(_0x4ac5df){if(!_['isNil'](_0x336b5e)&&!_[_0x0694('0x11')](_0x4ac5df)&&!_[_0x0694('0x11')](_0x4ac5df['rows'])){return _[_0x0694('0x12')](_0x4ac5df['rows'],function(_0x56fec8){return _0x56fec8['id']==_0x336b5e;});}return null;};}exports[_0x0694('0x13')]=function(_0x33211b,_0x2b5111){return respondWithRpcPromise(_0x0694('0x14'),_0x33211b[_0x0694('0x15')])['then'](respondWithResult(_0x2b5111,null))[_0x0694('0x16')](handleError(_0x2b5111,null));};exports['voiceChannelMixMonitor']=function(_0x245752,_0x203c6e){return respondWithRpcPromise(_0x0694('0x17'),_[_0x0694('0x18')](_0x245752['query'],_0x245752[_0x0694('0x19')]))['then'](respondWithResult(_0x203c6e,null))['catch'](handleError(_0x203c6e,null));};exports[_0x0694('0x1a')]=function(_0x1ef495,_0x2edff2){return respondWithRpcPromise(_0x0694('0x1b'),_['merge'](_0x1ef495[_0x0694('0x15')],_0x1ef495[_0x0694('0x19')]))[_0x0694('0x1c')](respondWithResult(_0x2edff2,null))[_0x0694('0x16')](handleError(_0x2edff2,null));};exports[_0x0694('0x1d')]=function(_0x944c5,_0x3072fd){return respondWithRpcPromise(_0x0694('0x1e'),_0x944c5[_0x0694('0x15')])[_0x0694('0x1c')](respondWithResult(_0x3072fd,null))[_0x0694('0x16')](handleError(_0x3072fd,null));};exports['showVoiceQueues']=function(_0x465717,_0x1046b8){return respondWithRpcPromise('VoiceQueues',_0x465717[_0x0694('0x15')])['then'](findById(_0x465717[_0x0694('0x19')]['id']))['then'](respondWithResult(_0x1046b8,null))['catch'](handleError(_0x1046b8,null));};exports[_0x0694('0x1f')]=function(_0x5250c9,_0x5675be){return respondWithRpcPromise('UpdateVoiceQueue',_[_0x0694('0x18')](_0x5250c9[_0x0694('0x20')],_0x5250c9[_0x0694('0x19')]))[_0x0694('0x1c')](respondWithResult(_0x5675be,null))[_0x0694('0x16')](handleError(_0x5675be,null));};exports['voiceQueuesPreview']=function(_0x2596e7,_0x3c43ac){return respondWithRpcPromise(_0x0694('0x21'),_[_0x0694('0x18')](_0x2596e7['query'],_0x2596e7['params']))[_0x0694('0x1c')](respondWithResult(_0x3c43ac,null))[_0x0694('0x16')](handleError(_0x3c43ac,null));};exports[_0x0694('0x22')]=function(_0x24b33e,_0x4f3274){return respondWithRpcPromise(_0x0694('0x23'),_0x24b33e[_0x0694('0x15')])['then'](respondWithResult(_0x4f3274,null))['catch'](handleError(_0x4f3274,null));};exports['voiceQueuesChannel']=function(_0x1077b1,_0x1414ec){return respondWithRpcPromise('VoiceQueuesChannel',_[_0x0694('0x18')](_0x1077b1[_0x0694('0x15')],_0x1077b1[_0x0694('0x19')]))['then'](respondWithResult(_0x1414ec,null))['catch'](handleError(_0x1414ec,null));};exports['voiceQueuesChannelHangup']=function(_0x41238c,_0x7b6e9){return respondWithRpcPromise(_0x0694('0x24'),_[_0x0694('0x18')](_0x41238c[_0x0694('0x15')],_0x41238c['params']))[_0x0694('0x1c')](respondWithResult(_0x7b6e9,null))[_0x0694('0x16')](handleError(_0x7b6e9,null));};exports[_0x0694('0x25')]=function(_0x4327a5,_0x4b8ebb){return respondWithRpcPromise(_0x0694('0x26'),_['merge'](_0x4327a5[_0x0694('0x15')],_0x4327a5['params']))[_0x0694('0x1c')](respondWithResult(_0x4b8ebb,null))[_0x0694('0x16')](handleError(_0x4b8ebb,null));};exports['outbound']=function(_0x2f75cd,_0x54db68){return respondWithRpcPromise(_0x0694('0x27'),_0x2f75cd['query'])['then'](respondWithResult(_0x54db68,null))[_0x0694('0x16')](handleError(_0x54db68,null));};exports[_0x0694('0x28')]=function(_0x5d2552,_0x344608){return respondWithRpcPromise(_0x0694('0x29'),_0x5d2552['query'])[_0x0694('0x1c')](respondWithResult(_0x344608,null))['catch'](handleError(_0x344608,null));};exports[_0x0694('0x2a')]=function(_0x4e053f,_0x5f0cd0){var _0x30e183;return respondWithRpcPromise('Agents',_0x4e053f[_0x0694('0x15')])[_0x0694('0x1c')](function(_0x3d8e6e){_0x30e183=_0x3d8e6e;return respondWithRpcPromise(_0x0694('0x2b'),_0x4e053f[_0x0694('0x15')],routingClient);})[_0x0694('0x1c')](function(_0x78e849){return _[_0x0694('0x18')]({},_0x78e849,_0x30e183);})[_0x0694('0x1c')](respondWithResult(_0x5f0cd0,null))['catch'](handleError(_0x5f0cd0,null));};exports[_0x0694('0x2c')]=function(_0x537d7d,_0x5befcd){if(_0x537d7d[_0x0694('0x20')]&&_0x537d7d[_0x0694('0x20')]['interaction']&&_0x537d7d[_0x0694('0x2d')]&&_0x537d7d[_0x0694('0x2d')][_0x0694('0xf')]){for(var _0x32e8de in _0x537d7d[_0x0694('0x20')][_0x0694('0x2e')]){if(_0x537d7d[_0x0694('0x20')]['interaction']['hasOwnProperty'](_0x32e8de)){db[_0x0694('0x2f')][_0x0694('0x30')]({'where':{'channel':_0x32e8de,'membername':_0x537d7d['user']['name'],'type':_0x0694('0x31'),'exitAt':null,'uniqueid':_0x537d7d['body']['interaction'][_0x32e8de]&&_0x537d7d[_0x0694('0x20')]['interaction'][_0x32e8de][_0x0694('0x32')]?{'$notIn':_0x537d7d[_0x0694('0x20')][_0x0694('0x2e')][_0x32e8de]}:{'$ne':null}}})[_0x0694('0x1c')](function(_0x2e2a65){var _0x4b6136=moment()[_0x0694('0x33')](_0x0694('0x34'));for(var _0xbce758=0x0,_0x41e84b=_0x2e2a65[_0x0694('0x32')];_0xbce758<_0x41e84b;_0xbce758+=0x1){_0x2e2a65[_0xbce758][_0x0694('0x35')]({'exitAt':_0x4b6136});}});for(var _0x9d70e7=0x0;_0x9d70e7<_0x537d7d[_0x0694('0x20')][_0x0694('0x2e')][_0x32e8de]['length'];_0x9d70e7+=0x1){db[_0x0694('0x2f')][_0x0694('0x36')]({'where':{'channel':_0x32e8de,'membername':_0x537d7d[_0x0694('0x2d')][_0x0694('0xf')],'type':'INTERACTION','uniqueid':_0x537d7d['body'][_0x0694('0x2e')][_0x32e8de][_0x9d70e7],'exitAt':null},'defaults':{'channel':_0x32e8de,'membername':_0x537d7d['user'][_0x0694('0xf')],'interface':_[_0x0694('0x11')](_0x537d7d[_0x0694('0x2d')]['interface'])?util[_0x0694('0x33')](_0x0694('0x37'),_0x537d7d[_0x0694('0x2d')][_0x0694('0xf')]):_0x537d7d[_0x0694('0x2d')]['interface'],'type':_0x0694('0x31'),'enterAt':moment()[_0x0694('0x33')](_0x0694('0x34')),'role':_0x0694('0x38'),'internal':_0x537d7d[_0x0694('0x2d')][_0x0694('0x39')],'uniqueid':_0x537d7d[_0x0694('0x20')][_0x0694('0x2e')][_0x32e8de][_0x9d70e7]}});}}}}return respondWithRpcPromise('AgentCapacity',{'id':_0x537d7d[_0x0694('0x19')]['id'],'capacity':_0x537d7d[_0x0694('0x20')]['capacity']},routingClient)[_0x0694('0x1c')](respondWithResult(_0x5befcd,null))[_0x0694('0x16')](handleError(_0x5befcd,null));};exports[_0x0694('0x3a')]=function(_0x5e445e,_0x5857c0){return respondWithRpcPromise(_0x0694('0x3b'),_0x5e445e[_0x0694('0x15')])[_0x0694('0x1c')](respondWithResult(_0x5857c0,null))[_0x0694('0x16')](handleError(_0x5857c0,null));};exports[_0x0694('0x3c')]=function(_0x2c3628,_0x8cb397){return respondWithRpcPromise(_0x0694('0x3d'),_0x2c3628[_0x0694('0x15')])[_0x0694('0x1c')](respondWithResult(_0x8cb397,null))[_0x0694('0x16')](handleError(_0x8cb397,null));};exports[_0x0694('0x3e')]=function(_0x307786,_0x2af378){return respondWithRpcPromise('Campaigns',_0x307786[_0x0694('0x15')])[_0x0694('0x1c')](respondWithResult(_0x2af378,null))[_0x0694('0x16')](handleError(_0x2af378,null));};exports['chatQueues']=function(_0x34e254,_0x250f30){return respondWithRpcPromise(_0x0694('0x3f'),_0x34e254[_0x0694('0x15')],routingClient)[_0x0694('0x1c')](respondWithResult(_0x250f30,null))[_0x0694('0x16')](handleError(_0x250f30,null));};exports[_0x0694('0x40')]=function(_0x3169ea,_0x1e123e){return respondWithRpcPromise(_0x0694('0x3f'),_0x3169ea[_0x0694('0x15')],routingClient)['then'](findById(_0x3169ea[_0x0694('0x19')]['id']))[_0x0694('0x1c')](respondWithResult(_0x1e123e,null))[_0x0694('0x16')](handleError(_0x1e123e,null));};exports['mailQueues']=function(_0x5d1fda,_0x5aaf50){return respondWithRpcPromise(_0x0694('0x41'),_0x5d1fda[_0x0694('0x15')],routingClient)[_0x0694('0x1c')](respondWithResult(_0x5aaf50,null))[_0x0694('0x16')](handleError(_0x5aaf50,null));};exports[_0x0694('0x42')]=function(_0xf20409,_0x4c7bff){return respondWithRpcPromise('MailQueues',_0xf20409[_0x0694('0x15')],routingClient)[_0x0694('0x1c')](findById(_0xf20409[_0x0694('0x19')]['id']))['then'](respondWithResult(_0x4c7bff,null))[_0x0694('0x16')](handleError(_0x4c7bff,null));};exports[_0x0694('0x43')]=function(_0x320ae3,_0x40a45f){return respondWithRpcPromise(_0x0694('0x44'),_0x320ae3[_0x0694('0x15')],mailClient)['then'](respondWithResult(_0x40a45f,null))[_0x0694('0x16')](handleError(_0x40a45f,null));};exports[_0x0694('0x45')]=function(_0x4e17df,_0x4b33b1){return respondWithRpcPromise('OpenchannelQueues',_0x4e17df['query'],routingClient)[_0x0694('0x1c')](respondWithResult(_0x4b33b1,null))['catch'](handleError(_0x4b33b1,null));};exports[_0x0694('0x46')]=function(_0x1dfb58,_0x5b3b69){return respondWithRpcPromise('OpenchannelQueues',_0x1dfb58[_0x0694('0x15')],routingClient)[_0x0694('0x1c')](findById(_0x1dfb58[_0x0694('0x19')]['id']))[_0x0694('0x1c')](respondWithResult(_0x5b3b69,null))[_0x0694('0x16')](handleError(_0x5b3b69,null));};exports[_0x0694('0x47')]=function(_0x2e2380,_0x5c310d){return respondWithRpcPromise(_0x0694('0x48'),_0x2e2380[_0x0694('0x15')],routingClient)[_0x0694('0x1c')](respondWithResult(_0x5c310d,null))[_0x0694('0x16')](handleError(_0x5c310d,null));};exports['showSmsQueues']=function(_0x39481a,_0x27a8bf){return respondWithRpcPromise(_0x0694('0x48'),_0x39481a[_0x0694('0x15')],routingClient)[_0x0694('0x1c')](findById(_0x39481a[_0x0694('0x19')]['id']))[_0x0694('0x1c')](respondWithResult(_0x27a8bf,null))['catch'](handleError(_0x27a8bf,null));};exports['whatsappQueues']=function(_0x20975b,_0x2f57ec){return respondWithRpcPromise('WhatsappQueues',_0x20975b[_0x0694('0x15')],routingClient)['then'](respondWithResult(_0x2f57ec,null))[_0x0694('0x16')](handleError(_0x2f57ec,null));};exports[_0x0694('0x49')]=function(_0x395bd7,_0x33b3aa){return respondWithRpcPromise('WhatsappQueues',_0x395bd7[_0x0694('0x15')],routingClient)['then'](findById(_0x395bd7[_0x0694('0x19')]['id']))[_0x0694('0x1c')](respondWithResult(_0x33b3aa,null))[_0x0694('0x16')](handleError(_0x33b3aa,null));};exports['faxQueues']=function(_0x210ae8,_0x416b30){return respondWithRpcPromise('FaxQueues',_0x210ae8[_0x0694('0x15')],routingClient)[_0x0694('0x1c')](respondWithResult(_0x416b30,null))[_0x0694('0x16')](handleError(_0x416b30,null));};exports['showFaxQueues']=function(_0x355148,_0x15883d){return respondWithRpcPromise(_0x0694('0x4a'),_0x355148['query'],routingClient)[_0x0694('0x1c')](findById(_0x355148[_0x0694('0x19')]['id']))[_0x0694('0x1c')](respondWithResult(_0x15883d,null))[_0x0694('0x16')](handleError(_0x15883d,null));};exports[_0x0694('0x4b')]=function(_0x9c1272,_0x3ff258){return respondWithRpcPromise('FaxAccounts',_0x9c1272[_0x0694('0x15')])[_0x0694('0x1c')](respondWithResult(_0x3ff258,null))[_0x0694('0x16')](handleError(_0x3ff258,null));};exports[_0x0694('0x4c')]=function(_0x2b50e9,_0x565d4d){return respondWithRpcPromise(_0x0694('0x4d'),_0x2b50e9[_0x0694('0x15')],routingClient)['then'](respondWithResult(_0x565d4d,null))['catch'](handleError(_0x565d4d,null));};exports[_0x0694('0x4e')]=function(_0x21d5f6,_0x32282e){return respondWithRpcPromise(_0x0694('0x4f'),_0x21d5f6[_0x0694('0x15')],routingClient)[_0x0694('0x1c')](respondWithResult(_0x32282e,null))['catch'](handleError(_0x32282e,null));};exports[_0x0694('0x50')]=function(_0x456b8d,_0x1f728b){return respondWithRpcPromise(_0x0694('0x51'),_0x456b8d[_0x0694('0x15')],routingClient)[_0x0694('0x1c')](respondWithResult(_0x1f728b,null))[_0x0694('0x16')](handleError(_0x1f728b,null));};exports[_0x0694('0x52')]=function(_0x444355,_0x597955){return respondWithRpcPromise(_0x0694('0x51'),_0x444355[_0x0694('0x15')],routingClient)[_0x0694('0x1c')](function(_0x257fd2){if(_0x444355[_0x0694('0x15')][_0x0694('0x53')]!==undefined){var _0x79d00e=_(_0x257fd2[_0x0694('0x54')])[_0x0694('0x55')]([_0x444355[_0x0694('0x15')]['type'],_0x444355[_0x0694('0x19')]['id']])[_0x0694('0x56')](_0x0694('0x57'))[_0x0694('0x58')]()[_0x0694('0x59')]();return _0x257fd2[_0x0694('0x54')]['filter'](function(_0x199c47){return _0x79d00e[_0x0694('0x5a')](_0x199c47[_0x0694('0x57')])>-0x1;});}else{return _0x257fd2[_0x0694('0x54')][_0x0694('0x55')](function(_0x57cbb1){return _0x57cbb1['queue_id']===parseInt(_0x444355[_0x0694('0x19')]['id']);});}})[_0x0694('0x1c')](respondWithResult(_0x597955,null))[_0x0694('0x16')](handleError(_0x597955,null));};exports[_0x0694('0x5b')]=function(_0x4ed7c4,_0x48f923){return respondWithRpcPromise(_0x0694('0x5c'),_0x4ed7c4[_0x0694('0x15')],routingClient)[_0x0694('0x1c')](respondWithResult(_0x48f923,null))[_0x0694('0x16')](handleError(_0x48f923,null));};exports['whatsappQueuesWaitingInteractions']=function(_0x13d8a3,_0x39a561){return respondWithRpcPromise(_0x0694('0x5d'),_0x13d8a3[_0x0694('0x15')],routingClient)['then'](respondWithResult(_0x39a561,null))[_0x0694('0x16')](handleError(_0x39a561,null));};exports[_0x0694('0x5e')]=function(_0x5c53bd,_0x31d14c){return respondWithRpcPromise(_0x0694('0x5f'),_0x5c53bd[_0x0694('0x15')],routingClient)[_0x0694('0x1c')](respondWithResult(_0x31d14c,null))['catch'](handleError(_0x31d14c,null));};exports[_0x0694('0x60')]=function(_0x413ed7){return function(_0x34cdf8,_0x1c12f4){var _0x36dd1e,_0x461a6d;var _0x120001=_[_0x0694('0x61')](_0x413ed7);var _0x3f43ce=_0x413ed7===_0x0694('0x62')?_0x0694('0x63'):'Account';return db[_0x120001+_0x0694('0x64')][_0x0694('0x65')]({'raw':!![],'where':{'id':_0x34cdf8[_0x0694('0x19')]['id']}})[_0x0694('0x1c')](function(_0x3b50f3){if(_['isNil'](_0x3b50f3)){throw new Error(_0x120001+_0x0694('0x66'));}_0x36dd1e=_0x3b50f3;return db[_0x120001+_0x0694('0x67')]['findOne']({'where':{'id':_0x34cdf8[_0x0694('0x20')][_0x0694('0x68')]},'include':[{'model':db[_0x120001+_0x0694('0x69')],'as':_0x0694('0x69')},{'model':db[_0x120001+_0x3f43ce],'as':_0x0694('0x6a')}]});})['then'](function(_0x4f8d66){if(_[_0x0694('0x11')](_0x4f8d66)){throw new Error(_0x120001+'\x20Message\x20not\x20found');}_0x461a6d=_0x4f8d66;return _0x4f8d66[_0x0694('0x6b')]({'read':0x0,'readAt':null,'UserId':null});})[_0x0694('0x1c')](function(){var _0x128640={'uniqueid':_0x413ed7+'.'+_0x461a6d['id']+'.'+_0x461a6d['Interaction']['id'],'FromUserId':_0x34cdf8[_0x0694('0x2d')]['id'],'type':_0x0694('0x6c')};_0x128640[_0x120001+_0x0694('0x6d')]=_0x461a6d['id'];_0x128640[_0x120001+'InteractionId']=_0x461a6d['Interaction']['id'];_0x128640[_0x0694('0x6e')+_0x120001+_0x3f43ce+'Id']=_0x461a6d['Account']['id'];_0x128640['To'+_0x120001+_0x0694('0x6f')]=_0x36dd1e['id'];return db[_0x120001+_0x0694('0x70')][_0x0694('0x71')](_0x128640);})[_0x0694('0x1c')](function(){return respondWithRpcPromise('Start',{'channel':_0x413ed7,'interaction':_0x461a6d['Interaction'],'message':_0x461a6d,'account':_0x461a6d['Account'],'applications':[{'id':0x0,'priority':0x1,'app':_0x0694('0x6c'),'appdata':_0x36dd1e[_0x0694('0xf')]+','+(_0x461a6d[_0x0694('0x6a')][_0x0694('0x72')]||0x12c),'interval':_0x0694('0x73')}]},routingClient);})[_0x0694('0x1c')](respondWithResult(_0x1c12f4,null))['catch'](handleError(_0x1c12f4,null));};};exports['agentNotify']=function(_0x25245b,_0x1969dc){var _0x421b4e,_0x5d5733;if(_['isNil'](_0x25245b[_0x0694('0x20')]['channel'])){throw new Error(_0x0694('0x74'));}var _0x21a424=_0x25245b['body'][_0x0694('0x75')];var _0x448c72=_[_0x0694('0x61')](_0x21a424);var _0x5110b2=_0x21a424===_0x0694('0x62')?_0x0694('0x63'):_0x0694('0x6a');return db[_0x0694('0x76')]['findOne']({'raw':!![],'where':{'id':_0x25245b[_0x0694('0x19')]['id'],'role':'agent'}})[_0x0694('0x1c')](function(_0x111022){if(_[_0x0694('0x11')](_0x111022)){throw new Error(_0x0694('0x77'));}_0x421b4e=_0x111022;return db[_0x448c72+_0x0694('0x67')]['findOne']({'where':{'id':_0x25245b['body'][_0x0694('0x68')]},'include':[{'model':db[_0x448c72+'Interaction'],'as':'Interaction'},{'model':db[_0x448c72+_0x5110b2],'as':'Account'}]});})[_0x0694('0x1c')](function(_0x3f13a8){if(_[_0x0694('0x11')](_0x3f13a8)){throw new Error(_0x448c72+'\x20Message\x20not\x20found');}_0x5d5733=_0x3f13a8;return _0x3f13a8[_0x0694('0x6b')]({'read':0x0,'readAt':null,'UserId':null});})['then'](function(){var _0x41d8a0={'uniqueid':_0x21a424+'.'+_0x5d5733['id']+'.'+_0x5d5733[_0x0694('0x69')]['id'],'FromUserId':_0x25245b[_0x0694('0x2d')]['id'],'type':'agent','ToUserId':_0x421b4e['id']};_0x41d8a0[_0x448c72+'MessageId']=_0x5d5733['id'];_0x41d8a0[_0x448c72+_0x0694('0x78')]=_0x5d5733['Interaction']['id'];_0x41d8a0[_0x0694('0x6e')+_0x448c72+_0x5110b2+'Id']=_0x5d5733['Account']['id'];return db[_0x448c72+_0x0694('0x70')][_0x0694('0x71')](_0x41d8a0);})[_0x0694('0x1c')](function(){return respondWithRpcPromise('Start',{'channel':_0x21a424,'interaction':_0x5d5733[_0x0694('0x69')],'message':_0x5d5733,'account':_0x5d5733['Account'],'applications':[{'id':0x0,'priority':0x1,'app':'agent','appdata':_0x421b4e[_0x0694('0xf')]+','+(_0x5d5733[_0x0694('0x6a')][_0x0694('0x79')]||0x12c),'interval':_0x0694('0x73')}]},routingClient);})[_0x0694('0x1c')](respondWithResult(_0x1969dc,null))[_0x0694('0x16')](handleError(_0x1969dc,null));};