Messaging

Build an SMS Auto-Reply Bot With the Telnyx Messaging API

Build an SMS auto-reply bot that responds instantly to inbound messages. Keyword routing, business-hours logic, and webhook signature verification with the Telnyx Messaging API.

By Harpreet Singh Seehra

An SMS auto-reply bot is a webhook-driven service that receives an inbound text, chooses a response, and sends an SMS reply without human action. With the Telnyx Messaging API, Telnyx sends your app a message.received webhook, then your app replies through POST /v2/messages. The SMS API supports global messaging with 10DLC, toll-free, shortcodes, and high throughput, so one bot can handle after-hours, pricing, and support replies.

Use an SMS autoresponder when customers text outside office hours, ask for support, or need a routing answer. The bot can return a text message auto reply, route “hours” to a schedule, route “pricing” to sales, and send “help” to a support path. The logic runs in your app, so rules can match your queue, time zone, and consent process.

What an SMS auto-reply bot does

An SMS autoresponder listens for incoming text messages and sends back a pre-defined reply based on the content of the message. Telnyx receives the text on your number and sends your application an SMS webhook. Your application inspects the payload, selects the right response, and sends the reply back through the API.

The routing layer has two main jobs. Keyword routing maps words like “help,” “hours,” or “pricing” to specific responses. Business-hours logic changes the reply based on whether your team is available. During the day, the reply can point to a live support path. At night, it can set a clear response window.

Note: Treat STOP and START as explicit routes. Store opt-out state in your system and check it before any promotional reply. This is implementation guidance, not legal advice.

How an SMS auto-reply bot works

An inbound SMS automation flow has three steps.

  1. A customer sends an SMS to your Telnyx number. Telnyx receives the message and forwards it to your application as a message.received webhook event. The payload includes the sender’s phone number, your Telnyx number, and the message text.
  2. Your application generates a response. Your webhook handler parses the incoming message, checks it against keyword rules and business-hours logic, and selects the reply.
  3. Your application sends the reply via the Telnyx API. Your app calls POST /v2/messages with the sender’s number as the destination, your Telnyx number as the sender, and the generated response as the message body.

No polling. No message queues. One webhook in, one API call out.

SMS auto-reply bot flow

1
Inbound SMS
2
message.received
3
Ed25519 check
4
Keyword rules
5
Business hours
6
POST /v2/messages
7
SMS reply

Autoresponder choices

There are three common ways to answer inbound SMS. The right fit depends on how much control you need over routing, timing, consent, and handoff.

ApproachHow it respondsBest fit
Manual inboxAn agent replies after opening the queue.Low volume and staffed hours.
Fixed SMS autoresponderEvery inbound text gets the same reply.Simple acknowledgments.
Telnyx webhook botYour app routes by keyword, consent state, and business hours.Support, sales, and operations workflows.

API calls for the Telnyx Messaging API

Everything below works with any language or framework. Your app needs 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.

json
{
 "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 have determined the response, send it back with a single API call.

bash
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.

Webhook signature verification

Telnyx signs every webhook request with an Ed25519 signature. Your application should verify this signature before processing the event to confirm the request came from Telnyx. The Telnyx SDKs handle this automatically. In Python, call client.webhooks.unwrap() with the raw request body and headers.

Note: Use the raw request body when you call the SDK unwrap method. If your framework parses and rewrites the body first, signature verification can fail because the signed bytes changed.

Routing rules for inbound SMS automation

Start with deterministic rules. Normalize the inbound text, trim whitespace, and compare lower-case content against your routing table. Keep SMS auto reply copy direct. State the answer, the next step, and when a human will respond if one is needed.

Keyword routing

Map high-intent words to specific replies. “Hours” can return the operating schedule. “Pricing” can return a sales link or sales phone number. “Help” can send a support path that changes by time of day. “Stop” and “Start” should update consent state before any other routing logic runs.

Business hours logic

Use one source of truth for your business hours and time zone. If your team is open, the bot can point to a live queue or a phone number. If your team is closed, the bot can set a response window and capture the customer's message for follow-up the next business day.

Receive an inbound SMS

When a customer texts your Telnyx number, Telnyx sends a POST request to your configured webhook URL. The payload includes the sender's phone number, your Telnyx number, and the message text.

json
{
  "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 your application determines the right response, send it back with a single API call.

bash
curl -X POST https://api.telnyx.com/v2/messages \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "from": "+13105559876",
    "to": "+12125551234",
    "text": "We are open Monday-Friday 9 AM to 5 PM EST. 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 is the entire round trip. Receive a webhook, send a reply.

Note: Telnyx signs every webhook request with an Ed25519 signature. Verify this signature before processing the event to confirm the request came from Telnyx. The Telnyx SDKs handle this automatically. In Python, call client.webhooks.unwrap() with the raw request body and headers.

Why Telnyx for SMS autoresponders

Signed webhooks

Every event is signed with Ed25519. Cryptographically verify inbound messages with public-key verification built into the SDK.

Full payload control

The Messaging API delivers the complete message to your webhook. You own keyword routing, STOP/START handling, and business-hours logic.

Private network

Telnyx operates a private global IP network. Messages avoid unnecessary public internet hops, reducing latency and improving delivery reliability.

Transparent pricing

Pay for what you use. No inflated per-message fees or hidden platform surcharges.

Channel comparison

FeatureSMS autoresponderManual queue
Response timeInstantHours to overnight
After hoursAutomated acknowledgmentNo response until morning
Keyword routingYes, programmableManual triage
ComplianceSTOP/START handled in codeManual process

Try the example app

Telnyx provides a working Python Flask example that implements keyword routing, business-hours logic, webhook signature verification, and opt-in/opt-out handling. Clone the sms-auto-reply-bot-python example from GitHub.

The example includes a webhook endpoint at /webhooks/sms, contextual response generation based on message keywords, and proper error handling for Telnyx API errors.

Getting started

Setup checklist:
  1. Sign up for a Telnyx account
  2. Buy a phone number and create a Messaging Profile in the Mission Control Portal
  3. Set your webhook URL to point to your /webhooks/sms endpoint
  4. Clone the example app
  5. Set your TELNYX_API_KEY, TELNYX_PUBLIC_KEY, and TELNYX_PHONE_NUMBER environment variables
  6. Run the app and test by texting your Telnyx number

Full API documentation is available at developers.telnyx.com. For more on verification flows, see the WhatsApp OTP and SMS 2FA guides.

FAQ

How does an SMS auto-reply bot work?
An SMS auto-reply bot listens for incoming text messages on a phone number, processes each message through keyword rules and business-hours logic, and sends a pre-defined response back through an API. With Telnyx, the flow is one webhook event in and one API call out.
Do I need to verify Telnyx webhook signatures?
Yes. Telnyx signs every webhook request with an Ed25519 signature. Your application should verify this signature before processing the event. The Telnyx SDKs handle this automatically. In Python, call client.webhooks.unwrap() with the raw request body and headers.
Can I handle STOP and START keywords for compliance?
Yes. The Messaging API delivers the full message payload to your webhook, giving you complete control over keyword routing including STOP/START opt-in/opt-out handling. You own the routing rules and can implement compliance logic in your application code.
What programming languages can I use?
Any language or framework that can receive HTTP requests and make HTTP requests. The Telnyx API is REST-based. The example app is written in Python with Flask, but the same pattern works in Node.js, Go, Ruby, PHP, Java, or any other language.
How much does it cost to run an SMS auto-reply bot?
You pay for the phone number and the messages you send and receive through the Telnyx SMS API. Telnyx pricing is usage-based with no per-message markup or hidden platform surcharges. Check the product page for current rates.

Build your SMS auto-reply bot todayOne webhook in, one API call out. No polling, no queues, no human in the loop.

Get started free
Share on Social

Sign up for emails of our latest articles and news