Skip to main content
Version: 0.0.5

Docker-Ready Producer Bot

The samples/producer-bot module provides a zero-code, Docker-ready Telegram bot that forwards every incoming update to Apache Kafka or RabbitMQ. It ships with two docker-compose files — one for each broker — so the only thing you need to provide is a Telegram bot token.

Full source: samples/producer-bot

What It Does

  • Receives updates from Telegram via long-polling (default) or webhook
  • Publishes each update as JSON to a Kafka topic or RabbitMQ exchange
  • Local @BotController handlers are never called (forward-only: true)
  • Works as a pure ingest gateway; downstream services handle all bot logic

Quick Start

Prerequisites

  • Docker and Docker Compose installed
  • A Telegram bot token from @BotFather

1. Clone and enter the module

git clone https://github.com/oson-code/easygram.git
cd easygram/samples/producer-bot

2. Create your .env file

cp .env.example .env
# Edit .env and set your bot token:
# easygram.token=1234567890:AAFxxxxxxxxxxxxxx

3. Start with Kafka

docker compose -f docker-compose.kafka.yml up

This starts:

  • Kafka (Bitnami KRaft — no ZooKeeper) on port 9092
  • Kafka UI at http://localhost:8090
  • Bot — long-polling, forwarding updates to topic easygram-updates

4. Start with RabbitMQ

docker compose -f docker-compose.rabbit.yml up

This starts:

  • RabbitMQ with management UI at http://localhost:15672 (user: rabbit, pass: rabbit)
  • Bot — long-polling, forwarding updates to exchange easygram-exchange

Configuration

All configuration is passed as Spring property names in the compose file's environment block. Override any value in your .env file.

Kafka Defaults

PropertyDefaultDescription
easygram.token(required)Bot API token from @BotFather
easygram.update.transportLONG_POLLINGUpdate source: LONG_POLLING or WEBHOOK
easygram.messaging.typePRODUCERBroker role
easygram.messaging.forward-onlytrueSkip local handlers
easygram.messaging.producer.typeKAFKABroker backend
easygram.messaging.kafka.topiceasygram-updatesTarget Kafka topic
spring.kafka.bootstrap-serverskafka:9092Kafka broker address (Docker service name)

RabbitMQ Defaults

PropertyDefaultDescription
easygram.token(required)Bot API token from @BotFather
easygram.update.transportLONG_POLLINGUpdate source
easygram.messaging.typePRODUCERBroker role
easygram.messaging.forward-onlytrueSkip local handlers
easygram.messaging.producer.typeRABBITBroker backend
easygram.messaging.rabbit.exchangeeasygram-exchangeTarget exchange
easygram.messaging.rabbit.queueeasygram-updatesQueue bound to exchange
easygram.messaging.rabbit.routing-keyeasygram.updatesRouting key
spring.rabbitmq.hostrabbitmqRabbitMQ host (Docker service name)
spring.rabbitmq.usernamerabbitRabbitMQ username
spring.rabbitmq.passwordrabbitRabbitMQ password

Advanced: Webhook as Update Source

To receive updates via webhook instead of long-polling, add these lines to your .env:

easygram.update.transport=WEBHOOK
easygram.update.webhook.url=https://your-domain.com/webhook
easygram.update.webhook.secret-token=your-webhook-secret

Then expose port 8080 in the compose file and configure your reverse proxy or TLS terminator.

Application Code

The application class contains no controllers — framework defaults handle everything:

@SpringBootApplication
public class ProducerBotApplication {
public static void main(String[] args) {
SpringApplication.run(ProducerBotApplication.class, args);
}
}

MDC Correlation Logging

The bot uses logback-spring.xml with MDC-aware patterns. Every log line for a given update automatically includes:

[upd:12345678] [chat:987654321] [uid:111222333] [transport:LONG_POLLING]

This makes it easy to trace a specific update through your logs when debugging.

Consuming the Updates

Use a Kafka or RabbitMQ consumer bot to process the forwarded updates. See:


See also: