Reputation: 313
Background: I am using the python slack API (slackclient) to build an iterative sequence of data-gathering actions in ephemeral messages.
The core of this works fine. After processing the incoming request that contains the user's interaction with a set of message buttons (or menus), I respond immediately with a JSON body, as described in the "Responding right away" section of the official slack docs.
The problem: Every response replaces the preceding message+attachments. In many cases, this is what I want, but there are situations where I want to add a response rather than replace the previous message.
Per the slack docs,setting replace_original
to false should do just that. But the following code, snipped from my handling of a simple button click (for example), replaces the original button (and the text message to which it was attached):
r = {
'response_type': 'ephemeral',
'text': 'foo',
'replace_original': 'false'
}
log.debug("Returning: {}".format(json.dumps(r)))
resp = Response(response=json.dumps(r),
mimetype="application/json",
status=200)
return resp
I have tried this with and without the delete_original
and response_type
fields, with no change.
In short, it appears that in this case the replace_original
field isn't doing anything at all; behavior is always as if it were set to 'true'.
I feel like I must be missing something here - any help is greatly appreciated.
Upvotes: 5
Views: 3981
Reputation: 313
Simple solution here: the slack API is expecting a boolean, not a string. So 'replace_original': 'false'
in the above snippet ends up as {"response_type": "ephemeral", "text": "foo", "replace_original": "false"}
after the json.dumps()
call, which is invalid.
Instead, setting 'replace_original': False
becomes {"response_type": "ephemeral", "text": "foo", "replace_original": false}
, which then has the expected behavior
Upvotes: 9