Built motion from commit 53172ac8.|2.6.30
[motion2.git] / server / services / ami / trigger / index.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 _0x02e3=['ChatWebsiteId','operator','value','AccountId','upperFirst','interaction','message','event','agent','membername','lastevent','routeId','mailSubstatus','null','substatus','offlineMessage','created','equals','exports','util','lodash','url','ioredis','./urlforward','./integration','./cmContact','./script','../../../config/logger','../ami','redis','localhost','socket.io-emitter','popup','triggers','agents','voiceQueues','templates','voiceExtensions','zendeskAccounts','freshdeskAccounts','salesforceAccounts','sugarcrmAccounts','zohoAccounts','deskAccounts','vtigerAccounts','servicenowAccounts','dynamics365Accounts','freshsalesAccounts','custom:agentcalled','bind','custom:agentconnect','custom:agentringnoanswer','syncCustomEvent','custom:agentnosuchnumber','custom:agentcongestion','custom:agentreject','custom:amd','custom:dialbegin','syncAgentDial','custom:dialconnect','custom:substatus','custom:incomingmessage','custom:acceptmessage','custom:offlineMessage','prototype','emit','info','stringify','clone','motionChannel','undefined','voice','debug','inspect','checkTriggers','interface','hasOwnProperty','status','checkTrigger','merge','variables','Actions','length','contactmanager','motionbar','browser','data1','TemplateId','data2','render','html','template\x20not\x20found','uri','buildUri','isNil','data3','data4','location','uriLocation','windowWidth','800','data5','windowHeight','data6','600','winapp','winApplication','winArguments','user:%s','format','trigger:%s:%s','action','toLowerCase','name','trigger:%s','integration','exec','accounts','queue','urlforward','parse','query','search','replace','channel','every','AllConditions','checkConditions','some','AnyConditions','checkTrigger:\x20trigger','evt','field','account','chat'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x02e3,0x1a8));var _0x302e=function(_0x42cae2,_0x284ef8){_0x42cae2=_0x42cae2-0x0;var _0x5f256f=_0x02e3[_0x42cae2];return _0x5f256f;};'use strict';var util=require(_0x302e('0x0'));var _=require(_0x302e('0x1'));var url=require(_0x302e('0x2'));var Mustache=require('mustache');var Redis=require(_0x302e('0x3'));var urlforward=require(_0x302e('0x4'));var integration=require(_0x302e('0x5'));var cmContact=require(_0x302e('0x6'));var script=require(_0x302e('0x7'));var config=require('../../../config/environment');var logger=require(_0x302e('0x8'))('trigger');var ami=require(_0x302e('0x9'));config[_0x302e('0xa')]=_['defaults'](config[_0x302e('0xa')],{'host':_0x302e('0xb'),'port':0x18eb});var io=require(_0x302e('0xc'))(new Redis(config[_0x302e('0xa')]));var operators={'equals':function(_0x2b29fe,_0x3d04e6){return _0x2b29fe==_0x3d04e6;},'not_equals':function(_0x38aed8,_0x211844){return _0x38aed8!=_0x211844;}};var barAndWebActions=[_0x302e('0xd'),'url','winapp'];function Trigger(_0x1c3fe4){this[_0x302e('0xe')]=_0x1c3fe4[_0x302e('0xe')];this[_0x302e('0xf')]=_0x1c3fe4[_0x302e('0xf')];this['voiceQueues']=_0x1c3fe4[_0x302e('0x10')];this[_0x302e('0x11')]=_0x1c3fe4[_0x302e('0x11')];this[_0x302e('0x12')]=_0x1c3fe4[_0x302e('0x12')];this[_0x302e('0x13')]=_0x1c3fe4[_0x302e('0x13')];this[_0x302e('0x14')]=_0x1c3fe4['freshdeskAccounts'];this[_0x302e('0x15')]=_0x1c3fe4['salesforceAccounts'];this[_0x302e('0x16')]=_0x1c3fe4[_0x302e('0x16')];this[_0x302e('0x17')]=_0x1c3fe4['zohoAccounts'];this[_0x302e('0x18')]=_0x1c3fe4[_0x302e('0x18')];this['vtigerAccounts']=_0x1c3fe4[_0x302e('0x19')];this[_0x302e('0x1a')]=_0x1c3fe4[_0x302e('0x1a')];this[_0x302e('0x1b')]=_0x1c3fe4['dynamics365Accounts'];this[_0x302e('0x1c')]=_0x1c3fe4['freshsalesAccounts'];this['accounts']={'zendesk':this[_0x302e('0x13')],'salesforce':this[_0x302e('0x15')],'freshdesk':this[_0x302e('0x14')],'sugarcrm':this[_0x302e('0x16')],'zoho':this['zohoAccounts'],'desk':this['deskAccounts'],'vtiger':this['vtigerAccounts'],'dynamics365':this['dynamics365Accounts'],'freshsales':this[_0x302e('0x1c')],'servicenow':this[_0x302e('0x1a')]};ami['on'](_0x302e('0x1d'),this['syncCustomEvent'][_0x302e('0x1e')](this));ami['on'](_0x302e('0x1f'),this['syncCustomEvent'][_0x302e('0x1e')](this));ami['on'](_0x302e('0x20'),this[_0x302e('0x21')]['bind'](this));ami['on']('custom:agentcomplete',this[_0x302e('0x21')][_0x302e('0x1e')](this));ami['on'](_0x302e('0x22'),this[_0x302e('0x21')][_0x302e('0x1e')](this));ami['on']('custom:agentnoanswer',this[_0x302e('0x21')][_0x302e('0x1e')](this));ami['on']('custom:agentbusy',this[_0x302e('0x21')][_0x302e('0x1e')](this));ami['on'](_0x302e('0x23'),this[_0x302e('0x21')][_0x302e('0x1e')](this));ami['on'](_0x302e('0x24'),this['syncCustomEvent']['bind'](this));ami['on'](_0x302e('0x25'),this[_0x302e('0x21')][_0x302e('0x1e')](this));ami['on']('custom:queuecallerabandon',this[_0x302e('0x21')][_0x302e('0x1e')](this));ami['on']('custom:timeout',this[_0x302e('0x21')][_0x302e('0x1e')](this));ami['on'](_0x302e('0x26'),this[_0x302e('0x27')][_0x302e('0x1e')](this));ami['on'](_0x302e('0x28'),this[_0x302e('0x27')]['bind'](this));ami['on']('custom:dialend',this[_0x302e('0x27')][_0x302e('0x1e')](this));ami['on']('custom:newinteraction',this[_0x302e('0x21')][_0x302e('0x1e')](this));ami['on']('custom:closedinteraction',this[_0x302e('0x21')][_0x302e('0x1e')](this));ami['on'](_0x302e('0x29'),this[_0x302e('0x21')][_0x302e('0x1e')](this));ami['on'](_0x302e('0x2a'),this['syncCustomEvent'][_0x302e('0x1e')](this));ami['on']('custom:outgoingmessage',this[_0x302e('0x21')][_0x302e('0x1e')](this));ami['on'](_0x302e('0x2b'),this['syncCustomEvent'][_0x302e('0x1e')](this));ami['on']('custom:rejectmessage',this[_0x302e('0x21')]['bind'](this));ami['on'](_0x302e('0x2c'),this[_0x302e('0x21')][_0x302e('0x1e')](this));}Trigger[_0x302e('0x2d')][_0x302e('0x2e')]=function(_0x9b885f,_0x4d636a,_0x1203c4){logger[_0x302e('0x2f')](_0x9b885f,_0x4d636a,JSON[_0x302e('0x30')](_0x1203c4));io['to'](_0x9b885f)[_0x302e('0x2e')](_0x4d636a,_0x1203c4);};Trigger[_0x302e('0x2d')][_0x302e('0x21')]=function(_0x1a8227){var _0xdc2483=_[_0x302e('0x31')](_0x1a8227);if(typeof _0xdc2483[_0x302e('0x32')]===_0x302e('0x33')){_0xdc2483[_0x302e('0x32')]=_0x302e('0x34');}logger[_0x302e('0x35')](_0x302e('0x21'),util[_0x302e('0x36')](_0xdc2483,{'showHidden':!![],'depth':null}));this[_0x302e('0x37')](_0xdc2483);};Trigger[_0x302e('0x2d')][_0x302e('0x27')]=function(_0x4cba2d){if(this[_0x302e('0xf')][_0x4cba2d[_0x302e('0x38')]]){this[_0x302e('0x21')](_0x4cba2d);}};Trigger[_0x302e('0x2d')][_0x302e('0x37')]=function(_0x1dae29){var _0x35bc54;for(var _0x5bfe58 in this[_0x302e('0xe')]){if(this[_0x302e('0xe')][_0x302e('0x39')](_0x5bfe58)){if(this[_0x302e('0xe')][_0x5bfe58][_0x302e('0x3a')]){_0x35bc54=this[_0x302e('0x3b')](this[_0x302e('0xe')][_0x5bfe58],_0x1dae29);if(_0x35bc54){_[_0x302e('0x3c')](_0x1dae29,_0x1dae29[_0x302e('0x3d')]);for(var _0x282ff8=0x0,_0x18d604,_0x337a97,_0x24ffc2;_0x282ff8<this[_0x302e('0xe')][_0x5bfe58][_0x302e('0x3e')][_0x302e('0x3f')];_0x282ff8+=0x1){_0x18d604=this[_0x302e('0xe')][_0x5bfe58][_0x302e('0x3e')][_0x282ff8];if(this['agents'][_0x1dae29[_0x302e('0x38')]]){switch(_0x18d604['action']['toLowerCase']()){case _0x302e('0x40'):break;case _0x302e('0x41'):case _0x302e('0x42'):var _0x105f77={};switch(barAndWebActions[_0x18d604[_0x302e('0x43')]]){case'popup':_0x105f77[_0x302e('0x44')]=_0x18d604['data2'];_0x105f77['html']=this[_0x302e('0x11')][_0x18d604[_0x302e('0x45')]]?Mustache[_0x302e('0x46')](this[_0x302e('0x11')][_0x18d604['data2']][_0x302e('0x47')],_0x1dae29):_0x302e('0x48');break;case _0x302e('0x2'):_0x105f77[_0x302e('0x49')]=this[_0x302e('0x4a')](_0x18d604[_0x302e('0x45')],_0x1dae29,_[_0x302e('0x4b')](_0x18d604[_0x302e('0x4c')])?!![]:parseInt(_0x18d604[_0x302e('0x4c')],0xa));if(_[_0x302e('0x4b')](_0x18d604[_0x302e('0x4d')])){_0x105f77[_0x302e('0x4e')]='0';}else{_0x105f77[_0x302e('0x4f')]=_0x18d604[_0x302e('0x4d')];_0x105f77[_0x302e('0x50')]=_['isNil'](_0x18d604['data5'])?_0x302e('0x51'):_0x18d604[_0x302e('0x52')];_0x105f77[_0x302e('0x53')]=_[_0x302e('0x4b')](_0x18d604[_0x302e('0x54')])?_0x302e('0x55'):_0x18d604['data6'];}break;case _0x302e('0x56'):_0x105f77[_0x302e('0x57')]=_0x18d604[_0x302e('0x45')]?Mustache[_0x302e('0x46')](_0x18d604[_0x302e('0x45')],_0x1dae29):'';_0x105f77[_0x302e('0x58')]=_0x18d604['data3']?Mustache[_0x302e('0x46')](_0x18d604[_0x302e('0x4c')],_0x1dae29):'';break;}this[_0x302e('0x2e')](util['format'](_0x302e('0x59'),this[_0x302e('0xf')][_0x1dae29[_0x302e('0x38')]]['name']),util[_0x302e('0x5a')](_0x302e('0x5b'),_0x18d604[_0x302e('0x5c')][_0x302e('0x5d')](),barAndWebActions[_0x18d604['data1']]),_[_0x302e('0x3c')](_0x105f77,_0x1dae29));break;case'jscripty':this[_0x302e('0x2e')](util['format'](_0x302e('0x59'),this['agents'][_0x1dae29[_0x302e('0x38')]][_0x302e('0x5e')]),util[_0x302e('0x5a')](_0x302e('0x5f'),_0x18d604[_0x302e('0x5c')][_0x302e('0x5d')]()),_['merge']({'ProjectId':parseInt(_0x18d604[_0x302e('0x43')],0xa)},_0x1dae29));break;default:this[_0x302e('0x2e')](util[_0x302e('0x5a')]('user:%s',this[_0x302e('0xf')][_0x1dae29[_0x302e('0x38')]][_0x302e('0x5e')]),util[_0x302e('0x5a')](_0x302e('0x5f'),_0x18d604['action']['toLowerCase']()),_[_0x302e('0x3c')]({},_0x18d604,_0x1dae29));}}switch(_0x18d604[_0x302e('0x5c')]['toLowerCase']()){case _0x302e('0x40'):cmContact['exec'](this[_0x302e('0xf')][_0x1dae29[_0x302e('0x38')]],this[_0x302e('0xe')][_0x5bfe58],_0x18d604,_0x1dae29);break;case _0x302e('0x60'):integration[_0x302e('0x61')](_0x18d604,_0x1dae29,this[_0x302e('0x62')],this[_0x302e('0xf')][_0x1dae29[_0x302e('0x38')]],this[_0x302e('0x10')][_0x1dae29[_0x302e('0x63')]],this[_0x302e('0x12')][_0x1dae29['routeId']]);break;case _0x302e('0x64'):urlforward[_0x302e('0x61')](_0x18d604,_0x1dae29);break;case'script':script['exec'](_0x18d604,_0x1dae29);break;}}}}}}};Trigger['prototype'][_0x302e('0x4a')]=function(_0x4abeaa,_0x1e9980,_0x28de7c){var _0x1defee=url[_0x302e('0x65')](Mustache[_0x302e('0x46')](_0x4abeaa,_0x1e9980),!![]);if(_0x28de7c){_[_0x302e('0x3c')](_0x1defee[_0x302e('0x66')],_0x1e9980);}delete _0x1defee[_0x302e('0x67')];var _0x38d941=url['format'](_0x1defee);_0x38d941=_0x38d941[_0x302e('0x68')](/\/\?/g,'?');return _0x38d941;};Trigger[_0x302e('0x2d')][_0x302e('0x3b')]=function(_0x3e73c2,_0x2fa705){var _0x4d6f2b=!![];var _0x3461ff=!![];var _0x3d23d2=![];if(_0x3e73c2[_0x302e('0x69')]===_0x2fa705[_0x302e('0x32')]){_0x3d23d2=!![];}if(_0x3e73c2['AllConditions']['length']){_0x4d6f2b=_[_0x302e('0x6a')](_0x3e73c2[_0x302e('0x6b')],this[_0x302e('0x6c')](_0x2fa705,_0x3e73c2['channel']));}if(_0x3e73c2['AnyConditions'][_0x302e('0x3f')]){_0x3461ff=_[_0x302e('0x6d')](_0x3e73c2[_0x302e('0x6e')],this[_0x302e('0x6c')](_0x2fa705,_0x3e73c2[_0x302e('0x69')]));}var _0x1610fc=_0x3d23d2&&_0x4d6f2b&&_0x3461ff;logger[_0x302e('0x35')](_0x302e('0x6f'),util[_0x302e('0x36')](_0x3e73c2,{'showHidden':!![],'depth':null}),_0x302e('0x70'),util[_0x302e('0x36')](_0x2fa705,{'showHidden':!![],'depth':null}),_0x3d23d2,_0x4d6f2b,_0x3461ff);return _0x1610fc;};Trigger[_0x302e('0x2d')][_0x302e('0x6c')]=function(_0x26b6dc,_0x137be9){return function(_0x204e3d){switch(_0x204e3d[_0x302e('0x71')]){case _0x302e('0x72'):if(_0x26b6dc[_0x302e('0x69')]===_0x137be9){if(_0x137be9===_0x302e('0x73')){return _0x26b6dc[_0x302e('0x74')]?operators[_0x204e3d[_0x302e('0x75')]](Number(_0x204e3d[_0x302e('0x76')]),_0x26b6dc['ChatWebsiteId']):![];}else{return _0x26b6dc[_['upperFirst'](_0x137be9)+_0x302e('0x77')]?operators[_0x204e3d[_0x302e('0x75')]](Number(_0x204e3d[_0x302e('0x76')]),_0x26b6dc[_[_0x302e('0x78')](_0x137be9)+_0x302e('0x77')]):![];}}break;case _0x302e('0x79'):case _0x302e('0x7a'):if(_0x26b6dc['channel']===_0x137be9){return _0x26b6dc[_0x302e('0x7b')]?operators[_0x204e3d['operator']](_0x204e3d[_0x302e('0x76')],_0x26b6dc[_0x302e('0x7b')]):![];}break;case'queue':return _0x26b6dc[_0x302e('0x63')]?operators[_0x204e3d[_0x302e('0x75')]](_0x204e3d['value'],_0x26b6dc[_0x302e('0x63')]):![];case _0x302e('0x7c'):return _0x26b6dc[_0x302e('0x7d')]?operators[_0x204e3d['operator']](_0x204e3d[_0x302e('0x76')],_0x26b6dc[_0x302e('0x7d')]):![];case'lastevent':return _0x26b6dc[_0x302e('0x7e')]?operators[_0x204e3d['operator']](_0x204e3d[_0x302e('0x76')],_0x26b6dc[_0x302e('0x7e')]):![];case _0x302e('0x7f'):return _0x26b6dc[_0x302e('0x7f')]?operators[_0x204e3d[_0x302e('0x75')]](_0x204e3d['value'],_0x26b6dc[_0x302e('0x7f')]):![];case _0x302e('0x80'):if(_0x204e3d[_0x302e('0x76')]===_0x302e('0x81'))_0x204e3d[_0x302e('0x76')]=null;return typeof _0x26b6dc[_0x302e('0x82')]!=='undefined'?operators[_0x204e3d[_0x302e('0x75')]](_0x204e3d[_0x302e('0x76')],_0x26b6dc['substatus']):![];case _0x302e('0x83'):if(_0x26b6dc[_0x302e('0x69')]===_0x137be9){return _0x204e3d['value']===_0x302e('0x84')&&_0x204e3d[_0x302e('0x75')]===_0x302e('0x85')?!![]:![];}break;}return![];};};module[_0x302e('0x86')]=Trigger;