Error inserting adaptive card to Compose box from a Message Extension (composeExtension/submitAction) Command

懵懂的女人 提交于 2020-04-17 20:28:09

问题


I have a message extension, available on the "..." message context menu, that launches a Task Module. In the task module, I submit some sample data (e.g. microsoftTeams.tasks.submitTask({"x":"y"}); )

I receive the call for "composeExtension/submitAction", but when I try insert something into the compose box, by submitting a response like the following:

            var card = new HeroCard
            {
                Title = "foo",
                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);

Then I get an error on the task module, and in the browser debug tools I see the following error:

<BotError>Error when processing invoke response: Task or Task Type is missing in Task Module response

Here is the payload being returned from my bot to 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
    }
}

The empty "task" object is there because of the "MessagingExtensionActionResponse" type, but I've tried removing it with my own custom type, and I've also tried various ideas of what to possibly put inside there. Per the docs, I can't actually see that a "task" is required though (e.g. per here).

Can anybody see where I'm going wrong, or how to guide me to a working solution on this.

来源:https://stackoverflow.com/questions/61175591/error-inserting-adaptive-card-to-compose-box-from-a-message-extension-composeex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!