azure-mgmt-botservice-py について
管理SDKでAzure Bot Serviceのリソースを操作するPythonスキルです。Botのライフサイクル管理、チャネル設定、OAuth接続設定に対応します。
主な機能
- 01Botの作成、確認、更新、削除
- 02リソースグループまたはサブスクリプション別の一覧
- 03Botチャネルの設定
- 04チャネル詳細とキーの取得
- 05OAuth接続設定の管理
活用シーン
- 01サブスクリプション内のBot確認
- 02TeamsまたはWeb Chatチャネルの設定
- 03BotのOAuth接続設定
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ sickn33/ agentic-awesome-skills --skill azure-mgmt-botservice-pyインストール後、Claude Code で/azure-mgmt-botservice-pyを入力して読み込まれたか確認します。
詳細
Python 用 Azure Bot Service 管理 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"
)
# Access Direct Line keys
if hasattr(keys.properties, 'properties'):
for site in keys.properties.properties.sites:
print(f"Site: {site.site_name}")
# Do not print Direct Line keys; store only in approved secret storage.
ボット接続(OAuth)
接続設定を作成
import os
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=os.environ["BOT_OAUTH_CLIENT_SECRET"],
scopes="User.Read",
service_provider_id="<service-provider-id>"
)
)
)
接続を一覧表示
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.bots | ボットの CRUD 操作 |
client.channels | チャネル構成 |
client.bot_connection | OAuth 接続設定 |
client.direct_line | Direct Line チャネル操作 |
client.email | メールチャネル操作 |
client.operations | 利用可能な操作 |
client.host_settings | ホスト設定操作 |
SKU オプション
| SKU | 説明 |
|---|---|
F0 | 無料ティア(メッセージ数に制限あり) |
S1 | スタンダードティア(メッセージ数無制限) |
チャネルの種類
| チャネル | クラス | 用途 |
|---|---|---|
MsTeamsChannel | Microsoft Teams | Teams との統合 |
DirectLineChannel | Direct Line | カスタムクライアントとの統合 |
WebChatChannel | Web Chat | 埋め込み可能な Web ウィジェット |
SlackChannel | Slack | Slack ワークスペースとの統合 |
FacebookChannel | Messenger との統合 | |
EmailChannel | メール | メールでの通信 |
ベストプラクティス
- 認証には DefaultAzureCredential を使用します
- 開発では F0 SKU から始め、本番環境では S1 にアップグレードします
- MSA アプリ ID/シークレットを安全に保存します。Key Vault を使用してください
- 必要なチャネルのみを有効にして、攻撃対象領域を減らします
- Direct Line キーを定期的にローテーションします
- 可能な場合は、ボット接続にマネージド ID を使用します
- Web Chat チャネル用に適切な CORS を構成します
使用するタイミング
このスキルは、概要で説明されているワークフローやアクションを実行する場合に適用できます。
制限事項
- このスキルは、タスクが上記の説明の範囲に明確に該当する場合にのみ使用してください。
- 出力を、環境固有の検証、テスト、専門家によるレビューの代わりとして扱わないでください。
- 必要な入力、権限、安全上の境界、成功基準が不足している場合は、作業を中断して確認してください。
管理の例では、実際のリソースやチャネルを作成・変更します。サブスクリプション、リソースグループ、ボット/チャネル ID、および意図する差分を確認してください。新しいボットを登録する前に、現在サポートされている ID の種類、アプリの種類、チャネル/API のバージョンを確認してください。過去の MultiTenant の例は、現在の登録要件を示すものではありません。F0 はティア名であり、すべての統合/チャネルが無料であることを保証するものではありません。チャネルキーや管理応答全体をログに記録しないでください。
コメント
Markdown 対応