· 4 min · TextMeFlow Team

Forward WhatsApp Messages to Discord with Webhooks

Not every team lives in Slack or Teams — many smaller companies, communities and dev teams run their internal communication through Discord. When customers reply on WhatsApp to a confirmation, invoice or question, you don't want to see that message only when someone happens to log in to the admin environment. With a small piece of glue code, you let TextMeFlow post every incoming WhatsApp message straight into a Discord channel.

This article builds the complete flow: from Discord webhook URL to a verified endpoint that forwards messages, without duplicate notifications on retries.

What you need

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

Step 1: create the Discord webhook

In Discord, go to Server Settings → Integrations → Webhooks → New Webhook, pick the channel (for example #whatsapp-inbox) and copy the webhook URL. It looks something like this: https://discord.com/api/webhooks/123456789/xxxxx. Store that URL as an environment variable, never hardcoded in your repo — anyone with that URL can post messages in your channel.

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 guesses your endpoint URL can send in fake messages. The full explanation of these headers is in the article on verifying webhook signatures.

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 DISCORD_URL = process.env.DISCORD_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, then process
  forwardToDiscord(JSON.parse(raw));
});

app.listen(3000);

We return 200 first and only then post to Discord. TextMeFlow expects a response within 10 seconds; if you wait synchronously on a slow downstream call, you risk an unwarranted retry.

Step 3: forward the message to Discord

The TextMeFlow payload contains type, from, from_name, to, file and message — the same fields as TextMeBot, so an existing integration migrates almost 1-to-1. Discord webhooks accept a simple JSON body with a content field:

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

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

For image, document or location messages, the file name or "<lat>,<lng>" is in message. For now, simply mention the type alongside it, so your team knows an attachment arrived.

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 Discord channel gets a duplicate message on every retry. In production, don't use an in-memory Set — it 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 further

This basic flow is quick to extend: route messages to different Discord channels based on the to number (handy with multiple linked devices from the Business plan), or use Discord's embeds field for a slightly tidier card with sender, time and message type separately. The full field reference and header list are in the webhook documentation.

Want to try it yourself? The free plan gives you 50 messages a 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