4665ca4bb70b48af7f588046b8ac0793fe8b08df
[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 _0xf3c9=['format','YYYY-MM-DD\x20HH:mm:ss','out','channel','sms','whatsapp','phone','chat','ChatWebsiteId','account','AccountId','InteractionId','created','isEmpty','body','create','catch','error','stringify','finally','[%s][AMAZONLEX]\x20Welcome\x20Message\x20has\x20been\x20sent!','stop','info','[%s][AMAZONLEX]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!','LexRuntime','$LATEST','message','postText','amazonlex','providerName','Message','then','dialogState','Failed','lodash','moment','aws-sdk','./utils','../../../../config/logger','routing','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','consequence','isNil','interaction','UserId','[%s][AMAZONLEX]\x20%s','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','next','contact'];(function(_0x4b6778,_0x505a76){var _0x22dbb9=function(_0x4881eb){while(--_0x4881eb){_0x4b6778['push'](_0x4b6778['shift']());}};_0x22dbb9(++_0x505a76);}(_0xf3c9,0xc4));var _0x9f3c=function(_0x243e78,_0x353aa0){_0x243e78=_0x243e78-0x0;var _0x476e81=_0xf3c9[_0x243e78];return _0x476e81;};'use strict';var _=require(_0x9f3c('0x0'));var moment=require(_0x9f3c('0x1'));var AWS=require(_0x9f3c('0x2'));var utils=require(_0x9f3c('0x3'));var logger=require(_0x9f3c('0x4'))(_0x9f3c('0x5'));var rpc={'chatMessage':require(_0x9f3c('0x6')),'openchannelMessage':require(_0x9f3c('0x7')),'mailMessage':require(_0x9f3c('0x8')),'smsMessage':require(_0x9f3c('0x9')),'faxMessage':require(_0x9f3c('0xa')),'whatsappMessage':require(_0x9f3c('0xb'))};exports[_0x9f3c('0xc')]=function(_0x531651,_0x2b39d0){return function(_0x11f60b){try{if(!_[_0x9f3c('0xd')](this[_0x9f3c('0xe')][_0x9f3c('0xf')])){logger['info'](_0x9f3c('0x10'),_0x531651,_0x9f3c('0x11'));return _0x11f60b[_0x9f3c('0x12')]();}var _0x43adf6={'ContactId':this[_0x9f3c('0x13')]['id'],'sentAt':moment()[_0x9f3c('0x14')](_0x9f3c('0x15')),'direction':_0x9f3c('0x16')};if(this[_0x9f3c('0x17')]===_0x9f3c('0x18')||this['channel']===_0x9f3c('0x19')){_0x43adf6[_0x9f3c('0x1a')]=this['interaction'][_0x9f3c('0x1a')];}var _0x13ec9f=this[_0x9f3c('0x17')];if(_0x13ec9f===_0x9f3c('0x1b')){_0x43adf6[_0x9f3c('0x1c')]=this[_0x9f3c('0x1d')]['id'];}else{_0x43adf6[_['upperFirst'](_0x13ec9f)+_0x9f3c('0x1e')]=this[_0x9f3c('0x1d')]['id'];}_0x43adf6[_['upperFirst'](_0x13ec9f)+_0x9f3c('0x1f')]=this['interaction']['id'];if(this[_0x9f3c('0xe')][_0x9f3c('0x20')]){var _0x4b983f=_0x2b39d0[0x4];if(!_[_0x9f3c('0x21')](_0x4b983f)){_0x43adf6[_0x9f3c('0x22')]=utils['getMustacheRender'](_0x4b983f,this);return rpc[_0x13ec9f+'Message'][_0x9f3c('0x23')](_0x43adf6)['then'](function(_0x467fde){logger['info'](_0x9f3c('0x10'),_0x531651,_0x43adf6[_0x9f3c('0x22')]);})[_0x9f3c('0x24')](function(_0x4eb842){logger[_0x9f3c('0x25')](_0x9f3c('0x10'),_0x531651,JSON[_0x9f3c('0x26')](_0x4eb842));})[_0x9f3c('0x27')](function(){logger['info'](_0x9f3c('0x28'),_0x531651);_0x11f60b[_0x9f3c('0x29')]();});}else{logger[_0x9f3c('0x2a')](_0x9f3c('0x2b'),_0x531651);_0x11f60b[_0x9f3c('0x29')]();}}else{var _0x17e1d1=this;var _0x39a5f6=new AWS[(_0x9f3c('0x2c'))]({'accessKeyId':_0x2b39d0[0x0],'secretAccessKey':_0x2b39d0[0x1],'region':_0x2b39d0[0x2]});var _0x2795aa={'botAlias':_0x9f3c('0x2d'),'botName':_0x2b39d0[0x3],'inputText':this[_0x9f3c('0x2e')][_0x9f3c('0x22')],'userId':this[_0x9f3c('0x17')]+':'+this['interaction']['id']['toString']()};_0x39a5f6[_0x9f3c('0x2f')](_0x2795aa,function(_0x53dfbe,_0x5eb515){if(_0x53dfbe){logger['error'](_0x9f3c('0x10'),_0x531651,_0x53dfbe[_0x9f3c('0x2e')]);_0x11f60b['next']();}else if(_0x5eb515&&_0x5eb515['message']){_0x17e1d1['body'][_0x9f3c('0x30')]=_0x5eb515;_0x43adf6[_0x9f3c('0x22')]=_0x5eb515[_0x9f3c('0x2e')];_0x43adf6[_0x9f3c('0x31')]='amazonlex';_0x43adf6['providerResponse']=JSON['stringify'](_0x5eb515);return rpc[_0x13ec9f+_0x9f3c('0x32')][_0x9f3c('0x23')](_0x43adf6)[_0x9f3c('0x33')](function(_0xb99e3){logger[_0x9f3c('0x2a')](_0x9f3c('0x10'),_0x531651,_0x43adf6[_0x9f3c('0x22')]);if(_0x5eb515[_0x9f3c('0x34')]==_0x9f3c('0x35')){_0x11f60b['next']();}else{_0x11f60b[_0x9f3c('0x29')]();}})[_0x9f3c('0x24')](function(_0x48a646){logger[_0x9f3c('0x25')](_0x9f3c('0x10'),_0x531651,JSON['stringify'](_0x48a646));_0x11f60b[_0x9f3c('0x12')]();});}else{_0x11f60b['next']();}});}}catch(_0x102a93){logger[_0x9f3c('0x25')](_0x9f3c('0x10'),_0x531651,JSON['stringify'](_0x102a93));_0x11f60b[_0x9f3c('0x29')]();}};};