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