ptgb
A complete Telegram Bot API client for Dart

FAQ

Why do I get “Bad state: No element” or a TypeError on the token?

This usually means .env wasn’t found or doesn’t contain the expected key. Confirm the file sits next to pubspec.yaml and contains a TOKEN=... line, or pass the token directly: Bot(token: '...'). See Configuration.

Can I use poll() and serveWebhook() at the same time?

No — Telegram only delivers updates through one channel at a time. Call deleteWebhook() before switching to polling, and setWebhook() (not poll()) when running a webhook server. See Polling vs. Webhooks.

Why does sendMessage (or similar) throw instead of returning an error object?

Every failed Bot API call throws TelegramApiException rather than returning a nullable/error result — this keeps the happy path free of null-checks. Catch it where you need to react to failures. See Error Handling.

Why are inline query results raw Maps instead of typed classes?

There are many inline result types (article, photo, gif, video, and more) with very different shapes, so typing all of them individually isn’t currently worth the API surface — this is intentional for now.

How do I call a Bot API method that doesn’t have a typed wrapper yet?

await bot.call('someNewMethod', {'param': 'value'});

See Bot.call in Core & Session.

Where do I find every method’s exact parameters?

The API Reference lists every typed Bot method, grouped by feature area, with its full signature and documentation.

What Dart SDK version do I need?

^3.5.0 or newer, per pubspec.yaml.