Opening Problem Statement
Meet Sarah, an active meetup organizer for a popular tech group in Da Nang. Every time a member asks about upcoming meetup schedules, Sarah spends 10-15 minutes searching through a Google Spreadsheet, copying the schedule, and typing out the response. Multiply that by dozens of daily queries, and she loses several hours weekly that could be better spent planning or networking.
Moreover, manual responses sometimes lead to outdated or incorrect information being shared, frustrating members and affecting attendance. Sarah needs an automated, reliable way to instantly answer schedule questions directly in Telegram where her community interacts most.
What This Automation Does
This n8n workflow creates an intelligent Telegram bot integrated with AI that can:
- Respond instantly in Telegram chats when members ask about meetup schedules.
- Fetch the latest schedule data from a Google Sheets document automatically.
- Convert the schedule data into a markdown table that AI can understand and use as context.
- Use an AI agent (LangChain-based) to generate accurate, context-aware responses about the schedule.
- Indicate when the bot is “typing” in Telegram to provide a smoother chat experience.
- Support multiple chat input sources and toggle response routing based on chat origin (Telegram or internal n8n chat).
This results in hours saved every week, improved response accuracy, and a professional, automated member interaction experience.
Prerequisites ⚙️
- n8n account (cloud or self-hosted) for workflow automation.
- Telegram Bot API credentials to connect and send messages.
- Google Sheets account with OAuth credentials for reading schedule data.
- OpenRouter account for AI large language model (LLM) processing.
- Basic familiarity with n8n interface.
📁 If you prefer self-hosting n8n, consider providers like Hostinger.
Step-by-Step Guide
Step 1: Set Up Telegram Trigger Node
Navigate to the nodes panel and add the Telegram Trigger node named telegramInput. Configure it to listen to incoming “message” updates. Connect your Telegram API credentials here.
This node listens for any message sent to your Telegram bot and starts the workflow.
Common mistake: Forgetting to select the correct “message” update type will prevent the bot from responding.
Step 2: Simulate Typing Action with SendTyping Node
Add a Telegram node named SendTyping. Set Operation to “sendChatAction” with the chat ID passed from telegramInput. This node simulates the bot “typing…” in the chat to enhance user experience.
Step 3: Normalize Telegram Input
Add a Set node (telegramChatSettings) that extracts the text message and chat ID from the telegram input. Set mode as “telegram” for later conditional routing.
Step 4: Normalize Internal Chat Input
Add a LangChain Chat Trigger node named n8nInput to handle chats triggered internally inside n8n. Then add a Set node (n8nChatSettings) to extract message and session ID, set mode as “n8n”.
Step 5: Set Workflow Settings
Add a Set node (Settings) to store static data such as your Google Sheets schedule URL and the mode (from previous inputs). This node centralizes your settings for easier management.
Step 6: Fetch Schedule from Google Sheets
Add a Google Sheets node named Schedule configured to read from your schedule spreadsheet URL, sheet “gid=0” (first sheet). Make sure you connect your Google Sheets OAuth credentials.
This node retrieves the latest schedule data as JSON.
Step 7: Convert Schedule Data to Markdown Table with Code Node
Add a Code node named ScheduleToMarkdown after the Google Sheets node. Paste the following JavaScript code to transform the JSON rows into a markdown table:
// Get all rows from the input (each item has a "json" property)
const rows = items.map(item => item.json);
// If no data, return an appropriate message
if (rows.length === 0) {
return [{ json: { markdown: "No data available." } }];
}
// Use the keys from the first row as the header columns
const headers = Object.keys(rows[0]);
// Build the markdown table string
let markdown = "";
// Create the header row
markdown += `| ${headers.join(" | ")} |n`;
// Create the separator row (using dashes for markdown)
markdown += `| ${headers.map(() => '---').join(" | ")} |n`;
// Add each data row to the table
rows.forEach(row => {
// Ensure we output something for missing values
const rowValues = headers.map(header => row[header] !== undefined ? row[header] : '');
markdown += `| ${rowValues.join(" | ")} |n`;
});
const result = { 'binary': {}, 'json': {} };
// Optionally, also return the markdown string in the json property if needed
result.json.markdown = markdown;
return result;
This script generates a markdown table string for the AI to use as context.
Step 8: Use LangChain Agent for AI-Powered Responses
Add the LangChain Agent node named ScheduleBot. Configure it with your input message, and set the system message to explain it’s a helpful assistant for answering meetup schedule questions using the markdown table provided.
Step 9: Attach AI Large Language Model (LLM) Node and Memory
Add LLM node (OpenRouter chat) and Memory Buffer node connected to the ScheduleBot. This enables contextual AI responses with chat history using OpenRouter’s API.
Step 10: Set Response Message
Add a Set node (SetResponse) that collects the AI output as the response message.
Step 11: Switch Node to Choose Response Channel
Add a Switch node that checks the mode from Settings. Routes output to either Telegram response or internal n8n response handlers.
Step 12: Telegram Response Node
Add a Telegram node (telegramResponse) configured to send the AI-generated response back to the Telegram chat using chat ID from settings.
Step 13: Internal n8n Response Node
Add a No Operation node (n8nResponse) for internal chat mode, which could be expanded later.
Customizations ✏️
- Change Schedule Source: In the
Settingsnode, update the scheduleURL property to point to a different Google Sheets document to manage a different meetup group. - Adjust AI Personality: Modify the systemMessage in the
ScheduleBotLangChain node to change how the assistant replies, tailoring tone or detail level. - Add More Chat Platforms: Add additional trigger and settings nodes for Slack or Discord and expand the
Switchnode to route accordingly. - Enable Markdown Output to Users: Adapt the
SetResponsenode to send back raw markdown if your Telegram clients support it.
Troubleshooting 🔧
Problem: Telegram Bot Not Responding
Cause: Incorrect Telegram Trigger node setup or bad API credentials.
Solution: Recheck webhook registration, ensure “message” updates selected, and verify correct Telegram API credentials under the Telegram Trigger and Telegram nodes.
Problem: Google Sheets Data Not Loading
Cause: Wrong sheet ID or insufficient OAuth permissions.
Solution: Verify your Google Sheets URL in the Settings node, make sure your OAuth token has read access, and check the spreadsheet’s sharing settings.
Problem: AI Responses Lack Context
Cause: Schedule markdown not properly passed or memory node misconfigured.
Solution: Inspect connections between ScheduleToMarkdown, ScheduleBot, and Memory nodes. Confirm that the markdown is included in the system message and memory buffer uses chatId as session key.
Pre-Production Checklist ✅
- Confirm Telegram bot webhook is active and receiving “message” updates.
- Verify Google Sheets access and that schedule data is up-to-date.
- Test AI with sample input messages and review response accuracy.
- Check routing in Switch node by testing both Telegram and n8n chat inputs.
Deployment Guide
Activate the workflow in n8n and ensure the Telegram bot webhook URL is publicly accessible. Monitor the workflow execution in n8n for any errors.
Consider logging responses for future audits or improvements by adding nodes to save chat history.
FAQs
Can I use a different AI provider instead of OpenRouter?
Yes. You can replace the LLM node with any supported AI provider in LangChain nodes, such as OpenAI, Cohere, or Hugging Face, adjusting credentials accordingly.
Is my Google Sheet data secure?
Only authorized OAuth tokens are used and data is never publicly exposed. Make sure your Google Sheet sharing settings are properly configured.
How scalable is this bot?
This setup handles typical meetup group sizes well. For very large volumes, consider adding caching or rate limiting to avoid API quota limits.
Conclusion
By building this Telegram scheduling bot with n8n and AI, you’ve automated a time-consuming manual task. Your meetup members get instant, accurate schedule updates right in their chat app, saving you hours weekly and improving member satisfaction.
Next, you might explore adding calendar integrations for RSVP tracking or connecting with Slack to widen your community support. Keep automating to focus more on what matters—building great events.
Happy automating!