Skip to content

Add Webex Teams Cards&Buttons as native python objects #93

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 13 commits into from
Apr 11, 2020

Conversation

sQu4rks
Copy link
Contributor

@sQu4rks sQu4rks commented Oct 26, 2019

This PR introduces Adaptive Cards as native python objects.

Example

from webexteamssdk.cards.card import AdaptiveCard
from webexteamssdk.cards.components import TextBlock
from webexteamssdk.cards.options import Colors, HorizontalAlignment
from webexteamssdk.cards.inputs import Text, Number
from webexteamssdk.cards.actions import Submit

title = TextBlock("Please give me your data!", color=Colors.GOOD)

first_name = Text('first_name', placeholder='Your first name')
age = Number('age', placeholder='Your age')

send_button = Submit(title='Send data')

card = AdaptiveCard(lang="en", body=[title, first_name, age], actions=[send_button])
print(str(card.to_json(pretty=True)))

will print the json required for this card

Screenshot 2019-10-26 at 17 14 44

You can now send a card like this:

```
from webexteamssdk import WebexTeamsAPI
from webexteamssdk.cards.card import AdaptiveCard
from webexteamssdk.cards.components import TextBlock
from webexteamssdk.cards.options import Colors

block = TextBlock("Hey hello there! I am a adaptive card",
color=Colors.GOOD)
card = AdaptiveCard(body=[block])
api = WebexTeamsAPI()
api.messages.create(text="fallback", roomId="...", cards=card)
```
@sQu4rks sQu4rks changed the title Introduces Webex Teams Cards&Buttons as native python objects Add Webex Teams Cards&Buttons as native python objects Oct 26, 2019
@cmlccie cmlccie merged commit 327b452 into WebexCommunity:master Apr 11, 2020
@cmlccie
Copy link
Collaborator

cmlccie commented Apr 11, 2020

@sQu4rks Thank you for the PR! I apologize for the delay in getting this merged. I am going to move the package to the webexteamssdk.models package and do some refactoring.

@sQu4rks
Copy link
Contributor Author

sQu4rks commented Apr 12, 2020

No worries @cmlccie. I have since split this into its own package (see CiscoSE/pyadaptivecards). What do you think about adding that package as a dependency and import them in the init.py so that there is only one „adaptive Cards in python“ code base instead of two.

@cmlccie
Copy link
Collaborator

cmlccie commented Apr 13, 2020

Makes sense to me! I'll modify the webexteamssdk code to add this as an optional dependency. If you can incorporate the make_card_attachment(card) function into your package, I will modify the SDK to automatically serialize the cards when passed to WebexTeamsAPI.messages.create(attachements=).

@cmlccie
Copy link
Collaborator

cmlccie commented Apr 13, 2020

@sQu4rks in case you are interested... Here are the refactoring edits I made to the code.

I agree it is better to have this functionality in a separate package that you can maintain without waiting on me. 🙂 Let me know when you have incorporated the make_card_attachment(card) function (or modeled attachments as python data model) and I will update the SDK to add your library as an optional dependency and integrate the automatic serialization into messages.create().

Also, have you seen/used the pydantic library? I am increasing using this and FastAPI for projects. It could very easily be used to model the Adaptive Cards. I am considering using it to model the Webex Teams data models in a future release that will support Python v3 (only). I am also thinking of migrating the library to support both synchronous and asynchronous execution in a v3 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants