Skip to content

Send messages to Slack

You can send messages to Slack from vals.

In this guide you’ll create an incoming webhook for your Slack workspace, and send a request to it with a message payload.

Screenshot 2023-06-27 at 07.09.52.png

Create a Slack app

Visit https://api.slack.com/apps?new_app=1, create a new app From Scratch, and choose your App Name and your workspace.

Screenshot 2023-06-27 at 07.05.40.png

Go to the incoming webhooks page

On the next page (or in the side bar), click Incoming Webhooks.

Screenshot 2023-06-26 at 21.30.46.png

Create an incoming webhook

Click the Activate Incoming Webhooks toggle.

Screenshot 2023-06-26 at 21.31.07.png

Scroll down, and click Add New Webhook to Workspace.

Screenshot 2023-06-26 at 21.31.18.png

Select the channel which the webhook will send messages to.

Screenshot 2023-06-27 at 07.04.24.png

Save the webhook address as a secret

You’ll be taken back to the Incoming Webhooks page (if not, you can find it via the side bar).

Screenshot 2023-06-26 at 21.33.04.png

Copy the Webhook URL for the webhook you just created and save it as a Val Town environment variable as slackWebhookURL.

Use fetch to send a message

Translate the sample cURL request to a fetch request. You can run the following val:

Send messageRun in Val Town ↗
const res = await fetch(Deno.env.get("slackWebhookURL"), {
method: "POST",
body: JSON.stringify({
text: `Hello, ~World~ from Val Town!`,
}),
});
console.log(res.statusText);

If it worked, you will get a message in the channel you configured earlier!

Screenshot 2023-06-27 at 07.09.52.png

Ran into a problem? Get help on the Val Town Discord.