· 4 min · TextMeFlow Team

Forward Incoming WhatsApp Messages to Microsoft Teams

Many companies that run on Microsoft 365 spend all day in Teams, not in a separate dashboard. A customer who replies on WhatsApp to an invoice or appointment reminder should therefore land in Teams — not only be noticed when someone happens to log in to the TextMeFlow admin. This article builds that flow: from a Teams channel with a webhook entry point to a verified endpoint that forwards every incoming WhatsApp message to Teams as a card.

Important: use the Workflows app, not the old "Incoming Webhook" connector

Microsoft has phased out the classic Office 365 connectors (the old "Incoming Webhook" in channel settings). The current route runs through the Workflows app in Teams, built on Power Automate. It gives you the same functionality — a unique URL that turns a POST request into a card in a channel — but supported and without a deprecation warning.

Step 1: create a webhook URL in Teams

  1. Open the channel where the messages should land, for example WhatsApp-inbox, and choose Workflows in the channel options.
  2. Find the template "Post to a channel when a webhook request is received" and follow the wizard.
  3. Teams generates a unique URL. Store it as an environment variable (TEAMS_WEBHOOK_URL) — never hardcoded in your repository, because anyone who knows that URL can post messages in your channel.

Step 2: build an endpoint that verifies the TextMeFlow webhook

For every incoming WhatsApp message, TextMeFlow sends a JSON body to the webhook_url you set in /admin/webhook, signed with HMAC-SHA256 in the X-TextMeFlow-Signature header (format sha256=<hex>). Always verify that signature before you trust the message. 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 TEAMS_URL = process.env.TEAMS_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
  forwardToTeams(JSON.parse(raw));
});

app.listen(3000);

Send back 200 first and only then process towards Teams. TextMeFlow expects an answer within 10 seconds; if you wait synchronously on a slow downstream call, you risk an unwarranted retry.

Step 3: post the message as a card in Teams

The TextMeFlow payload contains type, from, from_name, to and message — the same fields as with TextMeBot, so an existing integration migrates 1-to-1. The Workflows app's webhook trigger expects a JSON body; the simplest option is a plain text card:

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

  await fetch(TEAMS_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 — so simply mention the type as well, so colleagues know 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 Teams 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 that a duplicate insert simply fails and gets ignored.

Extending it further

Route messages to different channels based on the to number — handy once you work with multiple linked devices from the Business plan. 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 flow completely 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