26e4780578e5e8a9831190792c2589a71d19d030
[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 _0x31f0=['[%s][AMAZONLEX]\x20Welcome\x20Message\x20has\x20been\x20sent!','stop','[%s][AMAZONLEX]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!','$LATEST','message','postText','amazonlex','dialogState','Failed','catch','error','lodash','aws-sdk','../../../../config/logger','routing','../../rpc/chatMessage','../../rpc/openchannelMessage','../../rpc/smsMessage','../../rpc/faxMessage','isNil','interaction','UserId','info','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','next','contact','format','YYYY-MM-DD\x20HH:mm:ss','out','chat','ChatWebsiteId','account','upperFirst','AccountId','created','isEmpty','Message','create','then','[%s][AMAZONLEX]\x20%s','body','stringify','finally'];(function(_0x2653ac,_0x338212){var _0x14a4ba=function(_0xccd7ed){while(--_0xccd7ed){_0x2653ac['push'](_0x2653ac['shift']());}};_0x14a4ba(++_0x338212);}(_0x31f0,0xb7));var _0x031f=function(_0x2edb1b,_0x32267f){_0x2edb1b=_0x2edb1b-0x0;var _0x481926=_0x31f0[_0x2edb1b];return _0x481926;};'use strict';var _=require(_0x031f('0x0'));var moment=require('moment');var AWS=require(_0x031f('0x1'));var utils=require('./utils');var logger=require(_0x031f('0x2'))(_0x031f('0x3'));var rpc={'chatMessage':require(_0x031f('0x4')),'openchannelMessage':require(_0x031f('0x5')),'mailMessage':require('../../rpc/mailMessage'),'smsMessage':require(_0x031f('0x6')),'faxMessage':require(_0x031f('0x7')),'whatsappMessage':require('../../rpc/whatsappMessage')};exports['consequence']=function(_0x56328c,_0x3dc98e){return function(_0x487e65){try{if(!_[_0x031f('0x8')](this[_0x031f('0x9')][_0x031f('0xa')])){logger[_0x031f('0xb')]('[%s][AMAZONLEX]\x20%s',_0x56328c,_0x031f('0xc'));return _0x487e65[_0x031f('0xd')]();}var _0x327f11={'ContactId':this[_0x031f('0xe')]['id'],'sentAt':moment()[_0x031f('0xf')](_0x031f('0x10')),'direction':_0x031f('0x11')};var _0x3fd541=this['channel'];if(_0x3fd541===_0x031f('0x12')){_0x327f11[_0x031f('0x13')]=this[_0x031f('0x14')]['id'];}else{_0x327f11[_[_0x031f('0x15')](_0x3fd541)+_0x031f('0x16')]=this[_0x031f('0x14')]['id'];}_0x327f11[_[_0x031f('0x15')](_0x3fd541)+'InteractionId']=this[_0x031f('0x9')]['id'];if(this[_0x031f('0x9')][_0x031f('0x17')]){var _0x2e3dfe=_0x3dc98e[0x4];if(!_[_0x031f('0x18')](_0x2e3dfe)){_0x327f11['body']=utils['getMustacheRender'](_0x2e3dfe,this);return rpc[_0x3fd541+_0x031f('0x19')][_0x031f('0x1a')](_0x327f11)[_0x031f('0x1b')](function(_0x286177){logger['info'](_0x031f('0x1c'),_0x56328c,_0x327f11[_0x031f('0x1d')]);})['catch'](function(_0xcdae16){logger['error'](_0x031f('0x1c'),_0x56328c,JSON[_0x031f('0x1e')](_0xcdae16));})[_0x031f('0x1f')](function(){logger[_0x031f('0xb')](_0x031f('0x20'),_0x56328c);_0x487e65[_0x031f('0x21')]();});}else{logger[_0x031f('0xb')](_0x031f('0x22'),_0x56328c);_0x487e65[_0x031f('0x21')]();}}else{var _0x345bde=this;var _0x29dd6e=new AWS['LexRuntime']({'accessKeyId':_0x3dc98e[0x0],'secretAccessKey':_0x3dc98e[0x1],'region':_0x3dc98e[0x2]});var _0xf72793={'botAlias':_0x031f('0x23'),'botName':_0x3dc98e[0x3],'inputText':this[_0x031f('0x24')]['body'],'userId':this['channel']+':'+this[_0x031f('0x9')]['id']['toString']()};_0x29dd6e[_0x031f('0x25')](_0xf72793,function(_0x57f6c4,_0x54d054){if(_0x57f6c4){logger['error'](_0x031f('0x1c'),_0x56328c,_0x57f6c4[_0x031f('0x24')]);_0x487e65[_0x031f('0xd')]();}else if(_0x54d054&&_0x54d054[_0x031f('0x24')]){_0x345bde['body'][_0x031f('0x26')]=_0x54d054;_0x327f11['body']=_0x54d054[_0x031f('0x24')];return rpc[_0x3fd541+_0x031f('0x19')][_0x031f('0x1a')](_0x327f11)['then'](function(_0x35af16){logger[_0x031f('0xb')]('[%s][AMAZONLEX]\x20%s',_0x56328c,_0x327f11[_0x031f('0x1d')]);if(_0x54d054[_0x031f('0x27')]==_0x031f('0x28')){_0x487e65['next']();}else{_0x487e65[_0x031f('0x21')]();}})[_0x031f('0x29')](function(_0xb6ed6c){logger[_0x031f('0x2a')](_0x031f('0x1c'),_0x56328c,JSON[_0x031f('0x1e')](_0xb6ed6c));_0x487e65['next']();});}else{_0x487e65[_0x031f('0xd')]();}});}}catch(_0xab24ad){logger[_0x031f('0x2a')](_0x031f('0x1c'),_0x56328c,JSON[_0x031f('0x1e')](_0xab24ad));_0x487e65[_0x031f('0x21')]();}};};