Built motion from commit d5e4af8c.|2.6.23
[motion2.git] / server / config / triggers / index.js
index 545a4b0..7014eab 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x87cb=['error','code','catch','channel','event','direction','UserId','User','find','name','interface','format','SIP/%s','incomingmessage','get','opened','changed','closed','default','model','hook','callback','util','../../mysqldb','jayson/promise','../logger','triggers','client','http','ChatInteraction','afterCreate','newinteraction','Chat','afterUpdate','closedinteraction','ChatMessage','newmessage','Sms','SmsInteraction','SmsMessage','Whatsapp','WhatsappInteraction','WhatsappMessage','Fax','FaxInteraction','FaxMessage','Mail','MailInteraction','Openchannel','OpenchannelInteraction','OpenchannelMessage','request','EventManager','then','info','Trigger,\x20%s'];(function(_0x51bffe,_0x20668c){var _0x4f1236=function(_0x54d0aa){while(--_0x54d0aa){_0x51bffe['push'](_0x51bffe['shift']());}};_0x4f1236(++_0x20668c);}(_0x87cb,0x19e));var _0xb87c=function(_0x4a53d,_0x58a95e){_0x4a53d=_0x4a53d-0x0;var _0x27410e=_0x87cb[_0x4a53d];return _0x27410e;};'use strict';var util=require(_0xb87c('0x0'));var db=require(_0xb87c('0x1'))['db'];var jayson=require(_0xb87c('0x2'));var logger=require(_0xb87c('0x3'))(_0xb87c('0x4'));var client=jayson[_0xb87c('0x5')][_0xb87c('0x6')]({'port':0x232a});var triggers=[{'channel':'Chat','model':_0xb87c('0x7'),'event':_0xb87c('0x8'),'condition':_0xb87c('0x9'),'callback':afterCreate},{'channel':_0xb87c('0xa'),'model':_0xb87c('0x7'),'event':_0xb87c('0xb'),'condition':_0xb87c('0xc'),'callback':afterUpdate},{'channel':_0xb87c('0xa'),'model':_0xb87c('0xd'),'event':_0xb87c('0x8'),'condition':_0xb87c('0xe'),'callback':afterCreateMessage},{'channel':_0xb87c('0xf'),'model':_0xb87c('0x10'),'event':'afterCreate','condition':_0xb87c('0x9'),'callback':afterCreate},{'channel':_0xb87c('0xf'),'model':_0xb87c('0x10'),'event':_0xb87c('0xb'),'condition':_0xb87c('0xc'),'callback':afterUpdate},{'channel':'Sms','model':_0xb87c('0x11'),'event':_0xb87c('0x8'),'condition':_0xb87c('0xe'),'callback':afterCreateMessage},{'channel':_0xb87c('0x12'),'model':'WhatsappInteraction','event':_0xb87c('0x8'),'condition':'newinteraction','callback':afterCreate},{'channel':_0xb87c('0x12'),'model':_0xb87c('0x13'),'event':_0xb87c('0xb'),'condition':_0xb87c('0xc'),'callback':afterUpdate},{'channel':'Whatsapp','model':_0xb87c('0x14'),'event':_0xb87c('0x8'),'condition':_0xb87c('0xe'),'callback':afterCreateMessage},{'channel':_0xb87c('0x15'),'model':_0xb87c('0x16'),'event':_0xb87c('0x8'),'condition':'newinteraction','callback':afterCreate},{'channel':_0xb87c('0x15'),'model':_0xb87c('0x16'),'event':_0xb87c('0xb'),'condition':_0xb87c('0xc'),'callback':afterUpdate},{'channel':_0xb87c('0x15'),'model':_0xb87c('0x17'),'event':_0xb87c('0x8'),'condition':_0xb87c('0xe'),'callback':afterCreateMessage},{'channel':'Mail','model':'MailInteraction','event':_0xb87c('0x8'),'condition':_0xb87c('0x9'),'callback':afterCreate},{'channel':_0xb87c('0x18'),'model':_0xb87c('0x19'),'event':_0xb87c('0xb'),'condition':'closedinteraction','callback':afterUpdate},{'channel':_0xb87c('0x18'),'model':'MailMessage','event':_0xb87c('0x8'),'condition':_0xb87c('0xe'),'callback':afterCreateMessage},{'channel':_0xb87c('0x1a'),'model':_0xb87c('0x1b'),'event':'afterCreate','condition':_0xb87c('0x9'),'callback':afterCreate},{'channel':_0xb87c('0x1a'),'model':_0xb87c('0x1b'),'event':_0xb87c('0xb'),'condition':'closedinteraction','callback':afterUpdate},{'channel':_0xb87c('0x1a'),'model':_0xb87c('0x1c'),'event':_0xb87c('0x8'),'condition':_0xb87c('0xe'),'callback':afterCreateMessage}];function request(_0x398e1b){return client[_0xb87c('0x1d')](_0xb87c('0x1e'),_0x398e1b)[_0xb87c('0x1f')](function(_0x4ce8cd){logger[_0xb87c('0x20')](_0xb87c('0x21'),_0xb87c('0x1e'),_0x4ce8cd);if(_0x4ce8cd[_0xb87c('0x22')]){if(_0x4ce8cd['error'][_0xb87c('0x23')]===0x1f4){logger[_0xb87c('0x22')]('Trigger,\x20%s',_0xb87c('0x1e'),_0x4ce8cd['error']);}}})[_0xb87c('0x24')](function(_0x2355dd){logger['error']('Trigger,\x20%s',_0xb87c('0x1e'),_0x2355dd);});}function afterCreateMessage(_0x11f99e,_0x3fb2d2){return function(_0x260db9,_0x3ec57b){_0x260db9=_0x260db9['get']({'plain':!![]});_0x260db9[_0xb87c('0x25')]=_0x11f99e;_0x260db9[_0xb87c('0x26')]=_0x260db9[_0xb87c('0x27')];if(_0x260db9[_0xb87c('0x28')]){return db[_0xb87c('0x29')][_0xb87c('0x2a')]({'where':{'id':_0x260db9[_0xb87c('0x28')]},'attributes':['id',_0xb87c('0x2b')],'raw':!![]})[_0xb87c('0x1f')](function(_0x5efb28){_0x260db9[_0xb87c('0x2c')]=util[_0xb87c('0x2d')](_0xb87c('0x2e'),_0x5efb28['name']);_0x260db9[_0xb87c('0x25')]=_0x11f99e;return request({'event':_0xb87c('0x2f'),'message':_0x260db9});})['catch'](function(_0x13dab6){console[_0xb87c('0x22')](_0x13dab6);});}else{return request({'event':'outgoingmessage','message':_0x260db9});}};}function afterCreate(_0x37d147,_0x25c776){return function(_0x5e4346,_0x45537a){_0x5e4346=_0x5e4346[_0xb87c('0x30')]({'plain':!![]});_0x5e4346[_0xb87c('0x25')]=_0x37d147;_0x5e4346['event']=_0xb87c('0x31');return request({'event':_0x25c776,'message':_0x5e4346});};}function afterUpdate(_0x3ac1aa,_0xbc61a3){return function(_0x420e5c,_0x6364cd){if(_0x420e5c[_0xb87c('0x32')]('closed')&&_0x420e5c[_0xb87c('0x33')]){_0x420e5c=_0x420e5c['get']({'plain':!![]});_0x420e5c['channel']=_0x3ac1aa;_0x420e5c[_0xb87c('0x26')]=_0xb87c('0x33');if(_0x420e5c['UserId']){return db[_0xb87c('0x29')][_0xb87c('0x2a')]({'where':{'id':_0x420e5c[_0xb87c('0x28')]},'attributes':['id',_0xb87c('0x2b')],'raw':!![]})[_0xb87c('0x1f')](function(_0x137d64){_0x420e5c[_0xb87c('0x2c')]=util[_0xb87c('0x2d')](_0xb87c('0x2e'),_0x137d64[_0xb87c('0x2b')]);return request({'event':_0xbc61a3,'message':_0x420e5c});})[_0xb87c('0x24')](function(_0xc74dc4){console[_0xb87c('0x22')](_0xc74dc4);});}else{return request({'event':_0xbc61a3,'message':_0x420e5c});}}};}exports[_0xb87c('0x34')]=function(){for(var _0x1af086=0x0;_0x1af086<triggers['length'];_0x1af086+=0x1){if(db['hasOwnProperty'](triggers[_0x1af086][_0xb87c('0x35')])){db[triggers[_0x1af086]['model']][_0xb87c('0x36')](triggers[_0x1af086][_0xb87c('0x26')],triggers[_0x1af086][_0xb87c('0x37')](triggers[_0x1af086][_0xb87c('0x25')]['toLowerCase'](),triggers[_0x1af086]['condition']));}}};
\ No newline at end of file
+var _0xbb6d=['request','EventManager','then','info','Trigger,\x20%s','error','code','catch','get','channel','motionChannel','event','direction','resolve','ContactId','undefined','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','sequelize','QueryTypes','contact','UserId','interface','SIP/%s','name','agent','incomingmessage','outgoingmessage','opened','query','Sequelize','SELECT','AfterCreate','changed','closed','substatus','format','AfterUpdate','User','find','fullname','email','internal','default','length','model','callback','condition','../../mysqldb','jayson/promise','../logger','client','Chat','ChatInteraction','afterCreate','newinteraction','closedinteraction','ChatMessage','newmessage','Sms','SmsInteraction','afterUpdate','Whatsapp','WhatsappInteraction','Fax','FaxInteraction','FaxMessage','Mail','MailInteraction','MailMessage','Openchannel','OpenchannelInteraction','OpenchannelMessage'];(function(_0xbc2cfa,_0x4adaa8){var _0x28244f=function(_0x592415){while(--_0x592415){_0xbc2cfa['push'](_0xbc2cfa['shift']());}};_0x28244f(++_0x4adaa8);}(_0xbb6d,0x107));var _0xdbb6=function(_0x365da3,_0x54ffd5){_0x365da3=_0x365da3-0x0;var _0x142b8c=_0xbb6d[_0x365da3];return _0x142b8c;};'use strict';var util=require('util');var db=require(_0xdbb6('0x0'))['db'];var jayson=require(_0xdbb6('0x1'));var logger=require(_0xdbb6('0x2'))('triggers');var client=jayson[_0xdbb6('0x3')]['http']({'port':0x232a});var triggers=[{'channel':_0xdbb6('0x4'),'model':_0xdbb6('0x5'),'event':_0xdbb6('0x6'),'condition':_0xdbb6('0x7'),'callback':afterCreate},{'channel':_0xdbb6('0x4'),'model':_0xdbb6('0x5'),'event':'afterUpdate','condition':_0xdbb6('0x8'),'callback':afterUpdate},{'channel':_0xdbb6('0x4'),'model':_0xdbb6('0x9'),'event':_0xdbb6('0x6'),'condition':_0xdbb6('0xa'),'callback':afterCreateMessage},{'channel':_0xdbb6('0x4'),'model':'ChatOfflineMessage','event':'afterCreate','condition':_0xdbb6('0xa'),'callback':afterCreateOfflineMessage},{'channel':_0xdbb6('0xb'),'model':_0xdbb6('0xc'),'event':_0xdbb6('0x6'),'condition':'newinteraction','callback':afterCreate},{'channel':_0xdbb6('0xb'),'model':_0xdbb6('0xc'),'event':_0xdbb6('0xd'),'condition':'closedinteraction','callback':afterUpdate},{'channel':_0xdbb6('0xb'),'model':'SmsMessage','event':_0xdbb6('0x6'),'condition':_0xdbb6('0xa'),'callback':afterCreateMessage},{'channel':_0xdbb6('0xe'),'model':_0xdbb6('0xf'),'event':_0xdbb6('0x6'),'condition':_0xdbb6('0x7'),'callback':afterCreate},{'channel':_0xdbb6('0xe'),'model':_0xdbb6('0xf'),'event':_0xdbb6('0xd'),'condition':_0xdbb6('0x8'),'callback':afterUpdate},{'channel':_0xdbb6('0xe'),'model':'WhatsappMessage','event':_0xdbb6('0x6'),'condition':'newmessage','callback':afterCreateMessage},{'channel':_0xdbb6('0x10'),'model':_0xdbb6('0x11'),'event':'afterCreate','condition':_0xdbb6('0x7'),'callback':afterCreate},{'channel':_0xdbb6('0x10'),'model':_0xdbb6('0x11'),'event':_0xdbb6('0xd'),'condition':_0xdbb6('0x8'),'callback':afterUpdate},{'channel':_0xdbb6('0x10'),'model':_0xdbb6('0x12'),'event':'afterCreate','condition':'newmessage','callback':afterCreateMessage},{'channel':_0xdbb6('0x13'),'model':_0xdbb6('0x14'),'event':_0xdbb6('0x6'),'condition':_0xdbb6('0x7'),'callback':afterCreate},{'channel':_0xdbb6('0x13'),'model':_0xdbb6('0x14'),'event':_0xdbb6('0xd'),'condition':_0xdbb6('0x8'),'callback':afterUpdate},{'channel':_0xdbb6('0x13'),'model':_0xdbb6('0x15'),'event':_0xdbb6('0x6'),'condition':_0xdbb6('0xa'),'callback':afterCreateMessage},{'channel':_0xdbb6('0x16'),'model':_0xdbb6('0x17'),'event':_0xdbb6('0x6'),'condition':'newinteraction','callback':afterCreate},{'channel':'Openchannel','model':_0xdbb6('0x17'),'event':'afterUpdate','condition':_0xdbb6('0x8'),'callback':afterUpdate},{'channel':'Openchannel','model':_0xdbb6('0x18'),'event':_0xdbb6('0x6'),'condition':_0xdbb6('0xa'),'callback':afterCreateMessage}];function request(_0xc7e78e){return client[_0xdbb6('0x19')](_0xdbb6('0x1a'),_0xc7e78e)[_0xdbb6('0x1b')](function(_0x2991c0){logger[_0xdbb6('0x1c')](_0xdbb6('0x1d'),_0xdbb6('0x1a'),_0x2991c0);if(_0x2991c0[_0xdbb6('0x1e')]){if(_0x2991c0[_0xdbb6('0x1e')][_0xdbb6('0x1f')]===0x1f4){logger['error'](_0xdbb6('0x1d'),_0xdbb6('0x1a'),_0x2991c0['error']);}}})[_0xdbb6('0x20')](function(_0x2a76c1){logger['error'](_0xdbb6('0x1d'),_0xdbb6('0x1a'),_0x2a76c1);});}function afterCreateMessage(_0xbcbf7f){return function(_0x44b119){_0x44b119=_0x44b119[_0xdbb6('0x21')]({'plain':!![]});_0x44b119[_0xdbb6('0x22')]=_0xbcbf7f;_0x44b119[_0xdbb6('0x23')]=_0xbcbf7f;_0x44b119[_0xdbb6('0x24')]=_0x44b119[_0xdbb6('0x25')];Promise[_0xdbb6('0x26')]()['then'](function(){if(typeof _0x44b119[_0xdbb6('0x27')]===_0xdbb6('0x28'))return null;var _0x2f9a04=_0xdbb6('0x29')+_0x44b119[_0xdbb6('0x27')];return db[_0xdbb6('0x2a')]['query'](_0x2f9a04,{'type':db['Sequelize'][_0xdbb6('0x2b')]['SELECT'],'raw':!![]});})[_0xdbb6('0x1b')](function(_0x311f46){if(_0x311f46){_0x44b119[_0xdbb6('0x2c')]=_0x311f46[0x0];}if(typeof _0x44b119[_0xdbb6('0x2d')]==='undefined')return;return getAgent(_0x44b119['UserId']);})['then'](function(_0x46928a){if(_0x46928a){_0x44b119[_0xdbb6('0x2e')]=util['format'](_0xdbb6('0x2f'),_0x46928a[_0xdbb6('0x30')]);_0x44b119[_0xdbb6('0x31')]=_0x46928a;_0x44b119[_0xdbb6('0x22')]=_0xbcbf7f;return request({'event':_0xdbb6('0x32'),'message':_0x44b119});}else{return request({'event':_0xdbb6('0x33'),'message':_0x44b119});}})[_0xdbb6('0x20')](function(_0x3d761d){logger[_0xdbb6('0x1e')](_0xdbb6('0x1d'),'AfterCreateMessage',_0x3d761d);});};}function afterCreateOfflineMessage(_0x5f0361){return function(_0x5a3c05){_0x5a3c05=_0x5a3c05[_0xdbb6('0x21')]({'plain':!![]});_0x5a3c05[_0xdbb6('0x22')]=_0x5f0361;_0x5a3c05[_0xdbb6('0x23')]=_0x5f0361;_0x5a3c05['event']='offlineMessage';return request({'event':_0x5a3c05[_0xdbb6('0x24')],'message':_0x5a3c05});};}function afterCreate(_0x1e464c,_0x3a26f4){return function(_0x141380){_0x141380=_0x141380[_0xdbb6('0x21')]({'plain':!![]});_0x141380[_0xdbb6('0x22')]=_0x1e464c;_0x141380[_0xdbb6('0x23')]=_0x1e464c;_0x141380[_0xdbb6('0x24')]=_0xdbb6('0x34');Promise[_0xdbb6('0x26')]()[_0xdbb6('0x1b')](function(){var _0x80f66f=_0xdbb6('0x29')+_0x141380['ContactId'];return db[_0xdbb6('0x2a')][_0xdbb6('0x35')](_0x80f66f,{'type':db[_0xdbb6('0x36')]['QueryTypes'][_0xdbb6('0x37')],'raw':!![]});})['then'](function(_0x5c7b19){if(_0x5c7b19){_0x141380[_0xdbb6('0x2c')]=_0x5c7b19[0x0];}if(typeof _0x141380[_0xdbb6('0x2d')]===_0xdbb6('0x28'))return;return getAgent(_0x141380[_0xdbb6('0x2d')]);})['then'](function(_0x11d2d4){if(_0x11d2d4){_0x141380[_0xdbb6('0x2e')]=util['format'](_0xdbb6('0x2f'),_0x11d2d4[_0xdbb6('0x30')]);_0x141380[_0xdbb6('0x31')]=_0x11d2d4;}return request({'event':_0x3a26f4,'message':_0x141380});})['catch'](function(_0x249ee9){logger[_0xdbb6('0x1e')](_0xdbb6('0x1d'),_0xdbb6('0x38'),_0x249ee9);});};}function afterUpdate(_0x385fad){return function(_0x44fb8c){var _0x5b824d=_0x44fb8c[_0xdbb6('0x39')]('closed')&&_0x44fb8c[_0xdbb6('0x3a')];var _0x5293e8=_0x44fb8c['changed'](_0xdbb6('0x3b'));if(_0x5b824d||_0x5293e8){var _0x37cc8c=_0x5b824d?_0xdbb6('0x8'):_0xdbb6('0x3b');var _0x268efc=_0x44fb8c[_0xdbb6('0x21')]({'plain':!![]});_0x268efc[_0xdbb6('0x22')]=_0x385fad;_0x268efc[_0xdbb6('0x23')]=_0x385fad;_0x268efc[_0xdbb6('0x24')]=_0x5b824d?'closed':'substatus';var _0xc741c=_0xdbb6('0x29')+_0x268efc[_0xdbb6('0x27')];return db[_0xdbb6('0x2a')][_0xdbb6('0x35')](_0xc741c,{'type':db[_0xdbb6('0x36')][_0xdbb6('0x2b')][_0xdbb6('0x37')],'raw':!![]})[_0xdbb6('0x1b')](function(_0x2d95b0){if(_0x2d95b0){_0x268efc[_0xdbb6('0x2c')]=_0x2d95b0[0x0];}if(typeof _0x268efc[_0xdbb6('0x2d')]===_0xdbb6('0x28'))return;return getAgent(_0x268efc[_0xdbb6('0x2d')]);})[_0xdbb6('0x1b')](function(_0x150b0c){if(_0x150b0c){_0x268efc[_0xdbb6('0x2e')]=util[_0xdbb6('0x3c')](_0xdbb6('0x2f'),_0x150b0c[_0xdbb6('0x30')]);_0x268efc['agent']=_0x150b0c;}return request({'event':_0x37cc8c,'message':_0x268efc});})['catch'](function(_0x336c93){logger['error']('Trigger,\x20%s',_0xdbb6('0x3d'),_0x336c93);});}};}function getAgent(_0x44cb71){return db[_0xdbb6('0x3e')][_0xdbb6('0x3f')]({'where':{'id':_0x44cb71},'attributes':['id',_0xdbb6('0x30'),_0xdbb6('0x40'),_0xdbb6('0x41'),_0xdbb6('0x42')],'raw':!![]})[_0xdbb6('0x1b')](function(_0x5b9dcd){return _0x5b9dcd;});}exports[_0xdbb6('0x43')]=function(){for(var _0x512a5b=0x0;_0x512a5b<triggers[_0xdbb6('0x44')];_0x512a5b+=0x1){if(db['hasOwnProperty'](triggers[_0x512a5b][_0xdbb6('0x45')])){db[triggers[_0x512a5b][_0xdbb6('0x45')]]['hook'](triggers[_0x512a5b][_0xdbb6('0x24')],triggers[_0x512a5b][_0xdbb6('0x46')](triggers[_0x512a5b][_0xdbb6('0x22')]['toLowerCase'](),triggers[_0x512a5b][_0xdbb6('0x47')]));}}};
\ No newline at end of file