
关于
适用于 Python 的 Azure Bot Service 管理 SDK。用于创建、管理和配置 Azure Bot Service 资源。
name: azure-mgmt-botservice-py description: Azure Bot Service Python 管理 SDK。用于创建、管理和配置 Azure Bot Service 资源。 risk: unknown source: community date_added: '2026-02-27'
Azure Bot Service Python 管理 SDK
管理 Azure Bot Service 资源,包括机器人、频道和连接。
安装
pip install azure-mgmt-botservice
pip install azure-identity
环境变量
AZURE_SUBSCRIPTION_ID=<your-subscription-id>
AZURE_RESOURCE_GROUP=<your-resource-group>
认证
from azure.identity import DefaultAzureCredential
from azure.mgmt.botservice import AzureBotService
import os
credential = DefaultAzureCredential()
client = AzureBotService(
credential=credential,
subscription_id=os.environ["AZURE_SUBSCRIPTION_ID"]
)
创建机器人
from azure.mgmt.botservice import AzureBotService
from azure.mgmt.botservice.models import Bot, BotProperties, Sku
from azure.identity import DefaultAzureCredential
import os
credential = DefaultAzureCredential()
client = AzureBotService(
credential=credential,
subscription_id=os.environ["AZURE_SUBSCRIPTION_ID"]
)
resource_group = os.environ["AZURE_RESOURCE_GROUP"]
bot_name = "my-chat-bot"
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}")
获取机器人详情
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}")
列出资源组中的机器人
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}")
列出订阅中的所有机器人
all_bots = client.bots.list()
for bot in all_bots:
print(f"Bot: {bot.name} in {bot.id.split('/')[4]}")
更新机器人
bot = client.bots.update(
resource_group_name=resource_group,
resource_name=bot_name,
properties=BotProperties(
display_name="Updated Bot Name",
description="Updated description"
)
)
删除机器人
client.bots.delete(
resource_group_name=resource_group,
resource_name=bot_name
)
配置频道
添加 Teams 频道
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
)
)
)
)
添加 Direct Line 频道
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
)
]
)
)
)
)
添加 Web Chat 频道
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
)
]
)
)
)
)
获取频道详情
channel = client.channels.get(
resource_group_name=resource_group,
resource_name=bot_name,
channel_name="DirectLineChannel"
)
列出频道密钥
keys = client.channels.list_with_keys(
resource_group_name=resource_group,
resource_name=bot_name,
channel_name="DirectLineChannel"
)
兼容工具
Claude CodeCursor
标签
后端开发
