Skip to content

Cards example doesn't work #106

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

Closed
acilate opened this issue Apr 14, 2020 · 8 comments · Fixed by #122
Closed

Cards example doesn't work #106

acilate opened this issue Apr 14, 2020 · 8 comments · Fixed by #122

Comments

@acilate
Copy link

acilate commented Apr 14, 2020

The cards example doesn't work as written. The imports are invalid.

They did work as this:
from webexteamssdk.models.cards.card import AdaptiveCard
from webexteamssdk.models.cards.inputs import Text, Toggle
from webexteamssdk.models.cards.components import TextBlock
from webexteamssdk.models.cards.actions import Submit

Edited to add: I should mention this is a reference to the readthedocs example of cards. The card object import statements do not work as stated in those docs.

$ pip list
Package           Version
----------------- ----------
certifi           2020.4.5.1
chardet           3.0.4
click             7.1.1
future            0.18.2
idna              2.9
itsdangerous      1.1.0
Jinja2            2.11.1
MarkupSafe        1.1.1
mcrcon            0.6.0
pip               20.0.2
PyJWT             1.7.1
PyYAML            5.3.1
requests          2.23.0
requests-toolbelt 0.9.1
setuptools        46.1.3
urllib3           1.25.8
webexteamssdk     1.3
Werkzeug          1.0.1
wheel             0.34.2

$ python -V
Python 3.7.3

$ python
Python 3.7.3 (default, Mar 27 2019, 22:11:17)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from webexteamssdk import WebexTeamsAPI
>>> from webexteamssdk.cards.card import AdaptiveCard
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'webexteamssdk.cards'
>>>
@SolankiVBHV
Copy link

SolankiVBHV commented Apr 22, 2020

@acilate , I tried to import the cards the way you mentioned but I get this error:

File "{Project Path}\lib\site-packages\webexteamssdk\api\messages.py", line 217, in create
    json_data = self._session.post(API_ENDPOINT, json=post_data)
  File "{Project Path}\lib\site-packages\webexteamssdk\restsession.py", line 401, in post
    **kwargs)
  File "{Project Path}\lib\site-packages\webexteamssdk\restsession.py", line 254, in request
    response = self._req_session.request(method, abs_url, **kwargs)
  File "{Project Path}\lib\site-packages\requests\sessions.py", line 516, in request
    prep = self.prepare_request(req)
  File "{Project Path}\lib\site-packages\requests\sessions.py", line 459, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "{Project Path}\lib\site-packages\requests\models.py", line 317, in prepare
    self.prepare_body(data, files, json)
  File "{Project Path}\lib\site-packages\requests\models.py", line 467, in prepare_body
    body = complexjson.dumps(json)
  File "C:\Users\vasolank\AppData\Local\Programs\Python\Python36\lib\json\__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "C:\Users\vasolank\AppData\Local\Programs\Python\Python36\lib\json\encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "C:\Users\vasolank\AppData\Local\Programs\Python\Python36\lib\json\encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "C:\Users\vasolank\AppData\Local\Programs\Python\Python36\lib\json\encoder.py", line 180, in default
    o.__class__.__name__)
TypeError: Object of type 'AdaptiveCard' is not JSON serializable

How did you work around that?

@acilate
Copy link
Author

acilate commented Apr 22, 2020

So, I think this is another bug, but I didn't want to take the time to report it :)

You cannot serialize that object for some reason and I couldn't figure it out. For several issues like this one, I ended up just building a native python data object:

    attachment = [
      {
        "contentType": "application/vnd.microsoft.card.adaptive",
        "content": {
          "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
          "type": "AdaptiveCard",
          "version": "1.0",
          "body": card_contents,
          "actions": submit,
        }
      }
    ]

@SolankiVBHV
Copy link

alright, you might know about this already but checkout pyadaptivecards here.

@swarmt
Copy link

swarmt commented May 14, 2020

I have found this works

text_block = TextBlock(text)
card = AdaptiveCard(body=[text_block])
attachment = {
            "contentType": "application/vnd.microsoft.card.adaptive",
            "content": card.to_dict(),
        }
api.messages.create(roomId=ROOM_ID, text=text, attachments=[attachment])```

@edkuse
Copy link

edkuse commented Jun 23, 2020

Example doesn't work if you have a Submit action and provide "data" dictionary. Get error that 'dict' object has no attribute 'to_dict'. They claimed to have fixed this issue with pyadaptivecards, but it's not fixed.

@cmlccie cmlccie modified the milestone: v1.x Jul 7, 2020
@cmlccie
Copy link
Collaborator

cmlccie commented Jul 8, 2020

Let's either:

  1. Refactor the functionality of the adaptive card support in the webexteamssdk library to use pydantic.
  2. Remove the functionality and refer people to the pyadaptive cards package.

...or you could refactor pyadaptivecards, and we can refer people to the library. 😎

@sQu4rks, what do you think?

@sQu4rks
Copy link
Contributor

sQu4rks commented Jul 9, 2020

@cmlccie this is the same as issue #107 which I have fixed in a recent update.

You can try the code by installing my development branch (pip3 install git+https://github.com/sQu4rks/webexteamssdk@issue-107) or wait until the PR gets merged and a new release gets pushed. I have opened PR-112 for this.

@cmlccie
Copy link
Collaborator

cmlccie commented Jul 9, 2020

Released in v1.5 #124.

@cmlccie cmlccie closed this as completed Jul 9, 2020
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 a pull request may close this issue.

6 participants