Python-slack-sdk: invalid `trigger_id` modal.push

Created on 13 Sep 2020  路  4Comments  路  Source: slackapi/python-slack-sdk

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.

Reproducible in:

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

The Slack SDK version

slackclient==2.8.2

Python runtime version

Python 3.8.2

OS info

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

Steps to reproduce:

  1. if payload["type"] == "shortcut":
    api_response = client.views_open()
  2. elif payload["type"] == "view_submission":
    api_response = client.views_push()

Expected result:

Expected result ['ok'] == True and slack API except trigger_id.

Actual result:

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]']}}

Requirements

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.

question

Most helpful comment

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.

All 4 comments

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tinoargentino picture tinoargentino  路  4Comments

Dwyte picture Dwyte  路  3Comments

vv-grinko picture vv-grinko  路  3Comments

marshallino16 picture marshallino16  路  3Comments

ErikKalkoken picture ErikKalkoken  路  3Comments