· 4 min · TextMeFlow Team

Forward Incoming WhatsApp Messages to Slack with Webhooks

We don't want to leave customers who reply on WhatsApp to a booking confirmation or invoice waiting until someone happens to look in the admin environment. Most teams spend the whole day in Slack, so that's where the message needs to land. TextMeFlow sends every incoming WhatsApp message as a webhook to your server; with a small piece of glue code it ends up directly in a Slack channel, including the sender's name and phone number.

This article builds the complete flow: from a Slack incoming webhook to a verified, idempotent endpoint that forwards messages.

What you need

  • A TextMeFlow account with a linked WhatsApp number and a configured webhook_url in /admin/webhook
  • A Slack workspace where you're allowed to create an incoming webhook
  • A small server (Node/Express in this example, but the same works in PHP or Python)

Step 1: create a Slack incoming webhook

In Slack, create a new app (or reuse an existing one), enable Incoming Webhooks and link a channel, for example #whatsapp-inbox. Slack gives you a URL like https://hooks.slack.com/services/T000/B000/XXXX. Store it as an environment variable, never hardcoded in your repo.

Step 2: build an endpoint that verifies the TextMeFlow webhook

For every incoming message, TextMeFlow posts a JSON body to your webhook_url, signed with HMAC-SHA256 in the X-TextMeFlow-Signature header (format: sha256=<hex>). Always verify that signature before you trust the message, otherwise anyone who knows your endpoint URL can submit fake messages. See also the article on verifying webhook signatures for the full explanation of these headers.

const express = require('express');
const crypto = require('crypto');

const app = express();
app.use(express.raw({ type: 'application/json' }));

const SECRET = process.env.TMF_WEBHOOK_SECRET;
const SLACK_URL = process.env.SLACK_WEBHOOK_URL;
const seen = new Set(); // replace with a DB table in production

app.post('/textmeflow-inbound', async (req, res) => {
  const raw = req.body;
  const expected = 'sha256=' + crypto.createHmac('sha256', SECRET).update(raw).digest('hex');
  const received = req.headers['x-textmeflow-signature'] || '';

  if (!crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(received))) {
    return res.sendStatus(401);
  }

  const eventId = req.headers['x-textmeflow-event-id'];
  if (seen.has(eventId)) return res.sendStatus(200); // retry, already processed
  seen.add(eventId);

  res.sendStatus(200); // acknowledge first, process afterwards
  forwardToSlack(JSON.parse(raw));
});

app.listen(3000);

Note that we send back 200 first and only post to Slack afterwards. TextMeFlow expects a response within 10 seconds; if you wait synchronously on a slow downstream call (such as Slack), you risk an unwarranted retry.

Step 3: forward the message to Slack

The TextMeFlow payload contains type, from, from_name, to, file and message, exactly the same fields as TextMeBot, so an existing integration migrates 1-to-1. Build a readable Slack message from it:

async function forwardToSlack(payload) {
  const { type, from, from_name, message } = payload;
  const label = type === 'text' ? '' : ` (${type})`;

  await fetch(SLACK_URL, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      text: `📩 *${from_name || from}* (+${from})${label}: ${message}`,
    }),
  });
}

For image, document or location messages, the file name or "<lat>,<lng>" is in message. Media rehosting with a real URL comes in a later release, so for now simply mention the type so your colleagues know an attachment came in.

Don't forget retries and idempotency

A failed delivery (timeout, 5xx, 429) is retried up to 5 times with increasing backoff (1m, 5m, 30m, 2h, 6h). Without the seen check above, your Slack channel gets a duplicate message on every retry. In production, don't use an in-memory Set, which disappears on restart, but a unique constraint on X-TextMeFlow-Event-Id in your database, so a duplicate insert simply fails and is ignored.

Extending it further

This basic flow can be extended in a few minutes: route messages to different Slack channels based on the to number (handy with multiple linked devices from the Business plan), or add a "Reply" button that sends a reply back to the customer via the /v1/messages endpoint, without anyone having to open WhatsApp itself. The full field reference and header list are in the webhook documentation.

Want to try this yourself? The free plan gives you 50 messages per month, forever, enough to set up and validate this entire flow before you move to a paid plan. Start free.

Want to send WhatsApp messages via API yourself?

Free forever up to 50 messages/month. Scan a QR and send your first message within 5 minutes.

Free forever