Built motion from commit c1aa34a0.|2.6.28
[motion2.git] / server / services / routing / server / applications / dialogflowV2.js
index 980d732..af578ec 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xd385=['YYYY-MM-DD\x20HH:mm:ss','channel','sms','phone','chat','ChatWebsiteId','account','upperFirst','AccountId','created','isEmpty','getMustacheRender','catch','finally','[%s][DIALOGFLOWV2]\x20Welcome\x20Message\x20has\x20been\x20sent!','stop','[%s][DIALOGFLOWV2]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!','replace','sessionPath','detectIntent','length','dialogflowV2','queryResult','diagnosticInfo','fields','boolValue','DIALOGFLOWV2_ACTION','action','DIALOGFLOWV2_ALLREQUIREDPARAMSPRESENT','allRequiredParamsPresent','DIALOGFLOWV2_ENDCONVERSATION','DIALOGFLOWV2_INTENTNAME','name','DIALOGFLOWV2_INTENTDISPLAYNAME','displayName','intent','DIALOGFLOWV2_LANGUAGECODE','DIALOGFLOWV2_QUERYTEXT','DIALOGFLOWV2_SCORE','intentDetectionConfidence','providerName','stringify','push','fulfillmentText','all','next','stack','lodash','moment','bluebird','../../../../config/logger','routing','./utils','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','body','Message','create','then','error','isNil','interaction','UserId','info','[%s][DIALOGFLOWV2]\x20%s','contact','format'];(function(_0x498ccc,_0x1b7dd4){var _0xbaf470=function(_0x358227){while(--_0x358227){_0x498ccc['push'](_0x498ccc['shift']());}};_0xbaf470(++_0x1b7dd4);}(_0xd385,0x104));var _0x5d38=function(_0x50a7d6,_0x109734){_0x50a7d6=_0x50a7d6-0x0;var _0x37feb7=_0xd385[_0x50a7d6];return _0x37feb7;};'use strict';var _=require(_0x5d38('0x0'));var dialogflow=require('dialogflow');var md5=require('md5');var moment=require(_0x5d38('0x1'));var Promise=require(_0x5d38('0x2'));var logger=require(_0x5d38('0x3'))(_0x5d38('0x4'));var utils=require(_0x5d38('0x5'));var rpc={'chatMessage':require(_0x5d38('0x6')),'openchannelMessage':require(_0x5d38('0x7')),'mailMessage':require(_0x5d38('0x8')),'smsMessage':require(_0x5d38('0x9')),'faxMessage':require(_0x5d38('0xa')),'whatsappMessage':require(_0x5d38('0xb'))};function createMessage(_0x3c8907,_0x585fc3,_0x429eb6,_0x2b9b57){return new Promise(function(_0x5e4029,_0xff20f5){var _0x1e0fd8=_['clone'](_0x429eb6);_0x1e0fd8[_0x5d38('0xc')]=_0x2b9b57;return rpc[_0x585fc3+_0x5d38('0xd')][_0x5d38('0xe')](_0x1e0fd8)[_0x5d38('0xf')](function(){logger['info']('[%s][DIALOGFLOWV2]\x20%s',_0x3c8907,_0x1e0fd8[_0x5d38('0xc')]);_0x5e4029();})['catch'](function(_0x145d9b){logger[_0x5d38('0x10')]('[%s][DIALOGFLOWV2]\x20%s',_0x3c8907,JSON['stringify'](_0x145d9b));_0xff20f5(_0x145d9b);});});}exports['consequence']=function(_0x5b0c9d,_0x5e717e){return function(_0x46b163){try{if(!_[_0x5d38('0x11')](this[_0x5d38('0x12')][_0x5d38('0x13')])){logger[_0x5d38('0x14')](_0x5d38('0x15'),_0x5b0c9d,'Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.');return _0x46b163['next']();}var _0x10ba96={'ContactId':this[_0x5d38('0x16')]['id'],'sentAt':moment()[_0x5d38('0x17')](_0x5d38('0x18')),'direction':'out'};if(this[_0x5d38('0x19')]===_0x5d38('0x1a')||this[_0x5d38('0x19')]==='whatsapp'){_0x10ba96[_0x5d38('0x1b')]=this[_0x5d38('0x12')]['phone'];}var _0x528cf2=this[_0x5d38('0x19')];if(_0x528cf2===_0x5d38('0x1c')){_0x10ba96[_0x5d38('0x1d')]=this[_0x5d38('0x1e')]['id'];}else{_0x10ba96[_[_0x5d38('0x1f')](_0x528cf2)+_0x5d38('0x20')]=this[_0x5d38('0x1e')]['id'];}_0x10ba96[_['upperFirst'](_0x528cf2)+'InteractionId']=this[_0x5d38('0x12')]['id'];if(this[_0x5d38('0x12')][_0x5d38('0x21')]){var _0x1523e=_0x5e717e[0x4];if(!_[_0x5d38('0x22')](_0x1523e)){_0x10ba96[_0x5d38('0xc')]=utils[_0x5d38('0x23')](_0x1523e,this);return rpc[_0x528cf2+_0x5d38('0xd')][_0x5d38('0xe')](_0x10ba96)[_0x5d38('0xf')](function(_0x1b55da){logger[_0x5d38('0x14')](_0x5d38('0x15'),_0x5b0c9d,_0x10ba96[_0x5d38('0xc')]);})[_0x5d38('0x24')](function(_0x285362){logger[_0x5d38('0x10')](_0x5d38('0x15'),_0x5b0c9d,JSON['stringify'](_0x285362));})[_0x5d38('0x25')](function(){logger[_0x5d38('0x14')](_0x5d38('0x26'),_0x5b0c9d);_0x46b163[_0x5d38('0x27')]();});}else{logger[_0x5d38('0x14')](_0x5d38('0x28'),_0x5b0c9d);_0x46b163[_0x5d38('0x27')]();}}else{var _0x44d177=this;var _0x3ce1d8=_0x5e717e[0x2][_0x5d38('0x29')](/\\n/g,'\x0a');var _0x48e1c8={'credentials':{'private_key':_0x3ce1d8,'client_email':_0x5e717e[0x1]}};var _0x365bc5=new dialogflow['SessionsClient'](_0x48e1c8);var _0x32266b=_0x365bc5[_0x5d38('0x2a')](_0x5e717e[0x0],md5(_0x44d177[_0x5d38('0x12')]['id']));var _0x45958d={'session':_0x32266b,'queryInput':{'text':{'text':_0x44d177['message'][_0x5d38('0xc')],'languageCode':_0x5e717e[0x3]||'en'}}};return _0x365bc5[_0x5d38('0x2b')](_0x45958d)['then'](function(_0x6d07df){if(_0x6d07df&&_0x6d07df[_0x5d38('0x2c')]){_0x44d177[_0x5d38('0xc')][_0x5d38('0x2d')]=_0x6d07df;var _0x44464e=_0x6d07df[0x0];var _0x295641=_0x44464e[_0x5d38('0x2e')][_0x5d38('0x2f')]&&_0x44464e['queryResult'][_0x5d38('0x2f')][_0x5d38('0x30')]?_0x44464e[_0x5d38('0x2e')]['diagnosticInfo'][_0x5d38('0x30')]['end_conversation'][_0x5d38('0x31')]:![];_0x44d177[_0x5d38('0xc')][_0x5d38('0x32')]=_0x44464e['queryResult'][_0x5d38('0x33')];_0x44d177[_0x5d38('0xc')][_0x5d38('0x34')]=_0x44464e['queryResult'][_0x5d38('0x35')];_0x44d177[_0x5d38('0xc')][_0x5d38('0x36')]=_0x44464e['queryResult'][_0x5d38('0x2f')]&&_0x44464e[_0x5d38('0x2e')][_0x5d38('0x2f')][_0x5d38('0x30')]?_0x44464e[_0x5d38('0x2e')][_0x5d38('0x2f')]['fields']['end_conversation']['boolValue']:![];_0x44d177[_0x5d38('0xc')][_0x5d38('0x37')]=_0x44464e[_0x5d38('0x2e')]['intent'][_0x5d38('0x38')];_0x44d177['body'][_0x5d38('0x39')]=_0x44464e['queryResult']['intent'][_0x5d38('0x3a')];_0x44d177[_0x5d38('0xc')]['DIALOGFLOWV2_ISFALLBACKINTENT']=_0x44464e[_0x5d38('0x2e')][_0x5d38('0x3b')]['isFallback'];_0x44d177[_0x5d38('0xc')][_0x5d38('0x3c')]=_0x44464e[_0x5d38('0x2e')]['languageCode'];_0x44d177[_0x5d38('0xc')][_0x5d38('0x3d')]=_0x44464e[_0x5d38('0x2e')]['queryText'];_0x44d177['body'][_0x5d38('0x3e')]=_0x44464e[_0x5d38('0x2e')][_0x5d38('0x3f')];_0x10ba96[_0x5d38('0x40')]=_0x5d38('0x2d');_0x10ba96['providerResponse']=JSON[_0x5d38('0x41')](_0x6d07df);var _0x45997f=[];for(var _0x42b8d7=0x0;_0x42b8d7<_0x6d07df[_0x5d38('0x2c')];_0x42b8d7++){var _0x275cd7=_0x6d07df[_0x42b8d7];if(_0x275cd7&&_0x275cd7[_0x5d38('0x2e')]&&_0x275cd7[_0x5d38('0x2e')]['fulfillmentText']){_0x45997f[_0x5d38('0x42')](createMessage(_0x5b0c9d,_0x528cf2,_0x10ba96,_0x275cd7['queryResult'][_0x5d38('0x43')]));}}return Promise[_0x5d38('0x44')](_0x45997f)[_0x5d38('0xf')](function(){if(_0x295641){_0x46b163[_0x5d38('0x45')]();}else{_0x46b163[_0x5d38('0x27')]();}})[_0x5d38('0x24')](function(_0x4000d4){logger['error'](_0x5d38('0x15'),_0x5b0c9d,JSON['stringify'](_0x4000d4));_0x46b163[_0x5d38('0x45')]();});}})['catch'](function(_0xb79fb){logger[_0x5d38('0x10')]('[%s][DIALOGFLOWV2]\x20%s',_0x5b0c9d,_0xb79fb['message'],_0xb79fb[_0x5d38('0x46')]);_0x46b163[_0x5d38('0x45')]();});}}catch(_0x11d3b8){logger['error'](_0x5d38('0x15'),_0x5b0c9d,JSON[_0x5d38('0x41')](_0x11d3b8));_0x46b163[_0x5d38('0x27')]();}};};
\ No newline at end of file
+var _0x5d46=['interaction','chat','account','upperFirst','AccountId','InteractionId','created','isEmpty','getMustacheRender','then','catch','stop','[%s][DIALOGFLOWV2]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!','sessionPath','message','detectIntent','dialogflowV2','diagnosticInfo','fields','end_conversation','DIALOGFLOWV2_ACTION','queryResult','action','allRequiredParamsPresent','DIALOGFLOWV2_ENDCONVERSATION','boolValue','intent','name','DIALOGFLOWV2_INTENTDISPLAYNAME','displayName','DIALOGFLOWV2_ISFALLBACKINTENT','isFallback','DIALOGFLOWV2_LANGUAGECODE','queryText','DIALOGFLOWV2_SCORE','intentDetectionConfidence','providerResponse','length','fulfillmentText','push','all','next','stack','lodash','dialogflow','md5','bluebird','../../../../config/logger','routing','./utils','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','clone','body','Message','create','info','[%s][DIALOGFLOWV2]\x20%s','error','stringify','consequence','isNil','UserId','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','contact','format','out','channel','sms','whatsapp','phone'];(function(_0x35d3a8,_0x44406a){var _0x182378=function(_0x298e0b){while(--_0x298e0b){_0x35d3a8['push'](_0x35d3a8['shift']());}};_0x182378(++_0x44406a);}(_0x5d46,0x10c));var _0x65d4=function(_0x194db3,_0x103c6c){_0x194db3=_0x194db3-0x0;var _0x4e7a5b=_0x5d46[_0x194db3];return _0x4e7a5b;};'use strict';var _=require(_0x65d4('0x0'));var dialogflow=require(_0x65d4('0x1'));var md5=require(_0x65d4('0x2'));var moment=require('moment');var Promise=require(_0x65d4('0x3'));var logger=require(_0x65d4('0x4'))(_0x65d4('0x5'));var utils=require(_0x65d4('0x6'));var rpc={'chatMessage':require(_0x65d4('0x7')),'openchannelMessage':require(_0x65d4('0x8')),'mailMessage':require(_0x65d4('0x9')),'smsMessage':require(_0x65d4('0xa')),'faxMessage':require(_0x65d4('0xb')),'whatsappMessage':require(_0x65d4('0xc'))};function createMessage(_0x1469f3,_0x49d698,_0x4ae100,_0x159c8f){return new Promise(function(_0x48c50e,_0x250640){var _0x5c5e3a=_[_0x65d4('0xd')](_0x4ae100);_0x5c5e3a[_0x65d4('0xe')]=_0x159c8f;return rpc[_0x49d698+_0x65d4('0xf')][_0x65d4('0x10')](_0x5c5e3a)['then'](function(){logger[_0x65d4('0x11')](_0x65d4('0x12'),_0x1469f3,_0x5c5e3a['body']);_0x48c50e();})['catch'](function(_0x59aac6){logger[_0x65d4('0x13')]('[%s][DIALOGFLOWV2]\x20%s',_0x1469f3,JSON[_0x65d4('0x14')](_0x59aac6));_0x250640(_0x59aac6);});});}exports[_0x65d4('0x15')]=function(_0x32a053,_0x2d531f){return function(_0x37d984){try{if(!_[_0x65d4('0x16')](this['interaction'][_0x65d4('0x17')])){logger['info'](_0x65d4('0x12'),_0x32a053,_0x65d4('0x18'));return _0x37d984['next']();}var _0x5ec7a5={'ContactId':this[_0x65d4('0x19')]['id'],'sentAt':moment()[_0x65d4('0x1a')]('YYYY-MM-DD\x20HH:mm:ss'),'direction':_0x65d4('0x1b')};if(this[_0x65d4('0x1c')]===_0x65d4('0x1d')||this[_0x65d4('0x1c')]===_0x65d4('0x1e')){_0x5ec7a5[_0x65d4('0x1f')]=this[_0x65d4('0x20')]['phone'];}var _0x107cce=this[_0x65d4('0x1c')];if(_0x107cce===_0x65d4('0x21')){_0x5ec7a5['ChatWebsiteId']=this[_0x65d4('0x22')]['id'];}else{_0x5ec7a5[_[_0x65d4('0x23')](_0x107cce)+_0x65d4('0x24')]=this[_0x65d4('0x22')]['id'];}_0x5ec7a5[_[_0x65d4('0x23')](_0x107cce)+_0x65d4('0x25')]=this[_0x65d4('0x20')]['id'];if(this[_0x65d4('0x20')][_0x65d4('0x26')]){var _0x304638=_0x2d531f[0x4];if(!_[_0x65d4('0x27')](_0x304638)){_0x5ec7a5[_0x65d4('0xe')]=utils[_0x65d4('0x28')](_0x304638,this);return rpc[_0x107cce+'Message'][_0x65d4('0x10')](_0x5ec7a5)[_0x65d4('0x29')](function(_0x3509eb){logger['info'](_0x65d4('0x12'),_0x32a053,_0x5ec7a5['body']);})[_0x65d4('0x2a')](function(_0x11c100){logger[_0x65d4('0x13')](_0x65d4('0x12'),_0x32a053,JSON[_0x65d4('0x14')](_0x11c100));})['finally'](function(){logger[_0x65d4('0x11')]('[%s][DIALOGFLOWV2]\x20Welcome\x20Message\x20has\x20been\x20sent!',_0x32a053);_0x37d984[_0x65d4('0x2b')]();});}else{logger['info'](_0x65d4('0x2c'),_0x32a053);_0x37d984[_0x65d4('0x2b')]();}}else{var _0x5a8fbf=this;var _0x7a730f=_0x2d531f[0x2]['replace'](/\\n/g,'\x0a');var _0x9d2c5e={'credentials':{'private_key':_0x7a730f,'client_email':_0x2d531f[0x1]}};var _0x15662d=new dialogflow['SessionsClient'](_0x9d2c5e);var _0x114853=_0x15662d[_0x65d4('0x2d')](_0x2d531f[0x0],md5(_0x5a8fbf[_0x65d4('0x20')]['id']));var _0x3f6542={'session':_0x114853,'queryInput':{'text':{'text':_0x5a8fbf[_0x65d4('0x2e')][_0x65d4('0xe')],'languageCode':_0x2d531f[0x3]||'en'}}};return _0x15662d[_0x65d4('0x2f')](_0x3f6542)['then'](function(_0x43988d){if(_0x43988d&&_0x43988d['length']){_0x5a8fbf[_0x65d4('0xe')][_0x65d4('0x30')]=_0x43988d;var _0x2c3576=_0x43988d[0x0];var _0x49bf6d=_0x2c3576['queryResult'][_0x65d4('0x31')]&&_0x2c3576['queryResult'][_0x65d4('0x31')][_0x65d4('0x32')]?_0x2c3576['queryResult']['diagnosticInfo'][_0x65d4('0x32')][_0x65d4('0x33')]['boolValue']:![];_0x5a8fbf[_0x65d4('0xe')][_0x65d4('0x34')]=_0x2c3576[_0x65d4('0x35')][_0x65d4('0x36')];_0x5a8fbf[_0x65d4('0xe')]['DIALOGFLOWV2_ALLREQUIREDPARAMSPRESENT']=_0x2c3576[_0x65d4('0x35')][_0x65d4('0x37')];_0x5a8fbf[_0x65d4('0xe')][_0x65d4('0x38')]=_0x2c3576[_0x65d4('0x35')][_0x65d4('0x31')]&&_0x2c3576[_0x65d4('0x35')][_0x65d4('0x31')][_0x65d4('0x32')]?_0x2c3576[_0x65d4('0x35')][_0x65d4('0x31')][_0x65d4('0x32')][_0x65d4('0x33')][_0x65d4('0x39')]:![];_0x5a8fbf['body']['DIALOGFLOWV2_INTENTNAME']=_0x2c3576[_0x65d4('0x35')][_0x65d4('0x3a')][_0x65d4('0x3b')];_0x5a8fbf[_0x65d4('0xe')][_0x65d4('0x3c')]=_0x2c3576[_0x65d4('0x35')][_0x65d4('0x3a')][_0x65d4('0x3d')];_0x5a8fbf[_0x65d4('0xe')][_0x65d4('0x3e')]=_0x2c3576[_0x65d4('0x35')][_0x65d4('0x3a')][_0x65d4('0x3f')];_0x5a8fbf[_0x65d4('0xe')][_0x65d4('0x40')]=_0x2c3576['queryResult']['languageCode'];_0x5a8fbf['body']['DIALOGFLOWV2_QUERYTEXT']=_0x2c3576[_0x65d4('0x35')][_0x65d4('0x41')];_0x5a8fbf[_0x65d4('0xe')][_0x65d4('0x42')]=_0x2c3576[_0x65d4('0x35')][_0x65d4('0x43')];_0x5ec7a5['providerName']='dialogflowV2';_0x5ec7a5[_0x65d4('0x44')]=JSON[_0x65d4('0x14')](_0x43988d);var _0x55e5e6=[];for(var _0xd55cf4=0x0;_0xd55cf4<_0x43988d[_0x65d4('0x45')];_0xd55cf4++){var _0x1d026a=_0x43988d[_0xd55cf4];if(_0x1d026a&&_0x1d026a[_0x65d4('0x35')]&&_0x1d026a[_0x65d4('0x35')][_0x65d4('0x46')]){_0x55e5e6[_0x65d4('0x47')](createMessage(_0x32a053,_0x107cce,_0x5ec7a5,_0x1d026a[_0x65d4('0x35')][_0x65d4('0x46')]));}}return Promise[_0x65d4('0x48')](_0x55e5e6)[_0x65d4('0x29')](function(){if(_0x49bf6d){_0x37d984[_0x65d4('0x49')]();}else{_0x37d984[_0x65d4('0x2b')]();}})[_0x65d4('0x2a')](function(_0x91ae26){logger['error']('[%s][DIALOGFLOWV2]\x20%s',_0x32a053,JSON['stringify'](_0x91ae26));_0x37d984['next']();});}})[_0x65d4('0x2a')](function(_0x588847){logger[_0x65d4('0x13')](_0x65d4('0x12'),_0x32a053,_0x588847['message'],_0x588847[_0x65d4('0x4a')]);_0x37d984[_0x65d4('0x49')]();});}}catch(_0x5bf7d9){logger[_0x65d4('0x13')](_0x65d4('0x12'),_0x32a053,JSON[_0x65d4('0x14')](_0x5bf7d9));_0x37d984[_0x65d4('0x2b')]();}};};
\ No newline at end of file