Built motion from commit da617fac.|2.6.6
[motion2.git] / server / config / triggers / index.js
index fabf375..e70d64d 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xf5bc=['toLowerCase','condition','util','../../mysqldb','jayson/promise','../logger','client','http','afterCreate','newinteraction','Chat','ChatInteraction','afterUpdate','closedinteraction','ChatMessage','newmessage','SmsInteraction','Sms','SmsMessage','WhatsappInteraction','Whatsapp','WhatsappMessage','FaxInteraction','Fax','FaxMessage','MailInteraction','Mail','MailMessage','Openchannel','OpenchannelInteraction','OpenchannelMessage','request','then','info','error','code','Trigger,\x20%s','EventManager','catch','get','channel','UserId','User','find','name','interface','format','SIP/%s','incomingmessage','opened','changed','closed','default','length','model','hook','event','callback'];(function(_0x48999d,_0x1e02cb){var _0x1ad0d1=function(_0x3f974e){while(--_0x3f974e){_0x48999d['push'](_0x48999d['shift']());}};_0x1ad0d1(++_0x1e02cb);}(_0xf5bc,0xb0));var _0xcf5b=function(_0x167cc1,_0x56ef5a){_0x167cc1=_0x167cc1-0x0;var _0x10bc4b=_0xf5bc[_0x167cc1];return _0x10bc4b;};'use strict';var util=require(_0xcf5b('0x0'));var db=require(_0xcf5b('0x1'))['db'];var jayson=require(_0xcf5b('0x2'));var logger=require(_0xcf5b('0x3'))('triggers');var client=jayson[_0xcf5b('0x4')][_0xcf5b('0x5')]({'port':0x232a});var triggers=[{'channel':'Chat','model':'ChatInteraction','event':_0xcf5b('0x6'),'condition':_0xcf5b('0x7'),'callback':afterCreate},{'channel':_0xcf5b('0x8'),'model':_0xcf5b('0x9'),'event':_0xcf5b('0xa'),'condition':_0xcf5b('0xb'),'callback':afterUpdate},{'channel':_0xcf5b('0x8'),'model':_0xcf5b('0xc'),'event':_0xcf5b('0x6'),'condition':_0xcf5b('0xd'),'callback':afterCreateMessage},{'channel':'Sms','model':_0xcf5b('0xe'),'event':_0xcf5b('0x6'),'condition':_0xcf5b('0x7'),'callback':afterCreate},{'channel':'Sms','model':_0xcf5b('0xe'),'event':_0xcf5b('0xa'),'condition':_0xcf5b('0xb'),'callback':afterUpdate},{'channel':_0xcf5b('0xf'),'model':_0xcf5b('0x10'),'event':_0xcf5b('0x6'),'condition':_0xcf5b('0xd'),'callback':afterCreateMessage},{'channel':'Whatsapp','model':_0xcf5b('0x11'),'event':_0xcf5b('0x6'),'condition':'newinteraction','callback':afterCreate},{'channel':'Whatsapp','model':'WhatsappInteraction','event':_0xcf5b('0xa'),'condition':_0xcf5b('0xb'),'callback':afterUpdate},{'channel':_0xcf5b('0x12'),'model':_0xcf5b('0x13'),'event':'afterCreate','condition':'newmessage','callback':afterCreateMessage},{'channel':'Fax','model':_0xcf5b('0x14'),'event':'afterCreate','condition':_0xcf5b('0x7'),'callback':afterCreate},{'channel':'Fax','model':_0xcf5b('0x14'),'event':_0xcf5b('0xa'),'condition':_0xcf5b('0xb'),'callback':afterUpdate},{'channel':_0xcf5b('0x15'),'model':_0xcf5b('0x16'),'event':_0xcf5b('0x6'),'condition':_0xcf5b('0xd'),'callback':afterCreateMessage},{'channel':'Mail','model':_0xcf5b('0x17'),'event':'afterCreate','condition':_0xcf5b('0x7'),'callback':afterCreate},{'channel':_0xcf5b('0x18'),'model':_0xcf5b('0x17'),'event':'afterUpdate','condition':_0xcf5b('0xb'),'callback':afterUpdate},{'channel':_0xcf5b('0x18'),'model':_0xcf5b('0x19'),'event':_0xcf5b('0x6'),'condition':'newmessage','callback':afterCreateMessage},{'channel':_0xcf5b('0x1a'),'model':_0xcf5b('0x1b'),'event':'afterCreate','condition':_0xcf5b('0x7'),'callback':afterCreate},{'channel':'Openchannel','model':_0xcf5b('0x1b'),'event':_0xcf5b('0xa'),'condition':_0xcf5b('0xb'),'callback':afterUpdate},{'channel':_0xcf5b('0x1a'),'model':_0xcf5b('0x1c'),'event':'afterCreate','condition':_0xcf5b('0xd'),'callback':afterCreateMessage}];function request(_0x28647){return client[_0xcf5b('0x1d')]('EventManager',_0x28647)[_0xcf5b('0x1e')](function(_0x397b96){logger[_0xcf5b('0x1f')]('Trigger,\x20%s','EventManager',_0x397b96);if(_0x397b96[_0xcf5b('0x20')]){if(_0x397b96['error'][_0xcf5b('0x21')]===0x1f4){logger[_0xcf5b('0x20')](_0xcf5b('0x22'),_0xcf5b('0x23'),_0x397b96[_0xcf5b('0x20')]);}}})[_0xcf5b('0x24')](function(_0x599c23){logger[_0xcf5b('0x20')](_0xcf5b('0x22'),'EventManager',_0x599c23);});}function afterCreateMessage(_0x51f93a,_0x3fdbe0){return function(_0x3a9f13,_0x181c50){_0x3a9f13=_0x3a9f13[_0xcf5b('0x25')]({'plain':!![]});_0x3a9f13[_0xcf5b('0x26')]=_0x51f93a;_0x3a9f13['event']=_0x3a9f13['direction'];if(_0x3a9f13[_0xcf5b('0x27')]){return db[_0xcf5b('0x28')][_0xcf5b('0x29')]({'where':{'id':_0x3a9f13[_0xcf5b('0x27')]},'attributes':['id',_0xcf5b('0x2a')],'raw':!![]})[_0xcf5b('0x1e')](function(_0x1cf7c6){_0x3a9f13[_0xcf5b('0x2b')]=util[_0xcf5b('0x2c')](_0xcf5b('0x2d'),_0x1cf7c6[_0xcf5b('0x2a')]);_0x3a9f13[_0xcf5b('0x26')]=_0x51f93a;return request({'event':_0xcf5b('0x2e'),'message':_0x3a9f13});})[_0xcf5b('0x24')](function(_0x2ebdb0){console[_0xcf5b('0x20')](_0x2ebdb0);});}else{return request({'event':'outgoingmessage','message':_0x3a9f13});}};}function afterCreate(_0x152297,_0x17231d){return function(_0x1d906c,_0x279f7f){_0x1d906c=_0x1d906c['get']({'plain':!![]});_0x1d906c[_0xcf5b('0x26')]=_0x152297;_0x1d906c['event']=_0xcf5b('0x2f');return request({'event':_0x17231d,'message':_0x1d906c});};}function afterUpdate(_0x526973,_0x5e3c66){return function(_0x4839cf,_0x5e895f){if(_0x4839cf[_0xcf5b('0x30')](_0xcf5b('0x31'))&&_0x4839cf[_0xcf5b('0x31')]){_0x4839cf=_0x4839cf[_0xcf5b('0x25')]({'plain':!![]});_0x4839cf['channel']=_0x526973;_0x4839cf['event']='closed';if(_0x4839cf['UserId']){return db['User']['find']({'where':{'id':_0x4839cf[_0xcf5b('0x27')]},'attributes':['id','name'],'raw':!![]})['then'](function(_0x408cce){_0x4839cf[_0xcf5b('0x2b')]=util[_0xcf5b('0x2c')](_0xcf5b('0x2d'),_0x408cce[_0xcf5b('0x2a')]);return request({'event':_0x5e3c66,'message':_0x4839cf});})[_0xcf5b('0x24')](function(_0x4c4c4f){console[_0xcf5b('0x20')](_0x4c4c4f);});}else{return request({'event':_0x5e3c66,'message':_0x4839cf});}}};}exports[_0xcf5b('0x32')]=function(){for(var _0x33c0e5=0x0;_0x33c0e5<triggers[_0xcf5b('0x33')];_0x33c0e5+=0x1){if(db['hasOwnProperty'](triggers[_0x33c0e5]['model'])){db[triggers[_0x33c0e5][_0xcf5b('0x34')]][_0xcf5b('0x35')](triggers[_0x33c0e5][_0xcf5b('0x36')],triggers[_0x33c0e5][_0xcf5b('0x37')](triggers[_0x33c0e5][_0xcf5b('0x26')][_0xcf5b('0x38')](),triggers[_0x33c0e5][_0xcf5b('0x39')]));}}};
\ No newline at end of file
+var _0x3b48=['util','../../mysqldb','jayson/promise','../logger','triggers','client','ChatInteraction','afterCreate','newinteraction','Chat','afterUpdate','closedinteraction','ChatMessage','newmessage','ChatOfflineMessage','Sms','SmsInteraction','SmsMessage','WhatsappInteraction','Whatsapp','WhatsappMessage','FaxInteraction','Fax','FaxMessage','Mail','MailInteraction','MailMessage','Openchannel','OpenchannelInteraction','request','EventManager','then','info','Trigger,\x20%s','error','code','catch','get','channel','motionChannel','event','direction','resolve','ContactId','sequelize','query','QueryTypes','contact','UserId','SIP/%s','name','agent','incomingmessage','AfterCreateMessage','offlineMessage','opened','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','Sequelize','undefined','format','AfterCreate','changed','closed','substatus','SELECT','AfterUpdate','find','fullname','internal','default','length','hasOwnProperty','model','toLowerCase','condition'];(function(_0xfa131e,_0x4b1912){var _0x3146b4=function(_0x5e2ede){while(--_0x5e2ede){_0xfa131e['push'](_0xfa131e['shift']());}};_0x3146b4(++_0x4b1912);}(_0x3b48,0x1c2));var _0x83b4=function(_0x3820ba,_0x52c5c5){_0x3820ba=_0x3820ba-0x0;var _0x3c70ee=_0x3b48[_0x3820ba];return _0x3c70ee;};'use strict';var util=require(_0x83b4('0x0'));var db=require(_0x83b4('0x1'))['db'];var jayson=require(_0x83b4('0x2'));var logger=require(_0x83b4('0x3'))(_0x83b4('0x4'));var client=jayson[_0x83b4('0x5')]['http']({'port':0x232a});var triggers=[{'channel':'Chat','model':_0x83b4('0x6'),'event':_0x83b4('0x7'),'condition':_0x83b4('0x8'),'callback':afterCreate},{'channel':_0x83b4('0x9'),'model':_0x83b4('0x6'),'event':_0x83b4('0xa'),'condition':_0x83b4('0xb'),'callback':afterUpdate},{'channel':_0x83b4('0x9'),'model':_0x83b4('0xc'),'event':_0x83b4('0x7'),'condition':_0x83b4('0xd'),'callback':afterCreateMessage},{'channel':_0x83b4('0x9'),'model':_0x83b4('0xe'),'event':_0x83b4('0x7'),'condition':_0x83b4('0xd'),'callback':afterCreateOfflineMessage},{'channel':_0x83b4('0xf'),'model':_0x83b4('0x10'),'event':_0x83b4('0x7'),'condition':'newinteraction','callback':afterCreate},{'channel':_0x83b4('0xf'),'model':_0x83b4('0x10'),'event':'afterUpdate','condition':_0x83b4('0xb'),'callback':afterUpdate},{'channel':_0x83b4('0xf'),'model':_0x83b4('0x11'),'event':_0x83b4('0x7'),'condition':'newmessage','callback':afterCreateMessage},{'channel':'Whatsapp','model':_0x83b4('0x12'),'event':_0x83b4('0x7'),'condition':_0x83b4('0x8'),'callback':afterCreate},{'channel':_0x83b4('0x13'),'model':_0x83b4('0x12'),'event':_0x83b4('0xa'),'condition':'closedinteraction','callback':afterUpdate},{'channel':'Whatsapp','model':_0x83b4('0x14'),'event':_0x83b4('0x7'),'condition':_0x83b4('0xd'),'callback':afterCreateMessage},{'channel':'Fax','model':_0x83b4('0x15'),'event':_0x83b4('0x7'),'condition':_0x83b4('0x8'),'callback':afterCreate},{'channel':_0x83b4('0x16'),'model':_0x83b4('0x15'),'event':_0x83b4('0xa'),'condition':_0x83b4('0xb'),'callback':afterUpdate},{'channel':_0x83b4('0x16'),'model':_0x83b4('0x17'),'event':'afterCreate','condition':_0x83b4('0xd'),'callback':afterCreateMessage},{'channel':_0x83b4('0x18'),'model':'MailInteraction','event':_0x83b4('0x7'),'condition':_0x83b4('0x8'),'callback':afterCreate},{'channel':_0x83b4('0x18'),'model':_0x83b4('0x19'),'event':'afterUpdate','condition':_0x83b4('0xb'),'callback':afterUpdate},{'channel':_0x83b4('0x18'),'model':_0x83b4('0x1a'),'event':'afterCreate','condition':_0x83b4('0xd'),'callback':afterCreateMessage},{'channel':_0x83b4('0x1b'),'model':_0x83b4('0x1c'),'event':_0x83b4('0x7'),'condition':_0x83b4('0x8'),'callback':afterCreate},{'channel':_0x83b4('0x1b'),'model':'OpenchannelInteraction','event':'afterUpdate','condition':_0x83b4('0xb'),'callback':afterUpdate},{'channel':'Openchannel','model':'OpenchannelMessage','event':_0x83b4('0x7'),'condition':_0x83b4('0xd'),'callback':afterCreateMessage}];function request(_0x51cb7d){return client[_0x83b4('0x1d')](_0x83b4('0x1e'),_0x51cb7d)[_0x83b4('0x1f')](function(_0x14f8ac){logger[_0x83b4('0x20')](_0x83b4('0x21'),_0x83b4('0x1e'),_0x14f8ac);if(_0x14f8ac['error']){if(_0x14f8ac[_0x83b4('0x22')][_0x83b4('0x23')]===0x1f4){logger[_0x83b4('0x22')](_0x83b4('0x21'),_0x83b4('0x1e'),_0x14f8ac[_0x83b4('0x22')]);}}})[_0x83b4('0x24')](function(_0x22f3d3){logger[_0x83b4('0x22')](_0x83b4('0x21'),_0x83b4('0x1e'),_0x22f3d3);});}function afterCreateMessage(_0x114ffb){return function(_0x2c3963){_0x2c3963=_0x2c3963[_0x83b4('0x25')]({'plain':!![]});_0x2c3963[_0x83b4('0x26')]=_0x114ffb;_0x2c3963[_0x83b4('0x27')]=_0x114ffb;_0x2c3963[_0x83b4('0x28')]=_0x2c3963[_0x83b4('0x29')];Promise[_0x83b4('0x2a')]()[_0x83b4('0x1f')](function(){if(typeof _0x2c3963[_0x83b4('0x2b')]==='undefined')return null;var _0x422fa4='SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20'+_0x2c3963[_0x83b4('0x2b')];return db[_0x83b4('0x2c')][_0x83b4('0x2d')](_0x422fa4,{'type':db['Sequelize'][_0x83b4('0x2e')]['SELECT'],'raw':!![]});})[_0x83b4('0x1f')](function(_0x54ffaa){if(_0x54ffaa){_0x2c3963[_0x83b4('0x2f')]=_0x54ffaa[0x0];}if(typeof _0x2c3963['UserId']==='undefined')return;return getAgent(_0x2c3963[_0x83b4('0x30')]);})['then'](function(_0x19e376){if(_0x19e376){_0x2c3963['interface']=util['format'](_0x83b4('0x31'),_0x19e376[_0x83b4('0x32')]);_0x2c3963[_0x83b4('0x33')]=_0x19e376;_0x2c3963[_0x83b4('0x26')]=_0x114ffb;return request({'event':_0x83b4('0x34'),'message':_0x2c3963});}else{return request({'event':'outgoingmessage','message':_0x2c3963});}})['catch'](function(_0x373591){logger[_0x83b4('0x22')](_0x83b4('0x21'),_0x83b4('0x35'),_0x373591);});};}function afterCreateOfflineMessage(_0x350f45){return function(_0x39f0ae){_0x39f0ae=_0x39f0ae['get']({'plain':!![]});_0x39f0ae[_0x83b4('0x26')]=_0x350f45;_0x39f0ae['motionChannel']=_0x350f45;_0x39f0ae['event']=_0x83b4('0x36');return request({'event':_0x39f0ae[_0x83b4('0x28')],'message':_0x39f0ae});};}function afterCreate(_0x401744,_0x407a3b){return function(_0x5a3e35){_0x5a3e35=_0x5a3e35[_0x83b4('0x25')]({'plain':!![]});_0x5a3e35[_0x83b4('0x26')]=_0x401744;_0x5a3e35[_0x83b4('0x27')]=_0x401744;_0x5a3e35[_0x83b4('0x28')]=_0x83b4('0x37');Promise['resolve']()[_0x83b4('0x1f')](function(){var _0x40ab07=_0x83b4('0x38')+_0x5a3e35['ContactId'];return db[_0x83b4('0x2c')][_0x83b4('0x2d')](_0x40ab07,{'type':db[_0x83b4('0x39')][_0x83b4('0x2e')]['SELECT'],'raw':!![]});})[_0x83b4('0x1f')](function(_0x321351){if(_0x321351){_0x5a3e35['contact']=_0x321351[0x0];}if(typeof _0x5a3e35[_0x83b4('0x30')]===_0x83b4('0x3a'))return;return getAgent(_0x5a3e35[_0x83b4('0x30')]);})[_0x83b4('0x1f')](function(_0x4a6a65){if(_0x4a6a65){_0x5a3e35['interface']=util[_0x83b4('0x3b')](_0x83b4('0x31'),_0x4a6a65['name']);_0x5a3e35[_0x83b4('0x33')]=_0x4a6a65;}return request({'event':_0x407a3b,'message':_0x5a3e35});})['catch'](function(_0x5f1340){logger['error'](_0x83b4('0x21'),_0x83b4('0x3c'),_0x5f1340);});};}function afterUpdate(_0x1816fa){return function(_0x57c812){var _0x103ef6=_0x57c812[_0x83b4('0x3d')](_0x83b4('0x3e'))&&_0x57c812['closed'];var _0x791a9c=_0x57c812[_0x83b4('0x3d')]('substatus');if(_0x103ef6||_0x791a9c){var _0x5d43e3=_0x103ef6?_0x83b4('0xb'):_0x83b4('0x3f');var _0x4bb010=_0x57c812[_0x83b4('0x25')]({'plain':!![]});_0x4bb010[_0x83b4('0x26')]=_0x1816fa;_0x4bb010[_0x83b4('0x27')]=_0x1816fa;_0x4bb010[_0x83b4('0x28')]=_0x103ef6?_0x83b4('0x3e'):'substatus';var _0x1c77e7=_0x83b4('0x38')+_0x4bb010[_0x83b4('0x2b')];return db[_0x83b4('0x2c')][_0x83b4('0x2d')](_0x1c77e7,{'type':db['Sequelize']['QueryTypes'][_0x83b4('0x40')],'raw':!![]})[_0x83b4('0x1f')](function(_0x445c5e){if(_0x445c5e){_0x4bb010['contact']=_0x445c5e[0x0];}if(typeof _0x4bb010['UserId']===_0x83b4('0x3a'))return;return getAgent(_0x4bb010[_0x83b4('0x30')]);})[_0x83b4('0x1f')](function(_0x266209){if(_0x266209){_0x4bb010['interface']=util[_0x83b4('0x3b')](_0x83b4('0x31'),_0x266209[_0x83b4('0x32')]);_0x4bb010[_0x83b4('0x33')]=_0x266209;}return request({'event':_0x5d43e3,'message':_0x4bb010});})[_0x83b4('0x24')](function(_0x7acfd2){logger[_0x83b4('0x22')](_0x83b4('0x21'),_0x83b4('0x41'),_0x7acfd2);});}};}function getAgent(_0x42c3ef){return db['User'][_0x83b4('0x42')]({'where':{'id':_0x42c3ef},'attributes':['id',_0x83b4('0x32'),_0x83b4('0x43'),'email',_0x83b4('0x44')],'raw':!![]})[_0x83b4('0x1f')](function(_0x3c6697){return _0x3c6697;});}exports[_0x83b4('0x45')]=function(){for(var _0x48b62f=0x0;_0x48b62f<triggers[_0x83b4('0x46')];_0x48b62f+=0x1){if(db[_0x83b4('0x47')](triggers[_0x48b62f][_0x83b4('0x48')])){db[triggers[_0x48b62f][_0x83b4('0x48')]]['hook'](triggers[_0x48b62f]['event'],triggers[_0x48b62f]['callback'](triggers[_0x48b62f][_0x83b4('0x26')][_0x83b4('0x49')](),triggers[_0x48b62f][_0x83b4('0x4a')]));}}};
\ No newline at end of file