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 _0x031e=['exports','lodash','url','mustache','ioredis','./integration','./cmContact','./script','../rpc/cmContact','../../../config/environment','../../../config/logger','redis','localhost','socket.io-emitter','popup','triggers','agents','voiceQueues','templates','voiceExtensions','zendeskAccounts','freshdeskAccounts','sugarcrmAccounts','zohoAccounts','deskAccounts','vtigerAccounts','servicenowAccounts','dynamics365Accounts','freshsalesAccounts','accounts','salesforceAccounts','custom:agentcalled','syncCustomEvent','bind','custom:agentconnect','custom:agentringnoanswer','custom:agentnosuchnumber','custom:agentbusy','custom:agentcongestion','custom:agentreject','custom:timeout','syncAgentDial','custom:newinteraction','custom:closedinteraction','custom:incomingmessage','custom:outgoingmessage','custom:rejectmessage','prototype','emit','info','stringify','checkTriggers','interface','status','checkTrigger','merge','variables','Actions','length','toLowerCase','motionbar','browser','data1','TemplateId','data2','html','render','uri','buildUri','isNil','data3','data4','uriLocation','windowWidth','800','data5','windowHeight','data6','600','winapp','winApplication','winArguments','format','user:%s','name','trigger:%s:%s','action','jscripty','trigger:%s','contactmanager','exec','queue','routeId','parse','search','replace','AllConditions','every','checkConditions','AnyConditions','some','channel','field','account','chat','ChatWebsiteId','value','upperFirst','AccountId','operator','interaction','message','event','agent','membername','lastevent'];(function(_0x41a59e,_0x1f2931){var _0x4ccc26=function(_0x2a7dd3){while(--_0x2a7dd3){_0x41a59e['push'](_0x41a59e['shift']());}};_0x4ccc26(++_0x1f2931);}(_0x031e,0x75));var _0xe031=function(_0x24f31b,_0x44b8f3){_0x24f31b=_0x24f31b-0x0;var _0x488401=_0x031e[_0x24f31b];return _0x488401;};'use strict';var util=require('util');var _=require(_0xe031('0x0'));var url=require(_0xe031('0x1'));var Mustache=require(_0xe031('0x2'));var Redis=require(_0xe031('0x3'));var urlforward=require('./urlforward');var integration=require(_0xe031('0x4'));var cmContact=require(_0xe031('0x5'));var script=require(_0xe031('0x6'));var cmContactRpc=require(_0xe031('0x7'));var config=require(_0xe031('0x8'));var logger=require(_0xe031('0x9'))('trigger');var ami=require('../ami');config[_0xe031('0xa')]=_['defaults'](config[_0xe031('0xa')],{'host':_0xe031('0xb'),'port':0x18eb});var io=require(_0xe031('0xc'))(new Redis(config['redis']));var operators={'equals':function(_0x4600ae,_0x307b01){return _0x4600ae==_0x307b01;},'not_equals':function(_0x470c05,_0x9ab1dd){return _0x470c05!=_0x9ab1dd;}};var barAndWebActions=[_0xe031('0xd'),_0xe031('0x1'),'winapp'];function Trigger(_0xd01bfe){this[_0xe031('0xe')]=_0xd01bfe[_0xe031('0xe')];this['agents']=_0xd01bfe[_0xe031('0xf')];this[_0xe031('0x10')]=_0xd01bfe[_0xe031('0x10')];this[_0xe031('0x11')]=_0xd01bfe['templates'];this[_0xe031('0x12')]=_0xd01bfe[_0xe031('0x12')];this[_0xe031('0x13')]=_0xd01bfe[_0xe031('0x13')];this['freshdeskAccounts']=_0xd01bfe[_0xe031('0x14')];this['salesforceAccounts']=_0xd01bfe['salesforceAccounts'];this['sugarcrmAccounts']=_0xd01bfe[_0xe031('0x15')];this[_0xe031('0x16')]=_0xd01bfe['zohoAccounts'];this[_0xe031('0x17')]=_0xd01bfe[_0xe031('0x17')];this[_0xe031('0x18')]=_0xd01bfe['vtigerAccounts'];this['servicenowAccounts']=_0xd01bfe[_0xe031('0x19')];this[_0xe031('0x1a')]=_0xd01bfe['dynamics365Accounts'];this['freshsalesAccounts']=_0xd01bfe[_0xe031('0x1b')];this[_0xe031('0x1c')]={'zendesk':this[_0xe031('0x13')],'salesforce':this[_0xe031('0x1d')],'freshdesk':this['freshdeskAccounts'],'sugarcrm':this['sugarcrmAccounts'],'zoho':this['zohoAccounts'],'desk':this[_0xe031('0x17')],'vtiger':this['vtigerAccounts'],'dynamics365':this[_0xe031('0x1a')],'freshsales':this[_0xe031('0x1b')],'servicenow':this['servicenowAccounts']};ami['on'](_0xe031('0x1e'),this[_0xe031('0x1f')][_0xe031('0x20')](this));ami['on'](_0xe031('0x21'),this[_0xe031('0x1f')][_0xe031('0x20')](this));ami['on'](_0xe031('0x22'),this[_0xe031('0x1f')][_0xe031('0x20')](this));ami['on']('custom:agentcomplete',this[_0xe031('0x1f')][_0xe031('0x20')](this));ami['on'](_0xe031('0x23'),this[_0xe031('0x1f')][_0xe031('0x20')](this));ami['on']('custom:agentnoanswer',this['syncCustomEvent'][_0xe031('0x20')](this));ami['on'](_0xe031('0x24'),this[_0xe031('0x1f')][_0xe031('0x20')](this));ami['on'](_0xe031('0x25'),this[_0xe031('0x1f')][_0xe031('0x20')](this));ami['on'](_0xe031('0x26'),this['syncCustomEvent'][_0xe031('0x20')](this));ami['on']('custom:queuecallerabandon',this['syncCustomEvent'][_0xe031('0x20')](this));ami['on'](_0xe031('0x27'),this[_0xe031('0x1f')][_0xe031('0x20')](this));ami['on']('custom:dialbegin',this[_0xe031('0x28')][_0xe031('0x20')](this));ami['on']('custom:dialconnect',this[_0xe031('0x28')][_0xe031('0x20')](this));ami['on']('custom:dialend',this['syncAgentDial'][_0xe031('0x20')](this));ami['on'](_0xe031('0x29'),this[_0xe031('0x1f')][_0xe031('0x20')](this));ami['on'](_0xe031('0x2a'),this[_0xe031('0x1f')][_0xe031('0x20')](this));ami['on'](_0xe031('0x2b'),this[_0xe031('0x1f')][_0xe031('0x20')](this));ami['on'](_0xe031('0x2c'),this[_0xe031('0x1f')]['bind'](this));ami['on']('custom:acceptmessage',this['syncCustomEvent'][_0xe031('0x20')](this));ami['on'](_0xe031('0x2d'),this['syncCustomEvent'][_0xe031('0x20')](this));}Trigger[_0xe031('0x2e')][_0xe031('0x2f')]=function(_0x446edb,_0x50b75a,_0x356442){logger[_0xe031('0x30')](_0x446edb,_0x50b75a,JSON[_0xe031('0x31')](_0x356442));io['to'](_0x446edb)[_0xe031('0x2f')](_0x50b75a,_0x356442);};Trigger[_0xe031('0x2e')][_0xe031('0x1f')]=function(_0x4c0b56){var _0x587d44=_['clone'](_0x4c0b56);this[_0xe031('0x32')](_0x587d44);};Trigger[_0xe031('0x2e')][_0xe031('0x28')]=function(_0x4077d7){if(this[_0xe031('0xf')][_0x4077d7[_0xe031('0x33')]]){this[_0xe031('0x1f')](_0x4077d7);}};Trigger['prototype'][_0xe031('0x32')]=function(_0x3023c0){var _0x48eb5a;for(var _0x2d518e in this[_0xe031('0xe')]){if(this[_0xe031('0xe')]['hasOwnProperty'](_0x2d518e)){if(this['triggers'][_0x2d518e][_0xe031('0x34')]){_0x48eb5a=this[_0xe031('0x35')](this['triggers'][_0x2d518e],_0x3023c0);if(_0x48eb5a){_[_0xe031('0x36')](_0x3023c0,_0x3023c0[_0xe031('0x37')]);for(var _0x30460b=0x0,_0x3b7a80,_0x1ce8db,_0x2692af;_0x30460b<this['triggers'][_0x2d518e][_0xe031('0x38')][_0xe031('0x39')];_0x30460b+=0x1){_0x3b7a80=this[_0xe031('0xe')][_0x2d518e][_0xe031('0x38')][_0x30460b];if(this[_0xe031('0xf')][_0x3023c0[_0xe031('0x33')]]){switch(_0x3b7a80['action'][_0xe031('0x3a')]()){case'contactmanager':break;case _0xe031('0x3b'):case _0xe031('0x3c'):var _0x1362dc={};switch(barAndWebActions[_0x3b7a80[_0xe031('0x3d')]]){case'popup':_0x1362dc[_0xe031('0x3e')]=_0x3b7a80[_0xe031('0x3f')];_0x1362dc[_0xe031('0x40')]=this[_0xe031('0x11')][_0x3b7a80[_0xe031('0x3f')]]?Mustache[_0xe031('0x41')](this[_0xe031('0x11')][_0x3b7a80[_0xe031('0x3f')]][_0xe031('0x40')],_0x3023c0):'template\x20not\x20found';break;case _0xe031('0x1'):_0x1362dc[_0xe031('0x42')]=this[_0xe031('0x43')](_0x3b7a80['data2'],_0x3023c0,_[_0xe031('0x44')](_0x3b7a80['data3'])?!![]:parseInt(_0x3b7a80[_0xe031('0x45')],0xa));if(_[_0xe031('0x44')](_0x3b7a80[_0xe031('0x46')])){_0x1362dc['location']='0';}else{_0x1362dc[_0xe031('0x47')]=_0x3b7a80[_0xe031('0x46')];_0x1362dc[_0xe031('0x48')]=_['isNil'](_0x3b7a80['data5'])?_0xe031('0x49'):_0x3b7a80[_0xe031('0x4a')];_0x1362dc[_0xe031('0x4b')]=_[_0xe031('0x44')](_0x3b7a80[_0xe031('0x4c')])?_0xe031('0x4d'):_0x3b7a80[_0xe031('0x4c')];}break;case _0xe031('0x4e'):_0x1362dc[_0xe031('0x4f')]=_0x3b7a80[_0xe031('0x3f')]?Mustache[_0xe031('0x41')](_0x3b7a80['data2'],_0x3023c0):'';_0x1362dc[_0xe031('0x50')]=_0x3b7a80[_0xe031('0x45')]?Mustache[_0xe031('0x41')](_0x3b7a80[_0xe031('0x45')],_0x3023c0):'';break;}this[_0xe031('0x2f')](util[_0xe031('0x51')](_0xe031('0x52'),this[_0xe031('0xf')][_0x3023c0[_0xe031('0x33')]][_0xe031('0x53')]),util[_0xe031('0x51')](_0xe031('0x54'),_0x3b7a80[_0xe031('0x55')][_0xe031('0x3a')](),barAndWebActions[_0x3b7a80[_0xe031('0x3d')]]),_['merge'](_0x1362dc,_0x3023c0));break;case _0xe031('0x56'):this[_0xe031('0x2f')](util[_0xe031('0x51')]('user:%s',this[_0xe031('0xf')][_0x3023c0[_0xe031('0x33')]][_0xe031('0x53')]),util['format'](_0xe031('0x57'),_0x3b7a80[_0xe031('0x55')][_0xe031('0x3a')]()),_[_0xe031('0x36')]({'ProjectId':parseInt(_0x3b7a80[_0xe031('0x3d')],0xa)},_0x3023c0));break;default:this[_0xe031('0x2f')](util[_0xe031('0x51')](_0xe031('0x52'),this[_0xe031('0xf')][_0x3023c0[_0xe031('0x33')]][_0xe031('0x53')]),util[_0xe031('0x51')]('trigger:%s',_0x3b7a80['action'][_0xe031('0x3a')]()),_[_0xe031('0x36')]({},_0x3b7a80,_0x3023c0));}}switch(_0x3b7a80[_0xe031('0x55')][_0xe031('0x3a')]()){case _0xe031('0x58'):cmContact[_0xe031('0x59')](this[_0xe031('0xf')][_0x3023c0['interface']],_0x3b7a80,_0x3023c0,cmContactRpc);break;case'integration':integration[_0xe031('0x59')](_0x3b7a80,_0x3023c0,this[_0xe031('0x1c')],this['agents'][_0x3023c0[_0xe031('0x33')]],this[_0xe031('0x10')][_0x3023c0[_0xe031('0x5a')]],this[_0xe031('0x12')][_0x3023c0[_0xe031('0x5b')]]);break;case'urlforward':urlforward[_0xe031('0x59')](_0x3b7a80,_0x3023c0);break;case'script':script[_0xe031('0x59')](_0x3b7a80,_0x3023c0);break;}}}}}}};Trigger[_0xe031('0x2e')][_0xe031('0x43')]=function(_0x242f9e,_0x58afec,_0x74ef2b){var _0x1dcdd7=url[_0xe031('0x5c')](Mustache[_0xe031('0x41')](_0x242f9e,_0x58afec),!![]);if(_0x74ef2b){_[_0xe031('0x36')](_0x1dcdd7['query'],_0x58afec);}delete _0x1dcdd7[_0xe031('0x5d')];var _0x47654e=url[_0xe031('0x51')](_0x1dcdd7);_0x47654e=_0x47654e[_0xe031('0x5e')](/\/\?/g,'?');return _0x47654e;};Trigger['prototype'][_0xe031('0x35')]=function(_0x109f4e,_0x1f1b7b){var _0x3e5117=!![],_0x30b836=!![];if(_0x109f4e[_0xe031('0x5f')]['length']){_0x3e5117=_[_0xe031('0x60')](_0x109f4e['AllConditions'],this[_0xe031('0x61')](_0x1f1b7b,_0x109f4e['channel']));}if(_0x109f4e[_0xe031('0x62')][_0xe031('0x39')]){_0x30b836=_[_0xe031('0x63')](_0x109f4e[_0xe031('0x62')],this[_0xe031('0x61')](_0x1f1b7b,_0x109f4e[_0xe031('0x64')]));}return _0x3e5117&&_0x30b836;};Trigger[_0xe031('0x2e')][_0xe031('0x61')]=function(_0x87f576,_0x572e98){return function(_0x40e831){switch(_0x40e831[_0xe031('0x65')]){case _0xe031('0x66'):if(_0x87f576[_0xe031('0x64')]===_0x572e98){if(_0x572e98===_0xe031('0x67')){return _0x87f576[_0xe031('0x68')]?operators[_0x40e831['operator']](Number(_0x40e831[_0xe031('0x69')]),_0x87f576[_0xe031('0x68')]):![];}else{return _0x87f576[_[_0xe031('0x6a')](_0x572e98)+_0xe031('0x6b')]?operators[_0x40e831[_0xe031('0x6c')]](Number(_0x40e831[_0xe031('0x69')]),_0x87f576[_[_0xe031('0x6a')](_0x572e98)+_0xe031('0x6b')]):![];}}break;case _0xe031('0x6d'):case _0xe031('0x6e'):if(_0x87f576[_0xe031('0x64')]===_0x572e98){return _0x87f576['event']?operators[_0x40e831[_0xe031('0x6c')]](_0x40e831['value'],_0x87f576[_0xe031('0x6f')]):![];}break;case _0xe031('0x5a'):return _0x87f576['queue']?operators[_0x40e831[_0xe031('0x6c')]](_0x40e831['value'],_0x87f576[_0xe031('0x5a')]):![];case _0xe031('0x70'):return _0x87f576[_0xe031('0x71')]?operators[_0x40e831['operator']](_0x40e831['value'],_0x87f576[_0xe031('0x71')]):![];case'lastevent':return _0x87f576['lastevent']?operators[_0x40e831[_0xe031('0x6c')]](_0x40e831[_0xe031('0x69')],_0x87f576[_0xe031('0x72')]):![];case _0xe031('0x5b'):return _0x87f576[_0xe031('0x5b')]?operators[_0x40e831[_0xe031('0x6c')]](_0x40e831[_0xe031('0x69')],_0x87f576[_0xe031('0x5b')]):![];}return![];};};module[_0xe031('0x73')]=Trigger;