UpdateActivity 抛出 400 "Unknown activity type"

UpdateActivity throws 400 "Unknown activity type"

我有一个可以通过 MS Teams 访问的机器人。机器人发送带有一些文本和提交操作的自适应卡片。当用户单击此提交操作时,我想继续输入,然后通过调用 context.updateActivity 更新先前发送的自适应卡片。根据documentation,我可以使用activity.Id = turnContext.Activity.ReplyToId;来指定我要更新的消息。但是 context.updateActivity 的调用导致 400 HTTP 错误,消息是“Unknown activity type”。

一些调查:

有什么想法吗?

这是我的代码:

自适应卡

{
    "$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});
    }
}

知道了!

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[ 的“就地”实现=15=]