[英]Teams Bot Adaptive Card action.Submit returns undefined but works in Bot Emulator
I am having an issue with Teams Bot adaptive card action submit, when testing Bot Emulator it works as expected, but when it's published and performing the same action in Teams conversation, the action submit returns undefined.我遇到了 Teams Bot 自适应卡片操作提交问题,在测试 Bot Emulator 时它按预期工作,但是当它发布并在 Teams 对话中执行相同操作时,操作提交返回未定义。 I have attempted with both adaptive card version 1.0, and version 1.3, the issue is the same in both cases.
我尝试过使用自适应卡 1.0 版和 1.3 版,两种情况下的问题都是一样的。 Anyone know a solution for this?
有谁知道这个的解决方案?
The other answer provides some useful background, but I think it's only applicable to specific scenarios - I think the issue you're having here is that you're sending a raw string value in the data
property ("My Action") which Teams doesn't like, but the emulator doesn't mind at all.另一个答案提供了一些有用的背景,但我认为它仅适用于特定场景 - 我认为您在这里遇到的问题是您在 Teams 没有的
data
属性(“我的操作”)中发送原始字符串值'不喜欢,但模拟器根本不介意。 You can see more about that described in this Microsoft blog post .您可以在此 Microsoft 博客文章中看到有关该内容的更多信息。 You should instead be sending an actual object.
相反,您应该发送实际的 object。 I describe it in more detail in this answer: QnA Maker Bot AdaptiveCards: how to add Data object in C# .
我在这个答案中更详细地描述了它: QnA Maker Bot AdaptiveCards: how to add Data object in C# 。
What @billoverton is referring to is a specific use case where you want the button behaviour to be, for instance, actually putting a message into the text stream as a response, as well as sending it to your bot. @billoverton 指的是一个特定的用例,您希望按钮行为是,例如,实际上将消息放入文本 stream作为响应,并将其发送到您的机器人。 There are various options for these specific use cases, as described here , but they are optional if you want this specific behaviour.
如此处所述, 这些特定用例有多种选择,但如果您想要这种特定行为,它们是可选的。 If you're happy for the user to click the button and that to simply invoke the message to your bot, you don't need the "msteams" section in the data payload.
如果您很高兴用户单击按钮并简单地将消息调用到您的机器人,则不需要数据有效负载中的“msteams”部分。
A "standard" action.submit won't work in Teams. “标准” action.submit 在 Teams 中不起作用。 You need to add an msteams object under the data attribute.
您需要在 data 属性下添加一个 msteams object。 I'm guessing you are using a standard definition like
我猜您使用的是标准定义,例如
{
"type": "ActionSet",
"actions": [
{
"type": "Action.Submit",
"title": "My Action",
"data": "My Action"
}
]
}
For Teams, it instead needs to look like this:对于 Teams,它需要如下所示:
{
"type": "ActionSet",
"actions": [
{
"type": "Action.Submit",
"title": "My Action",
"data": {
"msteams": {
"type": "imBack",
"value": "My Action"
}
}
}
]
}
Of course when you do this, it won't work in the emulator or any non-teams channel.当然,当你这样做时,它不会在模拟器或任何非团队频道中工作。 I've seen some people update their onMessage handler to account for this by extracting the value so a single card definition can work for both channels, but it made the selection a backchannel event for one of the channels (can't remember if it was web or Teams) which was not the experience I was looking for.
我已经看到有些人通过提取值来更新他们的 onMessage 处理程序来解决这个问题,因此单个卡定义可以用于两个通道,但是它使选择成为其中一个通道的反向通道事件(不记得它是否是web 或团队)这不是我想要的体验。 So instead, I just conditionally display a Teams or non-Teams card based on channel.
因此,我只是根据频道有条件地显示 Teams 或非 Teams 卡片。 For example:
例如:
if (context.activity.channelId == 'msteams') {
var welcomeCard = CardHelper.GetMenuCardTeams();
} else {
var welcomeCard = CardHelper.GetMenuCard();
}
If you are not using a helper to generate your cards you can define them explicitly here, though I do recommend using a helper to keep things clean.如果您没有使用助手来生成卡片,您可以在此处明确定义它们,尽管我建议使用助手来保持清洁。 This does mean that you need to maintain two versions of your cards, but for me it was worth it to ensure a consistent experience across channels.
这确实意味着您需要维护两个版本的卡片,但对我来说,确保跨渠道的一致体验是值得的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.