public abstract class TelegramBot
extends java.lang.Object
| Constructor and Description |
|---|
TelegramBot(java.lang.String botToken)
Constructs a TelegramBot using the provided
botToken. |
| Modifier and Type | Method and Description |
|---|---|
Message |
forwardMessage(int chatId,
int fromChatId,
int messageId)
Forwards a message with ID
messageId from fromChatId to chatId. |
User |
getMe()
A simple method for testing your bot's auth token.
|
UserProfilePhotos |
getUserProfilePhotos(int userId) |
UserProfilePhotos |
getUserProfilePhotos(int userId,
OptionalArgs optionalArgs)
Returns a
UserProfilePhotos for a user. |
protected void |
notifyNewMessage(Message message)
This method is called by this class to process all new
Messages . |
void |
notifyNewUpdate(Update update)
This method is called by another class to process all new
Updates asynchronously. |
protected void |
onMessage(Message message)
This method is called when a new message has arrived.
|
protected void |
onStart() |
protected void |
onStop() |
Message |
replyTo(Message message,
java.lang.String text)
Convenience method for
sendMessage(message.getChat().getId(), text, new OptionalArgs().replyToMessageId(message.getMessageId())) |
Message |
sendAudio(int chatId,
java.io.File audioFile) |
Message |
sendAudio(int chatId,
java.io.File audioFile,
OptionalArgs optionalArgs)
Use this method to send audio files, if you want Telegram clients to display the file as a music playable with the internal player.
|
Message |
sendAudio(int chatId,
java.lang.String audioFileId) |
Message |
sendAudio(int chatId,
java.lang.String audioFileId,
OptionalArgs optionalArgs)
This version takes a file id instead of a
File, as a String argument. |
java.lang.Boolean |
sendChatAction(int chatId,
ChatAction chatAction)
Use this method when you need to tell the user that something is happening on the bot's side.
|
Message |
sendDocument(int chatId,
java.io.File documentFile) |
Message |
sendDocument(int chatId,
java.io.File documentFile,
OptionalArgs optionalArgs)
Use this method to send general files.
|
Message |
sendDocument(int chatId,
java.lang.String documentFileId) |
Message |
sendDocument(int chatId,
java.lang.String documentFileId,
OptionalArgs optionalArgs)
This version takes a file id instead of a
File. |
Message |
sendLocation(int chatId,
float latitude,
float longitude) |
Message |
sendLocation(int chatId,
float latitude,
float longitude,
OptionalArgs optionalArgs)
Use this method to send point on the map.
|
Message |
sendMessage(int chatId,
java.lang.String text) |
Message |
sendMessage(int chatId,
java.lang.String text,
OptionalArgs optionalArgs)
Use this method to send text messages.
|
Message |
sendPhoto(int chatId,
java.io.File photoFile) |
Message |
sendPhoto(int chatId,
java.io.File photoFile,
OptionalArgs optionalArgs)
Use this method to send photos.
|
Message |
sendPhoto(int chatId,
java.lang.String photoFileId) |
Message |
sendPhoto(int chatId,
java.lang.String photoFileId,
OptionalArgs optionalArgs)
This version takes a file id instead of a
File |
Message |
sendSticker(int chatId,
java.io.File stickerFile) |
Message |
sendSticker(int chatId,
java.io.File stickerFile,
OptionalArgs optionalArgs)
Use this method to send .webp stickers.
|
Message |
sendSticker(int chatId,
java.lang.String stickerFileId) |
Message |
sendSticker(int chatId,
java.lang.String stickerFileId,
OptionalArgs optionalArgs)
This version takes a file id instead of a
File. |
Message |
sendVideo(int chatId,
java.io.File videoFile) |
Message |
sendVideo(int chatId,
java.io.File videoFile,
OptionalArgs optionalArgs)
Use this method to send video files,
Telegram clients support mp4 videos (other formats may be sent as Document (
sendDocument(int, File, OptionalArgs))). |
Message |
sendVideo(int chatId,
java.lang.String videoFileId) |
Message |
sendVideo(int chatId,
java.lang.String videoFileId,
OptionalArgs optionalArgs)
This version uses a file id rather than a
File |
void |
start()
Starts the bot.
|
void |
stop()
Stops the bot.
|
public TelegramBot(java.lang.String botToken)
botToken.botToken - The token provided by @BotFatherpublic final void start()
protected void onStart()
public final void stop()
protected void onStop()
public final Message forwardMessage(int chatId, int fromChatId, int messageId)
messageId from fromChatId to chatId.chatId - Unique identifier for the message recipient — Chat idfromChatId - Unique identifier for the chat where the original message was sent — Chat idmessageId - Unique message identifierMessagepublic final User getMe()
Userpublic final UserProfilePhotos getUserProfilePhotos(int userId)
public final UserProfilePhotos getUserProfilePhotos(int userId, OptionalArgs optionalArgs)
UserProfilePhotos for a user.
For any optional arguments, refer to the Telegram documentation.userId - Unique identifier of the target useroptionalArgs - Any optional arguments for this methodUserProfilePhotosOptionalArgspublic final Message sendAudio(int chatId, java.io.File audioFile)
sendAudio(int, File, OptionalArgs)public final Message sendAudio(int chatId, java.io.File audioFile, OptionalArgs optionalArgs)
chatId - Unique identifier for the message recipient - Chat id or Channel UsernameaudioFile - Audio File to sendoptionalArgs - Any optional arguments for this methodMessagepublic final Message sendAudio(int chatId, java.lang.String audioFileId)
sendAudio(int, String, OptionalArgs)public final Message sendAudio(int chatId, java.lang.String audioFileId, OptionalArgs optionalArgs)
File, as a String argument.sendAudio(int, File, OptionalArgs)public final java.lang.Boolean sendChatAction(int chatId,
ChatAction chatAction)
chatId - Unique identifier for the message recipient - Chat id or Channel UsernamechatAction - The target ChatActionpublic final Message sendDocument(int chatId, java.io.File documentFile)
sendAudio(int, File, OptionalArgs)public final Message sendDocument(int chatId, java.io.File documentFile, OptionalArgs optionalArgs)
chatId - Unique identifier for the message recipient - Chat id or Channel UsernamedocumentFile - File to sendoptionalArgs - Any optional argumentsMessagepublic final Message sendDocument(int chatId, java.lang.String documentFileId)
public final Message sendDocument(int chatId, java.lang.String documentFileId, OptionalArgs optionalArgs)
File.public final Message sendLocation(int chatId, float latitude, float longitude)
public final Message sendLocation(int chatId, float latitude, float longitude, OptionalArgs optionalArgs)
chatId - Unique identifier for the message recipient - Chat id or Channel Usernamelatitude - Latitude of locationlongitude - Longitude of locationoptionalArgs - Any optional argumentsMessagepublic final Message sendMessage(int chatId, java.lang.String text)
public final Message sendMessage(int chatId, java.lang.String text, OptionalArgs optionalArgs)
chatId - Unique identifier for the message recipient - Chat id or Channel Usernametext - Text of the message to be sentoptionalArgs - Any optional argumentsMessagepublic final Message sendPhoto(int chatId, java.io.File photoFile)
sendPhoto(int, File, OptionalArgs)public final Message sendPhoto(int chatId, java.io.File photoFile, OptionalArgs optionalArgs)
chatId - Unique identifier for the message recipient - Chat id or Channel UsernamephotoFile - Photo to sendoptionalArgs - Any optional argumentsMessagepublic final Message sendPhoto(int chatId, java.lang.String photoFileId)
sendPhoto(int, String, OptionalArgs)public final Message sendPhoto(int chatId, java.lang.String photoFileId, OptionalArgs optionalArgs)
FilesendPhoto(int, File, OptionalArgs)public final Message sendSticker(int chatId, java.io.File stickerFile)
sendSticker(int, File, OptionalArgs)public final Message sendSticker(int chatId, java.io.File stickerFile, OptionalArgs optionalArgs)
chatId - Unique identifier for the message recipient - Chat id or Channel UsernamestickerFile - Sticker to send.optionalArgs - Any optional argumentsMessagepublic final Message sendSticker(int chatId, java.lang.String stickerFileId)
public final Message sendSticker(int chatId, java.lang.String stickerFileId, OptionalArgs optionalArgs)
File.sendSticker(int, File, OptionalArgs)public final Message sendVideo(int chatId, java.io.File videoFile)
sendVideo(int, File, OptionalArgs)public final Message sendVideo(int chatId, java.io.File videoFile, OptionalArgs optionalArgs)
sendDocument(int, File, OptionalArgs))).
Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future.
For any optional arguments, refer to the Telegram documentation.chatId - Unique identifier for the message recipient - Chat id or Channel UsernamevideoFile - Video to sendoptionalArgs - Any optional arguments.Messagepublic final Message sendVideo(int chatId, java.lang.String videoFileId)
sendVideo(int, File, OptionalArgs)public final Message sendVideo(int chatId, java.lang.String videoFileId, OptionalArgs optionalArgs)
FilesendVideo(int, File, OptionalArgs)public final Message replyTo(Message message, java.lang.String text)
sendMessage(message.getChat().getId(), text, new OptionalArgs().replyToMessageId(message.getMessageId()))protected void onMessage(Message message)
message - The newly arrived Messageprotected void notifyNewMessage(Message message)
Messages .message - The newly arrived Message