Skip to content

Commit

Permalink
added new message extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Raj committed Mar 31, 2024
1 parent 3eb48d5 commit c96f01b
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 57 deletions.
18 changes: 9 additions & 9 deletions Azure.AI.Services.Teams/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "https://teams.microsoft.com/l/app/52a13451-aef5-4030-a46c-6e2f99bfc42b?installAppPackage=true&webjoin=true&appTenantId=856766dd-7c1e-4c8c-8327-5476c947f877&login_hint=rajs@zjmmb.onmicrosoft.com",
"launchUrl": "https://teams.microsoft.com/l/app/c5672fe6-8ea4-4319-9371-70241815c2f2?installAppPackage=true&webjoin=true&appTenantId=856766dd-7c1e-4c8c-8327-5476c947f877&login_hint=rajs@zjmmb.onmicrosoft.com",
"applicationUrl": "http://localhost:5130",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
Expand All @@ -15,14 +15,14 @@
// Uncomment following profile to debug project only (without launching Teams)
,
"Start Project (not in Teams)": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7130;http://localhost:5130",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"hotReloadProfile": "aspnetcore"
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7130;http://localhost:5130",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"hotReloadProfile": "aspnetcore"
}
}
}
5 changes: 2 additions & 3 deletions Azure.AI.Services.Teams/Search/AISearch.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using Azure.Search.Documents.Models;
using Azure.AI.OpenAI;
using Azure.Search.Documents;
using Azure.AI.OpenAI;
using Azure.Search.Documents.Indexes;
using Azure;
using Azure.Search.Documents.Models;

namespace Azure.AI.Services.Teams.Search
{
Expand Down
99 changes: 62 additions & 37 deletions Azure.AI.Services.Teams/Search/SearchApp.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using Microsoft.Bot.Builder;
using AdaptiveCards;
using Azure.Search.Documents.Models;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Teams;
using Microsoft.Bot.Schema;
using Microsoft.Bot.Schema.Teams;
using AdaptiveCards;
using Newtonsoft.Json.Linq;
using Azure.Search.Documents.Models;
using System.Diagnostics;

namespace Azure.AI.Services.Teams.Search;
Expand All @@ -22,41 +21,67 @@ public SearchApp(AISearch aiSearch)
// Search
protected override async Task<MessagingExtensionResponse> OnTeamsMessagingExtensionQueryAsync(ITurnContext<IInvokeActivity> turnContext, MessagingExtensionQuery query, CancellationToken cancellationToken)
{
var templateJson = await System.IO.File.ReadAllTextAsync(_adaptiveCardFilePath, cancellationToken);
var template = new AdaptiveCards.Templating.AdaptiveCardTemplate(templateJson);

var text = query?.Parameters?[0]?.Value as string ?? string.Empty;
var hybridResponse = await _aiSearch.SemanticHybridSearch(text);
var attachments = new List<MessagingExtensionAttachment>();
Debug.WriteLine($"Hybrid Search Results:");
await foreach (SearchResult<SearchDocument> result in hybridResponse.GetResultsAsync())
switch (query.CommandId)
{
Debug.WriteLine($"Title: {result.Document["title"]}");
Debug.WriteLine($"Url: {result.Document["url"]}");
Debug.WriteLine($"Content: {result.Document["content"]}");
Debug.WriteLine($"Filepath: {result.Document["filepath"]}\n");

var previewCard = new HeroCard { Title = result.Document["filepath"].ToString(), Text = result.Document["content"].ToString() };
var adaptiveCardJson = template.Expand(new { content = result.Document["content"], filepath = result.Document["filepath"], url = result.Document["url"] });
var adaptiveCard = AdaptiveCard.FromJson(adaptiveCardJson).Card;
var attachment = new MessagingExtensionAttachment
{
ContentType = AdaptiveCard.ContentType,
Content = adaptiveCard,
Preview = previewCard.ToAttachment()
};

attachments.Add(attachment);
case "searchQuery":
{
var templateJson = await System.IO.File.ReadAllTextAsync(_adaptiveCardFilePath, cancellationToken);
var template = new AdaptiveCards.Templating.AdaptiveCardTemplate(templateJson);

var text = query?.Parameters?[0]?.Value as string ?? string.Empty;
var hybridResponse = await _aiSearch.SemanticHybridSearch(text);
var attachments = new List<MessagingExtensionAttachment>();
Debug.WriteLine($"Hybrid Search Results:");
await foreach (SearchResult<SearchDocument> result in hybridResponse.GetResultsAsync())
{
Debug.WriteLine($"Title: {result.Document["title"]}");
Debug.WriteLine($"Url: {result.Document["url"]}");
Debug.WriteLine($"Content: {result.Document["content"]}");
Debug.WriteLine($"Filepath: {result.Document["filepath"]}\n");

var previewCard = new HeroCard { Title = result.Document["filepath"].ToString(), Text = result.Document["content"].ToString() };
var adaptiveCardJson = template.Expand(new { content = result.Document["content"], filepath = result.Document["filepath"], url = result.Document["url"] });
var adaptiveCard = AdaptiveCard.FromJson(adaptiveCardJson).Card;
var attachment = new MessagingExtensionAttachment
{
ContentType = AdaptiveCard.ContentType,
Content = adaptiveCard,
Preview = previewCard.ToAttachment()
};

attachments.Add(attachment);

}
return new MessagingExtensionResponse
{
ComposeExtension = new MessagingExtensionResult
{
Type = "result",
AttachmentLayout = "list",
Attachments = attachments
}
};
}
case "timeQuery":
{
return await Task.FromResult(new MessagingExtensionResponse
{
ComposeExtension = new MessagingExtensionResult
{
Type = "result",
Text = DateTime.Now.ToLongTimeString()
}
});
}
default:
return new MessagingExtensionResponse
{
ComposeExtension = new MessagingExtensionResult
{
Type = "message",
Text = "Unknown CommandId"
}
};
}
return new MessagingExtensionResponse
{
ComposeExtension = new MessagingExtensionResult
{
Type = "result",
AttachmentLayout = "list",
Attachments = attachments
}
};
}
}
Binary file added Azure.AI.Services.Teams/appPackage/color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
34 changes: 26 additions & 8 deletions Azure.AI.Services.Teams/appPackage/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
"id": "${{TEAMS_APP_ID}}",
"packageName": "com.microsoft.teams.extension",
"developer": {
"name": "Teams App, Inc.",
"websiteUrl": "https://www.example.com",
"privacyUrl": "https://www.example.com/termofuse",
"termsOfUseUrl": "https://www.example.com/privacy"
"name": "Contoso Inc.",
"websiteUrl": "https://www.contoso.com",
"privacyUrl": "https://www.contoso.com/termofuse",
"termsOfUseUrl": "https://www.contoso.com/privacy"
},
"icons": {
"color": "ecogroceriescolor.png",
"outline": "ecogroceriestrnsprnt.png"
"color": "color.png",
"outline": "outline.png"
},
"name": {
"short": "EcoGroceries Call Center C#",
"full": "EcoGroceries Call Center Search message extension helping you find conversation records with clients"
"short": "Contoso Consulting",
"full": "Contoso Consulting search message extension helping you find conversation records with partners"
},
"description": {
"short": "Message extension to find recorded conversation scripts with clients",
Expand Down Expand Up @@ -45,6 +45,24 @@
"inputType": "text"
}
]
},
{
"id": "timeQuery",
"context": [
"compose",
"commandBox"
],
"description": "Get current time",
"title": "Time",
"type": "query",
"parameters": [
{
"name": "timeQuery",
"title": "Time Query",
"description": "Get current time",
"inputType": "text"
}
]
}
]
}
Expand Down
Binary file added Azure.AI.Services.Teams/appPackage/outline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c96f01b

Please sign in to comment.