Opening Problem Statement
Meet Derek, a busy project manager juggling multiple meetings, emails, and task lists daily. Derek often wastes precious minutes switching between his email inbox, Google Calendar, and task management tools just to find the information he needs. He frequently misses important meetings, overlooks urgent emails, and struggles to keep track of tasks, costing him hours every week and increasing his stress levels.
What Derek really needs is an assistant who can listen to his requests, gather all relevant data, and respond instantly with clear summaries and reminders — all within the messaging app he already uses, Telegram. But hiring a personal assistant is expensive and not always practical.
This is where automation steps in. By leveraging n8n’s powerful workflow automations integrated with OpenAI, Gmail, Google Calendar, and Baserow, you can create your own AI personal assistant. This assistant can fetch emails, read calendar events, keep track of tasks, and chat with you conversationally — saving Derek countless hours and reducing costly mistakes.
What This Automation Does ⚙️
When the workflow runs, here’s exactly what happens:
- It listens for incoming text or voice messages in Telegram.
- If voice, converts speech to text using OpenAI’s speech-to-text feature.
- Uses a sophisticated AI assistant powered by OpenAI GPT-4 to understand the request’s intent.
- Fetches unread emails from Gmail based on the date provided or assumed today, excludes promotional emails, and summarizes sender, date, subject, and key points.
- Retrieves Google Calendar events filtered by date or question context to give relevant upcoming appointments.
- Queries Baserow databases for contacts and task lists to provide updated information.
- Responds back in Telegram with clear, concise, and contextual answers, all in real time.
This automation allows Derek (or any user) to access complex, dynamic information conversationally within Telegram — reducing time spent manually searching across apps by hours weekly and improving task management clarity.
Prerequisites ⚙️
- n8n Account: You need access to n8n automation platform with permissions to create workflows.
- Telegram Account and Bot 📱: Required to receive and send messages via the Telegram Trigger and Telegram nodes.
- Gmail Account 📧: Connected using Gmail OAuth2 for fetching unread emails.
- Google Calendar Account 📅: OAuth2 credentials to access calendar events.
- Baserow Account 📊: For accessing tables containing contacts and tasks.
- OpenAI API Key 🔑: Needed for GPT-4 powered AI chat, speech-to-text transcription, and context memory.
You can self-host n8n following guides like those available at buldrr.com/hostinger if you want full control over your data and workflow environment.
Step-by-Step Guide ✏️
Step 1: Set Up Telegram Trigger to Listen for Incoming Messages
Navigate to your n8n workflow editor. Add the Telegram Trigger node named “Listen for incoming events”.
Configure it to listen for “message” update types.
Connect your Telegram Bot API credentials.
After saving, you’ll receive a webhook URL — ensure your Telegram bot is linked to this URL to receive updates.
You should now see new incoming Telegram messages triggering your workflow.
Common Mistake: Forgetting to authorize your Telegram bot with the correct webhook URL causes the workflow never to trigger.
Step 2: Extract Text or Voice Input
Connect the Telegram Trigger output into a Set node called “Voice or Text” that extracts the text message or empty string if voice is detected.
Then add an If node that checks if the text message is empty (meaning it’s a voice message).
Common Mistake: Misconfiguring the condition in If node to incorrectly identify voice or text.
Step 3: Retrieve Voice File from Telegram & Convert to Text
If it’s a voice message, connect to the Telegram Get File node to fetch the voice message file ID.
Then feed the file into the Speech to Text node using OpenAI API.
You’ll get a transcript string output.
Common Mistake: Incorrect file ID mapping results in failure to fetch or transcribe voice data.
Step 4: Initialize the AI Assistant Agent
Whether from text or transcribed voice, pass the message text to the LangChain Agent node named “Angie, AI Assistant 👩🏻🏫”.
Configure its system message to instruct how to handle fetching emails, calendar events, tasks, filtering out spam, summarizing details, and contextual responses.
This agent uses the OpenAI GPT-4o-mini model behind the scenes.
Common Mistake: Omitting key instructions in the system prompt could confuse the AI’s responses.
Step 5: Fetch Unread Emails via Gmail Node
The AI agent calls the Gmail Tool node that pulls all unread emails from the inbox received after the date inferred in user’s request.
Filter out promotional emails and format summaries of sender, date, subject, and message snapshot.
Common Mistake: Failing to configure label filters correctly can include unwanted emails.
Step 6: Retrieve Google Calendar Events
Another supporting node, Google Calendar Tool, fetches calendar entries filtered by date relevant to the assistant’s query.
Only events from the specified date range are returned to avoid clutter.
Common Mistake: Incorrect date filtering or OAuth credentials cause missing calendar data.
Step 7: Query Baserow for Tasks and Contacts
Two Baserow Tool nodes query your task and contact database tables respectively.
This helps the assistant provide up-to-date task statuses and relevant contact info.
Common Mistake: Ensure correct table IDs and credentials use to avoid empty results.
Step 8: Maintain Context with Window Buffer Memory Node
The Window Buffer Memory node stores session-based conversation context keyed by Telegram user ID.
This allows the AI to remember recent interactions and give coherent answers over multiple messages.
Common Mistake: Using incorrect session keys can lose conversation state.
Step 9: Send the AI’s Response Back to Telegram
Finally, the compiled AI response passes into the Telegram node, which sends a Markdown-formatted reply back to the user’s chat.
You should see your assistant’s message instantly appear in Telegram.
Common Mistake: Not matching chat IDs properly leads to replies sent to wrong users.
Customizations ✏️
- Change the Personal Assistant’s Name and Personality: Edit the system message in “Angie, AI Assistant 👩🏻🏫” node to modify tone, add personality traits, or specify task focus.
- Add Support for More Languages: In the Speech to Text node, change language settings to support transcription in other languages.
- Extend Calendar Date Range: Modify the Google Calendar node’s date filter parameter to look further ahead or in the past.
- Include Email Attachments: Enhance the Gmail Tool node to also fetch and summarize email attachments if relevant.
- Integrate Additional Baserow Tables: Add more Baserow Tool nodes to query project databases or notes for richer responses.
Troubleshooting 🔧
Problem: “No response from Telegram after sending message”
Cause: The Telegram webhook URL is not properly set or the bot token is invalid.
Solution: Go to the Telegram Trigger node, verify the webhook URL in your Telegram bot settings, and reauthorize the bot token.
Problem: “Speech to Text node fails to transcribe audio”
Cause: The file ID from Telegram is incorrect or the OpenAI API key lacks permissions.
Solution: Check that the “Get Voice File” node correctly accesses the voice file ID and confirm your OpenAI API key credentials in n8n.
Problem: “Emails include promotional or irrelevant messages”
Cause: Gmail label or filter misconfiguration.
Solution: Adjust label IDs in the “Get Email” node parameters to exclude promotional or spam labels explicitly.
Pre-Production Checklist ✅
- Verify Telegram bot webhook is active and receiving messages.
- Test OpenAI API credentials by sending test queries to the GPT model and speech-to-text service.
- Check Gmail and Google Calendar OAuth tokens are valid and permission scope includes read access.
- Validate Baserow API connection to task and contacts tables returns expected data.
- Run end-to-end test: send text and voice messages to the bot and confirm accurate summaries returned.
- Backup your workflow configuration before making major changes.
Deployment Guide
Activate your workflow in n8n by clicking ‘Activate’ in the editor once you have completed all setup and tests. Ensure your server or n8n cloud instance runs 24/7 if constant availability is required.
Monitor incoming Telegram messages and error logs in n8n to maintain smooth operation.
FAQs
Can I use another chat platform instead of Telegram?
Yes, but you would need to replace the Telegram Trigger and Telegram nodes with equivalents for your chosen platform, adjusting the workflow accordingly.
Does this workflow consume a lot of OpenAI API credits?
It depends on usage volume and request frequency. Speech-to-text and GPT calls consume credits, so monitor your OpenAI usage to manage costs.
Is my data secure in this workflow?
If you self-host your n8n instance and secure API credentials properly, your data remains under your control. Using cloud instances relies on the provider’s security measures.
Conclusion
By following this comprehensive tutorial, you have built a personalized AI assistant inside your Telegram app using n8n, OpenAI GPT-4, Gmail, Google Calendar, and Baserow. This AI assistant fetches emails, calendar events, and tasks, understands voice and text commands, and responds instantly.
You’ve saved valuable time searching through different apps and minimized the stress of managing your day manually. As next steps, consider adding integrations like Slack notifications, advanced natural language processing for deeper understanding, or automating task updates based on email follow-ups.
Happy automating!