Built motion from commit f623a78c.|2.6.31
[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 _0x82b7=['vtigerAccounts','servicenowAccounts','dynamics365Accounts','freshsalesAccounts','accounts','custom:agentcalled','custom:agentconnect','syncCustomEvent','bind','custom:agentringnoanswer','custom:agentcomplete','custom:agentnosuchnumber','custom:agentcongestion','custom:agentreject','custom:amd','custom:queuecallerabandon','custom:timeout','custom:dialbegin','syncAgentDial','custom:dialconnect','custom:newinteraction','custom:incomingmessage','custom:outgoingmessage','custom:acceptmessage','custom:rejectmessage','custom:offlineMessage','prototype','emit','stringify','clone','motionChannel','undefined','voice','debug','inspect','checkTriggers','interface','hasOwnProperty','status','merge','variables','length','Actions','action','toLowerCase','contactmanager','data1','TemplateId','data2','html','template\x20not\x20found','uri','buildUri','isNil','data3','location','uriLocation','data4','windowWidth','data5','800','windowHeight','600','data6','winApplication','render','winArguments','format','user:%s','trigger:%s:%s','name','trigger:%s','exec','integration','queue','urlforward','script','query','AllConditions','every','checkConditions','channel','some','AnyConditions','checkTrigger:\x20trigger','evt','field','account','ChatWebsiteId','operator','upperFirst','AccountId','value','message','event','agent','membername','lastevent','routeId','mailSubstatus','null','substatus','offlineMessage','created','equals','exports','util','lodash','url','ioredis','./urlforward','./integration','./script','../../../config/environment','trigger','redis','localhost','socket.io-emitter','popup','triggers','agents','voiceQueues','templates','voiceExtensions','zendeskAccounts','freshdeskAccounts','salesforceAccounts','sugarcrmAccounts','zohoAccounts','deskAccounts'];(function(_0xc0a3d3,_0x2c8d00){var _0x3386e8=function(_0x3f9df4){while(--_0x3f9df4){_0xc0a3d3['push'](_0xc0a3d3['shift']());}};_0x3386e8(++_0x2c8d00);}(_0x82b7,0xec));var _0x782b=function(_0x19c2fb,_0x38bbfa){_0x19c2fb=_0x19c2fb-0x0;var _0x26c6ab=_0x82b7[_0x19c2fb];return _0x26c6ab;};'use strict';var util=require(_0x782b('0x0'));var _=require(_0x782b('0x1'));var url=require(_0x782b('0x2'));var Mustache=require('mustache');var Redis=require(_0x782b('0x3'));var urlforward=require(_0x782b('0x4'));var integration=require(_0x782b('0x5'));var cmContact=require('./cmContact');var script=require(_0x782b('0x6'));var config=require(_0x782b('0x7'));var logger=require('../../../config/logger')(_0x782b('0x8'));var ami=require('../ami');config[_0x782b('0x9')]=_['defaults'](config['redis'],{'host':_0x782b('0xa'),'port':0x18eb});var io=require(_0x782b('0xb'))(new Redis(config['redis']));var operators={'equals':function(_0x48dda2,_0x221fdc){return _0x48dda2==_0x221fdc;},'not_equals':function(_0x15a704,_0xe4a09b){return _0x15a704!=_0xe4a09b;}};var barAndWebActions=[_0x782b('0xc'),'url','winapp'];function Trigger(_0x103a4c){this[_0x782b('0xd')]=_0x103a4c[_0x782b('0xd')];this[_0x782b('0xe')]=_0x103a4c[_0x782b('0xe')];this[_0x782b('0xf')]=_0x103a4c[_0x782b('0xf')];this[_0x782b('0x10')]=_0x103a4c['templates'];this[_0x782b('0x11')]=_0x103a4c['voiceExtensions'];this['zendeskAccounts']=_0x103a4c[_0x782b('0x12')];this[_0x782b('0x13')]=_0x103a4c[_0x782b('0x13')];this[_0x782b('0x14')]=_0x103a4c[_0x782b('0x14')];this[_0x782b('0x15')]=_0x103a4c['sugarcrmAccounts'];this['zohoAccounts']=_0x103a4c[_0x782b('0x16')];this[_0x782b('0x17')]=_0x103a4c[_0x782b('0x17')];this[_0x782b('0x18')]=_0x103a4c[_0x782b('0x18')];this[_0x782b('0x19')]=_0x103a4c['servicenowAccounts'];this[_0x782b('0x1a')]=_0x103a4c['dynamics365Accounts'];this[_0x782b('0x1b')]=_0x103a4c['freshsalesAccounts'];this[_0x782b('0x1c')]={'zendesk':this[_0x782b('0x12')],'salesforce':this[_0x782b('0x14')],'freshdesk':this[_0x782b('0x13')],'sugarcrm':this[_0x782b('0x15')],'zoho':this[_0x782b('0x16')],'desk':this[_0x782b('0x17')],'vtiger':this[_0x782b('0x18')],'dynamics365':this[_0x782b('0x1a')],'freshsales':this[_0x782b('0x1b')],'servicenow':this[_0x782b('0x19')]};ami['on'](_0x782b('0x1d'),this['syncCustomEvent']['bind'](this));ami['on'](_0x782b('0x1e'),this[_0x782b('0x1f')][_0x782b('0x20')](this));ami['on'](_0x782b('0x21'),this[_0x782b('0x1f')][_0x782b('0x20')](this));ami['on'](_0x782b('0x22'),this[_0x782b('0x1f')][_0x782b('0x20')](this));ami['on'](_0x782b('0x23'),this['syncCustomEvent'][_0x782b('0x20')](this));ami['on']('custom:agentnoanswer',this[_0x782b('0x1f')][_0x782b('0x20')](this));ami['on']('custom:agentbusy',this['syncCustomEvent'][_0x782b('0x20')](this));ami['on'](_0x782b('0x24'),this['syncCustomEvent'][_0x782b('0x20')](this));ami['on'](_0x782b('0x25'),this[_0x782b('0x1f')][_0x782b('0x20')](this));ami['on'](_0x782b('0x26'),this['syncCustomEvent'][_0x782b('0x20')](this));ami['on'](_0x782b('0x27'),this['syncCustomEvent'][_0x782b('0x20')](this));ami['on'](_0x782b('0x28'),this['syncCustomEvent'][_0x782b('0x20')](this));ami['on'](_0x782b('0x29'),this[_0x782b('0x2a')][_0x782b('0x20')](this));ami['on'](_0x782b('0x2b'),this[_0x782b('0x2a')][_0x782b('0x20')](this));ami['on']('custom:dialend',this[_0x782b('0x2a')]['bind'](this));ami['on'](_0x782b('0x2c'),this['syncCustomEvent'][_0x782b('0x20')](this));ami['on']('custom:closedinteraction',this[_0x782b('0x1f')][_0x782b('0x20')](this));ami['on']('custom:substatus',this[_0x782b('0x1f')]['bind'](this));ami['on'](_0x782b('0x2d'),this[_0x782b('0x1f')]['bind'](this));ami['on'](_0x782b('0x2e'),this['syncCustomEvent'][_0x782b('0x20')](this));ami['on'](_0x782b('0x2f'),this['syncCustomEvent'][_0x782b('0x20')](this));ami['on'](_0x782b('0x30'),this[_0x782b('0x1f')][_0x782b('0x20')](this));ami['on'](_0x782b('0x31'),this[_0x782b('0x1f')]['bind'](this));}Trigger[_0x782b('0x32')][_0x782b('0x33')]=function(_0x18189e,_0x277302,_0x12f451){logger['info'](_0x18189e,_0x277302,JSON[_0x782b('0x34')](_0x12f451));io['to'](_0x18189e)[_0x782b('0x33')](_0x277302,_0x12f451);};Trigger['prototype'][_0x782b('0x1f')]=function(_0x3385c3){var _0x3ba98e=_[_0x782b('0x35')](_0x3385c3);if(typeof _0x3ba98e[_0x782b('0x36')]===_0x782b('0x37')){_0x3ba98e[_0x782b('0x36')]=_0x782b('0x38');}logger[_0x782b('0x39')](_0x782b('0x1f'),util[_0x782b('0x3a')](_0x3ba98e,{'showHidden':!![],'depth':null}));this[_0x782b('0x3b')](_0x3ba98e);};Trigger['prototype']['syncAgentDial']=function(_0x274f19){if(this[_0x782b('0xe')][_0x274f19[_0x782b('0x3c')]]){this[_0x782b('0x1f')](_0x274f19);}};Trigger['prototype'][_0x782b('0x3b')]=function(_0x4314a2){var _0x3653ca;for(var _0x5d0b42 in this[_0x782b('0xd')]){if(this[_0x782b('0xd')][_0x782b('0x3d')](_0x5d0b42)){if(this['triggers'][_0x5d0b42][_0x782b('0x3e')]){_0x3653ca=this['checkTrigger'](this[_0x782b('0xd')][_0x5d0b42],_0x4314a2);if(_0x3653ca){_[_0x782b('0x3f')](_0x4314a2,_0x4314a2[_0x782b('0x40')]);for(var _0xb00583=0x0,_0x16573b,_0x12f606,_0x2afc98;_0xb00583<this[_0x782b('0xd')][_0x5d0b42]['Actions'][_0x782b('0x41')];_0xb00583+=0x1){_0x16573b=this['triggers'][_0x5d0b42][_0x782b('0x42')][_0xb00583];if(this['agents'][_0x4314a2['interface']]){switch(_0x16573b[_0x782b('0x43')][_0x782b('0x44')]()){case _0x782b('0x45'):break;case'motionbar':case'browser':var _0x13abd1={};switch(barAndWebActions[_0x16573b[_0x782b('0x46')]]){case _0x782b('0xc'):_0x13abd1[_0x782b('0x47')]=_0x16573b[_0x782b('0x48')];_0x13abd1[_0x782b('0x49')]=this['templates'][_0x16573b[_0x782b('0x48')]]?Mustache['render'](this[_0x782b('0x10')][_0x16573b[_0x782b('0x48')]][_0x782b('0x49')],_0x4314a2):_0x782b('0x4a');break;case'url':_0x13abd1[_0x782b('0x4b')]=this[_0x782b('0x4c')](_0x16573b['data2'],_0x4314a2,_[_0x782b('0x4d')](_0x16573b[_0x782b('0x4e')])?!![]:parseInt(_0x16573b[_0x782b('0x4e')],0xa));if(_['isNil'](_0x16573b['data4'])){_0x13abd1[_0x782b('0x4f')]='0';}else{_0x13abd1[_0x782b('0x50')]=_0x16573b[_0x782b('0x51')];_0x13abd1[_0x782b('0x52')]=_[_0x782b('0x4d')](_0x16573b[_0x782b('0x53')])?_0x782b('0x54'):_0x16573b[_0x782b('0x53')];_0x13abd1[_0x782b('0x55')]=_[_0x782b('0x4d')](_0x16573b['data6'])?_0x782b('0x56'):_0x16573b[_0x782b('0x57')];}break;case'winapp':_0x13abd1[_0x782b('0x58')]=_0x16573b[_0x782b('0x48')]?Mustache[_0x782b('0x59')](_0x16573b[_0x782b('0x48')],_0x4314a2):'';_0x13abd1[_0x782b('0x5a')]=_0x16573b[_0x782b('0x4e')]?Mustache[_0x782b('0x59')](_0x16573b[_0x782b('0x4e')],_0x4314a2):'';break;}this[_0x782b('0x33')](util[_0x782b('0x5b')](_0x782b('0x5c'),this[_0x782b('0xe')][_0x4314a2[_0x782b('0x3c')]]['name']),util[_0x782b('0x5b')](_0x782b('0x5d'),_0x16573b[_0x782b('0x43')][_0x782b('0x44')](),barAndWebActions[_0x16573b[_0x782b('0x46')]]),_[_0x782b('0x3f')](_0x13abd1,_0x4314a2));break;case'jscripty':this[_0x782b('0x33')](util['format'](_0x782b('0x5c'),this[_0x782b('0xe')][_0x4314a2['interface']][_0x782b('0x5e')]),util[_0x782b('0x5b')]('trigger:%s',_0x16573b[_0x782b('0x43')][_0x782b('0x44')]()),_[_0x782b('0x3f')]({'ProjectId':parseInt(_0x16573b[_0x782b('0x46')],0xa)},_0x4314a2));break;default:this[_0x782b('0x33')](util['format'](_0x782b('0x5c'),this[_0x782b('0xe')][_0x4314a2[_0x782b('0x3c')]][_0x782b('0x5e')]),util['format'](_0x782b('0x5f'),_0x16573b[_0x782b('0x43')][_0x782b('0x44')]()),_[_0x782b('0x3f')]({},_0x16573b,_0x4314a2));}}switch(_0x16573b[_0x782b('0x43')]['toLowerCase']()){case _0x782b('0x45'):cmContact[_0x782b('0x60')](this[_0x782b('0xe')][_0x4314a2[_0x782b('0x3c')]],this[_0x782b('0xd')][_0x5d0b42],_0x16573b,_0x4314a2);break;case _0x782b('0x61'):integration[_0x782b('0x60')](_0x16573b,_0x4314a2,this['accounts'],this[_0x782b('0xe')][_0x4314a2[_0x782b('0x3c')]],this[_0x782b('0xf')][_0x4314a2[_0x782b('0x62')]],this[_0x782b('0x11')][_0x4314a2['routeId']]);break;case _0x782b('0x63'):urlforward[_0x782b('0x60')](_0x16573b,_0x4314a2);break;case _0x782b('0x64'):script[_0x782b('0x60')](_0x16573b,_0x4314a2);break;}}}}}}};Trigger[_0x782b('0x32')][_0x782b('0x4c')]=function(_0x633917,_0x2e6b5e,_0x4bc2bb){var _0xcefbbc=url['parse'](Mustache[_0x782b('0x59')](_0x633917,_0x2e6b5e),!![]);if(_0x4bc2bb){_[_0x782b('0x3f')](_0xcefbbc[_0x782b('0x65')],_0x2e6b5e);}delete _0xcefbbc['search'];var _0x5bba4d=url[_0x782b('0x5b')](_0xcefbbc);_0x5bba4d=_0x5bba4d['replace'](/\/\?/g,'?');return _0x5bba4d;};Trigger[_0x782b('0x32')]['checkTrigger']=function(_0x42e0eb,_0x212f7f){var _0x337d13=!![];var _0x3309d7=!![];var _0x3aa848=![];if(_0x42e0eb['channel']===_0x212f7f[_0x782b('0x36')]){_0x3aa848=!![];}if(_0x42e0eb[_0x782b('0x66')][_0x782b('0x41')]){_0x337d13=_[_0x782b('0x67')](_0x42e0eb[_0x782b('0x66')],this[_0x782b('0x68')](_0x212f7f,_0x42e0eb[_0x782b('0x69')]));}if(_0x42e0eb['AnyConditions']['length']){_0x3309d7=_[_0x782b('0x6a')](_0x42e0eb[_0x782b('0x6b')],this[_0x782b('0x68')](_0x212f7f,_0x42e0eb[_0x782b('0x69')]));}var _0x16090e=_0x3aa848&&_0x337d13&&_0x3309d7;logger[_0x782b('0x39')](_0x782b('0x6c'),util['inspect'](_0x42e0eb,{'showHidden':!![],'depth':null}),_0x782b('0x6d'),util[_0x782b('0x3a')](_0x212f7f,{'showHidden':!![],'depth':null}),_0x3aa848,_0x337d13,_0x3309d7);return _0x16090e;};Trigger[_0x782b('0x32')]['checkConditions']=function(_0x40d6c6,_0x247b95){return function(_0x18b3a5){switch(_0x18b3a5[_0x782b('0x6e')]){case _0x782b('0x6f'):if(_0x40d6c6[_0x782b('0x69')]===_0x247b95){if(_0x247b95==='chat'){return _0x40d6c6[_0x782b('0x70')]?operators[_0x18b3a5[_0x782b('0x71')]](Number(_0x18b3a5['value']),_0x40d6c6[_0x782b('0x70')]):![];}else{return _0x40d6c6[_[_0x782b('0x72')](_0x247b95)+_0x782b('0x73')]?operators[_0x18b3a5[_0x782b('0x71')]](Number(_0x18b3a5[_0x782b('0x74')]),_0x40d6c6[_['upperFirst'](_0x247b95)+_0x782b('0x73')]):![];}}break;case'interaction':case _0x782b('0x75'):if(_0x40d6c6['channel']===_0x247b95){return _0x40d6c6[_0x782b('0x76')]?operators[_0x18b3a5[_0x782b('0x71')]](_0x18b3a5[_0x782b('0x74')],_0x40d6c6['event']):![];}break;case'queue':return _0x40d6c6[_0x782b('0x62')]?operators[_0x18b3a5[_0x782b('0x71')]](_0x18b3a5[_0x782b('0x74')],_0x40d6c6[_0x782b('0x62')]):![];case _0x782b('0x77'):return _0x40d6c6[_0x782b('0x78')]?operators[_0x18b3a5['operator']](_0x18b3a5[_0x782b('0x74')],_0x40d6c6['membername']):![];case _0x782b('0x79'):return _0x40d6c6[_0x782b('0x79')]?operators[_0x18b3a5[_0x782b('0x71')]](_0x18b3a5[_0x782b('0x74')],_0x40d6c6[_0x782b('0x79')]):![];case _0x782b('0x7a'):return _0x40d6c6['routeId']?operators[_0x18b3a5['operator']](_0x18b3a5[_0x782b('0x74')],_0x40d6c6[_0x782b('0x7a')]):![];case _0x782b('0x7b'):if(_0x18b3a5[_0x782b('0x74')]===_0x782b('0x7c'))_0x18b3a5[_0x782b('0x74')]=null;return typeof _0x40d6c6['substatus']!==_0x782b('0x37')?operators[_0x18b3a5[_0x782b('0x71')]](_0x18b3a5[_0x782b('0x74')],_0x40d6c6[_0x782b('0x7d')]):![];case _0x782b('0x7e'):if(_0x40d6c6['channel']===_0x247b95){return _0x18b3a5['value']===_0x782b('0x7f')&&_0x18b3a5[_0x782b('0x71')]===_0x782b('0x80')?!![]:![];}break;}return![];};};module[_0x782b('0x81')]=Trigger;