cf12ce8ee3476b3a301f055e4eb9f0afdfac8840
[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 _0x5025=['salesforceAccounts','sugarcrmAccounts','zohoAccounts','deskAccounts','vtigerAccounts','servicenowAccounts','dynamics365Accounts','freshsalesAccounts','freshdeskAccounts','custom:agentcalled','syncCustomEvent','bind','custom:agentconnect','custom:agentringnoanswer','custom:agentnosuchnumber','custom:agentnoanswer','custom:queuecallerabandon','custom:timeout','syncAgentDial','custom:dialconnect','custom:dialend','custom:closedinteraction','custom:outgoingmessage','custom:acceptmessage','custom:rejectmessage','prototype','emit','info','stringify','clone','checkTriggers','interface','triggers','status','checkTrigger','merge','variables','length','Actions','action','contactmanager','motionbar','browser','data1','data2','html','render','template\x20not\x20found','uri','buildUri','isNil','data3','data4','location','windowWidth','800','data5','windowHeight','600','data6','winApplication','winArguments','name','format','toLowerCase','jscripty','trigger:%s','user:%s','exec','integration','accounts','queue','routeId','urlforward','script','parse','query','search','replace','every','AllConditions','checkConditions','channel','AnyConditions','field','account','chat','ChatWebsiteId','value','AccountId','upperFirst','interaction','message','operator','event','agent','membername','lastevent','exports','util','lodash','url','mustache','ioredis','./integration','./cmContact','./script','../rpc/cmContact','../../../config/environment','../../../config/logger','../ami','redis','defaults','socket.io-emitter','popup','winapp','agents','voiceQueues','templates','voiceExtensions','zendeskAccounts'];(function(_0x201fce,_0x35b92e){var _0x44dad3=function(_0x3ce235){while(--_0x3ce235){_0x201fce['push'](_0x201fce['shift']());}};_0x44dad3(++_0x35b92e);}(_0x5025,0xdc));var _0x5502=function(_0x1d6dea,_0x1f8978){_0x1d6dea=_0x1d6dea-0x0;var _0x1b5967=_0x5025[_0x1d6dea];return _0x1b5967;};'use strict';var util=require(_0x5502('0x0'));var _=require(_0x5502('0x1'));var url=require(_0x5502('0x2'));var Mustache=require(_0x5502('0x3'));var Redis=require(_0x5502('0x4'));var urlforward=require('./urlforward');var integration=require(_0x5502('0x5'));var cmContact=require(_0x5502('0x6'));var script=require(_0x5502('0x7'));var cmContactRpc=require(_0x5502('0x8'));var config=require(_0x5502('0x9'));var logger=require(_0x5502('0xa'))('trigger');var ami=require(_0x5502('0xb'));config[_0x5502('0xc')]=_[_0x5502('0xd')](config[_0x5502('0xc')],{'host':'localhost','port':0x18eb});var io=require(_0x5502('0xe'))(new Redis(config[_0x5502('0xc')]));var operators={'equals':function(_0x24f542,_0xf4bdd0){return _0x24f542==_0xf4bdd0;},'not_equals':function(_0x5a6421,_0x3e5077){return _0x5a6421!=_0x3e5077;}};var barAndWebActions=[_0x5502('0xf'),'url',_0x5502('0x10')];function Trigger(_0x547b28){this['triggers']=_0x547b28['triggers'];this[_0x5502('0x11')]=_0x547b28[_0x5502('0x11')];this['voiceQueues']=_0x547b28[_0x5502('0x12')];this['templates']=_0x547b28[_0x5502('0x13')];this[_0x5502('0x14')]=_0x547b28[_0x5502('0x14')];this[_0x5502('0x15')]=_0x547b28[_0x5502('0x15')];this['freshdeskAccounts']=_0x547b28['freshdeskAccounts'];this[_0x5502('0x16')]=_0x547b28[_0x5502('0x16')];this[_0x5502('0x17')]=_0x547b28[_0x5502('0x17')];this[_0x5502('0x18')]=_0x547b28[_0x5502('0x18')];this[_0x5502('0x19')]=_0x547b28[_0x5502('0x19')];this[_0x5502('0x1a')]=_0x547b28[_0x5502('0x1a')];this[_0x5502('0x1b')]=_0x547b28[_0x5502('0x1b')];this[_0x5502('0x1c')]=_0x547b28[_0x5502('0x1c')];this[_0x5502('0x1d')]=_0x547b28[_0x5502('0x1d')];this['accounts']={'zendesk':this[_0x5502('0x15')],'salesforce':this[_0x5502('0x16')],'freshdesk':this[_0x5502('0x1e')],'sugarcrm':this[_0x5502('0x17')],'zoho':this[_0x5502('0x18')],'desk':this[_0x5502('0x19')],'vtiger':this[_0x5502('0x1a')],'dynamics365':this['dynamics365Accounts'],'freshsales':this[_0x5502('0x1d')],'servicenow':this['servicenowAccounts']};ami['on'](_0x5502('0x1f'),this[_0x5502('0x20')][_0x5502('0x21')](this));ami['on'](_0x5502('0x22'),this[_0x5502('0x20')][_0x5502('0x21')](this));ami['on'](_0x5502('0x23'),this[_0x5502('0x20')][_0x5502('0x21')](this));ami['on']('custom:agentcomplete',this[_0x5502('0x20')][_0x5502('0x21')](this));ami['on'](_0x5502('0x24'),this[_0x5502('0x20')]['bind'](this));ami['on'](_0x5502('0x25'),this[_0x5502('0x20')]['bind'](this));ami['on']('custom:agentbusy',this['syncCustomEvent'][_0x5502('0x21')](this));ami['on']('custom:agentcongestion',this[_0x5502('0x20')][_0x5502('0x21')](this));ami['on']('custom:agentreject',this[_0x5502('0x20')][_0x5502('0x21')](this));ami['on'](_0x5502('0x26'),this[_0x5502('0x20')]['bind'](this));ami['on'](_0x5502('0x27'),this[_0x5502('0x20')][_0x5502('0x21')](this));ami['on']('custom:dialbegin',this[_0x5502('0x28')][_0x5502('0x21')](this));ami['on'](_0x5502('0x29'),this['syncAgentDial'][_0x5502('0x21')](this));ami['on'](_0x5502('0x2a'),this[_0x5502('0x28')][_0x5502('0x21')](this));ami['on']('custom:newinteraction',this['syncCustomEvent'][_0x5502('0x21')](this));ami['on'](_0x5502('0x2b'),this[_0x5502('0x20')][_0x5502('0x21')](this));ami['on']('custom:incomingmessage',this[_0x5502('0x20')][_0x5502('0x21')](this));ami['on'](_0x5502('0x2c'),this[_0x5502('0x20')][_0x5502('0x21')](this));ami['on'](_0x5502('0x2d'),this[_0x5502('0x20')]['bind'](this));ami['on'](_0x5502('0x2e'),this[_0x5502('0x20')]['bind'](this));}Trigger[_0x5502('0x2f')][_0x5502('0x30')]=function(_0x2e6d7f,_0x15a989,_0x404173){logger[_0x5502('0x31')](_0x2e6d7f,_0x15a989,JSON[_0x5502('0x32')](_0x404173));io['to'](_0x2e6d7f)[_0x5502('0x30')](_0x15a989,_0x404173);};Trigger[_0x5502('0x2f')]['syncCustomEvent']=function(_0x17fcf9){var _0x1adff8=_[_0x5502('0x33')](_0x17fcf9);this[_0x5502('0x34')](_0x1adff8);};Trigger[_0x5502('0x2f')][_0x5502('0x28')]=function(_0x1afe81){if(this[_0x5502('0x11')][_0x1afe81[_0x5502('0x35')]]){this[_0x5502('0x20')](_0x1afe81);}};Trigger[_0x5502('0x2f')][_0x5502('0x34')]=function(_0x340e66){var _0x2ecb88;for(var _0x53e520 in this[_0x5502('0x36')]){if(this[_0x5502('0x36')]['hasOwnProperty'](_0x53e520)){if(this['triggers'][_0x53e520][_0x5502('0x37')]){_0x2ecb88=this[_0x5502('0x38')](this[_0x5502('0x36')][_0x53e520],_0x340e66);if(_0x2ecb88){_[_0x5502('0x39')](_0x340e66,_0x340e66[_0x5502('0x3a')]);for(var _0x3c01c4=0x0,_0x1a345b,_0x426883,_0x5c6793;_0x3c01c4<this['triggers'][_0x53e520]['Actions'][_0x5502('0x3b')];_0x3c01c4+=0x1){_0x1a345b=this['triggers'][_0x53e520][_0x5502('0x3c')][_0x3c01c4];if(this[_0x5502('0x11')][_0x340e66['interface']]){switch(_0x1a345b[_0x5502('0x3d')]['toLowerCase']()){case _0x5502('0x3e'):break;case _0x5502('0x3f'):case _0x5502('0x40'):var _0x501088={};switch(barAndWebActions[_0x1a345b[_0x5502('0x41')]]){case _0x5502('0xf'):_0x501088['TemplateId']=_0x1a345b[_0x5502('0x42')];_0x501088[_0x5502('0x43')]=this[_0x5502('0x13')][_0x1a345b['data2']]?Mustache[_0x5502('0x44')](this['templates'][_0x1a345b[_0x5502('0x42')]]['html'],_0x340e66):_0x5502('0x45');break;case _0x5502('0x2'):_0x501088[_0x5502('0x46')]=this[_0x5502('0x47')](_0x1a345b['data2'],_0x340e66,_[_0x5502('0x48')](_0x1a345b['data3'])?!![]:parseInt(_0x1a345b[_0x5502('0x49')],0xa));if(_['isNil'](_0x1a345b[_0x5502('0x4a')])){_0x501088[_0x5502('0x4b')]='0';}else{_0x501088['uriLocation']=_0x1a345b[_0x5502('0x4a')];_0x501088[_0x5502('0x4c')]=_[_0x5502('0x48')](_0x1a345b['data5'])?_0x5502('0x4d'):_0x1a345b[_0x5502('0x4e')];_0x501088[_0x5502('0x4f')]=_['isNil'](_0x1a345b['data6'])?_0x5502('0x50'):_0x1a345b[_0x5502('0x51')];}break;case'winapp':_0x501088[_0x5502('0x52')]=_0x1a345b[_0x5502('0x42')]?Mustache['render'](_0x1a345b[_0x5502('0x42')],_0x340e66):'';_0x501088[_0x5502('0x53')]=_0x1a345b['data3']?Mustache[_0x5502('0x44')](_0x1a345b[_0x5502('0x49')],_0x340e66):'';break;}this['emit'](util['format']('user:%s',this['agents'][_0x340e66[_0x5502('0x35')]][_0x5502('0x54')]),util[_0x5502('0x55')]('trigger:%s:%s',_0x1a345b[_0x5502('0x3d')][_0x5502('0x56')](),barAndWebActions[_0x1a345b[_0x5502('0x41')]]),_[_0x5502('0x39')](_0x501088,_0x340e66));break;case _0x5502('0x57'):this[_0x5502('0x30')](util['format']('user:%s',this[_0x5502('0x11')][_0x340e66[_0x5502('0x35')]][_0x5502('0x54')]),util['format'](_0x5502('0x58'),_0x1a345b['action'][_0x5502('0x56')]()),_[_0x5502('0x39')]({'ProjectId':parseInt(_0x1a345b[_0x5502('0x41')],0xa)},_0x340e66));break;default:this[_0x5502('0x30')](util[_0x5502('0x55')](_0x5502('0x59'),this[_0x5502('0x11')][_0x340e66['interface']][_0x5502('0x54')]),util[_0x5502('0x55')]('trigger:%s',_0x1a345b['action']['toLowerCase']()),_[_0x5502('0x39')]({},_0x1a345b,_0x340e66));}}switch(_0x1a345b['action'][_0x5502('0x56')]()){case _0x5502('0x3e'):cmContact[_0x5502('0x5a')](this[_0x5502('0x11')][_0x340e66[_0x5502('0x35')]],_0x1a345b,_0x340e66,cmContactRpc);break;case _0x5502('0x5b'):integration[_0x5502('0x5a')](_0x1a345b,_0x340e66,this[_0x5502('0x5c')],this['agents'][_0x340e66[_0x5502('0x35')]],this[_0x5502('0x12')][_0x340e66[_0x5502('0x5d')]],this['voiceExtensions'][_0x340e66[_0x5502('0x5e')]]);break;case _0x5502('0x5f'):urlforward[_0x5502('0x5a')](_0x1a345b,_0x340e66);break;case _0x5502('0x60'):script[_0x5502('0x5a')](_0x1a345b,_0x340e66);break;}}}}}}};Trigger['prototype']['buildUri']=function(_0x21cb8d,_0x4603cb,_0x2c6cf2){var _0xce74dd=url[_0x5502('0x61')](Mustache['render'](_0x21cb8d,_0x4603cb),!![]);if(_0x2c6cf2){_[_0x5502('0x39')](_0xce74dd[_0x5502('0x62')],_0x4603cb);}delete _0xce74dd[_0x5502('0x63')];var _0x23afca=url['format'](_0xce74dd);_0x23afca=_0x23afca[_0x5502('0x64')](/\/\?/g,'?');return _0x23afca;};Trigger['prototype'][_0x5502('0x38')]=function(_0xe40f,_0x3d5fb3){var _0xe23b8d=!![],_0x337c43=!![];if(_0xe40f['AllConditions'][_0x5502('0x3b')]){_0xe23b8d=_[_0x5502('0x65')](_0xe40f[_0x5502('0x66')],this[_0x5502('0x67')](_0x3d5fb3,_0xe40f[_0x5502('0x68')]));}if(_0xe40f[_0x5502('0x69')][_0x5502('0x3b')]){_0x337c43=_['some'](_0xe40f['AnyConditions'],this['checkConditions'](_0x3d5fb3,_0xe40f[_0x5502('0x68')]));}return _0xe23b8d&&_0x337c43;};Trigger[_0x5502('0x2f')]['checkConditions']=function(_0x316a73,_0x4a02f3){return function(_0x5c1f35){switch(_0x5c1f35[_0x5502('0x6a')]){case _0x5502('0x6b'):if(_0x316a73[_0x5502('0x68')]===_0x4a02f3){if(_0x4a02f3===_0x5502('0x6c')){return _0x316a73[_0x5502('0x6d')]?operators[_0x5c1f35['operator']](Number(_0x5c1f35[_0x5502('0x6e')]),_0x316a73[_0x5502('0x6d')]):![];}else{return _0x316a73[_['upperFirst'](_0x4a02f3)+_0x5502('0x6f')]?operators[_0x5c1f35['operator']](Number(_0x5c1f35[_0x5502('0x6e')]),_0x316a73[_[_0x5502('0x70')](_0x4a02f3)+_0x5502('0x6f')]):![];}}break;case _0x5502('0x71'):case _0x5502('0x72'):if(_0x316a73[_0x5502('0x68')]===_0x4a02f3){return _0x316a73['event']?operators[_0x5c1f35[_0x5502('0x73')]](_0x5c1f35['value'],_0x316a73[_0x5502('0x74')]):![];}break;case'queue':return _0x316a73['queue']?operators[_0x5c1f35['operator']](_0x5c1f35[_0x5502('0x6e')],_0x316a73[_0x5502('0x5d')]):![];case _0x5502('0x75'):return _0x316a73[_0x5502('0x76')]?operators[_0x5c1f35[_0x5502('0x73')]](_0x5c1f35['value'],_0x316a73[_0x5502('0x76')]):![];case _0x5502('0x77'):return _0x316a73[_0x5502('0x77')]?operators[_0x5c1f35[_0x5502('0x73')]](_0x5c1f35[_0x5502('0x6e')],_0x316a73[_0x5502('0x77')]):![];case _0x5502('0x5e'):return _0x316a73[_0x5502('0x5e')]?operators[_0x5c1f35['operator']](_0x5c1f35[_0x5502('0x6e')],_0x316a73['routeId']):![];}return![];};};module[_0x5502('0x78')]=Trigger;