Built motion from commit 953226e6.|2.6.32
[motion2.git] / server / config / triggers / index.js
index 68b9f93..99c7aa0 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x03ff=['find','name','then','format','SIP/%s','incomingmessage','outgoingmessage','opened','changed','closed','default','length','hasOwnProperty','model','hook','toLowerCase','condition','util','../../mysqldb','../logger','triggers','client','ChatInteraction','afterCreate','newinteraction','afterUpdate','closedinteraction','Chat','ChatMessage','Sms','SmsInteraction','SmsMessage','Whatsapp','WhatsappInteraction','WhatsappMessage','newmessage','FaxInteraction','Fax','FaxMessage','Mail','MailInteraction','MailMessage','OpenchannelInteraction','Openchannel','OpenchannelMessage','request','EventManager','info','Trigger,\x20%s','error','code','catch','get','channel','event','direction','UserId'];(function(_0x39772f,_0x5605cb){var _0xc9edbf=function(_0x106a39){while(--_0x106a39){_0x39772f['push'](_0x39772f['shift']());}};_0xc9edbf(++_0x5605cb);}(_0x03ff,0xf5));var _0xf03f=function(_0x5b561d,_0x422b7c){_0x5b561d=_0x5b561d-0x0;var _0x431060=_0x03ff[_0x5b561d];return _0x431060;};'use strict';var util=require(_0xf03f('0x0'));var db=require(_0xf03f('0x1'))['db'];var jayson=require('jayson/promise');var logger=require(_0xf03f('0x2'))(_0xf03f('0x3'));var client=jayson[_0xf03f('0x4')]['http']({'port':0x232a});var triggers=[{'channel':'Chat','model':_0xf03f('0x5'),'event':_0xf03f('0x6'),'condition':_0xf03f('0x7'),'callback':afterCreate},{'channel':'Chat','model':_0xf03f('0x5'),'event':_0xf03f('0x8'),'condition':_0xf03f('0x9'),'callback':afterUpdate},{'channel':_0xf03f('0xa'),'model':_0xf03f('0xb'),'event':_0xf03f('0x6'),'condition':'newmessage','callback':afterCreateMessage},{'channel':_0xf03f('0xc'),'model':'SmsInteraction','event':_0xf03f('0x6'),'condition':_0xf03f('0x7'),'callback':afterCreate},{'channel':'Sms','model':_0xf03f('0xd'),'event':_0xf03f('0x8'),'condition':_0xf03f('0x9'),'callback':afterUpdate},{'channel':_0xf03f('0xc'),'model':_0xf03f('0xe'),'event':'afterCreate','condition':'newmessage','callback':afterCreateMessage},{'channel':_0xf03f('0xf'),'model':_0xf03f('0x10'),'event':_0xf03f('0x6'),'condition':_0xf03f('0x7'),'callback':afterCreate},{'channel':_0xf03f('0xf'),'model':'WhatsappInteraction','event':_0xf03f('0x8'),'condition':_0xf03f('0x9'),'callback':afterUpdate},{'channel':'Whatsapp','model':_0xf03f('0x11'),'event':_0xf03f('0x6'),'condition':_0xf03f('0x12'),'callback':afterCreateMessage},{'channel':'Fax','model':_0xf03f('0x13'),'event':_0xf03f('0x6'),'condition':'newinteraction','callback':afterCreate},{'channel':_0xf03f('0x14'),'model':'FaxInteraction','event':_0xf03f('0x8'),'condition':_0xf03f('0x9'),'callback':afterUpdate},{'channel':'Fax','model':_0xf03f('0x15'),'event':_0xf03f('0x6'),'condition':'newmessage','callback':afterCreateMessage},{'channel':_0xf03f('0x16'),'model':_0xf03f('0x17'),'event':_0xf03f('0x6'),'condition':_0xf03f('0x7'),'callback':afterCreate},{'channel':_0xf03f('0x16'),'model':_0xf03f('0x17'),'event':_0xf03f('0x8'),'condition':_0xf03f('0x9'),'callback':afterUpdate},{'channel':'Mail','model':_0xf03f('0x18'),'event':_0xf03f('0x6'),'condition':_0xf03f('0x12'),'callback':afterCreateMessage},{'channel':'Openchannel','model':_0xf03f('0x19'),'event':_0xf03f('0x6'),'condition':_0xf03f('0x7'),'callback':afterCreate},{'channel':'Openchannel','model':_0xf03f('0x19'),'event':_0xf03f('0x8'),'condition':_0xf03f('0x9'),'callback':afterUpdate},{'channel':_0xf03f('0x1a'),'model':_0xf03f('0x1b'),'event':_0xf03f('0x6'),'condition':_0xf03f('0x12'),'callback':afterCreateMessage}];function request(_0x531fad){return client[_0xf03f('0x1c')](_0xf03f('0x1d'),_0x531fad)['then'](function(_0x563817){logger[_0xf03f('0x1e')](_0xf03f('0x1f'),_0xf03f('0x1d'),_0x563817);if(_0x563817['error']){if(_0x563817[_0xf03f('0x20')][_0xf03f('0x21')]===0x1f4){logger[_0xf03f('0x20')](_0xf03f('0x1f'),_0xf03f('0x1d'),_0x563817[_0xf03f('0x20')]);}}})[_0xf03f('0x22')](function(_0x202506){logger[_0xf03f('0x20')]('Trigger,\x20%s','EventManager',_0x202506);});}function afterCreateMessage(_0x475375,_0x49a939){return function(_0x12f1e0,_0xcab75f){_0x12f1e0=_0x12f1e0[_0xf03f('0x23')]({'plain':!![]});_0x12f1e0[_0xf03f('0x24')]=_0x475375;_0x12f1e0[_0xf03f('0x25')]=_0x12f1e0[_0xf03f('0x26')];if(_0x12f1e0[_0xf03f('0x27')]){return db['User'][_0xf03f('0x28')]({'where':{'id':_0x12f1e0['UserId']},'attributes':['id',_0xf03f('0x29')],'raw':!![]})[_0xf03f('0x2a')](function(_0x5931b2){_0x12f1e0['interface']=util[_0xf03f('0x2b')](_0xf03f('0x2c'),_0x5931b2[_0xf03f('0x29')]);_0x12f1e0[_0xf03f('0x24')]=_0x475375;return request({'event':_0xf03f('0x2d'),'message':_0x12f1e0});})[_0xf03f('0x22')](function(_0x18a231){console['error'](_0x18a231);});}else{return request({'event':_0xf03f('0x2e'),'message':_0x12f1e0});}};}function afterCreate(_0x24aa5f,_0x49031d){return function(_0x2a2e60,_0x4b2404){_0x2a2e60=_0x2a2e60[_0xf03f('0x23')]({'plain':!![]});_0x2a2e60[_0xf03f('0x24')]=_0x24aa5f;_0x2a2e60[_0xf03f('0x25')]=_0xf03f('0x2f');return request({'event':_0x49031d,'message':_0x2a2e60});};}function afterUpdate(_0x3409fd,_0x231d92){return function(_0x3b49fe,_0x4a8097){if(_0x3b49fe[_0xf03f('0x30')](_0xf03f('0x31'))&&_0x3b49fe[_0xf03f('0x31')]){_0x3b49fe=_0x3b49fe[_0xf03f('0x23')]({'plain':!![]});_0x3b49fe[_0xf03f('0x24')]=_0x3409fd;_0x3b49fe[_0xf03f('0x25')]='closed';if(_0x3b49fe['UserId']){return db['User']['find']({'where':{'id':_0x3b49fe[_0xf03f('0x27')]},'attributes':['id',_0xf03f('0x29')],'raw':!![]})[_0xf03f('0x2a')](function(_0x4243da){_0x3b49fe['interface']=util[_0xf03f('0x2b')](_0xf03f('0x2c'),_0x4243da['name']);return request({'event':_0x231d92,'message':_0x3b49fe});})[_0xf03f('0x22')](function(_0x52166f){console[_0xf03f('0x20')](_0x52166f);});}else{return request({'event':_0x231d92,'message':_0x3b49fe});}}};}exports[_0xf03f('0x32')]=function(){for(var _0xb8a5e1=0x0;_0xb8a5e1<triggers[_0xf03f('0x33')];_0xb8a5e1+=0x1){if(db[_0xf03f('0x34')](triggers[_0xb8a5e1][_0xf03f('0x35')])){db[triggers[_0xb8a5e1][_0xf03f('0x35')]][_0xf03f('0x36')](triggers[_0xb8a5e1][_0xf03f('0x25')],triggers[_0xb8a5e1]['callback'](triggers[_0xb8a5e1][_0xf03f('0x24')][_0xf03f('0x37')](),triggers[_0xb8a5e1][_0xf03f('0x38')]));}}};
\ No newline at end of file
+var _0xb98b=['User','find','fullname','email','internal','default','length','hasOwnProperty','hook','toLowerCase','condition','../../mysqldb','jayson/promise','triggers','client','http','Chat','afterCreate','newinteraction','afterUpdate','closedinteraction','ChatMessage','newmessage','ChatOfflineMessage','Sms','SmsInteraction','SmsMessage','Whatsapp','WhatsappInteraction','WhatsappMessage','FaxInteraction','Fax','FaxMessage','Mail','MailInteraction','MailMessage','Openchannel','OpenchannelInteraction','OpenchannelMessage','request','EventManager','then','info','error','Trigger,\x20%s','get','motionChannel','event','direction','resolve','ContactId','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','sequelize','query','QueryTypes','SELECT','contact','UserId','undefined','name','agent','channel','outgoingmessage','AfterCreateMessage','offlineMessage','opened','Sequelize','catch','changed','closed','substatus','SIP/%s','AfterUpdate'];(function(_0x4cecbd,_0x103c9c){var _0x143b0c=function(_0x453d0d){while(--_0x453d0d){_0x4cecbd['push'](_0x4cecbd['shift']());}};_0x143b0c(++_0x103c9c);}(_0xb98b,0x12f));var _0xbb98=function(_0x30c0af,_0x45701d){_0x30c0af=_0x30c0af-0x0;var _0x357cd1=_0xb98b[_0x30c0af];return _0x357cd1;};'use strict';var util=require('util');var db=require(_0xbb98('0x0'))['db'];var jayson=require(_0xbb98('0x1'));var logger=require('../logger')(_0xbb98('0x2'));var client=jayson[_0xbb98('0x3')][_0xbb98('0x4')]({'port':0x232a});var triggers=[{'channel':_0xbb98('0x5'),'model':'ChatInteraction','event':_0xbb98('0x6'),'condition':_0xbb98('0x7'),'callback':afterCreate},{'channel':'Chat','model':'ChatInteraction','event':_0xbb98('0x8'),'condition':_0xbb98('0x9'),'callback':afterUpdate},{'channel':_0xbb98('0x5'),'model':_0xbb98('0xa'),'event':'afterCreate','condition':_0xbb98('0xb'),'callback':afterCreateMessage},{'channel':'Chat','model':_0xbb98('0xc'),'event':_0xbb98('0x6'),'condition':_0xbb98('0xb'),'callback':afterCreateOfflineMessage},{'channel':_0xbb98('0xd'),'model':_0xbb98('0xe'),'event':'afterCreate','condition':_0xbb98('0x7'),'callback':afterCreate},{'channel':_0xbb98('0xd'),'model':_0xbb98('0xe'),'event':_0xbb98('0x8'),'condition':_0xbb98('0x9'),'callback':afterUpdate},{'channel':'Sms','model':_0xbb98('0xf'),'event':_0xbb98('0x6'),'condition':_0xbb98('0xb'),'callback':afterCreateMessage},{'channel':_0xbb98('0x10'),'model':_0xbb98('0x11'),'event':_0xbb98('0x6'),'condition':_0xbb98('0x7'),'callback':afterCreate},{'channel':'Whatsapp','model':_0xbb98('0x11'),'event':_0xbb98('0x8'),'condition':'closedinteraction','callback':afterUpdate},{'channel':_0xbb98('0x10'),'model':_0xbb98('0x12'),'event':_0xbb98('0x6'),'condition':'newmessage','callback':afterCreateMessage},{'channel':'Fax','model':_0xbb98('0x13'),'event':_0xbb98('0x6'),'condition':'newinteraction','callback':afterCreate},{'channel':_0xbb98('0x14'),'model':_0xbb98('0x13'),'event':_0xbb98('0x8'),'condition':_0xbb98('0x9'),'callback':afterUpdate},{'channel':_0xbb98('0x14'),'model':_0xbb98('0x15'),'event':_0xbb98('0x6'),'condition':_0xbb98('0xb'),'callback':afterCreateMessage},{'channel':_0xbb98('0x16'),'model':_0xbb98('0x17'),'event':_0xbb98('0x6'),'condition':_0xbb98('0x7'),'callback':afterCreate},{'channel':_0xbb98('0x16'),'model':'MailInteraction','event':_0xbb98('0x8'),'condition':'closedinteraction','callback':afterUpdate},{'channel':_0xbb98('0x16'),'model':_0xbb98('0x18'),'event':_0xbb98('0x6'),'condition':_0xbb98('0xb'),'callback':afterCreateMessage},{'channel':_0xbb98('0x19'),'model':_0xbb98('0x1a'),'event':_0xbb98('0x6'),'condition':_0xbb98('0x7'),'callback':afterCreate},{'channel':_0xbb98('0x19'),'model':_0xbb98('0x1a'),'event':_0xbb98('0x8'),'condition':'closedinteraction','callback':afterUpdate},{'channel':_0xbb98('0x19'),'model':_0xbb98('0x1b'),'event':_0xbb98('0x6'),'condition':_0xbb98('0xb'),'callback':afterCreateMessage}];function request(_0x13a3f7){return client[_0xbb98('0x1c')](_0xbb98('0x1d'),_0x13a3f7)[_0xbb98('0x1e')](function(_0x4c35a0){logger[_0xbb98('0x1f')]('Trigger,\x20%s',_0xbb98('0x1d'),_0x4c35a0);if(_0x4c35a0[_0xbb98('0x20')]){if(_0x4c35a0['error']['code']===0x1f4){logger[_0xbb98('0x20')](_0xbb98('0x21'),_0xbb98('0x1d'),_0x4c35a0[_0xbb98('0x20')]);}}})['catch'](function(_0x116a8f){logger['error'](_0xbb98('0x21'),_0xbb98('0x1d'),_0x116a8f);});}function afterCreateMessage(_0x18af5b){return function(_0x1a8a75){_0x1a8a75=_0x1a8a75[_0xbb98('0x22')]({'plain':!![]});_0x1a8a75['channel']=_0x18af5b;_0x1a8a75[_0xbb98('0x23')]=_0x18af5b;_0x1a8a75[_0xbb98('0x24')]=_0x1a8a75[_0xbb98('0x25')];Promise[_0xbb98('0x26')]()[_0xbb98('0x1e')](function(){if(typeof _0x1a8a75[_0xbb98('0x27')]==='undefined')return null;var _0x515f98=_0xbb98('0x28')+_0x1a8a75['ContactId'];return db[_0xbb98('0x29')][_0xbb98('0x2a')](_0x515f98,{'type':db['Sequelize'][_0xbb98('0x2b')][_0xbb98('0x2c')],'raw':!![]});})[_0xbb98('0x1e')](function(_0x24b919){if(_0x24b919){_0x1a8a75[_0xbb98('0x2d')]=_0x24b919[0x0];}if(typeof _0x1a8a75[_0xbb98('0x2e')]===_0xbb98('0x2f'))return;return getAgent(_0x1a8a75[_0xbb98('0x2e')]);})['then'](function(_0x1352e4){if(_0x1352e4){_0x1a8a75['interface']=util['format']('SIP/%s',_0x1352e4[_0xbb98('0x30')]);_0x1a8a75[_0xbb98('0x31')]=_0x1352e4;_0x1a8a75[_0xbb98('0x32')]=_0x18af5b;return request({'event':'incomingmessage','message':_0x1a8a75});}else{return request({'event':_0xbb98('0x33'),'message':_0x1a8a75});}})['catch'](function(_0x297e49){logger[_0xbb98('0x20')]('Trigger,\x20%s',_0xbb98('0x34'),_0x297e49);});};}function afterCreateOfflineMessage(_0x4c1f69){return function(_0x1b70cf){_0x1b70cf=_0x1b70cf[_0xbb98('0x22')]({'plain':!![]});_0x1b70cf[_0xbb98('0x32')]=_0x4c1f69;_0x1b70cf[_0xbb98('0x23')]=_0x4c1f69;_0x1b70cf['event']=_0xbb98('0x35');return request({'event':_0x1b70cf[_0xbb98('0x24')],'message':_0x1b70cf});};}function afterCreate(_0x175a2f,_0xd32c37){return function(_0x245a9b){var _0x5ae227=_0x245a9b[_0xbb98('0x22')]({'plain':!![]});_0x5ae227[_0xbb98('0x32')]=_0x175a2f;_0x5ae227[_0xbb98('0x23')]=_0x175a2f;_0x5ae227[_0xbb98('0x24')]=_0xbb98('0x36');Promise[_0xbb98('0x26')]()['then'](function(){var _0x3d0718=_0xbb98('0x28')+_0x5ae227[_0xbb98('0x27')];return db['sequelize'][_0xbb98('0x2a')](_0x3d0718,{'type':db[_0xbb98('0x37')][_0xbb98('0x2b')][_0xbb98('0x2c')],'raw':!![]});})['then'](function(_0x56a2b0){if(_0x56a2b0){_0x5ae227[_0xbb98('0x2d')]=_0x56a2b0[0x0];}if(_0x5ae227[_0xbb98('0x2e')]){return getAgent(_0x5ae227[_0xbb98('0x2e')]);}return;})[_0xbb98('0x1e')](function(_0xe6cf1a){if(_0xe6cf1a){_0x5ae227['interface']=util['format']('SIP/%s',_0xe6cf1a[_0xbb98('0x30')]);_0x5ae227[_0xbb98('0x31')]=_0xe6cf1a;}return request({'event':_0xd32c37,'message':_0x5ae227});})[_0xbb98('0x38')](function(_0x3dce3a){logger[_0xbb98('0x20')](_0xbb98('0x21'),'AfterCreate',_0x3dce3a);});};}function afterUpdate(_0x5ddc04){return function(_0x2aac34){var _0x2f2f13=_0x2aac34[_0xbb98('0x39')](_0xbb98('0x3a'))&&_0x2aac34[_0xbb98('0x3a')];var _0x38c440=_0x2aac34[_0xbb98('0x39')](_0xbb98('0x3b'));if(_0x2f2f13||_0x38c440){var _0x3dd42a=_0x2f2f13?_0xbb98('0x9'):_0xbb98('0x3b');var _0x545fb6=_0x2aac34[_0xbb98('0x22')]({'plain':!![]});_0x545fb6[_0xbb98('0x32')]=_0x5ddc04;_0x545fb6[_0xbb98('0x23')]=_0x5ddc04;_0x545fb6[_0xbb98('0x24')]=_0x2f2f13?_0xbb98('0x3a'):_0xbb98('0x3b');var _0x18412d=_0xbb98('0x28')+_0x545fb6[_0xbb98('0x27')];return db[_0xbb98('0x29')][_0xbb98('0x2a')](_0x18412d,{'type':db['Sequelize'][_0xbb98('0x2b')][_0xbb98('0x2c')],'raw':!![]})[_0xbb98('0x1e')](function(_0x15e6ed){if(_0x15e6ed){_0x545fb6[_0xbb98('0x2d')]=_0x15e6ed[0x0];}if(typeof _0x545fb6[_0xbb98('0x2e')]===_0xbb98('0x2f'))return;return getAgent(_0x545fb6[_0xbb98('0x2e')]);})['then'](function(_0x2b63fd){if(_0x2b63fd){_0x545fb6['interface']=util['format'](_0xbb98('0x3c'),_0x2b63fd['name']);_0x545fb6[_0xbb98('0x31')]=_0x2b63fd;}return request({'event':_0x3dd42a,'message':_0x545fb6});})[_0xbb98('0x38')](function(_0x529924){logger[_0xbb98('0x20')](_0xbb98('0x21'),_0xbb98('0x3d'),_0x529924);});}};}function getAgent(_0x4b8dfc){return db[_0xbb98('0x3e')][_0xbb98('0x3f')]({'where':{'id':_0x4b8dfc},'attributes':['id',_0xbb98('0x30'),_0xbb98('0x40'),_0xbb98('0x41'),_0xbb98('0x42')],'raw':!![]})[_0xbb98('0x1e')](function(_0x3f6d60){return _0x3f6d60;});}exports[_0xbb98('0x43')]=function(){for(var _0x3b8954=0x0;_0x3b8954<triggers[_0xbb98('0x44')];_0x3b8954+=0x1){if(db[_0xbb98('0x45')](triggers[_0x3b8954]['model'])){db[triggers[_0x3b8954]['model']][_0xbb98('0x46')](triggers[_0x3b8954][_0xbb98('0x24')],triggers[_0x3b8954]['callback'](triggers[_0x3b8954]['channel'][_0xbb98('0x47')](),triggers[_0x3b8954][_0xbb98('0x48')]));}}};
\ No newline at end of file