Built motion from commit (unavailable).|2.5.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 _0x7c05=['custom:agentreject','custom:amd','custom:queuecallerabandon','custom:timeout','syncAgentDial','custom:dialconnect','custom:dialend','custom:newinteraction','custom:closedinteraction','custom:incomingmessage','custom:acceptmessage','custom:rejectmessage','prototype','emit','info','stringify','clone','checkTriggers','interface','hasOwnProperty','status','checkTrigger','variables','Actions','length','action','motionbar','browser','data1','TemplateId','data2','html','render','template\x20not\x20found','uri','buildUri','isNil','data3','data4','windowWidth','800','data5','windowHeight','data6','winApplication','winArguments','user:%s','name','format','trigger:%s:%s','toLowerCase','merge','jscripty','contactmanager','exec','integration','queue','routeId','parse','query','search','AllConditions','checkConditions','channel','AnyConditions','field','account','chat','ChatWebsiteId','operator','value','upperFirst','AccountId','interaction','message','event','agent','membername','lastevent','exports','lodash','mustache','ioredis','./integration','./cmContact','./script','../../../config/logger','../ami','redis','defaults','localhost','socket.io-emitter','winapp','triggers','agents','voiceQueues','templates','voiceExtensions','zendeskAccounts','freshdeskAccounts','salesforceAccounts','sugarcrmAccounts','vtigerAccounts','servicenowAccounts','dynamics365Accounts','freshsalesAccounts','accounts','zohoAccounts','syncCustomEvent','bind','custom:agentconnect','custom:agentringnoanswer','custom:agentnosuchnumber','custom:agentnoanswer','custom:agentbusy','custom:agentcongestion'];(function(_0x502c7d,_0x2f1285){var _0x30b7ed=function(_0x2d92f3){while(--_0x2d92f3){_0x502c7d['push'](_0x502c7d['shift']());}};_0x30b7ed(++_0x2f1285);}(_0x7c05,0x1ac));var _0x57c0=function(_0x2c5340,_0x5c86e5){_0x2c5340=_0x2c5340-0x0;var _0x3c505e=_0x7c05[_0x2c5340];return _0x3c505e;};'use strict';var util=require('util');var _=require(_0x57c0('0x0'));var url=require('url');var Mustache=require(_0x57c0('0x1'));var Redis=require(_0x57c0('0x2'));var urlforward=require('./urlforward');var integration=require(_0x57c0('0x3'));var cmContact=require(_0x57c0('0x4'));var script=require(_0x57c0('0x5'));var config=require('../../../config/environment');var logger=require(_0x57c0('0x6'))('trigger');var ami=require(_0x57c0('0x7'));config[_0x57c0('0x8')]=_[_0x57c0('0x9')](config[_0x57c0('0x8')],{'host':_0x57c0('0xa'),'port':0x18eb});var io=require(_0x57c0('0xb'))(new Redis(config[_0x57c0('0x8')]));var operators={'equals':function(_0x7d9a57,_0x5dcfc2){return _0x7d9a57==_0x5dcfc2;},'not_equals':function(_0x55591e,_0x5ea629){return _0x55591e!=_0x5ea629;}};var barAndWebActions=['popup','url',_0x57c0('0xc')];function Trigger(_0x775350){this['triggers']=_0x775350[_0x57c0('0xd')];this['agents']=_0x775350[_0x57c0('0xe')];this[_0x57c0('0xf')]=_0x775350[_0x57c0('0xf')];this[_0x57c0('0x10')]=_0x775350[_0x57c0('0x10')];this[_0x57c0('0x11')]=_0x775350[_0x57c0('0x11')];this[_0x57c0('0x12')]=_0x775350[_0x57c0('0x12')];this[_0x57c0('0x13')]=_0x775350[_0x57c0('0x13')];this[_0x57c0('0x14')]=_0x775350[_0x57c0('0x14')];this[_0x57c0('0x15')]=_0x775350['sugarcrmAccounts'];this['zohoAccounts']=_0x775350['zohoAccounts'];this['deskAccounts']=_0x775350['deskAccounts'];this[_0x57c0('0x16')]=_0x775350[_0x57c0('0x16')];this[_0x57c0('0x17')]=_0x775350[_0x57c0('0x17')];this[_0x57c0('0x18')]=_0x775350['dynamics365Accounts'];this[_0x57c0('0x19')]=_0x775350[_0x57c0('0x19')];this[_0x57c0('0x1a')]={'zendesk':this[_0x57c0('0x12')],'salesforce':this['salesforceAccounts'],'freshdesk':this[_0x57c0('0x13')],'sugarcrm':this[_0x57c0('0x15')],'zoho':this[_0x57c0('0x1b')],'desk':this['deskAccounts'],'vtiger':this[_0x57c0('0x16')],'dynamics365':this['dynamics365Accounts'],'freshsales':this[_0x57c0('0x19')],'servicenow':this[_0x57c0('0x17')]};ami['on']('custom:agentcalled',this[_0x57c0('0x1c')][_0x57c0('0x1d')](this));ami['on'](_0x57c0('0x1e'),this[_0x57c0('0x1c')]['bind'](this));ami['on'](_0x57c0('0x1f'),this[_0x57c0('0x1c')]['bind'](this));ami['on']('custom:agentcomplete',this[_0x57c0('0x1c')][_0x57c0('0x1d')](this));ami['on'](_0x57c0('0x20'),this[_0x57c0('0x1c')][_0x57c0('0x1d')](this));ami['on'](_0x57c0('0x21'),this['syncCustomEvent']['bind'](this));ami['on'](_0x57c0('0x22'),this['syncCustomEvent'][_0x57c0('0x1d')](this));ami['on'](_0x57c0('0x23'),this[_0x57c0('0x1c')][_0x57c0('0x1d')](this));ami['on'](_0x57c0('0x24'),this[_0x57c0('0x1c')]['bind'](this));ami['on'](_0x57c0('0x25'),this[_0x57c0('0x1c')][_0x57c0('0x1d')](this));ami['on'](_0x57c0('0x26'),this[_0x57c0('0x1c')]['bind'](this));ami['on'](_0x57c0('0x27'),this[_0x57c0('0x1c')]['bind'](this));ami['on']('custom:dialbegin',this[_0x57c0('0x28')][_0x57c0('0x1d')](this));ami['on'](_0x57c0('0x29'),this[_0x57c0('0x28')][_0x57c0('0x1d')](this));ami['on'](_0x57c0('0x2a'),this[_0x57c0('0x28')]['bind'](this));ami['on'](_0x57c0('0x2b'),this['syncCustomEvent'][_0x57c0('0x1d')](this));ami['on'](_0x57c0('0x2c'),this[_0x57c0('0x1c')][_0x57c0('0x1d')](this));ami['on'](_0x57c0('0x2d'),this[_0x57c0('0x1c')][_0x57c0('0x1d')](this));ami['on']('custom:outgoingmessage',this[_0x57c0('0x1c')][_0x57c0('0x1d')](this));ami['on'](_0x57c0('0x2e'),this['syncCustomEvent'][_0x57c0('0x1d')](this));ami['on'](_0x57c0('0x2f'),this[_0x57c0('0x1c')]['bind'](this));}Trigger[_0x57c0('0x30')][_0x57c0('0x31')]=function(_0x36257b,_0x5c8b02,_0x39c2cf){logger[_0x57c0('0x32')](_0x36257b,_0x5c8b02,JSON[_0x57c0('0x33')](_0x39c2cf));io['to'](_0x36257b)[_0x57c0('0x31')](_0x5c8b02,_0x39c2cf);};Trigger['prototype']['syncCustomEvent']=function(_0x168d17){var _0x196fd4=_[_0x57c0('0x34')](_0x168d17);this[_0x57c0('0x35')](_0x196fd4);};Trigger[_0x57c0('0x30')][_0x57c0('0x28')]=function(_0x52b4e2){if(this[_0x57c0('0xe')][_0x52b4e2[_0x57c0('0x36')]]){this[_0x57c0('0x1c')](_0x52b4e2);}};Trigger[_0x57c0('0x30')][_0x57c0('0x35')]=function(_0x2317f5){var _0x48b6a5;for(var _0x3457c5 in this[_0x57c0('0xd')]){if(this[_0x57c0('0xd')][_0x57c0('0x37')](_0x3457c5)){if(this[_0x57c0('0xd')][_0x3457c5][_0x57c0('0x38')]){_0x48b6a5=this[_0x57c0('0x39')](this[_0x57c0('0xd')][_0x3457c5],_0x2317f5);if(_0x48b6a5){_['merge'](_0x2317f5,_0x2317f5[_0x57c0('0x3a')]);for(var _0x1e2025=0x0,_0x181cd5,_0x3e0566,_0x4c3bef;_0x1e2025<this[_0x57c0('0xd')][_0x3457c5][_0x57c0('0x3b')][_0x57c0('0x3c')];_0x1e2025+=0x1){_0x181cd5=this[_0x57c0('0xd')][_0x3457c5]['Actions'][_0x1e2025];if(this['agents'][_0x2317f5['interface']]){switch(_0x181cd5[_0x57c0('0x3d')]['toLowerCase']()){case'contactmanager':break;case _0x57c0('0x3e'):case _0x57c0('0x3f'):var _0x5402d2={};switch(barAndWebActions[_0x181cd5[_0x57c0('0x40')]]){case'popup':_0x5402d2[_0x57c0('0x41')]=_0x181cd5[_0x57c0('0x42')];_0x5402d2[_0x57c0('0x43')]=this[_0x57c0('0x10')][_0x181cd5[_0x57c0('0x42')]]?Mustache[_0x57c0('0x44')](this['templates'][_0x181cd5['data2']][_0x57c0('0x43')],_0x2317f5):_0x57c0('0x45');break;case'url':_0x5402d2[_0x57c0('0x46')]=this[_0x57c0('0x47')](_0x181cd5[_0x57c0('0x42')],_0x2317f5,_[_0x57c0('0x48')](_0x181cd5['data3'])?!![]:parseInt(_0x181cd5[_0x57c0('0x49')],0xa));if(_[_0x57c0('0x48')](_0x181cd5[_0x57c0('0x4a')])){_0x5402d2['location']='0';}else{_0x5402d2['uriLocation']=_0x181cd5['data4'];_0x5402d2[_0x57c0('0x4b')]=_['isNil'](_0x181cd5['data5'])?_0x57c0('0x4c'):_0x181cd5[_0x57c0('0x4d')];_0x5402d2[_0x57c0('0x4e')]=_['isNil'](_0x181cd5[_0x57c0('0x4f')])?'600':_0x181cd5[_0x57c0('0x4f')];}break;case'winapp':_0x5402d2[_0x57c0('0x50')]=_0x181cd5['data2']?Mustache[_0x57c0('0x44')](_0x181cd5[_0x57c0('0x42')],_0x2317f5):'';_0x5402d2[_0x57c0('0x51')]=_0x181cd5[_0x57c0('0x49')]?Mustache[_0x57c0('0x44')](_0x181cd5['data3'],_0x2317f5):'';break;}this[_0x57c0('0x31')](util['format'](_0x57c0('0x52'),this[_0x57c0('0xe')][_0x2317f5[_0x57c0('0x36')]][_0x57c0('0x53')]),util[_0x57c0('0x54')](_0x57c0('0x55'),_0x181cd5[_0x57c0('0x3d')][_0x57c0('0x56')](),barAndWebActions[_0x181cd5[_0x57c0('0x40')]]),_[_0x57c0('0x57')](_0x5402d2,_0x2317f5));break;case _0x57c0('0x58'):this[_0x57c0('0x31')](util['format'](_0x57c0('0x52'),this[_0x57c0('0xe')][_0x2317f5[_0x57c0('0x36')]][_0x57c0('0x53')]),util['format']('trigger:%s',_0x181cd5[_0x57c0('0x3d')][_0x57c0('0x56')]()),_[_0x57c0('0x57')]({'ProjectId':parseInt(_0x181cd5[_0x57c0('0x40')],0xa)},_0x2317f5));break;default:this[_0x57c0('0x31')](util['format'](_0x57c0('0x52'),this['agents'][_0x2317f5['interface']]['name']),util[_0x57c0('0x54')]('trigger:%s',_0x181cd5[_0x57c0('0x3d')][_0x57c0('0x56')]()),_[_0x57c0('0x57')]({},_0x181cd5,_0x2317f5));}}switch(_0x181cd5[_0x57c0('0x3d')][_0x57c0('0x56')]()){case _0x57c0('0x59'):cmContact[_0x57c0('0x5a')](this[_0x57c0('0xe')][_0x2317f5[_0x57c0('0x36')]],this[_0x57c0('0xd')][_0x3457c5],_0x181cd5,_0x2317f5);break;case _0x57c0('0x5b'):integration[_0x57c0('0x5a')](_0x181cd5,_0x2317f5,this[_0x57c0('0x1a')],this[_0x57c0('0xe')][_0x2317f5[_0x57c0('0x36')]],this[_0x57c0('0xf')][_0x2317f5[_0x57c0('0x5c')]],this['voiceExtensions'][_0x2317f5[_0x57c0('0x5d')]]);break;case'urlforward':urlforward[_0x57c0('0x5a')](_0x181cd5,_0x2317f5);break;case'script':script['exec'](_0x181cd5,_0x2317f5);break;}}}}}}};Trigger[_0x57c0('0x30')][_0x57c0('0x47')]=function(_0x4bdf26,_0x3e3079,_0x68d189){var _0x33e3d7=url[_0x57c0('0x5e')](Mustache['render'](_0x4bdf26,_0x3e3079),!![]);if(_0x68d189){_[_0x57c0('0x57')](_0x33e3d7[_0x57c0('0x5f')],_0x3e3079);}delete _0x33e3d7[_0x57c0('0x60')];var _0x16203b=url[_0x57c0('0x54')](_0x33e3d7);_0x16203b=_0x16203b['replace'](/\/\?/g,'?');return _0x16203b;};Trigger[_0x57c0('0x30')][_0x57c0('0x39')]=function(_0x79040d,_0x317ed9){var _0x5082f6=!![],_0x16a04e=!![];if(_0x79040d[_0x57c0('0x61')][_0x57c0('0x3c')]){_0x5082f6=_['every'](_0x79040d[_0x57c0('0x61')],this[_0x57c0('0x62')](_0x317ed9,_0x79040d[_0x57c0('0x63')]));}if(_0x79040d[_0x57c0('0x64')]['length']){_0x16a04e=_['some'](_0x79040d[_0x57c0('0x64')],this[_0x57c0('0x62')](_0x317ed9,_0x79040d[_0x57c0('0x63')]));}return _0x5082f6&&_0x16a04e;};Trigger[_0x57c0('0x30')][_0x57c0('0x62')]=function(_0x4a0557,_0x2fe340){return function(_0x487ddc){switch(_0x487ddc[_0x57c0('0x65')]){case _0x57c0('0x66'):if(_0x4a0557[_0x57c0('0x63')]===_0x2fe340){if(_0x2fe340===_0x57c0('0x67')){return _0x4a0557[_0x57c0('0x68')]?operators[_0x487ddc[_0x57c0('0x69')]](Number(_0x487ddc[_0x57c0('0x6a')]),_0x4a0557[_0x57c0('0x68')]):![];}else{return _0x4a0557[_[_0x57c0('0x6b')](_0x2fe340)+_0x57c0('0x6c')]?operators[_0x487ddc['operator']](Number(_0x487ddc['value']),_0x4a0557[_[_0x57c0('0x6b')](_0x2fe340)+_0x57c0('0x6c')]):![];}}break;case _0x57c0('0x6d'):case _0x57c0('0x6e'):if(_0x4a0557[_0x57c0('0x63')]===_0x2fe340){return _0x4a0557['event']?operators[_0x487ddc[_0x57c0('0x69')]](_0x487ddc[_0x57c0('0x6a')],_0x4a0557[_0x57c0('0x6f')]):![];}break;case _0x57c0('0x5c'):return _0x4a0557['queue']?operators[_0x487ddc[_0x57c0('0x69')]](_0x487ddc[_0x57c0('0x6a')],_0x4a0557[_0x57c0('0x5c')]):![];case _0x57c0('0x70'):return _0x4a0557[_0x57c0('0x71')]?operators[_0x487ddc[_0x57c0('0x69')]](_0x487ddc[_0x57c0('0x6a')],_0x4a0557[_0x57c0('0x71')]):![];case'lastevent':return _0x4a0557[_0x57c0('0x72')]?operators[_0x487ddc[_0x57c0('0x69')]](_0x487ddc['value'],_0x4a0557['lastevent']):![];case _0x57c0('0x5d'):return _0x4a0557[_0x57c0('0x5d')]?operators[_0x487ddc[_0x57c0('0x69')]](_0x487ddc[_0x57c0('0x6a')],_0x4a0557[_0x57c0('0x5d')]):![];}return![];};};module[_0x57c0('0x73')]=Trigger;