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

Introduction

Modern AI agents can perform dozens of tasks: from sending emails to managing chats. But often, connecting each service — Gmail, Telegram, Slack, or Trello — requires separate settings, tokens, and API keys. This slows down development and increases the risk of errors. The solution is a universal credential connector that unifies all services through a single interface. In this article, I will show you how to connect Gmail and Telegram to an AI agent in 10 minutes using standard credentials, and how this simplifies automation.

What is a Universal Credential Connector and Why Do You Need It?

A credential connector is a software bridge between an AI agent and external services. Instead of writing separate code for each API, you configure one module that stores and manages access keys (tokens, passwords, OAuth secrets). Advantages:
- Centralization — all credentials in one place.
- Security — automatic encryption and key rotation.
- Flexibility — easy to add a new service without rewriting the agent.

Step 1: Preparing Credentials for Gmail

For the AI to read and send emails, access to the Google API is required. Here's how to set it up:

  1. Create a project in Google Cloud Console
  2. Go to console.cloud.google.com
  3. Click "Create Project" and give it a name (e.g., "AI-Agent-Gmail").

  4. Enable the Gmail API

  5. In the menu, select "APIs & Services" → "Library".
  6. Find "Gmail API" and click "Enable".

  7. Set up OAuth 2.0 credentials

  8. Go to "Credentials" → "Create Credentials" → "OAuth client ID".
  9. Choose "Web application" as the type and specify the redirect URI (e.g., http://localhost:8080 for testing).
  10. Copy the Client ID and Client Secret.

  11. Generate an access token

  12. Use a library (e.g., google-auth for Python) to obtain a refresh token.
  13. Example command: gcloud auth application-default login.

Now you have credentials: Client ID, Client Secret, and Refresh Token. Save them in a secure storage.

Step 2: Setting Up Telegram via BotFather

Telegram bots do not require OAuth; an API token is sufficient. Algorithm:

  1. Create a bot
  2. Open Telegram and find @BotFather.
  3. Send the command /newbot and follow the instructions.
  4. After creation, you will receive an API Token (e.g., 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11).

  5. Configure permissions

  6. In BotFather, select /mybots → your bot → "Bot Settings" → "Group Privacy" → disable it so the bot can see all messages.
  7. To read notifications, add the bot to the necessary chats.

  8. Verify access

  9. Send the bot the /start command — it should respond.

Credentials for Telegram are simply the token itself.

Step 3: Integration via a Unified Connector

Now, combine both sets of credentials in one place. For example, let's take an open-source solution — Connector Hub (an analog may be built into your platform, e.g., asibiont.com).

  1. Install the connector
  2. If using Python: pip install connector-hub.
  3. Or add the module to your project.

  4. Create a configuration file (e.g., config.json):
    json { "services": { "gmail": { "client_id": "your-client-id", "client_secret": "your-client-secret", "refresh_token": "your-refresh-token" }, "telegram": { "api_token": "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11" } } }

  5. Connect the AI agent

  6. Import the connector and pass the credentials:
    ```python
    from connector_hub import Connector
    connector = Connector('config.json')
    # Now you can call methods:
    # connect

Conclusion

By using a unified credential connector, you can significantly simplify the process of connecting multiple services to an AI agent. This approach not only saves time but also enhances security and maintainability. Start integrating your Gmail and Telegram today and unlock the full potential of your AI automation.

← All posts

Comments