Edit on val.town ↗

Receive Slack webhooks & send messages

This guide walks you through sending a Slack message from Val Town in response to an incoming Slack webhook.

  1. Click here to create a new Slack app
  2. Click From Scratch
  3. Type an App Name
  4. Select your Slack workspace

Create Slack app

  1. Click Incoming Webhooks in the left sidebar of your app (under Features)
  2. Toggle Activate Incoming Webhooks to On

Enable incoming webhooks

  1. Click Add New Webhook at the bottom of the page
  2. Select your target channel
  3. Copy the Webhook URL from Slack
  4. (Bonus) Customize the App icon under Basic Information in the left sidebar (Val Town icons)

  1. Click Environment Variables in your val's left sidebar
  2. Add a new env variable with key: SLACK_WEBHOOK_URL
  3. Paste the webhook URL you copied from Slack as the value

Copy webhook URL

Now you're ready to send your first message to Slack!

import { IncomingWebhook } from "npm:@slack/webhook";

const slack = new IncomingWebhook(Deno.env.get("SLACK_WEBHOOK_URL"));
const EDIT = `<${import.meta.url.replace("esm", "val")}|(edit val)>`;
await slack.send(`🥳 Hi from Val Town! ${EDIT}`);

Message sent

We recommend including this link to the edit val, so everyone on your team is one click away from making changes.

Learn how to make your message fancy with advanced formatting.

Take this a step further by responding to mentions, slash commands, buttons, and other user interactions with our full Slack bot guide!

You can find more Slack examples on our Templates page.

Last updated