WebexCommunity / WebexPythonSDK

Work with the Webex APIs in native Python!
https://webexcommunity.github.io/WebexPythonSDK/
MIT License
239 stars 153 forks source link

Problem using Choices #195

Closed ManiAm closed 1 year ago

ManiAm commented 1 year ago

I get error while adding choices into my card:

from webexteamssdk.models.cards import Choices

        choices = [
            {
                "title": "Choice 1",
                "value": "Choice 1"
            },
            {
                "title": "Choice 2",
                "value": "Choice 2"
            }
        ]

        ts_choices = Choices(id="test_suites",
                             isMultiSelect=True,
                             choices=choices)

Here is the error:

Am I using the Choices correctly?

  File "/ws/mamoozad-sjc/CATS/cats/webex/commands/ut_xr.py", line 73, in execute
    return response_from_adaptive_card(card)
  File "/ws/mamoozad-sjc/CATS/cats/webex/models/response.py", line 19, in response_from_adaptive_card
    "content": adaptive_card.to_dict()
  File "/auto/panini-projs/fabric/spitfire/cats_venv/3.9.10/env/lib/python3.9/site-packages/webexteamssdk/models/cards/card.py", line 85, in to_dict
    serialized_data = super().to_dict()
  File "/auto/panini-projs/fabric/spitfire/cats_venv/3.9.10/env/lib/python3.9/site-packages/webexteamssdk/models/cards/adaptive_card_component.py", line 78, in to_dict
    serialized_data[property_name] = [
  File "/auto/panini-projs/fabric/spitfire/cats_venv/3.9.10/env/lib/python3.9/site-packages/webexteamssdk/models/cards/adaptive_card_component.py", line 79, in <listcomp>
    item.to_dict() for item in property_value
  File "/auto/panini-projs/fabric/spitfire/cats_venv/3.9.10/env/lib/python3.9/site-packages/webexteamssdk/models/cards/adaptive_card_component.py", line 78, in to_dict
    serialized_data[property_name] = [
  File "/auto/panini-projs/fabric/spitfire/cats_venv/3.9.10/env/lib/python3.9/site-packages/webexteamssdk/models/cards/adaptive_card_component.py", line 79, in <listcomp>
    item.to_dict() for item in property_value
  File "/auto/panini-projs/fabric/spitfire/cats_venv/3.9.10/env/lib/python3.9/site-packages/webexteamssdk/models/cards/adaptive_card_component.py", line 78, in to_dict
    serialized_data[property_name] = [
  File "/auto/panini-projs/fabric/spitfire/cats_venv/3.9.10/env/lib/python3.9/site-packages/webexteamssdk/models/cards/adaptive_card_component.py", line 79, in <listcomp>
    item.to_dict() for item in property_value
  File "/auto/panini-projs/fabric/spitfire/cats_venv/3.9.10/env/lib/python3.9/site-packages/webexteamssdk/models/cards/adaptive_card_component.py", line 78, in to_dict
    serialized_data[property_name] = [
  File "/auto/panini-projs/fabric/spitfire/cats_venv/3.9.10/env/lib/python3.9/site-packages/webexteamssdk/models/cards/adaptive_card_component.py", line 79, in <listcomp>
    item.to_dict() for item in property_value
AttributeError: 'dict' object has no attribute 'to_dict'
dstaudt commented 1 year ago

From looking at the code, it looks like the items in Choices['choices'] should be choice class objects, rather than raw dictionaries. They would then inherit toDict() from the parent AdaptiveCardComponent.

See: https://github.dev/WebexCommunity/WebexPythonSDK/blob/master/webexteamssdk/models/cards/components.py