From d292dc74030d8bf020ace6f84f08f680c58936d6 Mon Sep 17 00:00:00 2001 From: Hui Miao Date: Mon, 6 May 2024 13:13:34 +0800 Subject: [PATCH] fix: update API paths and descriptions for repairs (#11525) --- .../{Repair.cs.tpl => Repairs.cs.tpl} | 16 +++-- .../appPackage/ai-plugin.json.tpl | 60 ++++++++++++++++++- .../apiSpecificationFile/repair.yml | 8 +-- .../js/api-plugin-from-scratch/README.md | 6 +- .../appPackage/ai-plugin.json.tpl | 60 ++++++++++++++++++- .../apiSpecificationFile/repair.yml | 10 ++-- .../src/functions/{repair.js => repairs.js} | 15 ++--- .../ts/api-plugin-from-scratch/README.md | 4 +- .../appPackage/ai-plugin.json.tpl | 60 ++++++++++++++++++- .../apiSpecificationFile/repair.yml | 8 +-- .../src/functions/{repair.ts => repairs.ts} | 8 +-- 11 files changed, 213 insertions(+), 42 deletions(-) rename templates/csharp/api-plugin-from-scratch/{Repair.cs.tpl => Repairs.cs.tpl} (77%) rename templates/js/api-plugin-from-scratch/src/functions/{repair.js => repairs.js} (93%) rename templates/ts/api-plugin-from-scratch/src/functions/{repair.ts => repairs.ts} (94%) diff --git a/templates/csharp/api-plugin-from-scratch/Repair.cs.tpl b/templates/csharp/api-plugin-from-scratch/Repairs.cs.tpl similarity index 77% rename from templates/csharp/api-plugin-from-scratch/Repair.cs.tpl rename to templates/csharp/api-plugin-from-scratch/Repairs.cs.tpl index 5f3bfca385..db0f5a355a 100644 --- a/templates/csharp/api-plugin-from-scratch/Repair.cs.tpl +++ b/templates/csharp/api-plugin-from-scratch/Repairs.cs.tpl @@ -4,16 +4,16 @@ using Microsoft.Extensions.Logging; namespace {{SafeProjectName}} { - public class Repair + public class Repairs { private readonly ILogger _logger; - public Repair(ILoggerFactory loggerFactory) + public Repairs(ILoggerFactory loggerFactory) { - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory.CreateLogger(); } - [Function("repair")] + [Function("repairs")] public async Task RunAsync([HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequestData req) { // Log that the HTTP trigger function received a request. @@ -25,6 +25,14 @@ namespace {{SafeProjectName}} // Get the repair records. var repairRecords = RepairData.GetRepairs(); + // 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; + } + // Filter the repair records by the assignedTo query parameter. var repairs = repairRecords.Where(r => { diff --git a/templates/csharp/api-plugin-from-scratch/appPackage/ai-plugin.json.tpl b/templates/csharp/api-plugin-from-scratch/appPackage/ai-plugin.json.tpl index 3fec4e74cd..1fd835a6b7 100644 --- a/templates/csharp/api-plugin-from-scratch/appPackage/ai-plugin.json.tpl +++ b/templates/csharp/api-plugin-from-scratch/appPackage/ai-plugin.json.tpl @@ -1,12 +1,66 @@ { "schema_version": "v2.1", "name_for_human": "{{appName}}${{APP_NAME_SUFFIX}}", + "namespace": "repairs", "description_for_human": "Track your repair records", "description_for_model": "Plugin for searching a repair list, you can search by who's assigned to the repair.", "functions": [ { - "name": "repair", - "description": "Search for repairs" + "name": "listRepairs", + "description": "Returns a list of repairs with their details and images", + "capabilities": { + "response_semantics": { + "data_path": "$", + "properties": { + "title": "$.title", + "subtitle": "$.description", + "url": "$.image" + }, + "static_template": { + "type": "AdaptiveCard", + "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", + "version": "1.5", + "body": [ + { + "type": "Container", + "$data": "${$root}", + "items": [ + { + "type": "TextBlock", + "text": "id: ${if(id, id, 'N/A')}", + "wrap": true + }, + { + "type": "TextBlock", + "text": "title: ${if(title, title, 'N/A')}", + "wrap": true + }, + { + "type": "TextBlock", + "text": "description: ${if(description, description, 'N/A')}", + "wrap": true + }, + { + "type": "TextBlock", + "text": "assignedTo: ${if(assignedTo, assignedTo, 'N/A')}", + "wrap": true + }, + { + "type": "TextBlock", + "text": "date: ${if(date, date, 'N/A')}", + "wrap": true + }, + { + "type": "Image", + "url": "${image}", + "$when": "${image != null}" + } + ] + } + ] + } + } + } } ], "runtimes": [ @@ -19,7 +73,7 @@ "url": "apiSpecificationFile/repair.yml", "progress_style": "ShowUsageWithInputAndOutput" }, - "run_for_functions": ["repair"] + "run_for_functions": ["listRepairs"] } ] } diff --git a/templates/csharp/api-plugin-from-scratch/appPackage/apiSpecificationFile/repair.yml b/templates/csharp/api-plugin-from-scratch/appPackage/apiSpecificationFile/repair.yml index 7ca98042d0..d20b2f1a39 100644 --- a/templates/csharp/api-plugin-from-scratch/appPackage/apiSpecificationFile/repair.yml +++ b/templates/csharp/api-plugin-from-scratch/appPackage/apiSpecificationFile/repair.yml @@ -7,11 +7,11 @@ servers: - url: ${{OPENAPI_SERVER_URL}}/api description: The repair api server paths: - /repair: + /repairs: get: - operationId: repair - summary: Search for repairs - description: Search for repairs info with its details and image + operationId: listRepairs + summary: List all repairs + description: Returns a list of repairs with their details and images parameters: - name: assignedTo in: query diff --git a/templates/js/api-plugin-from-scratch/README.md b/templates/js/api-plugin-from-scratch/README.md index 84306e168e..54c3062dca 100644 --- a/templates/js/api-plugin-from-scratch/README.md +++ b/templates/js/api-plugin-from-scratch/README.md @@ -31,7 +31,7 @@ When you extend Copilot for Microsoft 365, you maximize the efficiency of your a ## What's included in the template -| Folder | Contents | +| Folder | Contents | | ------------ | ------------------------------------------------------------------------------------------- | | `.vscode` | VSCode files for debugging | | `appPackage` | Templates for the Teams application manifest, the plugin manifest and the API specification | @@ -43,7 +43,7 @@ The following files can be customized and demonstrate an example implementation | File | Contents | | -------------------------------------------- | ------------------------------------------------------------------------------------------------- | -| `src/functions/repair.js` | The main file of a function in Azure Functions. | +| `src/functions/repairs.js` | The main file of a function in Azure Functions. | | `src/repairsData.json` | The data source for the repair API. | | `appPackage/apiSpecificationFile/repair.yml` | A file that describes the structure and behavior of the repair API. | | `appPackage/manifest.json` | Teams application manifest that defines metadata for your plugin inside Microsoft Teams. | @@ -61,4 +61,4 @@ The following are Teams Toolkit specific project files. You can [visit a complet - [Extend Microsoft Copilot for Microsoft 365](https://aka.ms/teamsfx-copilot-plugin) - [Message extensions for Microsoft Copilot for Microsoft 365](https://learn.microsoft.com/microsoft-365-copilot/extensibility/overview-message-extension-bot) - [Microsoft Graph Connectors for Microsoft Copilot for Microsoft 365](https://learn.microsoft.com/microsoft-365-copilot/extensibility/overview-graph-connector) -- [Microsoft Copilot for Microsoft 365 extensibility samples](https://learn.microsoft.com/microsoft-365-copilot/extensibility/samples) \ No newline at end of file +- [Microsoft Copilot for Microsoft 365 extensibility samples](https://learn.microsoft.com/microsoft-365-copilot/extensibility/samples) diff --git a/templates/js/api-plugin-from-scratch/appPackage/ai-plugin.json.tpl b/templates/js/api-plugin-from-scratch/appPackage/ai-plugin.json.tpl index 3fec4e74cd..1fd835a6b7 100644 --- a/templates/js/api-plugin-from-scratch/appPackage/ai-plugin.json.tpl +++ b/templates/js/api-plugin-from-scratch/appPackage/ai-plugin.json.tpl @@ -1,12 +1,66 @@ { "schema_version": "v2.1", "name_for_human": "{{appName}}${{APP_NAME_SUFFIX}}", + "namespace": "repairs", "description_for_human": "Track your repair records", "description_for_model": "Plugin for searching a repair list, you can search by who's assigned to the repair.", "functions": [ { - "name": "repair", - "description": "Search for repairs" + "name": "listRepairs", + "description": "Returns a list of repairs with their details and images", + "capabilities": { + "response_semantics": { + "data_path": "$", + "properties": { + "title": "$.title", + "subtitle": "$.description", + "url": "$.image" + }, + "static_template": { + "type": "AdaptiveCard", + "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", + "version": "1.5", + "body": [ + { + "type": "Container", + "$data": "${$root}", + "items": [ + { + "type": "TextBlock", + "text": "id: ${if(id, id, 'N/A')}", + "wrap": true + }, + { + "type": "TextBlock", + "text": "title: ${if(title, title, 'N/A')}", + "wrap": true + }, + { + "type": "TextBlock", + "text": "description: ${if(description, description, 'N/A')}", + "wrap": true + }, + { + "type": "TextBlock", + "text": "assignedTo: ${if(assignedTo, assignedTo, 'N/A')}", + "wrap": true + }, + { + "type": "TextBlock", + "text": "date: ${if(date, date, 'N/A')}", + "wrap": true + }, + { + "type": "Image", + "url": "${image}", + "$when": "${image != null}" + } + ] + } + ] + } + } + } } ], "runtimes": [ @@ -19,7 +73,7 @@ "url": "apiSpecificationFile/repair.yml", "progress_style": "ShowUsageWithInputAndOutput" }, - "run_for_functions": ["repair"] + "run_for_functions": ["listRepairs"] } ] } diff --git a/templates/js/api-plugin-from-scratch/appPackage/apiSpecificationFile/repair.yml b/templates/js/api-plugin-from-scratch/appPackage/apiSpecificationFile/repair.yml index b19421902f..d20b2f1a39 100644 --- a/templates/js/api-plugin-from-scratch/appPackage/apiSpecificationFile/repair.yml +++ b/templates/js/api-plugin-from-scratch/appPackage/apiSpecificationFile/repair.yml @@ -7,11 +7,11 @@ servers: - url: ${{OPENAPI_SERVER_URL}}/api description: The repair api server paths: - /repair: + /repairs: get: - operationId: repair - summary: Search for repairs - description: Search for repairs info with its details and image + operationId: listRepairs + summary: List all repairs + description: Returns a list of repairs with their details and images parameters: - name: assignedTo in: query @@ -29,7 +29,7 @@ paths: items: properties: id: - type: integer + type: string description: The unique identifier of the repair title: type: string diff --git a/templates/js/api-plugin-from-scratch/src/functions/repair.js b/templates/js/api-plugin-from-scratch/src/functions/repairs.js similarity index 93% rename from templates/js/api-plugin-from-scratch/src/functions/repair.js rename to templates/js/api-plugin-from-scratch/src/functions/repairs.js index 21ad967665..00279139f3 100644 --- a/templates/js/api-plugin-from-scratch/src/functions/repair.js +++ b/templates/js/api-plugin-from-scratch/src/functions/repairs.js @@ -10,13 +10,17 @@ const { app } = require("@azure/functions"); * @param context - The Azure Functions context object. * @returns A promise that resolves with the HTTP response containing the repair information. */ -async function repair(req, context) { +async function repairs(req, context) { context.log("HTTP trigger function processed a request."); + + // Get the repair records from the data.json file. + const repairRecords = require("../repairsData.json"); + // Initialize response. const res = { status: 200, jsonBody: { - results: [], + results: repairRecords, }, }; @@ -28,9 +32,6 @@ async function repair(req, context) { return res; } - // Get the repair records from the data.json file. - const repairRecords = require("../repairsData.json"); - // Filter the repair records by the assignedTo query parameter. const repairs = repairRecords.filter((item) => { const query = assignedTo.trim().toLowerCase(); @@ -44,8 +45,8 @@ async function repair(req, context) { return res; } -app.http("repair", { +app.http("repairs", { methods: ["GET"], authLevel: "anonymous", - handler: repair, + handler: repairs, }); diff --git a/templates/ts/api-plugin-from-scratch/README.md b/templates/ts/api-plugin-from-scratch/README.md index 6fa841c4ac..d1b21bfcef 100644 --- a/templates/ts/api-plugin-from-scratch/README.md +++ b/templates/ts/api-plugin-from-scratch/README.md @@ -43,7 +43,7 @@ The following files can be customized and demonstrate an example implementation | File | Contents | | -------------------------------------------- | ------------------------------------------------------------------------------------------------- | -| `src/functions/repair.ts` | The main file of a function in Azure Functions. | +| `src/functions/repairs.ts` | The main file of a function in Azure Functions. | | `src/repairsData.json` | The data source for the repair API. | | `appPackage/apiSpecificationFile/repair.yml` | A file that describes the structure and behavior of the repair API. | | `appPackage/manifest.json` | Teams application manifest that defines metadata for your plugin inside Microsoft Teams. | @@ -61,4 +61,4 @@ The following are Teams Toolkit specific project files. You can [visit a complet - [Extend Microsoft Copilot for Microsoft 365](https://aka.ms/teamsfx-copilot-plugin) - [Message extensions for Microsoft Copilot for Microsoft 365](https://learn.microsoft.com/microsoft-365-copilot/extensibility/overview-message-extension-bot) - [Microsoft Graph Connectors for Microsoft Copilot for Microsoft 365](https://learn.microsoft.com/microsoft-365-copilot/extensibility/overview-graph-connector) -- [Microsoft Copilot for Microsoft 365 extensibility samples](https://learn.microsoft.com/microsoft-365-copilot/extensibility/samples) \ No newline at end of file +- [Microsoft Copilot for Microsoft 365 extensibility samples](https://learn.microsoft.com/microsoft-365-copilot/extensibility/samples) diff --git a/templates/ts/api-plugin-from-scratch/appPackage/ai-plugin.json.tpl b/templates/ts/api-plugin-from-scratch/appPackage/ai-plugin.json.tpl index 3fec4e74cd..8cf6aaee2a 100644 --- a/templates/ts/api-plugin-from-scratch/appPackage/ai-plugin.json.tpl +++ b/templates/ts/api-plugin-from-scratch/appPackage/ai-plugin.json.tpl @@ -1,12 +1,66 @@ { "schema_version": "v2.1", + "namespace": "repairs", "name_for_human": "{{appName}}${{APP_NAME_SUFFIX}}", "description_for_human": "Track your repair records", "description_for_model": "Plugin for searching a repair list, you can search by who's assigned to the repair.", "functions": [ { - "name": "repair", - "description": "Search for repairs" + "name": "listRepairs", + "description": "Returns a list of repairs with their details and images", + "capabilities": { + "response_semantics": { + "data_path": "$", + "properties": { + "title": "$.title", + "subtitle": "$.description", + "url": "$.image" + }, + "static_template": { + "type": "AdaptiveCard", + "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", + "version": "1.5", + "body": [ + { + "type": "Container", + "$data": "${$root}", + "items": [ + { + "type": "TextBlock", + "text": "id: ${if(id, id, 'N/A')}", + "wrap": true + }, + { + "type": "TextBlock", + "text": "title: ${if(title, title, 'N/A')}", + "wrap": true + }, + { + "type": "TextBlock", + "text": "description: ${if(description, description, 'N/A')}", + "wrap": true + }, + { + "type": "TextBlock", + "text": "assignedTo: ${if(assignedTo, assignedTo, 'N/A')}", + "wrap": true + }, + { + "type": "TextBlock", + "text": "date: ${if(date, date, 'N/A')}", + "wrap": true + }, + { + "type": "Image", + "url": "${image}", + "$when": "${image != null}" + } + ] + } + ] + } + } + } } ], "runtimes": [ @@ -19,7 +73,7 @@ "url": "apiSpecificationFile/repair.yml", "progress_style": "ShowUsageWithInputAndOutput" }, - "run_for_functions": ["repair"] + "run_for_functions": ["listRepairs"] } ] } diff --git a/templates/ts/api-plugin-from-scratch/appPackage/apiSpecificationFile/repair.yml b/templates/ts/api-plugin-from-scratch/appPackage/apiSpecificationFile/repair.yml index f4d0ab88ca..d20b2f1a39 100644 --- a/templates/ts/api-plugin-from-scratch/appPackage/apiSpecificationFile/repair.yml +++ b/templates/ts/api-plugin-from-scratch/appPackage/apiSpecificationFile/repair.yml @@ -7,11 +7,11 @@ servers: - url: ${{OPENAPI_SERVER_URL}}/api description: The repair api server paths: - /repair: + /repairs: get: - operationId: repair - summary: Returns a repair - description: Returns a repair with its details and image + operationId: listRepairs + summary: List all repairs + description: Returns a list of repairs with their details and images parameters: - name: assignedTo in: query diff --git a/templates/ts/api-plugin-from-scratch/src/functions/repair.ts b/templates/ts/api-plugin-from-scratch/src/functions/repairs.ts similarity index 94% rename from templates/ts/api-plugin-from-scratch/src/functions/repair.ts rename to templates/ts/api-plugin-from-scratch/src/functions/repairs.ts index 27fbecc0f9..fc81dfd57a 100644 --- a/templates/ts/api-plugin-from-scratch/src/functions/repair.ts +++ b/templates/ts/api-plugin-from-scratch/src/functions/repairs.ts @@ -14,7 +14,7 @@ import repairRecords from "../repairsData.json"; * @param {InvocationContext} context - The Azure Functions context object. * @returns {Promise} - A promise that resolves with the HTTP response containing the repair information. */ -export async function repair( +export async function repairs( req: HttpRequest, context: InvocationContext ): Promise { @@ -24,7 +24,7 @@ export async function repair( const res: HttpResponseInit = { status: 200, jsonBody: { - results: [], + results: repairRecords, }, }; @@ -49,8 +49,8 @@ export async function repair( return res; } -app.http("repair", { +app.http("repairs", { methods: ["GET"], authLevel: "anonymous", - handler: repair, + handler: repairs, });