Built motion from commit (unavailable).|2.5.14
[motion2.git] / server / services / routing / server / applications / dialogflowV2.js
index 02a7b95..9b8192b 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x314b=['lodash','dialogflow','md5','bluebird','./utils','../../rpc/openchannelMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','body','Message','create','then','catch','[%s][DIALOGFLOWV2]\x20%s','stringify','consequence','interaction','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','next','format','YYYY-MM-DD\x20HH:mm:ss','channel','whatsapp','chat','ChatWebsiteId','AccountId','account','InteractionId','isEmpty','getMustacheRender','info','[%s][DIALOGFLOWV2]\x20Welcome\x20Message\x20has\x20been\x20sent!','stop','[%s][DIALOGFLOWV2]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!','replace','SessionsClient','sessionPath','message','detectIntent','length','dialogflowV2','queryResult','diagnosticInfo','fields','end_conversation','action','DIALOGFLOWV2_ALLREQUIREDPARAMSPRESENT','allRequiredParamsPresent','DIALOGFLOWV2_ENDCONVERSATION','boolValue','DIALOGFLOWV2_INTENTNAME','DIALOGFLOWV2_INTENTDISPLAYNAME','displayName','DIALOGFLOWV2_ISFALLBACKINTENT','intent','DIALOGFLOWV2_LANGUAGECODE','languageCode','DIALOGFLOWV2_QUERYTEXT','queryText','DIALOGFLOWV2_SCORE','providerName','providerResponse','fulfillmentText','all','error'];(function(_0x9dbad8,_0x56a660){var _0x23d120=function(_0x1ceda5){while(--_0x1ceda5){_0x9dbad8['push'](_0x9dbad8['shift']());}};_0x23d120(++_0x56a660);}(_0x314b,0x14a));var _0xb314=function(_0x28578d,_0xcf5cf0){_0x28578d=_0x28578d-0x0;var _0x524826=_0x314b[_0x28578d];return _0x524826;};'use strict';var _=require(_0xb314('0x0'));var dialogflow=require(_0xb314('0x1'));var md5=require(_0xb314('0x2'));var moment=require('moment');var Promise=require(_0xb314('0x3'));var logger=require('../../../../config/logger')('routing');var utils=require(_0xb314('0x4'));var rpc={'chatMessage':require('../../rpc/chatMessage'),'openchannelMessage':require(_0xb314('0x5')),'mailMessage':require('../../rpc/mailMessage'),'smsMessage':require(_0xb314('0x6')),'faxMessage':require(_0xb314('0x7')),'whatsappMessage':require(_0xb314('0x8'))};function createMessage(_0x4e5764,_0x3773e7,_0x125664,_0x5e8b1e){return new Promise(function(_0x11b059,_0x14a360){var _0x27fd74=_['clone'](_0x125664);_0x27fd74[_0xb314('0x9')]=_0x5e8b1e;return rpc[_0x3773e7+_0xb314('0xa')][_0xb314('0xb')](_0x27fd74)[_0xb314('0xc')](function(){logger['info']('[%s][DIALOGFLOWV2]\x20%s',_0x4e5764,_0x27fd74[_0xb314('0x9')]);_0x11b059();})[_0xb314('0xd')](function(_0x22f4c4){logger['error'](_0xb314('0xe'),_0x4e5764,JSON[_0xb314('0xf')](_0x22f4c4));_0x14a360(_0x22f4c4);});});}exports[_0xb314('0x10')]=function(_0x149f6d,_0x19920c){return function(_0xa28f94){try{if(!_['isNil'](this[_0xb314('0x11')]['UserId'])){logger['info'](_0xb314('0xe'),_0x149f6d,_0xb314('0x12'));return _0xa28f94[_0xb314('0x13')]();}var _0xc93c30={'ContactId':this['contact']['id'],'sentAt':moment()[_0xb314('0x14')](_0xb314('0x15')),'direction':'out'};if(this[_0xb314('0x16')]==='sms'||this[_0xb314('0x16')]===_0xb314('0x17')){_0xc93c30['phone']=this[_0xb314('0x11')]['phone'];}var _0x3ebd72=this[_0xb314('0x16')];if(_0x3ebd72===_0xb314('0x18')){_0xc93c30[_0xb314('0x19')]=this['account']['id'];}else{_0xc93c30[_['upperFirst'](_0x3ebd72)+_0xb314('0x1a')]=this[_0xb314('0x1b')]['id'];}_0xc93c30[_['upperFirst'](_0x3ebd72)+_0xb314('0x1c')]=this[_0xb314('0x11')]['id'];if(this[_0xb314('0x11')]['created']){var _0x36edb5=_0x19920c[0x4];if(!_[_0xb314('0x1d')](_0x36edb5)){_0xc93c30[_0xb314('0x9')]=utils[_0xb314('0x1e')](_0x36edb5,this);return rpc[_0x3ebd72+_0xb314('0xa')][_0xb314('0xb')](_0xc93c30)['then'](function(_0x7bb3bd){logger[_0xb314('0x1f')](_0xb314('0xe'),_0x149f6d,_0xc93c30['body']);})['catch'](function(_0x5bd832){logger['error'](_0xb314('0xe'),_0x149f6d,JSON[_0xb314('0xf')](_0x5bd832));})['finally'](function(){logger[_0xb314('0x1f')](_0xb314('0x20'),_0x149f6d);_0xa28f94[_0xb314('0x21')]();});}else{logger[_0xb314('0x1f')](_0xb314('0x22'),_0x149f6d);_0xa28f94[_0xb314('0x21')]();}}else{var _0xaf1897=this;var _0x42c13d=_0x19920c[0x2][_0xb314('0x23')](/\\n/g,'\x0a');var _0x23e15d={'credentials':{'private_key':_0x42c13d,'client_email':_0x19920c[0x1]}};var _0x2f95e3=new dialogflow[(_0xb314('0x24'))](_0x23e15d);var _0x231e45=_0x2f95e3[_0xb314('0x25')](_0x19920c[0x0],md5(_0xaf1897['interaction']['id']));var _0x37caae={'session':_0x231e45,'queryInput':{'text':{'text':_0xaf1897[_0xb314('0x26')][_0xb314('0x9')],'languageCode':_0x19920c[0x3]||'en'}}};return _0x2f95e3[_0xb314('0x27')](_0x37caae)['then'](function(_0xfefd19){if(_0xfefd19&&_0xfefd19[_0xb314('0x28')]){_0xaf1897[_0xb314('0x9')][_0xb314('0x29')]=_0xfefd19;var _0x481a0a=_0xfefd19[0x0];var _0x82e4f6=_0x481a0a[_0xb314('0x2a')]['diagnosticInfo']&&_0x481a0a[_0xb314('0x2a')]['diagnosticInfo']['fields']?_0x481a0a[_0xb314('0x2a')][_0xb314('0x2b')][_0xb314('0x2c')][_0xb314('0x2d')]['boolValue']:![];_0xaf1897[_0xb314('0x9')]['DIALOGFLOWV2_ACTION']=_0x481a0a[_0xb314('0x2a')][_0xb314('0x2e')];_0xaf1897[_0xb314('0x9')][_0xb314('0x2f')]=_0x481a0a[_0xb314('0x2a')][_0xb314('0x30')];_0xaf1897['body'][_0xb314('0x31')]=_0x481a0a[_0xb314('0x2a')][_0xb314('0x2b')]&&_0x481a0a[_0xb314('0x2a')]['diagnosticInfo'][_0xb314('0x2c')]?_0x481a0a[_0xb314('0x2a')][_0xb314('0x2b')][_0xb314('0x2c')][_0xb314('0x2d')][_0xb314('0x32')]:![];_0xaf1897[_0xb314('0x9')][_0xb314('0x33')]=_0x481a0a[_0xb314('0x2a')]['intent']['name'];_0xaf1897[_0xb314('0x9')][_0xb314('0x34')]=_0x481a0a[_0xb314('0x2a')]['intent'][_0xb314('0x35')];_0xaf1897[_0xb314('0x9')][_0xb314('0x36')]=_0x481a0a[_0xb314('0x2a')][_0xb314('0x37')]['isFallback'];_0xaf1897[_0xb314('0x9')][_0xb314('0x38')]=_0x481a0a[_0xb314('0x2a')][_0xb314('0x39')];_0xaf1897[_0xb314('0x9')][_0xb314('0x3a')]=_0x481a0a[_0xb314('0x2a')][_0xb314('0x3b')];_0xaf1897[_0xb314('0x9')][_0xb314('0x3c')]=_0x481a0a[_0xb314('0x2a')]['intentDetectionConfidence'];_0xc93c30[_0xb314('0x3d')]=_0xb314('0x29');_0xc93c30[_0xb314('0x3e')]=JSON[_0xb314('0xf')](_0xfefd19);var _0x2b59d5=[];for(var _0x81ef59=0x0;_0x81ef59<_0xfefd19[_0xb314('0x28')];_0x81ef59++){var _0x21a8ff=_0xfefd19[_0x81ef59];if(_0x21a8ff&&_0x21a8ff[_0xb314('0x2a')]&&_0x21a8ff[_0xb314('0x2a')][_0xb314('0x3f')]){_0x2b59d5['push'](createMessage(_0x149f6d,_0x3ebd72,_0xc93c30,_0x21a8ff[_0xb314('0x2a')][_0xb314('0x3f')]));}}return Promise[_0xb314('0x40')](_0x2b59d5)['then'](function(){if(_0x82e4f6){_0xa28f94[_0xb314('0x13')]();}else{_0xa28f94[_0xb314('0x21')]();}})[_0xb314('0xd')](function(_0xb3e45a){logger[_0xb314('0x41')](_0xb314('0xe'),_0x149f6d,JSON[_0xb314('0xf')](_0xb3e45a));_0xa28f94[_0xb314('0x13')]();});}})[_0xb314('0xd')](function(_0xafe2ea){logger['error'](_0xb314('0xe'),_0x149f6d,_0xafe2ea[_0xb314('0x26')]);_0xa28f94['next']();});}}catch(_0x2ea41e){logger['error']('[%s][DIALOGFLOWV2]\x20%s',_0x149f6d,JSON[_0xb314('0xf')](_0x2ea41e));_0xa28f94[_0xb314('0x21')]();}};};
\ No newline at end of file
+var _0x43ff=['../../../../config/logger','routing','./utils','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','clone','body','Message','create','then','info','[%s][DIALOGFLOWV2]\x20%s','catch','stringify','isNil','interaction','UserId','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','next','contact','format','YYYY-MM-DD\x20HH:mm:ss','out','channel','sms','whatsapp','phone','account','upperFirst','AccountId','created','isEmpty','getMustacheRender','stop','[%s][DIALOGFLOWV2]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!','replace','SessionsClient','detectIntent','length','dialogflowV2','queryResult','diagnosticInfo','fields','end_conversation','boolValue','DIALOGFLOWV2_ALLREQUIREDPARAMSPRESENT','allRequiredParamsPresent','DIALOGFLOWV2_INTENTNAME','intent','name','DIALOGFLOWV2_INTENTDISPLAYNAME','isFallback','DIALOGFLOWV2_LANGUAGECODE','languageCode','queryText','DIALOGFLOWV2_SCORE','intentDetectionConfidence','providerName','providerResponse','fulfillmentText','push','all','error','message','lodash','dialogflow','md5','moment'];(function(_0x2d688d,_0x20fa88){var _0x536961=function(_0x199992){while(--_0x199992){_0x2d688d['push'](_0x2d688d['shift']());}};_0x536961(++_0x20fa88);}(_0x43ff,0x164));var _0xf43f=function(_0x2f87cd,_0xcaf299){_0x2f87cd=_0x2f87cd-0x0;var _0x5d7eda=_0x43ff[_0x2f87cd];return _0x5d7eda;};'use strict';var _=require(_0xf43f('0x0'));var dialogflow=require(_0xf43f('0x1'));var md5=require(_0xf43f('0x2'));var moment=require(_0xf43f('0x3'));var Promise=require('bluebird');var logger=require(_0xf43f('0x4'))(_0xf43f('0x5'));var utils=require(_0xf43f('0x6'));var rpc={'chatMessage':require(_0xf43f('0x7')),'openchannelMessage':require(_0xf43f('0x8')),'mailMessage':require(_0xf43f('0x9')),'smsMessage':require(_0xf43f('0xa')),'faxMessage':require(_0xf43f('0xb')),'whatsappMessage':require(_0xf43f('0xc'))};function createMessage(_0xf26afa,_0x290e8a,_0x14765a,_0x48e86f){return new Promise(function(_0x1992e0,_0x28357d){var _0x187d13=_[_0xf43f('0xd')](_0x14765a);_0x187d13[_0xf43f('0xe')]=_0x48e86f;return rpc[_0x290e8a+_0xf43f('0xf')][_0xf43f('0x10')](_0x187d13)[_0xf43f('0x11')](function(){logger[_0xf43f('0x12')](_0xf43f('0x13'),_0xf26afa,_0x187d13[_0xf43f('0xe')]);_0x1992e0();})[_0xf43f('0x14')](function(_0x5a1464){logger['error'](_0xf43f('0x13'),_0xf26afa,JSON[_0xf43f('0x15')](_0x5a1464));_0x28357d(_0x5a1464);});});}exports['consequence']=function(_0x2141ca,_0x471db5){return function(_0x1fd1bc){try{if(!_[_0xf43f('0x16')](this[_0xf43f('0x17')][_0xf43f('0x18')])){logger[_0xf43f('0x12')](_0xf43f('0x13'),_0x2141ca,_0xf43f('0x19'));return _0x1fd1bc[_0xf43f('0x1a')]();}var _0x12968d={'ContactId':this[_0xf43f('0x1b')]['id'],'sentAt':moment()[_0xf43f('0x1c')](_0xf43f('0x1d')),'direction':_0xf43f('0x1e')};if(this[_0xf43f('0x1f')]===_0xf43f('0x20')||this[_0xf43f('0x1f')]===_0xf43f('0x21')){_0x12968d[_0xf43f('0x22')]=this[_0xf43f('0x17')][_0xf43f('0x22')];}var _0x15284a=this[_0xf43f('0x1f')];if(_0x15284a==='chat'){_0x12968d['ChatWebsiteId']=this[_0xf43f('0x23')]['id'];}else{_0x12968d[_[_0xf43f('0x24')](_0x15284a)+_0xf43f('0x25')]=this[_0xf43f('0x23')]['id'];}_0x12968d[_[_0xf43f('0x24')](_0x15284a)+'InteractionId']=this[_0xf43f('0x17')]['id'];if(this['interaction'][_0xf43f('0x26')]){var _0x291278=_0x471db5[0x4];if(!_[_0xf43f('0x27')](_0x291278)){_0x12968d[_0xf43f('0xe')]=utils[_0xf43f('0x28')](_0x291278,this);return rpc[_0x15284a+_0xf43f('0xf')][_0xf43f('0x10')](_0x12968d)['then'](function(_0x4e83ac){logger['info']('[%s][DIALOGFLOWV2]\x20%s',_0x2141ca,_0x12968d[_0xf43f('0xe')]);})[_0xf43f('0x14')](function(_0xdb9a58){logger['error'](_0xf43f('0x13'),_0x2141ca,JSON[_0xf43f('0x15')](_0xdb9a58));})['finally'](function(){logger['info']('[%s][DIALOGFLOWV2]\x20Welcome\x20Message\x20has\x20been\x20sent!',_0x2141ca);_0x1fd1bc[_0xf43f('0x29')]();});}else{logger[_0xf43f('0x12')](_0xf43f('0x2a'),_0x2141ca);_0x1fd1bc['stop']();}}else{var _0x257f60=this;var _0x4f8315=_0x471db5[0x2][_0xf43f('0x2b')](/\\n/g,'\x0a');var _0x3647c3={'credentials':{'private_key':_0x4f8315,'client_email':_0x471db5[0x1]}};var _0x2ae6c2=new dialogflow[(_0xf43f('0x2c'))](_0x3647c3);var _0x333a77=_0x2ae6c2['sessionPath'](_0x471db5[0x0],md5(_0x257f60[_0xf43f('0x17')]['id']));var _0x143190={'session':_0x333a77,'queryInput':{'text':{'text':_0x257f60['message'][_0xf43f('0xe')],'languageCode':_0x471db5[0x3]||'en'}}};return _0x2ae6c2[_0xf43f('0x2d')](_0x143190)[_0xf43f('0x11')](function(_0x7b11c5){if(_0x7b11c5&&_0x7b11c5[_0xf43f('0x2e')]){_0x257f60[_0xf43f('0xe')][_0xf43f('0x2f')]=_0x7b11c5;var _0x169d2c=_0x7b11c5[0x0];var _0x235494=_0x169d2c[_0xf43f('0x30')][_0xf43f('0x31')]&&_0x169d2c[_0xf43f('0x30')][_0xf43f('0x31')]['fields']?_0x169d2c[_0xf43f('0x30')][_0xf43f('0x31')][_0xf43f('0x32')][_0xf43f('0x33')][_0xf43f('0x34')]:![];_0x257f60[_0xf43f('0xe')]['DIALOGFLOWV2_ACTION']=_0x169d2c[_0xf43f('0x30')]['action'];_0x257f60[_0xf43f('0xe')][_0xf43f('0x35')]=_0x169d2c[_0xf43f('0x30')][_0xf43f('0x36')];_0x257f60[_0xf43f('0xe')]['DIALOGFLOWV2_ENDCONVERSATION']=_0x169d2c['queryResult'][_0xf43f('0x31')]&&_0x169d2c['queryResult'][_0xf43f('0x31')][_0xf43f('0x32')]?_0x169d2c[_0xf43f('0x30')][_0xf43f('0x31')][_0xf43f('0x32')][_0xf43f('0x33')][_0xf43f('0x34')]:![];_0x257f60[_0xf43f('0xe')][_0xf43f('0x37')]=_0x169d2c['queryResult'][_0xf43f('0x38')][_0xf43f('0x39')];_0x257f60['body'][_0xf43f('0x3a')]=_0x169d2c[_0xf43f('0x30')][_0xf43f('0x38')]['displayName'];_0x257f60[_0xf43f('0xe')]['DIALOGFLOWV2_ISFALLBACKINTENT']=_0x169d2c[_0xf43f('0x30')]['intent'][_0xf43f('0x3b')];_0x257f60[_0xf43f('0xe')][_0xf43f('0x3c')]=_0x169d2c[_0xf43f('0x30')][_0xf43f('0x3d')];_0x257f60[_0xf43f('0xe')]['DIALOGFLOWV2_QUERYTEXT']=_0x169d2c[_0xf43f('0x30')][_0xf43f('0x3e')];_0x257f60[_0xf43f('0xe')][_0xf43f('0x3f')]=_0x169d2c[_0xf43f('0x30')][_0xf43f('0x40')];_0x12968d[_0xf43f('0x41')]='dialogflowV2';_0x12968d[_0xf43f('0x42')]=JSON[_0xf43f('0x15')](_0x7b11c5);var _0x2dbf43=[];for(var _0xf50cac=0x0;_0xf50cac<_0x7b11c5[_0xf43f('0x2e')];_0xf50cac++){var _0x2094b0=_0x7b11c5[_0xf50cac];if(_0x2094b0&&_0x2094b0[_0xf43f('0x30')]&&_0x2094b0[_0xf43f('0x30')][_0xf43f('0x43')]){_0x2dbf43[_0xf43f('0x44')](createMessage(_0x2141ca,_0x15284a,_0x12968d,_0x2094b0[_0xf43f('0x30')][_0xf43f('0x43')]));}}return Promise[_0xf43f('0x45')](_0x2dbf43)[_0xf43f('0x11')](function(){if(_0x235494){_0x1fd1bc[_0xf43f('0x1a')]();}else{_0x1fd1bc[_0xf43f('0x29')]();}})[_0xf43f('0x14')](function(_0x82788){logger[_0xf43f('0x46')](_0xf43f('0x13'),_0x2141ca,JSON[_0xf43f('0x15')](_0x82788));_0x1fd1bc[_0xf43f('0x1a')]();});}})[_0xf43f('0x14')](function(_0x993773){logger['error'](_0xf43f('0x13'),_0x2141ca,_0x993773[_0xf43f('0x47')]);_0x1fd1bc[_0xf43f('0x1a')]();});}}catch(_0x3676ef){logger[_0xf43f('0x46')](_0xf43f('0x13'),_0x2141ca,JSON[_0xf43f('0x15')](_0x3676ef));_0x1fd1bc[_0xf43f('0x29')]();}};};
\ No newline at end of file