5e97e9c16ed4829b9963971cec096e321ee2bb92
[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 _0x91f7=['AccountId','account','InteractionId','created','body','getMustacheRender','Message','create','then','catch','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','amazonlex','providerName','dialogState','Failed','error','stringify','lodash','moment','aws-sdk','routing','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/whatsappMessage','isNil','UserId','info','[%s][AMAZONLEX]\x20%s','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','next','contact','format','out','channel','sms','whatsapp','phone','interaction','chat','upperFirst'];(function(_0x519232,_0xab07a3){var _0x20d2b4=function(_0x33c7e9){while(--_0x33c7e9){_0x519232['push'](_0x519232['shift']());}};_0x20d2b4(++_0xab07a3);}(_0x91f7,0x169));var _0x791f=function(_0x1fef04,_0xf85322){_0x1fef04=_0x1fef04-0x0;var _0x1ad24c=_0x91f7[_0x1fef04];return _0x1ad24c;};'use strict';var _=require(_0x791f('0x0'));var moment=require(_0x791f('0x1'));var AWS=require(_0x791f('0x2'));var utils=require('./utils');var logger=require('../../../../config/logger')(_0x791f('0x3'));var rpc={'chatMessage':require('../../rpc/chatMessage'),'openchannelMessage':require(_0x791f('0x4')),'mailMessage':require(_0x791f('0x5')),'smsMessage':require('../../rpc/smsMessage'),'faxMessage':require('../../rpc/faxMessage'),'whatsappMessage':require(_0x791f('0x6'))};exports['consequence']=function(_0x1fd16f,_0x481ab5){return function(_0x441faa){try{if(!_[_0x791f('0x7')](this['interaction'][_0x791f('0x8')])){logger[_0x791f('0x9')](_0x791f('0xa'),_0x1fd16f,_0x791f('0xb'));return _0x441faa[_0x791f('0xc')]();}var _0x15aba1={'ContactId':this[_0x791f('0xd')]['id'],'sentAt':moment()[_0x791f('0xe')]('YYYY-MM-DD\x20HH:mm:ss'),'direction':_0x791f('0xf')};if(this[_0x791f('0x10')]===_0x791f('0x11')||this[_0x791f('0x10')]===_0x791f('0x12')){_0x15aba1[_0x791f('0x13')]=this[_0x791f('0x14')][_0x791f('0x13')];}var _0x29c6c1=this[_0x791f('0x10')];if(_0x29c6c1===_0x791f('0x15')){_0x15aba1['ChatWebsiteId']=this['account']['id'];}else{_0x15aba1[_[_0x791f('0x16')](_0x29c6c1)+_0x791f('0x17')]=this[_0x791f('0x18')]['id'];}_0x15aba1[_[_0x791f('0x16')](_0x29c6c1)+_0x791f('0x19')]=this['interaction']['id'];if(this[_0x791f('0x14')][_0x791f('0x1a')]){var _0x21d669=_0x481ab5[0x4];if(!_['isEmpty'](_0x21d669)){_0x15aba1[_0x791f('0x1b')]=utils[_0x791f('0x1c')](_0x21d669,this);return rpc[_0x29c6c1+_0x791f('0x1d')][_0x791f('0x1e')](_0x15aba1)[_0x791f('0x1f')](function(_0x22862e){logger['info'](_0x791f('0xa'),_0x1fd16f,_0x15aba1['body']);})[_0x791f('0x20')](function(_0x5fd938){logger['error'](_0x791f('0xa'),_0x1fd16f,JSON['stringify'](_0x5fd938));})[_0x791f('0x21')](function(){logger[_0x791f('0x9')](_0x791f('0x22'),_0x1fd16f);_0x441faa[_0x791f('0x23')]();});}else{logger['info'](_0x791f('0x24'),_0x1fd16f);_0x441faa['stop']();}}else{var _0x415e4b=this;var _0x4f5d16=new AWS[(_0x791f('0x25'))]({'accessKeyId':_0x481ab5[0x0],'secretAccessKey':_0x481ab5[0x1],'region':_0x481ab5[0x2]});var _0x24ab56={'botAlias':_0x791f('0x26'),'botName':_0x481ab5[0x3],'inputText':this[_0x791f('0x27')]['body'],'userId':this['channel']+':'+this[_0x791f('0x14')]['id'][_0x791f('0x28')]()};_0x4f5d16[_0x791f('0x29')](_0x24ab56,function(_0x17a61a,_0x2701d3){if(_0x17a61a){logger['error']('[%s][AMAZONLEX]\x20%s',_0x1fd16f,_0x17a61a[_0x791f('0x27')]);_0x441faa[_0x791f('0xc')]();}else if(_0x2701d3&&_0x2701d3['message']){_0x415e4b['body'][_0x791f('0x2a')]=_0x2701d3;_0x15aba1[_0x791f('0x1b')]=_0x2701d3[_0x791f('0x27')];_0x15aba1[_0x791f('0x2b')]='amazonlex';_0x15aba1['providerResponse']=JSON['stringify'](_0x2701d3);return rpc[_0x29c6c1+_0x791f('0x1d')][_0x791f('0x1e')](_0x15aba1)['then'](function(_0x173bdc){logger[_0x791f('0x9')](_0x791f('0xa'),_0x1fd16f,_0x15aba1['body']);if(_0x2701d3[_0x791f('0x2c')]==_0x791f('0x2d')){_0x441faa[_0x791f('0xc')]();}else{_0x441faa[_0x791f('0x23')]();}})['catch'](function(_0x38b198){logger[_0x791f('0x2e')](_0x791f('0xa'),_0x1fd16f,JSON['stringify'](_0x38b198));_0x441faa[_0x791f('0xc')]();});}else{_0x441faa[_0x791f('0xc')]();}});}}catch(_0x2e1578){logger[_0x791f('0x2e')](_0x791f('0xa'),_0x1fd16f,JSON[_0x791f('0x2f')](_0x2e1578));_0x441faa['stop']();}};};