python-slack-sdk icon indicating copy to clipboard operation
python-slack-sdk copied to clipboard

InputBlock returns class Object instead of parsable dict

Open sharvesh06 opened this issue 3 years ago • 2 comments

while using slack_sdk.models.blocks import InputBlock, the inputBlock returns <slack_sdk.InputBlock> instead of InputBlock

Reproducible in:

slack-sdk==3.18.3

The Slack SDK version

slack-sdk==3.18.3

Python runtime version

Python 3.8.10

Steps to reproduce:

print(InputBlock(label=PlainTextObject(text="test"), element=PlainTextInputElement(multiline=True, action_id="plain_text_input_action"))

Expected result:

{'element': {'action_id': 'plain_text_input_action', 'multiline': True, 'type': 'plain_text_input'}, 'label': {'text': 'SSH Key', 'type': 'plain_text'}

Actual result:

<slack_sdk.InputBlock: {'element': {'action_id': 'plain_text_input_action', 'multiline': True, 'type': 'plain_text_input'}, 'label': {'text': 'SSH Key', 'type': 'plain_text'}, 'type': 'input'}>

sharvesh06 avatar Sep 07 '22 19:09 sharvesh06

How do I parse this list?

sharvesh06 avatar Sep 07 '22 19:09 sharvesh06

HI @sharvesh06! Whether this class or another, any time you'd like to take a look at what methods/attributes are available on a given class or instance, you can always reach for the built-in dir function:

thing_to_parse = InputBlock(label=PlainTextObject(text="test"),
element=PlainTextInputElement(multiline=True, action_id="plain_text_input_action"))

dir(thing_to_parse)

From here, we can see that there is a to_dict method. If you invoke it:

thing_to_parse.to_dict()

you will get the output you seem to be looking for.

Let us know if that resolves the issue you're facing!

misscoded avatar Sep 08 '22 00:09 misscoded

I think that this question is already answered. Let us close this issue but please feel free to write in if you have follow-up questions.

seratch avatar Sep 29 '22 06:09 seratch