有没有办法在聊天机器人中启用日期和时间输入(即日历选项)而不使用自适应卡,正如我从下面的链接中了解到的,除 Microsoft 渠道外,所有渠道均不支持自适应卡。
如何使用 C# 添加通过卡片内的提示选项显示的自定义选项以及在 BOT V4 中单击选择时触发操作?
我使用以下输入启用了自适应卡:
[BotFramework]:如何捕获/提取通过在瀑布对话框中的 C# Web 聊天机器人中呈现的自适应卡提交的值?
然后我的问题是:除了使用英雄卡等自适应卡或任何其他卡(自适应卡除外)之外,如何在 BOT 中启用日期时间输入?
语言:C#
软件开发工具包:V4
渠道:网络聊天渠道
部署在:Azure
如果有办法,我要求您提供详细的分步指南,因为我是 BOT 和编码的新手。
感谢和问候
-ChaitanyanNG
我无法尝试 GitHub 上的以下内容,因为这与 React 有关,但我的代码是用 C# 和 AZURE 的 SDK V4 编写的:
https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/10.a.customization-card-components
预期结果:显示日历选项和时间选项来选择日期和时间,以便我可以捕获输入值并在瀑布对话框 C# 中继续我的过程
实际结果:无法实现,因为自适应卡似乎在网络聊天渠道中不受支持,仅在 Skype 等 Microsoft 渠道中受支持
@mrichardson-MSFT:感谢迄今为止的所有帮助。
问题描述:
我有带有多个瀑布对话框类的 BOT 程序,最后一个对话框类STEP #1:我展示了带有两个日期和时间输入的自适应卡,一个用于开始,另一个用于停止实际结果:自适应在模拟器和网络聊天频道中均成功显示,没有任何问题STEP #2:当我单击步骤 1 中显示的自适应卡上的 SetSchedule 时,应在步骤 #2 中捕获值并显示在屏幕上实际结果:
在模拟器中工作得很好,但在网络聊天频道机器人中却不行。我在网络聊天频道 BOT 中收到错误。
请找到用于访问机器人的 HTML 文件、瀑布对话框类和随附的自适应卡 json 文件以供参考。请同时找到网络聊天频道中附加的错误屏幕截图以供参考。
您能否像解决登录问题一样指导我解决此问题?请求您立即提供帮助,这阻碍了我的工作。
感谢和问候
-ChaitanyanNG
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Schema;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace EchoBot.Dialogs
{
public class Adaptivecarddialog : WaterfallDialog
{
public const string cards = @"./AdaptiveCard.json";
public Adaptivecarddialog(string dialogId, IEnumerable<WaterfallStep> steps = null)
: base(dialogId, steps)
{
AddStep(async (stepContext, cancellationToken) =>
{
var cardAttachment = CreateAdaptiveCardAttachment(cards);
var reply = stepContext.Context.Activity.CreateReply();
reply.Attachments = new List<Attachment>() { cardAttachment };
await stepContext.Context.SendActivityAsync(reply, cancellationToken);
var opts = new PromptOptions
{
Prompt = new Activity
{
Type = ActivityTypes.Message,
// You can comment this out if you don't want to display any text. Still works.
}
};
// Display a Text Prompt and wait for input
return await stepContext.PromptAsync(nameof(TextPrompt), opts);
});
AddStep(async (stepContext, cancellationToken) =>
{
var res = stepContext.Result.ToString();
dynamic jobject = JsonConvert.DeserializeObject(res);
string NewStartDateTime = jobject.Startdate + " " + jobject.Starttime;
string NewStopDateTime = jobject.Stopdate + " " + jobject.Stoptime;
await stepContext.Context.SendActivityAsync($"StartDateTime:{NewStartDateTime}", cancellationToken: cancellationToken);
await stepContext.Context.SendActivityAsync($"StopDateTime:{NewStopDateTime}", cancellationToken: cancellationToken);
return await stepContext.EndDialogAsync();
});
}
public static new string Id => "Adaptivecarddialog";
public static Adaptivecarddialog Instance { get; } = new Adaptivecarddialog(Id);
public static Attachment CreateAdaptiveCardAttachment(string filePath)
{
var adaptiveCardJson = File.ReadAllText(filePath);
var adaptiveCardAttachment = new Attachment()
{
ContentType = "application/vnd.microsoft.card.adaptive",
Content = JsonConvert.DeserializeObject(adaptiveCardJson),
};
return adaptiveCardAttachment;
}
}
}
{
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"id": "Start date text",
"separator": true,
"text": "Schedule Start DateTime:"
},
{
"type": "Input.Date",
"id": "Startdate",
"separator": true,
"value": "2019-05-24"
},
{
"type": "Input.Time",
"id": "Starttime",
"separator": true,
"value": "08:00"
},
{
"type": "TextBlock",
"id": "Stop date text",
"separator": true,
"text": "Schedule Stop DateTime:"
},
{
"type": "Input.Date",
"id": "Stopdate",
"separator": true,
"value": "2019-05-25"
},
{
"type": "Input.Time",
"id": "Stoptime",
"separator": true,
"value": "08:00"
}
],
"actions": [
{
"type": "Action.Submit",
"id": "SubmitBtn",
"title": "SetSchedule"
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.0"
}
尝试两次时出现错误消息:第一次尝试{错误:{代码:“BotError”,消息:“发送活动失败:机器人超时”},httpStatusCode:504}
错误:{代码:“BotError”,消息:“发送活动失败:机器人超时”}
代码:“机器人错误”
消息:“发送活动失败:机器人超时”
http状态代码:504
SecondTry
{error: {code: "BotError", message: "Failed to send activity: bot returned an error"},…}
error: {code: "BotError", message: "Failed to send activity: bot returned an error"}
code: "BotError"
message: "Failed to send activity: bot returned an error"
httpStatusCode: 500
HTML 文件:
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Web Chat: Custom style options</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--
For demonstration purposes, we are using the development branch of Web Chat at "/master/webchat.js".
When you are using Web Chat for production, you should use the latest stable release at "/latest/webchat.js",
or lock down on a specific version with the following format: "/4.1.0/webchat.js".
-->
<script src="https://cdn.botframework.com/botframework-webchat/master/webchat.js"></script>
<style>
html, body {
height: 100%
}
body {
margin: 0
}
#webchat {
height: 100%;
width: 100%;
}
</style>
</head>
<body>
<div id="webchat" role="main">
</div>
<script>
(async function () {
// In this demo, we are using Direct Line token from MockBot.
// To talk to your bot, you should use the token exchanged using your Direct Line secret.
// You should never put the Direct Line secret in the browser or client app.
// https://learn.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-authentication
// Token is found by going to Azure Portal > Your Web App Bot > Channels > Web Chat - Edit > Secret Keys - Show
// It looks something like this: pD*********xI.8ZbgTHof3GL_nM5***********aggt5qLOBrigZ8
const token = '<<Your Direct Line Secret Key>>';
// You can modify the style set by providing a limited set of style options
const styleOptions = {
botAvatarImage: 'https://learn.microsoft.com/en-us/azure/bot-service/v4sdk/media/logo_bot.svg?view=azure-bot-service-4.0',
botAvatarInitials: 'BF',
userAvatarImage: 'https://avatars1.githubusercontent.com/u/45868722?s=96&v=4',
userAvatarInitials: 'WC',
bubbleBackground: 'rgba(0, 0, 255, .1)',
bubbleFromUserBackground: 'rgba(0, 255, 0, .1)'
};
// We are using a customized store to add hooks to connect event
const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
// When we receive DIRECT_LINE/CONNECT_FULFILLED action, we will send an event activity using WEB_CHAT/SEND_EVENT
dispatch({
type: 'WEB_CHAT/SEND_EVENT',
payload: {
name: 'webchat/join',
value: { language: window.navigator.language }
}
});
}
return next(action);
});
window.WebChat.renderWebChat({
directLine: window.WebChat.createDirectLine({ token }),
styleOptions,store
}, document.getElementById('webchat'));
document.querySelector('#webchat > *').focus();
})().catch(err => console.error(err));
</script>
</body>
</html>