94cf362d822a1f36286e3a8c56c510cd6b4fbd58
[motion2.git] / server / services / routing / server / applications / amazonlex.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xac3f=['lodash','aws-sdk','./utils','../../../../config/logger','routing','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/smsMessage','UserId','info','[%s][AMAZONLEX]\x20%s','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','contact','format','YYYY-MM-DD\x20HH:mm:ss','out','sms','phone','interaction','chat','ChatWebsiteId','upperFirst','AccountId','account','InteractionId','isEmpty','body','getMustacheRender','Message','create','error','stringify','[%s][AMAZONLEX]\x20Welcome\x20Message\x20has\x20been\x20sent!','[%s][AMAZONLEX]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!','stop','LexRuntime','channel','toString','postText','message','next','amazonlex','then','dialogState','Failed'];(function(_0x178e48,_0x3c9509){var _0x440d7e=function(_0xc2f8a0){while(--_0xc2f8a0){_0x178e48['push'](_0x178e48['shift']());}};_0x440d7e(++_0x3c9509);}(_0xac3f,0x1c2));var _0xfac3=function(_0x4fbfd9,_0x3ab91a){_0x4fbfd9=_0x4fbfd9-0x0;var _0x31dc94=_0xac3f[_0x4fbfd9];return _0x31dc94;};'use strict';var _=require(_0xfac3('0x0'));var moment=require('moment');var AWS=require(_0xfac3('0x1'));var utils=require(_0xfac3('0x2'));var logger=require(_0xfac3('0x3'))(_0xfac3('0x4'));var rpc={'chatMessage':require(_0xfac3('0x5')),'openchannelMessage':require(_0xfac3('0x6')),'mailMessage':require('../../rpc/mailMessage'),'smsMessage':require(_0xfac3('0x7')),'faxMessage':require('../../rpc/faxMessage'),'whatsappMessage':require('../../rpc/whatsappMessage')};exports['consequence']=function(_0x34ef16,_0x220337){return function(_0x5e8461){try{if(!_['isNil'](this['interaction'][_0xfac3('0x8')])){logger[_0xfac3('0x9')](_0xfac3('0xa'),_0x34ef16,_0xfac3('0xb'));return _0x5e8461['next']();}var _0x5c8266={'ContactId':this[_0xfac3('0xc')]['id'],'sentAt':moment()[_0xfac3('0xd')](_0xfac3('0xe')),'direction':_0xfac3('0xf')};if(this['channel']===_0xfac3('0x10')||this['channel']==='whatsapp'){_0x5c8266[_0xfac3('0x11')]=this[_0xfac3('0x12')][_0xfac3('0x11')];}var _0x1995a6=this['channel'];if(_0x1995a6===_0xfac3('0x13')){_0x5c8266[_0xfac3('0x14')]=this['account']['id'];}else{_0x5c8266[_[_0xfac3('0x15')](_0x1995a6)+_0xfac3('0x16')]=this[_0xfac3('0x17')]['id'];}_0x5c8266[_['upperFirst'](_0x1995a6)+_0xfac3('0x18')]=this['interaction']['id'];if(this['interaction']['created']){var _0x2c6d7f=_0x220337[0x4];if(!_[_0xfac3('0x19')](_0x2c6d7f)){_0x5c8266[_0xfac3('0x1a')]=utils[_0xfac3('0x1b')](_0x2c6d7f,this);return rpc[_0x1995a6+_0xfac3('0x1c')][_0xfac3('0x1d')](_0x5c8266)['then'](function(_0x154fc0){logger[_0xfac3('0x9')](_0xfac3('0xa'),_0x34ef16,_0x5c8266[_0xfac3('0x1a')]);})['catch'](function(_0x421d06){logger[_0xfac3('0x1e')](_0xfac3('0xa'),_0x34ef16,JSON[_0xfac3('0x1f')](_0x421d06));})['finally'](function(){logger[_0xfac3('0x9')](_0xfac3('0x20'),_0x34ef16);_0x5e8461['stop']();});}else{logger[_0xfac3('0x9')](_0xfac3('0x21'),_0x34ef16);_0x5e8461[_0xfac3('0x22')]();}}else{var _0x524eea=this;var _0x2ca27f=new AWS[(_0xfac3('0x23'))]({'accessKeyId':_0x220337[0x0],'secretAccessKey':_0x220337[0x1],'region':_0x220337[0x2]});var _0x58c9c0={'botAlias':'$LATEST','botName':_0x220337[0x3],'inputText':this['message'][_0xfac3('0x1a')],'userId':this[_0xfac3('0x24')]+':'+this['interaction']['id'][_0xfac3('0x25')]()};_0x2ca27f[_0xfac3('0x26')](_0x58c9c0,function(_0x4b6cb6,_0x52a781){if(_0x4b6cb6){logger[_0xfac3('0x1e')]('[%s][AMAZONLEX]\x20%s',_0x34ef16,_0x4b6cb6[_0xfac3('0x27')]);_0x5e8461[_0xfac3('0x28')]();}else if(_0x52a781&&_0x52a781[_0xfac3('0x27')]){_0x524eea[_0xfac3('0x1a')][_0xfac3('0x29')]=_0x52a781;_0x5c8266[_0xfac3('0x1a')]=_0x52a781[_0xfac3('0x27')];_0x5c8266['providerName']=_0xfac3('0x29');_0x5c8266['providerResponse']=JSON[_0xfac3('0x1f')](_0x52a781);return rpc[_0x1995a6+'Message'][_0xfac3('0x1d')](_0x5c8266)[_0xfac3('0x2a')](function(_0x442d49){logger['info'](_0xfac3('0xa'),_0x34ef16,_0x5c8266[_0xfac3('0x1a')]);if(_0x52a781[_0xfac3('0x2b')]==_0xfac3('0x2c')){_0x5e8461['next']();}else{_0x5e8461[_0xfac3('0x22')]();}})['catch'](function(_0xf3b730){logger[_0xfac3('0x1e')](_0xfac3('0xa'),_0x34ef16,JSON[_0xfac3('0x1f')](_0xf3b730));_0x5e8461[_0xfac3('0x28')]();});}else{_0x5e8461[_0xfac3('0x28')]();}});}}catch(_0x2b7bcf){logger[_0xfac3('0x1e')](_0xfac3('0xa'),_0x34ef16,JSON[_0xfac3('0x1f')](_0x2b7bcf));_0x5e8461['stop']();}};};