4
4
Cards and Buttons
5
5
=================
6
6
7
- Webex Teams supports `AdaptiveCards <https://www.adaptivecards.io/ >`_ to allow
7
+ Webex supports `AdaptiveCards <https://www.adaptivecards.io/ >`_ to allow
8
8
new levels of interactivity for bots and integrations. You can read more about
9
9
how cards and buttons work `in the official guide <https://developer.webex.com/docs/api/guides/cards >`_.
10
10
11
- In this guide I want to cover the abstraction build into the webexteamssdk that
11
+ In this guide I want to cover the abstraction built into the webexteamssdk that
12
12
lets you author adaptive cards in pure python without having to touch the
13
- underlying json of a adaptive card.
13
+ underlying JSON of an adaptive card.
14
+
15
+ Sending a card
16
+ ==============
14
17
15
18
Lets dive into a simple example that sends a card to a room
16
19
17
20
.. code-block :: python
18
21
19
22
from webexteamssdk import WebexTeamsAPI
20
- from webexteamssdk.cards.card import AdaptiveCard
21
- from webexteamssdk.cards.inputs import Text, Number
22
- from webexteamssdk.cards.components import TextBlock
23
- from webexteamssdk.cards.actions import Submit
23
+ from webexteamssdk.models. cards.card import AdaptiveCard
24
+ from webexteamssdk.models. cards.inputs import Text, Number
25
+ from webexteamssdk.models. cards.components import TextBlock
26
+ from webexteamssdk.models. cards.actions import Submit
24
27
25
28
greeting = TextBlock(" Hey hello there! I am a adaptive card" )
26
29
first_name = Text(' first_name' , placeholder = " First Name" )
@@ -33,7 +36,40 @@ Lets dive into a simple example that sends a card to a room
33
36
api = WebexTeamsAPI()
34
37
api.messages.create(text = " fallback" , roomId = " ..." , attachments = [card])
35
38
36
- The message we send with this code then looks like this in our Webex Teams
39
+ The message we send with this code then looks like this in our Webex space
37
40
client:
38
41
39
42
.. image :: ../images/cards_sample.png
43
+
44
+
45
+ Processing a card action
46
+ =======================
47
+
48
+ Adaptive card interactions are treated as "attachment actions". Once user interacts
49
+ with your card and submits an action, your app will receive a webhook from Webex. You
50
+ must `setup a webhook <api.rst#webhooks >`_ in advance with ``resource = "attachmentActions" ``
51
+ and ``event = "created" ``.
52
+
53
+ Webhook payload will contain a JSON:
54
+
55
+ .. code-block :: json
56
+
57
+ {
58
+ "resource" : " attachmentActions" ,
59
+ "event" : " created" ,
60
+ "data" : {
61
+ "id" : " XYXYXY" ,
62
+ "type" : " submit"
63
+ }
64
+ }
65
+
66
+ Extract attachment action ID from ``['data']['id'] `` and
67
+ use `attachment_actions.get() <api.rst#attachment_actions >`_ to get full information
68
+ about user action and any submitted data.
69
+
70
+ .. code-block :: python
71
+
72
+ action = api.attachment_actions.get(webhookJson[' data' ][' id' ])
73
+
74
+ first_name = action.inputs[' first_name' ]
75
+ age = action.inputs[' age' ]
0 commit comments