Introduction
Imagine: your AI agent reads emails in Gmail on its own, responds to messages in Telegram, and performs tasks without requiring your participation. Sounds like science fiction? In reality, it's a reality accessible to everyone. Today, I'll show you how to connect Gmail and Telegram to an AI agent through a universal credential connector. You'll learn how to set up Gmail AI for email automation and Telegram AI for chat management, using a unified approach to managing credentials. This will save you hours of routine work and boost productivity.
Why a Universal Connector is a Must-Have for AI Agents
Traditionally, each service (Gmail, Telegram, Slack) requires separate integrations, leading to confusion with API keys, tokens, and OAuth processes. A universal credential connector solves this problem by consolidating all credentials in one place. Benefits:
- Single point of entry: one connector for all external services.
- Security: credentials are stored encrypted and automatically rotated.
- Flexibility: easy to add new services without rewriting code.
- Time savings: setup takes 10 minutes instead of an hour.
Step-by-Step Guide to Connecting Gmail to an AI Agent
Step 1: Obtain Credentials for the Gmail API
- Go to Google Cloud Console.
- Create a new project or select an existing one.
- Enable the Gmail API: go to "API Library" → find Gmail API → click "Enable".
- Create an OAuth 2.0 Client ID: go to "Credentials" → "Create Credentials" → "OAuth client ID" → select "Desktop app" → give it a name (e.g., "AI-Agent-Gmail").
- Download the JSON file with credentials (your
client_idandclient_secret).
Step 2: Configure the Universal Connector
- In the AI agent's control panel, find the "Credentials Connector" section.
- Click "Add Service" → select "Gmail".
- Upload the JSON file with credentials or paste them manually.
- Specify the access scope: for example,
https://www.googleapis.com/auth/gmail.readonlyfor reading orhttps://mail.google.com/for full access. - Save the connector. The AI agent will automatically request authorization via OAuth.
Step 3: Authorize Access
- Follow the link generated by the connector.
- Log in to your Google account and grant access.
- Copy the authorization code and paste it into the connector.
Done! Now your AI agent can read emails, send replies, and sort incoming messages. Example command: "Read the last 5 emails from clients and prepare a brief summary."
Connecting Telegram to the AI Agent via the Same Connector
Step 1: Create a Bot and Get a Token
- Open Telegram and find @BotFather.
- Send the command
/newbotand follow the instructions. - Get the token (looks like
123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11).
Step 2: Add Telegram to the Universal Connector
- In the same "Credentials Connector" section, click "Add Service" → select "Telegram".
- Paste the token into the API Token field.
- Configure the webhook: the connector will automatically generate a URL like
https://your-agent.com/webhook/telegram. Copy it. - Set the webhook by sending a request:
https://api.telegram.org/bot<TOKEN>/setWebhook?url=<YOUR_URL>. - Save the connector.
Step 3: Test the Connection
Send a message to your bot in Telegram. The AI agent should receive it and respond (if corresponding triggers are configured). Example: "Hi, who are you?" → AI replies: "I am your AI assistant, ready to help!"
Examples of Using Gmail AI and Telegram AI Together
Here are a few scenarios that become reality thanks to the unified connector:
- Automated customer support: AI reads requests from Gmail and responds to them via Telegram.
- Notifications: AI checks email every 10 minutes and sends important messages to Telegram.
- Task synchronization: AI extracts tasks from emails and adds them to a Telegram chat.
Example code
Comments