0355457b4e2f9c8d1d2171699a5c5d16a9ab8742
[motion-next.git] / server / services / routing / server / applications / amazonlex.js
1 const a1201_0x52f4=['created','../../rpc/smsMessage','create','phone','account','../../rpc/openchannelMessage','dialogState','ChatWebsiteId','InteractionId','../../rpc/whatsappMessage','YYYY-MM-DD\x20HH:mm:ss','Message','../../rpc/mailMessage','providerResponse','error','format','out','then','providerName','routing','../../rpc/faxMessage','[%s][AMAZONLEX]\x20%s','next','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','$LATEST','stringify','stop','message','aws-sdk','whatsapp','isEmpty','info','amazonlex','body','lodash','Failed','AccountId','isNil','contact','upperFirst','consequence','finally','catch','interaction'];(function(_0x1da2a7,_0x52f41c){const _0x4417be=function(_0x455aa0){while(--_0x455aa0){_0x1da2a7['push'](_0x1da2a7['shift']());}};_0x4417be(++_0x52f41c);}(a1201_0x52f4,0x1a6));const a1201_0x4417=function(_0x1da2a7,_0x52f41c){_0x1da2a7=_0x1da2a7-0x0;let _0x4417be=a1201_0x52f4[_0x1da2a7];return _0x4417be;};const _0x255474=a1201_0x4417;'use strict';const _=require(_0x255474('0x8')),moment=require('moment'),AWS=require(_0x255474('0x2')),utils=require('./utils'),logger=require('../../../../config/logger')(_0x255474('0x25')),rpc={'chatMessage':require('../../rpc/chatMessage'),'openchannelMessage':require(_0x255474('0x17')),'mailMessage':require(_0x255474('0x1e')),'smsMessage':require(_0x255474('0x13')),'faxMessage':require(_0x255474('0x26')),'whatsappMessage':require(_0x255474('0x1b'))};exports[_0x255474('0xe')]=function(_0x455aa0,_0x17a80d){return function(_0x44ffa6){const _0x2d1045=a1201_0x4417;try{if(!_[_0x2d1045('0xb')](this[_0x2d1045('0x11')]['UserId']))return logger[_0x2d1045('0x5')](_0x2d1045('0x27'),_0x455aa0,_0x2d1045('0x29')),_0x44ffa6[_0x2d1045('0x28')]();const _0x59d0c1={'ContactId':this[_0x2d1045('0xc')]['id'],'sentAt':moment()[_0x2d1045('0x21')](_0x2d1045('0x1c')),'direction':_0x2d1045('0x22')};(this['channel']==='sms'||this['channel']===_0x2d1045('0x3'))&&(_0x59d0c1[_0x2d1045('0x15')]=this['interaction'][_0x2d1045('0x15')]);const _0x45fc70=this['channel'];_0x45fc70==='chat'?_0x59d0c1[_0x2d1045('0x19')]=this['account']['id']:_0x59d0c1[_[_0x2d1045('0xd')](_0x45fc70)+_0x2d1045('0xa')]=this[_0x2d1045('0x16')]['id'];_0x59d0c1[_[_0x2d1045('0xd')](_0x45fc70)+_0x2d1045('0x1a')]=this[_0x2d1045('0x11')]['id'];if(this['interaction'][_0x2d1045('0x12')]){const _0x5b4fa9=_0x17a80d[0x4];if(!_[_0x2d1045('0x4')](_0x5b4fa9))return _0x59d0c1[_0x2d1045('0x7')]=utils['getMustacheRender'](_0x5b4fa9,this),rpc[_0x45fc70+_0x2d1045('0x1d')][_0x2d1045('0x14')](_0x59d0c1)[_0x2d1045('0x23')](function(){const _0x2705ab=_0x2d1045;logger['info'](_0x2705ab('0x27'),_0x455aa0,_0x59d0c1[_0x2705ab('0x7')]);})['catch'](function(_0x4ad97b){const _0x1eba2f=_0x2d1045;logger[_0x1eba2f('0x20')](_0x1eba2f('0x27'),_0x455aa0,JSON[_0x1eba2f('0x2b')](_0x4ad97b));})[_0x2d1045('0xf')](function(){const _0x47e141=_0x2d1045;logger[_0x47e141('0x5')]('[%s][AMAZONLEX]\x20Welcome\x20Message\x20has\x20been\x20sent!',_0x455aa0),_0x44ffa6[_0x47e141('0x0')]();});else logger[_0x2d1045('0x5')]('[%s][AMAZONLEX]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!',_0x455aa0),_0x44ffa6[_0x2d1045('0x0')]();}else{const _0x16b3ee=this,_0x274a96=new AWS['LexRuntime']({'accessKeyId':_0x17a80d[0x0],'secretAccessKey':_0x17a80d[0x1],'region':_0x17a80d[0x2]}),_0x19793d={'botAlias':_0x2d1045('0x2a'),'botName':_0x17a80d[0x3],'inputText':this['message'][_0x2d1045('0x7')],'userId':this['channel']+':'+this[_0x2d1045('0x11')]['id']['toString']()};_0x274a96['postText'](_0x19793d,function(_0x4130a4,_0x4c4429){const _0x5abb33=_0x2d1045;if(_0x4130a4)logger[_0x5abb33('0x20')](_0x5abb33('0x27'),_0x455aa0,_0x4130a4[_0x5abb33('0x1')]),_0x44ffa6[_0x5abb33('0x28')]();else{if(_0x4c4429&&_0x4c4429[_0x5abb33('0x1')])return _0x16b3ee['body'][_0x5abb33('0x6')]=_0x4c4429,_0x59d0c1[_0x5abb33('0x7')]=_0x4c4429[_0x5abb33('0x1')],_0x59d0c1[_0x5abb33('0x24')]='amazonlex',_0x59d0c1[_0x5abb33('0x1f')]=JSON[_0x5abb33('0x2b')](_0x4c4429),rpc[_0x45fc70+_0x5abb33('0x1d')][_0x5abb33('0x14')](_0x59d0c1)['then'](function(){const _0x2e1524=_0x5abb33;logger[_0x2e1524('0x5')](_0x2e1524('0x27'),_0x455aa0,_0x59d0c1[_0x2e1524('0x7')]),_0x4c4429[_0x2e1524('0x18')]==_0x2e1524('0x9')?_0x44ffa6['next']():_0x44ffa6[_0x2e1524('0x0')]();})[_0x5abb33('0x10')](function(_0x4394f3){const _0x397a82=_0x5abb33;logger[_0x397a82('0x20')]('[%s][AMAZONLEX]\x20%s',_0x455aa0,JSON[_0x397a82('0x2b')](_0x4394f3)),_0x44ffa6[_0x397a82('0x28')]();});else _0x44ffa6[_0x5abb33('0x28')]();}});}}catch(_0x73da80){logger['error'](_0x2d1045('0x27'),_0x455aa0,JSON['stringify'](_0x73da80)),_0x44ffa6['stop']();}};};