- Java telegram bot send audio
- Class SendAudio
- Field Summary
- Fields inherited from class org.telegram.telegrambots.api.methods.PartialBotApiMethod
- Constructor Summary
- Method Summary
- Methods inherited from class java.lang.Object
- Field Detail
- PATH
- DURATION_FIELD
- CHATID_FIELD
- AUDIO_FIELD
- REPLYTOMESSAGEID_FIELD
- DISABLENOTIFICATION_FIELD
- REPLYMARKUP_FIELD
- PERFOMER_FIELD
- TITLE_FIELD
- CAPTION_FIELD
- PARSEMODE_FIELD
- Constructor Detail
- SendAudio
- Method Detail
- getDuration
- setDuration
- getChatId
- setChatId
- setChatId
- getAudio
- setAudio
- setNewAudio
- setNewAudio
- getReplyToMessageId
- setReplyToMessageId
- getReplyMarkup
- setReplyMarkup
- getPerformer
- setPerformer
- getTitle
- setTitle
- getDisableNotification
- enableNotification
- disableNotification
- isNewAudio
- getAudioName
- getNewAudioFile
- getNewAudioStream
- getCaption
- setCaption
- getParseMode
- setParseMode
- deserializeResponse
- validate
- Java telegram bot send audio
- Class SendAudio
- Field Summary
- Fields inherited from class org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod
- Constructor Summary
- Method Summary
- Methods inherited from class java.lang.Object
- Field Detail
- PATH
- DURATION_FIELD
- CHATID_FIELD
- AUDIO_FIELD
- REPLYTOMESSAGEID_FIELD
- DISABLENOTIFICATION_FIELD
- REPLYMARKUP_FIELD
- PERFOMER_FIELD
- TITLE_FIELD
- CAPTION_FIELD
- PARSEMODE_FIELD
- THUMB_FIELD
- Constructor Detail
- SendAudio
- Method Detail
- getDuration
- setDuration
- getChatId
- setChatId
- setChatId
- getAudio
- setAudio
- setAudio
- setAudio
- setAudio
- getReplyToMessageId
- setReplyToMessageId
- getReplyMarkup
- setReplyMarkup
- getPerformer
- setPerformer
- getTitle
- setTitle
- getDisableNotification
- enableNotification
- disableNotification
- getCaption
- setCaption
- getParseMode
- setParseMode
- getThumb
- setThumb
- deserializeResponse
- validate
- toString
- Audio and Voice Messages
- Audio
- Voice
- Java telegram bot send audio
- Class SendAudio
- Field Summary
- Fields inherited from class org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod
- Constructor Summary
- Method Summary
- Methods inherited from class java.lang.Object
- Field Detail
- PATH
- DURATION_FIELD
- CHATID_FIELD
- AUDIO_FIELD
- REPLYTOMESSAGEID_FIELD
- DISABLENOTIFICATION_FIELD
- REPLYMARKUP_FIELD
- PERFOMER_FIELD
- TITLE_FIELD
- CAPTION_FIELD
- PARSEMODE_FIELD
- THUMB_FIELD
- Constructor Detail
- SendAudio
- Method Detail
- getDuration
- setDuration
- getChatId
- setChatId
- setChatId
- getAudio
- setAudio
- setAudio
- setAudio
- setAudio
- getReplyToMessageId
- setReplyToMessageId
- getReplyMarkup
- setReplyMarkup
- getPerformer
- setPerformer
- getTitle
- setTitle
- getDisableNotification
- enableNotification
- disableNotification
- getCaption
- setCaption
- getParseMode
- setParseMode
- getThumb
- setThumb
- deserializeResponse
- validate
- toString
- Java telegram bot send audio
- Class SendAudio
- Field Summary
- Fields inherited from class org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod
- Constructor Summary
- Method Summary
- Methods inherited from class java.lang.Object
- Field Detail
- PATH
- DURATION_FIELD
- CHATID_FIELD
- AUDIO_FIELD
- REPLYTOMESSAGEID_FIELD
- DISABLENOTIFICATION_FIELD
- REPLYMARKUP_FIELD
- PERFOMER_FIELD
- TITLE_FIELD
- CAPTION_FIELD
- PARSEMODE_FIELD
- THUMB_FIELD
- Constructor Detail
- SendAudio
- Method Detail
- getDuration
- setDuration
- getChatId
- setChatId
- setChatId
- getAudio
- setAudio
- setAudio
- setAudio
- setAudio
- getReplyToMessageId
- setReplyToMessageId
- getReplyMarkup
- setReplyMarkup
- getPerformer
- setPerformer
- getTitle
- setTitle
- getDisableNotification
- enableNotification
- disableNotification
- getCaption
- setCaption
- getParseMode
- setParseMode
- getThumb
- setThumb
- deserializeResponse
- validate
- toString
Java telegram bot send audio
Class SendAudio
Field Summary
Fields inherited from class org.telegram.telegrambots.api.methods.PartialBotApiMethod
Constructor Summary
Method Summary
Methods inherited from class java.lang.Object
Field Detail
PATH
DURATION_FIELD
CHATID_FIELD
AUDIO_FIELD
REPLYTOMESSAGEID_FIELD
DISABLENOTIFICATION_FIELD
public static final String DISABLENOTIFICATION_FIELD
REPLYMARKUP_FIELD
PERFOMER_FIELD
TITLE_FIELD
CAPTION_FIELD
PARSEMODE_FIELD
Constructor Detail
SendAudio
Method Detail
getDuration
setDuration
public SendAudio setDuration(Integer duration)
getChatId
setChatId
setChatId
getAudio
setAudio
setNewAudio
setNewAudio
public SendAudio setNewAudio(String audioName, InputStream inputStream)
getReplyToMessageId
setReplyToMessageId
public SendAudio setReplyToMessageId(Integer replyToMessageId)
getReplyMarkup
setReplyMarkup
public SendAudio setReplyMarkup(ReplyKeyboard replyMarkup)
getPerformer
setPerformer
public SendAudio setPerformer(String performer)
getTitle
setTitle
getDisableNotification
enableNotification
disableNotification
isNewAudio
public boolean isNewAudio()
getAudioName
getNewAudioFile
getNewAudioStream
getCaption
setCaption
getParseMode
setParseMode
public SendAudio setParseMode(String parseMode)
deserializeResponse
public Message deserializeResponse(String answer) throws TelegramApiRequestException
validate
Java telegram bot send audio
Class SendAudio
Field Summary
Fields inherited from class org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod
Constructor Summary
Method Summary
Methods inherited from class java.lang.Object
Field Detail
PATH
DURATION_FIELD
CHATID_FIELD
AUDIO_FIELD
REPLYTOMESSAGEID_FIELD
DISABLENOTIFICATION_FIELD
public static final String DISABLENOTIFICATION_FIELD
REPLYMARKUP_FIELD
PERFOMER_FIELD
TITLE_FIELD
CAPTION_FIELD
PARSEMODE_FIELD
THUMB_FIELD
Constructor Detail
SendAudio
Method Detail
getDuration
setDuration
public SendAudio setDuration(Integer duration)
getChatId
setChatId
setChatId
getAudio
setAudio
setAudio
setAudio
public SendAudio setAudio(String audioName, InputStream inputStream)
setAudio
getReplyToMessageId
setReplyToMessageId
public SendAudio setReplyToMessageId(Integer replyToMessageId)
getReplyMarkup
setReplyMarkup
public SendAudio setReplyMarkup(ReplyKeyboard replyMarkup)
getPerformer
setPerformer
public SendAudio setPerformer(String performer)
getTitle
setTitle
getDisableNotification
enableNotification
disableNotification
getCaption
setCaption
getParseMode
setParseMode
public SendAudio setParseMode(String parseMode)
getThumb
setThumb
deserializeResponse
public Message deserializeResponse(String answer) throws TelegramApiRequestException
validate
toString
Copyright © 2020. All rights reserved.
Audio and Voice Messages
These two types of messages are pretty similar. Audio is MP3-encoded file that can be played in music player. A voice file has OGG format and is not shown in music player.
Audio
This is the code to send an MP3 soundtrack. You might be wondering why some parameters are commented out? That’s because this MP3 file has metadata on it and Telegram does a good job at reading it.
Message message = await botClient.SendAudioAsync( chatId: chatId, audio: InputFile.FromUri("https://github.com/TelegramBots/book/raw/master/src/docs/audio-guitar.mp3"), /* performer: "Joel Thomas Hunger", title: "Fun Guitar and Ukulele", duration: 91, // in seconds */ cancellationToken: cancellationToken);
And a user can see the audio in Music Player:
Method returns an audio message. Let’s take a look at the value of message.Audio property in JSON format:
Voice
A voice message is an OGG audio file. Let’s send it differently this time by uploading the file from disk alongside with an HTTP request.
To run this example, download the NFL Commentary voice file to your disk.
A value is passed for duration because Telegram can’t figure that out from a file’s metadata.
⚠️ Replace /path/to/voice-nfl_commentary.ogg with an actual file path.
await using Stream stream = System.IO.File.OpenRead("/path/to/voice-nfl_commentary.ogg"); Message message = await botClient.SendVoiceAsync( chatId: chatId, voice: InputFile.FromStream(stream), duration: 36, cancellationToken: cancellationToken);
A voice message is returned from the method. Inspect the message.Voice property to learn more.
Java telegram bot send audio
Class SendAudio
Field Summary
Fields inherited from class org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod
Constructor Summary
Method Summary
Methods inherited from class java.lang.Object
Field Detail
PATH
DURATION_FIELD
CHATID_FIELD
AUDIO_FIELD
REPLYTOMESSAGEID_FIELD
DISABLENOTIFICATION_FIELD
public static final String DISABLENOTIFICATION_FIELD
REPLYMARKUP_FIELD
PERFOMER_FIELD
TITLE_FIELD
CAPTION_FIELD
PARSEMODE_FIELD
THUMB_FIELD
Constructor Detail
SendAudio
Method Detail
getDuration
setDuration
public SendAudio setDuration(Integer duration)
getChatId
setChatId
setChatId
getAudio
setAudio
setAudio
setAudio
public SendAudio setAudio(String audioName, InputStream inputStream)
setAudio
getReplyToMessageId
setReplyToMessageId
public SendAudio setReplyToMessageId(Integer replyToMessageId)
getReplyMarkup
setReplyMarkup
public SendAudio setReplyMarkup(ReplyKeyboard replyMarkup)
getPerformer
setPerformer
public SendAudio setPerformer(String performer)
getTitle
setTitle
getDisableNotification
enableNotification
disableNotification
getCaption
setCaption
getParseMode
setParseMode
public SendAudio setParseMode(String parseMode)
getThumb
setThumb
deserializeResponse
public Message deserializeResponse(String answer) throws TelegramApiRequestException
validate
toString
Copyright © 2020. All rights reserved.
Java telegram bot send audio
Class SendAudio
Field Summary
Fields inherited from class org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod
Constructor Summary
Method Summary
Methods inherited from class java.lang.Object
Field Detail
PATH
DURATION_FIELD
CHATID_FIELD
AUDIO_FIELD
REPLYTOMESSAGEID_FIELD
DISABLENOTIFICATION_FIELD
public static final String DISABLENOTIFICATION_FIELD
REPLYMARKUP_FIELD
PERFOMER_FIELD
TITLE_FIELD
CAPTION_FIELD
PARSEMODE_FIELD
THUMB_FIELD
Constructor Detail
SendAudio
Method Detail
getDuration
setDuration
public SendAudio setDuration(Integer duration)
getChatId
setChatId
setChatId
getAudio
setAudio
setAudio
setAudio
public SendAudio setAudio(String audioName, InputStream inputStream)
setAudio
getReplyToMessageId
setReplyToMessageId
public SendAudio setReplyToMessageId(Integer replyToMessageId)
getReplyMarkup
setReplyMarkup
public SendAudio setReplyMarkup(ReplyKeyboard replyMarkup)
getPerformer
setPerformer
public SendAudio setPerformer(String performer)
getTitle
setTitle
getDisableNotification
enableNotification
disableNotification
getCaption
setCaption
getParseMode
setParseMode
public SendAudio setParseMode(String parseMode)
getThumb
setThumb
deserializeResponse
public Message deserializeResponse(String answer) throws TelegramApiRequestException
validate
toString
Copyright © 2020. All rights reserved.