Built motion from commit ffdca78c.|2.6.24
[motion2.git] / server / services / routing / server / applications / dialogflow.js
index ba12603..9a2e366 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xdbfa=['catch','message','md5','../../../../config/logger','routing','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','isNil','UserId','info','[%s][DIALOGFLOW]\x20%s','next','contact','format','YYYY-MM-DD\x20HH:mm:ss','out','channel','sms','whatsapp','phone','ChatWebsiteId','upperFirst','AccountId','account','InteractionId','interaction','created','isEmpty','body','getMustacheRender','create','then','error','stringify','finally','[%s][DIALOGFLOW]\x20Welcome\x20Message\x20has\x20been\x20sent!','stop','textRequest','fulfillment','speech','providerName','dialogflow','providerResponse','result','metadata','endConversation'];(function(_0x563066,_0x376721){var _0x347618=function(_0x1cd119){while(--_0x1cd119){_0x563066['push'](_0x563066['shift']());}};_0x347618(++_0x376721);}(_0xdbfa,0x128));var _0xadbf=function(_0x44651d,_0x1e6710){_0x44651d=_0x44651d-0x0;var _0x49c068=_0xdbfa[_0x44651d];return _0x49c068;};'use strict';var _=require('lodash');var moment=require('moment');var apiai=require('apiai-promise');var md5=require(_0xadbf('0x0'));var utils=require('./utils');var logger=require(_0xadbf('0x1'))(_0xadbf('0x2'));var rpc={'chatMessage':require('../../rpc/chatMessage'),'openchannelMessage':require(_0xadbf('0x3')),'mailMessage':require(_0xadbf('0x4')),'smsMessage':require(_0xadbf('0x5')),'faxMessage':require(_0xadbf('0x6')),'whatsappMessage':require(_0xadbf('0x7'))};exports['consequence']=function(_0x1204f4,_0x30f643){return function(_0x16704e){try{if(!_[_0xadbf('0x8')](this['interaction'][_0xadbf('0x9')])){logger[_0xadbf('0xa')](_0xadbf('0xb'),_0x1204f4,'Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.');return _0x16704e[_0xadbf('0xc')]();}var _0x38f6e7={'ContactId':this[_0xadbf('0xd')]['id'],'sentAt':moment()[_0xadbf('0xe')](_0xadbf('0xf')),'direction':_0xadbf('0x10')};if(this[_0xadbf('0x11')]===_0xadbf('0x12')||this['channel']===_0xadbf('0x13')){_0x38f6e7[_0xadbf('0x14')]=this['interaction'][_0xadbf('0x14')];}var _0x4484a9=this['channel'];if(_0x4484a9==='chat'){_0x38f6e7[_0xadbf('0x15')]=this['account']['id'];}else{_0x38f6e7[_[_0xadbf('0x16')](_0x4484a9)+_0xadbf('0x17')]=this[_0xadbf('0x18')]['id'];}_0x38f6e7[_[_0xadbf('0x16')](_0x4484a9)+_0xadbf('0x19')]=this[_0xadbf('0x1a')]['id'];if(this[_0xadbf('0x1a')][_0xadbf('0x1b')]){var _0x21ee0f=_0x30f643[0x2];if(!_[_0xadbf('0x1c')](_0x21ee0f)){_0x38f6e7[_0xadbf('0x1d')]=utils[_0xadbf('0x1e')](_0x21ee0f,this);return rpc[_0x4484a9+'Message'][_0xadbf('0x1f')](_0x38f6e7)[_0xadbf('0x20')](function(_0x38e3f2){logger[_0xadbf('0xa')](_0xadbf('0xb'),_0x1204f4,_0x38f6e7[_0xadbf('0x1d')]);})['catch'](function(_0x1a1125){logger[_0xadbf('0x21')](_0xadbf('0xb'),_0x1204f4,JSON[_0xadbf('0x22')](_0x1a1125));})[_0xadbf('0x23')](function(){logger[_0xadbf('0xa')](_0xadbf('0x24'),_0x1204f4);_0x16704e[_0xadbf('0x25')]();});}else{logger[_0xadbf('0xa')]('[%s][DIALOGFLOW]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!',_0x1204f4);_0x16704e[_0xadbf('0x25')]();}}else{var _0x252d51=this;var _0x1c871f=apiai(_0x30f643[0x0],{'language':_0x30f643[0x1]||'en'});return _0x1c871f[_0xadbf('0x26')](this['message'][_0xadbf('0x1d')],{'sessionId':md5(this[_0xadbf('0x1a')]['id'])})[_0xadbf('0x20')](function(_0x34f042){_0x252d51[_0xadbf('0x1d')]['dialogflow']=_0x34f042;_0x38f6e7['body']=_0x34f042['result'][_0xadbf('0x27')][_0xadbf('0x28')];_0x38f6e7[_0xadbf('0x29')]=_0xadbf('0x2a');_0x38f6e7[_0xadbf('0x2b')]=JSON[_0xadbf('0x22')](_0x34f042);return rpc[_0x4484a9+'Message'][_0xadbf('0x1f')](_0x38f6e7)[_0xadbf('0x20')](function(_0x3989dc){logger['info'](_0xadbf('0xb'),_0x1204f4,_0x38f6e7[_0xadbf('0x1d')]);if(_0x34f042[_0xadbf('0x2c')][_0xadbf('0x2d')][_0xadbf('0x2e')]){_0x16704e[_0xadbf('0xc')]();}else{_0x16704e[_0xadbf('0x25')]();}})['catch'](function(_0x4d1015){logger[_0xadbf('0x21')](_0xadbf('0xb'),_0x1204f4,JSON[_0xadbf('0x22')](_0x4d1015));_0x16704e['next']();});})[_0xadbf('0x2f')](function(_0x41fdb6){logger[_0xadbf('0x21')]('[%s][DIALOGFLOW]\x20%s',_0x1204f4,_0x41fdb6[_0xadbf('0x30')]);_0x16704e[_0xadbf('0xc')]();});}}catch(_0x57a391){logger[_0xadbf('0x21')](_0xadbf('0xb'),_0x1204f4,JSON[_0xadbf('0x22')](_0x57a391));_0x16704e[_0xadbf('0x25')]();}};};
\ No newline at end of file
+var _0xb4c7=['providerName','providerResponse','metadata','endConversation','lodash','moment','apiai-promise','md5','./utils','routing','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/whatsappMessage','consequence','isNil','UserId','info','[%s][DIALOGFLOW]\x20%s','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','next','contact','format','YYYY-MM-DD\x20HH:mm:ss','out','channel','whatsapp','phone','interaction','chat','ChatWebsiteId','account','AccountId','upperFirst','InteractionId','created','body','getMustacheRender','Message','create','catch','error','stringify','[%s][DIALOGFLOW]\x20Welcome\x20Message\x20has\x20been\x20sent!','stop','[%s][DIALOGFLOW]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!','textRequest','message','then','dialogflow','result','fulfillment','speech'];(function(_0xe77565,_0x2aaa7c){var _0x8ee878=function(_0x256bb7){while(--_0x256bb7){_0xe77565['push'](_0xe77565['shift']());}};_0x8ee878(++_0x2aaa7c);}(_0xb4c7,0x1ea));var _0x7b4c=function(_0x1e5399,_0x245ae4){_0x1e5399=_0x1e5399-0x0;var _0x42157b=_0xb4c7[_0x1e5399];return _0x42157b;};'use strict';var _=require(_0x7b4c('0x0'));var moment=require(_0x7b4c('0x1'));var apiai=require(_0x7b4c('0x2'));var md5=require(_0x7b4c('0x3'));var utils=require(_0x7b4c('0x4'));var logger=require('../../../../config/logger')(_0x7b4c('0x5'));var rpc={'chatMessage':require(_0x7b4c('0x6')),'openchannelMessage':require(_0x7b4c('0x7')),'mailMessage':require(_0x7b4c('0x8')),'smsMessage':require(_0x7b4c('0x9')),'faxMessage':require('../../rpc/faxMessage'),'whatsappMessage':require(_0x7b4c('0xa'))};exports[_0x7b4c('0xb')]=function(_0x2dd5c7,_0x4bf85d){return function(_0x2d7b7e){try{if(!_[_0x7b4c('0xc')](this['interaction'][_0x7b4c('0xd')])){logger[_0x7b4c('0xe')](_0x7b4c('0xf'),_0x2dd5c7,_0x7b4c('0x10'));return _0x2d7b7e[_0x7b4c('0x11')]();}var _0x93d013={'ContactId':this[_0x7b4c('0x12')]['id'],'sentAt':moment()[_0x7b4c('0x13')](_0x7b4c('0x14')),'direction':_0x7b4c('0x15')};if(this['channel']==='sms'||this[_0x7b4c('0x16')]===_0x7b4c('0x17')){_0x93d013[_0x7b4c('0x18')]=this[_0x7b4c('0x19')][_0x7b4c('0x18')];}var _0x341d36=this[_0x7b4c('0x16')];if(_0x341d36===_0x7b4c('0x1a')){_0x93d013[_0x7b4c('0x1b')]=this[_0x7b4c('0x1c')]['id'];}else{_0x93d013[_['upperFirst'](_0x341d36)+_0x7b4c('0x1d')]=this[_0x7b4c('0x1c')]['id'];}_0x93d013[_[_0x7b4c('0x1e')](_0x341d36)+_0x7b4c('0x1f')]=this[_0x7b4c('0x19')]['id'];if(this[_0x7b4c('0x19')][_0x7b4c('0x20')]){var _0x22c409=_0x4bf85d[0x2];if(!_['isEmpty'](_0x22c409)){_0x93d013[_0x7b4c('0x21')]=utils[_0x7b4c('0x22')](_0x22c409,this);return rpc[_0x341d36+_0x7b4c('0x23')][_0x7b4c('0x24')](_0x93d013)['then'](function(_0x3ce10c){logger[_0x7b4c('0xe')](_0x7b4c('0xf'),_0x2dd5c7,_0x93d013[_0x7b4c('0x21')]);})[_0x7b4c('0x25')](function(_0x1363b4){logger[_0x7b4c('0x26')](_0x7b4c('0xf'),_0x2dd5c7,JSON[_0x7b4c('0x27')](_0x1363b4));})['finally'](function(){logger[_0x7b4c('0xe')](_0x7b4c('0x28'),_0x2dd5c7);_0x2d7b7e[_0x7b4c('0x29')]();});}else{logger[_0x7b4c('0xe')](_0x7b4c('0x2a'),_0x2dd5c7);_0x2d7b7e[_0x7b4c('0x29')]();}}else{var _0x176704=this;var _0x3d4826=apiai(_0x4bf85d[0x0],{'language':_0x4bf85d[0x1]||'en'});return _0x3d4826[_0x7b4c('0x2b')](this[_0x7b4c('0x2c')]['body'],{'sessionId':md5(this[_0x7b4c('0x19')]['id'])})[_0x7b4c('0x2d')](function(_0x276271){_0x176704[_0x7b4c('0x21')][_0x7b4c('0x2e')]=_0x276271;_0x93d013[_0x7b4c('0x21')]=_0x276271[_0x7b4c('0x2f')][_0x7b4c('0x30')][_0x7b4c('0x31')];_0x93d013[_0x7b4c('0x32')]=_0x7b4c('0x2e');_0x93d013[_0x7b4c('0x33')]=JSON[_0x7b4c('0x27')](_0x276271);return rpc[_0x341d36+'Message'][_0x7b4c('0x24')](_0x93d013)[_0x7b4c('0x2d')](function(_0x1fe0f5){logger[_0x7b4c('0xe')](_0x7b4c('0xf'),_0x2dd5c7,_0x93d013[_0x7b4c('0x21')]);if(_0x276271[_0x7b4c('0x2f')][_0x7b4c('0x34')][_0x7b4c('0x35')]){_0x2d7b7e[_0x7b4c('0x11')]();}else{_0x2d7b7e[_0x7b4c('0x29')]();}})[_0x7b4c('0x25')](function(_0x3544bc){logger[_0x7b4c('0x26')](_0x7b4c('0xf'),_0x2dd5c7,JSON[_0x7b4c('0x27')](_0x3544bc));_0x2d7b7e[_0x7b4c('0x11')]();});})[_0x7b4c('0x25')](function(_0x9d3d31){logger['error']('[%s][DIALOGFLOW]\x20%s',_0x2dd5c7,_0x9d3d31['message']);_0x2d7b7e[_0x7b4c('0x11')]();});}}catch(_0x2efff3){logger[_0x7b4c('0x26')](_0x7b4c('0xf'),_0x2dd5c7,JSON['stringify'](_0x2efff3));_0x2d7b7e[_0x7b4c('0x29')]();}};};
\ No newline at end of file