f12df63573dca078004128cdb2ee9f00ba5d49c8
[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 _0x3f8a=['channel','chat','ChatWebsiteId','account','upperFirst','AccountId','InteractionId','isEmpty','body','getMustacheRender','create','then','catch','error','finally','[%s][AMAZONLEX]\x20Welcome\x20Message\x20has\x20been\x20sent!','stop','[%s][AMAZONLEX]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!','LexRuntime','$LATEST','message','toString','postText','next','amazonlex','Message','dialogState','stringify','lodash','moment','aws-sdk','./utils','routing','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','consequence','isNil','interaction','UserId','info','[%s][AMAZONLEX]\x20%s','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','contact','format','YYYY-MM-DD\x20HH:mm:ss'];(function(_0x2fb16a,_0x19e217){var _0x1bbd83=function(_0x4940d7){while(--_0x4940d7){_0x2fb16a['push'](_0x2fb16a['shift']());}};_0x1bbd83(++_0x19e217);}(_0x3f8a,0x1d5));var _0xa3f8=function(_0x27bae4,_0x3d2bf8){_0x27bae4=_0x27bae4-0x0;var _0x9733e6=_0x3f8a[_0x27bae4];return _0x9733e6;};'use strict';var _=require(_0xa3f8('0x0'));var moment=require(_0xa3f8('0x1'));var AWS=require(_0xa3f8('0x2'));var utils=require(_0xa3f8('0x3'));var logger=require('../../../../config/logger')(_0xa3f8('0x4'));var rpc={'chatMessage':require(_0xa3f8('0x5')),'openchannelMessage':require(_0xa3f8('0x6')),'mailMessage':require(_0xa3f8('0x7')),'smsMessage':require(_0xa3f8('0x8')),'faxMessage':require(_0xa3f8('0x9')),'whatsappMessage':require(_0xa3f8('0xa'))};exports[_0xa3f8('0xb')]=function(_0x1f160a,_0xf895d9){return function(_0xcfea5){try{if(!_[_0xa3f8('0xc')](this[_0xa3f8('0xd')][_0xa3f8('0xe')])){logger[_0xa3f8('0xf')](_0xa3f8('0x10'),_0x1f160a,_0xa3f8('0x11'));return _0xcfea5['next']();}var _0x47496a={'ContactId':this[_0xa3f8('0x12')]['id'],'sentAt':moment()[_0xa3f8('0x13')](_0xa3f8('0x14')),'direction':'out'};var _0x206b69=this[_0xa3f8('0x15')];if(_0x206b69===_0xa3f8('0x16')){_0x47496a[_0xa3f8('0x17')]=this[_0xa3f8('0x18')]['id'];}else{_0x47496a[_[_0xa3f8('0x19')](_0x206b69)+_0xa3f8('0x1a')]=this[_0xa3f8('0x18')]['id'];}_0x47496a[_[_0xa3f8('0x19')](_0x206b69)+_0xa3f8('0x1b')]=this[_0xa3f8('0xd')]['id'];if(this[_0xa3f8('0xd')]['created']){var _0x2d8f74=_0xf895d9[0x4];if(!_[_0xa3f8('0x1c')](_0x2d8f74)){_0x47496a[_0xa3f8('0x1d')]=utils[_0xa3f8('0x1e')](_0x2d8f74,this);return rpc[_0x206b69+'Message'][_0xa3f8('0x1f')](_0x47496a)[_0xa3f8('0x20')](function(_0x46a8d9){logger[_0xa3f8('0xf')](_0xa3f8('0x10'),_0x1f160a,_0x47496a[_0xa3f8('0x1d')]);})[_0xa3f8('0x21')](function(_0x3e2e1c){logger[_0xa3f8('0x22')](_0xa3f8('0x10'),_0x1f160a,JSON['stringify'](_0x3e2e1c));})[_0xa3f8('0x23')](function(){logger['info'](_0xa3f8('0x24'),_0x1f160a);_0xcfea5[_0xa3f8('0x25')]();});}else{logger[_0xa3f8('0xf')](_0xa3f8('0x26'),_0x1f160a);_0xcfea5['stop']();}}else{var _0x1f0bb8=this;var _0x5b0d57=new AWS[(_0xa3f8('0x27'))]({'accessKeyId':_0xf895d9[0x0],'secretAccessKey':_0xf895d9[0x1],'region':_0xf895d9[0x2]});var _0x58336d={'botAlias':_0xa3f8('0x28'),'botName':_0xf895d9[0x3],'inputText':this[_0xa3f8('0x29')][_0xa3f8('0x1d')],'userId':this[_0xa3f8('0x15')]+':'+this[_0xa3f8('0xd')]['id'][_0xa3f8('0x2a')]()};_0x5b0d57[_0xa3f8('0x2b')](_0x58336d,function(_0x490717,_0xae76ec){if(_0x490717){logger['error'](_0xa3f8('0x10'),_0x1f160a,_0x490717[_0xa3f8('0x29')]);_0xcfea5[_0xa3f8('0x2c')]();}else if(_0xae76ec&&_0xae76ec[_0xa3f8('0x29')]){_0x1f0bb8[_0xa3f8('0x1d')][_0xa3f8('0x2d')]=_0xae76ec;_0x47496a[_0xa3f8('0x1d')]=_0xae76ec[_0xa3f8('0x29')];return rpc[_0x206b69+_0xa3f8('0x2e')][_0xa3f8('0x1f')](_0x47496a)['then'](function(_0x1c3358){logger[_0xa3f8('0xf')](_0xa3f8('0x10'),_0x1f160a,_0x47496a['body']);if(_0xae76ec[_0xa3f8('0x2f')]=='Failed'){_0xcfea5[_0xa3f8('0x2c')]();}else{_0xcfea5[_0xa3f8('0x25')]();}})[_0xa3f8('0x21')](function(_0x4ea213){logger[_0xa3f8('0x22')]('[%s][AMAZONLEX]\x20%s',_0x1f160a,JSON[_0xa3f8('0x30')](_0x4ea213));_0xcfea5[_0xa3f8('0x2c')]();});}else{_0xcfea5[_0xa3f8('0x2c')]();}});}}catch(_0x406140){logger[_0xa3f8('0x22')](_0xa3f8('0x10'),_0x1f160a,JSON[_0xa3f8('0x30')](_0x406140));_0xcfea5[_0xa3f8('0x25')]();}};};