This Twilio Function provides a template for forwarding both voice calls and SMS messages to another phone number. It includes features like caller restrictions and customizable call forwarding parameters.
- Forward incoming voice calls to a specified number
- Forward incoming SMS messages to a specified number
- Restrict forwarding to a list of allowed callers
- Customizable caller ID for voice calls
- Adjustable timeout for voice calls
- Deploy this function to your Twilio account.
- Set the
FORWARD_TO_NUMBERenvironment variable with the phone number you want to forward to. - Configure your Twilio phone number to use this function for both voice and messaging webhooks.
When a voice call is received, the function will:
- Check if the caller is allowed (if restrictions are set)
- Forward the call to the specified number
- Use custom caller ID and timeout if provided
When an SMS is received, the function will:
- Check if the sender is allowed (if restrictions are set)
- Tag the message with the original sender's number
- Forward the tagged message to the specified number
For responses from the forwarding number:
- The system will automatically route the response back to the original sender
- The recipient at the forwarding number can simply reply to the tagged message
Forwarded messages are tagged with the following format:
➡️OriginalSenderNumber:MessageContent
The right arrow emoji (➡️) indicates a forwarded message. When replying, the system will automatically handle routing based on this format.
You can customize the function's behavior by passing the following parameters:
PhoneNumber: The number to forward to (overrides environment variable)CallerId: Custom caller ID for voice callsTimeout: Custom timeout for voice callsallowedCallers: Array of phone numbers allowed to be forwarded
To modify this function:
- Clone the repository
- Make your changes in
index.js - Test thoroughly
- Deploy to Twilio