WAYSQUARE.COM | Techno Blog
n8n

How I Built a Fully Automated SMS AI Assistant with GPT-4.1, Twilio, and n8n — No More Missed Messages!

Learn how I built a fully functional AI SMS assistant using n8n, Twilio, GPT-4.1, Supabase for memory, and Perplexity for real-time product info. Perfect for automating support, sales, and reminders—no coding required!


Share this post

Hello everyone! 👋 In this blog post, I want to share my experience building a fully functional, automated AI SMS assistant using n8n, Twilio, GPT-4.1, Postgres for memory, and Perplexity API for real-time RAG (retrieval augmented generation).

⚙️ The Stack

  • Twilio for receiving and sending SMS
  • n8n as the automation engine
  • OpenAI GPT-4.1 as the brain
  • Postgres (via Supabase) for conversation memory
  • Perplexity API for RAG using website & support docs

📲 Why SMS? And What Makes It Special?

Most people expect fast replies on SMS or chat, but often they send multiple fragmented messages. Instead of reacting to each one, I built a batching mechanism that holds all messages from a sender for 5–10 seconds and processes them together. This allows a context-aware, complete AI response.

🚀 Step-by-Step Build

  1. Webhook Node: Receives incoming SMS from Twilio
  2. Google Sheet Holding Table: Temporarily stores messages for batching
  3. Wait Node: Waits a few seconds before pulling the batch
  4. Get Rows Node: Retrieves all messages for a phone number
  5. Code Node: Combines all messages into a single string
  6. Delete Rows Node: Cleans up the holding table
  7. AI Agent Node: GPT-4.1 with memory and RAG capabilities
  8. HTTP Request Node: Integrates Perplexity API to query company website/support pages
  9. Twilio Send Node: Sends the AI-generated SMS response back to the user

🧠 Memory & Personalization

I used Postgres chat memory via Supabase keyed by the sender's phone number. This way, every message sent and response generated is logged and used in future queries. It's like the AI “remembers” every conversation.

🔍 RAG via Perplexity API

Instead of setting up a complex database for retrieval, I use Perplexity API to search only my domain and support site. This gives real-time, accurate product data to the AI.

🧪 Testing & Results

I tested sending multiple messages like "Hi", "What products does Jula sell?", and it worked like a charm. The AI replied once with a complete answer, including a clickable link to the right page. ✨

✅ Final Touches

  • Limited output to 160 characters to fit within a single SMS
  • Ensured phone numbers use E.164 format for Twilio compatibility
  • Prompted the AI to include product URLs in replies

💡 Use Cases

  • Inbound customer support
  • Outbound appointment reminders
  • Automated sales SMS bots
  • Product FAQs via SMS

🙌 Conclusion

This was one of the most satisfying automations I’ve built in n8n. It brings together realtime intelligence, memory, and personalization — all over SMS. Best part? It's affordable, scalable, and fun to build!


Share this post

Written by
Wahyu Widagdo
Wahyu Widagdo
I am a professional telco engineer and blogger

Type above and press Enter to search.