Built motion from commit (unavailable).|2.4.5
[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 _0xbb7c=['../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/faxMessage','consequence','isNil','interaction','UserId','info','[%s][AMAZONLEX]\x20%s','next','contact','format','YYYY-MM-DD\x20HH:mm:ss','out','channel','chat','ChatWebsiteId','account','upperFirst','InteractionId','created','isEmpty','body','Message','create','then','catch','error','finally','[%s][AMAZONLEX]\x20Welcome\x20Message\x20has\x20been\x20sent!','[%s][AMAZONLEX]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!','stop','LexRuntime','toString','postText','message','amazonlex','dialogState','stringify','lodash','moment','aws-sdk','./utils','../../../../config/logger','routing'];(function(_0x3bc066,_0x10c906){var _0x3730c9=function(_0x2d9d8d){while(--_0x2d9d8d){_0x3bc066['push'](_0x3bc066['shift']());}};_0x3730c9(++_0x10c906);}(_0xbb7c,0x13c));var _0xcbb7=function(_0x1fcba7,_0x170d0c){_0x1fcba7=_0x1fcba7-0x0;var _0x5c074f=_0xbb7c[_0x1fcba7];return _0x5c074f;};'use strict';var _=require(_0xcbb7('0x0'));var moment=require(_0xcbb7('0x1'));var AWS=require(_0xcbb7('0x2'));var utils=require(_0xcbb7('0x3'));var logger=require(_0xcbb7('0x4'))(_0xcbb7('0x5'));var rpc={'chatMessage':require(_0xcbb7('0x6')),'openchannelMessage':require(_0xcbb7('0x7')),'mailMessage':require(_0xcbb7('0x8')),'smsMessage':require('../../rpc/smsMessage'),'faxMessage':require(_0xcbb7('0x9'))};exports[_0xcbb7('0xa')]=function(_0x2ca9ef,_0x16ea2f){return function(_0x32b828){try{if(!_[_0xcbb7('0xb')](this[_0xcbb7('0xc')][_0xcbb7('0xd')])){logger[_0xcbb7('0xe')](_0xcbb7('0xf'),_0x2ca9ef,'Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.');return _0x32b828[_0xcbb7('0x10')]();}var _0x8d5603={'ContactId':this[_0xcbb7('0x11')]['id'],'sentAt':moment()[_0xcbb7('0x12')](_0xcbb7('0x13')),'direction':_0xcbb7('0x14')};var _0x21c972=this[_0xcbb7('0x15')];if(_0x21c972===_0xcbb7('0x16')){_0x8d5603[_0xcbb7('0x17')]=this[_0xcbb7('0x18')]['id'];}else{_0x8d5603[_[_0xcbb7('0x19')](_0x21c972)+'AccountId']=this[_0xcbb7('0x18')]['id'];}_0x8d5603[_[_0xcbb7('0x19')](_0x21c972)+_0xcbb7('0x1a')]=this[_0xcbb7('0xc')]['id'];if(this['interaction'][_0xcbb7('0x1b')]){var _0x447b15=_0x16ea2f[0x4];if(!_[_0xcbb7('0x1c')](_0x447b15)){_0x8d5603[_0xcbb7('0x1d')]=utils['getMustacheRender'](_0x447b15,this);return rpc[_0x21c972+_0xcbb7('0x1e')][_0xcbb7('0x1f')](_0x8d5603)[_0xcbb7('0x20')](function(_0x2441ab){logger[_0xcbb7('0xe')](_0xcbb7('0xf'),_0x2ca9ef,_0x8d5603[_0xcbb7('0x1d')]);})[_0xcbb7('0x21')](function(_0x31de96){logger[_0xcbb7('0x22')]('[%s][AMAZONLEX]\x20%s',_0x2ca9ef,JSON['stringify'](_0x31de96));})[_0xcbb7('0x23')](function(){logger['info'](_0xcbb7('0x24'),_0x2ca9ef);_0x32b828['stop']();});}else{logger[_0xcbb7('0xe')](_0xcbb7('0x25'),_0x2ca9ef);_0x32b828[_0xcbb7('0x26')]();}}else{var _0x50116d=this;var _0x32d60b=new AWS[(_0xcbb7('0x27'))]({'accessKeyId':_0x16ea2f[0x0],'secretAccessKey':_0x16ea2f[0x1],'region':_0x16ea2f[0x2]});var _0x10dcc2={'botAlias':'$LATEST','botName':_0x16ea2f[0x3],'inputText':this['message'][_0xcbb7('0x1d')],'userId':this[_0xcbb7('0xc')]['id'][_0xcbb7('0x28')]()};_0x32d60b[_0xcbb7('0x29')](_0x10dcc2,function(_0x3c4926,_0x24f994){if(_0x3c4926){logger[_0xcbb7('0x22')](_0xcbb7('0xf'),_0x2ca9ef,_0x3c4926[_0xcbb7('0x2a')]);_0x32b828[_0xcbb7('0x10')]();}else if(_0x24f994&&_0x24f994[_0xcbb7('0x2a')]){_0x50116d[_0xcbb7('0x1d')][_0xcbb7('0x2b')]=_0x24f994;_0x8d5603[_0xcbb7('0x1d')]=_0x24f994['message'];return rpc[_0x21c972+'Message'][_0xcbb7('0x1f')](_0x8d5603)[_0xcbb7('0x20')](function(_0x157f8b){logger[_0xcbb7('0xe')](_0xcbb7('0xf'),_0x2ca9ef,_0x8d5603[_0xcbb7('0x1d')]);if(_0x24f994[_0xcbb7('0x2c')]=='Failed'){_0x32b828[_0xcbb7('0x10')]();}else{_0x32b828['stop']();}})['catch'](function(_0x322dc9){logger[_0xcbb7('0x22')](_0xcbb7('0xf'),_0x2ca9ef,JSON['stringify'](_0x322dc9));_0x32b828[_0xcbb7('0x10')]();});}else{_0x32b828[_0xcbb7('0x10')]();}});}}catch(_0x24805a){logger[_0xcbb7('0x22')]('[%s][AMAZONLEX]\x20%s',_0x2ca9ef,JSON[_0xcbb7('0x2d')](_0x24805a));_0x32b828['stop']();}};};