Built motion from commit b9b02fed.|2.6.5
[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 _0x58b6=['operator','AccountId','value','event','agent','membername','lastevent','mailSubstatus','null','substatus','created','equals','exports','util','lodash','url','mustache','ioredis','./cmContact','./script','../../../config/environment','trigger','../ami','redis','defaults','localhost','popup','winapp','triggers','agents','voiceQueues','templates','voiceExtensions','zendeskAccounts','freshdeskAccounts','salesforceAccounts','sugarcrmAccounts','zohoAccounts','deskAccounts','vtigerAccounts','servicenowAccounts','dynamics365Accounts','freshsalesAccounts','accounts','custom:agentcalled','syncCustomEvent','bind','custom:agentringnoanswer','custom:agentcomplete','custom:agentbusy','custom:agentcongestion','custom:agentreject','custom:amd','custom:queuecallerabandon','custom:timeout','syncAgentDial','custom:dialconnect','custom:newinteraction','custom:closedinteraction','custom:substatus','custom:outgoingmessage','custom:acceptmessage','prototype','info','emit','clone','undefined','voice','checkTriggers','interface','hasOwnProperty','status','checkTrigger','variables','Actions','action','toLowerCase','contactmanager','motionbar','browser','TemplateId','data2','render','html','template\x20not\x20found','buildUri','isNil','data3','data4','uriLocation','data5','800','windowHeight','data6','600','winApplication','winArguments','format','trigger:%s:%s','data1','merge','user:%s','name','exec','integration','queue','routeId','urlforward','script','query','search','replace','channel','motionChannel','AllConditions','length','every','checkConditions','AnyConditions','field','account','chat','ChatWebsiteId'];(function(_0x4a8a77,_0x320333){var _0x5661a3=function(_0x57c28f){while(--_0x57c28f){_0x4a8a77['push'](_0x4a8a77['shift']());}};_0x5661a3(++_0x320333);}(_0x58b6,0x103));var _0x658b=function(_0x2d349c,_0x5a6794){_0x2d349c=_0x2d349c-0x0;var _0x27729a=_0x58b6[_0x2d349c];return _0x27729a;};'use strict';var util=require(_0x658b('0x0'));var _=require(_0x658b('0x1'));var url=require(_0x658b('0x2'));var Mustache=require(_0x658b('0x3'));var Redis=require(_0x658b('0x4'));var urlforward=require('./urlforward');var integration=require('./integration');var cmContact=require(_0x658b('0x5'));var script=require(_0x658b('0x6'));var config=require(_0x658b('0x7'));var logger=require('../../../config/logger')(_0x658b('0x8'));var ami=require(_0x658b('0x9'));config[_0x658b('0xa')]=_[_0x658b('0xb')](config[_0x658b('0xa')],{'host':_0x658b('0xc'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0x658b('0xa')]));var operators={'equals':function(_0x5bcda5,_0x31569d){return _0x5bcda5==_0x31569d;},'not_equals':function(_0x1ae6f3,_0x4e23d3){return _0x1ae6f3!=_0x4e23d3;}};var barAndWebActions=[_0x658b('0xd'),_0x658b('0x2'),_0x658b('0xe')];function Trigger(_0x1d8171){this[_0x658b('0xf')]=_0x1d8171['triggers'];this[_0x658b('0x10')]=_0x1d8171['agents'];this['voiceQueues']=_0x1d8171[_0x658b('0x11')];this[_0x658b('0x12')]=_0x1d8171[_0x658b('0x12')];this[_0x658b('0x13')]=_0x1d8171['voiceExtensions'];this[_0x658b('0x14')]=_0x1d8171[_0x658b('0x14')];this[_0x658b('0x15')]=_0x1d8171[_0x658b('0x15')];this[_0x658b('0x16')]=_0x1d8171[_0x658b('0x16')];this[_0x658b('0x17')]=_0x1d8171['sugarcrmAccounts'];this[_0x658b('0x18')]=_0x1d8171['zohoAccounts'];this[_0x658b('0x19')]=_0x1d8171['deskAccounts'];this[_0x658b('0x1a')]=_0x1d8171[_0x658b('0x1a')];this[_0x658b('0x1b')]=_0x1d8171[_0x658b('0x1b')];this[_0x658b('0x1c')]=_0x1d8171[_0x658b('0x1c')];this[_0x658b('0x1d')]=_0x1d8171['freshsalesAccounts'];this[_0x658b('0x1e')]={'zendesk':this[_0x658b('0x14')],'salesforce':this['salesforceAccounts'],'freshdesk':this[_0x658b('0x15')],'sugarcrm':this[_0x658b('0x17')],'zoho':this[_0x658b('0x18')],'desk':this[_0x658b('0x19')],'vtiger':this[_0x658b('0x1a')],'dynamics365':this['dynamics365Accounts'],'freshsales':this[_0x658b('0x1d')],'servicenow':this[_0x658b('0x1b')]};ami['on'](_0x658b('0x1f'),this[_0x658b('0x20')][_0x658b('0x21')](this));ami['on']('custom:agentconnect',this[_0x658b('0x20')][_0x658b('0x21')](this));ami['on'](_0x658b('0x22'),this[_0x658b('0x20')][_0x658b('0x21')](this));ami['on'](_0x658b('0x23'),this[_0x658b('0x20')][_0x658b('0x21')](this));ami['on']('custom:agentnosuchnumber',this[_0x658b('0x20')][_0x658b('0x21')](this));ami['on']('custom:agentnoanswer',this[_0x658b('0x20')][_0x658b('0x21')](this));ami['on'](_0x658b('0x24'),this['syncCustomEvent']['bind'](this));ami['on'](_0x658b('0x25'),this[_0x658b('0x20')][_0x658b('0x21')](this));ami['on'](_0x658b('0x26'),this[_0x658b('0x20')][_0x658b('0x21')](this));ami['on'](_0x658b('0x27'),this['syncCustomEvent'][_0x658b('0x21')](this));ami['on'](_0x658b('0x28'),this[_0x658b('0x20')][_0x658b('0x21')](this));ami['on'](_0x658b('0x29'),this[_0x658b('0x20')][_0x658b('0x21')](this));ami['on']('custom:dialbegin',this[_0x658b('0x2a')][_0x658b('0x21')](this));ami['on'](_0x658b('0x2b'),this['syncAgentDial'][_0x658b('0x21')](this));ami['on']('custom:dialend',this['syncAgentDial']['bind'](this));ami['on'](_0x658b('0x2c'),this[_0x658b('0x20')][_0x658b('0x21')](this));ami['on'](_0x658b('0x2d'),this[_0x658b('0x20')]['bind'](this));ami['on'](_0x658b('0x2e'),this[_0x658b('0x20')][_0x658b('0x21')](this));ami['on']('custom:incomingmessage',this['syncCustomEvent'][_0x658b('0x21')](this));ami['on'](_0x658b('0x2f'),this['syncCustomEvent'][_0x658b('0x21')](this));ami['on'](_0x658b('0x30'),this[_0x658b('0x20')][_0x658b('0x21')](this));ami['on']('custom:rejectmessage',this['syncCustomEvent'][_0x658b('0x21')](this));ami['on']('custom:offlineMessage',this[_0x658b('0x20')][_0x658b('0x21')](this));}Trigger[_0x658b('0x31')]['emit']=function(_0xe07f53,_0x57f01b,_0x4f98b3){logger[_0x658b('0x32')](_0xe07f53,_0x57f01b,JSON['stringify'](_0x4f98b3));io['to'](_0xe07f53)[_0x658b('0x33')](_0x57f01b,_0x4f98b3);};Trigger['prototype'][_0x658b('0x20')]=function(_0x250441){var _0x3d6e07=_[_0x658b('0x34')](_0x250441);if(typeof _0x3d6e07['motionChannel']===_0x658b('0x35')){_0x3d6e07['motionChannel']=_0x658b('0x36');}this[_0x658b('0x37')](_0x3d6e07);};Trigger[_0x658b('0x31')][_0x658b('0x2a')]=function(_0x35e9a4){if(this[_0x658b('0x10')][_0x35e9a4[_0x658b('0x38')]]){this[_0x658b('0x20')](_0x35e9a4);}};Trigger[_0x658b('0x31')][_0x658b('0x37')]=function(_0x32d426){var _0x544e2a;for(var _0xec8691 in this[_0x658b('0xf')]){if(this[_0x658b('0xf')][_0x658b('0x39')](_0xec8691)){if(this[_0x658b('0xf')][_0xec8691][_0x658b('0x3a')]){_0x544e2a=this[_0x658b('0x3b')](this[_0x658b('0xf')][_0xec8691],_0x32d426);if(_0x544e2a){_['merge'](_0x32d426,_0x32d426[_0x658b('0x3c')]);for(var _0x344f39=0x0,_0x5c544f,_0x381a3a,_0x4238c4;_0x344f39<this[_0x658b('0xf')][_0xec8691][_0x658b('0x3d')]['length'];_0x344f39+=0x1){_0x5c544f=this[_0x658b('0xf')][_0xec8691][_0x658b('0x3d')][_0x344f39];if(this[_0x658b('0x10')][_0x32d426['interface']]){switch(_0x5c544f[_0x658b('0x3e')][_0x658b('0x3f')]()){case _0x658b('0x40'):break;case _0x658b('0x41'):case _0x658b('0x42'):var _0x22b42b={};switch(barAndWebActions[_0x5c544f['data1']]){case _0x658b('0xd'):_0x22b42b[_0x658b('0x43')]=_0x5c544f['data2'];_0x22b42b['html']=this['templates'][_0x5c544f[_0x658b('0x44')]]?Mustache[_0x658b('0x45')](this[_0x658b('0x12')][_0x5c544f[_0x658b('0x44')]][_0x658b('0x46')],_0x32d426):_0x658b('0x47');break;case _0x658b('0x2'):_0x22b42b['uri']=this[_0x658b('0x48')](_0x5c544f[_0x658b('0x44')],_0x32d426,_[_0x658b('0x49')](_0x5c544f[_0x658b('0x4a')])?!![]:parseInt(_0x5c544f[_0x658b('0x4a')],0xa));if(_[_0x658b('0x49')](_0x5c544f[_0x658b('0x4b')])){_0x22b42b['location']='0';}else{_0x22b42b[_0x658b('0x4c')]=_0x5c544f[_0x658b('0x4b')];_0x22b42b['windowWidth']=_[_0x658b('0x49')](_0x5c544f[_0x658b('0x4d')])?_0x658b('0x4e'):_0x5c544f[_0x658b('0x4d')];_0x22b42b[_0x658b('0x4f')]=_[_0x658b('0x49')](_0x5c544f[_0x658b('0x50')])?_0x658b('0x51'):_0x5c544f[_0x658b('0x50')];}break;case _0x658b('0xe'):_0x22b42b[_0x658b('0x52')]=_0x5c544f['data2']?Mustache[_0x658b('0x45')](_0x5c544f[_0x658b('0x44')],_0x32d426):'';_0x22b42b[_0x658b('0x53')]=_0x5c544f['data3']?Mustache['render'](_0x5c544f[_0x658b('0x4a')],_0x32d426):'';break;}this['emit'](util[_0x658b('0x54')]('user:%s',this[_0x658b('0x10')][_0x32d426[_0x658b('0x38')]]['name']),util['format'](_0x658b('0x55'),_0x5c544f[_0x658b('0x3e')][_0x658b('0x3f')](),barAndWebActions[_0x5c544f[_0x658b('0x56')]]),_[_0x658b('0x57')](_0x22b42b,_0x32d426));break;case'jscripty':this[_0x658b('0x33')](util[_0x658b('0x54')](_0x658b('0x58'),this[_0x658b('0x10')][_0x32d426[_0x658b('0x38')]][_0x658b('0x59')]),util['format']('trigger:%s',_0x5c544f['action']['toLowerCase']()),_[_0x658b('0x57')]({'ProjectId':parseInt(_0x5c544f['data1'],0xa)},_0x32d426));break;default:this[_0x658b('0x33')](util['format']('user:%s',this[_0x658b('0x10')][_0x32d426[_0x658b('0x38')]][_0x658b('0x59')]),util[_0x658b('0x54')]('trigger:%s',_0x5c544f[_0x658b('0x3e')]['toLowerCase']()),_['merge']({},_0x5c544f,_0x32d426));}}switch(_0x5c544f[_0x658b('0x3e')]['toLowerCase']()){case _0x658b('0x40'):cmContact[_0x658b('0x5a')](this['agents'][_0x32d426[_0x658b('0x38')]],this[_0x658b('0xf')][_0xec8691],_0x5c544f,_0x32d426);break;case _0x658b('0x5b'):integration['exec'](_0x5c544f,_0x32d426,this[_0x658b('0x1e')],this[_0x658b('0x10')][_0x32d426[_0x658b('0x38')]],this[_0x658b('0x11')][_0x32d426[_0x658b('0x5c')]],this[_0x658b('0x13')][_0x32d426[_0x658b('0x5d')]]);break;case _0x658b('0x5e'):urlforward[_0x658b('0x5a')](_0x5c544f,_0x32d426);break;case _0x658b('0x5f'):script['exec'](_0x5c544f,_0x32d426);break;}}}}}}};Trigger['prototype']['buildUri']=function(_0x4a31ce,_0x18e938,_0x41b25d){var _0x1aba49=url['parse'](Mustache[_0x658b('0x45')](_0x4a31ce,_0x18e938),!![]);if(_0x41b25d){_[_0x658b('0x57')](_0x1aba49[_0x658b('0x60')],_0x18e938);}delete _0x1aba49[_0x658b('0x61')];var _0x64d0de=url[_0x658b('0x54')](_0x1aba49);_0x64d0de=_0x64d0de[_0x658b('0x62')](/\/\?/g,'?');return _0x64d0de;};Trigger[_0x658b('0x31')][_0x658b('0x3b')]=function(_0x31dc8f,_0x2a0f13){var _0x327459=!![];var _0x2ccc52=!![];var _0x55ff11=![];if(_0x31dc8f[_0x658b('0x63')]===_0x2a0f13[_0x658b('0x64')]){_0x55ff11=!![];}if(_0x31dc8f[_0x658b('0x65')][_0x658b('0x66')]){_0x327459=_[_0x658b('0x67')](_0x31dc8f['AllConditions'],this[_0x658b('0x68')](_0x2a0f13,_0x31dc8f[_0x658b('0x63')]));}if(_0x31dc8f[_0x658b('0x69')][_0x658b('0x66')]){_0x2ccc52=_['some'](_0x31dc8f[_0x658b('0x69')],this[_0x658b('0x68')](_0x2a0f13,_0x31dc8f['channel']));}return _0x55ff11&&_0x327459&&_0x2ccc52;};Trigger[_0x658b('0x31')]['checkConditions']=function(_0x2091df,_0x202aeb){return function(_0x17e0b6){switch(_0x17e0b6[_0x658b('0x6a')]){case _0x658b('0x6b'):if(_0x2091df[_0x658b('0x63')]===_0x202aeb){if(_0x202aeb===_0x658b('0x6c')){return _0x2091df[_0x658b('0x6d')]?operators[_0x17e0b6[_0x658b('0x6e')]](Number(_0x17e0b6['value']),_0x2091df['ChatWebsiteId']):![];}else{return _0x2091df[_['upperFirst'](_0x202aeb)+_0x658b('0x6f')]?operators[_0x17e0b6['operator']](Number(_0x17e0b6['value']),_0x2091df[_['upperFirst'](_0x202aeb)+'AccountId']):![];}}break;case'interaction':case'message':if(_0x2091df[_0x658b('0x63')]===_0x202aeb){return _0x2091df['event']?operators[_0x17e0b6[_0x658b('0x6e')]](_0x17e0b6[_0x658b('0x70')],_0x2091df[_0x658b('0x71')]):![];}break;case _0x658b('0x5c'):return _0x2091df[_0x658b('0x5c')]?operators[_0x17e0b6[_0x658b('0x6e')]](_0x17e0b6[_0x658b('0x70')],_0x2091df[_0x658b('0x5c')]):![];case _0x658b('0x72'):return _0x2091df[_0x658b('0x73')]?operators[_0x17e0b6[_0x658b('0x6e')]](_0x17e0b6[_0x658b('0x70')],_0x2091df[_0x658b('0x73')]):![];case _0x658b('0x74'):return _0x2091df[_0x658b('0x74')]?operators[_0x17e0b6[_0x658b('0x6e')]](_0x17e0b6[_0x658b('0x70')],_0x2091df[_0x658b('0x74')]):![];case _0x658b('0x5d'):return _0x2091df[_0x658b('0x5d')]?operators[_0x17e0b6[_0x658b('0x6e')]](_0x17e0b6[_0x658b('0x70')],_0x2091df['routeId']):![];case _0x658b('0x75'):if(_0x17e0b6[_0x658b('0x70')]===_0x658b('0x76'))_0x17e0b6[_0x658b('0x70')]=null;return typeof _0x2091df[_0x658b('0x77')]!==_0x658b('0x35')?operators[_0x17e0b6[_0x658b('0x6e')]](_0x17e0b6[_0x658b('0x70')],_0x2091df[_0x658b('0x77')]):![];case'offlineMessage':if(_0x2091df[_0x658b('0x63')]===_0x202aeb){return _0x17e0b6[_0x658b('0x70')]===_0x658b('0x78')&&_0x17e0b6[_0x658b('0x6e')]===_0x658b('0x79')?!![]:![];}break;}return![];};};module[_0x658b('0x7a')]=Trigger;