[英]How to have cancel button in Adaptive cards to be displayed in Web Channel chat bot developed in MS Bot framework SDK V4 in C#?
[英]Is there a way to enable calendar option as an input in V4 chat bot C# other than using Adaptive cards?
有没有办法启用日期和时间输入,换言之,聊天Bot中的日历选项,而不使用自适应卡,我从下面的链接了解除了Microsoft通道以外的所有通道都不支持自适应卡。
如何添加通过卡片中的提示选项显示的自定义选项和选择时的触发操作使用c#单击BOT V4?
我使用以下输入启用了自适应卡:
[BotFramework]:如何在瀑布对话框中捕获/提取通过C#Web Chat bot中呈现的自适应卡提交的值?
然后我的查询:我是如何在BOT中启用日期时间输入而不是使用Hero Card或任何其他卡(自适应卡除外)等自适应卡?
语言:C#SDK:V4频道:Web聊天频道部署在:Azure
如果有一种方式我请求你请提供详细的分步指南,因为我是BOT和编码的新手。
谢谢和问候-ChaitanyaNG
我无法从GitHub尝试以下内容,因为这与React有关,但我的代码是用AZURE的C#和SDK V4编写的:
预期结果:显示日历选项和时间选项以选择日期和时间,以便我可以捕获输入值并在瀑布对话框C#中继续我的过程
实际结果:无法实现此功能,因为Web聊天频道似乎不支持自适应卡,仅支持Skype等Microsoft频道
@ mrichardson-MSFT:感谢所有的帮助,直到现在。
问题描述:
我有BOT程序有多个瀑布对话框类最后一个对话框类STEP#1:我正在显示自适应卡,其中两个日期和时间输入一个用于启动,另一个用于停止实际结果:自适应在模拟器和Web聊天中都成功显示没有任何问题的通道步骤#2:当我点击步骤1中显示的自适应卡上的SetSchedule时,应该在步骤#2中捕获值并显示在屏幕上实际结果 :在模拟器中工作得很好但在Web Chat通道bot中没有。 我在网聊渠道BOT中收到错误。 请查找用于访问bot的HTML文件,瀑布对话框类和附加的自适应卡json文件以供参考。 除此之外,请在网络聊天频道中找到错误截图,以供参考。
您是否可以指导我解决此问题,就像您在签到问题时所做的那样? 请求你的直接帮助这是阻碍我的工作。
谢谢和问候-ChaitanyaNG
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" }
尝试两次时出现错误消息: 首先尝试 {error:{code:“BotError”,消息:“无法发送活动:bot超时”},httpStatusCode:504}错误:{code:“BotError”,消息:“失败发送活动:机器人超时“}代码:”BotError“消息:”无法发送活动:机器人超时“httpStatusCode:504
SecondTry {error:{code:“BotError”,message:“无法发送活动:bot返回错误”},...}错误:{code:“BotError”,消息:“无法发送活动:bot返回错误”代码:“BotError”消息:“无法发送活动:bot返回错误”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://docs.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://docs.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>
简短的回答是此功能不可用。 自适应卡是任何类型的基于UI的日期/时间选择器的最佳途径。 是的,微软渠道(包括WebChat)完全支持自适应卡,而其他渠道则不太受支持。
您拥有的最佳选择是使用DateTime提示 。
实现这一点的方法有很多不同的复杂方法,但虚拟助手日历技能使用它非常广泛。 它的DatePrompt和TimePrompt可能是很好的起点。
CoreBot还有一个可能有用的DateResolverDialog ,并且更容易理解。
DateTime在聊天机器人中非常复杂,因为“周三4点”可能意味着周三凌晨4点或下午4点。 如果您要使用基于文本的输入, Timex Resolution Sample应提供额外的处理方法。
由于您的其他问题 ,这可能不适用于WebChat。 我刚刚测试了此卡的日期和时间输入,它正在工作:
{
"type": "AdaptiveCard",
"actions": [{
"type": "Action.Submit",
"id": "submit",
"title": "Submit"
}],
"body": [
{
"type": "Input.Date",
"id": "date",
"title": "New Input.Toggle"
},
{
"type": "Container",
"items": [
{
"type": "Input.Time",
"id": "time",
"title": "New Input.Toggle"
}
]
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.0"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.