Built motion from commit da617fac.|2.6.6
[motion2.git] / server / services / routing / server / applications / amazonlex.js
index 1013da6..1f9ee64 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x7a75=['error','stringify','stop','LexRuntime','$LATEST','message','toString','postText','amazonlex','providerResponse','dialogState','Failed','lodash','moment','./utils','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','consequence','isNil','[%s][AMAZONLEX]\x20%s','next','format','YYYY-MM-DD\x20HH:mm:ss','out','sms','channel','phone','interaction','ChatWebsiteId','account','upperFirst','InteractionId','created','isEmpty','body','create','then','info','catch'];(function(_0x3d5b93,_0x597bcf){var _0x68f72=function(_0x5ae851){while(--_0x5ae851){_0x3d5b93['push'](_0x3d5b93['shift']());}};_0x68f72(++_0x597bcf);}(_0x7a75,0x18f));var _0x57a7=function(_0x3bfe60,_0x35abf6){_0x3bfe60=_0x3bfe60-0x0;var _0x369bac=_0x7a75[_0x3bfe60];return _0x369bac;};'use strict';var _=require(_0x57a7('0x0'));var moment=require(_0x57a7('0x1'));var AWS=require('aws-sdk');var utils=require(_0x57a7('0x2'));var logger=require('../../../../config/logger')('routing');var rpc={'chatMessage':require(_0x57a7('0x3')),'openchannelMessage':require(_0x57a7('0x4')),'mailMessage':require(_0x57a7('0x5')),'smsMessage':require(_0x57a7('0x6')),'faxMessage':require(_0x57a7('0x7')),'whatsappMessage':require(_0x57a7('0x8'))};exports[_0x57a7('0x9')]=function(_0x31b29c,_0xa979d0){return function(_0xd16e89){try{if(!_[_0x57a7('0xa')](this['interaction']['UserId'])){logger['info'](_0x57a7('0xb'),_0x31b29c,'Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.');return _0xd16e89[_0x57a7('0xc')]();}var _0x38aa4d={'ContactId':this['contact']['id'],'sentAt':moment()[_0x57a7('0xd')](_0x57a7('0xe')),'direction':_0x57a7('0xf')};if(this['channel']===_0x57a7('0x10')||this[_0x57a7('0x11')]==='whatsapp'){_0x38aa4d[_0x57a7('0x12')]=this[_0x57a7('0x13')][_0x57a7('0x12')];}var _0x3b67f2=this['channel'];if(_0x3b67f2==='chat'){_0x38aa4d[_0x57a7('0x14')]=this[_0x57a7('0x15')]['id'];}else{_0x38aa4d[_[_0x57a7('0x16')](_0x3b67f2)+'AccountId']=this[_0x57a7('0x15')]['id'];}_0x38aa4d[_[_0x57a7('0x16')](_0x3b67f2)+_0x57a7('0x17')]=this['interaction']['id'];if(this['interaction'][_0x57a7('0x18')]){var _0x1ad695=_0xa979d0[0x4];if(!_[_0x57a7('0x19')](_0x1ad695)){_0x38aa4d[_0x57a7('0x1a')]=utils['getMustacheRender'](_0x1ad695,this);return rpc[_0x3b67f2+'Message'][_0x57a7('0x1b')](_0x38aa4d)[_0x57a7('0x1c')](function(_0x2c29fc){logger[_0x57a7('0x1d')](_0x57a7('0xb'),_0x31b29c,_0x38aa4d[_0x57a7('0x1a')]);})[_0x57a7('0x1e')](function(_0x3acf79){logger[_0x57a7('0x1f')](_0x57a7('0xb'),_0x31b29c,JSON[_0x57a7('0x20')](_0x3acf79));})['finally'](function(){logger[_0x57a7('0x1d')]('[%s][AMAZONLEX]\x20Welcome\x20Message\x20has\x20been\x20sent!',_0x31b29c);_0xd16e89[_0x57a7('0x21')]();});}else{logger[_0x57a7('0x1d')]('[%s][AMAZONLEX]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!',_0x31b29c);_0xd16e89[_0x57a7('0x21')]();}}else{var _0x87f191=this;var _0x47004e=new AWS[(_0x57a7('0x22'))]({'accessKeyId':_0xa979d0[0x0],'secretAccessKey':_0xa979d0[0x1],'region':_0xa979d0[0x2]});var _0x57fab8={'botAlias':_0x57a7('0x23'),'botName':_0xa979d0[0x3],'inputText':this[_0x57a7('0x24')]['body'],'userId':this[_0x57a7('0x11')]+':'+this[_0x57a7('0x13')]['id'][_0x57a7('0x25')]()};_0x47004e[_0x57a7('0x26')](_0x57fab8,function(_0x1d32ce,_0x3a537d){if(_0x1d32ce){logger[_0x57a7('0x1f')](_0x57a7('0xb'),_0x31b29c,_0x1d32ce[_0x57a7('0x24')]);_0xd16e89[_0x57a7('0xc')]();}else if(_0x3a537d&&_0x3a537d[_0x57a7('0x24')]){_0x87f191[_0x57a7('0x1a')][_0x57a7('0x27')]=_0x3a537d;_0x38aa4d[_0x57a7('0x1a')]=_0x3a537d[_0x57a7('0x24')];_0x38aa4d['providerName']='amazonlex';_0x38aa4d[_0x57a7('0x28')]=JSON['stringify'](_0x3a537d);return rpc[_0x3b67f2+'Message'][_0x57a7('0x1b')](_0x38aa4d)[_0x57a7('0x1c')](function(_0x5cb5ae){logger['info'](_0x57a7('0xb'),_0x31b29c,_0x38aa4d[_0x57a7('0x1a')]);if(_0x3a537d[_0x57a7('0x29')]==_0x57a7('0x2a')){_0xd16e89[_0x57a7('0xc')]();}else{_0xd16e89[_0x57a7('0x21')]();}})[_0x57a7('0x1e')](function(_0x35c433){logger['error']('[%s][AMAZONLEX]\x20%s',_0x31b29c,JSON['stringify'](_0x35c433));_0xd16e89[_0x57a7('0xc')]();});}else{_0xd16e89['next']();}});}}catch(_0xa69cbb){logger[_0x57a7('0x1f')]('[%s][AMAZONLEX]\x20%s',_0x31b29c,JSON['stringify'](_0xa69cbb));_0xd16e89[_0x57a7('0x21')]();}};};
\ No newline at end of file
+var _0xc7ec=['amazonlex','providerName','dialogState','Failed','error','lodash','moment','aws-sdk','./utils','../../../../config/logger','routing','../../rpc/chatMessage','../../rpc/smsMessage','../../rpc/whatsappMessage','consequence','isNil','UserId','info','[%s][AMAZONLEX]\x20%s','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','next','contact','format','YYYY-MM-DD\x20HH:mm:ss','out','channel','sms','interaction','phone','chat','ChatWebsiteId','upperFirst','account','created','body','getMustacheRender','Message','create','then','catch','stringify','finally','[%s][AMAZONLEX]\x20Welcome\x20Message\x20has\x20been\x20sent!','stop','message','postText'];(function(_0x426257,_0x4d0f32){var _0x2c4ace=function(_0x3cd93d){while(--_0x3cd93d){_0x426257['push'](_0x426257['shift']());}};_0x2c4ace(++_0x4d0f32);}(_0xc7ec,0x1a3));var _0xcc7e=function(_0x1809c5,_0x46cabc){_0x1809c5=_0x1809c5-0x0;var _0x5254a4=_0xc7ec[_0x1809c5];return _0x5254a4;};'use strict';var _=require(_0xcc7e('0x0'));var moment=require(_0xcc7e('0x1'));var AWS=require(_0xcc7e('0x2'));var utils=require(_0xcc7e('0x3'));var logger=require(_0xcc7e('0x4'))(_0xcc7e('0x5'));var rpc={'chatMessage':require(_0xcc7e('0x6')),'openchannelMessage':require('../../rpc/openchannelMessage'),'mailMessage':require('../../rpc/mailMessage'),'smsMessage':require(_0xcc7e('0x7')),'faxMessage':require('../../rpc/faxMessage'),'whatsappMessage':require(_0xcc7e('0x8'))};exports[_0xcc7e('0x9')]=function(_0x5dba35,_0xe100e6){return function(_0x12e4b6){try{if(!_[_0xcc7e('0xa')](this['interaction'][_0xcc7e('0xb')])){logger[_0xcc7e('0xc')](_0xcc7e('0xd'),_0x5dba35,_0xcc7e('0xe'));return _0x12e4b6[_0xcc7e('0xf')]();}var _0x593d7b={'ContactId':this[_0xcc7e('0x10')]['id'],'sentAt':moment()[_0xcc7e('0x11')](_0xcc7e('0x12')),'direction':_0xcc7e('0x13')};if(this[_0xcc7e('0x14')]===_0xcc7e('0x15')||this[_0xcc7e('0x14')]==='whatsapp'){_0x593d7b['phone']=this[_0xcc7e('0x16')][_0xcc7e('0x17')];}var _0x33bc98=this[_0xcc7e('0x14')];if(_0x33bc98===_0xcc7e('0x18')){_0x593d7b[_0xcc7e('0x19')]=this['account']['id'];}else{_0x593d7b[_[_0xcc7e('0x1a')](_0x33bc98)+'AccountId']=this[_0xcc7e('0x1b')]['id'];}_0x593d7b[_[_0xcc7e('0x1a')](_0x33bc98)+'InteractionId']=this[_0xcc7e('0x16')]['id'];if(this[_0xcc7e('0x16')][_0xcc7e('0x1c')]){var _0x4d4d3e=_0xe100e6[0x4];if(!_['isEmpty'](_0x4d4d3e)){_0x593d7b[_0xcc7e('0x1d')]=utils[_0xcc7e('0x1e')](_0x4d4d3e,this);return rpc[_0x33bc98+_0xcc7e('0x1f')][_0xcc7e('0x20')](_0x593d7b)[_0xcc7e('0x21')](function(_0x16c254){logger[_0xcc7e('0xc')](_0xcc7e('0xd'),_0x5dba35,_0x593d7b['body']);})[_0xcc7e('0x22')](function(_0x459496){logger['error'](_0xcc7e('0xd'),_0x5dba35,JSON[_0xcc7e('0x23')](_0x459496));})[_0xcc7e('0x24')](function(){logger[_0xcc7e('0xc')](_0xcc7e('0x25'),_0x5dba35);_0x12e4b6[_0xcc7e('0x26')]();});}else{logger[_0xcc7e('0xc')]('[%s][AMAZONLEX]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!',_0x5dba35);_0x12e4b6[_0xcc7e('0x26')]();}}else{var _0x47ffb2=this;var _0x1f92f8=new AWS['LexRuntime']({'accessKeyId':_0xe100e6[0x0],'secretAccessKey':_0xe100e6[0x1],'region':_0xe100e6[0x2]});var _0x47d78d={'botAlias':'$LATEST','botName':_0xe100e6[0x3],'inputText':this[_0xcc7e('0x27')][_0xcc7e('0x1d')],'userId':this['channel']+':'+this[_0xcc7e('0x16')]['id']['toString']()};_0x1f92f8[_0xcc7e('0x28')](_0x47d78d,function(_0x801b89,_0x43a2e8){if(_0x801b89){logger['error'](_0xcc7e('0xd'),_0x5dba35,_0x801b89[_0xcc7e('0x27')]);_0x12e4b6[_0xcc7e('0xf')]();}else if(_0x43a2e8&&_0x43a2e8[_0xcc7e('0x27')]){_0x47ffb2[_0xcc7e('0x1d')][_0xcc7e('0x29')]=_0x43a2e8;_0x593d7b[_0xcc7e('0x1d')]=_0x43a2e8[_0xcc7e('0x27')];_0x593d7b[_0xcc7e('0x2a')]=_0xcc7e('0x29');_0x593d7b['providerResponse']=JSON[_0xcc7e('0x23')](_0x43a2e8);return rpc[_0x33bc98+_0xcc7e('0x1f')][_0xcc7e('0x20')](_0x593d7b)['then'](function(_0xb0cb50){logger['info']('[%s][AMAZONLEX]\x20%s',_0x5dba35,_0x593d7b[_0xcc7e('0x1d')]);if(_0x43a2e8[_0xcc7e('0x2b')]==_0xcc7e('0x2c')){_0x12e4b6[_0xcc7e('0xf')]();}else{_0x12e4b6[_0xcc7e('0x26')]();}})[_0xcc7e('0x22')](function(_0x3993a8){logger[_0xcc7e('0x2d')]('[%s][AMAZONLEX]\x20%s',_0x5dba35,JSON[_0xcc7e('0x23')](_0x3993a8));_0x12e4b6[_0xcc7e('0xf')]();});}else{_0x12e4b6[_0xcc7e('0xf')]();}});}}catch(_0x4eab69){logger[_0xcc7e('0x2d')]('[%s][AMAZONLEX]\x20%s',_0x5dba35,JSON['stringify'](_0x4eab69));_0x12e4b6[_0xcc7e('0x26')]();}};};
\ No newline at end of file