I found a bug in Shortcut Modal Push (https://api.slack.com/surfaces/modals/using#pushing_api).
I created a modal by this guide (https://github.com/slackapi/python-slackclient/blob/a86536766274b02f8e6a7532f9b5494f1a8ae354/docs-src/basic_usage.rst#opening-a-modal) and filled it with proper elements (input, submit and etc.) and everything works fine in slack. But when I send client.views_push() I get an error from slack's server invalid 'trigger_id'
Also I tried to reproduce this issue without python-slackclient using requests library and got same result. According to logs I respond to server less then 3 second.
client = WebClient(token=slack_token)
view = {
"type": "modal",
"title": {"type": "plain_text", "text": "Show me result"},
"blocks": []
}
try:
api_response = client.views_push(
trigger_id=payload["trigger_id"],
view=view,
)
logger.info(api_response)
except Exception as e:
logger.error(repr(e))
raise
slackclient==2.8.2
Python 3.8.2
Linux semu 5.4.0-47-generic #51-Ubuntu SMP Fri Sep 4 19:50:52 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Expected result ['ok'] == True and slack API except trigger_id.
slack.errors.SlackApiError: The request to the Slack API failed.
The server responded with: {'ok': False, 'error': 'invalid_arguments', 'response_metadata': {'messages': ['[ERROR] invalid 'trigger_id' [json-pointer:/trigger_id]']}}
For general questions/issues about Slack API platform or its server-side, could you submit questions at https://my.slack.com/help/requests/new instead. :bow:
Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.
Hi @kompotkot thanks for writing in!
In response to a view_submission type request, please use response_action: push in its HTTP response instead of calling views.push API methods. Refer to this document for details: https://api.slack.com/surfaces/modals/using#pushing_views
If you're using Flask as with the doc you mentioned, constructing a JSON response body containing response_action: push and view, plus building an HTTP response using Flask's make_response utility method should work for you.
@seratch : Have been experiencing the same trigger_id issue as @kompotkot . Does this mean that views.push is just not working and we shouldn't rely on it?
@nkashy1 You can use views.push API method when your app gets a block_actions request from Slack. This may happen when a modal has an interactive type (=actions) block (not input type). In this case, calling views.push API method is the way to go.
views.push requires a trigger_id (similar to views.open) and can only be called when a modal is already open. Therefore, the only possible way to acquire a trigger_id to use here is from the use of an interactive component in the modal.
an interactive component in the above sentence means an actions block, not an input block.
For your reference:
As I've already answered the question here, let me close this issue now. Thanks for asking the question!
Most helpful comment
Hi @kompotkot thanks for writing in!
In response to a
view_submissiontype request, please useresponse_action: pushin its HTTP response instead of callingviews.pushAPI methods. Refer to this document for details: https://api.slack.com/surfaces/modals/using#pushing_viewsIf you're using Flask as with the doc you mentioned, constructing a JSON response body containing
response_action: pushandview, plus building an HTTP response using Flask'smake_responseutility method should work for you.