UpdateActivity 抛出 400“未知活动类型”
Posted
技术标签:
【中文标题】UpdateActivity 抛出 400“未知活动类型”【英文标题】:UpdateActivity throws 400 "Unknown activity type" 【发布时间】:2021-09-01 15:19:13 【问题描述】:我确实有一个可以通过 MS Teams 访问的 Bot。机器人发送带有一些文本和提交操作的自适应卡片。当用户单击此提交操作时,我想继续输入,然后通过调用 context.updateActivity
更新先前发送的自适应卡。根据documentation,我可以使用activity.Id = turnContext.Activity.ReplyToId;
指定我要更新的消息。但是context.updateActivity
的调用会导致400 HTTP错误,消息是“Unknown activity type”。
一些调查:
当我想发送另一张自适应卡片和发送纯文本时会出现此错误 我验证,sendActivity
的id
与turnContext.Activity.ReplyToId
相同
有什么想法吗?
这是我的代码:
适配卡
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
"type": "TextBlock",
"text": "Some text",
"wrap": true
,
"type": "Input.ChoiceSet",
"id": "Feedback",
"value": "",
"style": "compact",
"placeholder": "Wie hilfreich war diese Antwort?",
"choices": [
"title": "⭐",
"value": "1"
,
"title": "⭐⭐",
"value": "2"
,
"title": "⭐⭐⭐",
"value": "3"
,
"title": "⭐⭐⭐⭐",
"value": "4"
,
"title": "⭐⭐⭐⭐⭐",
"value": "5"
]
],
"actions": [
"title": "Feedback absenden",
"type": "Action.Submit"
]
发送消息:
private handleMessage = async (context: TurnContext, next: () => Promise<void>): Promise<void> =>
const adaptiveCard = AdaptiveCardFactory.createAdaptiveCardFromTemplateAndData(AnswerWithFeedbackCard);
const result = await context.sendActivity( attachments: [adaptiveCard] );
console.error("send msg with id " + result?.id);
更新消息的代码:
private handleMessage = async (context: TurnContext, next: () => Promise<void>): Promise<void> =>
console.error("received msg with id " + context.activity.replyToId);
if (context.activity.value && !context.activity.text)
const updatedCard = CardFactory.adaptiveCard(this.botConfig.updatedCard);
await context.updateActivity( text: "updated :)", id: context.activity.replyToId);
//or
await context.updateActivity( attachments: [updatedCard], id: context.activity.replyToId);
【问题讨论】:
我们正在努力。我们会尽快回复您。 谢谢。来自package.json
的一些附加信息:"adaptivecards-templating": "^1.4.0", "applicationinsights": "^2.0.0", "azure-search-client": "^3.1.5", "botbuilder": "^4.11.0",
这方面有什么更新吗?
通过这个sample更新自适应卡。
【参考方案1】:
知道了!
const att = AdaptiveCardFactory.createAdaptiveCardFromTemplateAndData(AnswerWithAnsweredFeedbackCard,
answer: "Mir geht's super, danke der Nachfrage!",
starsCount: context.activity.value.Feedback
);
const id = await context.updateActivity( attachments: [ att ], id: context.activity.replyToId );
这不起作用,但这样做:
const att = AdaptiveCardFactory.createAdaptiveCardFromTemplateAndData(AnswerWithAnsweredFeedbackCard,
answer: "Mir geht's super, danke der Nachfrage!",
starsCount: context.activity.value.Feedback
);
const msg = MessageFactory.attachment( att )
msg.id = context.activity.replyToId;
const id = await context.updateActivity( msg )
因此,您需要将发送的msg
保存在一个变量中,并设置该变量的id
,而不是使用updateActivity
的“就地”实现
【讨论】:
以上是关于UpdateActivity 抛出 400“未知活动类型”的主要内容,如果未能解决你的问题,请参考以下文章
Google App Engine OAuth 端点在生产中抛出 400
FireBase 在第一轮循环后抛出 WebException 400
RestTemplate GET 请求抛出 400 Bad Request