3ab59476a0c429ba70d74d4c7f91870d48a072c3
[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 _0x738b=['Trunks','campaigns','Campaigns','chatQueues','showChatQueues','ChatQueues','MailQueues','showMailQueues','mailAccounts','MailAccounts','openchannelQueues','OpenchannelQueues','showOpenchannelQueues','smsQueues','SmsQueues','whatsappQueues','WhatsappQueues','showWhatsappQueues','faxQueues','FaxQueues','showFaxQueues','FaxAccounts','chatQueuesWaitingInteractions','ChatQueuesWaitingInteractions','mailQueuesWaitingInteractions','MailQueuesWaitingInteractions','OpenchannelQueuesWaitingInteractions','type','filter','map','queue_id','uniq','value','smsQueuesWaitingInteractions','SmsQueuesWaitingInteractions','whatsappQueuesWaitingInteractions','faxQueuesWaitingInteractions','FaxQueuesWaitingInteractions','queueNotify','capitalize','Account','Queue','findOne','Message','messageId','Interaction','\x20Message\x20not\x20found','update','queue','MessageId','From','QueueId','TransferReport','create','queueTransferTimeout','*,*,*,*','channel','chat','Website','User','Agent\x20not\x20found','Start','bluebird','moment','lodash','../../mysqldb','../../config/logger','api','jayson/promise','client','http','request','then','error','code','message','result','catch','status','json','sendStatus','stack','name','send','isNil','find','rows','voiceChannels','query','VoiceChannelMixMonitor','merge','params','voiceChannelStopMixMonitor','VoiceChannelStopMixMonitor','voiceQueues','VoiceQueues','showVoiceQueues','updateVoiceQueue','body','voiceQueuesPreview','voiceQueuesChannels','VoiceQueuesChannels','voiceQueuesChannel','voiceQueuesChannelHangup','VoiceQueuesChannelHangup','voiceQueuesChannelRedirect','VoiceQueuesChannelRedirect','outboundChannels','OutboundChannels','Agents','agentCapacity','user','hasOwnProperty','MemberReport','findAll','INTERACTION','interaction','length','format','YYYY-MM-DD\x20HH:mm:ss','SIP/%s','interface','agent','internal','AgentCapacity','capacity','telephones','Telephones','trunks'];(function(_0x5a111d,_0x56422a){var _0x404bfd=function(_0x282063){while(--_0x282063){_0x5a111d['push'](_0x5a111d['shift']());}};_0x404bfd(++_0x56422a);}(_0x738b,0x1c1));var _0xb738=function(_0xb987b7,_0x44b4e4){_0xb987b7=_0xb987b7-0x0;var _0x2efdbb=_0x738b[_0xb987b7];return _0x2efdbb;};'use strict';var BPromise=require(_0xb738('0x0'));var moment=require(_0xb738('0x1'));var _=require(_0xb738('0x2'));var util=require('util');var db=require(_0xb738('0x3'))['db'];var logger=require(_0xb738('0x4'))(_0xb738('0x5'));var jayson=require(_0xb738('0x6'));var amiClient=jayson[_0xb738('0x7')][_0xb738('0x8')]({'port':0x232a});var mailClient=jayson[_0xb738('0x7')][_0xb738('0x8')]({'port':0x232b});var routingClient=jayson[_0xb738('0x7')]['http']({'port':0x232c});function respondWithRpcPromise(_0x461c4e,_0x340325,_0x119c91){return new BPromise(function(_0x9ec59c,_0x1ec7f0){var _0x2345df=_0x119c91?_0x119c91:amiClient;return _0x2345df[_0xb738('0x9')](_0x461c4e,_0x340325)[_0xb738('0xa')](function(_0x4993aa){if(_0x4993aa[_0xb738('0xb')]){if(_0x4993aa['error'][_0xb738('0xc')]===0x1f4){return _0x1ec7f0(_0x4993aa[_0xb738('0xb')][_0xb738('0xd')]);}return _0x9ec59c(_0x4993aa[_0xb738('0xb')][_0xb738('0xd')]);}else{_0x9ec59c(_0x4993aa[_0xb738('0xe')]);}})[_0xb738('0xf')](function(_0x406138){_0x1ec7f0(_0x406138);});});}function respondWithResult(_0x3b1a7e,_0x5e33da){_0x5e33da=_0x5e33da||0xc8;return function(_0x1e92c0){if(_0x1e92c0){return _0x3b1a7e[_0xb738('0x10')](_0x5e33da)[_0xb738('0x11')](_0x1e92c0);}return _0x3b1a7e[_0xb738('0x12')](0x194);};}function handleError(_0x2cf435,_0x6cc3f){_0x6cc3f=_0x6cc3f||0x1f4;return function(_0x21b6ff){logger[_0xb738('0xb')](_0x21b6ff[_0xb738('0x13')]);if(_0x21b6ff['name']){delete _0x21b6ff[_0xb738('0x14')];}_0x2cf435[_0xb738('0x10')](_0x6cc3f)[_0xb738('0x15')](_0x21b6ff);};}function findById(_0x1aac31){return function(_0xfc18f7){if(!_[_0xb738('0x16')](_0x1aac31)&&!_[_0xb738('0x16')](_0xfc18f7)&&!_[_0xb738('0x16')](_0xfc18f7['rows'])){return _[_0xb738('0x17')](_0xfc18f7[_0xb738('0x18')],function(_0x3e6afe){return _0x3e6afe['id']==_0x1aac31;});}return null;};}exports[_0xb738('0x19')]=function(_0x462501,_0x12d650){return respondWithRpcPromise('VoiceChannels',_0x462501[_0xb738('0x1a')])['then'](respondWithResult(_0x12d650,null))[_0xb738('0xf')](handleError(_0x12d650,null));};exports['voiceChannelMixMonitor']=function(_0x314717,_0x20d8bc){return respondWithRpcPromise(_0xb738('0x1b'),_[_0xb738('0x1c')](_0x314717[_0xb738('0x1a')],_0x314717[_0xb738('0x1d')]))[_0xb738('0xa')](respondWithResult(_0x20d8bc,null))[_0xb738('0xf')](handleError(_0x20d8bc,null));};exports[_0xb738('0x1e')]=function(_0x31e1c1,_0x5e9653){return respondWithRpcPromise(_0xb738('0x1f'),_[_0xb738('0x1c')](_0x31e1c1[_0xb738('0x1a')],_0x31e1c1[_0xb738('0x1d')]))[_0xb738('0xa')](respondWithResult(_0x5e9653,null))[_0xb738('0xf')](handleError(_0x5e9653,null));};exports[_0xb738('0x20')]=function(_0x43d972,_0x523d30){return respondWithRpcPromise(_0xb738('0x21'),_0x43d972[_0xb738('0x1a')])[_0xb738('0xa')](respondWithResult(_0x523d30,null))[_0xb738('0xf')](handleError(_0x523d30,null));};exports[_0xb738('0x22')]=function(_0x1cdd3a,_0x1299cb){return respondWithRpcPromise(_0xb738('0x21'),_0x1cdd3a['query'])[_0xb738('0xa')](findById(_0x1cdd3a[_0xb738('0x1d')]['id']))['then'](respondWithResult(_0x1299cb,null))[_0xb738('0xf')](handleError(_0x1299cb,null));};exports[_0xb738('0x23')]=function(_0x21c232,_0x4deb2b){return respondWithRpcPromise('UpdateVoiceQueue',_[_0xb738('0x1c')](_0x21c232[_0xb738('0x24')],_0x21c232[_0xb738('0x1d')]))[_0xb738('0xa')](respondWithResult(_0x4deb2b,null))[_0xb738('0xf')](handleError(_0x4deb2b,null));};exports[_0xb738('0x25')]=function(_0x27edad,_0x5c1728){return respondWithRpcPromise('VoiceQueuesPreview',_['merge'](_0x27edad[_0xb738('0x1a')],_0x27edad['params']))[_0xb738('0xa')](respondWithResult(_0x5c1728,null))[_0xb738('0xf')](handleError(_0x5c1728,null));};exports[_0xb738('0x26')]=function(_0x2404cf,_0x124ff5){return respondWithRpcPromise(_0xb738('0x27'),_0x2404cf[_0xb738('0x1a')])[_0xb738('0xa')](respondWithResult(_0x124ff5,null))[_0xb738('0xf')](handleError(_0x124ff5,null));};exports[_0xb738('0x28')]=function(_0x41ffb4,_0x769b9){return respondWithRpcPromise('VoiceQueuesChannel',_[_0xb738('0x1c')](_0x41ffb4['query'],_0x41ffb4['params']))[_0xb738('0xa')](respondWithResult(_0x769b9,null))['catch'](handleError(_0x769b9,null));};exports[_0xb738('0x29')]=function(_0x3c57b7,_0x3c6991){return respondWithRpcPromise(_0xb738('0x2a'),_[_0xb738('0x1c')](_0x3c57b7[_0xb738('0x1a')],_0x3c57b7['params']))[_0xb738('0xa')](respondWithResult(_0x3c6991,null))[_0xb738('0xf')](handleError(_0x3c6991,null));};exports[_0xb738('0x2b')]=function(_0x30400d,_0x1a35ac){return respondWithRpcPromise(_0xb738('0x2c'),_[_0xb738('0x1c')](_0x30400d['query'],_0x30400d[_0xb738('0x1d')]))['then'](respondWithResult(_0x1a35ac,null))[_0xb738('0xf')](handleError(_0x1a35ac,null));};exports['outbound']=function(_0x516194,_0x274aff){return respondWithRpcPromise('Outbound',_0x516194[_0xb738('0x1a')])['then'](respondWithResult(_0x274aff,null))[_0xb738('0xf')](handleError(_0x274aff,null));};exports[_0xb738('0x2d')]=function(_0xd0668e,_0x2f7787){return respondWithRpcPromise(_0xb738('0x2e'),_0xd0668e[_0xb738('0x1a')])[_0xb738('0xa')](respondWithResult(_0x2f7787,null))[_0xb738('0xf')](handleError(_0x2f7787,null));};exports['agents']=function(_0x26c4f6,_0x11e547){var _0x17df5e;return respondWithRpcPromise(_0xb738('0x2f'),_0x26c4f6[_0xb738('0x1a')])[_0xb738('0xa')](function(_0x4f932f){_0x17df5e=_0x4f932f;return respondWithRpcPromise('Agents',_0x26c4f6[_0xb738('0x1a')],routingClient);})['then'](function(_0x2036c5){return _[_0xb738('0x1c')]({},_0x2036c5,_0x17df5e);})[_0xb738('0xa')](respondWithResult(_0x11e547,null))[_0xb738('0xf')](handleError(_0x11e547,null));};exports[_0xb738('0x30')]=function(_0x5cfcaf,_0x403a27){if(_0x5cfcaf[_0xb738('0x24')]&&_0x5cfcaf[_0xb738('0x24')]['interaction']&&_0x5cfcaf[_0xb738('0x31')]&&_0x5cfcaf['user']['name']){for(var _0xded48c in _0x5cfcaf[_0xb738('0x24')]['interaction']){if(_0x5cfcaf[_0xb738('0x24')]['interaction'][_0xb738('0x32')](_0xded48c)){db[_0xb738('0x33')][_0xb738('0x34')]({'where':{'channel':_0xded48c,'membername':_0x5cfcaf[_0xb738('0x31')][_0xb738('0x14')],'type':_0xb738('0x35'),'exitAt':null,'uniqueid':_0x5cfcaf[_0xb738('0x24')][_0xb738('0x36')][_0xded48c]&&_0x5cfcaf[_0xb738('0x24')][_0xb738('0x36')][_0xded48c][_0xb738('0x37')]?{'$notIn':_0x5cfcaf[_0xb738('0x24')][_0xb738('0x36')][_0xded48c]}:{'$ne':null}}})[_0xb738('0xa')](function(_0x34f473){var _0x2f27a3=moment()[_0xb738('0x38')](_0xb738('0x39'));for(var _0x5e1df3=0x0,_0x10ed96=_0x34f473[_0xb738('0x37')];_0x5e1df3<_0x10ed96;_0x5e1df3+=0x1){_0x34f473[_0x5e1df3]['updateAttributes']({'exitAt':_0x2f27a3});}});for(var _0x4d54a8=0x0;_0x4d54a8<_0x5cfcaf[_0xb738('0x24')][_0xb738('0x36')][_0xded48c][_0xb738('0x37')];_0x4d54a8+=0x1){db[_0xb738('0x33')]['findOrCreate']({'where':{'channel':_0xded48c,'membername':_0x5cfcaf[_0xb738('0x31')][_0xb738('0x14')],'type':_0xb738('0x35'),'uniqueid':_0x5cfcaf[_0xb738('0x24')][_0xb738('0x36')][_0xded48c][_0x4d54a8],'exitAt':null},'defaults':{'channel':_0xded48c,'membername':_0x5cfcaf['user'][_0xb738('0x14')],'interface':_[_0xb738('0x16')](_0x5cfcaf[_0xb738('0x31')]['interface'])?util[_0xb738('0x38')](_0xb738('0x3a'),_0x5cfcaf[_0xb738('0x31')]['name']):_0x5cfcaf[_0xb738('0x31')][_0xb738('0x3b')],'type':_0xb738('0x35'),'enterAt':moment()[_0xb738('0x38')]('YYYY-MM-DD\x20HH:mm:ss'),'role':_0xb738('0x3c'),'internal':_0x5cfcaf['user'][_0xb738('0x3d')],'uniqueid':_0x5cfcaf['body']['interaction'][_0xded48c][_0x4d54a8]}});}}}}return respondWithRpcPromise(_0xb738('0x3e'),{'id':_0x5cfcaf[_0xb738('0x1d')]['id'],'capacity':_0x5cfcaf[_0xb738('0x24')][_0xb738('0x3f')]},routingClient)['then'](respondWithResult(_0x403a27,null))['catch'](handleError(_0x403a27,null));};exports[_0xb738('0x40')]=function(_0x36d605,_0x3e9ee5){return respondWithRpcPromise(_0xb738('0x41'),_0x36d605[_0xb738('0x1a')])['then'](respondWithResult(_0x3e9ee5,null))['catch'](handleError(_0x3e9ee5,null));};exports[_0xb738('0x42')]=function(_0x4c3dba,_0x2e96e2){return respondWithRpcPromise(_0xb738('0x43'),_0x4c3dba[_0xb738('0x1a')])[_0xb738('0xa')](respondWithResult(_0x2e96e2,null))[_0xb738('0xf')](handleError(_0x2e96e2,null));};exports[_0xb738('0x44')]=function(_0x3d11e7,_0x456236){return respondWithRpcPromise(_0xb738('0x45'),_0x3d11e7[_0xb738('0x1a')])[_0xb738('0xa')](respondWithResult(_0x456236,null))['catch'](handleError(_0x456236,null));};exports[_0xb738('0x46')]=function(_0x1a1ffa,_0x40dd9b){return respondWithRpcPromise('ChatQueues',_0x1a1ffa['query'],routingClient)[_0xb738('0xa')](respondWithResult(_0x40dd9b,null))[_0xb738('0xf')](handleError(_0x40dd9b,null));};exports[_0xb738('0x47')]=function(_0x570ee0,_0x5cc3ba){return respondWithRpcPromise(_0xb738('0x48'),_0x570ee0[_0xb738('0x1a')],routingClient)[_0xb738('0xa')](findById(_0x570ee0[_0xb738('0x1d')]['id']))['then'](respondWithResult(_0x5cc3ba,null))['catch'](handleError(_0x5cc3ba,null));};exports['mailQueues']=function(_0x5660cd,_0x379caa){return respondWithRpcPromise(_0xb738('0x49'),_0x5660cd[_0xb738('0x1a')],routingClient)[_0xb738('0xa')](respondWithResult(_0x379caa,null))['catch'](handleError(_0x379caa,null));};exports[_0xb738('0x4a')]=function(_0x222e8e,_0x43850e){return respondWithRpcPromise(_0xb738('0x49'),_0x222e8e['query'],routingClient)[_0xb738('0xa')](findById(_0x222e8e[_0xb738('0x1d')]['id']))[_0xb738('0xa')](respondWithResult(_0x43850e,null))[_0xb738('0xf')](handleError(_0x43850e,null));};exports[_0xb738('0x4b')]=function(_0x51d6a2,_0x2574d3){return respondWithRpcPromise(_0xb738('0x4c'),_0x51d6a2[_0xb738('0x1a')],mailClient)['then'](respondWithResult(_0x2574d3,null))['catch'](handleError(_0x2574d3,null));};exports[_0xb738('0x4d')]=function(_0x4630c9,_0x2c1c37){return respondWithRpcPromise(_0xb738('0x4e'),_0x4630c9[_0xb738('0x1a')],routingClient)[_0xb738('0xa')](respondWithResult(_0x2c1c37,null))[_0xb738('0xf')](handleError(_0x2c1c37,null));};exports[_0xb738('0x4f')]=function(_0x562b4d,_0x5f1704){return respondWithRpcPromise(_0xb738('0x4e'),_0x562b4d[_0xb738('0x1a')],routingClient)['then'](findById(_0x562b4d[_0xb738('0x1d')]['id']))['then'](respondWithResult(_0x5f1704,null))['catch'](handleError(_0x5f1704,null));};exports[_0xb738('0x50')]=function(_0x59b53d,_0x345528){return respondWithRpcPromise(_0xb738('0x51'),_0x59b53d['query'],routingClient)[_0xb738('0xa')](respondWithResult(_0x345528,null))[_0xb738('0xf')](handleError(_0x345528,null));};exports['showSmsQueues']=function(_0x1587f6,_0x120107){return respondWithRpcPromise(_0xb738('0x51'),_0x1587f6['query'],routingClient)['then'](findById(_0x1587f6[_0xb738('0x1d')]['id']))['then'](respondWithResult(_0x120107,null))[_0xb738('0xf')](handleError(_0x120107,null));};exports[_0xb738('0x52')]=function(_0xfca66d,_0x5686ac){return respondWithRpcPromise(_0xb738('0x53'),_0xfca66d[_0xb738('0x1a')],routingClient)[_0xb738('0xa')](respondWithResult(_0x5686ac,null))[_0xb738('0xf')](handleError(_0x5686ac,null));};exports[_0xb738('0x54')]=function(_0x4fbcb8,_0x120f20){return respondWithRpcPromise(_0xb738('0x53'),_0x4fbcb8['query'],routingClient)[_0xb738('0xa')](findById(_0x4fbcb8[_0xb738('0x1d')]['id']))[_0xb738('0xa')](respondWithResult(_0x120f20,null))[_0xb738('0xf')](handleError(_0x120f20,null));};exports[_0xb738('0x55')]=function(_0x1af486,_0x2b9e00){return respondWithRpcPromise(_0xb738('0x56'),_0x1af486[_0xb738('0x1a')],routingClient)[_0xb738('0xa')](respondWithResult(_0x2b9e00,null))[_0xb738('0xf')](handleError(_0x2b9e00,null));};exports[_0xb738('0x57')]=function(_0x36a855,_0xcd1ae9){return respondWithRpcPromise(_0xb738('0x56'),_0x36a855[_0xb738('0x1a')],routingClient)[_0xb738('0xa')](findById(_0x36a855[_0xb738('0x1d')]['id']))[_0xb738('0xa')](respondWithResult(_0xcd1ae9,null))[_0xb738('0xf')](handleError(_0xcd1ae9,null));};exports['faxAccounts']=function(_0x574ad0,_0x507c2e){return respondWithRpcPromise(_0xb738('0x58'),_0x574ad0[_0xb738('0x1a')])[_0xb738('0xa')](respondWithResult(_0x507c2e,null))[_0xb738('0xf')](handleError(_0x507c2e,null));};exports[_0xb738('0x59')]=function(_0x391bc7,_0x4cbb30){return respondWithRpcPromise(_0xb738('0x5a'),_0x391bc7[_0xb738('0x1a')],routingClient)[_0xb738('0xa')](respondWithResult(_0x4cbb30,null))[_0xb738('0xf')](handleError(_0x4cbb30,null));};exports[_0xb738('0x5b')]=function(_0x9d50be,_0x16527f){return respondWithRpcPromise(_0xb738('0x5c'),_0x9d50be['query'],routingClient)['then'](respondWithResult(_0x16527f,null))['catch'](handleError(_0x16527f,null));};exports['openchannelQueuesWaitingInteractions']=function(_0x1dfcdb,_0x1c0991){return respondWithRpcPromise(_0xb738('0x5d'),_0x1dfcdb[_0xb738('0x1a')],routingClient)[_0xb738('0xa')](respondWithResult(_0x1c0991,null))[_0xb738('0xf')](handleError(_0x1c0991,null));};exports['openchannelQueuesIdWaitingInteractions']=function(_0x5bb0bf,_0x4a5d3c){return respondWithRpcPromise(_0xb738('0x5d'),_0x5bb0bf[_0xb738('0x1a')],routingClient)[_0xb738('0xa')](function(_0xcbb033){if(_0x5bb0bf[_0xb738('0x1a')][_0xb738('0x5e')]!==undefined){var _0x447787=_(_0xcbb033[_0xb738('0x18')])[_0xb738('0x5f')]([_0x5bb0bf[_0xb738('0x1a')][_0xb738('0x5e')],_0x5bb0bf[_0xb738('0x1d')]['id']])[_0xb738('0x60')](_0xb738('0x61'))[_0xb738('0x62')]()[_0xb738('0x63')]();return _0xcbb033[_0xb738('0x18')][_0xb738('0x5f')](function(_0xe4f638){return _0x447787['indexOf'](_0xe4f638[_0xb738('0x61')])>-0x1;});}else{return _0xcbb033[_0xb738('0x18')][_0xb738('0x5f')](function(_0x1650a2){return _0x1650a2[_0xb738('0x61')]===parseInt(_0x5bb0bf[_0xb738('0x1d')]['id']);});}})[_0xb738('0xa')](respondWithResult(_0x4a5d3c,null))[_0xb738('0xf')](handleError(_0x4a5d3c,null));};exports[_0xb738('0x64')]=function(_0x4a20ca,_0x584b4a){return respondWithRpcPromise(_0xb738('0x65'),_0x4a20ca[_0xb738('0x1a')],routingClient)['then'](respondWithResult(_0x584b4a,null))[_0xb738('0xf')](handleError(_0x584b4a,null));};exports[_0xb738('0x66')]=function(_0x17ccc7,_0x32a489){return respondWithRpcPromise('WhatsappQueuesWaitingInteractions',_0x17ccc7[_0xb738('0x1a')],routingClient)[_0xb738('0xa')](respondWithResult(_0x32a489,null))['catch'](handleError(_0x32a489,null));};exports[_0xb738('0x67')]=function(_0x14f669,_0x4d72dd){return respondWithRpcPromise(_0xb738('0x68'),_0x14f669['query'],routingClient)[_0xb738('0xa')](respondWithResult(_0x4d72dd,null))['catch'](handleError(_0x4d72dd,null));};exports[_0xb738('0x69')]=function(_0x52887b){return function(_0x389f11,_0x52ef6b){var _0x3270de,_0x128196;var _0x2d6517=_[_0xb738('0x6a')](_0x52887b);var _0xf787e1=_0x52887b==='chat'?'Website':_0xb738('0x6b');return db[_0x2d6517+_0xb738('0x6c')][_0xb738('0x6d')]({'raw':!![],'where':{'id':_0x389f11['params']['id']}})[_0xb738('0xa')](function(_0x420efc){if(_[_0xb738('0x16')](_0x420efc)){throw new Error(_0x2d6517+'\x20Queue\x20not\x20found');}_0x3270de=_0x420efc;return db[_0x2d6517+_0xb738('0x6e')][_0xb738('0x6d')]({'where':{'id':_0x389f11[_0xb738('0x24')][_0xb738('0x6f')]},'include':[{'model':db[_0x2d6517+_0xb738('0x70')],'as':'Interaction'},{'model':db[_0x2d6517+_0xf787e1],'as':_0xb738('0x6b')}]});})[_0xb738('0xa')](function(_0x110cf4){if(_[_0xb738('0x16')](_0x110cf4)){throw new Error(_0x2d6517+_0xb738('0x71'));}_0x128196=_0x110cf4;return _0x110cf4[_0xb738('0x72')]({'read':0x0,'readAt':null,'UserId':null});})['then'](function(){var _0xb1f765={'uniqueid':_0x52887b+'.'+_0x128196['id']+'.'+_0x128196[_0xb738('0x70')]['id'],'FromUserId':_0x389f11[_0xb738('0x31')]['id'],'type':_0xb738('0x73')};_0xb1f765[_0x2d6517+_0xb738('0x74')]=_0x128196['id'];_0xb1f765[_0x2d6517+'InteractionId']=_0x128196[_0xb738('0x70')]['id'];_0xb1f765[_0xb738('0x75')+_0x2d6517+_0xf787e1+'Id']=_0x128196[_0xb738('0x6b')]['id'];_0xb1f765['To'+_0x2d6517+_0xb738('0x76')]=_0x3270de['id'];return db[_0x2d6517+_0xb738('0x77')][_0xb738('0x78')](_0xb1f765);})[_0xb738('0xa')](function(){return respondWithRpcPromise('Start',{'channel':_0x52887b,'interaction':_0x128196[_0xb738('0x70')],'message':_0x128196,'account':_0x128196['Account'],'applications':[{'id':0x0,'priority':0x1,'app':_0xb738('0x73'),'appdata':_0x3270de[_0xb738('0x14')]+','+(_0x128196[_0xb738('0x6b')][_0xb738('0x79')]||0x12c),'interval':_0xb738('0x7a')}]},routingClient);})[_0xb738('0xa')](respondWithResult(_0x52ef6b,null))[_0xb738('0xf')](handleError(_0x52ef6b,null));};};exports['agentNotify']=function(_0x4559df,_0x58c3d6){var _0x46e2ba,_0x3a63ff;if(_[_0xb738('0x16')](_0x4559df[_0xb738('0x24')][_0xb738('0x7b')])){throw new Error('Channel\x20field\x20is\x20mandatory');}var _0xabe174=_0x4559df['body'][_0xb738('0x7b')];var _0x221ea1=_['capitalize'](_0xabe174);var _0x3c5211=_0xabe174===_0xb738('0x7c')?_0xb738('0x7d'):_0xb738('0x6b');return db[_0xb738('0x7e')]['findOne']({'raw':!![],'where':{'id':_0x4559df[_0xb738('0x1d')]['id'],'role':_0xb738('0x3c')}})[_0xb738('0xa')](function(_0x11a029){if(_[_0xb738('0x16')](_0x11a029)){throw new Error(_0xb738('0x7f'));}_0x46e2ba=_0x11a029;return db[_0x221ea1+'Message'][_0xb738('0x6d')]({'where':{'id':_0x4559df[_0xb738('0x24')][_0xb738('0x6f')]},'include':[{'model':db[_0x221ea1+_0xb738('0x70')],'as':_0xb738('0x70')},{'model':db[_0x221ea1+_0x3c5211],'as':_0xb738('0x6b')}]});})[_0xb738('0xa')](function(_0x3db16b){if(_[_0xb738('0x16')](_0x3db16b)){throw new Error(_0x221ea1+_0xb738('0x71'));}_0x3a63ff=_0x3db16b;return _0x3db16b[_0xb738('0x72')]({'read':0x0,'readAt':null,'UserId':null});})[_0xb738('0xa')](function(){var _0x57e45f={'uniqueid':_0xabe174+'.'+_0x3a63ff['id']+'.'+_0x3a63ff[_0xb738('0x70')]['id'],'FromUserId':_0x4559df[_0xb738('0x31')]['id'],'type':_0xb738('0x73'),'ToUserId':_0x46e2ba['id']};_0x57e45f[_0x221ea1+_0xb738('0x74')]=_0x3a63ff['id'];_0x57e45f[_0x221ea1+'InteractionId']=_0x3a63ff[_0xb738('0x70')]['id'];_0x57e45f[_0xb738('0x75')+_0x221ea1+_0x3c5211+'Id']=_0x3a63ff[_0xb738('0x6b')]['id'];return db[_0x221ea1+'TransferReport'][_0xb738('0x78')](_0x57e45f);})[_0xb738('0xa')](function(){return respondWithRpcPromise(_0xb738('0x80'),{'channel':_0xabe174,'interaction':_0x3a63ff['Interaction'],'message':_0x3a63ff,'account':_0x3a63ff[_0xb738('0x6b')],'applications':[{'id':0x0,'priority':0x1,'app':_0xb738('0x3c'),'appdata':_0x46e2ba['name']+','+(_0x3a63ff[_0xb738('0x6b')]['agentTransferTimeout']||0x12c),'interval':_0xb738('0x7a')}]},routingClient);})['then'](respondWithResult(_0x58c3d6,null))['catch'](handleError(_0x58c3d6,null));};