dart-telegram-bot
Telegram ボット API のシンプルな純粋ラッパー
- スター
- 29
- フォーク
- 8
- 最終プッシュ(UTC)
- 2025/01/02
- プロジェクト状態
- 公開中
元の README
以下は英語原文のスナップショットです。最新版は GitHub をご覧ください。
Dart Telegram Bot ![Dart CI/CD]()
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)
言語Dart
カテゴリー
使用している依存関係
プロジェクトに合うリポジトリを選ぶには?
用途で絞り込み、開発状況を比較し、採用前に元のリポジトリで要件を確認しましょう。
- 名前・作者・説明で検索し、技術トピックで絞り込みます。
- スター、フォーク、最近のプッシュを比較します。スターは関心の目安であり、品質の保証ではありません。
- 利用前に GitHub で README、ライセンス、Issues を確認します。
情報源と管理
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗