33b6d3fba3415592c1f6880b120b12356170f19e
[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 _0xadc8=['then','catch','error','stringify','[%s][AMAZONLEX]\x20Welcome\x20Message\x20has\x20been\x20sent!','stop','[%s][AMAZONLEX]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!','$LATEST','toString','postText','message','amazonlex','providerResponse','Message','dialogState','Failed','moment','aws-sdk','./utils','routing','../../rpc/openchannelMessage','../../rpc/mailMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','consequence','isNil','interaction','UserId','info','[%s][AMAZONLEX]\x20%s','next','format','YYYY-MM-DD\x20HH:mm:ss','out','channel','phone','chat','ChatWebsiteId','account','upperFirst','AccountId','InteractionId','created','isEmpty','body','create'];(function(_0x3ff4a3,_0xa5bfa6){var _0x38676f=function(_0x3ab2b1){while(--_0x3ab2b1){_0x3ff4a3['push'](_0x3ff4a3['shift']());}};_0x38676f(++_0xa5bfa6);}(_0xadc8,0x152));var _0x8adc=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0xadc8[_0x3dd15e];return _0x231fd0;};'use strict';var _=require('lodash');var moment=require(_0x8adc('0x0'));var AWS=require(_0x8adc('0x1'));var utils=require(_0x8adc('0x2'));var logger=require('../../../../config/logger')(_0x8adc('0x3'));var rpc={'chatMessage':require('../../rpc/chatMessage'),'openchannelMessage':require(_0x8adc('0x4')),'mailMessage':require(_0x8adc('0x5')),'smsMessage':require('../../rpc/smsMessage'),'faxMessage':require(_0x8adc('0x6')),'whatsappMessage':require(_0x8adc('0x7'))};exports[_0x8adc('0x8')]=function(_0x128bf1,_0x5cfbce){return function(_0x591d50){try{if(!_[_0x8adc('0x9')](this[_0x8adc('0xa')][_0x8adc('0xb')])){logger[_0x8adc('0xc')](_0x8adc('0xd'),_0x128bf1,'Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.');return _0x591d50[_0x8adc('0xe')]();}var _0x36f6d3={'ContactId':this['contact']['id'],'sentAt':moment()[_0x8adc('0xf')](_0x8adc('0x10')),'direction':_0x8adc('0x11')};if(this[_0x8adc('0x12')]==='sms'||this['channel']==='whatsapp'){_0x36f6d3[_0x8adc('0x13')]=this[_0x8adc('0xa')][_0x8adc('0x13')];}var _0xe24aed=this[_0x8adc('0x12')];if(_0xe24aed===_0x8adc('0x14')){_0x36f6d3[_0x8adc('0x15')]=this[_0x8adc('0x16')]['id'];}else{_0x36f6d3[_[_0x8adc('0x17')](_0xe24aed)+_0x8adc('0x18')]=this[_0x8adc('0x16')]['id'];}_0x36f6d3[_[_0x8adc('0x17')](_0xe24aed)+_0x8adc('0x19')]=this[_0x8adc('0xa')]['id'];if(this[_0x8adc('0xa')][_0x8adc('0x1a')]){var _0x2a9af4=_0x5cfbce[0x4];if(!_[_0x8adc('0x1b')](_0x2a9af4)){_0x36f6d3[_0x8adc('0x1c')]=utils['getMustacheRender'](_0x2a9af4,this);return rpc[_0xe24aed+'Message'][_0x8adc('0x1d')](_0x36f6d3)[_0x8adc('0x1e')](function(_0x4f9845){logger[_0x8adc('0xc')]('[%s][AMAZONLEX]\x20%s',_0x128bf1,_0x36f6d3[_0x8adc('0x1c')]);})[_0x8adc('0x1f')](function(_0x255814){logger[_0x8adc('0x20')](_0x8adc('0xd'),_0x128bf1,JSON[_0x8adc('0x21')](_0x255814));})['finally'](function(){logger[_0x8adc('0xc')](_0x8adc('0x22'),_0x128bf1);_0x591d50[_0x8adc('0x23')]();});}else{logger[_0x8adc('0xc')](_0x8adc('0x24'),_0x128bf1);_0x591d50[_0x8adc('0x23')]();}}else{var _0x1b4760=this;var _0xfde59f=new AWS['LexRuntime']({'accessKeyId':_0x5cfbce[0x0],'secretAccessKey':_0x5cfbce[0x1],'region':_0x5cfbce[0x2]});var _0x370505={'botAlias':_0x8adc('0x25'),'botName':_0x5cfbce[0x3],'inputText':this['message']['body'],'userId':this[_0x8adc('0x12')]+':'+this[_0x8adc('0xa')]['id'][_0x8adc('0x26')]()};_0xfde59f[_0x8adc('0x27')](_0x370505,function(_0x6a9477,_0x4e1716){if(_0x6a9477){logger[_0x8adc('0x20')](_0x8adc('0xd'),_0x128bf1,_0x6a9477[_0x8adc('0x28')]);_0x591d50[_0x8adc('0xe')]();}else if(_0x4e1716&&_0x4e1716[_0x8adc('0x28')]){_0x1b4760[_0x8adc('0x1c')][_0x8adc('0x29')]=_0x4e1716;_0x36f6d3['body']=_0x4e1716[_0x8adc('0x28')];_0x36f6d3['providerName']=_0x8adc('0x29');_0x36f6d3[_0x8adc('0x2a')]=JSON[_0x8adc('0x21')](_0x4e1716);return rpc[_0xe24aed+_0x8adc('0x2b')][_0x8adc('0x1d')](_0x36f6d3)[_0x8adc('0x1e')](function(_0x3d6349){logger[_0x8adc('0xc')]('[%s][AMAZONLEX]\x20%s',_0x128bf1,_0x36f6d3[_0x8adc('0x1c')]);if(_0x4e1716[_0x8adc('0x2c')]==_0x8adc('0x2d')){_0x591d50[_0x8adc('0xe')]();}else{_0x591d50[_0x8adc('0x23')]();}})[_0x8adc('0x1f')](function(_0x14bed3){logger['error'](_0x8adc('0xd'),_0x128bf1,JSON[_0x8adc('0x21')](_0x14bed3));_0x591d50[_0x8adc('0xe')]();});}else{_0x591d50['next']();}});}}catch(_0xeb12f8){logger[_0x8adc('0x20')](_0x8adc('0xd'),_0x128bf1,JSON[_0x8adc('0x21')](_0xeb12f8));_0x591d50['stop']();}};};