telebot

Creator: coderz1093

Last updated:

0 purchases

TODO
Add to Cart

Description:

telebot

telebot #
中文版
telebot is a Telegram Bot API implementation for Dart, you can use this library
to execute Telegram Bot API by easy ways, see Telegram Bot API in Telegram Bot Document.


Install #
dependencies:
telebot: ^1.0.0
copied to clipboard
Imports #
import 'package:telebot/telebot.dart';
copied to clipboard
How to Create A Bot ? #
See here or follow steps below
Step 1. Add BotFather as Contact #
All Telegram Bot's action is by talking with BotFather to complete, so you need to browse
https://t.me/botfather to add BotFather as contact
Step 2. Talk with BotFather and Execute Command #
Open Telegram and find BotFather, then send any message to him, he will tell you all what can he do
Step 3. Create A New Bot #
Send /newbot to him and follow the steps, final you will create a bot
Step 4. Get API Token of Bot #
Send /mybots to him then choose your bot, then choose option API Token, final you will get token
How to Use telebot ? #
Create Bot #
var bot = TelegramBot.init("BOT_TOKEN");
copied to clipboard
Send Message #
var bot = TelegramBot.init("BOT_TOKEN");
bot.sendMessage(chateId: "CHAT_ID", text: "Hello World").then((Message messageResult){
// got result
}).catchError((error){
// handle error
});
copied to clipboard
or use async/await
var bot = TelegramBot("BOT_TOKEN");
Message messageResult = await bot.sendMessage(chateId: "CHAT_ID", text: "Hello World");
copied to clipboard
Other APIs #
All Telegram Bot API was implemented in telebot, see Telegram Bot Document.
Objects Field #
var bot = TelegramBot("BOT_TOKEN");
await bot.sendMessage(
chatId: "CHAT_ID",
text: "Choose One!",
replyMarkup: InlineKeyboardMarkup(
inlineKeyboard: [
[
InlineKeyboardButton(text: "Apple", callbackData: "1000"),
InlineKeyboardButton(text: "Banana", callbackData: "1001"),
]
],
),
);
copied to clipboard
InputFile or String Field #
Now telebot only support String url.
Run with Webhook #
Step 1. Initialize TelegramBot
var bot = TelegramBot.init(BOT_TOKEN);
copied to clipboard
Step 2. Listen Events
bot.onMessage((message)){
if(message.from.isBot) return;
message.reply("Hello! I'm a bot.");
}.onEditedMessage((message){
// do something
});
copied to clipboard
TelegramBot supported events



Event
Parameter




onUpdate
Update


onMessage
Message


onEditedMessage
Message


onChannelPost
Message


onEditedChannelPost
Message


onInlineQuery
InlineQuery


onChosenInlineResult
ChosenInlineResult


onCallbackQuery
CallbackQuery


onShippingQuery
ShippingQuery


onPreCheckoutQuery
PreCheckoutQuery


onPoll
Poll


onPollAnswer
PollAnswer



Step 3. Start Bot Server
bot.startServer(host: "YOUR SERVER HOST", port: SERVER_PORT);
copied to clipboard
Run Example #

Clone this project
git clone https://github.com/Arxing/dart-telebot.git
copied to clipboard

Edit example/env.dart and input BOT_TOKEN, SERVER_PORT and WEBHOOK_URL
Run example/update_webhook.dart to set bot's webhook url
dart ./example/update_webhook.dart
copied to clipboard

Run example/start_bot_server.dart to start listening
dart ./example/start_bot_server.dart
copied to clipboard

Now talk to your bot in Telegram, then it will reply you same message!

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.