KaikyuLotus/dart-telegram-bot
A simple pure wrapper for Telegram bot API
go to github downloadDart Telegram Bot ![Dart CI/CD](https://github.com/KaikyuLotus/dart-telegram-bot/actions/workflows/dart-dev.yml/badge.svg)
Dart Telegram Bot is a Dart wrapper for Telegram
bot API.
It is compatible with Native, Flutter and JS.
Using Dart Telegram Bot is straightforward, here’s an example echo bot:
import 'package:dart_telegram_bot/dart_telegram_bot.dart';
import 'package:dart_telegram_bot/telegram_entities.dart';
void main() {
Bot(
// Insert your bot token here
token: 'BOT_TOKEN',
// Once the bot is ready this function will be called
// You can start the bot here
onReady: (bot) => bot.start(clean: true),
// Register a new callback for new updates
).onUpdate((bot, update) async {
// Send a message to the update chat with the received message
bot.sendMessage(ChatID(update.message!.chat.id), update.message!.text!);
});
}
Bot start may fail when bot token is invalid or with network issues.
To handle such cases follow the next example:
void main() {
Bot(
token: 'BOT_TOKEN',
onReady: (bot) => bot.start(clean: true),
// Handle start failure
onStartFailed: (bot, e, s) => print('Start failed'),
);
}
Also, you may want to disable or allow only certain update types.
To do so follow the next example:
void main() {
Bot(
token: 'BOT_TOKEN',
onReady: (bot) => bot.start(clean: true),
// Either allow all types but some
allowedUpdates: UpdateType.allBut([UpdateType.channelPost]),
// OR allow only a list of types
allowedUpdates: [UpdateType.message, UpdateType.editedMessage],
);
}
Dart Telegram Bot also supports a more OOP approach.
The following example is still an echo bot, this time with OOP approach:
class MyBot extends Bot {
MyBot() : super(token: 'BOT_TOKEN') {
onUpdate(updateHandler);
}
@override
Future onReady(Bot bot) => bot.start(clean: true);
@override
Future onStartFailed(Bot bot, Object err, StackTrace st) async {
print('Bot failed to start: $err');
}
Future updateHandler(Bot bot, Update update) async {
bot.sendMessage(ChatID(update.message!.chat.id), update.message!.text!);
}
}
Written by Kaikyu Lotus (Telegram)
![](/images/banner-woo.jpg)
excellent projects related to KaikyuLotus/dart-telegram-bot recommend downloading
localsend
33797
An open-source cross-platform alternative to AirDrop
gsy_github_app_flutter
14559
Flutter 超完整的开源项目,功能丰富,适合学习和日常使用。GSYGithubApp系列的优势:我们目前已经拥有Flutter、Weex、ReactNative、kotlin 四个版本。 功能齐全,项目框架内技术涉及面广,完成度高,持续维护,配套文章,适合全面学习,对比参考。跨平台的开源Github客户端App,更好的体验,更丰富的功能,旨在更好的日常管理和维护个人Github,提供更好更方便的驾车体验Σ( ̄。 ̄ノ)ノ。同款Weex版本 : https://github.com/CarGuo/GSYGithubAppWeex 、同款React Native版本 : https://github.com/CarGuo/GSYGithubApp 、原生 kotlin 版本 https://github.com/CarGuo/GSYGithubAppKotlin
dio
12249
A powerful HTTP client for Dart and Flutter, which supports global settings, Interceptors, FormData, aborting and canceling a request, files uploading and downloading, requests timeout, custom adapters, etc.
bloc
11441
A predictable state management library that helps implement the BLoC design pattern
getx
9899
Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
flame
8846
A Flutter based game engine.
flutter_deer
7595
🦌 Flutter 练习项目(包括集成测试、可访问性测试)。内含完整UI设计图,更贴近真实项目的练习。Flutter practice project (including integration testing and accessibility testing). Contains complete UI design drawings for a more realistic practice project.
riverpod
5828
A reactive caching and data-binding framework. Riverpod makes working with asynchronous code a breeze.
provider
5029
InheritedWidgets, but simple
getwidget
4416
Most popular and easy to use open source UI library with 1000+ Widgets to build flutter app.
fvm
4325
Flutter Version Management: A simple CLI to manage Flutter SDK versions.
pilipala
4003
PiliPala 是使用Flutter开发的BiliBili第三方客户端,感谢使用。
flutter_screenutil
3787
Flutter screen adaptation, font adaptation, get screen information
flutter_rust_bridge
3608
Flutter/Dart <-> Rust binding generator, feature-rich, but seamless and simple.
isar
3366
Extremely fast, easy to use, and fully async NoSQL database for Flutter
bruno
3126
An enterprise-class package of Flutter components for mobile applications. ( Bruno 是基于一整套设计体系的 Flutter 组件库。)
flutter_staggered_grid_view
3043
A Flutter staggered grid view
flutter_hooks
3030
React hooks for Flutter. Hooks are a new kind of object that manages a Widget life-cycles. They are used to increase code sharing between widgets and as a complete replacement for StatefulWidget.
flutter_spinkit
2945
✨ A collection of loading indicators animated with flutter. Heavily Inspired by http://tobiasahlin.com/spinkit.
PicaComic
2877
A comic app built with Flutter, supporting multiple comic sources.