Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.

Add support for search invoke - #6272

Merged
Gabo Gilabert (gabog) merged 3 commits into
mainfrom
eric/addSearch
Mar 21, 2022
Merged

Gabo Gilabert (gabog) merged 3 commits into
mainfrom
eric/addSearch

Conversation

@EricDahlvang

@EricDahlvang Eric Dahlvang (EricDahlvang) commented Mar 18, 2022 •

Copy link
Copy Markdown
Member

Fixes #5643

OnInvokeActivityAsync here:
https://github.com/OfficeDev/Microsoft-Teams-Samples/blob/main/samples/bot-type-ahead-search-adaptive-cards/csharp/TypeaheadSearch/Bots/ActivityBot.cs#L85

Would be changed to:

protected override async Task<SearchInvokeResponse> OnSearchInvokeAsync(ITurnContext<IInvokeActivity> turnContext, SearchInvokeValue invokeValue, CancellationToken cancellationToken)
{
    var packageResult = JObject.Parse(await(new HttpClient()).GetStringAsync($"https://azuresearch-usnc.nuget.org/query?q=id:{invokeValue.QueryText}&prerelease=true"));
    if (packageResult == null)
    {
        // no results available, return 204
        return new SearchInvokeResponse
        {
            Type = "application/vnd.microsoft.search.searchResponse",
            StatusCode = 204
        };
    }
    else
    {
        var packageList = packageResult["data"]
            .Skip(invokeValue.QueryOptions.Skip)
            .Take(invokeValue.QueryOptions.Top)
            .Select(item => (item["id"].ToString(), item["description"].ToString()))
            .Select(item => new { title = item.Item1, value = item.Item1 + " - " + item.Item2 })
            .ToList();
        
        return new SearchInvokeResponse
        {
            Type = "application/vnd.microsoft.search.searchResponse",
            Value = JObject.FromObject(new { results = packageList }),
            StatusCode = 200
        };
    }
}

@EricDahlvang
Eric Dahlvang (EricDahlvang) requested a review from a team as a code owner March 18, 2022 22:49
@EricDahlvang Eric Dahlvang (EricDahlvang) added the Automation: Parity all The PR needs to be ported to all repos (dotnet, JS, Python and Java) label Mar 18, 2022
@coveralls

Copy link
Copy Markdown
Collaborator

Pull Request Test Coverage Report for Build 296646

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 41 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.01%) to 78.637%

Files with Coverage Reduction New Missed Lines %
/libraries/Microsoft.Bot.Builder/ActivityHandler.cs 41 67.79%
Totals Coverage Status
Change from base Build 296444: -0.01%
Covered Lines: 25266
Relevant Lines: 32130

💛 - Coveralls

@johnataylor johnataylor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validate logic looks pretty watertight to me. Maybe an extra unit test to prevent someone accidentally regressing this in the future.


if (string.IsNullOrEmpty(searchInvokeValue.QueryText))
{
missingField = nameof(searchInvokeValue.QueryText);

@johnataylor johnataylor Mar 21, 2022 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: isn't nameof going to give you the C# identifier whereas what you really want in the error message is the JSON property name. OK this is perhaps a nit because the only difference in this case at the current time is the casing.

I'm assuming the json property attribute doesn't override the nameof result (can you even do that?)

@gabog
Gabo Gilabert (gabog) merged commit 1d1edef into main Mar 21, 2022
@gabog
Gabo Gilabert (gabog) deleted the eric/addSearch branch March 21, 2022 18:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Automation: Parity all The PR needs to be ported to all repos (dotnet, JS, Python and Java)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Search invoke and response (C#)

4 participants