Built motion from commit a61a4a20.|2.5.46
[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 _0x7f12=['Failed','catch','lodash','aws-sdk','./utils','../../rpc/chatMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','UserId','info','[%s][AMAZONLEX]\x20%s','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','YYYY-MM-DD\x20HH:mm:ss','out','channel','sms','whatsapp','phone','interaction','ChatWebsiteId','account','upperFirst','InteractionId','created','isEmpty','body','getMustacheRender','Message','create','then','error','stringify','finally','[%s][AMAZONLEX]\x20Welcome\x20Message\x20has\x20been\x20sent!','stop','[%s][AMAZONLEX]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!','$LATEST','message','toString','next','providerName','amazonlex','providerResponse','dialogState'];(function(_0x28394f,_0x5ebdd2){var _0x2618d2=function(_0x2ffed6){while(--_0x2ffed6){_0x28394f['push'](_0x28394f['shift']());}};_0x2618d2(++_0x5ebdd2);}(_0x7f12,0x116));var _0x27f1=function(_0x50922d,_0xe0be5b){_0x50922d=_0x50922d-0x0;var _0x407760=_0x7f12[_0x50922d];return _0x407760;};'use strict';var _=require(_0x27f1('0x0'));var moment=require('moment');var AWS=require(_0x27f1('0x1'));var utils=require(_0x27f1('0x2'));var logger=require('../../../../config/logger')('routing');var rpc={'chatMessage':require(_0x27f1('0x3')),'openchannelMessage':require('../../rpc/openchannelMessage'),'mailMessage':require(_0x27f1('0x4')),'smsMessage':require(_0x27f1('0x5')),'faxMessage':require(_0x27f1('0x6')),'whatsappMessage':require(_0x27f1('0x7'))};exports['consequence']=function(_0x4f180c,_0x15cf7d){return function(_0xb70068){try{if(!_['isNil'](this['interaction'][_0x27f1('0x8')])){logger[_0x27f1('0x9')](_0x27f1('0xa'),_0x4f180c,_0x27f1('0xb'));return _0xb70068['next']();}var _0x4d50bd={'ContactId':this['contact']['id'],'sentAt':moment()['format'](_0x27f1('0xc')),'direction':_0x27f1('0xd')};if(this[_0x27f1('0xe')]===_0x27f1('0xf')||this[_0x27f1('0xe')]===_0x27f1('0x10')){_0x4d50bd[_0x27f1('0x11')]=this[_0x27f1('0x12')][_0x27f1('0x11')];}var _0x37f27f=this[_0x27f1('0xe')];if(_0x37f27f==='chat'){_0x4d50bd[_0x27f1('0x13')]=this[_0x27f1('0x14')]['id'];}else{_0x4d50bd[_[_0x27f1('0x15')](_0x37f27f)+'AccountId']=this[_0x27f1('0x14')]['id'];}_0x4d50bd[_[_0x27f1('0x15')](_0x37f27f)+_0x27f1('0x16')]=this[_0x27f1('0x12')]['id'];if(this['interaction'][_0x27f1('0x17')]){var _0x539039=_0x15cf7d[0x4];if(!_[_0x27f1('0x18')](_0x539039)){_0x4d50bd[_0x27f1('0x19')]=utils[_0x27f1('0x1a')](_0x539039,this);return rpc[_0x37f27f+_0x27f1('0x1b')][_0x27f1('0x1c')](_0x4d50bd)[_0x27f1('0x1d')](function(_0x4fd950){logger[_0x27f1('0x9')](_0x27f1('0xa'),_0x4f180c,_0x4d50bd[_0x27f1('0x19')]);})['catch'](function(_0x3d16c3){logger[_0x27f1('0x1e')](_0x27f1('0xa'),_0x4f180c,JSON[_0x27f1('0x1f')](_0x3d16c3));})[_0x27f1('0x20')](function(){logger[_0x27f1('0x9')](_0x27f1('0x21'),_0x4f180c);_0xb70068[_0x27f1('0x22')]();});}else{logger[_0x27f1('0x9')](_0x27f1('0x23'),_0x4f180c);_0xb70068[_0x27f1('0x22')]();}}else{var _0x75f98d=this;var _0x3a20e7=new AWS['LexRuntime']({'accessKeyId':_0x15cf7d[0x0],'secretAccessKey':_0x15cf7d[0x1],'region':_0x15cf7d[0x2]});var _0x127cba={'botAlias':_0x27f1('0x24'),'botName':_0x15cf7d[0x3],'inputText':this[_0x27f1('0x25')][_0x27f1('0x19')],'userId':this[_0x27f1('0xe')]+':'+this[_0x27f1('0x12')]['id'][_0x27f1('0x26')]()};_0x3a20e7['postText'](_0x127cba,function(_0x4cc0f2,_0x74b4d9){if(_0x4cc0f2){logger[_0x27f1('0x1e')](_0x27f1('0xa'),_0x4f180c,_0x4cc0f2[_0x27f1('0x25')]);_0xb70068[_0x27f1('0x27')]();}else if(_0x74b4d9&&_0x74b4d9['message']){_0x75f98d[_0x27f1('0x19')]['amazonlex']=_0x74b4d9;_0x4d50bd[_0x27f1('0x19')]=_0x74b4d9['message'];_0x4d50bd[_0x27f1('0x28')]=_0x27f1('0x29');_0x4d50bd[_0x27f1('0x2a')]=JSON[_0x27f1('0x1f')](_0x74b4d9);return rpc[_0x37f27f+_0x27f1('0x1b')][_0x27f1('0x1c')](_0x4d50bd)[_0x27f1('0x1d')](function(_0x3b6044){logger['info'](_0x27f1('0xa'),_0x4f180c,_0x4d50bd[_0x27f1('0x19')]);if(_0x74b4d9[_0x27f1('0x2b')]==_0x27f1('0x2c')){_0xb70068[_0x27f1('0x27')]();}else{_0xb70068['stop']();}})[_0x27f1('0x2d')](function(_0xe913){logger[_0x27f1('0x1e')]('[%s][AMAZONLEX]\x20%s',_0x4f180c,JSON[_0x27f1('0x1f')](_0xe913));_0xb70068[_0x27f1('0x27')]();});}else{_0xb70068[_0x27f1('0x27')]();}});}}catch(_0x47c172){logger['error'](_0x27f1('0xa'),_0x4f180c,JSON[_0x27f1('0x1f')](_0x47c172));_0xb70068[_0x27f1('0x22')]();}};};