Telegram bots
Run a Go Telegram bot with gotgbot, long polling, secure credentials, and a single active consumer.
Create a bot and protect its token
Section titled “Create a bot and protect its token”Create a bot through Telegram’s verified @BotFather account and obtain its token. Add TELEGRAM_BOT_TOKEN to the application’s Deplexo environment variables. Use the exact variable name expected by the starter.
The token grants control of the bot. Never commit it, paste it into public issues, or log request URLs that contain it. If exposed, revoke or regenerate it through BotFather and redeploy with the replacement.
Run long polling as a worker
Section titled “Run long polling as a worker”A polling bot connects outward to Telegram and waits for updates. It does not need a public HTTP endpoint or a custom domain. The gotgbot polling starter uses a worker service and runs until it receives a termination signal.
Keep one active polling consumer per token. Stop the local development process before deploying the same bot, and remove any existing Telegram webhook before switching that token to polling. A webhook and getUpdates polling cannot be used simultaneously.
framework: dockerfiledockerfile: Dockerfile
Verify a real conversation
Section titled “Verify a real conversation”After deployment, check runtime logs for successful startup. Open the bot in Telegram and send /start, or the command documented by the starter. Verify its response rather than relying only on the application’s running status.
Authentication failures usually indicate a wrong or revoked token. A getUpdates conflict often means another process or a configured webhook is consuming updates. Group message visibility also depends on Telegram’s privacy settings and the bot’s permissions.
Handle restarts and stored state
Section titled “Handle restarts and stored state”Stop polling on termination and allow in-flight handlers to finish. Keep handlers safe to retry when they write external state. Network reconnects and application restarts are normal events for a long-running bot.
In-memory state disappears on restart. Store important user settings or job state in an external database or a file in the persistent mount. If using SQLite, keep the database and journal files on the writable mount and maintain backups.
When to use a webhook
Section titled “When to use a webhook”A Telegram webhook bot is an HTTP service with a reachable HTTPS endpoint. It needs request validation, including Telegram’s webhook secret header when configured, and prompt responses to avoid unnecessary retries.
Changing only the service type does not turn a polling starter into a webhook bot. The application must implement a webhook handler and register its URL with Telegram. Keep that as a deliberate application change.
Check the bot rather than its assigned URL
Section titled “Check the bot rather than its assigned URL”Deplexo currently performs a port check for all applications. A polling or Gateway bot has no HTTP listener, so startup may include a port warning before completing. Confirm that the bot responds in your test chat or server and inspect its logs. Do not add a dummy HTTP server just to make the assigned URL load.