1cced1b5b2117f16360bcf9c6f5bb25324131e6f
[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 _0x6f58=['postText','amazonlex','providerName','providerResponse','stringify','Failed','error','lodash','moment','./utils','../../../../config/logger','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/smsMessage','../../rpc/whatsappMessage','consequence','isNil','interaction','UserId','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','next','contact','format','out','channel','sms','whatsapp','phone','chat','ChatWebsiteId','upperFirst','AccountId','account','InteractionId','created','isEmpty','create','then','[%s][AMAZONLEX]\x20%s','body','finally','info','[%s][AMAZONLEX]\x20Welcome\x20Message\x20has\x20been\x20sent!','stop','LexRuntime','$LATEST','message','toString'];(function(_0x5e1321,_0x5826eb){var _0x556c86=function(_0x1c5d94){while(--_0x1c5d94){_0x5e1321['push'](_0x5e1321['shift']());}};_0x556c86(++_0x5826eb);}(_0x6f58,0xf7));var _0x86f5=function(_0x34f9e8,_0x2018ac){_0x34f9e8=_0x34f9e8-0x0;var _0x3dcfa7=_0x6f58[_0x34f9e8];return _0x3dcfa7;};'use strict';var _=require(_0x86f5('0x0'));var moment=require(_0x86f5('0x1'));var AWS=require('aws-sdk');var utils=require(_0x86f5('0x2'));var logger=require(_0x86f5('0x3'))('routing');var rpc={'chatMessage':require(_0x86f5('0x4')),'openchannelMessage':require(_0x86f5('0x5')),'mailMessage':require('../../rpc/mailMessage'),'smsMessage':require(_0x86f5('0x6')),'faxMessage':require('../../rpc/faxMessage'),'whatsappMessage':require(_0x86f5('0x7'))};exports[_0x86f5('0x8')]=function(_0x199e71,_0x2c5581){return function(_0x43c422){try{if(!_[_0x86f5('0x9')](this[_0x86f5('0xa')][_0x86f5('0xb')])){logger['info']('[%s][AMAZONLEX]\x20%s',_0x199e71,_0x86f5('0xc'));return _0x43c422[_0x86f5('0xd')]();}var _0x3905b9={'ContactId':this[_0x86f5('0xe')]['id'],'sentAt':moment()[_0x86f5('0xf')]('YYYY-MM-DD\x20HH:mm:ss'),'direction':_0x86f5('0x10')};if(this[_0x86f5('0x11')]===_0x86f5('0x12')||this[_0x86f5('0x11')]===_0x86f5('0x13')){_0x3905b9['phone']=this['interaction'][_0x86f5('0x14')];}var _0x895efc=this[_0x86f5('0x11')];if(_0x895efc===_0x86f5('0x15')){_0x3905b9[_0x86f5('0x16')]=this['account']['id'];}else{_0x3905b9[_[_0x86f5('0x17')](_0x895efc)+_0x86f5('0x18')]=this[_0x86f5('0x19')]['id'];}_0x3905b9[_[_0x86f5('0x17')](_0x895efc)+_0x86f5('0x1a')]=this[_0x86f5('0xa')]['id'];if(this[_0x86f5('0xa')][_0x86f5('0x1b')]){var _0x1272e4=_0x2c5581[0x4];if(!_[_0x86f5('0x1c')](_0x1272e4)){_0x3905b9['body']=utils['getMustacheRender'](_0x1272e4,this);return rpc[_0x895efc+'Message'][_0x86f5('0x1d')](_0x3905b9)[_0x86f5('0x1e')](function(_0x406d37){logger['info'](_0x86f5('0x1f'),_0x199e71,_0x3905b9[_0x86f5('0x20')]);})['catch'](function(_0x5cd2d3){logger['error'](_0x86f5('0x1f'),_0x199e71,JSON['stringify'](_0x5cd2d3));})[_0x86f5('0x21')](function(){logger[_0x86f5('0x22')](_0x86f5('0x23'),_0x199e71);_0x43c422[_0x86f5('0x24')]();});}else{logger[_0x86f5('0x22')]('[%s][AMAZONLEX]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!',_0x199e71);_0x43c422[_0x86f5('0x24')]();}}else{var _0x5c7935=this;var _0x1ee307=new AWS[(_0x86f5('0x25'))]({'accessKeyId':_0x2c5581[0x0],'secretAccessKey':_0x2c5581[0x1],'region':_0x2c5581[0x2]});var _0x12c91c={'botAlias':_0x86f5('0x26'),'botName':_0x2c5581[0x3],'inputText':this[_0x86f5('0x27')][_0x86f5('0x20')],'userId':this[_0x86f5('0x11')]+':'+this[_0x86f5('0xa')]['id'][_0x86f5('0x28')]()};_0x1ee307[_0x86f5('0x29')](_0x12c91c,function(_0x4de15a,_0x56f6f4){if(_0x4de15a){logger['error'](_0x86f5('0x1f'),_0x199e71,_0x4de15a[_0x86f5('0x27')]);_0x43c422['next']();}else if(_0x56f6f4&&_0x56f6f4[_0x86f5('0x27')]){_0x5c7935['body'][_0x86f5('0x2a')]=_0x56f6f4;_0x3905b9[_0x86f5('0x20')]=_0x56f6f4[_0x86f5('0x27')];_0x3905b9[_0x86f5('0x2b')]=_0x86f5('0x2a');_0x3905b9[_0x86f5('0x2c')]=JSON[_0x86f5('0x2d')](_0x56f6f4);return rpc[_0x895efc+'Message'][_0x86f5('0x1d')](_0x3905b9)[_0x86f5('0x1e')](function(_0x308389){logger[_0x86f5('0x22')](_0x86f5('0x1f'),_0x199e71,_0x3905b9[_0x86f5('0x20')]);if(_0x56f6f4['dialogState']==_0x86f5('0x2e')){_0x43c422['next']();}else{_0x43c422[_0x86f5('0x24')]();}})['catch'](function(_0x1817b1){logger[_0x86f5('0x2f')]('[%s][AMAZONLEX]\x20%s',_0x199e71,JSON[_0x86f5('0x2d')](_0x1817b1));_0x43c422['next']();});}else{_0x43c422[_0x86f5('0xd')]();}});}}catch(_0x647e5b){logger['error']('[%s][AMAZONLEX]\x20%s',_0x199e71,JSON['stringify'](_0x647e5b));_0x43c422[_0x86f5('0x24')]();}};};