d5ec1489051a3707648e3866e6e626f105da94dd
[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 _0xba3c=['voiceExtensions','zendeskAccounts','freshdeskAccounts','salesforceAccounts','sugarcrmAccounts','deskAccounts','vtigerAccounts','servicenowAccounts','dynamics365Accounts','freshsalesAccounts','accounts','zohoAccounts','custom:agentcalled','syncCustomEvent','bind','custom:agentconnect','custom:agentringnoanswer','custom:agentcomplete','custom:agentnoanswer','custom:agentbusy','custom:agentreject','custom:queuecallerabandon','custom:dialbegin','syncAgentDial','custom:dialconnect','custom:newinteraction','custom:incomingmessage','custom:acceptmessage','custom:offlineMessage','prototype','emit','info','stringify','clone','motionChannel','undefined','voice','debug','inspect','checkTriggers','interface','hasOwnProperty','checkTrigger','merge','variables','Actions','length','action','toLowerCase','contactmanager','browser','data1','TemplateId','data2','html','render','template\x20not\x20found','uri','isNil','data3','data4','uriLocation','windowWidth','800','data5','windowHeight','data6','600','winapp','winApplication','winArguments','user:%s','name','format','trigger:%s:%s','jscripty','trigger:%s','exec','script','buildUri','parse','query','search','replace','channel','AllConditions','every','checkConditions','AnyConditions','some','checkTrigger:\x20trigger','field','chat','operator','value','ChatWebsiteId','AccountId','upperFirst','message','event','queue','agent','membername','lastevent','routeId','null','substatus','offlineMessage','created','equals','exports','lodash','url','mustache','ioredis','./cmContact','./script','../../../config/environment','../../../config/logger','trigger','../ami','redis','defaults','socket.io-emitter','popup','triggers','agents','voiceQueues','templates'];(function(_0x274638,_0x578968){var _0x5755df=function(_0x3227d5){while(--_0x3227d5){_0x274638['push'](_0x274638['shift']());}};_0x5755df(++_0x578968);}(_0xba3c,0x1f2));var _0xcba3=function(_0x82bcd7,_0x2ac0b7){_0x82bcd7=_0x82bcd7-0x0;var _0x1ae6fc=_0xba3c[_0x82bcd7];return _0x1ae6fc;};'use strict';var util=require('util');var _=require(_0xcba3('0x0'));var url=require(_0xcba3('0x1'));var Mustache=require(_0xcba3('0x2'));var Redis=require(_0xcba3('0x3'));var urlforward=require('./urlforward');var integration=require('./integration');var cmContact=require(_0xcba3('0x4'));var script=require(_0xcba3('0x5'));var config=require(_0xcba3('0x6'));var logger=require(_0xcba3('0x7'))(_0xcba3('0x8'));var ami=require(_0xcba3('0x9'));config[_0xcba3('0xa')]=_[_0xcba3('0xb')](config[_0xcba3('0xa')],{'host':'localhost','port':0x18eb});var io=require(_0xcba3('0xc'))(new Redis(config[_0xcba3('0xa')]));var operators={'equals':function(_0x1a5329,_0x37615f){return _0x1a5329==_0x37615f;},'not_equals':function(_0x1b7332,_0x985fea){return _0x1b7332!=_0x985fea;}};var barAndWebActions=[_0xcba3('0xd'),_0xcba3('0x1'),'winapp'];function Trigger(_0x1dcffe){this[_0xcba3('0xe')]=_0x1dcffe['triggers'];this[_0xcba3('0xf')]=_0x1dcffe[_0xcba3('0xf')];this['voiceQueues']=_0x1dcffe[_0xcba3('0x10')];this[_0xcba3('0x11')]=_0x1dcffe[_0xcba3('0x11')];this[_0xcba3('0x12')]=_0x1dcffe[_0xcba3('0x12')];this[_0xcba3('0x13')]=_0x1dcffe[_0xcba3('0x13')];this['freshdeskAccounts']=_0x1dcffe[_0xcba3('0x14')];this[_0xcba3('0x15')]=_0x1dcffe['salesforceAccounts'];this['sugarcrmAccounts']=_0x1dcffe[_0xcba3('0x16')];this['zohoAccounts']=_0x1dcffe['zohoAccounts'];this[_0xcba3('0x17')]=_0x1dcffe['deskAccounts'];this[_0xcba3('0x18')]=_0x1dcffe[_0xcba3('0x18')];this[_0xcba3('0x19')]=_0x1dcffe[_0xcba3('0x19')];this['dynamics365Accounts']=_0x1dcffe[_0xcba3('0x1a')];this['freshsalesAccounts']=_0x1dcffe[_0xcba3('0x1b')];this[_0xcba3('0x1c')]={'zendesk':this[_0xcba3('0x13')],'salesforce':this[_0xcba3('0x15')],'freshdesk':this[_0xcba3('0x14')],'sugarcrm':this[_0xcba3('0x16')],'zoho':this[_0xcba3('0x1d')],'desk':this[_0xcba3('0x17')],'vtiger':this[_0xcba3('0x18')],'dynamics365':this[_0xcba3('0x1a')],'freshsales':this[_0xcba3('0x1b')],'servicenow':this['servicenowAccounts']};ami['on'](_0xcba3('0x1e'),this[_0xcba3('0x1f')][_0xcba3('0x20')](this));ami['on'](_0xcba3('0x21'),this[_0xcba3('0x1f')][_0xcba3('0x20')](this));ami['on'](_0xcba3('0x22'),this[_0xcba3('0x1f')]['bind'](this));ami['on'](_0xcba3('0x23'),this[_0xcba3('0x1f')]['bind'](this));ami['on']('custom:agentnosuchnumber',this[_0xcba3('0x1f')][_0xcba3('0x20')](this));ami['on'](_0xcba3('0x24'),this[_0xcba3('0x1f')][_0xcba3('0x20')](this));ami['on'](_0xcba3('0x25'),this[_0xcba3('0x1f')][_0xcba3('0x20')](this));ami['on']('custom:agentcongestion',this[_0xcba3('0x1f')]['bind'](this));ami['on'](_0xcba3('0x26'),this[_0xcba3('0x1f')]['bind'](this));ami['on']('custom:amd',this[_0xcba3('0x1f')][_0xcba3('0x20')](this));ami['on'](_0xcba3('0x27'),this[_0xcba3('0x1f')][_0xcba3('0x20')](this));ami['on']('custom:timeout',this[_0xcba3('0x1f')][_0xcba3('0x20')](this));ami['on'](_0xcba3('0x28'),this[_0xcba3('0x29')][_0xcba3('0x20')](this));ami['on'](_0xcba3('0x2a'),this[_0xcba3('0x29')][_0xcba3('0x20')](this));ami['on']('custom:dialend',this[_0xcba3('0x29')][_0xcba3('0x20')](this));ami['on'](_0xcba3('0x2b'),this[_0xcba3('0x1f')][_0xcba3('0x20')](this));ami['on']('custom:closedinteraction',this['syncCustomEvent'][_0xcba3('0x20')](this));ami['on']('custom:substatus',this[_0xcba3('0x1f')]['bind'](this));ami['on'](_0xcba3('0x2c'),this[_0xcba3('0x1f')][_0xcba3('0x20')](this));ami['on']('custom:outgoingmessage',this[_0xcba3('0x1f')]['bind'](this));ami['on'](_0xcba3('0x2d'),this[_0xcba3('0x1f')]['bind'](this));ami['on']('custom:rejectmessage',this['syncCustomEvent'][_0xcba3('0x20')](this));ami['on'](_0xcba3('0x2e'),this[_0xcba3('0x1f')][_0xcba3('0x20')](this));}Trigger[_0xcba3('0x2f')][_0xcba3('0x30')]=function(_0x135198,_0x26ffd3,_0x4e8492){logger[_0xcba3('0x31')](_0x135198,_0x26ffd3,JSON[_0xcba3('0x32')](_0x4e8492));io['to'](_0x135198)[_0xcba3('0x30')](_0x26ffd3,_0x4e8492);};Trigger['prototype'][_0xcba3('0x1f')]=function(_0x3f0dde){var _0x376d31=_[_0xcba3('0x33')](_0x3f0dde);if(typeof _0x376d31[_0xcba3('0x34')]===_0xcba3('0x35')){_0x376d31[_0xcba3('0x34')]=_0xcba3('0x36');}logger[_0xcba3('0x37')](_0xcba3('0x1f'),util[_0xcba3('0x38')](_0x376d31,{'showHidden':!![],'depth':null}));this[_0xcba3('0x39')](_0x376d31);};Trigger[_0xcba3('0x2f')][_0xcba3('0x29')]=function(_0x5cb2b4){if(this[_0xcba3('0xf')][_0x5cb2b4[_0xcba3('0x3a')]]){this[_0xcba3('0x1f')](_0x5cb2b4);}};Trigger[_0xcba3('0x2f')]['checkTriggers']=function(_0x250544){var _0xfae4ae;for(var _0x5b0c6d in this[_0xcba3('0xe')]){if(this[_0xcba3('0xe')][_0xcba3('0x3b')](_0x5b0c6d)){if(this['triggers'][_0x5b0c6d]['status']){_0xfae4ae=this[_0xcba3('0x3c')](this['triggers'][_0x5b0c6d],_0x250544);if(_0xfae4ae){_[_0xcba3('0x3d')](_0x250544,_0x250544[_0xcba3('0x3e')]);for(var _0x40a542=0x0,_0x5e132b,_0x2e48ee,_0xd6fab7;_0x40a542<this[_0xcba3('0xe')][_0x5b0c6d][_0xcba3('0x3f')][_0xcba3('0x40')];_0x40a542+=0x1){_0x5e132b=this[_0xcba3('0xe')][_0x5b0c6d][_0xcba3('0x3f')][_0x40a542];if(this[_0xcba3('0xf')][_0x250544[_0xcba3('0x3a')]]){switch(_0x5e132b[_0xcba3('0x41')][_0xcba3('0x42')]()){case _0xcba3('0x43'):break;case'motionbar':case _0xcba3('0x44'):var _0x168404={};switch(barAndWebActions[_0x5e132b[_0xcba3('0x45')]]){case _0xcba3('0xd'):_0x168404[_0xcba3('0x46')]=_0x5e132b[_0xcba3('0x47')];_0x168404[_0xcba3('0x48')]=this['templates'][_0x5e132b['data2']]?Mustache[_0xcba3('0x49')](this['templates'][_0x5e132b[_0xcba3('0x47')]]['html'],_0x250544):_0xcba3('0x4a');break;case'url':_0x168404[_0xcba3('0x4b')]=this['buildUri'](_0x5e132b['data2'],_0x250544,_[_0xcba3('0x4c')](_0x5e132b[_0xcba3('0x4d')])?!![]:parseInt(_0x5e132b[_0xcba3('0x4d')],0xa));if(_['isNil'](_0x5e132b[_0xcba3('0x4e')])){_0x168404['location']='0';}else{_0x168404[_0xcba3('0x4f')]=_0x5e132b[_0xcba3('0x4e')];_0x168404[_0xcba3('0x50')]=_['isNil'](_0x5e132b['data5'])?_0xcba3('0x51'):_0x5e132b[_0xcba3('0x52')];_0x168404[_0xcba3('0x53')]=_['isNil'](_0x5e132b[_0xcba3('0x54')])?_0xcba3('0x55'):_0x5e132b[_0xcba3('0x54')];}break;case _0xcba3('0x56'):_0x168404[_0xcba3('0x57')]=_0x5e132b[_0xcba3('0x47')]?Mustache[_0xcba3('0x49')](_0x5e132b[_0xcba3('0x47')],_0x250544):'';_0x168404[_0xcba3('0x58')]=_0x5e132b['data3']?Mustache['render'](_0x5e132b[_0xcba3('0x4d')],_0x250544):'';break;}this[_0xcba3('0x30')](util['format'](_0xcba3('0x59'),this[_0xcba3('0xf')][_0x250544[_0xcba3('0x3a')]][_0xcba3('0x5a')]),util[_0xcba3('0x5b')](_0xcba3('0x5c'),_0x5e132b[_0xcba3('0x41')]['toLowerCase'](),barAndWebActions[_0x5e132b[_0xcba3('0x45')]]),_[_0xcba3('0x3d')](_0x168404,_0x250544));break;case _0xcba3('0x5d'):this[_0xcba3('0x30')](util[_0xcba3('0x5b')](_0xcba3('0x59'),this['agents'][_0x250544['interface']][_0xcba3('0x5a')]),util[_0xcba3('0x5b')](_0xcba3('0x5e'),_0x5e132b['action']['toLowerCase']()),_[_0xcba3('0x3d')]({'ProjectId':parseInt(_0x5e132b[_0xcba3('0x45')],0xa)},_0x250544));break;default:this[_0xcba3('0x30')](util[_0xcba3('0x5b')]('user:%s',this[_0xcba3('0xf')][_0x250544[_0xcba3('0x3a')]]['name']),util['format'](_0xcba3('0x5e'),_0x5e132b[_0xcba3('0x41')][_0xcba3('0x42')]()),_[_0xcba3('0x3d')]({},_0x5e132b,_0x250544));}}switch(_0x5e132b[_0xcba3('0x41')][_0xcba3('0x42')]()){case _0xcba3('0x43'):cmContact[_0xcba3('0x5f')](this[_0xcba3('0xf')][_0x250544[_0xcba3('0x3a')]],this['triggers'][_0x5b0c6d],_0x5e132b,_0x250544);break;case'integration':integration[_0xcba3('0x5f')](_0x5e132b,_0x250544,this['accounts'],this[_0xcba3('0xf')][_0x250544[_0xcba3('0x3a')]],this['voiceQueues'][_0x250544['queue']],this[_0xcba3('0x12')][_0x250544['routeId']]);break;case'urlforward':urlforward[_0xcba3('0x5f')](_0x5e132b,_0x250544);break;case _0xcba3('0x60'):script[_0xcba3('0x5f')](_0x5e132b,_0x250544);break;}}}}}}};Trigger[_0xcba3('0x2f')][_0xcba3('0x61')]=function(_0x104fa9,_0x421314,_0x2512ad){var _0xbe8904=url[_0xcba3('0x62')](Mustache[_0xcba3('0x49')](_0x104fa9,_0x421314),!![]);if(_0x2512ad){_['merge'](_0xbe8904[_0xcba3('0x63')],_0x421314);}delete _0xbe8904[_0xcba3('0x64')];var _0x13fae0=url['format'](_0xbe8904);_0x13fae0=_0x13fae0[_0xcba3('0x65')](/\/\?/g,'?');return _0x13fae0;};Trigger[_0xcba3('0x2f')]['checkTrigger']=function(_0x1db5fb,_0x5f2dbe){var _0x2969ea=!![];var _0x715f2e=!![];var _0x315ac4=![];if(_0x1db5fb[_0xcba3('0x66')]===_0x5f2dbe[_0xcba3('0x34')]){_0x315ac4=!![];}if(_0x1db5fb[_0xcba3('0x67')][_0xcba3('0x40')]){_0x2969ea=_[_0xcba3('0x68')](_0x1db5fb[_0xcba3('0x67')],this[_0xcba3('0x69')](_0x5f2dbe,_0x1db5fb[_0xcba3('0x66')]));}if(_0x1db5fb[_0xcba3('0x6a')]['length']){_0x715f2e=_[_0xcba3('0x6b')](_0x1db5fb['AnyConditions'],this[_0xcba3('0x69')](_0x5f2dbe,_0x1db5fb[_0xcba3('0x66')]));}var _0x28f8cb=_0x315ac4&&_0x2969ea&&_0x715f2e;logger[_0xcba3('0x37')](_0xcba3('0x6c'),util[_0xcba3('0x38')](_0x1db5fb,{'showHidden':!![],'depth':null}),'evt',util[_0xcba3('0x38')](_0x5f2dbe,{'showHidden':!![],'depth':null}),_0x315ac4,_0x2969ea,_0x715f2e);return _0x28f8cb;};Trigger['prototype'][_0xcba3('0x69')]=function(_0x3a1590,_0x5b9b5d){return function(_0x7fbaca){switch(_0x7fbaca[_0xcba3('0x6d')]){case'account':if(_0x3a1590[_0xcba3('0x66')]===_0x5b9b5d){if(_0x5b9b5d===_0xcba3('0x6e')){return _0x3a1590['ChatWebsiteId']?operators[_0x7fbaca[_0xcba3('0x6f')]](Number(_0x7fbaca[_0xcba3('0x70')]),_0x3a1590[_0xcba3('0x71')]):![];}else{return _0x3a1590[_['upperFirst'](_0x5b9b5d)+_0xcba3('0x72')]?operators[_0x7fbaca[_0xcba3('0x6f')]](Number(_0x7fbaca[_0xcba3('0x70')]),_0x3a1590[_[_0xcba3('0x73')](_0x5b9b5d)+_0xcba3('0x72')]):![];}}break;case'interaction':case _0xcba3('0x74'):if(_0x3a1590[_0xcba3('0x66')]===_0x5b9b5d){return _0x3a1590[_0xcba3('0x75')]?operators[_0x7fbaca[_0xcba3('0x6f')]](_0x7fbaca[_0xcba3('0x70')],_0x3a1590[_0xcba3('0x75')]):![];}break;case'queue':return _0x3a1590[_0xcba3('0x76')]?operators[_0x7fbaca['operator']](_0x7fbaca[_0xcba3('0x70')],_0x3a1590[_0xcba3('0x76')]):![];case _0xcba3('0x77'):return _0x3a1590[_0xcba3('0x78')]?operators[_0x7fbaca['operator']](_0x7fbaca[_0xcba3('0x70')],_0x3a1590[_0xcba3('0x78')]):![];case _0xcba3('0x79'):return _0x3a1590[_0xcba3('0x79')]?operators[_0x7fbaca[_0xcba3('0x6f')]](_0x7fbaca[_0xcba3('0x70')],_0x3a1590[_0xcba3('0x79')]):![];case _0xcba3('0x7a'):return _0x3a1590[_0xcba3('0x7a')]?operators[_0x7fbaca[_0xcba3('0x6f')]](_0x7fbaca[_0xcba3('0x70')],_0x3a1590[_0xcba3('0x7a')]):![];case'mailSubstatus':if(_0x7fbaca[_0xcba3('0x70')]===_0xcba3('0x7b'))_0x7fbaca[_0xcba3('0x70')]=null;return typeof _0x3a1590[_0xcba3('0x7c')]!==_0xcba3('0x35')?operators[_0x7fbaca[_0xcba3('0x6f')]](_0x7fbaca[_0xcba3('0x70')],_0x3a1590[_0xcba3('0x7c')]):![];case _0xcba3('0x7d'):if(_0x3a1590[_0xcba3('0x66')]===_0x5b9b5d){return _0x7fbaca['value']===_0xcba3('0x7e')&&_0x7fbaca[_0xcba3('0x6f')]===_0xcba3('0x7f')?!![]:![];}break;}return![];};};module[_0xcba3('0x80')]=Trigger;