Skip to content

Commit

Permalink
Merge pull request #11909 from OfficeDev/yimin/fix-copilot-plugin
Browse files Browse the repository at this point in the history
fix: fix copilot plugin api-key&oauth template
  • Loading branch information
eriolchan authored Jun 26, 2024
2 parents 1db899e + 4a3ec9d commit 159bcaa
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,32 @@
> - [Visual Studio 2022](https://aka.ms/vs) 17.11 or higher and [install Teams Toolkit](https://aka.ms/install-teams-toolkit-vs)
> - A [Microsoft 365 account for development](https://docs.microsoft.com/microsoftteams/platform/toolkit/accounts)

1. In the debug dropdown menu, select Dev Tunnels > Create a Tunnel (set authentication type to Public) or select an existing public dev tunnel
### Add your own API Key

1. Open PowerShell, change the current working directory to this project root and run command `./TeamsApp/GenerateApiKey.ps1`
```
> ./TeamsApp/GenerateApiKey.ps1
```

2. The above command will output something like "Generated a new API Key: xxx...".
3. Fill in API Key into `env/.env.*.user`.
```
SECRET_API_KEY=<your-api-key>
```

### Start the app in Teams Web Client

1. If you haven't added your own API Key, please follow the above steps to add your own API Key.
2. In the debug dropdown menu, select Dev Tunnels > Create a Tunnel (set authentication type to Public) or select an existing public dev tunnel
</br>![image](https://raw.githubusercontent.com/OfficeDev/TeamsFx/dev/docs/images/visualstudio/debug/create-devtunnel-button.png)
2. Right-click the '{{NewProjectTypeName}}' project and select Teams Toolkit > Prepare Teams App Dependencies
3. If prompted, sign in with a Microsoft 365 account for the Teams organization you want to install the app to.
4. Press F5, or select the `Debug > Start Debugging` menu in Visual Studio to start your app
3. Right-click the '{{NewProjectTypeName}}' project and select Teams Toolkit > Prepare Teams App Dependencies
4. If prompted, sign in with a Microsoft 365 account for the Teams organization you want to install the app to.
5. Press F5, or select the `Debug > Start Debugging` menu in Visual Studio to start your app
</br>![image](https://raw.githubusercontent.com/OfficeDev/TeamsFx/dev/docs/images/visualstudio/debug/debug-button.png)
5. When Teams launches in the browser, you can open the Copilot app and send a prompt to trigger your plugin.
6. Send a message to Copilot to find an NuGet package information. For example: Find the NuGet package info on Microsoft.CSharp.
6. When Teams launches in the browser, click the Apps icon from Teams client left rail to open Teams app store and search for Copilot.
7. Open the `Copilot` app, select `Plugins`, and from the list of plugins, turn on the toggle for your plugin. Now, you can send a prompt to trigger your plugin.
8. Send a message to Copilot to query the repair record. For example: List all repairs.
> Note: Please make sure to switch to New Teams when Teams web client has launched

## Get more info

Expand Down
30 changes: 23 additions & 7 deletions templates/csharp/api-plugin-from-scratch-bearer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,29 @@
> - A [Microsoft 365 account for development](https://docs.microsoft.com/microsoftteams/platform/toolkit/accounts).
> - [Copilot for Microsoft 365 license](https://learn.microsoft.com/microsoft-365-copilot/extensibility/prerequisites#prerequisites)
1. In the debug dropdown menu, select `Dev Tunnels > Create a Tunnel` (set authentication type to Public) or select an existing public dev tunnel.
2. Right-click your project and select `Teams Toolkit > Prepare Teams App Dependencies`.
3. If prompted, sign in with a Microsoft 365 account for the Teams organization you want to install the app to.
4. Press F5, or select the `Debug > Start Debugging` menu in Visual Studio
5. When Teams launches in the browser, click the Apps icon from Teams client left rail to open Teams app store and search for Copilot.
6. Open the `Copilot` app, select `Plugins`, and from the list of plugins, turn on the toggle for your plugin. Now, you can send a prompt to trigger your plugin.
7. Send a message to Copilot to query the repair record. For example: List all repairs.
### Add your own API Key

1. Open PowerShell, change the current working directory to this project root and run command `./TeamsApp/GenerateApiKey.ps1`
```
> ./TeamsApp/GenerateApiKey.ps1
```
2. The above command will output something like "Generated a new API Key: xxx...".
3. Fill in API Key into `env/.env.*.user`.
```
SECRET_API_KEY=<your-api-key>
```
### Debug app in Teams Web Client
1. If you haven't added your own API Key, please follow the above steps to add your own API Key.
2. In the debug dropdown menu, select `Dev Tunnels > Create a Tunnel` (set authentication type to Public) or select an existing public dev tunnel.
3. Right-click your project and select `Teams Toolkit > Prepare Teams App Dependencies`.
4. If prompted, sign in with a Microsoft 365 account for the Teams organization you want to install the app to.
5. Press F5, or select the `Debug > Start Debugging` menu in Visual Studio
6. When Teams launches in the browser, click the Apps icon from Teams client left rail to open Teams app store and search for Copilot.
7. Open the `Copilot` app, select `Plugins`, and from the list of plugins, turn on the toggle for your plugin. Now, you can send a prompt to trigger your plugin.
8. Send a message to Copilot to query the repair record. For example: List all repairs.
> Note: Please make sure to switch to New Teams when Teams web client has launched
## Learn more
Expand Down
11 changes: 6 additions & 5 deletions templates/csharp/api-plugin-from-scratch-bearer/Repairs.cs.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using System.Net;

namespace {{SafeProjectName}}
{
Expand All @@ -10,9 +11,9 @@ namespace {{SafeProjectName}}
private readonly ILogger _logger;
private readonly IConfiguration _configuration;
public Repair(ILoggerFactory loggerFactory, IConfiguration configuration)
public Repairs(ILoggerFactory loggerFactory, IConfiguration configuration)
{
_logger = loggerFactory.CreateLogger<Repair>();
_logger = loggerFactory.CreateLogger<Repairs>();
_configuration = configuration;
}

Expand All @@ -38,9 +39,9 @@ namespace {{SafeProjectName}}
// If the assignedTo query parameter is not provided, return all repair records.
if (string.IsNullOrEmpty(assignedTo))
{
var response = req.CreateResponse();
await response.WriteAsJsonAsync(new { results = repairRecords });
return response;
var res = req.CreateResponse();
await res.WriteAsJsonAsync(new { results = repairRecords });
return res;
}

// Filter the repair records by the assignedTo query parameter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
{
"type": "OpenApi",
"auth": {
"type": "apiKey"
"type": "ApiKeyPluginVault"
"reference_id": "${{APIKEY_REGISTRATION_ID}}"
},
"spec": {
"url": "apiSpecificationFile/repair.yml",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"contentVersion": "1.0.0.0",
"parameters": {
"resourceBaseName": {
"value": "sme${{RESOURCE_SUFFIX}}"
"value": "plugin${{RESOURCE_SUFFIX}}"
},
"functionAppSKU": {
"value": "Y1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ provision:
run:
echo "::set-teamsfx-env OPENAPI_SERVER_URL=https://${{DEV_TUNNEL_URL}}";

# Generate runtime settings to JSON file
- uses: file/createOrUpdateJsonFile
with:
{{#isNewProjectTypeEnabled}}
{{#PlaceProjectFileInSolutionDir}}
target: ../local.settings.json
{{/PlaceProjectFileInSolutionDir}}
{{^PlaceProjectFileInSolutionDir}}
target: ../{{appName}}/local.settings.json
{{/PlaceProjectFileInSolutionDir}}
{{/isNewProjectTypeEnabled}}
{{^isNewProjectTypeEnabled}}
target: ./local.settings.json
{{/isNewProjectTypeEnabled}}
content:
IsEncrypted: false
Values:
FUNCTIONS_WORKER_RUNTIME: "dotnet-isolated"
API_KEY: ${{SECRET_API_KEY}}

# Register API KEY
- uses: apiKey/register
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ provision:
# variable before ARM deployment.
parameters: ./infra/azure.parameters.json
# Required when deploying ARM template
deploymentName: Create-resources-for-sme
deploymentName: Create-resources-for-api-plugin
# Teams Toolkit will download this bicep CLI version from github for you,
# will use bicep CLI in PATH if you remove this config.
bicepCliVersion: v0.9.1
Expand Down
6 changes: 3 additions & 3 deletions templates/csharp/api-plugin-from-scratch-oauth/Repairs.cs.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ namespace {{SafeProjectName}}
// If the assignedTo query parameter is not provided, return all repair records.
if (string.IsNullOrEmpty(assignedTo))
{
var response = req.CreateResponse();
await response.WriteAsJsonAsync(new { results = repairRecords });
return response;
var res = req.CreateResponse();
await res.WriteAsJsonAsync(new { results = repairRecords });
return res;
}

// Filter the repair records by the assignedTo query parameter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ paths:
operationId: listRepairs
summary: List all repairs
description: Returns a list of repairs with their details and images
security:
- oAuth2AuthCode: []
parameters:
- name: assignedTo
in: query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ paths:
operationId: listRepairs
summary: List all repairs
description: Returns a list of repairs with their details and images
security:
- oAuth2AuthCode: []
parameters:
- name: assignedTo
in: query
Expand Down

0 comments on commit 159bcaa

Please sign in to comment.