Built motion from commit ae138b72.|2.6.28
[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 _0x6cf5=['merge','variables','Actions','length','action','toLowerCase','browser','data1','TemplateId','data2','html','render','template\x20not\x20found','uri','buildUri','isNil','data3','data4','location','uriLocation','windowWidth','data5','800','windowHeight','data6','600','format','user:%s','trigger:%s:%s','trigger:%s','contactmanager','exec','queue','routeId','urlforward','script','parse','search','replace','channel','AllConditions','checkConditions','AnyConditions','checkTrigger:\x20trigger','evt','field','account','chat','ChatWebsiteId','value','upperFirst','AccountId','operator','interaction','event','agent','membername','lastevent','mailSubstatus','null','substatus','offlineMessage','created','exports','util','lodash','url','mustache','./urlforward','./integration','./cmContact','./script','../../../config/logger','../ami','defaults','redis','socket.io-emitter','popup','winapp','triggers','agents','voiceQueues','templates','voiceExtensions','zendeskAccounts','freshdeskAccounts','salesforceAccounts','sugarcrmAccounts','zohoAccounts','deskAccounts','vtigerAccounts','servicenowAccounts','dynamics365Accounts','freshsalesAccounts','accounts','custom:agentcalled','syncCustomEvent','bind','custom:agentconnect','custom:agentringnoanswer','custom:agentcomplete','custom:agentnosuchnumber','custom:agentnoanswer','custom:agentcongestion','custom:agentreject','custom:queuecallerabandon','custom:timeout','custom:dialbegin','syncAgentDial','custom:dialconnect','custom:dialend','custom:newinteraction','custom:closedinteraction','custom:substatus','custom:incomingmessage','custom:outgoingmessage','custom:rejectmessage','custom:offlineMessage','prototype','info','stringify','emit','clone','motionChannel','undefined','voice','debug','inspect','checkTriggers','interface','hasOwnProperty','status','checkTrigger'];(function(_0x5d6456,_0x58ecc7){var _0x4d66c1=function(_0x4335e3){while(--_0x4335e3){_0x5d6456['push'](_0x5d6456['shift']());}};_0x4d66c1(++_0x58ecc7);}(_0x6cf5,0x1cf));var _0x56cf=function(_0x30900b,_0x2c1d22){_0x30900b=_0x30900b-0x0;var _0x14cfa1=_0x6cf5[_0x30900b];return _0x14cfa1;};'use strict';var util=require(_0x56cf('0x0'));var _=require(_0x56cf('0x1'));var url=require(_0x56cf('0x2'));var Mustache=require(_0x56cf('0x3'));var Redis=require('ioredis');var urlforward=require(_0x56cf('0x4'));var integration=require(_0x56cf('0x5'));var cmContact=require(_0x56cf('0x6'));var script=require(_0x56cf('0x7'));var config=require('../../../config/environment');var logger=require(_0x56cf('0x8'))('trigger');var ami=require(_0x56cf('0x9'));config['redis']=_[_0x56cf('0xa')](config[_0x56cf('0xb')],{'host':'localhost','port':0x18eb});var io=require(_0x56cf('0xc'))(new Redis(config['redis']));var operators={'equals':function(_0x51b676,_0x4b65ac){return _0x51b676==_0x4b65ac;},'not_equals':function(_0x4b78ce,_0x18c2ba){return _0x4b78ce!=_0x18c2ba;}};var barAndWebActions=[_0x56cf('0xd'),_0x56cf('0x2'),_0x56cf('0xe')];function Trigger(_0x23e1e6){this[_0x56cf('0xf')]=_0x23e1e6['triggers'];this[_0x56cf('0x10')]=_0x23e1e6[_0x56cf('0x10')];this[_0x56cf('0x11')]=_0x23e1e6[_0x56cf('0x11')];this[_0x56cf('0x12')]=_0x23e1e6[_0x56cf('0x12')];this[_0x56cf('0x13')]=_0x23e1e6['voiceExtensions'];this[_0x56cf('0x14')]=_0x23e1e6[_0x56cf('0x14')];this[_0x56cf('0x15')]=_0x23e1e6[_0x56cf('0x15')];this[_0x56cf('0x16')]=_0x23e1e6[_0x56cf('0x16')];this['sugarcrmAccounts']=_0x23e1e6[_0x56cf('0x17')];this[_0x56cf('0x18')]=_0x23e1e6[_0x56cf('0x18')];this[_0x56cf('0x19')]=_0x23e1e6[_0x56cf('0x19')];this['vtigerAccounts']=_0x23e1e6[_0x56cf('0x1a')];this[_0x56cf('0x1b')]=_0x23e1e6[_0x56cf('0x1b')];this[_0x56cf('0x1c')]=_0x23e1e6[_0x56cf('0x1c')];this[_0x56cf('0x1d')]=_0x23e1e6[_0x56cf('0x1d')];this[_0x56cf('0x1e')]={'zendesk':this[_0x56cf('0x14')],'salesforce':this['salesforceAccounts'],'freshdesk':this[_0x56cf('0x15')],'sugarcrm':this[_0x56cf('0x17')],'zoho':this[_0x56cf('0x18')],'desk':this[_0x56cf('0x19')],'vtiger':this[_0x56cf('0x1a')],'dynamics365':this[_0x56cf('0x1c')],'freshsales':this[_0x56cf('0x1d')],'servicenow':this[_0x56cf('0x1b')]};ami['on'](_0x56cf('0x1f'),this[_0x56cf('0x20')][_0x56cf('0x21')](this));ami['on'](_0x56cf('0x22'),this[_0x56cf('0x20')][_0x56cf('0x21')](this));ami['on'](_0x56cf('0x23'),this[_0x56cf('0x20')][_0x56cf('0x21')](this));ami['on'](_0x56cf('0x24'),this[_0x56cf('0x20')][_0x56cf('0x21')](this));ami['on'](_0x56cf('0x25'),this[_0x56cf('0x20')]['bind'](this));ami['on'](_0x56cf('0x26'),this[_0x56cf('0x20')]['bind'](this));ami['on']('custom:agentbusy',this[_0x56cf('0x20')]['bind'](this));ami['on'](_0x56cf('0x27'),this[_0x56cf('0x20')][_0x56cf('0x21')](this));ami['on'](_0x56cf('0x28'),this[_0x56cf('0x20')][_0x56cf('0x21')](this));ami['on']('custom:amd',this['syncCustomEvent'][_0x56cf('0x21')](this));ami['on'](_0x56cf('0x29'),this[_0x56cf('0x20')][_0x56cf('0x21')](this));ami['on'](_0x56cf('0x2a'),this[_0x56cf('0x20')][_0x56cf('0x21')](this));ami['on'](_0x56cf('0x2b'),this[_0x56cf('0x2c')][_0x56cf('0x21')](this));ami['on'](_0x56cf('0x2d'),this[_0x56cf('0x2c')][_0x56cf('0x21')](this));ami['on'](_0x56cf('0x2e'),this[_0x56cf('0x2c')][_0x56cf('0x21')](this));ami['on'](_0x56cf('0x2f'),this['syncCustomEvent'][_0x56cf('0x21')](this));ami['on'](_0x56cf('0x30'),this[_0x56cf('0x20')][_0x56cf('0x21')](this));ami['on'](_0x56cf('0x31'),this['syncCustomEvent'][_0x56cf('0x21')](this));ami['on'](_0x56cf('0x32'),this[_0x56cf('0x20')][_0x56cf('0x21')](this));ami['on'](_0x56cf('0x33'),this[_0x56cf('0x20')][_0x56cf('0x21')](this));ami['on']('custom:acceptmessage',this[_0x56cf('0x20')][_0x56cf('0x21')](this));ami['on'](_0x56cf('0x34'),this[_0x56cf('0x20')]['bind'](this));ami['on'](_0x56cf('0x35'),this[_0x56cf('0x20')][_0x56cf('0x21')](this));}Trigger[_0x56cf('0x36')]['emit']=function(_0x32287f,_0x44ac62,_0x54edaf){logger[_0x56cf('0x37')](_0x32287f,_0x44ac62,JSON[_0x56cf('0x38')](_0x54edaf));io['to'](_0x32287f)[_0x56cf('0x39')](_0x44ac62,_0x54edaf);};Trigger[_0x56cf('0x36')][_0x56cf('0x20')]=function(_0x3bff23){var _0x37650c=_[_0x56cf('0x3a')](_0x3bff23);if(typeof _0x37650c[_0x56cf('0x3b')]===_0x56cf('0x3c')){_0x37650c[_0x56cf('0x3b')]=_0x56cf('0x3d');}logger[_0x56cf('0x3e')](_0x56cf('0x20'),util[_0x56cf('0x3f')](_0x37650c,{'showHidden':!![],'depth':null}));this[_0x56cf('0x40')](_0x37650c);};Trigger[_0x56cf('0x36')][_0x56cf('0x2c')]=function(_0x2c0d39){if(this[_0x56cf('0x10')][_0x2c0d39[_0x56cf('0x41')]]){this[_0x56cf('0x20')](_0x2c0d39);}};Trigger[_0x56cf('0x36')][_0x56cf('0x40')]=function(_0x5b9ae1){var _0x1e5070;for(var _0x286f22 in this[_0x56cf('0xf')]){if(this[_0x56cf('0xf')][_0x56cf('0x42')](_0x286f22)){if(this[_0x56cf('0xf')][_0x286f22][_0x56cf('0x43')]){_0x1e5070=this[_0x56cf('0x44')](this[_0x56cf('0xf')][_0x286f22],_0x5b9ae1);if(_0x1e5070){_[_0x56cf('0x45')](_0x5b9ae1,_0x5b9ae1[_0x56cf('0x46')]);for(var _0x14bed9=0x0,_0x4cf7fd,_0x305385,_0x4c346d;_0x14bed9<this[_0x56cf('0xf')][_0x286f22][_0x56cf('0x47')][_0x56cf('0x48')];_0x14bed9+=0x1){_0x4cf7fd=this[_0x56cf('0xf')][_0x286f22][_0x56cf('0x47')][_0x14bed9];if(this[_0x56cf('0x10')][_0x5b9ae1[_0x56cf('0x41')]]){switch(_0x4cf7fd[_0x56cf('0x49')][_0x56cf('0x4a')]()){case'contactmanager':break;case'motionbar':case _0x56cf('0x4b'):var _0x56a382={};switch(barAndWebActions[_0x4cf7fd[_0x56cf('0x4c')]]){case _0x56cf('0xd'):_0x56a382[_0x56cf('0x4d')]=_0x4cf7fd[_0x56cf('0x4e')];_0x56a382[_0x56cf('0x4f')]=this[_0x56cf('0x12')][_0x4cf7fd['data2']]?Mustache[_0x56cf('0x50')](this[_0x56cf('0x12')][_0x4cf7fd[_0x56cf('0x4e')]][_0x56cf('0x4f')],_0x5b9ae1):_0x56cf('0x51');break;case _0x56cf('0x2'):_0x56a382[_0x56cf('0x52')]=this[_0x56cf('0x53')](_0x4cf7fd[_0x56cf('0x4e')],_0x5b9ae1,_[_0x56cf('0x54')](_0x4cf7fd[_0x56cf('0x55')])?!![]:parseInt(_0x4cf7fd[_0x56cf('0x55')],0xa));if(_[_0x56cf('0x54')](_0x4cf7fd[_0x56cf('0x56')])){_0x56a382[_0x56cf('0x57')]='0';}else{_0x56a382[_0x56cf('0x58')]=_0x4cf7fd['data4'];_0x56a382[_0x56cf('0x59')]=_[_0x56cf('0x54')](_0x4cf7fd[_0x56cf('0x5a')])?_0x56cf('0x5b'):_0x4cf7fd['data5'];_0x56a382[_0x56cf('0x5c')]=_[_0x56cf('0x54')](_0x4cf7fd[_0x56cf('0x5d')])?_0x56cf('0x5e'):_0x4cf7fd['data6'];}break;case _0x56cf('0xe'):_0x56a382['winApplication']=_0x4cf7fd[_0x56cf('0x4e')]?Mustache[_0x56cf('0x50')](_0x4cf7fd[_0x56cf('0x4e')],_0x5b9ae1):'';_0x56a382['winArguments']=_0x4cf7fd[_0x56cf('0x55')]?Mustache[_0x56cf('0x50')](_0x4cf7fd[_0x56cf('0x55')],_0x5b9ae1):'';break;}this[_0x56cf('0x39')](util[_0x56cf('0x5f')](_0x56cf('0x60'),this[_0x56cf('0x10')][_0x5b9ae1['interface']]['name']),util[_0x56cf('0x5f')](_0x56cf('0x61'),_0x4cf7fd[_0x56cf('0x49')][_0x56cf('0x4a')](),barAndWebActions[_0x4cf7fd[_0x56cf('0x4c')]]),_[_0x56cf('0x45')](_0x56a382,_0x5b9ae1));break;case'jscripty':this['emit'](util['format']('user:%s',this[_0x56cf('0x10')][_0x5b9ae1[_0x56cf('0x41')]]['name']),util[_0x56cf('0x5f')](_0x56cf('0x62'),_0x4cf7fd['action']['toLowerCase']()),_[_0x56cf('0x45')]({'ProjectId':parseInt(_0x4cf7fd[_0x56cf('0x4c')],0xa)},_0x5b9ae1));break;default:this['emit'](util[_0x56cf('0x5f')](_0x56cf('0x60'),this[_0x56cf('0x10')][_0x5b9ae1['interface']]['name']),util[_0x56cf('0x5f')](_0x56cf('0x62'),_0x4cf7fd[_0x56cf('0x49')]['toLowerCase']()),_['merge']({},_0x4cf7fd,_0x5b9ae1));}}switch(_0x4cf7fd[_0x56cf('0x49')][_0x56cf('0x4a')]()){case _0x56cf('0x63'):cmContact[_0x56cf('0x64')](this[_0x56cf('0x10')][_0x5b9ae1[_0x56cf('0x41')]],this[_0x56cf('0xf')][_0x286f22],_0x4cf7fd,_0x5b9ae1);break;case'integration':integration['exec'](_0x4cf7fd,_0x5b9ae1,this['accounts'],this[_0x56cf('0x10')][_0x5b9ae1['interface']],this[_0x56cf('0x11')][_0x5b9ae1[_0x56cf('0x65')]],this['voiceExtensions'][_0x5b9ae1[_0x56cf('0x66')]]);break;case _0x56cf('0x67'):urlforward[_0x56cf('0x64')](_0x4cf7fd,_0x5b9ae1);break;case _0x56cf('0x68'):script[_0x56cf('0x64')](_0x4cf7fd,_0x5b9ae1);break;}}}}}}};Trigger[_0x56cf('0x36')][_0x56cf('0x53')]=function(_0x2d4553,_0x13f8bb,_0x318418){var _0x3e0bc3=url[_0x56cf('0x69')](Mustache[_0x56cf('0x50')](_0x2d4553,_0x13f8bb),!![]);if(_0x318418){_[_0x56cf('0x45')](_0x3e0bc3['query'],_0x13f8bb);}delete _0x3e0bc3[_0x56cf('0x6a')];var _0x2d7914=url['format'](_0x3e0bc3);_0x2d7914=_0x2d7914[_0x56cf('0x6b')](/\/\?/g,'?');return _0x2d7914;};Trigger[_0x56cf('0x36')][_0x56cf('0x44')]=function(_0x39bc0f,_0x218f64){var _0x2d6157=!![];var _0xb06407=!![];var _0x3decad=![];if(_0x39bc0f[_0x56cf('0x6c')]===_0x218f64[_0x56cf('0x3b')]){_0x3decad=!![];}if(_0x39bc0f[_0x56cf('0x6d')][_0x56cf('0x48')]){_0x2d6157=_['every'](_0x39bc0f[_0x56cf('0x6d')],this[_0x56cf('0x6e')](_0x218f64,_0x39bc0f[_0x56cf('0x6c')]));}if(_0x39bc0f[_0x56cf('0x6f')][_0x56cf('0x48')]){_0xb06407=_['some'](_0x39bc0f[_0x56cf('0x6f')],this[_0x56cf('0x6e')](_0x218f64,_0x39bc0f[_0x56cf('0x6c')]));}var _0x160a81=_0x3decad&&_0x2d6157&&_0xb06407;logger['debug'](_0x56cf('0x70'),util['inspect'](_0x39bc0f,{'showHidden':!![],'depth':null}),_0x56cf('0x71'),util[_0x56cf('0x3f')](_0x218f64,{'showHidden':!![],'depth':null}),_0x3decad,_0x2d6157,_0xb06407);return _0x160a81;};Trigger['prototype']['checkConditions']=function(_0x30ac0c,_0x3993b5){return function(_0x3eff56){switch(_0x3eff56[_0x56cf('0x72')]){case _0x56cf('0x73'):if(_0x30ac0c[_0x56cf('0x6c')]===_0x3993b5){if(_0x3993b5===_0x56cf('0x74')){return _0x30ac0c[_0x56cf('0x75')]?operators[_0x3eff56['operator']](Number(_0x3eff56[_0x56cf('0x76')]),_0x30ac0c[_0x56cf('0x75')]):![];}else{return _0x30ac0c[_[_0x56cf('0x77')](_0x3993b5)+_0x56cf('0x78')]?operators[_0x3eff56[_0x56cf('0x79')]](Number(_0x3eff56[_0x56cf('0x76')]),_0x30ac0c[_['upperFirst'](_0x3993b5)+_0x56cf('0x78')]):![];}}break;case _0x56cf('0x7a'):case'message':if(_0x30ac0c[_0x56cf('0x6c')]===_0x3993b5){return _0x30ac0c[_0x56cf('0x7b')]?operators[_0x3eff56[_0x56cf('0x79')]](_0x3eff56[_0x56cf('0x76')],_0x30ac0c[_0x56cf('0x7b')]):![];}break;case _0x56cf('0x65'):return _0x30ac0c[_0x56cf('0x65')]?operators[_0x3eff56[_0x56cf('0x79')]](_0x3eff56[_0x56cf('0x76')],_0x30ac0c[_0x56cf('0x65')]):![];case _0x56cf('0x7c'):return _0x30ac0c[_0x56cf('0x7d')]?operators[_0x3eff56[_0x56cf('0x79')]](_0x3eff56[_0x56cf('0x76')],_0x30ac0c['membername']):![];case _0x56cf('0x7e'):return _0x30ac0c[_0x56cf('0x7e')]?operators[_0x3eff56[_0x56cf('0x79')]](_0x3eff56[_0x56cf('0x76')],_0x30ac0c[_0x56cf('0x7e')]):![];case _0x56cf('0x66'):return _0x30ac0c[_0x56cf('0x66')]?operators[_0x3eff56[_0x56cf('0x79')]](_0x3eff56[_0x56cf('0x76')],_0x30ac0c[_0x56cf('0x66')]):![];case _0x56cf('0x7f'):if(_0x3eff56[_0x56cf('0x76')]===_0x56cf('0x80'))_0x3eff56['value']=null;return typeof _0x30ac0c[_0x56cf('0x81')]!=='undefined'?operators[_0x3eff56['operator']](_0x3eff56[_0x56cf('0x76')],_0x30ac0c['substatus']):![];case _0x56cf('0x82'):if(_0x30ac0c[_0x56cf('0x6c')]===_0x3993b5){return _0x3eff56[_0x56cf('0x76')]===_0x56cf('0x83')&&_0x3eff56[_0x56cf('0x79')]==='equals'?!![]:![];}break;}return![];};};module[_0x56cf('0x84')]=Trigger;