Reputation: 868
I've built a Workspace App for Slack, which now comes with a channel (under the Apps header), where a user can send messages to the app itself. This triggers a message.app_home event, that my backend receives. I want to respond to that message, using chat.postMessage, but only the message text appears in the response. None of the attachments I send along appear in the channel. Returning this structure as part of a JSON response to a Slash Command request works correctly.
Here are the attachments structure I sending along:
(
{
"title": "Create a space, optionally setting its name and adding other users",
"text": "`/luffa create [space name] [teammates]`\nExample: `/luffa create Marketing Campaign 2018 @john @kate`",
"color": SLACK_COLOR,
},
{
"title": "Start a new meeting, optionally strating it in the space matching the provided name",
"text": "`/luffa start [space name]`\nExample: `/luffa start Marketing Campaign 2018`",
"color": SLACK_COLOR,
},
{
"title": "Search Luffa",
"text": "`/luffa search [query]`\nExample: `/luffa search interviews before:Yesterday `",
"color": SLACK_COLOR,
},
{
"text": "There is more help available in our Help Center: https://help.okluffa.com/",
},
)
I am using the slackclient Python library to wrap my calls to the Slack API.
There is no error message returned and the structure seems to be correct based on the documentation. Is there something missing there?
Upvotes: 1
Views: 1320
Reputation: 868
The issue turned out that the data structure I was passing to slackclient 1.2.1 was a tuple
of objects. The library will only serialize as JSON list
or dict
objects. (See slackrequest.py
, line 94, if isinstance(v, (list, dict)):
). Passing a tuple, or any other iterable for that matter, will not be serialized correctly and the Slack API will disregard the attachments. That was not an issue with a JSON response to a request, since Python's JSON serializer converts all iterables to a JSON array.
I solved the issue by passing in a list
to the slackclient method.
Upvotes: 1
Reputation: 16806
Something small to check - try removing the extra commas on each last value in your attachments
structure, as those are causing validation errors when plugged into the Slack message tester here:
Upvotes: 1