Built motion from commit (unavailable).|2.5.4
[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 _0xd7fa=['emit','info','stringify','checkTriggers','hasOwnProperty','status','checkTrigger','merge','variables','interface','action','toLowerCase','motionbar','browser','data1','data2','render','html','uri','buildUri','isNil','data3','data4','data5','800','windowHeight','winApplication','winArguments','user:%s','name','trigger:%s:%s','jscripty','format','trigger:%s','contactmanager','integration','queue','routeId','urlforward','exec','script','parse','search','replace','AllConditions','every','checkConditions','channel','AnyConditions','length','field','account','chat','upperFirst','AccountId','operator','value','interaction','message','event','agent','membername','lastevent','util','lodash','url','mustache','ioredis','./urlforward','./integration','./cmContact','./script','../rpc/cmContact','../../../config/environment','../../../config/logger','trigger','../ami','defaults','localhost','popup','winapp','triggers','agents','voiceQueues','templates','voiceExtensions','freshdeskAccounts','salesforceAccounts','sugarcrmAccounts','zohoAccounts','deskAccounts','vtigerAccounts','servicenowAccounts','dynamics365Accounts','freshsalesAccounts','accounts','zendeskAccounts','custom:agentcalled','syncCustomEvent','bind','custom:agentringnoanswer','custom:agentcomplete','custom:agentnosuchnumber','custom:agentnoanswer','custom:agentbusy','custom:agentcongestion','custom:agentreject','custom:queuecallerabandon','custom:timeout','syncAgentDial','custom:dialend','custom:newinteraction','custom:closedinteraction','custom:outgoingmessage','custom:rejectmessage','prototype'];(function(_0x55e08b,_0x421620){var _0xd1a7ff=function(_0x58c7ff){while(--_0x58c7ff){_0x55e08b['push'](_0x55e08b['shift']());}};_0xd1a7ff(++_0x421620);}(_0xd7fa,0x127));var _0xad7f=function(_0xe8a3dd,_0x2cac07){_0xe8a3dd=_0xe8a3dd-0x0;var _0x5d489c=_0xd7fa[_0xe8a3dd];return _0x5d489c;};'use strict';var util=require(_0xad7f('0x0'));var _=require(_0xad7f('0x1'));var url=require(_0xad7f('0x2'));var Mustache=require(_0xad7f('0x3'));var Redis=require(_0xad7f('0x4'));var urlforward=require(_0xad7f('0x5'));var integration=require(_0xad7f('0x6'));var cmContact=require(_0xad7f('0x7'));var script=require(_0xad7f('0x8'));var cmContactRpc=require(_0xad7f('0x9'));var config=require(_0xad7f('0xa'));var logger=require(_0xad7f('0xb'))(_0xad7f('0xc'));var ami=require(_0xad7f('0xd'));config['redis']=_[_0xad7f('0xe')](config['redis'],{'host':_0xad7f('0xf'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config['redis']));var operators={'equals':function(_0x50bd19,_0x500913){return _0x50bd19==_0x500913;},'not_equals':function(_0x4f0ed2,_0x3a5791){return _0x4f0ed2!=_0x3a5791;}};var barAndWebActions=[_0xad7f('0x10'),'url',_0xad7f('0x11')];function Trigger(_0x774182){this[_0xad7f('0x12')]=_0x774182[_0xad7f('0x12')];this[_0xad7f('0x13')]=_0x774182['agents'];this[_0xad7f('0x14')]=_0x774182['voiceQueues'];this[_0xad7f('0x15')]=_0x774182['templates'];this[_0xad7f('0x16')]=_0x774182[_0xad7f('0x16')];this['zendeskAccounts']=_0x774182['zendeskAccounts'];this[_0xad7f('0x17')]=_0x774182['freshdeskAccounts'];this[_0xad7f('0x18')]=_0x774182['salesforceAccounts'];this[_0xad7f('0x19')]=_0x774182[_0xad7f('0x19')];this[_0xad7f('0x1a')]=_0x774182['zohoAccounts'];this[_0xad7f('0x1b')]=_0x774182[_0xad7f('0x1b')];this[_0xad7f('0x1c')]=_0x774182[_0xad7f('0x1c')];this[_0xad7f('0x1d')]=_0x774182[_0xad7f('0x1d')];this[_0xad7f('0x1e')]=_0x774182[_0xad7f('0x1e')];this[_0xad7f('0x1f')]=_0x774182['freshsalesAccounts'];this[_0xad7f('0x20')]={'zendesk':this[_0xad7f('0x21')],'salesforce':this[_0xad7f('0x18')],'freshdesk':this[_0xad7f('0x17')],'sugarcrm':this[_0xad7f('0x19')],'zoho':this[_0xad7f('0x1a')],'desk':this[_0xad7f('0x1b')],'vtiger':this[_0xad7f('0x1c')],'dynamics365':this[_0xad7f('0x1e')],'freshsales':this[_0xad7f('0x1f')],'servicenow':this[_0xad7f('0x1d')]};ami['on'](_0xad7f('0x22'),this[_0xad7f('0x23')][_0xad7f('0x24')](this));ami['on']('custom:agentconnect',this[_0xad7f('0x23')][_0xad7f('0x24')](this));ami['on'](_0xad7f('0x25'),this[_0xad7f('0x23')][_0xad7f('0x24')](this));ami['on'](_0xad7f('0x26'),this[_0xad7f('0x23')][_0xad7f('0x24')](this));ami['on'](_0xad7f('0x27'),this['syncCustomEvent'][_0xad7f('0x24')](this));ami['on'](_0xad7f('0x28'),this[_0xad7f('0x23')][_0xad7f('0x24')](this));ami['on'](_0xad7f('0x29'),this['syncCustomEvent'][_0xad7f('0x24')](this));ami['on'](_0xad7f('0x2a'),this[_0xad7f('0x23')][_0xad7f('0x24')](this));ami['on'](_0xad7f('0x2b'),this['syncCustomEvent'][_0xad7f('0x24')](this));ami['on'](_0xad7f('0x2c'),this[_0xad7f('0x23')][_0xad7f('0x24')](this));ami['on'](_0xad7f('0x2d'),this[_0xad7f('0x23')][_0xad7f('0x24')](this));ami['on']('custom:dialbegin',this['syncAgentDial'][_0xad7f('0x24')](this));ami['on']('custom:dialconnect',this[_0xad7f('0x2e')][_0xad7f('0x24')](this));ami['on'](_0xad7f('0x2f'),this[_0xad7f('0x2e')]['bind'](this));ami['on'](_0xad7f('0x30'),this[_0xad7f('0x23')][_0xad7f('0x24')](this));ami['on'](_0xad7f('0x31'),this[_0xad7f('0x23')][_0xad7f('0x24')](this));ami['on']('custom:incomingmessage',this[_0xad7f('0x23')][_0xad7f('0x24')](this));ami['on'](_0xad7f('0x32'),this[_0xad7f('0x23')][_0xad7f('0x24')](this));ami['on']('custom:acceptmessage',this[_0xad7f('0x23')][_0xad7f('0x24')](this));ami['on'](_0xad7f('0x33'),this[_0xad7f('0x23')][_0xad7f('0x24')](this));}Trigger[_0xad7f('0x34')][_0xad7f('0x35')]=function(_0x54d9a6,_0x378e20,_0x57a7af){logger[_0xad7f('0x36')](_0x54d9a6,_0x378e20,JSON[_0xad7f('0x37')](_0x57a7af));io['to'](_0x54d9a6)[_0xad7f('0x35')](_0x378e20,_0x57a7af);};Trigger[_0xad7f('0x34')][_0xad7f('0x23')]=function(_0x59996a){var _0x5aa02f=_['clone'](_0x59996a);this['checkTriggers'](_0x5aa02f);};Trigger['prototype']['syncAgentDial']=function(_0x3db959){if(this[_0xad7f('0x13')][_0x3db959['interface']]){this[_0xad7f('0x23')](_0x3db959);}};Trigger['prototype'][_0xad7f('0x38')]=function(_0x55cab7){var _0x35a614;for(var _0x5c9e5e in this['triggers']){if(this['triggers'][_0xad7f('0x39')](_0x5c9e5e)){if(this[_0xad7f('0x12')][_0x5c9e5e][_0xad7f('0x3a')]){_0x35a614=this[_0xad7f('0x3b')](this['triggers'][_0x5c9e5e],_0x55cab7);if(_0x35a614){_[_0xad7f('0x3c')](_0x55cab7,_0x55cab7[_0xad7f('0x3d')]);for(var _0xa6d046=0x0,_0xa8217e,_0x483e58,_0x10def3;_0xa6d046<this[_0xad7f('0x12')][_0x5c9e5e]['Actions']['length'];_0xa6d046+=0x1){_0xa8217e=this['triggers'][_0x5c9e5e]['Actions'][_0xa6d046];if(this[_0xad7f('0x13')][_0x55cab7[_0xad7f('0x3e')]]){switch(_0xa8217e[_0xad7f('0x3f')][_0xad7f('0x40')]()){case'contactmanager':break;case _0xad7f('0x41'):case _0xad7f('0x42'):var _0xa98261={};switch(barAndWebActions[_0xa8217e[_0xad7f('0x43')]]){case _0xad7f('0x10'):_0xa98261['TemplateId']=_0xa8217e[_0xad7f('0x44')];_0xa98261['html']=this[_0xad7f('0x15')][_0xa8217e[_0xad7f('0x44')]]?Mustache[_0xad7f('0x45')](this['templates'][_0xa8217e[_0xad7f('0x44')]][_0xad7f('0x46')],_0x55cab7):'template\x20not\x20found';break;case _0xad7f('0x2'):_0xa98261[_0xad7f('0x47')]=this[_0xad7f('0x48')](_0xa8217e[_0xad7f('0x44')],_0x55cab7,_[_0xad7f('0x49')](_0xa8217e[_0xad7f('0x4a')])?!![]:parseInt(_0xa8217e[_0xad7f('0x4a')],0xa));if(_[_0xad7f('0x49')](_0xa8217e[_0xad7f('0x4b')])){_0xa98261['location']='0';}else{_0xa98261['uriLocation']=_0xa8217e[_0xad7f('0x4b')];_0xa98261['windowWidth']=_[_0xad7f('0x49')](_0xa8217e[_0xad7f('0x4c')])?_0xad7f('0x4d'):_0xa8217e['data5'];_0xa98261[_0xad7f('0x4e')]=_[_0xad7f('0x49')](_0xa8217e['data6'])?'600':_0xa8217e['data6'];}break;case'winapp':_0xa98261[_0xad7f('0x4f')]=_0xa8217e['data2']?Mustache[_0xad7f('0x45')](_0xa8217e[_0xad7f('0x44')],_0x55cab7):'';_0xa98261[_0xad7f('0x50')]=_0xa8217e[_0xad7f('0x4a')]?Mustache[_0xad7f('0x45')](_0xa8217e[_0xad7f('0x4a')],_0x55cab7):'';break;}this[_0xad7f('0x35')](util['format'](_0xad7f('0x51'),this[_0xad7f('0x13')][_0x55cab7[_0xad7f('0x3e')]][_0xad7f('0x52')]),util['format'](_0xad7f('0x53'),_0xa8217e[_0xad7f('0x3f')]['toLowerCase'](),barAndWebActions[_0xa8217e[_0xad7f('0x43')]]),_[_0xad7f('0x3c')](_0xa98261,_0x55cab7));break;case _0xad7f('0x54'):this[_0xad7f('0x35')](util['format'](_0xad7f('0x51'),this['agents'][_0x55cab7[_0xad7f('0x3e')]][_0xad7f('0x52')]),util[_0xad7f('0x55')](_0xad7f('0x56'),_0xa8217e[_0xad7f('0x3f')][_0xad7f('0x40')]()),_[_0xad7f('0x3c')]({'ProjectId':parseInt(_0xa8217e[_0xad7f('0x43')],0xa)},_0x55cab7));break;default:this[_0xad7f('0x35')](util[_0xad7f('0x55')](_0xad7f('0x51'),this[_0xad7f('0x13')][_0x55cab7[_0xad7f('0x3e')]][_0xad7f('0x52')]),util[_0xad7f('0x55')](_0xad7f('0x56'),_0xa8217e[_0xad7f('0x3f')][_0xad7f('0x40')]()),_[_0xad7f('0x3c')]({},_0xa8217e,_0x55cab7));}}switch(_0xa8217e['action'][_0xad7f('0x40')]()){case _0xad7f('0x57'):cmContact['exec'](this[_0xad7f('0x13')][_0x55cab7[_0xad7f('0x3e')]],_0xa8217e,_0x55cab7,cmContactRpc);break;case _0xad7f('0x58'):integration['exec'](_0xa8217e,_0x55cab7,this[_0xad7f('0x20')],this[_0xad7f('0x13')][_0x55cab7[_0xad7f('0x3e')]],this[_0xad7f('0x14')][_0x55cab7[_0xad7f('0x59')]],this[_0xad7f('0x16')][_0x55cab7[_0xad7f('0x5a')]]);break;case _0xad7f('0x5b'):urlforward[_0xad7f('0x5c')](_0xa8217e,_0x55cab7);break;case _0xad7f('0x5d'):script['exec'](_0xa8217e,_0x55cab7);break;}}}}}}};Trigger[_0xad7f('0x34')]['buildUri']=function(_0x380bdf,_0x4ab950,_0x47de73){var _0x2e3b1f=url[_0xad7f('0x5e')](Mustache[_0xad7f('0x45')](_0x380bdf,_0x4ab950),!![]);if(_0x47de73){_['merge'](_0x2e3b1f['query'],_0x4ab950);}delete _0x2e3b1f[_0xad7f('0x5f')];var _0x4d5a2a=url[_0xad7f('0x55')](_0x2e3b1f);_0x4d5a2a=_0x4d5a2a[_0xad7f('0x60')](/\/\?/g,'?');return _0x4d5a2a;};Trigger['prototype'][_0xad7f('0x3b')]=function(_0x4fde2b,_0x3b42d2){var _0x37e0ca=!![],_0x356b20=!![];if(_0x4fde2b[_0xad7f('0x61')]['length']){_0x37e0ca=_[_0xad7f('0x62')](_0x4fde2b[_0xad7f('0x61')],this[_0xad7f('0x63')](_0x3b42d2,_0x4fde2b[_0xad7f('0x64')]));}if(_0x4fde2b[_0xad7f('0x65')][_0xad7f('0x66')]){_0x356b20=_['some'](_0x4fde2b[_0xad7f('0x65')],this[_0xad7f('0x63')](_0x3b42d2,_0x4fde2b['channel']));}return _0x37e0ca&&_0x356b20;};Trigger[_0xad7f('0x34')][_0xad7f('0x63')]=function(_0x17e581,_0x6f4808){return function(_0x3c43ff){switch(_0x3c43ff[_0xad7f('0x67')]){case _0xad7f('0x68'):if(_0x17e581[_0xad7f('0x64')]===_0x6f4808){if(_0x6f4808===_0xad7f('0x69')){return _0x17e581['ChatWebsiteId']?operators[_0x3c43ff['operator']](Number(_0x3c43ff['value']),_0x17e581['ChatWebsiteId']):![];}else{return _0x17e581[_[_0xad7f('0x6a')](_0x6f4808)+_0xad7f('0x6b')]?operators[_0x3c43ff[_0xad7f('0x6c')]](Number(_0x3c43ff[_0xad7f('0x6d')]),_0x17e581[_['upperFirst'](_0x6f4808)+_0xad7f('0x6b')]):![];}}break;case _0xad7f('0x6e'):case _0xad7f('0x6f'):if(_0x17e581[_0xad7f('0x64')]===_0x6f4808){return _0x17e581['event']?operators[_0x3c43ff[_0xad7f('0x6c')]](_0x3c43ff[_0xad7f('0x6d')],_0x17e581[_0xad7f('0x70')]):![];}break;case _0xad7f('0x59'):return _0x17e581['queue']?operators[_0x3c43ff['operator']](_0x3c43ff['value'],_0x17e581[_0xad7f('0x59')]):![];case _0xad7f('0x71'):return _0x17e581[_0xad7f('0x72')]?operators[_0x3c43ff[_0xad7f('0x6c')]](_0x3c43ff['value'],_0x17e581[_0xad7f('0x72')]):![];case'lastevent':return _0x17e581[_0xad7f('0x73')]?operators[_0x3c43ff['operator']](_0x3c43ff[_0xad7f('0x6d')],_0x17e581['lastevent']):![];case _0xad7f('0x5a'):return _0x17e581['routeId']?operators[_0x3c43ff['operator']](_0x3c43ff[_0xad7f('0x6d')],_0x17e581['routeId']):![];}return![];};};module['exports']=Trigger;