Built motion from commit 5ba5b610.|2.5.33
[motion2.git] / server / services / routing / server / applications / dialogflowV2.js
index bf9139e..f6427ea 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xd83b=['finally','[%s][DIALOGFLOWV2]\x20Welcome\x20Message\x20has\x20been\x20sent!','replace','SessionsClient','sessionPath','message','detectIntent','length','dialogflowV2','queryResult','diagnosticInfo','fields','end_conversation','boolValue','action','DIALOGFLOWV2_ALLREQUIREDPARAMSPRESENT','allRequiredParamsPresent','DIALOGFLOWV2_ENDCONVERSATION','DIALOGFLOWV2_INTENTNAME','name','DIALOGFLOWV2_INTENTDISPLAYNAME','intent','displayName','DIALOGFLOWV2_ISFALLBACKINTENT','isFallback','DIALOGFLOWV2_LANGUAGECODE','languageCode','queryText','DIALOGFLOWV2_SCORE','intentDetectionConfidence','providerName','providerResponse','fulfillmentText','push','all','next','stop','error','lodash','md5','moment','bluebird','routing','./utils','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','clone','body','Message','create','then','info','[%s][DIALOGFLOWV2]\x20%s','catch','stringify','interaction','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','contact','format','YYYY-MM-DD\x20HH:mm:ss','out','channel','sms','whatsapp','phone','chat','ChatWebsiteId','account','upperFirst','AccountId','InteractionId','created','isEmpty','getMustacheRender'];(function(_0x2004b2,_0x3dd810){var _0x1b5232=function(_0x4ed810){while(--_0x4ed810){_0x2004b2['push'](_0x2004b2['shift']());}};_0x1b5232(++_0x3dd810);}(_0xd83b,0x71));var _0xbd83=function(_0x3fe92d,_0x963233){_0x3fe92d=_0x3fe92d-0x0;var _0xc3fca7=_0xd83b[_0x3fe92d];return _0xc3fca7;};'use strict';var _=require(_0xbd83('0x0'));var dialogflow=require('dialogflow');var md5=require(_0xbd83('0x1'));var moment=require(_0xbd83('0x2'));var Promise=require(_0xbd83('0x3'));var logger=require('../../../../config/logger')(_0xbd83('0x4'));var utils=require(_0xbd83('0x5'));var rpc={'chatMessage':require(_0xbd83('0x6')),'openchannelMessage':require(_0xbd83('0x7')),'mailMessage':require(_0xbd83('0x8')),'smsMessage':require('../../rpc/smsMessage'),'faxMessage':require('../../rpc/faxMessage'),'whatsappMessage':require('../../rpc/whatsappMessage')};function createMessage(_0x346f7b,_0x90d583,_0x318818,_0x5beb21){return new Promise(function(_0x130b4d,_0xe3eca4){var _0x1ad821=_[_0xbd83('0x9')](_0x318818);_0x1ad821[_0xbd83('0xa')]=_0x5beb21;return rpc[_0x90d583+_0xbd83('0xb')][_0xbd83('0xc')](_0x1ad821)[_0xbd83('0xd')](function(){logger[_0xbd83('0xe')](_0xbd83('0xf'),_0x346f7b,_0x1ad821[_0xbd83('0xa')]);_0x130b4d();})[_0xbd83('0x10')](function(_0x2eb93a){logger['error']('[%s][DIALOGFLOWV2]\x20%s',_0x346f7b,JSON[_0xbd83('0x11')](_0x2eb93a));_0xe3eca4(_0x2eb93a);});});}exports['consequence']=function(_0x4702ab,_0x3134cb){return function(_0x1270ee){try{if(!_['isNil'](this[_0xbd83('0x12')]['UserId'])){logger[_0xbd83('0xe')](_0xbd83('0xf'),_0x4702ab,_0xbd83('0x13'));return _0x1270ee['next']();}var _0x150569={'ContactId':this[_0xbd83('0x14')]['id'],'sentAt':moment()[_0xbd83('0x15')](_0xbd83('0x16')),'direction':_0xbd83('0x17')};if(this[_0xbd83('0x18')]===_0xbd83('0x19')||this[_0xbd83('0x18')]===_0xbd83('0x1a')){_0x150569[_0xbd83('0x1b')]=this['interaction'][_0xbd83('0x1b')];}var _0x367b7c=this[_0xbd83('0x18')];if(_0x367b7c===_0xbd83('0x1c')){_0x150569[_0xbd83('0x1d')]=this[_0xbd83('0x1e')]['id'];}else{_0x150569[_[_0xbd83('0x1f')](_0x367b7c)+_0xbd83('0x20')]=this[_0xbd83('0x1e')]['id'];}_0x150569[_['upperFirst'](_0x367b7c)+_0xbd83('0x21')]=this[_0xbd83('0x12')]['id'];if(this[_0xbd83('0x12')][_0xbd83('0x22')]){var _0x5b9828=_0x3134cb[0x4];if(!_[_0xbd83('0x23')](_0x5b9828)){_0x150569[_0xbd83('0xa')]=utils[_0xbd83('0x24')](_0x5b9828,this);return rpc[_0x367b7c+_0xbd83('0xb')][_0xbd83('0xc')](_0x150569)[_0xbd83('0xd')](function(_0xbd7af8){logger[_0xbd83('0xe')](_0xbd83('0xf'),_0x4702ab,_0x150569['body']);})['catch'](function(_0x4e109c){logger['error']('[%s][DIALOGFLOWV2]\x20%s',_0x4702ab,JSON[_0xbd83('0x11')](_0x4e109c));})[_0xbd83('0x25')](function(){logger[_0xbd83('0xe')](_0xbd83('0x26'),_0x4702ab);_0x1270ee['stop']();});}else{logger[_0xbd83('0xe')]('[%s][DIALOGFLOWV2]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!',_0x4702ab);_0x1270ee['stop']();}}else{var _0x4f2d6f=this;var _0x3789bf=_0x3134cb[0x2][_0xbd83('0x27')](/\\n/g,'\x0a');var _0x4e0818={'credentials':{'private_key':_0x3789bf,'client_email':_0x3134cb[0x1]}};var _0x288fd2=new dialogflow[(_0xbd83('0x28'))](_0x4e0818);var _0x3643fd=_0x288fd2[_0xbd83('0x29')](_0x3134cb[0x0],md5(_0x4f2d6f['interaction']['id']));var _0x3a758d={'session':_0x3643fd,'queryInput':{'text':{'text':_0x4f2d6f[_0xbd83('0x2a')][_0xbd83('0xa')],'languageCode':_0x3134cb[0x3]||'en'}}};return _0x288fd2[_0xbd83('0x2b')](_0x3a758d)[_0xbd83('0xd')](function(_0x2d4cdd){if(_0x2d4cdd&&_0x2d4cdd[_0xbd83('0x2c')]){_0x4f2d6f[_0xbd83('0xa')][_0xbd83('0x2d')]=_0x2d4cdd;var _0x4d4f5a=_0x2d4cdd[0x0];var _0x466adb=_0x4d4f5a[_0xbd83('0x2e')]['diagnosticInfo']&&_0x4d4f5a[_0xbd83('0x2e')][_0xbd83('0x2f')][_0xbd83('0x30')]?_0x4d4f5a[_0xbd83('0x2e')]['diagnosticInfo'][_0xbd83('0x30')][_0xbd83('0x31')][_0xbd83('0x32')]:![];_0x4f2d6f[_0xbd83('0xa')]['DIALOGFLOWV2_ACTION']=_0x4d4f5a[_0xbd83('0x2e')][_0xbd83('0x33')];_0x4f2d6f[_0xbd83('0xa')][_0xbd83('0x34')]=_0x4d4f5a[_0xbd83('0x2e')][_0xbd83('0x35')];_0x4f2d6f['body'][_0xbd83('0x36')]=_0x4d4f5a[_0xbd83('0x2e')][_0xbd83('0x2f')]&&_0x4d4f5a['queryResult'][_0xbd83('0x2f')][_0xbd83('0x30')]?_0x4d4f5a[_0xbd83('0x2e')][_0xbd83('0x2f')][_0xbd83('0x30')][_0xbd83('0x31')][_0xbd83('0x32')]:![];_0x4f2d6f[_0xbd83('0xa')][_0xbd83('0x37')]=_0x4d4f5a[_0xbd83('0x2e')]['intent'][_0xbd83('0x38')];_0x4f2d6f['body'][_0xbd83('0x39')]=_0x4d4f5a[_0xbd83('0x2e')][_0xbd83('0x3a')][_0xbd83('0x3b')];_0x4f2d6f[_0xbd83('0xa')][_0xbd83('0x3c')]=_0x4d4f5a['queryResult']['intent'][_0xbd83('0x3d')];_0x4f2d6f[_0xbd83('0xa')][_0xbd83('0x3e')]=_0x4d4f5a[_0xbd83('0x2e')][_0xbd83('0x3f')];_0x4f2d6f['body']['DIALOGFLOWV2_QUERYTEXT']=_0x4d4f5a[_0xbd83('0x2e')][_0xbd83('0x40')];_0x4f2d6f[_0xbd83('0xa')][_0xbd83('0x41')]=_0x4d4f5a[_0xbd83('0x2e')][_0xbd83('0x42')];_0x150569[_0xbd83('0x43')]='dialogflowV2';_0x150569[_0xbd83('0x44')]=JSON[_0xbd83('0x11')](_0x2d4cdd);var _0x37c7ab=[];for(var _0x31e042=0x0;_0x31e042<_0x2d4cdd['length'];_0x31e042++){var _0x5664fa=_0x2d4cdd[_0x31e042];if(_0x5664fa&&_0x5664fa[_0xbd83('0x2e')]&&_0x5664fa[_0xbd83('0x2e')][_0xbd83('0x45')]){_0x37c7ab[_0xbd83('0x46')](createMessage(_0x4702ab,_0x367b7c,_0x150569,_0x5664fa[_0xbd83('0x2e')]['fulfillmentText']));}}return Promise[_0xbd83('0x47')](_0x37c7ab)['then'](function(){if(_0x466adb){_0x1270ee[_0xbd83('0x48')]();}else{_0x1270ee[_0xbd83('0x49')]();}})['catch'](function(_0x22d186){logger[_0xbd83('0x4a')](_0xbd83('0xf'),_0x4702ab,JSON[_0xbd83('0x11')](_0x22d186));_0x1270ee[_0xbd83('0x48')]();});}})['catch'](function(_0x2370ef){logger[_0xbd83('0x4a')]('[%s][DIALOGFLOWV2]\x20%s',_0x4702ab,_0x2370ef[_0xbd83('0x2a')]);_0x1270ee[_0xbd83('0x48')]();});}}catch(_0x107223){logger[_0xbd83('0x4a')](_0xbd83('0xf'),_0x4702ab,JSON[_0xbd83('0x11')](_0x107223));_0x1270ee[_0xbd83('0x49')]();}};};
\ No newline at end of file
+var _0x7568=['../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','Message','create','then','body','catch','error','[%s][DIALOGFLOWV2]\x20%s','stringify','consequence','interaction','UserId','info','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','next','format','YYYY-MM-DD\x20HH:mm:ss','out','channel','sms','whatsapp','phone','chat','ChatWebsiteId','account','upperFirst','InteractionId','isEmpty','finally','[%s][DIALOGFLOWV2]\x20Welcome\x20Message\x20has\x20been\x20sent!','[%s][DIALOGFLOWV2]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!','stop','SessionsClient','sessionPath','message','detectIntent','dialogflowV2','queryResult','diagnosticInfo','fields','DIALOGFLOWV2_ACTION','DIALOGFLOWV2_ALLREQUIREDPARAMSPRESENT','allRequiredParamsPresent','DIALOGFLOWV2_ENDCONVERSATION','boolValue','name','intent','DIALOGFLOWV2_ISFALLBACKINTENT','isFallback','DIALOGFLOWV2_LANGUAGECODE','languageCode','DIALOGFLOWV2_QUERYTEXT','queryText','DIALOGFLOWV2_SCORE','intentDetectionConfidence','providerName','providerResponse','length','fulfillmentText','push','lodash','dialogflow','moment','bluebird','../../../../config/logger','routing','./utils'];(function(_0x2741d0,_0x139111){var _0x281e9f=function(_0x59af49){while(--_0x59af49){_0x2741d0['push'](_0x2741d0['shift']());}};_0x281e9f(++_0x139111);}(_0x7568,0xd1));var _0x8756=function(_0x2aa0e7,_0x4e5145){_0x2aa0e7=_0x2aa0e7-0x0;var _0x1472c0=_0x7568[_0x2aa0e7];return _0x1472c0;};'use strict';var _=require(_0x8756('0x0'));var dialogflow=require(_0x8756('0x1'));var md5=require('md5');var moment=require(_0x8756('0x2'));var Promise=require(_0x8756('0x3'));var logger=require(_0x8756('0x4'))(_0x8756('0x5'));var utils=require(_0x8756('0x6'));var rpc={'chatMessage':require(_0x8756('0x7')),'openchannelMessage':require(_0x8756('0x8')),'mailMessage':require(_0x8756('0x9')),'smsMessage':require(_0x8756('0xa')),'faxMessage':require(_0x8756('0xb')),'whatsappMessage':require(_0x8756('0xc'))};function createMessage(_0x23f7bf,_0xef7c4d,_0x4f92d3,_0x2c0148){return new Promise(function(_0x6a874f,_0x45b77d){var _0x66e141=_['clone'](_0x4f92d3);_0x66e141['body']=_0x2c0148;return rpc[_0xef7c4d+_0x8756('0xd')][_0x8756('0xe')](_0x66e141)[_0x8756('0xf')](function(){logger['info']('[%s][DIALOGFLOWV2]\x20%s',_0x23f7bf,_0x66e141[_0x8756('0x10')]);_0x6a874f();})[_0x8756('0x11')](function(_0x253c85){logger[_0x8756('0x12')](_0x8756('0x13'),_0x23f7bf,JSON[_0x8756('0x14')](_0x253c85));_0x45b77d(_0x253c85);});});}exports[_0x8756('0x15')]=function(_0x181ae3,_0x2073cb){return function(_0x395401){try{if(!_['isNil'](this[_0x8756('0x16')][_0x8756('0x17')])){logger[_0x8756('0x18')](_0x8756('0x13'),_0x181ae3,_0x8756('0x19'));return _0x395401[_0x8756('0x1a')]();}var _0x1f26e8={'ContactId':this['contact']['id'],'sentAt':moment()[_0x8756('0x1b')](_0x8756('0x1c')),'direction':_0x8756('0x1d')};if(this[_0x8756('0x1e')]===_0x8756('0x1f')||this[_0x8756('0x1e')]===_0x8756('0x20')){_0x1f26e8[_0x8756('0x21')]=this[_0x8756('0x16')][_0x8756('0x21')];}var _0x48642f=this[_0x8756('0x1e')];if(_0x48642f===_0x8756('0x22')){_0x1f26e8[_0x8756('0x23')]=this[_0x8756('0x24')]['id'];}else{_0x1f26e8[_[_0x8756('0x25')](_0x48642f)+'AccountId']=this['account']['id'];}_0x1f26e8[_[_0x8756('0x25')](_0x48642f)+_0x8756('0x26')]=this[_0x8756('0x16')]['id'];if(this[_0x8756('0x16')]['created']){var _0x14a7e9=_0x2073cb[0x4];if(!_[_0x8756('0x27')](_0x14a7e9)){_0x1f26e8[_0x8756('0x10')]=utils['getMustacheRender'](_0x14a7e9,this);return rpc[_0x48642f+_0x8756('0xd')][_0x8756('0xe')](_0x1f26e8)['then'](function(_0x2bc599){logger['info'](_0x8756('0x13'),_0x181ae3,_0x1f26e8[_0x8756('0x10')]);})[_0x8756('0x11')](function(_0x1ac6a4){logger['error']('[%s][DIALOGFLOWV2]\x20%s',_0x181ae3,JSON[_0x8756('0x14')](_0x1ac6a4));})[_0x8756('0x28')](function(){logger[_0x8756('0x18')](_0x8756('0x29'),_0x181ae3);_0x395401['stop']();});}else{logger[_0x8756('0x18')](_0x8756('0x2a'),_0x181ae3);_0x395401[_0x8756('0x2b')]();}}else{var _0x473e02=this;var _0x36e560=_0x2073cb[0x2]['replace'](/\\n/g,'\x0a');var _0x57914e={'credentials':{'private_key':_0x36e560,'client_email':_0x2073cb[0x1]}};var _0x3b890c=new dialogflow[(_0x8756('0x2c'))](_0x57914e);var _0x4dd5b6=_0x3b890c[_0x8756('0x2d')](_0x2073cb[0x0],md5(_0x473e02[_0x8756('0x16')]['id']));var _0x35875a={'session':_0x4dd5b6,'queryInput':{'text':{'text':_0x473e02[_0x8756('0x2e')][_0x8756('0x10')],'languageCode':_0x2073cb[0x3]||'en'}}};return _0x3b890c[_0x8756('0x2f')](_0x35875a)['then'](function(_0x4a627e){if(_0x4a627e&&_0x4a627e['length']){_0x473e02['body'][_0x8756('0x30')]=_0x4a627e;var _0x24b349=_0x4a627e[0x0];var _0x8e5b52=_0x24b349[_0x8756('0x31')][_0x8756('0x32')]&&_0x24b349[_0x8756('0x31')][_0x8756('0x32')][_0x8756('0x33')]?_0x24b349[_0x8756('0x31')][_0x8756('0x32')][_0x8756('0x33')]['end_conversation']['boolValue']:![];_0x473e02['body'][_0x8756('0x34')]=_0x24b349[_0x8756('0x31')]['action'];_0x473e02[_0x8756('0x10')][_0x8756('0x35')]=_0x24b349['queryResult'][_0x8756('0x36')];_0x473e02['body'][_0x8756('0x37')]=_0x24b349[_0x8756('0x31')]['diagnosticInfo']&&_0x24b349[_0x8756('0x31')][_0x8756('0x32')]['fields']?_0x24b349['queryResult']['diagnosticInfo']['fields']['end_conversation'][_0x8756('0x38')]:![];_0x473e02[_0x8756('0x10')]['DIALOGFLOWV2_INTENTNAME']=_0x24b349[_0x8756('0x31')]['intent'][_0x8756('0x39')];_0x473e02['body']['DIALOGFLOWV2_INTENTDISPLAYNAME']=_0x24b349['queryResult'][_0x8756('0x3a')]['displayName'];_0x473e02['body'][_0x8756('0x3b')]=_0x24b349[_0x8756('0x31')][_0x8756('0x3a')][_0x8756('0x3c')];_0x473e02['body'][_0x8756('0x3d')]=_0x24b349[_0x8756('0x31')][_0x8756('0x3e')];_0x473e02[_0x8756('0x10')][_0x8756('0x3f')]=_0x24b349[_0x8756('0x31')][_0x8756('0x40')];_0x473e02[_0x8756('0x10')][_0x8756('0x41')]=_0x24b349[_0x8756('0x31')][_0x8756('0x42')];_0x1f26e8[_0x8756('0x43')]='dialogflowV2';_0x1f26e8[_0x8756('0x44')]=JSON[_0x8756('0x14')](_0x4a627e);var _0x503367=[];for(var _0x2ee542=0x0;_0x2ee542<_0x4a627e[_0x8756('0x45')];_0x2ee542++){var _0x43b8b4=_0x4a627e[_0x2ee542];if(_0x43b8b4&&_0x43b8b4[_0x8756('0x31')]&&_0x43b8b4['queryResult'][_0x8756('0x46')]){_0x503367[_0x8756('0x47')](createMessage(_0x181ae3,_0x48642f,_0x1f26e8,_0x43b8b4[_0x8756('0x31')]['fulfillmentText']));}}return Promise['all'](_0x503367)[_0x8756('0xf')](function(){if(_0x8e5b52){_0x395401['next']();}else{_0x395401[_0x8756('0x2b')]();}})[_0x8756('0x11')](function(_0x22cea3){logger[_0x8756('0x12')](_0x8756('0x13'),_0x181ae3,JSON['stringify'](_0x22cea3));_0x395401[_0x8756('0x1a')]();});}})[_0x8756('0x11')](function(_0x47d67c){logger[_0x8756('0x12')](_0x8756('0x13'),_0x181ae3,_0x47d67c['message']);_0x395401['next']();});}}catch(_0x5a2041){logger['error'](_0x8756('0x13'),_0x181ae3,JSON[_0x8756('0x14')](_0x5a2041));_0x395401[_0x8756('0x2b')]();}};};
\ No newline at end of file