Built motion from commit e1760111.|2.6.18
[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 _0x3689=['Message','create','then','info','[%s][AMAZONLEX]\x20%s','body','error','stringify','finally','[%s][AMAZONLEX]\x20Welcome\x20Message\x20has\x20been\x20sent!','stop','LexRuntime','message','toString','postText','amazonlex','dialogState','lodash','moment','aws-sdk','./utils','../../../../config/logger','routing','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','isNil','interaction','UserId','next','channel','sms','phone','chat','ChatWebsiteId','account','upperFirst','AccountId','created','isEmpty','getMustacheRender'];(function(_0x408918,_0x949caa){var _0x4efe75=function(_0x338ab0){while(--_0x338ab0){_0x408918['push'](_0x408918['shift']());}};_0x4efe75(++_0x949caa);}(_0x3689,0xc1));var _0x9368=function(_0x1e32f3,_0x578dc5){_0x1e32f3=_0x1e32f3-0x0;var _0x2c8751=_0x3689[_0x1e32f3];return _0x2c8751;};'use strict';var _=require(_0x9368('0x0'));var moment=require(_0x9368('0x1'));var AWS=require(_0x9368('0x2'));var utils=require(_0x9368('0x3'));var logger=require(_0x9368('0x4'))(_0x9368('0x5'));var rpc={'chatMessage':require(_0x9368('0x6')),'openchannelMessage':require(_0x9368('0x7')),'mailMessage':require(_0x9368('0x8')),'smsMessage':require(_0x9368('0x9')),'faxMessage':require(_0x9368('0xa')),'whatsappMessage':require(_0x9368('0xb'))};exports['consequence']=function(_0x1971b0,_0x1451c6){return function(_0x4ce973){try{if(!_[_0x9368('0xc')](this[_0x9368('0xd')][_0x9368('0xe')])){logger['info']('[%s][AMAZONLEX]\x20%s',_0x1971b0,'Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.');return _0x4ce973[_0x9368('0xf')]();}var _0x4e63bf={'ContactId':this['contact']['id'],'sentAt':moment()['format']('YYYY-MM-DD\x20HH:mm:ss'),'direction':'out'};if(this[_0x9368('0x10')]===_0x9368('0x11')||this['channel']==='whatsapp'){_0x4e63bf[_0x9368('0x12')]=this[_0x9368('0xd')][_0x9368('0x12')];}var _0x2a3140=this[_0x9368('0x10')];if(_0x2a3140===_0x9368('0x13')){_0x4e63bf[_0x9368('0x14')]=this[_0x9368('0x15')]['id'];}else{_0x4e63bf[_[_0x9368('0x16')](_0x2a3140)+_0x9368('0x17')]=this[_0x9368('0x15')]['id'];}_0x4e63bf[_[_0x9368('0x16')](_0x2a3140)+'InteractionId']=this[_0x9368('0xd')]['id'];if(this[_0x9368('0xd')][_0x9368('0x18')]){var _0x49cd54=_0x1451c6[0x4];if(!_[_0x9368('0x19')](_0x49cd54)){_0x4e63bf['body']=utils[_0x9368('0x1a')](_0x49cd54,this);return rpc[_0x2a3140+_0x9368('0x1b')][_0x9368('0x1c')](_0x4e63bf)[_0x9368('0x1d')](function(_0x277d07){logger[_0x9368('0x1e')](_0x9368('0x1f'),_0x1971b0,_0x4e63bf[_0x9368('0x20')]);})['catch'](function(_0x1aa54e){logger[_0x9368('0x21')](_0x9368('0x1f'),_0x1971b0,JSON[_0x9368('0x22')](_0x1aa54e));})[_0x9368('0x23')](function(){logger['info'](_0x9368('0x24'),_0x1971b0);_0x4ce973[_0x9368('0x25')]();});}else{logger[_0x9368('0x1e')]('[%s][AMAZONLEX]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!',_0x1971b0);_0x4ce973[_0x9368('0x25')]();}}else{var _0x41c45c=this;var _0x5e80af=new AWS[(_0x9368('0x26'))]({'accessKeyId':_0x1451c6[0x0],'secretAccessKey':_0x1451c6[0x1],'region':_0x1451c6[0x2]});var _0x5dcae5={'botAlias':'$LATEST','botName':_0x1451c6[0x3],'inputText':this[_0x9368('0x27')][_0x9368('0x20')],'userId':this[_0x9368('0x10')]+':'+this[_0x9368('0xd')]['id'][_0x9368('0x28')]()};_0x5e80af[_0x9368('0x29')](_0x5dcae5,function(_0xae1e46,_0x3fb11a){if(_0xae1e46){logger[_0x9368('0x21')](_0x9368('0x1f'),_0x1971b0,_0xae1e46[_0x9368('0x27')]);_0x4ce973[_0x9368('0xf')]();}else if(_0x3fb11a&&_0x3fb11a[_0x9368('0x27')]){_0x41c45c['body'][_0x9368('0x2a')]=_0x3fb11a;_0x4e63bf[_0x9368('0x20')]=_0x3fb11a[_0x9368('0x27')];_0x4e63bf['providerName']=_0x9368('0x2a');_0x4e63bf['providerResponse']=JSON['stringify'](_0x3fb11a);return rpc[_0x2a3140+_0x9368('0x1b')]['create'](_0x4e63bf)[_0x9368('0x1d')](function(_0x3fb29c){logger[_0x9368('0x1e')](_0x9368('0x1f'),_0x1971b0,_0x4e63bf[_0x9368('0x20')]);if(_0x3fb11a[_0x9368('0x2b')]=='Failed'){_0x4ce973[_0x9368('0xf')]();}else{_0x4ce973[_0x9368('0x25')]();}})['catch'](function(_0x459643){logger[_0x9368('0x21')](_0x9368('0x1f'),_0x1971b0,JSON[_0x9368('0x22')](_0x459643));_0x4ce973[_0x9368('0xf')]();});}else{_0x4ce973['next']();}});}}catch(_0x4cdc23){logger[_0x9368('0x21')](_0x9368('0x1f'),_0x1971b0,JSON[_0x9368('0x22')](_0x4cdc23));_0x4ce973[_0x9368('0x25')]();}};};