Handling view_submission payload from Slack view interaction

I have a Slack app shortcut, that opens a modal in Slack allowing for user input. I create the view using the "Interactivity & Shortcuts", setting the Request URL to a retool workflow trigger.

The user can submit the input, and I'm expecting to receive a view_submission payload to the same retool workflow Request URL, but nothing comes in and the submission times out in Slack.

Is this something that Retool can support?

Hi Vlad,

It might be helpful to include some more screenshots and details. What's the url of the workflow trigger that you're submitting to?

The URL is the workflow trigger URL with the workflow API Key appended.

It’s functional, as I’m receiving the trigger when clicking on the shortcut in Slack. That’s what allows me to respond back with a view and open the modal. It seems Retool isn’t processing any of the view actions such as “view_submission” as separate triggers.

This is kind of tough bc there are the slack parts and the retool parts. I don't know anything about the slack parts so I can't help there. When you say "it's functional," do you mean on the retool side or slack side. Because further up you say "nothing comes in and the submission times out in slack."

Got it, it's definitely a little confusing.

Slack sends different types of payloads depending on the interaction:
shortcut payload (clicking on a shortcut in Slack) - received by my Retool workflow
view interaction payload (clicking submit in a view) - not received by my Retool workflow

Hope this is more clear.

We might still need some more info.

  1. You have a single retool workflow that could be triggered by one of these two slack events right? And the workflow does what? You say there's a view and a modal, that's in slack right?
  2. Maybe you mean slack is sending one call to the workflow trigger but it contains multiple view actions?

After a lot of research, I believe it comes down to the types of webhook data Retool supports. Currently, it's only application/json

Is there any plan to support application/x-www-form-urlencoded?

Could you share your current setup? I tried implementing this on my end using a Slack block with a button to trigger the Workflow:

Slice of the block key for the POST /chat.postMessage request:
Screenshot 2024-11-15 at 10.42.12 AM

This is successfully creating the block:
Screenshot 2024-11-15 at 10.50.13 AM

But there's no way to pass a header to the request (for the API Key). I explored a few options, a workaround I found (not implemented yet) is using a AWS Lambda function:

  1. Set up a Lambda function that receives a the request (from Slack) and forwards it to the Retool workflow URL with the X-Workflow-Api-Key header.
  2. In the Slack block JSON, update the url for the "Approve" button to point to your Lambda endpoint.
  3. Trigger the WF via Webhook using the Lambda function.

Example code for Lambda func:

const https = require('https');

exports.handler = async (event) => {
    const options = {
        hostname: 'api.tryretool.com',
        path: '/v1/workflows/c879c56e-a414-44bb-a0c0-e8e4aea87845/startTrigger',
        method: 'POST',
        headers: {
            'X-Workflow-Api-Key': 'your-api-key-here',
            'Content-Type': 'application/json'
        }
    };

    return new Promise((resolve, reject) => {
        const req = https.request(options, (res) => {
            let data = '';
            res.on('data', (chunk) => data += chunk);
            res.on('end', () => resolve({ statusCode: 200, body: JSON.stringify({ message: 'Request forwarded' }) }));
        });

        req.on('error', (e) => reject({ statusCode: 500, body: JSON.stringify({ error: e.message }) }));
        req.write(JSON.stringify(event.body));  // Forward Slack's payload if needed
        req.end();
    });
};

You can pass the API key as a parameter of the URL (yes, it's not as secure)

For example:

https://api.retool.com/v1/workflows/12345/startTrigger?workflowApiKey=retool_wk_a12345

1 Like

I was trying to avoid this approach but since we are running it from a Workflow, and we can limit access to it, it's not as insecure as I initially thought. I'll try implementing this now.

Success!

{"success":true,"workflow_run":{"id":"6f02c8...-917f-baf96e440cd8","workflow_id":"<REMOVED>","created_at":"2024-11-15T21:33:58.946Z","status":"PENDING"}}

I'm getting the runs on the WF.
Screenshot 2024-11-15 at 1.36.33 PM

As you pointed out, Webhook events sent to the workflow endpoint must use Content-Type: application/json. I'm happy to create an internal feature request to allow additional content types. If you could share more details about your setup, including a few screenshots of where you'd set up the desired content type, I'll include them in the request in order to provide better context for your use case.

Feel free to attach it to a DM if you would like to not share your use case publicly.

1 Like

This was the solution to my use case as well. In my case the user sends a slash command on slack and triggers the Retool workflow, the result of the workflow is returned to the user. Eg: "/GOOGL price" and the bot returns the stock price