显示文字不会回显
我正在创建一个带有标题,DisplayText,文本和值的Messageback按钮(v3 SDK).运行机器人时,标题已正确设置,单击按钮后未显示显示文本.
I am creating a Messageback Button with Title, DisplayText, text, and value (v3 SDK). The title is set correctly when running the bot, the display text did not appear after clicking the button.
我设置了两张卡片动作.
I have set up two card action.
CardAction yesBtn = new CardAction()
{
Type = ActionTypes.MessageBack,
Title = "Yes",
DisplayText = "OK",
Text = "Yes",
};
CardAction noBtn = new CardAction()
{
Type = ActionTypes.MessageBack,
Title = "No",
DisplayText = "No",
Text = "No",
};
我找不到解决此问题的任何方法. 最相似的是: CardAction DisplayText似乎不起作用 但没有答案.
I cannot find any solution to this problem. The most similar one is : CardAction DisplayText doesn't seem to work but there is no answer.
Microsoft bot框架的文档说
The document of Microsoft bot framework said
displayText
选修的.执行该操作时,用户已将其回呼到聊天流中.该文本不会发送到您的机器人.
displayText
Optional. Echoed by the user into the chat stream when the action is performed. This text is not sent to your bot.
但是单击按钮后什么也没有发生.
but nothing happens after clicking the button.
我还尝试了imBack ActionType,结果是相同的.
I also tried the imBack ActionType, and the result is the same.
我在bot模拟器和azure门户上对其进行了测试,两者均无法正常工作.
I test it on the bot emulator and azure portal, both don't work.
卡行为本质上是特定于渠道的.
无论卡类型,操作类型或通道如何,这都是正确的.虽然某些准则适用于例如卡片操作的属性,但您确实不能依赖像displayText
这样的属性来表现您期望的行为.您需要自己测试卡.以下是一些代码,可帮助您测试各种卡片操作类型和属性:
This is true across the board, regardless of card type, action type, or channel. While certain guidelines apply to, say, the properties of card actions, you really can't depend on a property like displayText
behaving the way you expect it to. You need to test the card yourself. Here's some code that will help you test a variety of card action types and properties:
var actionTypes = new List<string>
{
ActionTypes.ImBack,
ActionTypes.PostBack,
ActionTypes.MessageBack,
};
var cardActions = actionTypes.Select(actionType => new CardAction(
actionType,
$"{actionType} title",
null,
$"{actionType} value",
$"{actionType} text",
$"{actionType} displayText"
)).ToList();
var reply = activity.CreateReply("Reply:");
reply.Attachments = new List<Attachment> { new Attachment(HeroCard.ContentType, content: new HeroCard("Hero title", "Hero subtitle", "Hero text", buttons: cardActions)) };
reply.SuggestedActions = new SuggestedActions(new List<string> { activity.From.Id }, cardActions);
await Connector.Conversations.ReplyToActivityAsync(reply);
这三种操作类型(ImBack,PostBack和MessageBack)具有一些与之相关的预期行为:
These three action types (ImBack, PostBack, and MessageBack) have some expected behavior associated with them:
- ImBack用于在对话历史记录中显示一条消息,就像用户键入该消息一样
- PostBack旨在通过隐藏的元数据向机器人发送不可见的消息
- MessageBack旨在向机器人发送一条在对话历史记录中显示的消息,并且 包含隐藏的元数据,并结合了其他两种类型
- ImBack is meant to display a message in the conversation history as though the user typed it
- PostBack is meant to send an invisible message to the bot with hidden metadata
- MessageBack is meant to send a message to the bot that gets displayed in the conversation history and contains hidden metadata, combining the other two types
同样,您不能指望这种行为可以在不同渠道上得到一致实施.在这三个中,事实证明Facebook Messenger平台仅具有
Again, you cannot count on this behavior to be implemented consistently across different channels. Of the three of these, it turns out that the Facebook Messenger Platform only has the PostBack type, but it actually behaves like a MessageBack in that it displays text to the user as well as sending alternate text to the bot. In a hero card, CardAction.Title
will be used for the button's label and the text displayed in the conversation history, and CardAction.Value
will be used as hidden data assigned to both the incoming activity's Text
and Value
properties. CardAction.Text
and CardAction.DisplayText
will be ignored by the Facebook Messenger connector.
由于您只想在对话历史记录中显示文本,因此很幸运.实际上,使用哪种操作类型都没有关系. Facebook连接器会自动将具有这三种操作类型中的任何一种的英雄卡转换为快速答复稍有不同,发送到您的漫游器的数据将采用不同的格式,但是您可以从它们中提取相同的信息.
Since you just want text to be displayed in the conversation history, you're in luck. It actually doesn't matter which action type you use. The Facebook connector automatically converts a hero card with any of those three action types to a generic template with PostBack buttons. Suggested actions get converted to Quick Replies, which behave a bit differently in that the data sent to your bot will be in a different format, but you can extract the same information from them.
如果您想直接将Facebook模板发送给Messenger,而不是依赖于连接器来转换英雄卡,则可以使用
If you want to send a Facebook template to Messenger directly instead of depending on the connector to convert a hero card, you can use channel data. You could construct the template in C# like this:
object data = new
{
attachment = new
{
type = "template",
payload = new
{
template_type = "generic",
elements = new[]
{
new
{
title = "generic title",
subtitle = "generic subtitle",
image_url = "",
buttons = new[]
{
new
{
type = "postback",
title = "postback title",
payload = "postback payload"
}
}
}
}
}
}
};
由于某种原因,当您使用这样的匿名类型时,SDK不喜欢它,因此您需要先将其转换为JObject
,然后再发送至Facebook:
For some reason the SDK doesn't like it when you use an anonymous type like that, so you'll want to convert it to a JObject
before sending it to Facebook:
reply.ChannelData = JObject.FromObject(data);
await connector.Conversations.ReplyToActivityAsync(reply);