Azure Bot Service 资源管理 SDK
azure-mgmt-botservice-py
适用于 Python 的 Azure Bot Service 管理 SDK。用于创建、管理和配置 Azure Bot Service 资源。 触发词:"azure-mgmt-botservice"、"AzureBotService"、"bot management"(机器人管理)、"conversational AI"(对话式 AI)、"bot channels"(机器人渠道)。
- License 许可
- MIT
- 所属仓库
- microsoft/skills
- 最近更新
- 2026-11-14
- Stars
- ★ 3.2k
- Forks
- 368
01 前言 Front Matter
- name
- azure-mgmt-botservice-py
- license
- MIT
- metadata
- { "author": "Microsoft", "version": "1.0.0" }
- description
- Azure Bot Service Management SDK for Python. Use for creating, managing, and configuring Azure Bot Service resources. Triggers: "azure-mgmt-botservice", "AzureBotService", "bot management", "conversational AI", "bot channels".
02 资源文件 2
- 参考文档references/capabilities.md2.3 KB
- 参考文档references/non-hero-scenarios.md4.9 KB
03 SKILL.md 正文
Azure Bot Service Management SDK for Python
Manage Azure Bot Service resources including bots, channels, and connections.
Installation
pip install azure-mgmt-botservice
pip install azure-identity
Environment Variables
AZURE_SUBSCRIPTION_ID=<your-subscription-id> # Required for all auth methods
AZURE_RESOURCE_GROUP=<your-resource-group> # Required for all auth methods
AZURE_TOKEN_CREDENTIALS=prod # Required only if DefaultAzureCredential is used in production
Authentication & Lifecycle
? Two rules apply to every code sample below:
- Prefer
DefaultAzureCredential. It works locally (Azure CLI / VS Code / Developer CLI) and in Azure (managed identity, workload identity) with no code change. Avoid connection strings, account/API keys — they bypass Entra audit and rotation.
- Local dev:
DefaultAzureCredentialworks as-is.- Production: set
AZURE_TOKEN_CREDENTIALS=prod(orAZURE_TOKEN_CREDENTIALS=<specific_credential>) to constrain the credential chain to production-safe credentials.- Wrap every client in a context manager so HTTP transports, sockets, and token caches are released deterministically:
- Sync:
with <Client>(...) as client:- Async:
async with <Client>(...) as client:andasync with DefaultAzureCredential() as credential:(fromazure.identity.aio)Snippets may abbreviate this setup, but production code should always follow both rules.
from azure.identity import DefaultAzureCredential, ManagedIdentityCredential
from azure.mgmt.botservice import AzureBotService
import os
# Local dev: DefaultAzureCredential. Production: set AZURE_TOKEN_CREDENTIALS=prod or AZURE_TOKEN_CREDENTIALS=<specific_credential>
credential = DefaultAzureCredential(require_envvar=True)
# Or use a specific credential directly in production:
# See https://learn.microsoft.com/python/api/overview/azure/identity-readme?view=azure-python#credential-classes
# credential = ManagedIdentityCredential()
with AzureBotService(
credential=credential,
subscription_id=os.environ["AZURE_SUBSCRIPTION_ID"]
) as client:
# Use `client` for all subsequent operations (see examples below)
...
Create a Bot
from azure.mgmt.botservice import AzureBotService
from azure.mgmt.botservice.models import Bot, BotProperties, Sku
from azure.identity import DefaultAzureCredential
import os
resource_group = os.environ["AZURE_RESOURCE_GROUP"]
bot_name = "my-chat-bot"
credential = DefaultAzureCredential()
with AzureBotService(
credential=credential,
subscription_id=os.environ["AZURE_SUBSCRIPTION_ID"]
) as client:
bot = client.bots.create(
resource_group_name=resource_group,
resource_name=bot_name,
parameters=Bot(
location="global",
sku=Sku(name="F0"), # Free tier
kind="azurebot",
properties=BotProperties(
display_name="My Chat Bot",
description="A conversational AI bot",
endpoint="https://my-bot-app.azurewebsites.net/api/messages",
msa_app_id="<your-app-id>",
msa_app_type="MultiTenant"
)
)
)
print(f"Bot created: {bot.name}")
Get Bot Details
bot = client.bots.get(
resource_group_name=resource_group,
resource_name=bot_name
)
print(f"Bot: {bot.properties.display_name}")
print(f"Endpoint: {bot.properties.endpoint}")
print(f"SKU: {bot.sku.name}")
List Bots in Resource Group
bots = client.bots.list_by_resource_group(resource_group_name=resource_group)
for bot in bots:
print(f"Bot: {bot.name} - {bot.properties.display_name}")
List All Bots in Subscription
all_bots = client.bots.list()
for bot in all_bots:
print(f"Bot: {bot.name} in {bot.id.split('/')[4]}")
Update Bot
bot = client.bots.update(
resource_group_name=resource_group,
resource_name=bot_name,
properties=BotProperties(
display_name="Updated Bot Name",
description="Updated description"
)
)
Delete Bot
client.bots.delete(
resource_group_name=resource_group,
resource_name=bot_name
)
Configure Channels
Add Teams Channel
from azure.mgmt.botservice.models import (
BotChannel,
MsTeamsChannel,
MsTeamsChannelProperties
)
channel = client.channels.create(
resource_group_name=resource_group,
resource_name=bot_name,
channel_name="MsTeamsChannel",
parameters=BotChannel(
location="global",
properties=MsTeamsChannel(
properties=MsTeamsChannelProperties(
is_enabled=True
)
)
)
)
Add Direct Line Channel
from azure.mgmt.botservice.models import (
BotChannel,
DirectLineChannel,
DirectLineChannelProperties,
DirectLineSite
)
channel = client.channels.create(
resource_group_name=resource_group,
resource_name=bot_name,
channel_name="DirectLineChannel",
parameters=BotChannel(
location="global",
properties=DirectLineChannel(
properties=DirectLineChannelProperties(
sites=[
DirectLineSite(
site_name="Default Site",
is_enabled=True,
is_v1_enabled=False,
is_v3_enabled=True
)
]
)
)
)
)
Add Web Chat Channel
from azure.mgmt.botservice.models import (
BotChannel,
WebChatChannel,
WebChatChannelProperties,
WebChatSite
)
channel = client.channels.create(
resource_group_name=resource_group,
resource_name=bot_name,
channel_name="WebChatChannel",
parameters=BotChannel(
location="global",
properties=WebChatChannel(
properties=WebChatChannelProperties(
sites=[
WebChatSite(
site_name="Default Site",
is_enabled=True
)
]
)
)
)
)
Get Channel Details
channel = client.channels.get(
resource_group_name=resource_group,
resource_name=bot_name,
channel_name="DirectLineChannel"
)
List Channel Keys
keys = client.channels.list_with_keys(
resource_group_name=resource_group,
resource_name=bot_name,
channel_name="DirectLineChannel"
)
# Access Direct Line keys
if hasattr(keys.properties, 'properties'):
for site in keys.properties.properties.sites:
print(f"Site: {site.site_name}")
print(f"Key: {site.key}")
Bot Connections (OAuth)
Create Connection Setting
from azure.mgmt.botservice.models import (
ConnectionSetting,
ConnectionSettingProperties
)
connection = client.bot_connection.create(
resource_group_name=resource_group,
resource_name=bot_name,
connection_name="graph-connection",
parameters=ConnectionSetting(
location="global",
properties=ConnectionSettingProperties(
client_id="<oauth-client-id>",
client_secret="<oauth-client-secret>",
scopes="User.Read",
service_provider_id="<service-provider-id>"
)
)
)
List Connections
connections = client.bot_connection.list_by_bot_service(
resource_group_name=resource_group,
resource_name=bot_name
)
for conn in connections:
print(f"Connection: {conn.name}")
Client Operations
| Operation | Method |
|---|---|
client.bots |
Bot CRUD operations |
client.channels |
Channel configuration |
client.bot_connection |
OAuth connection settings |
client.direct_line |
Direct Line channel operations |
client.email |
Email channel operations |
client.operations |
Available operations |
client.host_settings |
Host settings operations |
SKU Options
| SKU | Description |
|---|---|
F0 |
Free tier (limited messages) |
S1 |
Standard tier (unlimited messages) |
Channel Types
| Channel | Class | Purpose |
|---|---|---|
MsTeamsChannel |
Microsoft Teams | Teams integration |
DirectLineChannel |
Direct Line | Custom client integration |
WebChatChannel |
Web Chat | Embeddable web widget |
SlackChannel |
Slack | Slack workspace integration |
FacebookChannel |
Messenger integration | |
EmailChannel |
Email communication |
Best Practices
- Pick sync OR async and stay consistent. Do not mix
azure.xxxsync clients withazure.xxx.aioasync clients in the same call path. Choose one mode per module. - Always use context managers for clients and async credentials. Wrap every client in
with Client(...) as client:(sync) orasync with Client(...) as client:(async). For asyncDefaultAzureCredentialfromazure.identity.aio, also useasync with credential:so tokens and transports are cleaned up. - Use
DefaultAzureCredentialfor code that runs locally. Use a specific token credential for code that runs in Azure. - Start with F0 SKU for development, upgrade to S1 for production
- Store MSA App ID/Secret securely — use Key Vault
- Enable only needed channels — reduces attack surface
- Rotate Direct Line keys periodically
- Use managed identity when possible for bot connections
- Configure proper CORS for Web Chat channel
Reference Files
| File | Contents |
|---|---|
| references/capabilities.md | Additional non-hero capabilities, operation-group coverage, and production checklists. |
| references/non-hero-scenarios.md | Dedicated non-hero examples for secondary/advanced scenarios. |
04 同仓库更多 Skills
azure-advisor-cost-optimization
Analyze Azure Advisor Cost/IdleResources findings and prevalidate deletion safety, including Service Groups. WHEN: "find unused Azure resources", "what resources am I paying for but no longer using", "idle-resource savings", "historical idle-resource savings", "are these idle resources safe to delete". Generic Cost, other subcategories, and cross-category requests use azure-advisor.
Azure 技能创建与更新指南
skill-creator
面向使用 Azure SDK 和 Microsoft Foundry 服务的 AI 编码智能体,指导其创建高效技能的指南。在创建新技能或更新现有技能时使用。
AI 播客音频生成
podcast-generation
通过 WebSocket 使用 Azure OpenAI 的 GPT Realtime Mini 模型生成 AI 驱动的播客式音频叙述。当构建文本转语音功能、音频叙述生成、根据内容制作播客,或集成 Azure OpenAI Realtime API 以获得真实音频输出时使用。涵盖从 React 前端到 Python FastAPI 后端及 WebSocket 流式传输的全栈实现。
Microsoft 技术文档查询
microsoft-docs
通过查询官方文档来理解 Microsoft 技术。当用户询问某项技术的工作原理、想要教程、需要任何 Microsoft 技术(Azure、.NET、M365、Windows、Power Platform 等)的配置选项、限制、配额或最佳实践时使用——即使他们没有提到"文档"。如果问题是为了理解概念而非编写代码,那么这就是合适的技能。
MCP 服务器构建
mcp-builder
用于创建高质量 MCP(Model Context Protocol)服务器的指南,使大语言模型能够通过设计完善的工具与外部服务交互。当构建用于集成外部 API 或服务的 MCP 服务器时使用,无论采用 Python(FastMCP)、Node/TypeScript(MCP SDK),还是 C#/.NET(Microsoft MCP SDK)。
KQL 查询编写与调试
kql
KQL 语言专业能力,用于编写正确且高效的 Kusto Query Language 查询。涵盖语法陷阱、join 模式、dynamic 类型、datetime 陷阱、regex 模式、序列化、内存管理、结果集规模控制,以及高级函数(geo、vector、graph)。在编写、调试或审查 KQL 查询时均使用本技能——即使是简单查询——因为陷阱章节可防止最常见的错误,避免浪费工具调用并引发代价高昂的连锁重试。触发条件:KQL、Kusto、ADX、Azure Data Explorer、Fabric Real-Time Intelligence、EventHouse、Log Analytics、日志分析、数据探索、时间序列、异常检测、summarize、where 子句、join、extend、project、let 语句、parse 运算符、extract 函数,以及任何提及管道式查询语法的情形。