Bot class
Televerse This class is used to create a new bot instance. The bot instance is used to send and receive messages.
You can use the token to create a new bot instance. You can also pass a fetcher to the constructor. The fetcher is used to fetch updates from the Telegram servers. By default, the bot uses long polling to fetch updates. You can also use webhooks to fetch updates.
Create a new bot instance:
import 'package:televerse/televerse.dart';
void main() {
final bot = Bot("YOUR_BOT_TOKEN");
bot.start();
}
- Available Extensions
Constructors
- Bot(String token, {Fetcher? fetcher, String baseURL = RawAPI.defaultBase, APIScheme scheme = APIScheme.https, LoggerOptions? loggerOptions, Duration? timeout})
- Create a new bot instance.
- Bot.fromAPI(RawAPI api, {Fetcher? fetcher})
-
Constructs a Bot instance from the passed
RawAPI
instance. - Bot.local(String token, {Fetcher? fetcher, String baseURL = "localhost:8081", APIScheme scheme = APIScheme.http, LoggerOptions? loggerOptions, Duration? timeout})
-
Televerse local constructor. This constructor is used to create a bot instance that listens to a local Bot API server.
factory
Properties
- api → RawAPI
-
Raw API - gives you access to all the methods of Telegram Bot API.
no setter
- fetcher ↔ Fetcher
-
The fetcher - used to fetch updates from the Telegram servers.
latefinal
- hashCode → int
-
The hash code for this object.
no setterinherited
- initialized → bool
-
Whether the
Bot.me
is filledno setter - isLocal → bool
-
A flag that indicates whether the Bot API is running locally or not.
final
- me → User
-
Get information about the bot.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- timeout → Duration?
-
The timeout duration for the requests.
final
- token → String
-
The bot token.
final
-
updatesStream
→ Stream<
Update> -
Stream of
Update
objects.no setter
Methods
-
attachMenu(
→ void ) - Attach an Inline Menu.
-
callbackQuery(
Pattern data, Handler callback, {RegExp? regex, ScopeOptions? options}) → void - Registers a callback for a callback query.
-
chatJoinRequest(
ID chatId, Handler callback, {ScopeOptions? options}) → void - Registers a callback for the Update.chatJoinRequest events of the particular chat mentioned by the chatId.
-
chatMember(
Handler callback, {ChatMemberStatus? oldStatus, ChatMemberStatus? newStatus, ScopeOptions? options}) → void - Registers a callback for the Update.chatMember events.
-
chatType(
ChatType type, Handler callback, {ScopeOptions? options}) → void - Registers a callback for particular chat types. The callback will be called when a message is received that is from a chat of the specified type.
-
chatTypes(
List< ChatType> types, Handler callback, {ScopeOptions? options}) → void - Registers a callback for multiple chat types. The callback will be called when a message is received that is from one of the specified chat types.
-
chosenInlineResult(
Handler callback, {ScopeOptions? options}) → void - Registers a callback for the Update.chosenInlineResult events. The callback will be called when a chosen inline result is received.
-
command(
Pattern command, Handler callback, {ScopeOptions? options}) → void - Registers a callback for a command. The command must be without the leading slash.
-
entities(
List< MessageEntityType> types, Handler callback, {bool shouldMatchCaptionEntities = false, ScopeOptions? options}) → void - Registers a callback for messages that contains the specified entity types. The callback will be called when a message is received that contains the specified entity types.
-
entity(
MessageEntityType type, Handler callback, {bool shouldMatchCaptionEntities = false, ScopeOptions? options}) → void - Registers a callback for messages that contains the specified entity type.
-
filter(
bool predicate(Context ctx), Handler callback, {ScopeOptions? options}) → void - Registers a callback for a message that matches the specified filter.
-
getMe(
) → Future< User> - Get information about the bot.
-
handleUpdate(
Update update) → void - To manually handle updates without fetcher
-
hears(
RegExp exp, Handler callback, {ScopeOptions? options}) → void - Registers a callback for a message that contains a text that matches the specified regular expression. The callback will be called when a message is received that contains a text that matches the specified regular expression.
-
help(
Handler handler, {ScopeOptions? options}) → void -
Registers a callback for the
/help
command. -
inlineQuery(
Pattern query, Handler callback, {ScopeOptions? options}) → void - Registers a callback for inline queries.
-
myChatMember(
{required Handler callback, ChatMemberStatus? oldStatus, ChatMemberStatus? newStatus, ScopeOptions? options}) → void - Registers a callback for the Update.myChatMember events.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onAnimation(
Handler callback, {bool includeChannelPosts = false, bool onlyChannelPosts = false, ID? chatId, ScopeOptions? options}) → void - Registers a callback to be fired when an animation is sent
-
onAudio(
Handler callback, {bool includeChannelPosts = false, bool onlyChannelPosts = false, ID? chatId, ScopeOptions? options}) → void - Registers a callback for messages that contain an audio.
-
onBusinessConnection(
Handler callback, {ScopeOptions? options}) → void - Registers a callback to be fired when a connection of the bot with a business account is made.
-
onBusinessMessage(
Handler callback, {ScopeOptions? options}) → void - Registers callback to be fired when a new message is received in a business account connected to the bot.
-
onBusinessMessageDeleted(
Handler callback, {ScopeOptions? options}) → void - Registers a callback to be fired when a business message is deleted.
-
onBusinessMessageEdited(
Handler callback, {ScopeOptions? options}) → void - Registers a callback to be fired when a business message is edited.
-
onCallbackQuery(
Handler callback, {ScopeOptions? options}) → void - Registers a callback for all Callback Query updates
-
onCaption(
Handler callback, {bool includeChannelPosts = false, bool onlyChannelPosts = false, ID? chatId, ScopeOptions? options}) → void - Registers a callback to be fired when a message with caption is received.
-
onChannelPost(
Handler callback, {ScopeOptions? options}) → void - Registers a callback for all Channel Post updates
-
onChatBoosted(
Handler callback, {ScopeOptions? options}) → void - Registers a callback for when the chat was boosted.
-
onChatBoostRemoved(
Handler callback, {ScopeOptions? options}) → void - Registers a callback to be fired when the chat boost was removed.
-
onChatJoinRequest(
Handler callback, {ScopeOptions? options}) → void - Registers a callback for all Chat Join Request updates
-
onChatMember(
Handler callback, {ScopeOptions? options}) → void - Registers a callback for all Chat Member updates
- Registers a callback for a chat is shared to the bot
-
onChosenInlineResult(
Handler callback, {ScopeOptions? options}) → void - Registers a callback for all Chosen Inline Result updates
-
onCommand(
Handler callback, {bool includeChannelPosts = false, bool onlyChannelPosts = false, ID? chatId, ScopeOptions? options}) → void - Register a callback for any command.
-
onContact(
Handler callback, {ID? chatId, ScopeOptions? options}) → void - Registers a callback for messages that contain a contact.
-
onDeleteChatPhoto(
Handler callback, {ID? chatId, ScopeOptions? options}) → void - Registers a callback for delete chat photo service messages.
-
onDice(
Handler callback, {bool includeChannelPosts = false, bool onlyChannelPosts = false, ID? chatId, ScopeOptions? options}) → void - Registers a callback for messages that contain a dice.
-
onDocument(
Handler callback, {bool includeChannelPosts = false, bool onlyChannelPosts = false, ID? chatId, ScopeOptions? options}) → void - Registers a callback for messages that contain a document.
-
onEditedChannelPost(
Handler callback, {ScopeOptions? options}) → void - Registers a callback for all Edited Channel Post updates
-
onEditedMessage(
Handler callback, {ScopeOptions? options}) → void - Registers a callback for all Edited Message updates
-
onEmail(
Handler callback, {bool shouldMatchCaptionEntities = false, ScopeOptions? options}) → void - Sets up a callback for when a message with email is received.
-
onError(
void handler(BotError err)) → void - Registers a callback for any unexpected error.
-
onForumTopicClosed(
Handler callback, {ID? chatId, ScopeOptions? options}) → void - Registers a callback to be fired when a forum topic is closed
-
onForumTopicCreated(
Handler callback, {ID? chatId, ScopeOptions? options}) → void - Registers a callback to be fired when a forum topic is created
-
onForumTopicEdited(
Handler callback, {ID? chatId, ScopeOptions? options}) → void - Registers a callback to be fired when a forum topic is edited
-
onForumTopicReopened(
Handler callback, {ID? chatId, ScopeOptions? options}) → void - Registers a callback to be fired when a forum topic is reopened
-
onGame(
Handler callback, {bool includeChannelPosts = false, bool onlyChannelPosts = false, ID? chatId, ScopeOptions? options}) → void - Registers a callback for messages that contain a game.
-
onHashtag(
Handler callback, {bool shouldMatchCaptionEntities = false, String? hashtag, ScopeOptions? options}) → void - Sets up a callback for when a message with hashtag is received.
-
onInlineQuery(
Handler callback, {ScopeOptions? options}) → void - Registers a callback for all Inline Query updates
-
onLiveLocation(
Handler callback, {ID? chatId, ScopeOptions? options}) → void - Registers a callback for messages that is a live location update.
-
onLocation(
Handler callback, {bool includeChannelPosts = false, bool onlyChannelPosts = false, ID? chatId, ScopeOptions? options}) → void - Registers a callback for messages that contains a location.
-
onMention(
Handler callback, {String? username, int? userId, ScopeOptions? options}) → void -
Sets up a callback for when a mention is occurred.
Optionally, you can pass the
username
parameter oruserId
parameter to only receive updates for a specific user. -
onMessage(
Handler callback, {ScopeOptions? options}) → void - Registers a callback for all Message updates
-
onMessageReaction(
Handler callback, {ScopeOptions? options}) → void - Register a callback when a reaction to a message was changed by a user.
-
onMessageReactionCount(
Handler callback, {ScopeOptions? options}) → void - Reactions to a message with anonymous reactions were changed.
-
onMyChatMember(
Handler callback, {ScopeOptions? options}) → void - Registers a callback for all My Chat Member updates
-
onNewChatPhoto(
Handler callback, {bool includeChannelPosts = false, bool onlyChannelPosts = false, ID? chatId, ScopeOptions? options}) → void - Registers a callback for new chat photo service messages.
-
onNewChatTitle(
Handler callback, {bool includeChannelPosts = false, bool onlyChannelPosts = false, ID? chatId, ScopeOptions? options}) → void - Registers a callback for new chat title service messages.
-
onPhoneNumber(
Handler callback, {bool shouldMatchCaptionEntities = false, ScopeOptions? options}) → void - Sets up a callback for when a message with phone number is received.
-
onPhoto(
Handler callback, {bool includeChannelPosts = false, bool onlyChannelPosts = false, ID? chatId, ScopeOptions? options}) → void - Registers a callback for messages that contain a photo.
-
onPinnedMessage(
Handler callback, {bool includeChannelPosts = false, bool onlyChannelPosts = false, ID? chatId, ScopeOptions? options}) → void - Registers a callback for pinned message service messages.
-
onPoll(
Handler callback, {ScopeOptions? options}) → void - Registers a callback for all Poll updates
-
onPollAnswer(
Handler callback, {ScopeOptions? options}) → void - Registers a callback for all Poll Answer updates
-
onPollMessage(
Handler callback, {bool includeChannelPosts = false, bool onlyChannelPosts = false, ID? chatId, ScopeOptions? options}) → void - Registers a callback for messages that contain a poll.
-
onPreCheckoutQuery(
Handler callback, {ScopeOptions? options}) → void - Registers a callback for all Pre Checkout Query updates
-
onShippingQuery(
Handler callback, {ScopeOptions? options}) → void - Registers a callback for all Shipping Query updates
-
onSticker(
Handler callback, {bool includeChannelPosts = false, bool onlyChannelPosts = false, ID? chatId, ScopeOptions? options}) → void - Registers a callback for messages that contain a sticker.
-
onStop(
void callback()) → void - Registers a callback when the the bot is stopped.
-
onSuccessfulPayment(
Handler callback, {ScopeOptions? options}) → void - Registers a callback to be fired for all successful payments
-
onText(
Handler callback, {bool includeChannelPosts = false, bool onlyChannelPosts = false, ID? chatId, ScopeOptions? options}) → void - Registers a callback to be fired when a text message is received.
-
onURL(
Handler callback, {bool shouldMatchCaptionEntities = false, ScopeOptions? options}) → void - Sets up a callback for when a message with URL is received.
- Registers a callback for a user is shared to the bot
-
onVenue(
Handler callback, {bool includeChannelPosts = false, bool onlyChannelPosts = false, ID? chatId, ScopeOptions? options}) → void - Registers a callback for messages that contain a venue.
-
onVideo(
Handler callback, {bool includeChannelPosts = false, bool onlyChannelPosts = false, ID? chatId, ScopeOptions? options}) → void - Registers a callback for messages that contain a video.
-
onVideoNote(
Handler callback, {bool includeChannelPosts = false, bool onlyChannelPosts = false, ID? chatId, ScopeOptions? options}) → void - Registers a callback for messages that contain a video note.
-
onVoice(
Handler callback, {bool includeChannelPosts = false, bool onlyChannelPosts = false, ID? chatId, ScopeOptions? options}) → void - Registers a callback for messages that contain a voice note.
-
onWebAppData(
Handler callback, {ID? chatId, ScopeOptions? options}) → void - Registers a callback to be fired when data sent from a web app is received
-
poll(
Handler callback, {ScopeOptions? options}) → void - Registers a callback for the Update.poll events.
-
pollAnswer(
Handler callback, {String? pollId, ScopeOptions? options}) → void - Registers a callback for the Update.pollAnswer events.
-
preCheckoutQuery(
ChatID chatId, Handler callback, {ScopeOptions? options}) → void - Registers a callback for Pre Checkout Query events.
-
removeMenu(
→ void ) - Remove an Inline Menu.
-
removeScope(
String name) → bool - Removes an already added listener by name
-
setNextStep(
Message msg, Handler callback, ScopeOptions? options) → void - Next step handler
-
settings(
Handler handler, {ScopeOptions? options}) → void -
Registers a callback for the
/settings
command. -
shippingQuery(
ID chatId, Handler callback, {ScopeOptions? options}) → void - Registers a callback for Shipping Query events for the specified User.
-
start(
[Handler? handler, bool isServerless = false]) → Future< void> - Start polling for updates.
-
stop(
{bool shouldCloseHttpClient = true}) → Future< void> - Stop listening for updates.
-
text(
String text, Handler callback, {ScopeOptions? options}) → void - Registers a callback for a message that contains a text. The callback will be called when a message is received that contains a particular text.
-
toString(
) → String -
A string representation of this object.
inherited
-
whenMentioned(
Handler callback, {ScopeOptions? options}) → void - This method sets up a callback to be fired when the bot is mentioned.
-
whenReacted(
String emoji, Handler callback, {ScopeOptions? options}) → void - Registers a callback to be fired when a user reacts given emoji to a message.
-
whenVideoChatEnded(
Handler callback, {bool includeChannelPosts = false, bool onlyChannelPosts = false, ID? chatId, ScopeOptions? options}) → void - Registers a callback for a video chat is ended
-
whenVideoChatParticipantsInvited(
Handler callback, {ID? chatId, ScopeOptions? options}) → void - Registers a callback to be fired when new participants are invited to a video chat
-
whenVideoChatScheduled(
Handler callback, {bool includeChannelPosts = false, bool onlyChannelPosts = false, ID? chatId, ScopeOptions? options}) → void - Registers a callback for a video chat is scheduled
-
whenVideoChatStarted(
Handler callback, {bool includeChannelPosts = false, bool onlyChannelPosts = false, ID? chatId, ScopeOptions? options}) → void - Registers a callback for a video chat is started
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited