Support teams do not only need to know that a customer texted them. They need to know when a conversation is getting urgent.
This sample builds a sentiment analysis agent for inbound SMS on Telnyx Edge Compute. Every message is classified by an LLM, written to actor-local SQL, and given an empathetic reply. When the sentiment is negative, the same flow sends an SMS alert to an ops number for human escalation.
The important part is where the logic runs: at the edge, directly in the request path for messaging events.
What the Sample Builds
The sentiment-analysis-agent sample is a Node.js Telnyx Edge Compute function with an Agent SDK actor:
class SentimentAgent extends Agent
The agent receives an inbound SMS event, calls Telnyx AI Inference, stores the result in SQL, and decides whether the conversation needs a human.
The flow looks like this:
Inbound SMS webhook
-> Edge Compute fetch handler
-> SentimentAgent.receive()
-> Telnyx Inference sentiment classification
-> actor-local SQL sentiment log
-> empathetic auto-reply
-> SMS escalation for negative sentiment
The repo also includes a browser view for testing the flow, sending sample messages, resetting the log, and showing the live sentiment timeline during a demo.
Why Edge Compute Matters Here
Sentiment routing is most useful when it happens immediately.
If the logic sits behind a separate queue, a regional app server, and a few webhook hops, the user experience starts to feel delayed. A frustrated customer might send a second message before anyone knows the first one was negative.
Running the agent on Telnyx Edge Compute keeps the decision close to the inbound event. The same function that receives the messaging webhook can classify the message, persist a log entry, and trigger the escalation path.
That makes this a good fit for workflows like:
- Support inbox triage
- Refund or cancellation detection
- VIP customer escalation
- Abuse or safety review queues
- After-hours customer follow-up
The Telnyx Pieces
The sample uses four Telnyx primitives together:
- Edge Compute deploys the HTTP handler and agent actor.
- Agent SDK keeps the sentiment workflow organized around
SentimentAgent. - Telnyx AI Inference runs the sentiment classification through
this.env.TELNYX.ai.openai.chat.createCompletion(). - Telnyx Messaging sends replies and escalation alerts through
this.env.TELNYX.messages.send()when production SMS is enabled.
It also uses actor-local SQL:
CREATE TABLE sentiment(
id INTEGER PRIMARY KEY AUTOINCREMENT,
sender TEXT NOT NULL,
message TEXT NOT NULL,
label TEXT NOT NULL,
score REAL NOT NULL,
escalated INTEGER NOT NULL,
reply TEXT NOT NULL,
at INTEGER NOT NULL
);
That gives the browser demo a live log and gives the production workflow a durable record of what the agent decided.
Running the Demo
Clone the code examples repo and install dependencies:
cd telnyx-code-examples/sentiment-analysis-agent
npm install
npm run typecheck
npm run types
Authenticate the Edge CLI:
telnyx-edge auth api-key set "$TELNYX_API_KEY"
telnyx-edge auth status
For a new function, scaffold the Telnyx identity first:
telnyx-edge new-func --actor --name=sentiment-analysis-agent
Then deploy:
telnyx-edge ship
Open the deployed telnyxcompute.com URL. The UI lets you send test SMS messages and inspect the live sentiment log.
Try these messages:
I love this app, just paid for a year
What are your hours?
this is broken and nobody is helping me, I want a refund
Positive and neutral messages get normal replies. Negative messages show a human escalation badge and send an SMS alert to the configured ops number.
Connect Messaging
Point your Telnyx Messaging webhook to:
https://<your-function>.telnyxcompute.com/webhooks/messaging
Inbound messages hit the Edge function, customer replies go out through Telnyx Messaging, and negative sentiment sends an SMS alert to the configured ops number.
What This Shows
This is a compact example, but it demonstrates a useful pattern: use Edge Compute for the event path, use AI Inference for the decision, use local state for traceability, and use Messaging for the customer-facing action.
The result is not just sentiment analysis as a background report. It is sentiment analysis wired into the moment where a customer is asking for help.