How to Connect Gmail and Telegram to an AI Agent via a Unified Connector: A Step-by-Step Guide with Credentials

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

  1. Go to Google Cloud Console.
  2. Create a new project or select an existing one.
  3. Enable the Gmail API: go to "API Library" → find Gmail API → click "Enable".
  4. 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").
  5. Download the JSON file with credentials (your client_id and client_secret).

Step 2: Configure the Universal Connector

  1. In the AI agent's control panel, find the "Credentials Connector" section.
  2. Click "Add Service" → select "Gmail".
  3. Upload the JSON file with credentials or paste them manually.
  4. Specify the access scope: for example, https://www.googleapis.com/auth/gmail.readonly for reading or https://mail.google.com/ for full access.
  5. Save the connector. The AI agent will automatically request authorization via OAuth.

Step 3: Authorize Access

  1. Follow the link generated by the connector.
  2. Log in to your Google account and grant access.
  3. 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

  1. Open Telegram and find @BotFather.
  2. Send the command /newbot and follow the instructions.
  3. Get the token (looks like 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11).

Step 2: Add Telegram to the Universal Connector

  1. In the same "Credentials Connector" section, click "Add Service" → select "Telegram".
  2. Paste the token into the API Token field.
  3. Configure the webhook: the connector will automatically generate a URL like https://your-agent.com/webhook/telegram. Copy it.
  4. Set the webhook by sending a request: https://api.telegram.org/bot<TOKEN>/setWebhook?url=<YOUR_URL>.
  5. 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

← All posts

Comments