Prompt
How do I build a phone number forwarding system with webhooks?
Latest observation
A phone-number forwarding system with webhooks usually means:
- You own a phone number
- Incoming calls/SMS hit your app via webhook
- Your app decides what to do
- You forward the call/SMS to another number or endpoint
- You notify your systems with webhooks about what happened
The exact implementation depends on whether you want:
- call forwarding
- SMS forwarding
- or both
Below is a practical blueprint.
1) Pick a telephony provider
Use a provider that supports:
- buying phone numbers
- inbound call/SMS webhooks
- call forwarding / bridging / call transfer
- status callbacks
Common choices:
- Twilio
- Vonage
- Telnyx
- Plivo
Twilio is often easiest for webhooks.
2) Basic architecture
Call flow
- Caller dials your number
- Telecom provider sends your server a webhook:
POST /inbound-call - Your server looks up rules:
- forward to a specific number
- ring multiple numbers
- route by time of day / caller ID / IVR menu
- Your server responds with call instructions
- Provider connects the call onward
- Provider sends status webhooks:
- ringing
- answered
- busy
- failed
- completed
SMS flow
- Message arrives
- Provider hits your webhook:
POST /inbound-sms - Your server processes or forwards the message
- Your app can:
- send the message to another number
- store it
- email it
- send to Slack/CRM/webhook
- Provider sends delivery/status callbacks if supported
3) Decide your forwarding logic
Typical rules:
- Static forward: all calls to one destination
- Per-number routing: different inbound numbers go to different destinations
- Schedule-based: business hours vs after hours
- Fallback chain: call A, then B, then C
- Simultaneous ring: call multiple phones at once
- Context-based: route based on customer, area code, language, etc.
Store these rules in a database table like:
forwarding_rules
- id
- inbound_number
- destination_type
- destination_value
- active
- business_hours
- fallback_order
- created_at
4) Build the webhook endpoints
You usually need at least:
POST /webhooks/inbound-callPOST /webhooks/inbound-smsPOST /webhooks/call-statusPOST /webhooks/sms-status
Optional:
POST /webhooks/user-config-changedPOST /webhooks/ivr-inputPOST /webhooks/fallback-result
5) Example: call forwarding with Twilio
Inbound webhook
When Twilio receives a call to your number, it requests your webhook.
Your server can respond with TwiML like:
<Response>
<Dial>
<Number>+14155551234</Number>
</Dial>
</Response>
That means: “connect the caller to that destination number.”
Example in Node.js/Express
import express from "express";
import twilio from "twilio";
const app = express();
app.use(express.urlencoded({ extended: false }));
app.post("/webhooks/inbound-call", async (req, res) => {
const from = req.body.From;
const to = req.body.To;
// Look up forwarding rule in DB
const forwardTo = "+14155551234";
const twiml = new twilio.twiml.VoiceResponse();
const dial = twiml.dial({
callerId: to
});
dial.number(forwardTo);
res.type("text/xml").send(twiml.toString());
});
app.listen(3000, () => console.log("Listening on 3000"));
6) Add status webhooks
You’ll want to know if the forward succeeded.
For example, Twilio can send events about the dialed call status.
Store:
- original caller
- original called number
- forwarded number
- status
- duration
- recording URL if enabled
Example statuses:
- initiated
- ringing
- answered
- completed
- no-answer
- busy
- failed
This helps with:
- analytics
- retries
- audit logs
- billing
7) Add SMS forwarding
If someone texts your number, your provider hits your webhook.
Simple SMS forward example
app.post("/webhooks/inbound-sms", async (req, res) => {
const from = req.body.From;
const body = req.body.Body;
// Option 1: forward to another phone number via provider API
// Option 2: forward to email/Slack/internal webhook
console.log(`SMS from ${from}: ${body}`);
const twiml = new twilio.twiml.MessagingResponse();
twiml.message("Thanks, we received your message.");
res.type("text/xml").send(twiml.toString());
});
If you want true SMS-to-SMS forwarding, your app usually sends a new outbound message to the destination number using the provider API.
8) Secure your webhooks
Important protections:
- Verify signatures from the telephony provider
- Use HTTPS
- Reject unsigned/invalid requests
- Add idempotency so duplicate webhooks don’t trigger duplicate forwarding
- Log request IDs for debugging
For Twilio, verify X-Twilio-Signature.
9) Handle edge cases
You should design for:
- No answer
- Busy
- Destination unavailable
- Call loops
- Forwarding to voicemail
- Multiple forwarding rules
- Rate limits
- Provider retries
- Duplicate webhook delivery
- Time zone handling
- Caller ID masking/privacy laws
Avoid loops like:
- inbound number forwards to a number that routes back to the same inbound number
10) If you need advanced routing
You may want:
- IVR (“Press 1 for sales”)
- voicemail transcription
- call recording
- warm transfer / attended transfer
- queueing
- agent availability
- CRM lookups before connecting
That usually means your webhook responds dynamically based on business logic.
11) Example data model
A simple config schema:
{
"inboundNumber": "+18005550199",
"routingMode": "fallback",
"destinations": [
{ "number": "+14155550001", "timeoutSeconds": 20 },
{ "number": "+14155550002", "timeoutSeconds": 20 }
],
"businessHours": {
"timezone": "America/New_York",
"open": "09:00",
"close": "17:00"
},
"afterHoursDestination": "+14155550999"
}
12) Deployment checklist
- Buy and configure phone number
- Point inbound voice/SMS webhooks to your app
- Set up HTTPS
- Verify provider signatures
- Build routing rules in DB/admin UI
- Add call/SMS status callbacks
- Test:
- answered call
- no answer
- busy
- failed
- SMS in/out
- Monitor logs and retries
13) Simplest possible implementation
If you just want basic call forwarding:
- Buy a number from a provider
- Set its inbound voice webhook to your server
- Return a
<Dial>response to the chosen destination number - Add status callbacks for tracking
That’s enough for a first version.
If you want, I can also give you:
- a Twilio-specific step-by-step guide
- a Node.js example
- a Python/FastAPI example
- or a full architecture for call + SMS forwarding with database schema and webhook security