mcpField
A
azure-mgmt-botservice-py

azure-mgmt-botservice-py

github.com/sickn33クラウド・DevOps48.7k53 回インストール今日更新
リポジトリ

azure-mgmt-botservice-py について

管理SDKでAzure Bot Serviceのリソースを操作するPythonスキルです。Botのライフサイクル管理、チャネル設定、OAuth接続設定に対応します。

主な機能

  1. 01Botの作成、確認、更新、削除
  2. 02リソースグループまたはサブスクリプション別の一覧
  3. 03Botチャネルの設定
  4. 04チャネル詳細とキーの取得
  5. 05OAuth接続設定の管理

活用シーン

  1. 01サブスクリプション内のBot確認
  2. 02TeamsまたはWeb Chatチャネルの設定
  3. 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_connectionOAuth 接続設定
client.direct_lineDirect Line チャネル操作
client.emailメールチャネル操作
client.operations利用可能な操作
client.host_settingsホスト設定操作

SKU オプション

SKU説明
F0無料ティア(メッセージ数に制限あり)
S1スタンダードティア(メッセージ数無制限)

チャネルの種類

チャネルクラス用途
MsTeamsChannelMicrosoft TeamsTeams との統合
DirectLineChannelDirect Lineカスタムクライアントとの統合
WebChatChannelWeb Chat埋め込み可能な Web ウィジェット
SlackChannelSlackSlack ワークスペースとの統合
FacebookChannelFacebookMessenger との統合
EmailChannelメールメールでの通信

ベストプラクティス

  1. 認証には DefaultAzureCredential を使用します
  2. 開発では F0 SKU から始め、本番環境では S1 にアップグレードします
  3. MSA アプリ ID/シークレットを安全に保存します。Key Vault を使用してください
  4. 必要なチャネルのみを有効にして、攻撃対象領域を減らします
  5. Direct Line キーを定期的にローテーションします
  6. 可能な場合は、ボット接続にマネージド ID を使用します
  7. Web Chat チャネル用に適切な CORS を構成します

使用するタイミング

このスキルは、概要で説明されているワークフローやアクションを実行する場合に適用できます。

制限事項

  • このスキルは、タスクが上記の説明の範囲に明確に該当する場合にのみ使用してください。
  • 出力を、環境固有の検証、テスト、専門家によるレビューの代わりとして扱わないでください。
  • 必要な入力、権限、安全上の境界、成功基準が不足している場合は、作業を中断して確認してください。

管理の例では、実際のリソースやチャネルを作成・変更します。サブスクリプション、リソースグループ、ボット/チャネル ID、および意図する差分を確認してください。新しいボットを登録する前に、現在サポートされている ID の種類、アプリの種類、チャネル/API のバージョンを確認してください。過去の MultiTenant の例は、現在の登録要件を示すものではありません。F0 はティア名であり、すべての統合/チャネルが無料であることを保証するものではありません。チャネルキーや管理応答全体をログに記録しないでください。

コメント