Skip to content

koctuk999/myTelegramBot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

My Telegram Bot

Telegram bot built with Kotlin and Spring Boot. It supports chat commands, scheduled messages, weather updates, and AI-assisted responses. Daily chat messages are stored in MongoDB, encrypted at rest, and cleared at 03:00.

Features

  • Telegram commands: help, cat, explain, weather, daily summary, and more
  • Scheduled posts: morning/evening messages and daily weather
  • AI integrations (DeepSeek) for styled replies and summaries
  • MongoDB persistence for chats and daily messages
  • AES-GCM encryption for stored daily messages
  • Telegram send safety: HTML escaping, chunked messages, and detailed API error logs

Tech Stack

  • Kotlin, Spring Boot
  • MongoDB (KMongo)
  • Kotlin Telegram Bot API
  • Retrofit + OkHttp

Configuration

Create application.yml (or use env vars). All keys are required.

spring:
  application:
    name: myTelegramBot
  data:
    mongodb:
      uri: mongodb://mongo:27017/bot
  config:
    import:
      - classpath:styles/cute.yml
      - classpath:styles/communist.yml
      - classpath:styles/chill.yml
      - classpath:styles/highrank.yml
      - classpath:styles/dusny.yml
      - classpath:styles/swear.yml

bot:
  token: BOT_TOKEN
  style: cute

group:
  name: GROUP_NAME

cat:
  api-key: CAT_API_KEY

deepseek:
  api-key: DEEPSEEK_API_KEY

weather:
  api-key: WEATHER_API_KEY

messages:
  encryption-key: CHANGE_ME_32_BYTES_KEY_123456789

Notes:

  • messages.encryption-key must be a Base64 string or a raw string of 16/24/32 bytes.
  • If you rotate the key, old stored messages will not decrypt.

Style Configuration

Styles are defined in separate files under src/main/resources/styles and include bot.styles.<name>.prompts and bot.styles.<name>.texts sections:

  • src/main/resources/styles/cute.yml
  • src/main/resources/styles/communist.yml
  • src/main/resources/styles/dusny.yml
  • src/main/resources/styles/swear.yml

Default style is bot.style in src/main/resources/application.yml (default cute). The available styles come from the list in spring.config.import. You can switch styles per chat via /style <name>.

Commands

  • /help - show available commands
  • /cat - random cat image
  • /translate - translate a replied message into the active style
  • /style <name> - change chat style (use without args to list)
  • /explain <question> - explain something in a child-friendly way
  • /today - day status (workday/holiday)
  • /tomorrow - day status for tomorrow
  • /weather <city> - weather in supported cities
  • /day - AI summary of messages for the day

Supported cities are listed in CityCoordinates.

Notes:

  • Long AI responses are split into multiple messages.
  • Photo captions over Telegram limits are sent as a follow-up message.

Scheduled Jobs

  • 03:00 - clear daily messages collection
  • 06:00 - morning greeting + day status
  • 08:00 - weather for supported cities
  • 19:00 - evening message + daily summary

Telegram Formatting and Limits

  • Messages are sent as HTML with basic escaping to avoid Telegram parse errors.
  • Text is split into chunks if it exceeds Telegram limits (4096 chars).
  • Photo captions are limited to 1024 chars; remaining text is sent as a follow-up message.

Running Locally

./gradlew bootRun

Tests

./gradlew test

Docker (Jib)

Build container image with Jib (uses env vars for registry credentials):

./gradlew jib

Encryption Key Generation

Generate a Base64 key:

openssl rand -base64 32

Project Structure

  • src/main/kotlin/.../config - bot wiring and Mongo config
  • src/main/kotlin/.../client - external APIs
  • src/main/kotlin/.../service - schedulers and shared services
  • src/main/kotlin/.../repository - Mongo collections
  • src/main/resources - application config and resources
  • src/main/resources/styles - per-style prompts and messages

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages