Search code examples
typescriptbotframeworkmicrosoft-teams

Microsoft Teams Messaging Extension query result invoke issue


I am creating an app that shows results in the Teams command bar from the Microsoft Graph and displays them to a user. When the user then clicks on a result I want to display an adaptive card with more specific data on the chosen result. I am using preview.content.tap in order to trigger the onSelectItem function to get the adaptive card for the chosen result, which works well. The issue I am facing is when I want to clear the selected item from the command bar (clicking the "X" of the viewed result), I would expect to see the results of my previous search, but instead I get "We didn't find any matches"

Is there anything I can do to retain the results (e.g. a callback function, cache), or possibly restart the search without further input from the user?

1. The list of results

2. The "X" in question

3. The result of clicking "X"

My code is as follows:

@PreventIframe("/myMessageExtension/config.html")
export default class MyMessageExtension implements IMessagingExtensionMiddlewareProcessor {

    public async onQuery(context: TurnContext, query: MessagingExtensionQuery): Promise<MessagingExtensionResult> {

        const results = await getGraphSearchResults(query);

        const attachments = results?.map((result: any) => {
            const name = result.resource.name ?? result.resource.fields?.title;
            const preview = CardFactory.heroCard(name, result.resource.fields.url);
            preview.content.tap = { type: 'invoke', value: { type: "SearchResult", result } };
            return preview;
        });

        return Promise.resolve({
            type: "result",
            attachmentLayout: "list",
            attachments
        } as MessagingExtensionResult);

    }

    public async onSelectItem(context: TurnContext, value: { type: string, result: any }): Promise<MessagingExtensionResult> {
        if (value.type === "SearchResult") {
            const attachment = await getAdaptiveCard(value.result);

            return Promise.resolve({
                type: "result",
                attachmentLayout: "list",
                attachments: [attachment]
            } as MessagingExtensionResult);
        }

        return Promise.resolve({
            type: "result",
            attachmentLayout: "list",
            attachments: []
        } as MessagingExtensionResult);
    }
}

Any help or guidance is appreciated,

Thanks


Solution

  • When you clear the selected item from the command bar (clicking the "X" of the viewed result) and getting "We didn't find any matches" is the expected behavior. In compose area it you will get result even when you clear the search query but currently in command bar it will not work. It is by design.