我有一个消息扩展名,可在“ ...”消息上下文菜单中使用,它可以启动任务模块。在任务模块中,我提交了一些示例数据(例如microsoftTeams.tasks.submitTask({"x":"y"});
)
我收到了对“ composeExtension / submitAction”的调用,但是当我尝试通过在提交框中输入以下内容来将一些内容插入到compose框中时:
var card = new HeroCard
{
Title = "foo",
Subtitle = "subtitle",
Text = "bar"
};
var attachments = new List<MessagingExtensionAttachment>();
attachments.Add(new MessagingExtensionAttachment
{
Content = card,
ContentType = HeroCard.ContentType,
Preview = card.ToAttachment(),
});
var activity = new Activity
{
Type = ActivityTypesEx.InvokeResponse,
Value = new InvokeResponse
{
Status = (int)HttpStatusCode.OK,
Body = new MessagingExtensionActionResponse
{
ComposeExtension = new MessagingExtensionResult
{
AttachmentLayout = "list",
Type = "result",
Attachments = attachments
},
}
}
};
await turnContext.SendActivityAsync(activity, cancellationToken: cancellationToken);
然后在任务模块上出现错误,并且在浏览器调试工具中我看到以下错误:
<BotError>Error when processing invoke response: Task or Task Type is missing in Task Module response
这是从我的机器人返回到Teams的有效载荷:
{
"task": null,
"composeExtension": {
"attachmentLayout": "list",
"type": "result",
"attachments": [
{
"preview": {
"contentType": "application/vnd.microsoft.card.hero",
"contentUrl": null,
"content": {
"title": "foo",
"subtitle": null,
"text": "bar",
"images": null,
"buttons": null,
"tap": null
},
"name": null,
"thumbnailUrl": null
},
"contentType": "application/vnd.microsoft.card.hero",
"contentUrl": null,
"content": {
"title": "foo",
"subtitle": null,
"text": "bar",
"images": null,
"buttons": null,
"tap": null
},
"name": null,
"thumbnailUrl": null
}
],
"suggestedActions": null,
"text": null,
"activityPreview": null
}
}
由于存在“ MessagingExtensionActionResponse”类型,因此出现了空的“任务”对象,但是我尝试使用自己的自定义类型将其删除,并且还尝试了各种可能放置在其中的对象。根据文档,我实际上看不到需要“任务”(例如,根据here)。
任何人都可以看到我在哪里出问题了,或者如何引导我找到可行的解决方案。
[更新:根据下面答案中的注释,对上面的代码示例进行了较小的更新]