BotBuilder Schema
The `botbuilder-schema` library provides the core data structures and schema definitions for the Microsoft Bot Framework Python SDK. It defines essential classes like `Activity`, `ConversationAccount`, and `ChannelAccount` that represent messages and participants in a bot conversation. Version 4.17.1 is the final release, as the broader Bot Framework Python SDK has officially reached end-of-life and will no longer be updated or maintained.
Warnings
- breaking End-of-Life (EOL) Status: The `botbuilder-schema` library is part of the Bot Framework Python SDK, which has officially reached End-of-Life (EOL) with version 4.17.1. It will no longer receive updates, maintenance, or support. Existing applications will not be immediately disrupted, but new development or seeking support is highly discouraged.
- gotcha Python 3.8+ Requirement: Beginning with SDK version 4.15.0, the broader Bot Framework SDK (of which `botbuilder-schema` is a component) requires Python 3.8 or newer due to its `aiohttp` dependency (version 3.9+). Deployments using Python 3.7 or earlier will encounter compatibility issues.
- gotcha Missing Schema for Newer Features: As an EOL library, `botbuilder-schema` will not receive updates for new Microsoft Teams or Bot Framework features. If your bot needs to interact with recently introduced invoke types (e.g., 'config/fetch', 'config/submit' added in 4.17.0) or other new schema elements, older `botbuilder-schema` versions might lack the necessary definitions, leading to runtime errors or unexpected behavior when deserializing activities.
Install
-
pip install botbuilder-schema
Imports
- Activity
from botbuilder.schema import Activity
- ConversationAccount
from botbuilder.schema import ConversationAccount
- ChannelAccount
from botbuilder.schema import ChannelAccount
Quickstart
import datetime
from botbuilder.schema import Activity, ActivityTypes, ConversationAccount, ChannelAccount
# Create a sample conversation account
conversation = ConversationAccount(
id="conversationId123",
conversation_type="personal",
is_group=False,
tenant_id="tenantId123"
)
# Create a sample channel account for the user
user = ChannelAccount(
id="userId123",
name="Test User",
role="user"
)
# Create a sample channel account for the bot
bot = ChannelAccount(
id="botId456",
name="Test Bot",
role="bot"
)
# Create an Activity object
activity = Activity(
type=ActivityTypes.message,
id="messageId789",
timestamp=datetime.datetime.now(datetime.timezone.utc),
service_url="https://example.azurewebsites.net/api/messages",
channel_id="emulator",
conversation=conversation,
from_property=user, # 'from' is a reserved keyword in Python, hence from_property
recipient=bot,
text="Hello from the botbuilder-schema quickstart!",
locale="en-US"
)
print(f"Created Activity of type: {activity.type}")
print(f"Activity text: {activity.text}")
print(f"From: {activity.from_property.name} ({activity.from_property.id})")
print(f"To: {activity.recipient.name} ({activity.recipient.id})")