Forward Incoming SMS to Telegram, Slack or Email
When a text arrives on your SMSNET line, you can forward it to Telegram, Slack, email, or any HTTP endpoint. This guide shows two approaches: an n8n workflow (no code) and a 20-line Cloudflare Worker (code you control). Both verify the SMSNET webhook signature.
What do I need?
- A connected phone in SMSNET with an API key
- A public HTTPS endpoint for the webhook (n8n Cloud, your own n8n, or a Cloudflare Worker)
- The webhook secret from
PUT /api/v1/webhooks
The free plan covers 300 messages/month, 20/day, and replies are never counted.
Option A: n8n workflow (no code)
1. Create the webhook in n8n
- Add a Webhook node, set HTTP Method to
POST, path e.g.sms/incoming - Set Response Mode to
On Received(returns 200 immediately) - Copy the production webhook URL (looks like
https://your-n8n/webhook/sms/incoming)
2. Register the webhook with SMSNET
curl -X PUT https://smsnet.net/api/v1/webhooks \
-H "X-API-Key: YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "https://your-n8n/webhook/sms/incoming"}'
Save the secret from the response: you'll need it in the next step.
3. Verify the signature in n8n
Add a Function node right after the Webhook node:
// n8n Code node: verify SMSNET webhook signature
// Webhook node: turn on Options > Raw Body, so the exact bytes SMSNET signed are kept.
// Self-hosted n8n: allow the module with NODE_FUNCTION_ALLOW_BUILTIN=crypto.
const crypto = require('crypto');
const item = $input.first();
const headers = item.json.headers;
const secret = $env.SMSNET_WEBHOOK_SECRET; // or paste it from a credential you control
const ts = headers['x-smsnet-timestamp'];
const sig = headers['x-smsnet-signature'] || '';
const delivery = headers['x-smsnet-delivery'];
const raw = Buffer.from(item.binary.data.data, 'base64').toString('utf8');
if (!ts || !sig) {
throw new Error('Missing timestamp or signature header');
}
if (Math.abs(Date.now() / 1000 - Number(ts)) > 300) {
throw new Error('Timestamp out of 5-minute window');
}
const expected = 'v1=' + crypto
.createHmac('sha256', secret)
.update(ts + '.' + raw)
.digest('hex');
// timingSafeEqual throws on different lengths, so compare lengths first.
const a = Buffer.from(expected), b = Buffer.from(sig);
if (a.length !== b.length || !crypto.timingSafeEqual(a, b)) {
throw new Error('Invalid signature');
}
const event = JSON.parse(raw);
// Dedupe: store delivery ID in a simple key-value (Redis, Postgres, or n8n's static data)
// Workflow static data persists between production runs (not manual test runs).
// It is saved as JSON, so keep a plain array, and only the most recent ids.
const store = $getWorkflowStaticData('global');
store.seen = store.seen || [];
if (store.seen.includes(delivery)) {
return [];
}
store.seen = [...store.seen.slice(-499), delivery];
return [{ json: event }]; // the verified event, for the next node
Put the secret in the SMSNET_WEBHOOK_SECRET environment variable of your n8n instance (on self-hosted n8n, also allow $env in Code nodes), never in the workflow itself.
4. Route to Telegram / Slack / Email
After the Code node, add:
- Telegram node: chat ID from your bot, text:
{{ $json.data.from }}: {{ $json.data.body }} - Slack node: webhook URL, text:
SMS from {{ $json.data.from }}: {{ $json.data.body }} - Send Email node: to, subject
New SMS from {{ $json.data.from }}, body{{ $json.data.body }}
Connect the Code node output to whichever destination nodes you need.
5. Test it
curl -X POST https://smsnet.net/api/v1/webhooks/test \
-H "X-API-Key: YOUR_KEY" \
-H "Content-Type: application/json"
You should see a message.received event in n8n and a message in Telegram/Slack/email.
Option B: Cloudflare Worker (20 lines, your infrastructure)
Deploy this as a Worker at https://your-worker.your-subdomain.workers.dev:
// wrangler.toml: name = "smsnet-forward", compatibility_date = "2026-10-25"
export default {
async fetch(request, env) {
if (request.method !== 'POST') return new Response('Method not allowed', { status: 405 });
const secret = env.SMSNET_WEBHOOK_SECRET; // set in wrangler secret put
const ts = request.headers.get('X-SMSNET-Timestamp');
const sig = request.headers.get('X-SMSNET-Signature');
const delivery = request.headers.get('X-SMSNET-Delivery');
const raw = await request.text();
if (!ts || !sig) return new Response('Missing headers', { status: 400 });
if (Math.abs(Date.now() / 1000 - parseInt(ts)) > 300) return new Response('Timestamp expired', { status: 400 });
const enc = new TextEncoder();
const key = await crypto.subtle.importKey('raw', enc.encode(secret), { name: 'HMAC', hash: 'SHA-256' }, false, ['sign']);
const mac = new Uint8Array(await crypto.subtle.sign('HMAC', key, enc.encode(ts + '.' + raw)));
const expected = enc.encode('v1=' + [...mac].map((b) => b.toString(16).padStart(2, '0')).join(''));
const given = enc.encode(sig);
// Workers expose a constant-time compare on crypto.subtle; it needs equal lengths.
if (expected.byteLength !== given.byteLength || !crypto.subtle.timingSafeEqual(expected, given)) {
return new Response('Invalid signature', { status: 401 });
}
// Dedupe: use KV or Durable Object in production; here we just log
const event = JSON.parse(raw);
if (event.event === 'message.received') {
const text = `SMS from ${event.data.from}: ${event.data.body}`;
// Telegram
await fetch(`https://api.telegram.org/bot${env.TG_BOT_TOKEN}/sendMessage`, {
method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ chat_id: env.TG_CHAT_ID, text })
});
// Slack (incoming webhook)
await fetch(env.SLACK_WEBHOOK_URL, {
method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text })
});
// Email (via your provider, e.g. SendGrid, Mailgun, or Cloudflare Email Workers)
}
return new Response('OK');
}
}
Set secrets:
wrangler secret put SMSNET_WEBHOOK_SECRET
wrangler secret put TG_BOT_TOKEN
wrangler secret put TG_CHAT_ID
wrangler secret put SLACK_WEBHOOK_URL
Register the Worker URL with SMSNET:
curl -X PUT https://smsnet.net/api/v1/webhooks \
-H "X-API-Key: YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "https://your-worker.your-subdomain.workers.dev"}'
Signature verification (both approaches)
SMSNET signs each webhook with HMAC-SHA256 over timestamp + "." + rawBody. The signature header is X-SMSNET-Signature: v1=<hex>. Always:
- Reject timestamps older than 5 minutes (
abs(now - ts) > 300) - Compute
expected = 'v1=' + HMAC_SHA256(secret, ts + '.' + rawBody) - Compare with
crypto.timingSafeEqual(orhash_equalsin PHP) - Dedupe on
X-SMSNET-Delivery(stable across retries)
The secret is returned once when you register the webhook. Store it securely; it cannot be retrieved again.
FAQ
How do I forward incoming SMS to Telegram?
Register an n8n webhook or Cloudflare Worker with SMSNET, verify the HMAC signature, then use the Telegram Bot API to send the message to your chat.
Can I forward to multiple destinations at once?
Yes. In n8n, connect the verified Code node to multiple destination nodes (Telegram, Slack, Email). In the Worker, await multiple fetch calls in parallel.
What if the webhook is called multiple times for the same message?
SMSNET retries up to 6 times over about 9 hours. The X-SMSNET-Delivery header is stable across retries, so use it to deduplicate (store in Redis, KV, database, or n8n static data).
Does the webhook include the sender's number?
Yes. The message.received event payload has data.from (E.164), data.body, data.conversation_id, and data.message_id.
Can I reply from Telegram back to the sender?
That requires a separate flow: your Telegram bot receives a reply, then calls POST /api/v1/messages/send with to = original sender, body = reply text. See Receive SMS Webhooks for the send path.
Is there a hosted n8n template I can import?
Not yet. The Code node code above is the core; you can build the rest in 5 minutes.
Related guides
This is a spoke of SMS Automation. Prerequisite: How to Receive SMS and Handle Replies with Webhooks. The phone comes from Turn Your Android Phone into an SMS Gateway. For the send path, see Send SMS from Node.js.
Send your first message today
Free plan, no card: 400 messages a month from your own number, with the API, webhooks and MCP included.
Get the app See pricing