aws-lambda - 在来自 Lambda 的 Amazon lex 响应中呈现 HTML
问题描述
我是 Amazon Lex 的新手。我正在尝试将超链接作为从 Lambda 函数到 Amazon Lex 的“内容”响应的一部分返回。基本上我做了以下事情:
var message = {
'contentType': 'PlainText',
'content': 'We offer x,y,z. For more information, visit our <a href="www.xyz.com">website</a>'
}
这会将整个响应作为字符串返回,而我希望在聊天机器人上显示之前呈现 html 部分。我不想在我的回复下方使用 responseCard。是否可以在返回的内容中包含超链接?谢谢
解决方案
请注意,这是为了在 HTML 页面上呈现对话
当我开发一个 HTML 页面来呈现用户和聊天机器人之间的聊天时,我遇到了同样的问题。我设法使用以下Javascript函数解决了它:
function showResponse(lexResponse) {
var conversationDiv = document.getElementById('conversation');
var responsePara = document.createElement("P");
responsePara.className = 'lexResponse';
if (lexResponse.message) {
var message = lexResponse.message.replace(/"/g, '\'');
responsePara.innerHTML = message;
responsePara.appendChild(document.createElement('br'));
}
conversationDiv.appendChild(responsePara);
conversationDiv.scrollTop = conversationDiv.scrollHeight;
}
作为参考,您可以参考我就同一问题提出的问题:LexResponse output does not understand HTML data
推荐阅读
- javascript - Discord.js 尝试向用户发送消息时出现“意外标识符”
- python - django 管理数据未在数据库中注册
- spring - Spring Boot数据sql镜像文件
- nuxt.js - 在页面刷新时,在 SSR 模式下使用 Nuxt 时,我们应该在哪里调用获取令牌或用户详细信息 API?
- postgresql - 使用 Knex 在一个语句中更新多行
- c# - 使用 .Net Core 3.1 Razor Pages 应用程序访问类中的会话
- excel - 通过在多张纸上打印区域
- node.js - 将一个简单的 React 表单应用程序添加到现有的 Nodejs docker 映像中
- php - 试图理解我的 Apache 错误日志中的 php 警告
- excel - VBA 用户表单 (Excel) 的字体和大小相同,但以不同的大小显示