Class TelegramMessageService

java.lang.Object
com.bytedesk.social.telegram.TelegramMessageService

@Service public class TelegramMessageService extends Object
Telegram消息服务,处理发送各种类型消息的功能
  • Field Details

    • telegramClient

      private final org.telegram.telegrambots.meta.generics.TelegramClient telegramClient
    • uploadRestService

      private final UploadRestService uploadRestService
  • Constructor Details

    • TelegramMessageService

      public TelegramMessageService()
  • Method Details

    • createInstance

      public static TelegramMessageService createInstance(String botToken, UploadRestService uploadRestService)
      创建TelegramMessageService实例的工厂方法
      Parameters:
      botToken - bot token
      uploadRestService - UploadRestService实例
      Returns:
      TelegramMessageService实例
    • sendTextMessage

      public boolean sendTextMessage(String chatId, String text)
      发送文本消息
      Parameters:
      chatId - 聊天ID
      text - 消息文本
      Returns:
      是否发送成功
    • showChatAction

      public boolean showChatAction(String chatId, String actionType)
      显示聊天动作(如"正在输入")
      Parameters:
      chatId - 聊天ID
      actionType - 动作类型
      Returns:
      是否发送成功
    • getFilePath

      public String getFilePath(org.telegram.telegrambots.meta.api.objects.PhotoSize photoSize)
      获取文件路径 https://core.telegram.org/bots/api#getfile https://core.telegram.org/bots/api#file
      Parameters:
      photoSize - 照片对象
      Returns:
      文件路径
    • downloadPhotoByFilePath

      public File downloadPhotoByFilePath(String filePath)
      通过文件路径下载照片
      Parameters:
      filePath - 文件路径
      Returns:
      下载的文件
    • sendImageFromUrl

      public boolean sendImageFromUrl(String url, String chatId, String caption)
      通过URL发送图片
      Parameters:
      url - 图片URL
      chatId - 聊天ID
      caption - 图片说明(可选)
      Returns:
      是否发送成功
    • sendImageFromUrl

      public boolean sendImageFromUrl(String url, String chatId)
      通过URL发送图片(无说明文字)
      Parameters:
      url - 图片URL
      chatId - 聊天ID
      Returns:
      是否发送成功
    • sendImageFromFileId

      public boolean sendImageFromFileId(String fileId, String chatId)
      通过文件ID发送图片
      Parameters:
      fileId - 文件ID
      chatId - 聊天ID
      Returns:
      是否发送成功
    • sendImageUploadingAFile

      public boolean sendImageUploadingAFile(String filePath, String chatId)
      上传文件并发送图片
      Parameters:
      filePath - 文件路径
      chatId - 聊天ID
      Returns:
      是否发送成功
    • sendSticker

      public boolean sendSticker(String chatId, String stickerFileId)
      发送贴纸
      Parameters:
      chatId - 聊天ID
      stickerFileId - 贴纸文件ID或URL
      Returns:
      是否发送成功
    • sendCustomKeyboard

      public boolean sendCustomKeyboard(String chatId, String text)
      发送自定义键盘
      Parameters:
      chatId - 聊天ID
      text - 消息文本
      Returns:
      是否发送成功
    • sendInlineKeyboard

      public boolean sendInlineKeyboard(String chatId, String text)
      发送内联键盘
      Parameters:
      chatId - 聊天ID
      text - 消息文本
      Returns:
      是否发送成功
    • downloadFileByFileId

      public File downloadFileByFileId(String fileId, String botToken)
      通过 file_id 下载 Telegram 文件(支持图片和文件),保留原始文件名
      Parameters:
      fileId - 文件ID
      botToken - 机器人Token
      Returns:
      下载后的文件对象(包含原始文件名,如果可用)
    • sendDocument

      public boolean sendDocument(String chatId, String documentUrl, String caption)
      发送文档
      Parameters:
      chatId - 聊天ID
      documentUrl - 文档URL或文件ID
      caption - 文档说明(可选)
      Returns:
      是否发送成功
    • sendDocument

      public boolean sendDocument(String chatId, String documentUrl)
      发送文档(无说明文字)
      Parameters:
      chatId - 聊天ID
      documentUrl - 文档URL或文件ID
      Returns:
      是否发送成功
    • sendAudio

      public boolean sendAudio(String chatId, String audioUrl, String caption, String title, String performer)
      发送音频
      Parameters:
      chatId - 聊天ID
      audioUrl - 音频URL或文件ID
      caption - 音频说明(可选)
      title - 音频标题(可选)
      performer - 表演者(可选)
      Returns:
      是否发送成功
    • sendAudio

      public boolean sendAudio(String chatId, String audioUrl)
      发送音频(无附加信息)
      Parameters:
      chatId - 聊天ID
      audioUrl - 音频URL或文件ID
      Returns:
      是否发送成功
    • sendVideo

      public boolean sendVideo(String chatId, String videoUrl, String caption)
      发送视频
      Parameters:
      chatId - 聊天ID
      videoUrl - 视频URL或文件ID
      caption - 视频说明(可选)
      Returns:
      是否发送成功
    • sendVideo

      public boolean sendVideo(String chatId, String videoUrl)
      发送视频(无说明文字)
      Parameters:
      chatId - 聊天ID
      videoUrl - 视频URL或文件ID
      Returns:
      是否发送成功
    • sendVoice

      public boolean sendVoice(String chatId, String voiceUrl, String caption)
      发送语音消息
      Parameters:
      chatId - 聊天ID
      voiceUrl - 语音URL或文件ID
      caption - 语音说明(可选)
      Returns:
      是否发送成功
    • sendVoice

      public boolean sendVoice(String chatId, String voiceUrl)
      发送语音消息(无说明文字)
      Parameters:
      chatId - 聊天ID
      voiceUrl - 语音URL或文件ID
      Returns:
      是否发送成功