Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add template #12552

Merged
merged 5 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions templates/csharp/custom-copilot-rag-microsoft365/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# TeamsFx files
build
appPackage/build
env/.env.*.user
env/.env.local
appsettings.Development.json
appsettings.TestTool.json
.deployment

# User-specific files
*.user

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/

# Notification local store
.notification.localstore.json
.notification.testtoolstore.json

# devTools
devTools/
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Overview of the AI Chat Bot template

This template showcases a bot app that responds to user questions like an AI assistant. This enables your users to talk with the AI assistant in Teams to find information.

The app template is built using the Teams AI library, which provides the capabilities to build AI-based Teams applications.

## Quick Start

**Prerequisites**
> To run the AI Chat Bot template in your local dev machine, you will need:
>
{{#useOpenAI}}
> - an account with [OpenAI](https://platform.openai.com).
{{/useOpenAI}}
{{#useAzureOpenAI}}
> - [Azure OpenAI](https://aka.ms/oai/access) resource
{{/useAzureOpenAI}}

### Debug bot app in Teams App Test Tool
{{#useOpenAI}}
1. Ensure your OpenAI API Key is filled in `appsettings.TestTool.json`.
```
"OpenAI": {
"ApiKey": "<your-openai-api-key>"
}
```
{{/useOpenAI}}
{{#useAzureOpenAI}}
1. Ensure your Azure OpenAI settings are filled in `appsettings.TestTool.json`.
```
"Azure": {
"OpenAIApiKey": "<your-azure-openai-api-key>",
"OpenAIEndpoint": "<your-azure-openai-endpoint>",
"OpenAIDeploymentName": "<your-azure-openai-deployment-name>"
}
```
{{/useAzureOpenAI}}
1. Select `Teams App Test Tool (browser)` in debug dropdown menu.
1. Press F5, or select the Debug > Start Debugging menu in Visual Studio.
1. In Teams App Test Tool from the launched browser, type and send anything to your bot to trigger a response.

### Debug bot app in Teams Web Client
{{#useOpenAI}}
1. Ensure your OpenAI API Key is filled in `env/.env.local.user`.
```
SECRET_OPENAI_API_KEY="<your-openai-api-key>"
```
{{/useOpenAI}}
{{#useAzureOpenAI}}
1. Ensure your Azure OpenAI settings are filled in `env/.env.local.user`.
```
SECRET_AZURE_OPENAI_API_KEY="<your-azure-openai-api-key>"
AZURE_OPENAI_ENDPOINT="<your-azure-openai-endpoint>"
AZURE_OPENAI_DEPLOYMENT_NAME="<your-azure-openai-deployment-name>"
```
{{/useAzureOpenAI}}
1. In the debug dropdown menu, select Dev Tunnels > Create A Tunnel (set authentication type to Public) or select an existing public dev tunnel.
1. Right-click your project and select Teams Toolkit > Prepare Teams App Dependencies.
1. If prompted, sign in with a Microsoft 365 account for the Teams organization you want to install the app to.
1. Press F5, or select the Debug > Start Debugging menu in Visual Studio.
1. In the launched browser, select the Add button to load the app in Teams.
1. In the chat bar, type and send anything to your bot to trigger a response.

> For local debugging using Teams Toolkit CLI, you need to do some extra steps described in [Set up your Teams Toolkit CLI for local debugging](https://aka.ms/teamsfx-cli-debugging).

## Extend the AI Chat Bot template with more AI capabilities

You can follow [Get started with Teams AI library](https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/teams%20conversational%20ai/how-conversation-ai-get-started) to extend the AI Chat Bot template with more AI capabilities.

## Additional information and references
- [Teams AI library](https://aka.ms/teams-ai-library)
- [Teams Toolkit Documentations](https://docs.microsoft.com/microsoftteams/platform/toolkit/teams-toolkit-fundamentals)
- [Teams Toolkit CLI](https://aka.ms/teamsfx-toolkit-cli)
- [Teams Toolkit Samples](https://github.com/OfficeDev/TeamsFx-Samples)

## Learn more

New to Teams app development or Teams Toolkit? Learn more about
Teams app manifests, deploying to the cloud, and more in the documentation
at https://aka.ms/teams-toolkit-vs-docs.

## Report an issue

Select Visual Studio > Help > Send Feedback > Report a Problem.
Or, you can create an issue directly in our GitHub repository:
https://github.com/OfficeDev/TeamsFx/issues.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"profiles": {
// Launch project within Teams
"Microsoft Teams (browser)": {
"commandName": "Project",
"launchUrl": "https://teams.microsoft.com/l/app/${{TEAMS_APP_ID}}?installAppPackage=true&webjoin=true&appTenantId=${{TEAMS_APP_TENANT_ID}}&login_hint=${{TEAMSFX_M365_USER_NAME}}",
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" Sdk="Microsoft.TeamsFx.Sdk">
<ItemGroup>
<ProjectCapability Include="ProjectConfigurationsDeclaredDimensions" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup>
{{#enableTestToolByDefault}}
<ActiveDebugProfile>Teams App Test Tool (browser)</ActiveDebugProfile>
{{/enableTestToolByDefault}}
{{^enableTestToolByDefault}}
<ActiveDebugProfile>Microsoft Teams (browser)</ActiveDebugProfile>
{{/enableTestToolByDefault}}
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
[
{{#enableTestToolByDefault}}
{
"Name": "Teams App Test Tool (browser)",
"Projects": [
{
"Path": "{{NewProjectTypeName}}\\{{NewProjectTypeName}}.{{NewProjectTypeExt}}",
"Name": "{{NewProjectTypeName}}\\{{NewProjectTypeName}}.{{NewProjectTypeExt}}",
"Action": "StartWithoutDebugging",
"DebugTarget": "Teams App Test Tool (browser)"
},
{
{{#PlaceProjectFileInSolutionDir}}
"Path": "{{ProjectName}}.csproj",
"Name": "{{ProjectName}}.csproj",
{{/PlaceProjectFileInSolutionDir}}
{{^PlaceProjectFileInSolutionDir}}
"Path": "{{ProjectName}}\\{{ProjectName}}.csproj",
"Name": "{{ProjectName}}\\{{ProjectName}}.csproj",
{{/PlaceProjectFileInSolutionDir}}
"Action": "Start",
"DebugTarget": "Teams App Test Tool"
}
]
},
{{/enableTestToolByDefault}}
{
"Name": "Microsoft Teams (browser)",
"Projects": [
{
"Path": "{{NewProjectTypeName}}\\{{NewProjectTypeName}}.{{NewProjectTypeExt}}",
"Name": "{{NewProjectTypeName}}\\{{NewProjectTypeName}}.{{NewProjectTypeExt}}",
"Action": "StartWithoutDebugging",
"DebugTarget": "Microsoft Teams (browser)"
},
{
{{#PlaceProjectFileInSolutionDir}}
"Path": "{{ProjectName}}.csproj",
"Name": "{{ProjectName}}.csproj",
{{/PlaceProjectFileInSolutionDir}}
{{^PlaceProjectFileInSolutionDir}}
"Path": "{{ProjectName}}\\{{ProjectName}}.csproj",
"Name": "{{ProjectName}}\\{{ProjectName}}.csproj",
{{/PlaceProjectFileInSolutionDir}}
"Action": "Start",
"DebugTarget": "Start Project"
}
]
{{#enableTestToolByDefault}}
}
{{/enableTestToolByDefault}}
{{^enableTestToolByDefault}}
},
{
"Name": "Teams App Test Tool (browser)",
"Projects": [
{
"Path": "{{NewProjectTypeName}}\\{{NewProjectTypeName}}.{{NewProjectTypeExt}}",
"Name": "{{NewProjectTypeName}}\\{{NewProjectTypeName}}.{{NewProjectTypeExt}}",
"Action": "StartWithoutDebugging",
"DebugTarget": "Teams App Test Tool (browser)"
},
{
{{#PlaceProjectFileInSolutionDir}}
"Path": "{{ProjectName}}.csproj",
"Name": "{{ProjectName}}.csproj",
{{/PlaceProjectFileInSolutionDir}}
{{^PlaceProjectFileInSolutionDir}}
"Path": "{{ProjectName}}\\{{ProjectName}}.csproj",
"Name": "{{ProjectName}}\\{{ProjectName}}.csproj",
{{/PlaceProjectFileInSolutionDir}}
"Action": "Start",
"DebugTarget": "Teams App Test Tool"
}
]
}
{{/enableTestToolByDefault}}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Bot.Builder.TraceExtensions;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Schema;

namespace {{SafeProjectName}}
{
public class AdapterWithErrorHandler : CloudAdapter
{
public AdapterWithErrorHandler(BotFrameworkAuthentication auth, ILogger<CloudAdapter> logger)
: base(auth, logger)
{
OnTurnError = async (turnContext, exception) =>
{
// Log any leaked exception from the application.
// NOTE: In production environment, you should consider logging this to
// Azure Application Insights. Visit https://aka.ms/bottelemetry to see how
// to add telemetry capture to your bot.
logger.LogError(exception, $"[OnTurnError] unhandled error : {exception.Message}");

// Only send error message for user messages, not for other message types so the bot doesn't spam a channel or chat.
if (turnContext.Activity.Type == ActivityTypes.Message)
{
// Send a message to the user
await turnContext.SendActivityAsync($"The bot encountered an unhandled error: {exception.Message}");
await turnContext.SendActivityAsync("To continue to run this bot, please fix the bot source code.");

// Send a trace activity
await turnContext.TraceActivityAsync("OnTurnError Trace", exception.Message, "https://www.botframework.com/schemas/error", "TurnError");
}
};
}
}
}
38 changes: 38 additions & 0 deletions templates/csharp/custom-copilot-rag-microsoft365/Config.cs.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace {{SafeProjectName}}
{
public class ConfigOptions
{
public string BOT_ID { get; set; }
public string BOT_PASSWORD { get; set; }
public string BOT_TYPE { get; set; }
public string BOT_TENANT_ID { get; set; }
{{#useOpenAI}}
public OpenAIConfigOptions OpenAI { get; set; }
{{/useOpenAI}}
{{#useAzureOpenAI}}
public AzureConfigOptions Azure { get; set; }
{{/useAzureOpenAI}}
}

{{#useOpenAI}}
/// <summary>
/// Options for Open AI
/// </summary>
public class OpenAIConfigOptions
{
public string ApiKey { get; set; }
public string DefaultModel = "gpt-3.5-turbo";
}
{{/useOpenAI}}
{{#useAzureOpenAI}}
/// <summary>
/// Options for Azure OpenAI and Azure Content Safety
/// </summary>
public class AzureConfigOptions
{
public string OpenAIApiKey { get; set; }
public string OpenAIEndpoint { get; set; }
public string OpenAIDeploymentName { get; set; }
}
{{/useAzureOpenAI}}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Integration.AspNet.Core;

namespace {{SafeProjectName}}.Controllers
{
[Route("api/messages")]
[ApiController]
public class BotController : ControllerBase
{
private readonly CloudAdapter Adapter;
private readonly IBot Bot;

public BotController(CloudAdapter adapter, IBot bot)
{
Adapter = adapter;
Bot = bot;
}

[HttpPost]
public async Task PostAsync(CancellationToken cancellationToken = default)
{
await Adapter.ProcessAsync(Request, Response, Bot, cancellationToken);
}
}
}
Loading
Loading