Quick Overview
This workflow responds to Telegram customer messages by using Google Gemini to detect whether the user wants an order status update or an FAQ answer, pulls the relevant data from Google Sheets, logs the conversation to Google Sheets, and replies back in Telegram.
How it works
- Receives an incoming Telegram message.
- Uses Google Gemini to classify the message intent (order status vs. FAQ) and extract an order ID when applicable.
- If the intent is order status, looks up the order in Google Sheets (ORDERS) by order_id and formats a status/tracking reply (or a not-found prompt).
- If the intent is FAQ, reads the FAQ entries from Google Sheets (FAQ) and uses Google Gemini to generate an answer based on the stored questions and answers.
- Writes the timestamp, chat ID, customer message, detected intent, order ID, and reply to a Google Sheets conversation log (CONVERSATION).
- Sends the prepared reply back to the customer via Telegram.
Setup
- Create a Telegram bot, add your Telegram credentials in n8n, and start a chat with the bot so it can receive and reply to messages.
- Add a Google Gemini (Google PaLM) API credential and select the model for both the intent detection and FAQ answering steps.
- Add Google Sheets service account credentials, share your spreadsheet with the service account email, and ensure it contains ORDERS, FAQ, and CONVERSATION sheets.
- Update the spreadsheet ID (and sheet names/columns if different) so order lookups use an order_id column and the conversation log has columns like timestamp, chat_id, customer_message, intent, order_id, and reply.