microsoft/AdaptiveCards

[Authoring] CodeBlock does not documented properly

pavel-smirnov-sephora opened this issue ยท 0 comments

Target Application

Microsoft Teams

Application Operating System

Windows

Schema Version

1.5

Problem Description

Right now the only information about CodeBlock syntax available here - https://learn.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-format?tabs=adaptive-md%2Cdesktop%2Cconnector-html#codeblock-in-adaptive-cards.
As it's finds out empirically, not all supported languages are actually supported by Adaptive card renderer on MSTeams side.

I'll add working and non-working examples as I'm progressing through experimentation.

In the end - it's super hard to guess what is acceptable set of languages when developing Bot responses with CodeBlock. Please update Documentation and Schema guys.

Expected Outcome

CodeBlock requirements and supported values (i.e. in language field) should be added in https://adaptivecards.io/schemas/1.5.0/adaptive-card.json (or later versions)

Actual Outcome

Example of not working "language" keys:

  • 'sh' as for bash snippet
  • 'c' as for C
  • 'batch' as for DOS
  • 'go' as for Go
  • 'markdown' as for Markdown
  • 'vb' and 'vba' as for Virtual Basic

Examples of working (empirically tested it myself) "language" keys:

  • 'cpp' as for C++
  • 'csharp' as for C#
  • 'python' as for Python
  • 'css' as for CSS
  • 'verilog' as for Verilog
  • 'vhdl' as for VHDL
  • 'xml' as for XML
  • 'sql' as for SQL
  • 'powershell' as for PowerShell
  • 'php' as for PHP
  • 'perl' as for Perl
  • 'json' as for JSON
  • 'java' as for Java
  • 'html' as for HTML
  • 'graphql' as for GraphQL
  • 'golang' as for Go
  • 'bash' as for Bash

Card JSON

{"type": "AdaptiveCard", "version": "1.2", "msteams": {"width": "Full"}, "body": [{"type": "TextBlock", "wrap": True, "text": "Certainly! Below is another example of a Go program. This one demonstrates how to create a simple HTTP server that responds with "Hello, World!" when accessed via a web browser or an HTTP client.", "isSubtle": False, "size": "Default"}, {"type": "CodeBlock", "language": "go", "startLineNumber": 1, "codeSnippet": "package main\n\nimport (\n\t"fmt"\n\t"net/http"\n)\n\n// helloHandler responds with "Hello, World!" to any HTTP request\nfunc helloHandler(w http.ResponseWriter, r *http.Request) {\n\tfmt.Fprintln(w, "Hello, World!")\n}\n\nfunc main() {\n\t// Register the helloHandler function to handle requests to the root URL "/"\n\thttp.HandleFunc("/", helloHandler)\n\n\t// Start the HTTP server on port 8080\n\tfmt.Println("Starting server on :8080")\n\tif err := http.ListenAndServe(":8080", nil); err != nil {\n\t\tfmt.Println("Error starting server:", err)\n\t}\n}"}, {"type": "TextBlock", "wrap": True, "text": "### Explanation:\n\n1. **Package Declaration**: The program starts with `package main`, indicating that this is an executable program.\n\n2. **Importing Packages**: The `fmt` package is imported for formatted I/O operations, and the `net/http` package is imported to create the HTTP server.\n\n3. **Handler Function**: \n   - The `helloHandler` function is defined to handle HTTP requests. It takes two parameters: `w` (an `http.ResponseWriter` to write the response) and `r` (an `*http.Request` representing the incoming request).\n   - The function writes "Hello, World!" to the response writer using `fmt.Fprintln`.\n\n4. **Main Function**:\n   - The `main` function registers the `helloHandler` function to handle requests to the root URL `/` using `http.HandleFunc`.\n   - It starts the HTTP server on port 8080 using `http.ListenAndServe`. If the server fails to start, it prints an error message.\n\nTo run this program, save it to a file with a `.go` extension (e.g., `server.go`), and then use the `go run` command:", "isSubtle": False, "size": "Default"}, {"type": "CodeBlock", "language": "sh", "startLineNumber": 1, "codeSnippet": "go run server.go"}, {"type": "TextBlock", "wrap": True, "text": "This will start the HTTP server on port 8080. You can then open a web browser and navigate to `http://localhost:8080` to see the "Hello, World!" message. Alternatively, you can use a tool like `curl` to make an HTTP request:", "isSubtle": False, "size": "Default"}, {"type": "CodeBlock", "language": "sh", "startLineNumber": 1, "codeSnippet": "curl http://localhost:8080"}, {"type": "TextBlock", "wrap": True, "text": "---", "isSubtle": False, "size": "Default"}, {"type": "Container", "items": [{"type": "TextBlock", "wrap": True, "text": "AI-generated content may be incorrect. Check references for accuracy.", "isSubtle": True, "size": "Small"}, {"type": "ActionSet", "actions": [{"type": "Action.ShowCard", "title": "๐Ÿ‘", "card": {"type": "AdaptiveCard", "version": "1.2", "msteams": None, "body": [{"type": "Input.Text", "id": "COMMENT_LIKE", "isMultiline": True, "label": "Add a comment and press OK to send your feedback"}], "actions": [{"type": "Action.Submit", "title": "OK", "data": {"message_id": "18e22f21b9c648aab95cc1bc00a28d90", "card_id": "f11c4ac8bd89440cb2c12cbb253deea0", "type": "LIKE"}}]}}, {"type": "Action.ShowCard", "title": "๐Ÿ‘Ž", "card": {"type": "AdaptiveCard", "version": "1.2", "msteams": None, "body": [{"type": "Input.Text", "id": "COMMENT_DISLIKE", "isMultiline": True, "label": "Add a comment and press OK to send your feedback"}], "actions": [{"type": "Action.Submit", "title": "OK", "data": {"message_id": "18e22f21b9c648aab95cc1bc00a28d90", "card_id": "f11c4ac8bd89440cb2c12cbb253deea0", "type": "DISLIKE"}}]}}]}], "width": "stretch"}], "actions": None, "$schema": "http://adaptivecards.io/schemas/adaptive-card.json"}

Repro Steps

No response