The webexpythonsdk provides a Pythonic abstraction for creating Adaptive Cards without manually constructing complex JSON structures. You can compose cards using specialized model classes for the card container, body elements (like TextBlock), inputs (like Text or Number), and actions (like Submit).
To send a card, include the AdaptiveCard instance in the attachments list of the api.messages.create() method.
from webexpythonsdk import WebexAPI
from webexpythonsdk.models.cards.card import AdaptiveCard
from webexpythonsdk.models.cards.inputs import Text, Number
from webexpythonsdk.models.cards.card_elements import TextBlock
from webexpythonsdk.models.cards.actions import Submit
# Define card elements
greeting = TextBlock("Hey hello there! I am a adaptive card")
first_name = Text('first_name', placeholder="First Name")
age = Number('age', placeholder="Age")
# Define actions
submit = Submit(title="Send me!")
# Compose the card
card = AdaptiveCard(body=[greeting, first_name, age], actions=[submit])
# Send the card via a message
api = WebexAPI()
api.messages.create(text="fallback", roomId="YOUR_ROOM_ID", attachments=[card])