Microsoft Azure Bot Service Client Library for Python

2.0.0 · active · verified Thu Apr 09

The azure-mgmt-botservice library provides the Python SDK for programmatically managing Azure Bot Service resources. It enables the creation, update, retrieval, and deletion of bots, channels, connections, SKUs, and properties. It utilizes the modern Azure SDK guidelines, including `azure-identity` for authentication. The current stable version is 2.0.0, and it follows the typical Azure SDK release cadence.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with Azure using `DefaultAzureCredential` and list Bot Service resources within a specified resource group. Ensure `AZURE_SUBSCRIPTION_ID`, `AZURE_RESOURCE_GROUP`, and `AZURE_BOT_NAME` environment variables are set for successful authentication and execution.

import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.botservice import AzureBotService

# Set environment variables or replace with your actual values
# AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET, AZURE_SUBSCRIPTION_ID

subscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', 'YOUR_SUBSCRIPTION_ID')
resource_group_name = os.environ.get('AZURE_RESOURCE_GROUP', 'YOUR_RESOURCE_GROUP_NAME')
bot_name = os.environ.get('AZURE_BOT_NAME', 'YOUR_BOT_NAME')

if subscription_id == 'YOUR_SUBSCRIPTION_ID' or resource_group_name == 'YOUR_RESOURCE_GROUP_NAME' or bot_name == 'YOUR_BOT_NAME':
    raise ValueError("Please set AZURE_SUBSCRIPTION_ID, AZURE_RESOURCE_GROUP, and AZURE_BOT_NAME environment variables or replace placeholders.")

# Authenticate using DefaultAzureCredential
credential = DefaultAzureCredential()

# Create a Bot Service management client
client = AzureBotService(credential=credential, subscription_id=subscription_id)

# Example: List bots in a resource group
try:
    print(f"Listing bots in resource group '{resource_group_name}':")
    bots = client.bots.list_by_resource_group(resource_group_name)
    for bot in bots:
        print(f"  Bot Name: {bot.name}, Location: {bot.location}")
except Exception as e:
    print(f"Error listing bots: {e}")

view raw JSON →