Files
TelegramBotAPI-examples/FSMBot
2026-05-07 17:18:24 +06:00
..
2025-08-11 15:56:20 +06:00
2021-10-18 20:21:58 +06:00
2026-05-07 17:18:24 +06:00

FSMBot

A demonstration of the Finite State Machine (FSM) pattern provided by the MicroUtils library.

Functionality

Implements a simple two-state FSM. After /start is sent, the bot enters ExpectContentOrStopState and re-sends every message it receives back to the user. This continues until the user sends /stop, at which point the FSM transitions to StopState and content forwarding ends.

Arguments

Position Value Description
1 BOT_TOKEN Telegram bot token

Optional arguments (any order after the token):

Value Description
debug Enable verbose debug logging
testServer Connect to the Telegram test server instead of production

Bot Commands

Command Description
/start Starts the FSM loop — bot begins echoing content back to the user
/stop Ends the FSM loop — bot stops echoing

Capabilities

  • Two-state FSM: ExpectContentOrStopStateStopState
  • ExpectContentOrStopState uses expectContentOrCommands() to filter messages
  • Erroneous FSM states are caught and handled gracefully
  • Runs via long polling

Launch

../gradlew run --args="BOT_TOKEN"