Built motion from commit efa66e19.|2.6.22
[motion2.git] / server / services / routing / server / applications / dialogflowV2.js
index 7ec69a4..24f6546 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x457f=['DIALOGFLOWV2_SCORE','intentDetectionConfidence','providerName','providerResponse','length','fulfillmentText','push','all','message','stack','dialogflow','md5','moment','bluebird','../../../../config/logger','routing','./utils','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','clone','body','then','[%s][DIALOGFLOWV2]\x20%s','catch','error','stringify','consequence','isNil','interaction','UserId','info','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','next','contact','YYYY-MM-DD\x20HH:mm:ss','channel','sms','phone','chat','ChatWebsiteId','account','upperFirst','AccountId','created','isEmpty','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','dialogflowV2','queryResult','diagnosticInfo','fields','end_conversation','boolValue','action','DIALOGFLOWV2_ALLREQUIREDPARAMSPRESENT','allRequiredParamsPresent','DIALOGFLOWV2_ENDCONVERSATION','intent','name','DIALOGFLOWV2_INTENTDISPLAYNAME','displayName','DIALOGFLOWV2_ISFALLBACKINTENT','isFallback','languageCode','DIALOGFLOWV2_QUERYTEXT','queryText'];(function(_0x14349b,_0x1eb24d){var _0x34f8cb=function(_0x100008){while(--_0x100008){_0x14349b['push'](_0x14349b['shift']());}};_0x34f8cb(++_0x1eb24d);}(_0x457f,0x172));var _0xf457=function(_0x1f6ff3,_0x462810){_0x1f6ff3=_0x1f6ff3-0x0;var _0x15488d=_0x457f[_0x1f6ff3];return _0x15488d;};'use strict';var _=require('lodash');var dialogflow=require(_0xf457('0x0'));var md5=require(_0xf457('0x1'));var moment=require(_0xf457('0x2'));var Promise=require(_0xf457('0x3'));var logger=require(_0xf457('0x4'))(_0xf457('0x5'));var utils=require(_0xf457('0x6'));var rpc={'chatMessage':require('../../rpc/chatMessage'),'openchannelMessage':require(_0xf457('0x7')),'mailMessage':require(_0xf457('0x8')),'smsMessage':require('../../rpc/smsMessage'),'faxMessage':require(_0xf457('0x9')),'whatsappMessage':require(_0xf457('0xa'))};function createMessage(_0x3ccfea,_0x37496e,_0x9d10f5,_0x362e88){return new Promise(function(_0x4684db,_0x585933){var _0x365d0c=_[_0xf457('0xb')](_0x9d10f5);_0x365d0c[_0xf457('0xc')]=_0x362e88;return rpc[_0x37496e+'Message']['create'](_0x365d0c)[_0xf457('0xd')](function(){logger['info'](_0xf457('0xe'),_0x3ccfea,_0x365d0c[_0xf457('0xc')]);_0x4684db();})[_0xf457('0xf')](function(_0x3f1a8d){logger[_0xf457('0x10')](_0xf457('0xe'),_0x3ccfea,JSON[_0xf457('0x11')](_0x3f1a8d));_0x585933(_0x3f1a8d);});});}exports[_0xf457('0x12')]=function(_0x307ff7,_0x19cc3d){return function(_0x14bcac){try{if(!_[_0xf457('0x13')](this[_0xf457('0x14')][_0xf457('0x15')])){logger[_0xf457('0x16')](_0xf457('0xe'),_0x307ff7,_0xf457('0x17'));return _0x14bcac[_0xf457('0x18')]();}var _0x1e6635={'ContactId':this[_0xf457('0x19')]['id'],'sentAt':moment()['format'](_0xf457('0x1a')),'direction':'out'};if(this[_0xf457('0x1b')]===_0xf457('0x1c')||this['channel']==='whatsapp'){_0x1e6635['phone']=this[_0xf457('0x14')][_0xf457('0x1d')];}var _0xdad716=this[_0xf457('0x1b')];if(_0xdad716===_0xf457('0x1e')){_0x1e6635[_0xf457('0x1f')]=this[_0xf457('0x20')]['id'];}else{_0x1e6635[_[_0xf457('0x21')](_0xdad716)+_0xf457('0x22')]=this[_0xf457('0x20')]['id'];}_0x1e6635[_[_0xf457('0x21')](_0xdad716)+'InteractionId']=this[_0xf457('0x14')]['id'];if(this[_0xf457('0x14')][_0xf457('0x23')]){var _0x11bd9a=_0x19cc3d[0x4];if(!_[_0xf457('0x24')](_0x11bd9a)){_0x1e6635[_0xf457('0xc')]=utils['getMustacheRender'](_0x11bd9a,this);return rpc[_0xdad716+'Message']['create'](_0x1e6635)[_0xf457('0xd')](function(_0xdcff4e){logger['info']('[%s][DIALOGFLOWV2]\x20%s',_0x307ff7,_0x1e6635['body']);})[_0xf457('0xf')](function(_0x174610){logger['error'](_0xf457('0xe'),_0x307ff7,JSON[_0xf457('0x11')](_0x174610));})[_0xf457('0x25')](function(){logger[_0xf457('0x16')](_0xf457('0x26'),_0x307ff7);_0x14bcac[_0xf457('0x27')]();});}else{logger[_0xf457('0x16')](_0xf457('0x28'),_0x307ff7);_0x14bcac['stop']();}}else{var _0x211627=this;var _0x201654=_0x19cc3d[0x2][_0xf457('0x29')](/\\n/g,'\x0a');var _0x5c88a9={'credentials':{'private_key':_0x201654,'client_email':_0x19cc3d[0x1]}};var _0x13941b=new dialogflow['SessionsClient'](_0x5c88a9);var _0x3c58bb=_0x13941b[_0xf457('0x2a')](_0x19cc3d[0x0],md5(_0x211627[_0xf457('0x14')]['id']));var _0x438f22={'session':_0x3c58bb,'queryInput':{'text':{'text':_0x211627['message'][_0xf457('0xc')],'languageCode':_0x19cc3d[0x3]||'en'}}};return _0x13941b['detectIntent'](_0x438f22)[_0xf457('0xd')](function(_0x38ab1c){if(_0x38ab1c&&_0x38ab1c['length']){_0x211627[_0xf457('0xc')][_0xf457('0x2b')]=_0x38ab1c;var _0x312ff5=_0x38ab1c[0x0];var _0x3bc6a8=_0x312ff5[_0xf457('0x2c')][_0xf457('0x2d')]&&_0x312ff5[_0xf457('0x2c')][_0xf457('0x2d')]['fields']?_0x312ff5[_0xf457('0x2c')]['diagnosticInfo'][_0xf457('0x2e')][_0xf457('0x2f')][_0xf457('0x30')]:![];_0x211627['body']['DIALOGFLOWV2_ACTION']=_0x312ff5['queryResult'][_0xf457('0x31')];_0x211627[_0xf457('0xc')][_0xf457('0x32')]=_0x312ff5[_0xf457('0x2c')][_0xf457('0x33')];_0x211627[_0xf457('0xc')][_0xf457('0x34')]=_0x312ff5[_0xf457('0x2c')][_0xf457('0x2d')]&&_0x312ff5[_0xf457('0x2c')][_0xf457('0x2d')][_0xf457('0x2e')]?_0x312ff5[_0xf457('0x2c')][_0xf457('0x2d')][_0xf457('0x2e')][_0xf457('0x2f')][_0xf457('0x30')]:![];_0x211627[_0xf457('0xc')]['DIALOGFLOWV2_INTENTNAME']=_0x312ff5[_0xf457('0x2c')][_0xf457('0x35')][_0xf457('0x36')];_0x211627['body'][_0xf457('0x37')]=_0x312ff5['queryResult'][_0xf457('0x35')][_0xf457('0x38')];_0x211627[_0xf457('0xc')][_0xf457('0x39')]=_0x312ff5['queryResult'][_0xf457('0x35')][_0xf457('0x3a')];_0x211627[_0xf457('0xc')]['DIALOGFLOWV2_LANGUAGECODE']=_0x312ff5[_0xf457('0x2c')][_0xf457('0x3b')];_0x211627[_0xf457('0xc')][_0xf457('0x3c')]=_0x312ff5[_0xf457('0x2c')][_0xf457('0x3d')];_0x211627[_0xf457('0xc')][_0xf457('0x3e')]=_0x312ff5[_0xf457('0x2c')][_0xf457('0x3f')];_0x1e6635[_0xf457('0x40')]=_0xf457('0x2b');_0x1e6635[_0xf457('0x41')]=JSON['stringify'](_0x38ab1c);var _0x4f33a4=[];for(var _0x26306d=0x0;_0x26306d<_0x38ab1c[_0xf457('0x42')];_0x26306d++){var _0x51339a=_0x38ab1c[_0x26306d];if(_0x51339a&&_0x51339a[_0xf457('0x2c')]&&_0x51339a['queryResult'][_0xf457('0x43')]){_0x4f33a4[_0xf457('0x44')](createMessage(_0x307ff7,_0xdad716,_0x1e6635,_0x51339a[_0xf457('0x2c')][_0xf457('0x43')]));}}return Promise[_0xf457('0x45')](_0x4f33a4)['then'](function(){if(_0x3bc6a8){_0x14bcac[_0xf457('0x18')]();}else{_0x14bcac['stop']();}})[_0xf457('0xf')](function(_0x1192e2){logger[_0xf457('0x10')](_0xf457('0xe'),_0x307ff7,JSON['stringify'](_0x1192e2));_0x14bcac['next']();});}})[_0xf457('0xf')](function(_0x3dc3ca){logger[_0xf457('0x10')](_0xf457('0xe'),_0x307ff7,_0x3dc3ca[_0xf457('0x46')],_0x3dc3ca[_0xf457('0x47')]);_0x14bcac['next']();});}}catch(_0x1a3c61){logger['error'](_0xf457('0xe'),_0x307ff7,JSON[_0xf457('0x11')](_0x1a3c61));_0x14bcac['stop']();}};};
\ No newline at end of file
+var _0xc08e=['finally','[%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','detectIntent','then','length','queryResult','diagnosticInfo','end_conversation','DIALOGFLOWV2_ACTION','action','DIALOGFLOWV2_ALLREQUIREDPARAMSPRESENT','allRequiredParamsPresent','DIALOGFLOWV2_ENDCONVERSATION','fields','boolValue','DIALOGFLOWV2_INTENTNAME','name','DIALOGFLOWV2_INTENTDISPLAYNAME','intent','DIALOGFLOWV2_ISFALLBACKINTENT','isFallback','DIALOGFLOWV2_LANGUAGECODE','languageCode','queryText','DIALOGFLOWV2_SCORE','intentDetectionConfidence','dialogflowV2','providerResponse','fulfillmentText','push','all','lodash','dialogflow','md5','bluebird','routing','./utils','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','clone','body','Message','create','info','[%s][DIALOGFLOWV2]\x20%s','catch','stringify','isNil','interaction','UserId','next','contact','format','YYYY-MM-DD\x20HH:mm:ss','channel','sms','phone','chat','ChatWebsiteId','upperFirst','AccountId','account','InteractionId','created','isEmpty','error'];(function(_0x1eabda,_0x5164e5){var _0x101654=function(_0x2a3a9e){while(--_0x2a3a9e){_0x1eabda['push'](_0x1eabda['shift']());}};_0x101654(++_0x5164e5);}(_0xc08e,0xb4));var _0xec08=function(_0x3d05c2,_0x2abc6e){_0x3d05c2=_0x3d05c2-0x0;var _0x2d98e4=_0xc08e[_0x3d05c2];return _0x2d98e4;};'use strict';var _=require(_0xec08('0x0'));var dialogflow=require(_0xec08('0x1'));var md5=require(_0xec08('0x2'));var moment=require('moment');var Promise=require(_0xec08('0x3'));var logger=require('../../../../config/logger')(_0xec08('0x4'));var utils=require(_0xec08('0x5'));var rpc={'chatMessage':require(_0xec08('0x6')),'openchannelMessage':require(_0xec08('0x7')),'mailMessage':require(_0xec08('0x8')),'smsMessage':require('../../rpc/smsMessage'),'faxMessage':require('../../rpc/faxMessage'),'whatsappMessage':require('../../rpc/whatsappMessage')};function createMessage(_0x118d80,_0x5603b1,_0x1ee390,_0x23d8d2){return new Promise(function(_0x29ce4e,_0x1cdc31){var _0x566b26=_[_0xec08('0x9')](_0x1ee390);_0x566b26[_0xec08('0xa')]=_0x23d8d2;return rpc[_0x5603b1+_0xec08('0xb')][_0xec08('0xc')](_0x566b26)['then'](function(){logger[_0xec08('0xd')](_0xec08('0xe'),_0x118d80,_0x566b26['body']);_0x29ce4e();})[_0xec08('0xf')](function(_0x474d58){logger['error']('[%s][DIALOGFLOWV2]\x20%s',_0x118d80,JSON[_0xec08('0x10')](_0x474d58));_0x1cdc31(_0x474d58);});});}exports['consequence']=function(_0x4361ee,_0xbd3337){return function(_0x4e18c1){try{if(!_[_0xec08('0x11')](this[_0xec08('0x12')][_0xec08('0x13')])){logger[_0xec08('0xd')](_0xec08('0xe'),_0x4361ee,'Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.');return _0x4e18c1[_0xec08('0x14')]();}var _0x5cbc55={'ContactId':this[_0xec08('0x15')]['id'],'sentAt':moment()[_0xec08('0x16')](_0xec08('0x17')),'direction':'out'};if(this[_0xec08('0x18')]===_0xec08('0x19')||this[_0xec08('0x18')]==='whatsapp'){_0x5cbc55[_0xec08('0x1a')]=this['interaction']['phone'];}var _0x51174f=this['channel'];if(_0x51174f===_0xec08('0x1b')){_0x5cbc55[_0xec08('0x1c')]=this['account']['id'];}else{_0x5cbc55[_[_0xec08('0x1d')](_0x51174f)+_0xec08('0x1e')]=this[_0xec08('0x1f')]['id'];}_0x5cbc55[_['upperFirst'](_0x51174f)+_0xec08('0x20')]=this[_0xec08('0x12')]['id'];if(this[_0xec08('0x12')][_0xec08('0x21')]){var _0x3fea59=_0xbd3337[0x4];if(!_[_0xec08('0x22')](_0x3fea59)){_0x5cbc55[_0xec08('0xa')]=utils['getMustacheRender'](_0x3fea59,this);return rpc[_0x51174f+_0xec08('0xb')]['create'](_0x5cbc55)['then'](function(_0x296283){logger[_0xec08('0xd')](_0xec08('0xe'),_0x4361ee,_0x5cbc55[_0xec08('0xa')]);})['catch'](function(_0x24fbe9){logger[_0xec08('0x23')](_0xec08('0xe'),_0x4361ee,JSON[_0xec08('0x10')](_0x24fbe9));})[_0xec08('0x24')](function(){logger[_0xec08('0xd')](_0xec08('0x25'),_0x4361ee);_0x4e18c1[_0xec08('0x26')]();});}else{logger['info'](_0xec08('0x27'),_0x4361ee);_0x4e18c1[_0xec08('0x26')]();}}else{var _0x4562e2=this;var _0x1adb93=_0xbd3337[0x2][_0xec08('0x28')](/\\n/g,'\x0a');var _0x2d5ef5={'credentials':{'private_key':_0x1adb93,'client_email':_0xbd3337[0x1]}};var _0x93a4bf=new dialogflow[(_0xec08('0x29'))](_0x2d5ef5);var _0x23eb81=_0x93a4bf[_0xec08('0x2a')](_0xbd3337[0x0],md5(_0x4562e2[_0xec08('0x12')]['id']));var _0x570ad3={'session':_0x23eb81,'queryInput':{'text':{'text':_0x4562e2['message']['body'],'languageCode':_0xbd3337[0x3]||'en'}}};return _0x93a4bf[_0xec08('0x2b')](_0x570ad3)[_0xec08('0x2c')](function(_0x292387){if(_0x292387&&_0x292387[_0xec08('0x2d')]){_0x4562e2[_0xec08('0xa')]['dialogflowV2']=_0x292387;var _0x2e1b2b=_0x292387[0x0];var _0x4f51ed=_0x2e1b2b[_0xec08('0x2e')][_0xec08('0x2f')]&&_0x2e1b2b[_0xec08('0x2e')]['diagnosticInfo']['fields']?_0x2e1b2b[_0xec08('0x2e')][_0xec08('0x2f')]['fields'][_0xec08('0x30')]['boolValue']:![];_0x4562e2[_0xec08('0xa')][_0xec08('0x31')]=_0x2e1b2b['queryResult'][_0xec08('0x32')];_0x4562e2[_0xec08('0xa')][_0xec08('0x33')]=_0x2e1b2b[_0xec08('0x2e')][_0xec08('0x34')];_0x4562e2[_0xec08('0xa')][_0xec08('0x35')]=_0x2e1b2b['queryResult'][_0xec08('0x2f')]&&_0x2e1b2b[_0xec08('0x2e')][_0xec08('0x2f')]['fields']?_0x2e1b2b['queryResult']['diagnosticInfo'][_0xec08('0x36')]['end_conversation'][_0xec08('0x37')]:![];_0x4562e2['body'][_0xec08('0x38')]=_0x2e1b2b[_0xec08('0x2e')]['intent'][_0xec08('0x39')];_0x4562e2[_0xec08('0xa')][_0xec08('0x3a')]=_0x2e1b2b['queryResult'][_0xec08('0x3b')]['displayName'];_0x4562e2[_0xec08('0xa')][_0xec08('0x3c')]=_0x2e1b2b[_0xec08('0x2e')][_0xec08('0x3b')][_0xec08('0x3d')];_0x4562e2[_0xec08('0xa')][_0xec08('0x3e')]=_0x2e1b2b['queryResult'][_0xec08('0x3f')];_0x4562e2['body']['DIALOGFLOWV2_QUERYTEXT']=_0x2e1b2b[_0xec08('0x2e')][_0xec08('0x40')];_0x4562e2['body'][_0xec08('0x41')]=_0x2e1b2b['queryResult'][_0xec08('0x42')];_0x5cbc55['providerName']=_0xec08('0x43');_0x5cbc55[_0xec08('0x44')]=JSON[_0xec08('0x10')](_0x292387);var _0x103941=[];for(var _0x4ca712=0x0;_0x4ca712<_0x292387[_0xec08('0x2d')];_0x4ca712++){var _0x62849b=_0x292387[_0x4ca712];if(_0x62849b&&_0x62849b[_0xec08('0x2e')]&&_0x62849b[_0xec08('0x2e')][_0xec08('0x45')]){_0x103941[_0xec08('0x46')](createMessage(_0x4361ee,_0x51174f,_0x5cbc55,_0x62849b[_0xec08('0x2e')][_0xec08('0x45')]));}}return Promise[_0xec08('0x47')](_0x103941)[_0xec08('0x2c')](function(){if(_0x4f51ed){_0x4e18c1[_0xec08('0x14')]();}else{_0x4e18c1['stop']();}})[_0xec08('0xf')](function(_0x3496a8){logger[_0xec08('0x23')](_0xec08('0xe'),_0x4361ee,JSON[_0xec08('0x10')](_0x3496a8));_0x4e18c1[_0xec08('0x14')]();});}})['catch'](function(_0x56f1b4){logger[_0xec08('0x23')](_0xec08('0xe'),_0x4361ee,_0x56f1b4['message'],_0x56f1b4['stack']);_0x4e18c1[_0xec08('0x14')]();});}}catch(_0x208efb){logger[_0xec08('0x23')](_0xec08('0xe'),_0x4361ee,JSON[_0xec08('0x10')](_0x208efb));_0x4e18c1[_0xec08('0x26')]();}};};
\ No newline at end of file