Sign inSign up

tmvdl/gemini-telegram

By tmvdl

Updated 11 months ago

Image
0

1.2K

tmvdl/gemini-telegram repository overview

Gemini on Telegram Bot

A lightweight Telegram bot powered by Google's Gemini 2.5 Flash AI model for intelligent conversational responses.

Quick Start

docker run -d \
  --name gemini-telegram-bot \
  -e GOOGLE_API_KEY=your_google_api_key \
  -e TELEGRAM_API_KEY=your_telegram_bot_token \
  tmvdl/gemini-telegram

Or use Docker Compose:

services:
  telegram-bot:
    image: tmvdl/gemini-telegram
    container_name: gemini-telegram-bot
    restart: unless-stopped
    environment:
      - GOOGLE_API_KEY=${GOOGLE_API_KEY}
      - TELEGRAM_API_KEY=${TELEGRAM_API_KEY}

Required Environment Variables

VariableDescriptionHow to Get
GOOGLE_API_KEYGoogle Gemini API keyGet from Google AI Studio
TELEGRAM_API_KEYTelegram bot tokenGet from @BotFather

Features

  • AI-Powered Conversations: Chat with Google's Gemini 2.5 Flash model through Telegram
  • Simple Command Interface: Use /gemini <message> to interact with the AI
  • Message Echo: Automatic echo responses for transparency
  • Lightweight: Built on Python 3.11-slim for minimal footprint
  • Auto-Restart: Configured to restart unless explicitly stopped

Usage

Once the bot is running and added to your Telegram:

  1. Start a conversation with your bot
  2. Use the /gemini command followed by your question or message:
/gemini What is the capital of France?
/gemini Explain quantum computing in simple terms
/gemini Write a haiku about coding

The bot will respond with AI-generated content from Google's Gemini model.

Example Docker Compose Setup

  1. Create a docker-compose.yml:
services:
  telegram-bot:
    image: tmvdl/gemini-telegram
    container_name: gemini-telegram-bot
    restart: unless-stopped
    environment:
      - GOOGLE_API_KEY=${GOOGLE_API_KEY}
      - TELEGRAM_API_KEY=${TELEGRAM_API_KEY}
    networks:
      - bot-network

networks:
  bot-network:
    driver: bridge
  1. Create a .env file with your credentials:
GOOGLE_API_KEY=your_google_api_key_here
TELEGRAM_API_KEY=your_telegram_bot_token_here
  1. Start the bot:
docker-compose up -d
  1. View logs:
docker-compose logs -f

Technology Stack

  • Python 3.11: Modern Python runtime
  • python-telegram-bot: Official Telegram Bot API wrapper
  • google-generativeai: Google's Gemini AI SDK
  • Docker: Containerized for easy deployment

Getting Your API Keys

Telegram Bot Token
  1. Open Telegram and search for @BotFather
  2. Send /newbot and follow the instructions
  3. Copy the API token provided
Google Gemini API Key
  1. Visit Google AI Studio
  2. Sign in with your Google account
  3. Create a new API key
  4. Copy the key for use in your environment variables

Container Details

  • Base Image: python:3.11-slim
  • Working Directory: /app
  • Exposed Ports: None (bot uses polling)
  • Restart Policy: unless-stopped

Security Notes

  • Never commit your API keys to version control
  • Use environment variables or Docker secrets for credentials
  • Regularly rotate your API keys
  • Monitor your bot's usage to detect unauthorized access

Troubleshooting

Bot not responding:

  • Verify both API keys are correct
  • Check container logs: docker logs gemini-telegram-bot
  • Ensure your Telegram bot is not already running elsewhere

Connection issues:

  • Verify internet connectivity
  • Check if your firewall allows outbound connections
  • Ensure Google AI API and Telegram API are accessible

Source Code

GitHub: tarsislimadev/gemini_on_telegram

Support

For issues, questions, or contributions, please visit the GitHub repository and open an issue.

License

This project is open source and available for educational purposes.

Tag summary

Content type

Image

Digest

sha256:c5bd2a0ea

Size

79.2 MB

Last updated

11 months ago

docker pull tmvdl/gemini-telegram