Build an SMS Auto-Reply Bot With the Telnyx Messaging API
Every business gets text messages outside of office hours. Customers ask about pricing, request support, or just want to know when you’re…
Build an SMS Auto-Reply Bot With the Telnyx Messaging API
Every business gets text messages outside of office hours. Customers ask about pricing, request support, or just want to know when you’re open. Without an autoresponder in place, those messages sit unanswered until someone checks the queue the next morning — and by then, the customer has moved on.
An SMS auto-reply bot solves this by responding instantly to every inbound message. You can route replies by keyword, adjust responses based on business hours, and handle opt-in/opt-out compliance — all without a human in the loop. With the Telnyx Messaging API and webhooks, you can build one in a single endpoint.
What Is an SMS Autoresponder?
An SMS autoresponder is a service that listens for incoming text messages and sends back a pre-defined reply based on the content of the message. The Telnyx Messaging API makes this straightforward: when someone texts your Telnyx number, Telnyx delivers the message to your application as a webhook event. Your application inspects the message, picks the right response, and sends a reply back through the API.
The key components are keyword routing and business-hours logic. Keyword routing maps words like “help,” “hours,” or “pricing” to specific responses. Business-hours logic lets you tailor replies depending on whether your team is currently available — directing callers to a phone number during the day, or setting expectations about response times at night.
How It Works
The autoresponder flow has three steps:
- A customer sends an SMS to your Telnyx number. Telnyx receives the message and forwards it to your application as a
message.receivedwebhook event. The payload includes the sender's phone number, your Telnyx number, and the message text. - Your application generates a response. Your webhook handler parses the incoming message, checks it against keyword rules and business-hours logic, and selects the appropriate reply. For example, a message containing “hours” returns your operating schedule, while “help” routes to a support response that varies based on time of day.
- Your application sends the reply via the Telnyx API. Your app calls
POST /v2/messageswith the sender's number as the destination, your Telnyx number as the sender, and the generated response as the message body. The customer receives the reply as a standard SMS.
No polling. No message queues. One webhook in, one API call out.
Key API Calls
Everything below works with any language or framework. All you need is the ability to receive HTTP requests and make HTTP requests.
Receive an Inbound SMS (Webhook)
When a customer texts your Telnyx number, Telnyx sends a POST request to your configured webhook URL. The payload looks like this:
{
"data": {
"event_type": "message.received",
"payload": {
"direction": "inbound",
"type": "SMS",
"from": {
"phone_number": "+12125551234"
},
"to": [
{ "phone_number": "+13105559876" }
],
"text": "What are your hours?"
}
}
}
Your webhook handler should verify the request signature, check that the event_type is message.received, and extract the from.phone_number and text fields.
Send an SMS Reply
Once you’ve determined the response, send it back with a single API call:
curl -X POST https://api.telnyx.com/v2/messages \
-H "Authorization: Bearer YOUR_TELNYX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"from": "+13105559876",
"to": "+12125551234",
"text": "We'\''re open Monday-Friday 9 AM to 5 PM EST. Weekend hours: Saturday 10 AM - 2 PM. Closed Sundays."
}'
The from field is your Telnyx phone number. The to field is the customer's number from the inbound webhook. A 200 response means the message has been accepted for delivery.
That’s the entire round trip. Receive a webhook, send a reply.
Webhook Signature Verification
Telnyx signs every webhook request with an Ed25519 signature. Your application should verify this signature before processing the event to ensure the request actually came from Telnyx. The Telnyx SDKs handle this automatically — in Python, for example, you call client.webhooks.unwrap() with the raw request body and headers.
Why Telnyx
Telnyx is AI Communications Infrastructure built for developers who need programmable connectivity at scale. Here’s what that means for SMS autoresponders:
Webhooks with signature verification. Every webhook event is signed with Ed25519, so your application can cryptographically verify that inbound messages are legitimate. No shared secrets, no HMAC complexity — just public-key verification built into the SDK.
Keyword and compliance handling. The Messaging API delivers the full message payload to your webhook, giving you complete control over keyword routing, opt-in/opt-out handling (STOP/START), and business-hours logic. You own the routing rules, not the platform.
Private network infrastructure. Telnyx operates a private, global IP network. Your messages don’t traverse the public internet any more than necessary, reducing latency and improving delivery reliability.
No per-message markup games. Telnyx pricing is straightforward. You pay for what you use without inflated per-message fees or hidden platform surcharges.
Get Started
A complete working example — a Python Flask application that implements keyword routing, business-hours logic, webhook signature verification, and opt-in/opt-out handling — is available in the Telnyx code examples repository:
sms-auto-reply-bot-python on GitHub
The example includes a webhook endpoint (/webhooks/sms), contextual response generation based on message keywords, and proper error handling for Telnyx API errors. Clone it, add your credentials, and you have a running SMS autoresponder.
To get started:
- Sign up for a Telnyx account if you don’t have one.
- Buy a phone number and create a Messaging Profile in the Mission Control Portal, setting your webhook URL to point to your
/webhooks/smsendpoint. - Clone the example repo, set your
TELNYX_API_KEY,TELNYX_PUBLIC_KEY, andTELNYX_PHONE_NUMBERenvironment variables, and run the app.
Full API documentation is available at developers.telnyx.com.
메타데이터
- post_id
- d11d6360ebac
- slug
- build-an-sms-auto-reply-bot-with-the-telnyx-messaging-api-d11d6360ebac
- url
- https://medium.com/@harpreetadobe/build-an-sms-auto-reply-bot-with-the-telnyx-messaging-api-d11d6360ebac
- canonical_url
- https://medium.com/@harpreetadobe/build-an-sms-auto-reply-bot-with-the-telnyx-messaging-api-d11d6360ebac
- author_url
- https://medium.com/@harpreetadobe
- status
- ok
- fetched_at
- 2026-07-09 13:13:48