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(long chatId,
long fromChatId,
long 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(long userId) |
UserProfilePhotos |
getUserProfilePhotos(long 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(long chatId,
java.io.File audioFile) |
Message |
sendAudio(long 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(long chatId,
java.lang.String audioFileId) |
Message |
sendAudio(long 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(long chatId,
ChatAction chatAction)
Use this method when you need to tell the user that something is happening on the bot's side.
|
Message |
sendDocument(long chatId,
java.io.File documentFile) |
Message |
sendDocument(long chatId,
java.io.File documentFile,
OptionalArgs optionalArgs)
Use this method to send general files.
|
Message |
sendDocument(long chatId,
java.lang.String documentFileId) |
Message |
sendDocument(long chatId,
java.lang.String documentFileId,
OptionalArgs optionalArgs)
This version takes a file id instead of a
File. |
Message |
sendLocation(long chatId,
float latitude,
float longitude) |
Message |
sendLocation(long chatId,
float latitude,
float longitude,
OptionalArgs optionalArgs)
Use this method to send point on the map.
|
Message |
sendMessage(long chatId,
java.lang.String text) |
Message |
sendMessage(long chatId,
java.lang.String text,
OptionalArgs optionalArgs)
Use this method to send text messages.
|
Message |
sendMessage(java.lang.String channelUsername,
java.lang.String text) |
Message |
sendMessage(java.lang.String chatId,
java.lang.String text,
OptionalArgs optionalArgs) |
Message |
sendPhoto(long chatId,
java.io.File photoFile) |
Message |
sendPhoto(long chatId,
java.io.File photoFile,
OptionalArgs optionalArgs)
Use this method to send photos.
|
Message |
sendPhoto(long chatId,
java.lang.String photoFileId) |
Message |
sendPhoto(long chatId,
java.lang.String photoFileId,
OptionalArgs optionalArgs)
This version takes a file id instead of a
File |
Message |
sendSticker(long chatId,
java.io.File stickerFile) |
Message |
sendSticker(long chatId,
java.io.File stickerFile,
OptionalArgs optionalArgs)
Use this method to send .webp stickers.
|
Message |
sendSticker(long chatId,
java.lang.String stickerFileId) |
Message |
sendSticker(long chatId,
java.lang.String stickerFileId,
OptionalArgs optionalArgs)
This version takes a file id instead of a
File. |
Message |
sendVideo(long chatId,
java.io.File videoFile) |
Message |
sendVideo(long 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(long, File, OptionalArgs))). |
Message |
sendVideo(long chatId,
java.lang.String videoFileId) |
Message |
sendVideo(long chatId,
java.lang.String videoFileId,
OptionalArgs optionalArgs)
This version uses a file id rather than a
File |
boolean |
setWebHook(java.lang.String servletAddress)
set the webhook of the bot.
|
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(long chatId, long fromChatId, long 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(long userId)
public final UserProfilePhotos getUserProfilePhotos(long 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(long chatId, java.io.File audioFile)
sendAudio(long, File, OptionalArgs)public final Message sendAudio(long 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(long chatId, java.lang.String audioFileId)
public final Message sendAudio(long chatId, java.lang.String audioFileId, OptionalArgs optionalArgs)
File, as a String argument.sendAudio(long, File, OptionalArgs)public final java.lang.Boolean sendChatAction(long chatId,
ChatAction chatAction)
chatId - Unique identifier for the message recipient - Chat id or Channel UsernamechatAction - The target ChatActionpublic final Message sendDocument(long chatId, java.io.File documentFile)
sendAudio(long, File, OptionalArgs)public final Message sendDocument(long 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(long chatId, java.lang.String documentFileId)
public final Message sendDocument(long chatId, java.lang.String documentFileId, OptionalArgs optionalArgs)
File.public final Message sendLocation(long chatId, float latitude, float longitude)
public final Message sendLocation(long 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(long chatId, java.lang.String text)
public final Message sendMessage(java.lang.String channelUsername, java.lang.String text)
public final Message sendMessage(long 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 sendMessage(java.lang.String chatId, java.lang.String text, OptionalArgs optionalArgs)
sendPhoto(long, File, OptionalArgs)public final Message sendPhoto(long chatId, java.io.File photoFile)
sendPhoto(long, File, OptionalArgs)public final Message sendPhoto(long 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(long chatId, java.lang.String photoFileId)
public final Message sendPhoto(long chatId, java.lang.String photoFileId, OptionalArgs optionalArgs)
FilesendPhoto(long, File, OptionalArgs)public final Message sendSticker(long chatId, java.io.File stickerFile)
public final Message sendSticker(long 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(long chatId, java.lang.String stickerFileId)
public final Message sendSticker(long chatId, java.lang.String stickerFileId, OptionalArgs optionalArgs)
File.public final Message sendVideo(long chatId, java.io.File videoFile)
sendVideo(long, File, OptionalArgs)public final Message sendVideo(long chatId, java.io.File videoFile, OptionalArgs optionalArgs)
sendDocument(long, 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(long chatId, java.lang.String videoFileId)
sendVideo(long, File, OptionalArgs)public final Message sendVideo(long chatId, java.lang.String videoFileId, OptionalArgs optionalArgs)
FilesendVideo(long, File, OptionalArgs)public final Message replyTo(Message message, java.lang.String text)
sendMessage(message.getChat().getId(), text, new OptionalArgs().replyToMessageId(message.getMessageId()))public final boolean setWebHook(java.lang.String servletAddress)
servletAddress - address of the servlet that handles the requestsprotected void onMessage(Message message)
message - The newly arrived Messageprotected void notifyNewMessage(Message message)
Messages .message - The newly arrived Message