Built motion from commit 06eb8eb0.|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 _0xcbe1=['emit','info','clone','motionChannel','undefined','voice','inspect','checkTriggers','hasOwnProperty','status','checkTrigger','merge','variables','Actions','length','interface','action','toLowerCase','contactmanager','motionbar','browser','html','render','uri','buildUri','data2','data3','isNil','location','uriLocation','windowWidth','data5','800','windowHeight','600','data6','winApplication','winArguments','format','user:%s','trigger:%s:%s','jscripty','trigger:%s','data1','name','exec','integration','queue','routeId','urlforward','script','parse','query','search','replace','channel','AllConditions','every','checkConditions','AnyConditions','some','checkTrigger:\x20trigger','field','account','chat','ChatWebsiteId','operator','value','upperFirst','interaction','message','event','agent','membername','lastevent','mailSubstatus','null','substatus','offlineMessage','equals','util','lodash','url','ioredis','./cmContact','../../../config/environment','../../../config/logger','trigger','../ami','redis','defaults','localhost','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:agentcomplete','custom:agentnoanswer','custom:agentbusy','custom:agentcongestion','custom:agentreject','custom:amd','custom:queuecallerabandon','custom:timeout','custom:dialbegin','syncAgentDial','custom:dialconnect','custom:dialend','custom:newinteraction','custom:closedinteraction','custom:substatus','custom:incomingmessage','custom:acceptmessage','custom:rejectmessage','custom:offlineMessage','prototype'];(function(_0x53e19d,_0x604957){var _0x5ba332=function(_0x34f66e){while(--_0x34f66e){_0x53e19d['push'](_0x53e19d['shift']());}};_0x5ba332(++_0x604957);}(_0xcbe1,0xd7));var _0x1cbe=function(_0x127728,_0x11c9c5){_0x127728=_0x127728-0x0;var _0x3b6cfe=_0xcbe1[_0x127728];return _0x3b6cfe;};'use strict';var util=require(_0x1cbe('0x0'));var _=require(_0x1cbe('0x1'));var url=require(_0x1cbe('0x2'));var Mustache=require('mustache');var Redis=require(_0x1cbe('0x3'));var urlforward=require('./urlforward');var integration=require('./integration');var cmContact=require(_0x1cbe('0x4'));var script=require('./script');var config=require(_0x1cbe('0x5'));var logger=require(_0x1cbe('0x6'))(_0x1cbe('0x7'));var ami=require(_0x1cbe('0x8'));config[_0x1cbe('0x9')]=_[_0x1cbe('0xa')](config[_0x1cbe('0x9')],{'host':_0x1cbe('0xb'),'port':0x18eb});var io=require(_0x1cbe('0xc'))(new Redis(config[_0x1cbe('0x9')]));var operators={'equals':function(_0x196b5a,_0x2325bc){return _0x196b5a==_0x2325bc;},'not_equals':function(_0x2cd82b,_0x22268c){return _0x2cd82b!=_0x22268c;}};var barAndWebActions=[_0x1cbe('0xd'),_0x1cbe('0x2'),_0x1cbe('0xe')];function Trigger(_0x1d10e3){this[_0x1cbe('0xf')]=_0x1d10e3[_0x1cbe('0xf')];this[_0x1cbe('0x10')]=_0x1d10e3['agents'];this[_0x1cbe('0x11')]=_0x1d10e3[_0x1cbe('0x11')];this[_0x1cbe('0x12')]=_0x1d10e3[_0x1cbe('0x12')];this[_0x1cbe('0x13')]=_0x1d10e3[_0x1cbe('0x13')];this[_0x1cbe('0x14')]=_0x1d10e3['zendeskAccounts'];this['freshdeskAccounts']=_0x1d10e3[_0x1cbe('0x15')];this[_0x1cbe('0x16')]=_0x1d10e3[_0x1cbe('0x16')];this[_0x1cbe('0x17')]=_0x1d10e3[_0x1cbe('0x17')];this[_0x1cbe('0x18')]=_0x1d10e3[_0x1cbe('0x18')];this[_0x1cbe('0x19')]=_0x1d10e3[_0x1cbe('0x19')];this[_0x1cbe('0x1a')]=_0x1d10e3[_0x1cbe('0x1a')];this[_0x1cbe('0x1b')]=_0x1d10e3[_0x1cbe('0x1b')];this[_0x1cbe('0x1c')]=_0x1d10e3['dynamics365Accounts'];this[_0x1cbe('0x1d')]=_0x1d10e3[_0x1cbe('0x1d')];this[_0x1cbe('0x1e')]={'zendesk':this[_0x1cbe('0x14')],'salesforce':this[_0x1cbe('0x16')],'freshdesk':this[_0x1cbe('0x15')],'sugarcrm':this[_0x1cbe('0x17')],'zoho':this[_0x1cbe('0x18')],'desk':this[_0x1cbe('0x19')],'vtiger':this['vtigerAccounts'],'dynamics365':this[_0x1cbe('0x1c')],'freshsales':this['freshsalesAccounts'],'servicenow':this['servicenowAccounts']};ami['on'](_0x1cbe('0x1f'),this[_0x1cbe('0x20')][_0x1cbe('0x21')](this));ami['on'](_0x1cbe('0x22'),this[_0x1cbe('0x20')][_0x1cbe('0x21')](this));ami['on']('custom:agentringnoanswer',this[_0x1cbe('0x20')][_0x1cbe('0x21')](this));ami['on'](_0x1cbe('0x23'),this[_0x1cbe('0x20')]['bind'](this));ami['on']('custom:agentnosuchnumber',this['syncCustomEvent']['bind'](this));ami['on'](_0x1cbe('0x24'),this['syncCustomEvent'][_0x1cbe('0x21')](this));ami['on'](_0x1cbe('0x25'),this[_0x1cbe('0x20')][_0x1cbe('0x21')](this));ami['on'](_0x1cbe('0x26'),this[_0x1cbe('0x20')][_0x1cbe('0x21')](this));ami['on'](_0x1cbe('0x27'),this['syncCustomEvent']['bind'](this));ami['on'](_0x1cbe('0x28'),this[_0x1cbe('0x20')][_0x1cbe('0x21')](this));ami['on'](_0x1cbe('0x29'),this[_0x1cbe('0x20')][_0x1cbe('0x21')](this));ami['on'](_0x1cbe('0x2a'),this['syncCustomEvent'][_0x1cbe('0x21')](this));ami['on'](_0x1cbe('0x2b'),this[_0x1cbe('0x2c')][_0x1cbe('0x21')](this));ami['on'](_0x1cbe('0x2d'),this[_0x1cbe('0x2c')][_0x1cbe('0x21')](this));ami['on'](_0x1cbe('0x2e'),this['syncAgentDial'][_0x1cbe('0x21')](this));ami['on'](_0x1cbe('0x2f'),this[_0x1cbe('0x20')]['bind'](this));ami['on'](_0x1cbe('0x30'),this[_0x1cbe('0x20')][_0x1cbe('0x21')](this));ami['on'](_0x1cbe('0x31'),this['syncCustomEvent'][_0x1cbe('0x21')](this));ami['on'](_0x1cbe('0x32'),this[_0x1cbe('0x20')][_0x1cbe('0x21')](this));ami['on']('custom:outgoingmessage',this['syncCustomEvent'][_0x1cbe('0x21')](this));ami['on'](_0x1cbe('0x33'),this[_0x1cbe('0x20')][_0x1cbe('0x21')](this));ami['on'](_0x1cbe('0x34'),this[_0x1cbe('0x20')]['bind'](this));ami['on'](_0x1cbe('0x35'),this['syncCustomEvent'][_0x1cbe('0x21')](this));}Trigger[_0x1cbe('0x36')][_0x1cbe('0x37')]=function(_0x29dad7,_0x13f6a5,_0x4c2880){logger[_0x1cbe('0x38')](_0x29dad7,_0x13f6a5,JSON['stringify'](_0x4c2880));io['to'](_0x29dad7)[_0x1cbe('0x37')](_0x13f6a5,_0x4c2880);};Trigger[_0x1cbe('0x36')][_0x1cbe('0x20')]=function(_0x46a439){var _0x5bb94c=_[_0x1cbe('0x39')](_0x46a439);if(typeof _0x5bb94c[_0x1cbe('0x3a')]===_0x1cbe('0x3b')){_0x5bb94c[_0x1cbe('0x3a')]=_0x1cbe('0x3c');}logger['debug'](_0x1cbe('0x20'),util[_0x1cbe('0x3d')](_0x5bb94c,{'showHidden':!![],'depth':null}));this[_0x1cbe('0x3e')](_0x5bb94c);};Trigger[_0x1cbe('0x36')][_0x1cbe('0x2c')]=function(_0x4df798){if(this['agents'][_0x4df798['interface']]){this['syncCustomEvent'](_0x4df798);}};Trigger[_0x1cbe('0x36')]['checkTriggers']=function(_0x55b454){var _0x2418ad;for(var _0x2f75a0 in this[_0x1cbe('0xf')]){if(this[_0x1cbe('0xf')][_0x1cbe('0x3f')](_0x2f75a0)){if(this[_0x1cbe('0xf')][_0x2f75a0][_0x1cbe('0x40')]){_0x2418ad=this[_0x1cbe('0x41')](this['triggers'][_0x2f75a0],_0x55b454);if(_0x2418ad){_[_0x1cbe('0x42')](_0x55b454,_0x55b454[_0x1cbe('0x43')]);for(var _0x2a23a9=0x0,_0x5ea8f8,_0x3db552,_0x196a48;_0x2a23a9<this[_0x1cbe('0xf')][_0x2f75a0][_0x1cbe('0x44')][_0x1cbe('0x45')];_0x2a23a9+=0x1){_0x5ea8f8=this[_0x1cbe('0xf')][_0x2f75a0][_0x1cbe('0x44')][_0x2a23a9];if(this[_0x1cbe('0x10')][_0x55b454[_0x1cbe('0x46')]]){switch(_0x5ea8f8[_0x1cbe('0x47')][_0x1cbe('0x48')]()){case _0x1cbe('0x49'):break;case _0x1cbe('0x4a'):case _0x1cbe('0x4b'):var _0x538a0d={};switch(barAndWebActions[_0x5ea8f8['data1']]){case _0x1cbe('0xd'):_0x538a0d['TemplateId']=_0x5ea8f8['data2'];_0x538a0d[_0x1cbe('0x4c')]=this['templates'][_0x5ea8f8['data2']]?Mustache[_0x1cbe('0x4d')](this['templates'][_0x5ea8f8['data2']]['html'],_0x55b454):'template\x20not\x20found';break;case _0x1cbe('0x2'):_0x538a0d[_0x1cbe('0x4e')]=this[_0x1cbe('0x4f')](_0x5ea8f8[_0x1cbe('0x50')],_0x55b454,_['isNil'](_0x5ea8f8[_0x1cbe('0x51')])?!![]:parseInt(_0x5ea8f8[_0x1cbe('0x51')],0xa));if(_[_0x1cbe('0x52')](_0x5ea8f8['data4'])){_0x538a0d[_0x1cbe('0x53')]='0';}else{_0x538a0d[_0x1cbe('0x54')]=_0x5ea8f8['data4'];_0x538a0d[_0x1cbe('0x55')]=_['isNil'](_0x5ea8f8[_0x1cbe('0x56')])?_0x1cbe('0x57'):_0x5ea8f8[_0x1cbe('0x56')];_0x538a0d[_0x1cbe('0x58')]=_[_0x1cbe('0x52')](_0x5ea8f8['data6'])?_0x1cbe('0x59'):_0x5ea8f8[_0x1cbe('0x5a')];}break;case _0x1cbe('0xe'):_0x538a0d[_0x1cbe('0x5b')]=_0x5ea8f8['data2']?Mustache['render'](_0x5ea8f8['data2'],_0x55b454):'';_0x538a0d[_0x1cbe('0x5c')]=_0x5ea8f8[_0x1cbe('0x51')]?Mustache['render'](_0x5ea8f8[_0x1cbe('0x51')],_0x55b454):'';break;}this['emit'](util[_0x1cbe('0x5d')](_0x1cbe('0x5e'),this[_0x1cbe('0x10')][_0x55b454['interface']]['name']),util[_0x1cbe('0x5d')](_0x1cbe('0x5f'),_0x5ea8f8[_0x1cbe('0x47')][_0x1cbe('0x48')](),barAndWebActions[_0x5ea8f8['data1']]),_[_0x1cbe('0x42')](_0x538a0d,_0x55b454));break;case _0x1cbe('0x60'):this[_0x1cbe('0x37')](util[_0x1cbe('0x5d')](_0x1cbe('0x5e'),this[_0x1cbe('0x10')][_0x55b454[_0x1cbe('0x46')]]['name']),util['format'](_0x1cbe('0x61'),_0x5ea8f8[_0x1cbe('0x47')][_0x1cbe('0x48')]()),_['merge']({'ProjectId':parseInt(_0x5ea8f8[_0x1cbe('0x62')],0xa)},_0x55b454));break;default:this[_0x1cbe('0x37')](util['format']('user:%s',this[_0x1cbe('0x10')][_0x55b454['interface']][_0x1cbe('0x63')]),util[_0x1cbe('0x5d')]('trigger:%s',_0x5ea8f8['action'][_0x1cbe('0x48')]()),_[_0x1cbe('0x42')]({},_0x5ea8f8,_0x55b454));}}switch(_0x5ea8f8[_0x1cbe('0x47')][_0x1cbe('0x48')]()){case _0x1cbe('0x49'):cmContact[_0x1cbe('0x64')](this['agents'][_0x55b454[_0x1cbe('0x46')]],this[_0x1cbe('0xf')][_0x2f75a0],_0x5ea8f8,_0x55b454);break;case _0x1cbe('0x65'):integration['exec'](_0x5ea8f8,_0x55b454,this[_0x1cbe('0x1e')],this[_0x1cbe('0x10')][_0x55b454[_0x1cbe('0x46')]],this[_0x1cbe('0x11')][_0x55b454[_0x1cbe('0x66')]],this[_0x1cbe('0x13')][_0x55b454[_0x1cbe('0x67')]]);break;case _0x1cbe('0x68'):urlforward['exec'](_0x5ea8f8,_0x55b454);break;case _0x1cbe('0x69'):script['exec'](_0x5ea8f8,_0x55b454);break;}}}}}}};Trigger['prototype'][_0x1cbe('0x4f')]=function(_0x4b3319,_0x17f57b,_0x3e5b7a){var _0x335fcb=url[_0x1cbe('0x6a')](Mustache[_0x1cbe('0x4d')](_0x4b3319,_0x17f57b),!![]);if(_0x3e5b7a){_['merge'](_0x335fcb[_0x1cbe('0x6b')],_0x17f57b);}delete _0x335fcb[_0x1cbe('0x6c')];var _0x4528ec=url[_0x1cbe('0x5d')](_0x335fcb);_0x4528ec=_0x4528ec[_0x1cbe('0x6d')](/\/\?/g,'?');return _0x4528ec;};Trigger['prototype'][_0x1cbe('0x41')]=function(_0x28aa81,_0x1a3bf3){var _0x8097db=!![];var _0x40ae5e=!![];var _0x25e57d=![];if(_0x28aa81[_0x1cbe('0x6e')]===_0x1a3bf3[_0x1cbe('0x3a')]){_0x25e57d=!![];}if(_0x28aa81[_0x1cbe('0x6f')][_0x1cbe('0x45')]){_0x8097db=_[_0x1cbe('0x70')](_0x28aa81['AllConditions'],this[_0x1cbe('0x71')](_0x1a3bf3,_0x28aa81[_0x1cbe('0x6e')]));}if(_0x28aa81[_0x1cbe('0x72')]['length']){_0x40ae5e=_[_0x1cbe('0x73')](_0x28aa81[_0x1cbe('0x72')],this[_0x1cbe('0x71')](_0x1a3bf3,_0x28aa81[_0x1cbe('0x6e')]));}var _0x52ec23=_0x25e57d&&_0x8097db&&_0x40ae5e;logger['debug'](_0x1cbe('0x74'),util[_0x1cbe('0x3d')](_0x28aa81,{'showHidden':!![],'depth':null}),'evt',util[_0x1cbe('0x3d')](_0x1a3bf3,{'showHidden':!![],'depth':null}),_0x25e57d,_0x8097db,_0x40ae5e);return _0x52ec23;};Trigger['prototype'][_0x1cbe('0x71')]=function(_0x53ad37,_0x6d06cb){return function(_0x5eff33){switch(_0x5eff33[_0x1cbe('0x75')]){case _0x1cbe('0x76'):if(_0x53ad37[_0x1cbe('0x6e')]===_0x6d06cb){if(_0x6d06cb===_0x1cbe('0x77')){return _0x53ad37[_0x1cbe('0x78')]?operators[_0x5eff33[_0x1cbe('0x79')]](Number(_0x5eff33[_0x1cbe('0x7a')]),_0x53ad37[_0x1cbe('0x78')]):![];}else{return _0x53ad37[_[_0x1cbe('0x7b')](_0x6d06cb)+'AccountId']?operators[_0x5eff33[_0x1cbe('0x79')]](Number(_0x5eff33['value']),_0x53ad37[_['upperFirst'](_0x6d06cb)+'AccountId']):![];}}break;case _0x1cbe('0x7c'):case _0x1cbe('0x7d'):if(_0x53ad37[_0x1cbe('0x6e')]===_0x6d06cb){return _0x53ad37[_0x1cbe('0x7e')]?operators[_0x5eff33[_0x1cbe('0x79')]](_0x5eff33[_0x1cbe('0x7a')],_0x53ad37[_0x1cbe('0x7e')]):![];}break;case _0x1cbe('0x66'):return _0x53ad37[_0x1cbe('0x66')]?operators[_0x5eff33['operator']](_0x5eff33[_0x1cbe('0x7a')],_0x53ad37[_0x1cbe('0x66')]):![];case _0x1cbe('0x7f'):return _0x53ad37[_0x1cbe('0x80')]?operators[_0x5eff33['operator']](_0x5eff33['value'],_0x53ad37[_0x1cbe('0x80')]):![];case _0x1cbe('0x81'):return _0x53ad37[_0x1cbe('0x81')]?operators[_0x5eff33[_0x1cbe('0x79')]](_0x5eff33[_0x1cbe('0x7a')],_0x53ad37['lastevent']):![];case _0x1cbe('0x67'):return _0x53ad37[_0x1cbe('0x67')]?operators[_0x5eff33[_0x1cbe('0x79')]](_0x5eff33['value'],_0x53ad37['routeId']):![];case _0x1cbe('0x82'):if(_0x5eff33['value']===_0x1cbe('0x83'))_0x5eff33['value']=null;return typeof _0x53ad37['substatus']!==_0x1cbe('0x3b')?operators[_0x5eff33[_0x1cbe('0x79')]](_0x5eff33[_0x1cbe('0x7a')],_0x53ad37[_0x1cbe('0x84')]):![];case _0x1cbe('0x85'):if(_0x53ad37[_0x1cbe('0x6e')]===_0x6d06cb){return _0x5eff33[_0x1cbe('0x7a')]==='created'&&_0x5eff33['operator']===_0x1cbe('0x86')?!![]:![];}break;}return![];};};module['exports']=Trigger;