Built motion from commit 351e7f9c.|2.6.31
[motion2.git] / server / services / routing / server / applications / dialogflowV2.js
index a4aab6e..320fa53 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x80b2=['intentDetectionConfidence','providerName','length','fulfillmentText','push','all','stringify','lodash','dialogflow','md5','bluebird','../../../../config/logger','routing','./utils','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','clone','Message','create','then','info','body','error','[%s][DIALOGFLOWV2]\x20%s','consequence','isNil','interaction','UserId','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','next','contact','format','out','channel','sms','whatsapp','phone','chat','ChatWebsiteId','account','upperFirst','AccountId','InteractionId','isEmpty','getMustacheRender','catch','finally','[%s][DIALOGFLOWV2]\x20Welcome\x20Message\x20has\x20been\x20sent!','stop','replace','sessionPath','message','detectIntent','dialogflowV2','queryResult','diagnosticInfo','fields','end_conversation','boolValue','DIALOGFLOWV2_ACTION','action','DIALOGFLOWV2_ENDCONVERSATION','intent','name','DIALOGFLOWV2_INTENTDISPLAYNAME','DIALOGFLOWV2_ISFALLBACKINTENT','isFallback','DIALOGFLOWV2_LANGUAGECODE','DIALOGFLOWV2_QUERYTEXT','queryText'];(function(_0x5e133c,_0x19a379){var _0x372b5c=function(_0x51e069){while(--_0x51e069){_0x5e133c['push'](_0x5e133c['shift']());}};_0x372b5c(++_0x19a379);}(_0x80b2,0x99));var _0x280b=function(_0x38d903,_0x23c79b){_0x38d903=_0x38d903-0x0;var _0x29e46b=_0x80b2[_0x38d903];return _0x29e46b;};'use strict';var _=require(_0x280b('0x0'));var dialogflow=require(_0x280b('0x1'));var md5=require(_0x280b('0x2'));var moment=require('moment');var Promise=require(_0x280b('0x3'));var logger=require(_0x280b('0x4'))(_0x280b('0x5'));var utils=require(_0x280b('0x6'));var rpc={'chatMessage':require('../../rpc/chatMessage'),'openchannelMessage':require(_0x280b('0x7')),'mailMessage':require(_0x280b('0x8')),'smsMessage':require(_0x280b('0x9')),'faxMessage':require(_0x280b('0xa')),'whatsappMessage':require(_0x280b('0xb'))};function createMessage(_0x299b17,_0x5786af,_0x38a6e4,_0x3f8dab){return new Promise(function(_0x32d9a6,_0x120a48){var _0x7d4fe9=_[_0x280b('0xc')](_0x38a6e4);_0x7d4fe9['body']=_0x3f8dab;return rpc[_0x5786af+_0x280b('0xd')][_0x280b('0xe')](_0x7d4fe9)[_0x280b('0xf')](function(){logger[_0x280b('0x10')]('[%s][DIALOGFLOWV2]\x20%s',_0x299b17,_0x7d4fe9[_0x280b('0x11')]);_0x32d9a6();})['catch'](function(_0xd070c0){logger[_0x280b('0x12')](_0x280b('0x13'),_0x299b17,JSON['stringify'](_0xd070c0));_0x120a48(_0xd070c0);});});}exports[_0x280b('0x14')]=function(_0x38d9e4,_0x20b054){return function(_0xaec8d){try{if(!_[_0x280b('0x15')](this[_0x280b('0x16')][_0x280b('0x17')])){logger['info'](_0x280b('0x13'),_0x38d9e4,_0x280b('0x18'));return _0xaec8d[_0x280b('0x19')]();}var _0x412553={'ContactId':this[_0x280b('0x1a')]['id'],'sentAt':moment()[_0x280b('0x1b')]('YYYY-MM-DD\x20HH:mm:ss'),'direction':_0x280b('0x1c')};if(this[_0x280b('0x1d')]===_0x280b('0x1e')||this[_0x280b('0x1d')]===_0x280b('0x1f')){_0x412553['phone']=this[_0x280b('0x16')][_0x280b('0x20')];}var _0x358fcc=this[_0x280b('0x1d')];if(_0x358fcc===_0x280b('0x21')){_0x412553[_0x280b('0x22')]=this[_0x280b('0x23')]['id'];}else{_0x412553[_[_0x280b('0x24')](_0x358fcc)+_0x280b('0x25')]=this[_0x280b('0x23')]['id'];}_0x412553[_['upperFirst'](_0x358fcc)+_0x280b('0x26')]=this[_0x280b('0x16')]['id'];if(this[_0x280b('0x16')]['created']){var _0xd8c280=_0x20b054[0x4];if(!_[_0x280b('0x27')](_0xd8c280)){_0x412553[_0x280b('0x11')]=utils[_0x280b('0x28')](_0xd8c280,this);return rpc[_0x358fcc+'Message'][_0x280b('0xe')](_0x412553)[_0x280b('0xf')](function(_0xaac709){logger[_0x280b('0x10')](_0x280b('0x13'),_0x38d9e4,_0x412553[_0x280b('0x11')]);})[_0x280b('0x29')](function(_0x1ce3d6){logger[_0x280b('0x12')](_0x280b('0x13'),_0x38d9e4,JSON['stringify'](_0x1ce3d6));})[_0x280b('0x2a')](function(){logger[_0x280b('0x10')](_0x280b('0x2b'),_0x38d9e4);_0xaec8d[_0x280b('0x2c')]();});}else{logger['info']('[%s][DIALOGFLOWV2]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!',_0x38d9e4);_0xaec8d[_0x280b('0x2c')]();}}else{var _0x6b73e2=this;var _0x462df8=_0x20b054[0x2][_0x280b('0x2d')](/\\n/g,'\x0a');var _0x197df9={'credentials':{'private_key':_0x462df8,'client_email':_0x20b054[0x1]}};var _0x49952c=new dialogflow['SessionsClient'](_0x197df9);var _0x2972dd=_0x49952c[_0x280b('0x2e')](_0x20b054[0x0],md5(_0x6b73e2[_0x280b('0x16')]['id']));var _0x2b25a6={'session':_0x2972dd,'queryInput':{'text':{'text':_0x6b73e2[_0x280b('0x2f')][_0x280b('0x11')],'languageCode':_0x20b054[0x3]||'en'}}};return _0x49952c[_0x280b('0x30')](_0x2b25a6)[_0x280b('0xf')](function(_0x4d0fcd){if(_0x4d0fcd&&_0x4d0fcd['length']){_0x6b73e2[_0x280b('0x11')][_0x280b('0x31')]=_0x4d0fcd;var _0x320292=_0x4d0fcd[0x0];var _0x1acf1f=_0x320292[_0x280b('0x32')]['diagnosticInfo']&&_0x320292[_0x280b('0x32')][_0x280b('0x33')][_0x280b('0x34')]?_0x320292['queryResult'][_0x280b('0x33')][_0x280b('0x34')][_0x280b('0x35')][_0x280b('0x36')]:![];_0x6b73e2['body'][_0x280b('0x37')]=_0x320292[_0x280b('0x32')][_0x280b('0x38')];_0x6b73e2[_0x280b('0x11')]['DIALOGFLOWV2_ALLREQUIREDPARAMSPRESENT']=_0x320292['queryResult']['allRequiredParamsPresent'];_0x6b73e2[_0x280b('0x11')][_0x280b('0x39')]=_0x320292[_0x280b('0x32')][_0x280b('0x33')]&&_0x320292[_0x280b('0x32')][_0x280b('0x33')][_0x280b('0x34')]?_0x320292[_0x280b('0x32')][_0x280b('0x33')][_0x280b('0x34')][_0x280b('0x35')][_0x280b('0x36')]:![];_0x6b73e2[_0x280b('0x11')]['DIALOGFLOWV2_INTENTNAME']=_0x320292[_0x280b('0x32')][_0x280b('0x3a')][_0x280b('0x3b')];_0x6b73e2[_0x280b('0x11')][_0x280b('0x3c')]=_0x320292['queryResult']['intent']['displayName'];_0x6b73e2['body'][_0x280b('0x3d')]=_0x320292['queryResult']['intent'][_0x280b('0x3e')];_0x6b73e2[_0x280b('0x11')][_0x280b('0x3f')]=_0x320292[_0x280b('0x32')]['languageCode'];_0x6b73e2[_0x280b('0x11')][_0x280b('0x40')]=_0x320292[_0x280b('0x32')][_0x280b('0x41')];_0x6b73e2['body']['DIALOGFLOWV2_SCORE']=_0x320292[_0x280b('0x32')][_0x280b('0x42')];_0x412553[_0x280b('0x43')]=_0x280b('0x31');_0x412553['providerResponse']=JSON['stringify'](_0x4d0fcd);var _0x22f7f1=[];for(var _0x3a3393=0x0;_0x3a3393<_0x4d0fcd[_0x280b('0x44')];_0x3a3393++){var _0x19d454=_0x4d0fcd[_0x3a3393];if(_0x19d454&&_0x19d454[_0x280b('0x32')]&&_0x19d454[_0x280b('0x32')][_0x280b('0x45')]){_0x22f7f1[_0x280b('0x46')](createMessage(_0x38d9e4,_0x358fcc,_0x412553,_0x19d454[_0x280b('0x32')][_0x280b('0x45')]));}}return Promise[_0x280b('0x47')](_0x22f7f1)[_0x280b('0xf')](function(){if(_0x1acf1f){_0xaec8d[_0x280b('0x19')]();}else{_0xaec8d[_0x280b('0x2c')]();}})[_0x280b('0x29')](function(_0x27c5e5){logger['error'](_0x280b('0x13'),_0x38d9e4,JSON[_0x280b('0x48')](_0x27c5e5));_0xaec8d[_0x280b('0x19')]();});}})[_0x280b('0x29')](function(_0x29aeaa){logger[_0x280b('0x12')](_0x280b('0x13'),_0x38d9e4,_0x29aeaa[_0x280b('0x2f')],_0x29aeaa['stack']);_0xaec8d[_0x280b('0x19')]();});}}catch(_0x1cf398){logger[_0x280b('0x12')]('[%s][DIALOGFLOWV2]\x20%s',_0x38d9e4,JSON[_0x280b('0x48')](_0x1cf398));_0xaec8d[_0x280b('0x2c')]();}};};
\ No newline at end of file
+var _0xf6db=['info','catch','error','[%s][DIALOGFLOWV2]\x20%s','consequence','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','chat','ChatWebsiteId','upperFirst','account','isEmpty','body','getMustacheRender','create','stringify','finally','[%s][DIALOGFLOWV2]\x20Welcome\x20Message\x20has\x20been\x20sent!','stop','replace','SessionsClient','length','dialogflowV2','queryResult','diagnosticInfo','fields','end_conversation','boolValue','DIALOGFLOWV2_ALLREQUIREDPARAMSPRESENT','allRequiredParamsPresent','DIALOGFLOWV2_ENDCONVERSATION','DIALOGFLOWV2_INTENTNAME','intent','DIALOGFLOWV2_INTENTDISPLAYNAME','displayName','DIALOGFLOWV2_ISFALLBACKINTENT','isFallback','DIALOGFLOWV2_LANGUAGECODE','languageCode','DIALOGFLOWV2_QUERYTEXT','intentDetectionConfidence','providerName','providerResponse','fulfillmentText','push','all','message','stack','lodash','md5','moment','bluebird','../../../../config/logger','routing','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','Message','then'];(function(_0x4d3029,_0x1a4062){var _0x3f555e=function(_0x439da9){while(--_0x439da9){_0x4d3029['push'](_0x4d3029['shift']());}};_0x3f555e(++_0x1a4062);}(_0xf6db,0xcb));var _0xbf6d=function(_0x5c9865,_0x1a299a){_0x5c9865=_0x5c9865-0x0;var _0x54c22b=_0xf6db[_0x5c9865];return _0x54c22b;};'use strict';var _=require(_0xbf6d('0x0'));var dialogflow=require('dialogflow');var md5=require(_0xbf6d('0x1'));var moment=require(_0xbf6d('0x2'));var Promise=require(_0xbf6d('0x3'));var logger=require(_0xbf6d('0x4'))(_0xbf6d('0x5'));var utils=require('./utils');var rpc={'chatMessage':require(_0xbf6d('0x6')),'openchannelMessage':require(_0xbf6d('0x7')),'mailMessage':require('../../rpc/mailMessage'),'smsMessage':require(_0xbf6d('0x8')),'faxMessage':require(_0xbf6d('0x9')),'whatsappMessage':require(_0xbf6d('0xa'))};function createMessage(_0x4d3440,_0x46599c,_0x54190a,_0x263bb1){return new Promise(function(_0x8fd858,_0x115ba6){var _0x3249ed=_['clone'](_0x54190a);_0x3249ed['body']=_0x263bb1;return rpc[_0x46599c+_0xbf6d('0xb')]['create'](_0x3249ed)[_0xbf6d('0xc')](function(){logger[_0xbf6d('0xd')]('[%s][DIALOGFLOWV2]\x20%s',_0x4d3440,_0x3249ed['body']);_0x8fd858();})[_0xbf6d('0xe')](function(_0x50f40e){logger[_0xbf6d('0xf')](_0xbf6d('0x10'),_0x4d3440,JSON['stringify'](_0x50f40e));_0x115ba6(_0x50f40e);});});}exports[_0xbf6d('0x11')]=function(_0x3ee88d,_0x4945da){return function(_0x37f4bc){try{if(!_[_0xbf6d('0x12')](this[_0xbf6d('0x13')][_0xbf6d('0x14')])){logger[_0xbf6d('0xd')](_0xbf6d('0x10'),_0x3ee88d,_0xbf6d('0x15'));return _0x37f4bc[_0xbf6d('0x16')]();}var _0x3ad2bb={'ContactId':this[_0xbf6d('0x17')]['id'],'sentAt':moment()[_0xbf6d('0x18')](_0xbf6d('0x19')),'direction':_0xbf6d('0x1a')};if(this[_0xbf6d('0x1b')]===_0xbf6d('0x1c')||this[_0xbf6d('0x1b')]===_0xbf6d('0x1d')){_0x3ad2bb['phone']=this[_0xbf6d('0x13')][_0xbf6d('0x1e')];}var _0x5ccb72=this['channel'];if(_0x5ccb72===_0xbf6d('0x1f')){_0x3ad2bb[_0xbf6d('0x20')]=this['account']['id'];}else{_0x3ad2bb[_[_0xbf6d('0x21')](_0x5ccb72)+'AccountId']=this[_0xbf6d('0x22')]['id'];}_0x3ad2bb[_[_0xbf6d('0x21')](_0x5ccb72)+'InteractionId']=this['interaction']['id'];if(this[_0xbf6d('0x13')]['created']){var _0x391ba7=_0x4945da[0x4];if(!_[_0xbf6d('0x23')](_0x391ba7)){_0x3ad2bb[_0xbf6d('0x24')]=utils[_0xbf6d('0x25')](_0x391ba7,this);return rpc[_0x5ccb72+_0xbf6d('0xb')][_0xbf6d('0x26')](_0x3ad2bb)['then'](function(_0x1cd7ab){logger['info'](_0xbf6d('0x10'),_0x3ee88d,_0x3ad2bb[_0xbf6d('0x24')]);})[_0xbf6d('0xe')](function(_0x690f88){logger[_0xbf6d('0xf')](_0xbf6d('0x10'),_0x3ee88d,JSON[_0xbf6d('0x27')](_0x690f88));})[_0xbf6d('0x28')](function(){logger['info'](_0xbf6d('0x29'),_0x3ee88d);_0x37f4bc[_0xbf6d('0x2a')]();});}else{logger[_0xbf6d('0xd')]('[%s][DIALOGFLOWV2]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!',_0x3ee88d);_0x37f4bc['stop']();}}else{var _0x33fd16=this;var _0x2651ab=_0x4945da[0x2][_0xbf6d('0x2b')](/\\n/g,'\x0a');var _0x42aca8={'credentials':{'private_key':_0x2651ab,'client_email':_0x4945da[0x1]}};var _0x21dec8=new dialogflow[(_0xbf6d('0x2c'))](_0x42aca8);var _0xacc04a=_0x21dec8['sessionPath'](_0x4945da[0x0],md5(_0x33fd16[_0xbf6d('0x13')]['id']));var _0xde710c={'session':_0xacc04a,'queryInput':{'text':{'text':_0x33fd16['message'][_0xbf6d('0x24')],'languageCode':_0x4945da[0x3]||'en'}}};return _0x21dec8['detectIntent'](_0xde710c)[_0xbf6d('0xc')](function(_0x236a0c){if(_0x236a0c&&_0x236a0c[_0xbf6d('0x2d')]){_0x33fd16[_0xbf6d('0x24')][_0xbf6d('0x2e')]=_0x236a0c;var _0x26bcd1=_0x236a0c[0x0];var _0x433788=_0x26bcd1[_0xbf6d('0x2f')][_0xbf6d('0x30')]&&_0x26bcd1['queryResult'][_0xbf6d('0x30')]['fields']?_0x26bcd1[_0xbf6d('0x2f')][_0xbf6d('0x30')][_0xbf6d('0x31')][_0xbf6d('0x32')][_0xbf6d('0x33')]:![];_0x33fd16[_0xbf6d('0x24')]['DIALOGFLOWV2_ACTION']=_0x26bcd1['queryResult']['action'];_0x33fd16[_0xbf6d('0x24')][_0xbf6d('0x34')]=_0x26bcd1[_0xbf6d('0x2f')][_0xbf6d('0x35')];_0x33fd16[_0xbf6d('0x24')][_0xbf6d('0x36')]=_0x26bcd1[_0xbf6d('0x2f')][_0xbf6d('0x30')]&&_0x26bcd1[_0xbf6d('0x2f')][_0xbf6d('0x30')][_0xbf6d('0x31')]?_0x26bcd1[_0xbf6d('0x2f')][_0xbf6d('0x30')][_0xbf6d('0x31')][_0xbf6d('0x32')][_0xbf6d('0x33')]:![];_0x33fd16[_0xbf6d('0x24')][_0xbf6d('0x37')]=_0x26bcd1['queryResult'][_0xbf6d('0x38')]['name'];_0x33fd16[_0xbf6d('0x24')][_0xbf6d('0x39')]=_0x26bcd1[_0xbf6d('0x2f')]['intent'][_0xbf6d('0x3a')];_0x33fd16[_0xbf6d('0x24')][_0xbf6d('0x3b')]=_0x26bcd1['queryResult'][_0xbf6d('0x38')][_0xbf6d('0x3c')];_0x33fd16[_0xbf6d('0x24')][_0xbf6d('0x3d')]=_0x26bcd1[_0xbf6d('0x2f')][_0xbf6d('0x3e')];_0x33fd16['body'][_0xbf6d('0x3f')]=_0x26bcd1['queryResult']['queryText'];_0x33fd16[_0xbf6d('0x24')]['DIALOGFLOWV2_SCORE']=_0x26bcd1[_0xbf6d('0x2f')][_0xbf6d('0x40')];_0x3ad2bb[_0xbf6d('0x41')]=_0xbf6d('0x2e');_0x3ad2bb[_0xbf6d('0x42')]=JSON[_0xbf6d('0x27')](_0x236a0c);var _0x53d83e=[];for(var _0x11b3dd=0x0;_0x11b3dd<_0x236a0c['length'];_0x11b3dd++){var _0x599968=_0x236a0c[_0x11b3dd];if(_0x599968&&_0x599968[_0xbf6d('0x2f')]&&_0x599968[_0xbf6d('0x2f')][_0xbf6d('0x43')]){_0x53d83e[_0xbf6d('0x44')](createMessage(_0x3ee88d,_0x5ccb72,_0x3ad2bb,_0x599968[_0xbf6d('0x2f')][_0xbf6d('0x43')]));}}return Promise[_0xbf6d('0x45')](_0x53d83e)[_0xbf6d('0xc')](function(){if(_0x433788){_0x37f4bc['next']();}else{_0x37f4bc['stop']();}})['catch'](function(_0x1e5ae3){logger['error'](_0xbf6d('0x10'),_0x3ee88d,JSON[_0xbf6d('0x27')](_0x1e5ae3));_0x37f4bc['next']();});}})[_0xbf6d('0xe')](function(_0x3f42c4){logger['error'](_0xbf6d('0x10'),_0x3ee88d,_0x3f42c4[_0xbf6d('0x46')],_0x3f42c4[_0xbf6d('0x47')]);_0x37f4bc[_0xbf6d('0x16')]();});}}catch(_0x1ba547){logger[_0xbf6d('0xf')](_0xbf6d('0x10'),_0x3ee88d,JSON[_0xbf6d('0x27')](_0x1ba547));_0x37f4bc['stop']();}};};
\ No newline at end of file