bolt-js icon indicating copy to clipboard operation
bolt-js copied to clipboard

Getting exchanged_trigger_id error on clicking a button

Open mrafiqi21 opened this issue 4 years ago • 9 comments

Description

I am using the following code inside an action callback (action is clicking on a button in a modal) and getting an : exchanged_trigger_id error.

client.views.push({
  trigger_id: body.trigger_id,
  view: modals.sampleModal()
 });

This error occurs sometimes but not always. It is occuring randomly. Any help here?

Error: An API error occurred: exchanged_trigger_id
    at platformErrorFromResult (..)
    at WebClient.apiCall (..)
    at processTicksAndRejections (internal/process/task_queues.js:95:5) {
  code: 'slack_webapi_platform_error',
  data: {
    ok: false,
    error: 'exchanged_trigger_id',
    response_metadata: { scopes: [Array] }
  }
}

What type of issue is this? (place an x in one of the [ ])

  • [ ] bug
  • [ ] enhancement (feature request)
  • [x] question
  • [ ] documentation related
  • [x] example code related
  • [ ] testing related
  • [ ] discussion

Requirements (place an x in each of the [ ])

  • [x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • [x] I've read and agree to the Code of Conduct.
  • [x] I've searched for any related issues and avoided creating a duplicate issue.

mrafiqi21 avatar Mar 15 '22 05:03 mrafiqi21

Hi @mrafiqi21, thanks for asking the question!

As mentioned in the API document (https://api.slack.com/methods/views.push#errors), the error code indicates the trigger_id is already used for a different interaction. To receive a new trigger_id for further modal view changes, your app needs to ask the app's end-user to make a new user action such as button click and item selection in a select menu.

I hope this was helpful.

seratch avatar Mar 15 '22 05:03 seratch

@seratch Thanks for the quick reply.

The trigger id is not used. I have an action listener for the button in the modal. Once the user clicks on the button, the action callback method calls

client.views.push({
 trigger_id: body.trigger_id,
 view: modals.sampleModal()
});

body.trigger_id in this case is a fresh trigger id right which was generated on the click of that button? And as I said, this error is occuring sometimes but not always. Anything that I may be missing here?

mrafiqi21 avatar Mar 15 '22 05:03 mrafiqi21

@mrafiqi21 Thanks for the response. Is what you are doing now something like this?

app.shortcut("socket-mode-shortcut", async ({ client, body, ack }) => {
  try {
    const res = await client.views.open({
      "trigger_id": body.trigger_id,
      "view": {
        "type": "modal",
        "callback_id": "test-modal",
        "title": {
          "type": "plain_text",
          "text": "The first modal"
        },
        "blocks": [
          {
            "type": "section",
            "text": {
              "type": "mrkdwn",
              "text": "Click this:"
            },
            "accessory": {
              "type": "button",
              "text": {
                "type": "plain_text",
                "text": "Push a new one"
              },
              "value": "click_me_123",
              "action_id": "button-action"
            }
          }
        ]
      }
    });
    await ack();
  } catch (e) {
    console.log(e);
  }
});

app.action("button-action", async ({ ack, client, body }) => {
  await ack();
  try {
    await client.views.push({
      trigger_id: body.trigger_id,
      view: {
        "type": "modal",
        "callback_id": "test-modal",
        "title": {
          "type": "plain_text",
          "text": `Created from ${body.view.id}`
        },
        "blocks": [
          {
            "type": "section",
            "text": {
              "type": "mrkdwn",
              "text": "Click this:"
            },
            "accessory": {
              "type": "button",
              "text": {
                "type": "plain_text",
                "text": "Push a new one"
              },
              "value": "click_me_123",
              "action_id": "button-action"
            }
          }
        ]
      }
    });  
  } catch (e) {
    console.log(e);
  }
});

I'm not sure why the error can occasionally arise in your use case yet. I tried to reproduce the situation on my end but I've never seen the same yet. The only cause that I confirmed is multiple API calls with the same trigger_id.

seratch avatar Mar 15 '22 06:03 seratch

Yes this is exactly what I'm doing. It is like on clicking the button I get this error and nothing happens, and when I re-click it, it works. And this is happening randomly, not always.

mrafiqi21 avatar Mar 15 '22 06:03 mrafiqi21

@seratch This is how the action callback looks like (have replaced variable names with dummy variables). I don't understand how there could be another call with the same trigger id since it's different for all button clicks.

const dummyCallback = async ({ action, body, client, ack }) => {
  try {
    await ack();
    const variable = action.action_id.split('xxx-')[1]
    const privateMetaData = JSON.parse(body.view.private_metadata);
    const dummy = privateMetaData.dummy1.dummy2.filter((dummy) => {
      return dummy.dummy3==variable;
    })

    if(dummy.length){

    await client.views.push({
      trigger_id: body.trigger_id,
      view: modals.modal()
    });

    }

  } catch (error) {

    console.error(error);
  }
};

mrafiqi21 avatar Mar 15 '22 06:03 mrafiqi21

👋 It looks like this issue has been open for 30 days with no activity. We'll mark this as stale for now, and wait 10 days for an update or for further comment before closing this issue out. If you think this issue needs to be prioritized, please comment to get the thread going again! Maintainers also review issues marked as stale on a regular basis and comment or adjust status if the issue needs to be reprioritized.

github-actions[bot] avatar Apr 18 '22 00:04 github-actions[bot]

As this issue has been inactive for more than one month, we will be closing it. Thank you to all the participants! If you would like to raise a related issue, please create a new issue which includes your specific details and references this issue number.

github-actions[bot] avatar May 02 '22 00:05 github-actions[bot]

For me this issue only happens in local development through socket mode, have no issues in non socket mode.

Kuanming3 avatar Dec 09 '22 11:12 Kuanming3

I'm also having this issue in socket mode. I have not tried non-socket mode yet.

jbwc avatar May 05 '23 04:05 jbwc