Skip to content

Commit c2cb0fd

Browse files
Adding Sample da-adaptive-card-dialog-python
1 parent b11dbee commit c2cb0fd

29 files changed

Lines changed: 1531 additions & 0 deletions
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.funcignore
2+
.git*
3+
.vscode
4+
local.settings.json
5+
.DS_Store
6+
.deployment
7+
__pycache__
8+
.venv
9+
*.pyc
10+
README.md
11+
m365agents.yml
12+
m365agents.*.yml
13+
/env/
14+
/appPackage/
15+
/infra/
16+
/devTools/
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
# TeamsFx files
3+
env/.env.*.user
4+
.DS_Store
5+
build
6+
appPackage/build
7+
.deployment
8+
9+
# dependencies
10+
__pycache__/
11+
*.pyc
12+
.venv/
13+
14+
# testing
15+
/coverage
16+
17+
# Dev tool directories
18+
/devTools/
19+
20+
# Python output
21+
*.egg-info/
22+
*.egg
23+
24+
# Azure Functions artifacts
25+
bin
26+
obj
27+
appsettings.json
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"recommendations": [
3+
"TeamsDevApp.ms-teams-vscode-extension",
4+
"ms-python.python"
5+
]
6+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Launch Agent in Teams (Edge)",
6+
"type": "msedge",
7+
"request": "launch",
8+
"url": "https://m365.cloud.microsoft/chat/entity1-d870f6cd-4aa5-4d42-9626-ab690c041429/${local:agent-hint}?auth=2&developerMode=Basic",
9+
"cascadeTerminateToConfigurations": [
10+
"Python: Run App Locally"
11+
],
12+
"presentation": {
13+
"group": "all",
14+
"hidden": true
15+
},
16+
"internalConsoleOptions": "neverOpen"
17+
},
18+
{
19+
"name": "Launch Agent in Teams (Chrome)",
20+
"type": "chrome",
21+
"request": "launch",
22+
"url": "https://m365.cloud.microsoft/chat/entity1-d870f6cd-4aa5-4d42-9626-ab690c041429/${local:agent-hint}?auth=2&developerMode=Basic",
23+
"cascadeTerminateToConfigurations": [
24+
"Python: Run App Locally"
25+
],
26+
"presentation": {
27+
"group": "all",
28+
"hidden": true
29+
},
30+
"internalConsoleOptions": "neverOpen"
31+
},
32+
{
33+
"name": "Preview in Copilot (Edge)",
34+
"type": "msedge",
35+
"request": "launch",
36+
"url": "https://m365.cloud.microsoft/chat/entity1-d870f6cd-4aa5-4d42-9626-ab690c041429/${agent-hint}?auth=2&developerMode=Basic",
37+
"presentation": {
38+
"group": "remote",
39+
"order": 1
40+
},
41+
"internalConsoleOptions": "neverOpen",
42+
"runtimeArgs": [
43+
"--remote-debugging-port=9224",
44+
"--no-first-run"
45+
]
46+
},
47+
{
48+
"name": "Preview in Copilot (Chrome)",
49+
"type": "chrome",
50+
"request": "launch",
51+
"url": "https://m365.cloud.microsoft/chat/entity1-d870f6cd-4aa5-4d42-9626-ab690c041429/${agent-hint}?auth=2&developerMode=Basic",
52+
"presentation": {
53+
"group": "remote",
54+
"order": 2
55+
},
56+
"internalConsoleOptions": "neverOpen",
57+
"runtimeArgs": [
58+
"--remote-debugging-port=9225",
59+
"--no-first-run"
60+
]
61+
},
62+
{
63+
"name": "Python: Run App Locally",
64+
"type": "debugpy",
65+
"request": "launch",
66+
"program": "${workspaceFolder}/app.py",
67+
"cwd": "${workspaceFolder}",
68+
"console": "integratedTerminal",
69+
"env": {
70+
"PATH": "${workspaceFolder}/devTools/func;${env:PATH}"
71+
}
72+
}
73+
],
74+
"compounds": [
75+
{
76+
"name": "Debug in Copilot (Edge)",
77+
"configurations": [
78+
"Launch Agent in Teams (Edge)",
79+
"Python: Run App Locally"
80+
],
81+
"preLaunchTask": "Start Agent Locally",
82+
"presentation": {
83+
"group": "all",
84+
"order": 1
85+
},
86+
"stopAll": true
87+
},
88+
{
89+
"name": "Debug in Copilot (Chrome)",
90+
"configurations": [
91+
"Launch Agent in Teams (Chrome)",
92+
"Python: Run App Locally"
93+
],
94+
"preLaunchTask": "Start Agent Locally",
95+
"presentation": {
96+
"group": "all",
97+
"order": 2
98+
},
99+
"stopAll": true
100+
}
101+
]
102+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"debug.onTaskErrors": "abort",
3+
"json.schemas": [
4+
{
5+
"fileMatch": [
6+
"/aad.*.json"
7+
],
8+
"schema": {}
9+
}
10+
],
11+
"azureFunctions.stopFuncTaskPostDebug": false,
12+
"azureFunctions.showProjectWarning": false
13+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// This file is automatically generated by Microsoft 365 Agents Toolkit.
2+
// The teamsfx tasks defined in this file require Microsoft 365 Agents Toolkit version >= 5.0.0.
3+
// See https://aka.ms/teamsfx-tasks for details on how to customize each task.
4+
{
5+
"version": "2.0.0",
6+
"tasks": [
7+
{
8+
"label": "Start Agent Locally",
9+
"dependsOn": [
10+
"Validate prerequisites",
11+
"Start local tunnel",
12+
"Create resources",
13+
"Build project"
14+
],
15+
"dependsOrder": "sequence"
16+
},
17+
{
18+
"label": "Validate prerequisites",
19+
"type": "teamsfx",
20+
"command": "debug-check-prerequisites",
21+
"args": {
22+
"prerequisites": [
23+
"m365Account",
24+
"portOccupancy"
25+
],
26+
"portOccupancy": [
27+
7071
28+
]
29+
}
30+
},
31+
{
32+
// Start the local tunnel service to forward public URL to local port and inspect traffic.
33+
// See https://aka.ms/teamsfx-tasks/local-tunnel for the detailed args definitions.
34+
"label": "Start local tunnel",
35+
"type": "teamsfx",
36+
"command": "debug-start-local-tunnel",
37+
"args": {
38+
"type": "dev-tunnel",
39+
"ports": [
40+
{
41+
"portNumber": 7071,
42+
"protocol": "http",
43+
"access": "public",
44+
"writeToEnvironmentFile": {
45+
"endpoint": "OPENAPI_SERVER_URL", // output tunnel endpoint as OPENAPI_SERVER_URL
46+
"domain": "BOT_DOMAIN" // output tunnel domain as BOT_DOMAIN
47+
}
48+
}
49+
],
50+
"env": "local"
51+
},
52+
"isBackground": true,
53+
"problemMatcher": "$teamsfx-local-tunnel-watch"
54+
},
55+
{
56+
"label": "Create resources",
57+
"type": "teamsfx",
58+
"command": "provision",
59+
"args": {
60+
"env": "local"
61+
}
62+
},
63+
{
64+
"label": "Build project",
65+
"type": "teamsfx",
66+
"command": "deploy",
67+
"args": {
68+
"env": "local"
69+
}
70+
}
71+
]
72+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
2+
# Adaptive Card Dialog (Python)
3+
4+
## Summary
5+
6+
This sample demonstrates how to open dialog boxes from Adaptive Cards in a Microsoft 365 Copilot declarative agent. Users can browse programming tutorials for Node.js, JavaScript, and Git, watch official Microsoft video tutorials embedded in dialog boxes, and take interactive quizzes with instant feedback—all within the Copilot interface.
7+
8+
The sample showcases Action.OpenUrlDialog from Adaptive Cards v1.5, Python Azure Functions backend, and API Plugin integration.
9+
10+
<img src="assets/AdaptiveCardsDialogBox.gif" alt="Adaptive Card Dialog" width="100%" />
11+
12+
13+
## Version history
14+
15+
Version|Date|Author|Comments
16+
-------|----|----|--------
17+
1.0|April 20, 2026|[YugalPradhan31](https://github.com/YugalPradhan31)|Initial release
18+
19+
## Prerequisites
20+
21+
* [Microsoft 365 account with Copilot access](https://www.microsoft.com/microsoft-365/enterprise/copilot-for-microsoft-365)
22+
* [Python](https://www.python.org/downloads/) version 3.10 or later
23+
* [Azure Functions Core Tools](https://learn.microsoft.com/azure/azure-functions/functions-run-local) v4
24+
* [Visual Studio Code](https://code.visualstudio.com/)
25+
* [Microsoft 365 Agents Toolkit for VS Code](https://marketplace.visualstudio.com/items?itemName=TeamsDevApp.ms-teams-vscode-extension)
26+
* [Dev tunnels CLI](https://learn.microsoft.com/azure/developer/dev-tunnels/get-started) for local development
27+
28+
## Minimal Path to Awesome
29+
30+
* Clone this repository (or download this solution as a .ZIP file then unzip it)
31+
```bash
32+
git clone https://github.com/pnp/copilot-pro-dev-samples.git
33+
cd copilot-pro-dev-samples/samples/da-adaptive-card-dialog-python
34+
```
35+
* Open the project in Visual Studio Code
36+
* Select the **Microsoft 365 Agents Toolkit** icon on the left in the VS Code toolbar
37+
* In the **Account** section, sign in with your Microsoft 365 account if you haven't already
38+
* Install Python dependencies:
39+
```bash
40+
pip install -r requirements.txt
41+
```
42+
* Create Teams app by selecting **Provision** in the **Lifecycle** section
43+
* Select **Preview in Copilot (Edge)** or **Preview in Copilot (Chrome)** from the launch configuration dropdown, or use **Debug in Microsoft 365 Agents Playground** for local testing
44+
* Once the agent is loaded, you can ask questions like:
45+
- "Show me programming tutorials"
46+
- "I want to learn JavaScript"
47+
- "Git tutorials for beginners"
48+
* The agent will respond with programming tutorials and you can interact with action buttons:
49+
- **Watch Video** - Opens YouTube embed in a large dialog
50+
- **Interactive Quiz** - Opens custom HTML quiz with instant feedback
51+
52+
## Features
53+
54+
This sample illustrates the following concepts for Microsoft 365 Copilot declarative agents:
55+
56+
* **Action.OpenUrlDialog** - Opens URLs in modal dialogs within Microsoft 365 Copilot without leaving the chat interface
57+
58+
### What is Action.OpenUrlDialog?
59+
60+
`Action.OpenUrlDialog` is a new Adaptive Card action (v1.5+) that opens a URL in a modal dialog within Microsoft 365 Copilot, providing an integrated experience without leaving the chat interface.
61+
62+
**Key Characteristics:**
63+
- Opens URLs in modal dialogs within Copilot
64+
- Supports custom dialog sizes (width/height in px or predefined: small, medium, large)
65+
- Requires URLs to be whitelisted in `validDomains` in manifest.json
66+
- Works with YouTube embeds, custom HTML pages, and other web content
67+
68+
### Interaction Flow
69+
70+
**Step 1: Ask for tutorials**
71+
```
72+
User: "Show me programming tutorials"
73+
```
74+
75+
**Step 2: Browse learning resources**
76+
The agent returns adaptive cards showing:
77+
- Topic name (Node.js, JavaScript, Git)
78+
- Difficulty level and duration
79+
- Description
80+
- Two action buttons
81+
82+
**Step 3: Watch Video**
83+
Click "Watch Video" button:
84+
- Opens YouTube embed in a large dialog
85+
- Shows official Microsoft tutorial videos
86+
- Supports fullscreen playback
87+
88+
**Step 4: Take Interactive Quiz**
89+
Click "Interactive Quiz" button:
90+
- Opens custom HTML quiz in dialog (700px height)
91+
- 3 questions with multiple choice options
92+
- Instant feedback with explanations
93+
- Progress bar showing completion
94+
- Final score and key takeaways
95+
- Option to retake quiz
96+
97+
98+
## Help
99+
100+
We do not support samples, but this community is always willing to help, and we want to improve these samples. We use GitHub to track issues, which makes it easy for community members to volunteer their time and help resolve issues.
101+
102+
You can try looking at [issues related to this sample](https://github.com/pnp/copilot-pro-dev-samples/issues?q=label%3A%22sample%3A%20da-adaptive-card-dialog-python%22) to see if anybody else is having the same issues.
103+
104+
If you encounter any issues using this sample, [create a new issue](https://github.com/pnp/copilot-pro-dev-samples/issues/new).
105+
106+
Finally, if you have an idea for improvement, [make a suggestion](https://github.com/pnp/copilot-pro-dev-samples/issues/new).
107+
108+
109+
## Disclaimer
110+
111+
**THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.**
112+
113+
114+
## Further reading
115+
116+
- [Action.OpenUrlDialog Documentation](https://learn.microsoft.com/en-us/microsoft-365-copilot/extensibility/adaptive-card-dialog-box)
117+
- [Build declarative agents for Microsoft 365 Copilot](https://learn.microsoft.com/microsoft-365-copilot/extensibility/overview-declarative-agent)
118+
- [Adaptive Cards Schema Explorer](https://adaptivecards.io/explorer/)
119+
- [API Plugins for Microsoft 365 Copilot](https://learn.microsoft.com/microsoft-365-copilot/extensibility/overview-api-plugins)
120+
121+
<img src="https://m365-visitor-stats.azurewebsites.net/copilot-pro-dev-samples/samples/da-adaptive-card-dialog-python" />
122+
123+
---
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import shutil
2+
import subprocess
3+
import sys
4+
5+
6+
def run_azure_functions():
7+
func_path = shutil.which("func")
8+
9+
if func_path:
10+
try:
11+
subprocess.run(
12+
[func_path, "start", "--port", "7071", "--cors", "*"],
13+
check=True,
14+
)
15+
except subprocess.CalledProcessError as e:
16+
print(f"Error occurred while running Azure Functions: {e}")
17+
sys.exit(1)
18+
else:
19+
print("Azure Functions Core Tools not found. Install from: https://learn.microsoft.com/azure/azure-functions/functions-run-local")
20+
sys.exit(1)
21+
22+
23+
if __name__ == "__main__":
24+
run_azure_functions()

0 commit comments

Comments
 (0)