Package com.bytedesk.social.telegram
Class TelegramMessageService
java.lang.Object
com.bytedesk.social.telegram.TelegramMessageService
Telegram消息服务,处理发送各种类型消息的功能
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final org.telegram.telegrambots.meta.generics.TelegramClientprivate final UploadRestService -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic TelegramMessageServicecreateInstance(String botToken, UploadRestService uploadRestService) 创建TelegramMessageService实例的工厂方法downloadFileByFileId(String fileId, String botToken) 通过 file_id 下载 Telegram 文件(支持图片和文件),保留原始文件名downloadPhotoByFilePath(String filePath) 通过文件路径下载照片getFilePath(org.telegram.telegrambots.meta.api.objects.PhotoSize photoSize) 获取文件路径 https://core.telegram.org/bots/api#getfile https://core.telegram.org/bots/api#fileboolean发送音频(无附加信息)boolean发送音频booleansendCustomKeyboard(String chatId, String text) 发送自定义键盘booleansendDocument(String chatId, String documentUrl) 发送文档(无说明文字)booleansendDocument(String chatId, String documentUrl, String caption) 发送文档booleansendImageFromFileId(String fileId, String chatId) 通过文件ID发送图片booleansendImageFromUrl(String url, String chatId) 通过URL发送图片(无说明文字)booleansendImageFromUrl(String url, String chatId, String caption) 通过URL发送图片booleansendImageUploadingAFile(String filePath, String chatId) 上传文件并发送图片booleansendInlineKeyboard(String chatId, String text) 发送内联键盘booleansendSticker(String chatId, String stickerFileId) 发送贴纸booleansendTextMessage(String chatId, String text) 发送文本消息boolean发送视频(无说明文字)boolean发送视频boolean发送语音消息(无说明文字)boolean发送语音消息booleanshowChatAction(String chatId, String actionType) 显示聊天动作(如"正在输入")
-
Field Details
-
telegramClient
private final org.telegram.telegrambots.meta.generics.TelegramClient telegramClient -
uploadRestService
-
-
Constructor Details
-
TelegramMessageService
public TelegramMessageService()
-
-
Method Details
-
createInstance
public static TelegramMessageService createInstance(String botToken, UploadRestService uploadRestService) 创建TelegramMessageService实例的工厂方法- Parameters:
botToken- bot tokenuploadRestService- UploadRestService实例- Returns:
- TelegramMessageService实例
-
sendTextMessage
发送文本消息- Parameters:
chatId- 聊天IDtext- 消息文本- Returns:
- 是否发送成功
-
showChatAction
显示聊天动作(如"正在输入")- Parameters:
chatId- 聊天IDactionType- 动作类型- Returns:
- 是否发送成功
-
getFilePath
获取文件路径 https://core.telegram.org/bots/api#getfile https://core.telegram.org/bots/api#file- Parameters:
photoSize- 照片对象- Returns:
- 文件路径
-
downloadPhotoByFilePath
通过文件路径下载照片- Parameters:
filePath- 文件路径- Returns:
- 下载的文件
-
sendImageFromUrl
通过URL发送图片- Parameters:
url- 图片URLchatId- 聊天IDcaption- 图片说明(可选)- Returns:
- 是否发送成功
-
sendImageFromUrl
通过URL发送图片(无说明文字)- Parameters:
url- 图片URLchatId- 聊天ID- Returns:
- 是否发送成功
-
sendImageFromFileId
通过文件ID发送图片- Parameters:
fileId- 文件IDchatId- 聊天ID- Returns:
- 是否发送成功
-
sendImageUploadingAFile
上传文件并发送图片- Parameters:
filePath- 文件路径chatId- 聊天ID- Returns:
- 是否发送成功
-
sendSticker
发送贴纸- Parameters:
chatId- 聊天IDstickerFileId- 贴纸文件ID或URL- Returns:
- 是否发送成功
-
sendCustomKeyboard
发送自定义键盘- Parameters:
chatId- 聊天IDtext- 消息文本- Returns:
- 是否发送成功
-
sendInlineKeyboard
发送内联键盘- Parameters:
chatId- 聊天IDtext- 消息文本- Returns:
- 是否发送成功
-
downloadFileByFileId
通过 file_id 下载 Telegram 文件(支持图片和文件),保留原始文件名- Parameters:
fileId- 文件IDbotToken- 机器人Token- Returns:
- 下载后的文件对象(包含原始文件名,如果可用)
-
sendDocument
发送文档- Parameters:
chatId- 聊天IDdocumentUrl- 文档URL或文件IDcaption- 文档说明(可选)- Returns:
- 是否发送成功
-
sendDocument
发送文档(无说明文字)- Parameters:
chatId- 聊天IDdocumentUrl- 文档URL或文件ID- Returns:
- 是否发送成功
-
sendAudio
public boolean sendAudio(String chatId, String audioUrl, String caption, String title, String performer) 发送音频- Parameters:
chatId- 聊天IDaudioUrl- 音频URL或文件IDcaption- 音频说明(可选)title- 音频标题(可选)performer- 表演者(可选)- Returns:
- 是否发送成功
-
sendAudio
发送音频(无附加信息)- Parameters:
chatId- 聊天IDaudioUrl- 音频URL或文件ID- Returns:
- 是否发送成功
-
sendVideo
发送视频- Parameters:
chatId- 聊天IDvideoUrl- 视频URL或文件IDcaption- 视频说明(可选)- Returns:
- 是否发送成功
-
sendVideo
发送视频(无说明文字)- Parameters:
chatId- 聊天IDvideoUrl- 视频URL或文件ID- Returns:
- 是否发送成功
-
sendVoice
发送语音消息- Parameters:
chatId- 聊天IDvoiceUrl- 语音URL或文件IDcaption- 语音说明(可选)- Returns:
- 是否发送成功
-
sendVoice
发送语音消息(无说明文字)- Parameters:
chatId- 聊天IDvoiceUrl- 语音URL或文件ID- Returns:
- 是否发送成功
-