Built motion from commit (unavailable).|2.5.28
[motion2.git] / server / config / triggers / 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 _0x9bf2=['direction','UserId','find','then','interface','format','SIP/%s','name','channel','outgoingmessage','opened','changed','closed','User','default','hasOwnProperty','model','callback','toLowerCase','../../mysqldb','../logger','triggers','client','http','ChatInteraction','newinteraction','Chat','afterUpdate','closedinteraction','ChatMessage','afterCreate','newmessage','SmsInteraction','Sms','SmsMessage','Whatsapp','WhatsappInteraction','WhatsappMessage','Fax','FaxInteraction','FaxMessage','Mail','MailMessage','Openchannel','OpenchannelInteraction','OpenchannelMessage','request','EventManager','info','Trigger,\x20%s','error','code','catch','get','event'];(function(_0x557702,_0xd93eea){var _0x3eb6e5=function(_0x3de4ca){while(--_0x3de4ca){_0x557702['push'](_0x557702['shift']());}};_0x3eb6e5(++_0xd93eea);}(_0x9bf2,0x15d));var _0x29bf=function(_0x1f0ac0,_0xef0e93){_0x1f0ac0=_0x1f0ac0-0x0;var _0x2f2761=_0x9bf2[_0x1f0ac0];return _0x2f2761;};'use strict';var util=require('util');var db=require(_0x29bf('0x0'))['db'];var jayson=require('jayson/promise');var logger=require(_0x29bf('0x1'))(_0x29bf('0x2'));var client=jayson[_0x29bf('0x3')][_0x29bf('0x4')]({'port':0x232a});var triggers=[{'channel':'Chat','model':_0x29bf('0x5'),'event':'afterCreate','condition':_0x29bf('0x6'),'callback':afterCreate},{'channel':_0x29bf('0x7'),'model':_0x29bf('0x5'),'event':_0x29bf('0x8'),'condition':_0x29bf('0x9'),'callback':afterUpdate},{'channel':_0x29bf('0x7'),'model':_0x29bf('0xa'),'event':_0x29bf('0xb'),'condition':_0x29bf('0xc'),'callback':afterCreateMessage},{'channel':'Sms','model':_0x29bf('0xd'),'event':_0x29bf('0xb'),'condition':_0x29bf('0x6'),'callback':afterCreate},{'channel':_0x29bf('0xe'),'model':'SmsInteraction','event':_0x29bf('0x8'),'condition':_0x29bf('0x9'),'callback':afterUpdate},{'channel':_0x29bf('0xe'),'model':_0x29bf('0xf'),'event':_0x29bf('0xb'),'condition':'newmessage','callback':afterCreateMessage},{'channel':_0x29bf('0x10'),'model':'WhatsappInteraction','event':_0x29bf('0xb'),'condition':_0x29bf('0x6'),'callback':afterCreate},{'channel':_0x29bf('0x10'),'model':_0x29bf('0x11'),'event':_0x29bf('0x8'),'condition':_0x29bf('0x9'),'callback':afterUpdate},{'channel':_0x29bf('0x10'),'model':_0x29bf('0x12'),'event':_0x29bf('0xb'),'condition':_0x29bf('0xc'),'callback':afterCreateMessage},{'channel':_0x29bf('0x13'),'model':_0x29bf('0x14'),'event':_0x29bf('0xb'),'condition':_0x29bf('0x6'),'callback':afterCreate},{'channel':_0x29bf('0x13'),'model':_0x29bf('0x14'),'event':_0x29bf('0x8'),'condition':_0x29bf('0x9'),'callback':afterUpdate},{'channel':_0x29bf('0x13'),'model':_0x29bf('0x15'),'event':_0x29bf('0xb'),'condition':'newmessage','callback':afterCreateMessage},{'channel':'Mail','model':'MailInteraction','event':_0x29bf('0xb'),'condition':_0x29bf('0x6'),'callback':afterCreate},{'channel':_0x29bf('0x16'),'model':'MailInteraction','event':_0x29bf('0x8'),'condition':_0x29bf('0x9'),'callback':afterUpdate},{'channel':'Mail','model':_0x29bf('0x17'),'event':_0x29bf('0xb'),'condition':'newmessage','callback':afterCreateMessage},{'channel':_0x29bf('0x18'),'model':_0x29bf('0x19'),'event':_0x29bf('0xb'),'condition':_0x29bf('0x6'),'callback':afterCreate},{'channel':_0x29bf('0x18'),'model':_0x29bf('0x19'),'event':_0x29bf('0x8'),'condition':_0x29bf('0x9'),'callback':afterUpdate},{'channel':_0x29bf('0x18'),'model':_0x29bf('0x1a'),'event':_0x29bf('0xb'),'condition':_0x29bf('0xc'),'callback':afterCreateMessage}];function request(_0x189bdc){return client[_0x29bf('0x1b')](_0x29bf('0x1c'),_0x189bdc)['then'](function(_0x5e2d40){logger[_0x29bf('0x1d')](_0x29bf('0x1e'),'EventManager',_0x5e2d40);if(_0x5e2d40[_0x29bf('0x1f')]){if(_0x5e2d40['error'][_0x29bf('0x20')]===0x1f4){logger['error'](_0x29bf('0x1e'),_0x29bf('0x1c'),_0x5e2d40[_0x29bf('0x1f')]);}}})[_0x29bf('0x21')](function(_0x45c087){logger['error'](_0x29bf('0x1e'),_0x29bf('0x1c'),_0x45c087);});}function afterCreateMessage(_0x13f083,_0x3eb6c4){return function(_0x32cec2,_0x2ded99){_0x32cec2=_0x32cec2[_0x29bf('0x22')]({'plain':!![]});_0x32cec2['channel']=_0x13f083;_0x32cec2[_0x29bf('0x23')]=_0x32cec2[_0x29bf('0x24')];if(_0x32cec2[_0x29bf('0x25')]){return db['User'][_0x29bf('0x26')]({'where':{'id':_0x32cec2[_0x29bf('0x25')]},'attributes':['id','name'],'raw':!![]})[_0x29bf('0x27')](function(_0x34f8b6){_0x32cec2[_0x29bf('0x28')]=util[_0x29bf('0x29')](_0x29bf('0x2a'),_0x34f8b6[_0x29bf('0x2b')]);_0x32cec2[_0x29bf('0x2c')]=_0x13f083;return request({'event':'incomingmessage','message':_0x32cec2});})[_0x29bf('0x21')](function(_0x503d0b){console[_0x29bf('0x1f')](_0x503d0b);});}else{return request({'event':_0x29bf('0x2d'),'message':_0x32cec2});}};}function afterCreate(_0x2f1ddb,_0x364d17){return function(_0x1b7b02,_0x31ee25){_0x1b7b02=_0x1b7b02[_0x29bf('0x22')]({'plain':!![]});_0x1b7b02[_0x29bf('0x2c')]=_0x2f1ddb;_0x1b7b02['event']=_0x29bf('0x2e');return request({'event':_0x364d17,'message':_0x1b7b02});};}function afterUpdate(_0x3c0653,_0x43a4d6){return function(_0x3dbca4,_0x1a704a){if(_0x3dbca4[_0x29bf('0x2f')](_0x29bf('0x30'))&&_0x3dbca4[_0x29bf('0x30')]){_0x3dbca4=_0x3dbca4[_0x29bf('0x22')]({'plain':!![]});_0x3dbca4[_0x29bf('0x2c')]=_0x3c0653;_0x3dbca4[_0x29bf('0x23')]=_0x29bf('0x30');if(_0x3dbca4['UserId']){return db[_0x29bf('0x31')][_0x29bf('0x26')]({'where':{'id':_0x3dbca4[_0x29bf('0x25')]},'attributes':['id',_0x29bf('0x2b')],'raw':!![]})[_0x29bf('0x27')](function(_0x3be9a2){_0x3dbca4[_0x29bf('0x28')]=util[_0x29bf('0x29')]('SIP/%s',_0x3be9a2['name']);return request({'event':_0x43a4d6,'message':_0x3dbca4});})[_0x29bf('0x21')](function(_0x411b18){console[_0x29bf('0x1f')](_0x411b18);});}else{return request({'event':_0x43a4d6,'message':_0x3dbca4});}}};}exports[_0x29bf('0x32')]=function(){for(var _0x146746=0x0;_0x146746<triggers['length'];_0x146746+=0x1){if(db[_0x29bf('0x33')](triggers[_0x146746][_0x29bf('0x34')])){db[triggers[_0x146746][_0x29bf('0x34')]]['hook'](triggers[_0x146746][_0x29bf('0x23')],triggers[_0x146746][_0x29bf('0x35')](triggers[_0x146746][_0x29bf('0x2c')][_0x29bf('0x36')](),triggers[_0x146746]['condition']));}}};