Skip to content

Adaptive cards doc fixes #184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Dec 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 44 additions & 8 deletions docs/user/cards.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,26 @@
Cards and Buttons
=================

Webex Teams supports `AdaptiveCards <https://www.adaptivecards.io/>`_ to allow
Webex supports `AdaptiveCards <https://www.adaptivecards.io/>`_ to allow
new levels of interactivity for bots and integrations. You can read more about
how cards and buttons work `in the official guide <https://developer.webex.com/docs/api/guides/cards>`_.

In this guide I want to cover the abstraction build into the webexteamssdk that
In this guide I want to cover the abstraction built into the webexteamssdk that
lets you author adaptive cards in pure python without having to touch the
underlying json of a adaptive card.
underlying JSON of an adaptive card.

Sending a card
==============

Lets dive into a simple example that sends a card to a room

.. code-block:: python

from webexteamssdk import WebexTeamsAPI
from webexteamssdk.cards.card import AdaptiveCard
from webexteamssdk.cards.inputs import Text, Number
from webexteamssdk.cards.components import TextBlock
from webexteamssdk.cards.actions import Submit
from webexteamssdk.models.cards.card import AdaptiveCard
from webexteamssdk.models.cards.inputs import Text, Number
from webexteamssdk.models.cards.components import TextBlock
from webexteamssdk.models.cards.actions import Submit

greeting = TextBlock("Hey hello there! I am a adaptive card")
first_name = Text('first_name', placeholder="First Name")
Expand All @@ -33,7 +36,40 @@ Lets dive into a simple example that sends a card to a room
api = WebexTeamsAPI()
api.messages.create(text="fallback", roomId="...", attachments=[card])

The message we send with this code then looks like this in our Webex Teams
The message we send with this code then looks like this in our Webex space
client:

.. image:: ../images/cards_sample.png


Processing a card action
=======================

Adaptive card interactions are treated as "attachment actions". Once user interacts
with your card and submits an action, your app will receive a webhook from Webex. You
must `setup a webhook <api.rst#webhooks>`_ in advance with ``resource = "attachmentActions"``
and ``event = "created"``.

Webhook payload will contain a JSON:

.. code-block:: json

{
"resource": "attachmentActions",
"event": "created",
"data": {
"id": "XYXYXY",
"type": "submit"
}
}

Extract attachment action ID from ``['data']['id']`` and
use `attachment_actions.get() <api.rst#attachment_actions>`_ to get full information
about user action and any submitted data.

.. code-block:: python

action = api.attachment_actions.get(webhookJson['data']['id'])

first_name = action.inputs['first_name']
age = action.inputs['age']