6a88914ddd313fb9d2f7444133e035b56b996e1f
[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 _0xd73f=['exec','accounts','queue','routeId','urlforward','script','parse','query','search','checkTrigger','channel','AllConditions','length','every','checkConditions','AnyConditions','ChatWebsiteId','value','upperFirst','AccountId','operator','interaction','message','event','agent','membername','lastevent','exports','lodash','url','mustache','./urlforward','./cmContact','./script','../../../config/environment','../../../config/logger','trigger','../ami','defaults','localhost','socket.io-emitter','redis','popup','triggers','agents','voiceQueues','templates','voiceExtensions','zendeskAccounts','freshdeskAccounts','salesforceAccounts','sugarcrmAccounts','zohoAccounts','deskAccounts','vtigerAccounts','servicenowAccounts','dynamics365Accounts','freshsalesAccounts','custom:agentcalled','syncCustomEvent','bind','custom:agentringnoanswer','custom:agentcomplete','custom:agentnosuchnumber','custom:agentnoanswer','custom:agentcongestion','custom:agentreject','custom:queuecallerabandon','custom:dialbegin','syncAgentDial','custom:dialend','custom:substatus','custom:incomingmessage','custom:outgoingmessage','custom:acceptmessage','custom:rejectmessage','prototype','emit','info','stringify','clone','motionChannel','voice','checkTriggers','interface','hasOwnProperty','merge','variables','Actions','action','contactmanager','motionbar','browser','data1','TemplateId','data2','html','template\x20not\x20found','uri','buildUri','isNil','data4','location','uriLocation','data5','windowHeight','data6','600','winApplication','winArguments','render','format','user:%s','name','toLowerCase','jscripty'];(function(_0x11005e,_0x20c3d2){var _0x29338f=function(_0x3384e9){while(--_0x3384e9){_0x11005e['push'](_0x11005e['shift']());}};_0x29338f(++_0x20c3d2);}(_0xd73f,0x90));var _0xfd73=function(_0x1b3e32,_0x49ad74){_0x1b3e32=_0x1b3e32-0x0;var _0x4796e3=_0xd73f[_0x1b3e32];return _0x4796e3;};'use strict';var util=require('util');var _=require(_0xfd73('0x0'));var url=require(_0xfd73('0x1'));var Mustache=require(_0xfd73('0x2'));var Redis=require('ioredis');var urlforward=require(_0xfd73('0x3'));var integration=require('./integration');var cmContact=require(_0xfd73('0x4'));var script=require(_0xfd73('0x5'));var config=require(_0xfd73('0x6'));var logger=require(_0xfd73('0x7'))(_0xfd73('0x8'));var ami=require(_0xfd73('0x9'));config['redis']=_[_0xfd73('0xa')](config['redis'],{'host':_0xfd73('0xb'),'port':0x18eb});var io=require(_0xfd73('0xc'))(new Redis(config[_0xfd73('0xd')]));var operators={'equals':function(_0x3dc28b,_0x3fd9dc){return _0x3dc28b==_0x3fd9dc;},'not_equals':function(_0x5162a5,_0x1f0dc2){return _0x5162a5!=_0x1f0dc2;}};var barAndWebActions=[_0xfd73('0xe'),_0xfd73('0x1'),'winapp'];function Trigger(_0x39a587){this['triggers']=_0x39a587[_0xfd73('0xf')];this[_0xfd73('0x10')]=_0x39a587[_0xfd73('0x10')];this[_0xfd73('0x11')]=_0x39a587[_0xfd73('0x11')];this['templates']=_0x39a587[_0xfd73('0x12')];this['voiceExtensions']=_0x39a587[_0xfd73('0x13')];this[_0xfd73('0x14')]=_0x39a587[_0xfd73('0x14')];this[_0xfd73('0x15')]=_0x39a587[_0xfd73('0x15')];this[_0xfd73('0x16')]=_0x39a587[_0xfd73('0x16')];this[_0xfd73('0x17')]=_0x39a587['sugarcrmAccounts'];this[_0xfd73('0x18')]=_0x39a587[_0xfd73('0x18')];this[_0xfd73('0x19')]=_0x39a587[_0xfd73('0x19')];this['vtigerAccounts']=_0x39a587[_0xfd73('0x1a')];this['servicenowAccounts']=_0x39a587[_0xfd73('0x1b')];this['dynamics365Accounts']=_0x39a587[_0xfd73('0x1c')];this[_0xfd73('0x1d')]=_0x39a587[_0xfd73('0x1d')];this['accounts']={'zendesk':this[_0xfd73('0x14')],'salesforce':this['salesforceAccounts'],'freshdesk':this['freshdeskAccounts'],'sugarcrm':this[_0xfd73('0x17')],'zoho':this[_0xfd73('0x18')],'desk':this[_0xfd73('0x19')],'vtiger':this[_0xfd73('0x1a')],'dynamics365':this['dynamics365Accounts'],'freshsales':this[_0xfd73('0x1d')],'servicenow':this[_0xfd73('0x1b')]};ami['on'](_0xfd73('0x1e'),this[_0xfd73('0x1f')][_0xfd73('0x20')](this));ami['on']('custom:agentconnect',this[_0xfd73('0x1f')][_0xfd73('0x20')](this));ami['on'](_0xfd73('0x21'),this[_0xfd73('0x1f')][_0xfd73('0x20')](this));ami['on'](_0xfd73('0x22'),this[_0xfd73('0x1f')][_0xfd73('0x20')](this));ami['on'](_0xfd73('0x23'),this[_0xfd73('0x1f')]['bind'](this));ami['on'](_0xfd73('0x24'),this[_0xfd73('0x1f')][_0xfd73('0x20')](this));ami['on']('custom:agentbusy',this[_0xfd73('0x1f')][_0xfd73('0x20')](this));ami['on'](_0xfd73('0x25'),this[_0xfd73('0x1f')][_0xfd73('0x20')](this));ami['on'](_0xfd73('0x26'),this[_0xfd73('0x1f')][_0xfd73('0x20')](this));ami['on']('custom:amd',this[_0xfd73('0x1f')]['bind'](this));ami['on'](_0xfd73('0x27'),this[_0xfd73('0x1f')][_0xfd73('0x20')](this));ami['on']('custom:timeout',this[_0xfd73('0x1f')][_0xfd73('0x20')](this));ami['on'](_0xfd73('0x28'),this['syncAgentDial'][_0xfd73('0x20')](this));ami['on']('custom:dialconnect',this[_0xfd73('0x29')][_0xfd73('0x20')](this));ami['on'](_0xfd73('0x2a'),this[_0xfd73('0x29')]['bind'](this));ami['on']('custom:newinteraction',this['syncCustomEvent'][_0xfd73('0x20')](this));ami['on']('custom:closedinteraction',this[_0xfd73('0x1f')][_0xfd73('0x20')](this));ami['on'](_0xfd73('0x2b'),this[_0xfd73('0x1f')][_0xfd73('0x20')](this));ami['on'](_0xfd73('0x2c'),this['syncCustomEvent']['bind'](this));ami['on'](_0xfd73('0x2d'),this[_0xfd73('0x1f')][_0xfd73('0x20')](this));ami['on'](_0xfd73('0x2e'),this[_0xfd73('0x1f')][_0xfd73('0x20')](this));ami['on'](_0xfd73('0x2f'),this['syncCustomEvent']['bind'](this));}Trigger[_0xfd73('0x30')][_0xfd73('0x31')]=function(_0x3f1cba,_0x7dd4a9,_0x3e32fe){logger[_0xfd73('0x32')](_0x3f1cba,_0x7dd4a9,JSON[_0xfd73('0x33')](_0x3e32fe));io['to'](_0x3f1cba)['emit'](_0x7dd4a9,_0x3e32fe);};Trigger[_0xfd73('0x30')][_0xfd73('0x1f')]=function(_0x320823){var _0x202f06=_[_0xfd73('0x34')](_0x320823);if(typeof _0x202f06[_0xfd73('0x35')]==='undefined'){_0x202f06[_0xfd73('0x35')]=_0xfd73('0x36');}this[_0xfd73('0x37')](_0x202f06);};Trigger[_0xfd73('0x30')][_0xfd73('0x29')]=function(_0x3081d6){if(this[_0xfd73('0x10')][_0x3081d6[_0xfd73('0x38')]]){this[_0xfd73('0x1f')](_0x3081d6);}};Trigger[_0xfd73('0x30')][_0xfd73('0x37')]=function(_0x447c2d){var _0x53a9fe;for(var _0x4b13b0 in this[_0xfd73('0xf')]){if(this[_0xfd73('0xf')][_0xfd73('0x39')](_0x4b13b0)){if(this[_0xfd73('0xf')][_0x4b13b0]['status']){_0x53a9fe=this['checkTrigger'](this[_0xfd73('0xf')][_0x4b13b0],_0x447c2d);if(_0x53a9fe){_[_0xfd73('0x3a')](_0x447c2d,_0x447c2d[_0xfd73('0x3b')]);for(var _0x546981=0x0,_0x3d380c,_0x584d95,_0x3edb47;_0x546981<this[_0xfd73('0xf')][_0x4b13b0][_0xfd73('0x3c')]['length'];_0x546981+=0x1){_0x3d380c=this[_0xfd73('0xf')][_0x4b13b0][_0xfd73('0x3c')][_0x546981];if(this[_0xfd73('0x10')][_0x447c2d['interface']]){switch(_0x3d380c[_0xfd73('0x3d')]['toLowerCase']()){case _0xfd73('0x3e'):break;case _0xfd73('0x3f'):case _0xfd73('0x40'):var _0x28555b={};switch(barAndWebActions[_0x3d380c[_0xfd73('0x41')]]){case _0xfd73('0xe'):_0x28555b[_0xfd73('0x42')]=_0x3d380c[_0xfd73('0x43')];_0x28555b[_0xfd73('0x44')]=this[_0xfd73('0x12')][_0x3d380c[_0xfd73('0x43')]]?Mustache['render'](this['templates'][_0x3d380c['data2']][_0xfd73('0x44')],_0x447c2d):_0xfd73('0x45');break;case'url':_0x28555b[_0xfd73('0x46')]=this[_0xfd73('0x47')](_0x3d380c[_0xfd73('0x43')],_0x447c2d,_[_0xfd73('0x48')](_0x3d380c['data3'])?!![]:parseInt(_0x3d380c['data3'],0xa));if(_[_0xfd73('0x48')](_0x3d380c[_0xfd73('0x49')])){_0x28555b[_0xfd73('0x4a')]='0';}else{_0x28555b[_0xfd73('0x4b')]=_0x3d380c[_0xfd73('0x49')];_0x28555b['windowWidth']=_[_0xfd73('0x48')](_0x3d380c[_0xfd73('0x4c')])?'800':_0x3d380c[_0xfd73('0x4c')];_0x28555b[_0xfd73('0x4d')]=_[_0xfd73('0x48')](_0x3d380c[_0xfd73('0x4e')])?_0xfd73('0x4f'):_0x3d380c[_0xfd73('0x4e')];}break;case'winapp':_0x28555b[_0xfd73('0x50')]=_0x3d380c[_0xfd73('0x43')]?Mustache['render'](_0x3d380c[_0xfd73('0x43')],_0x447c2d):'';_0x28555b[_0xfd73('0x51')]=_0x3d380c['data3']?Mustache[_0xfd73('0x52')](_0x3d380c['data3'],_0x447c2d):'';break;}this[_0xfd73('0x31')](util[_0xfd73('0x53')](_0xfd73('0x54'),this['agents'][_0x447c2d[_0xfd73('0x38')]][_0xfd73('0x55')]),util[_0xfd73('0x53')]('trigger:%s:%s',_0x3d380c[_0xfd73('0x3d')][_0xfd73('0x56')](),barAndWebActions[_0x3d380c[_0xfd73('0x41')]]),_[_0xfd73('0x3a')](_0x28555b,_0x447c2d));break;case _0xfd73('0x57'):this['emit'](util['format'](_0xfd73('0x54'),this[_0xfd73('0x10')][_0x447c2d[_0xfd73('0x38')]][_0xfd73('0x55')]),util['format']('trigger:%s',_0x3d380c[_0xfd73('0x3d')][_0xfd73('0x56')]()),_[_0xfd73('0x3a')]({'ProjectId':parseInt(_0x3d380c[_0xfd73('0x41')],0xa)},_0x447c2d));break;default:this[_0xfd73('0x31')](util[_0xfd73('0x53')](_0xfd73('0x54'),this[_0xfd73('0x10')][_0x447c2d[_0xfd73('0x38')]][_0xfd73('0x55')]),util[_0xfd73('0x53')]('trigger:%s',_0x3d380c[_0xfd73('0x3d')][_0xfd73('0x56')]()),_[_0xfd73('0x3a')]({},_0x3d380c,_0x447c2d));}}switch(_0x3d380c[_0xfd73('0x3d')]['toLowerCase']()){case _0xfd73('0x3e'):cmContact[_0xfd73('0x58')](this[_0xfd73('0x10')][_0x447c2d[_0xfd73('0x38')]],this[_0xfd73('0xf')][_0x4b13b0],_0x3d380c,_0x447c2d);break;case'integration':integration['exec'](_0x3d380c,_0x447c2d,this[_0xfd73('0x59')],this[_0xfd73('0x10')][_0x447c2d['interface']],this[_0xfd73('0x11')][_0x447c2d[_0xfd73('0x5a')]],this[_0xfd73('0x13')][_0x447c2d[_0xfd73('0x5b')]]);break;case _0xfd73('0x5c'):urlforward[_0xfd73('0x58')](_0x3d380c,_0x447c2d);break;case _0xfd73('0x5d'):script['exec'](_0x3d380c,_0x447c2d);break;}}}}}}};Trigger[_0xfd73('0x30')][_0xfd73('0x47')]=function(_0x4ccd7b,_0x4bbe8e,_0x4d2267){var _0x3220e8=url[_0xfd73('0x5e')](Mustache[_0xfd73('0x52')](_0x4ccd7b,_0x4bbe8e),!![]);if(_0x4d2267){_[_0xfd73('0x3a')](_0x3220e8[_0xfd73('0x5f')],_0x4bbe8e);}delete _0x3220e8[_0xfd73('0x60')];var _0x2f006b=url['format'](_0x3220e8);_0x2f006b=_0x2f006b['replace'](/\/\?/g,'?');return _0x2f006b;};Trigger['prototype'][_0xfd73('0x61')]=function(_0x50b9e2,_0x1785d8){var _0x836c45=!![];var _0x471f8f=!![];var _0x2aab92=![];if(_0x50b9e2[_0xfd73('0x62')]===_0x1785d8['motionChannel']){_0x2aab92=!![];}if(_0x50b9e2[_0xfd73('0x63')][_0xfd73('0x64')]){_0x836c45=_[_0xfd73('0x65')](_0x50b9e2[_0xfd73('0x63')],this[_0xfd73('0x66')](_0x1785d8,_0x50b9e2['channel']));}if(_0x50b9e2['AnyConditions']['length']){_0x471f8f=_['some'](_0x50b9e2[_0xfd73('0x67')],this[_0xfd73('0x66')](_0x1785d8,_0x50b9e2[_0xfd73('0x62')]));}return _0x2aab92&&_0x836c45&&_0x471f8f;};Trigger['prototype'][_0xfd73('0x66')]=function(_0x24183c,_0x5f4d5c){return function(_0x2f2bc5){switch(_0x2f2bc5['field']){case'account':if(_0x24183c['channel']===_0x5f4d5c){if(_0x5f4d5c==='chat'){return _0x24183c[_0xfd73('0x68')]?operators[_0x2f2bc5['operator']](Number(_0x2f2bc5[_0xfd73('0x69')]),_0x24183c['ChatWebsiteId']):![];}else{return _0x24183c[_[_0xfd73('0x6a')](_0x5f4d5c)+_0xfd73('0x6b')]?operators[_0x2f2bc5[_0xfd73('0x6c')]](Number(_0x2f2bc5[_0xfd73('0x69')]),_0x24183c[_['upperFirst'](_0x5f4d5c)+_0xfd73('0x6b')]):![];}}break;case _0xfd73('0x6d'):case _0xfd73('0x6e'):if(_0x24183c[_0xfd73('0x62')]===_0x5f4d5c){return _0x24183c[_0xfd73('0x6f')]?operators[_0x2f2bc5[_0xfd73('0x6c')]](_0x2f2bc5[_0xfd73('0x69')],_0x24183c[_0xfd73('0x6f')]):![];}break;case _0xfd73('0x5a'):return _0x24183c[_0xfd73('0x5a')]?operators[_0x2f2bc5[_0xfd73('0x6c')]](_0x2f2bc5[_0xfd73('0x69')],_0x24183c[_0xfd73('0x5a')]):![];case _0xfd73('0x70'):return _0x24183c[_0xfd73('0x71')]?operators[_0x2f2bc5[_0xfd73('0x6c')]](_0x2f2bc5[_0xfd73('0x69')],_0x24183c[_0xfd73('0x71')]):![];case _0xfd73('0x72'):return _0x24183c[_0xfd73('0x72')]?operators[_0x2f2bc5[_0xfd73('0x6c')]](_0x2f2bc5[_0xfd73('0x69')],_0x24183c[_0xfd73('0x72')]):![];case _0xfd73('0x5b'):return _0x24183c[_0xfd73('0x5b')]?operators[_0x2f2bc5[_0xfd73('0x6c')]](_0x2f2bc5[_0xfd73('0x69')],_0x24183c[_0xfd73('0x5b')]):![];}return![];};};module[_0xfd73('0x73')]=Trigger;