Class TelegramDefaultConsumer

java.lang.Object
com.bytedesk.social.telegram.config.TelegramDefaultConsumer
All Implemented Interfaces:
org.telegram.telegrambots.longpolling.interfaces.LongPollingUpdateConsumer, org.telegram.telegrambots.longpolling.util.LongPollingSingleThreadUpdateConsumer

@Service public class TelegramDefaultConsumer extends Object implements org.telegram.telegrambots.longpolling.util.LongPollingSingleThreadUpdateConsumer
  • Field Details

  • Constructor Details

    • TelegramDefaultConsumer

      public TelegramDefaultConsumer()
  • Method Details

    • setBotToken

      public void setBotToken(String botToken, String orgUid)
      设置当前消费者的bot token
      Parameters:
      botToken - bot token
    • getBotToken

      public String getBotToken()
      获取当前消费者的bot token
      Returns:
      bot token
    • getOrgUid

      public String getOrgUid()
    • createInstance

      public static TelegramDefaultConsumer createInstance(TelegramRestService telegramRestService, VisitorRestService visitorRestService, IMessageSendService messageSendService, UidUtils uidUtils, UploadRestService uploadRestService)
      创建TelegramDefaultConsumer实例的工厂方法
      Parameters:
      telegramRestService - Telegram服务
      visitorRestService - 访客服务
      messageSendService - 消息发送服务
      uidUtils - UID工具
      uploadRestService - 上传服务
      Returns:
      TelegramDefaultConsumer实例
    • setTelegramMessageService

      public void setTelegramMessageService(TelegramMessageService telegramMessageService)
      设置TelegramMessageService
      Parameters:
      telegramMessageService - Telegram消息服务
    • consume

      public void consume(org.telegram.telegrambots.meta.api.objects.Update update)
      This method is called when an update is received. https://core.telegram.org/bots/api#update
      Specified by:
      consume in interface org.telegram.telegrambots.longpolling.util.LongPollingSingleThreadUpdateConsumer
      Parameters:
      update - the update received from Telegram
    • getPhoto

      private org.telegram.telegrambots.meta.api.objects.PhotoSize getPhoto(org.telegram.telegrambots.meta.api.objects.Update update)
      获取消息中最大的照片
      Parameters:
      update - 更新对象
      Returns:
      最大的照片对象
    • processVisitorMessage

      private void processVisitorMessage(TelegramEntity telegramEntity, org.telegram.telegrambots.meta.api.objects.Update update, String text)
      处理访客消息,对接到微语系统中
      Parameters:
      update - Telegram更新对象
      text - 文本消息内容
    • getTelegramEntityByBotToken

      private TelegramEntity getTelegramEntityByBotToken()
      根据当前bot token获取对应的Telegram配置
      Returns:
      Telegram配置实体
    • processAttachmentMessage

      private void processAttachmentMessage(org.telegram.telegrambots.meta.api.objects.Update update, org.telegram.telegrambots.meta.api.objects.PhotoSize photo)
      处理附件消息
      Parameters:
      update - Telegram更新对象
      photo - 照片对象
    • processDocumentMessage

      private void processDocumentMessage(org.telegram.telegrambots.meta.api.objects.Update update, String fileId, String fileName, String mimeType)
      处理文档消息
      Parameters:
      update - Telegram更新对象
      fileId - 文件ID
      fileName - 文件名
      mimeType - MIME类型
    • processStickerMessage

      private void processStickerMessage(org.telegram.telegrambots.meta.api.objects.Update update, String fileId)
      处理贴纸消息
      Parameters:
      update - Telegram更新对象
      fileId - 贴纸文件ID
    • processVideoMessage

      private void processVideoMessage(org.telegram.telegrambots.meta.api.objects.Update update, org.telegram.telegrambots.meta.api.objects.Video video)
      处理视频消息
      Parameters:
      update - Telegram更新对象
      video - 视频对象
    • processAudioMessage

      private void processAudioMessage(org.telegram.telegrambots.meta.api.objects.Update update, org.telegram.telegrambots.meta.api.objects.Audio audio)
      处理音频消息
      Parameters:
      update - Telegram更新对象
      audio - 音频对象
    • processVoiceMessage

      private void processVoiceMessage(org.telegram.telegrambots.meta.api.objects.Update update, org.telegram.telegrambots.meta.api.objects.Voice voice)
      处理语音消息
      Parameters:
      update - Telegram更新对象
      voice - 语音对象
    • processLocationMessage

      private void processLocationMessage(org.telegram.telegrambots.meta.api.objects.Update update, org.telegram.telegrambots.meta.api.objects.Location location)
      处理位置消息
      Parameters:
      update - Telegram更新对象
      location - 位置对象
    • processContactMessage

      private void processContactMessage(org.telegram.telegrambots.meta.api.objects.Update update, org.telegram.telegrambots.meta.api.objects.Contact contact)
      处理联系人消息
      Parameters:
      update - Telegram更新对象
      contact - 联系人对象
    • buildVisitorRequest

      private VisitorRequest buildVisitorRequest(org.telegram.telegrambots.meta.api.objects.Update update, String text, TelegramEntity telegramEntity)
      根据Telegram用户信息构建访客请求对象
      Parameters:
      update - Telegram更新对象
      text - 文本消息
      telegramEntity - Telegram配置实体
      Returns:
      访客请求对象
    • sendToCustomerService

      private void sendToCustomerService(org.telegram.telegrambots.meta.api.objects.Update update, String content, VisitorResponse visitor, ThreadProtobuf thread, TelegramEntity telegramEntity)
      将Telegram访客消息发送给客服
      Parameters:
      update - Telegram更新对象
      content - 消息内容
      visitor - 访客信息
      thread - 会话信息
      telegramEntity - Telegram配置实体
    • sendToCustomerService

      private void sendToCustomerService(org.telegram.telegrambots.meta.api.objects.Update update, String content, VisitorResponse visitor, ThreadProtobuf thread, TelegramEntity telegramEntity, MessageTypeEnum messageType)
      将Telegram访客消息发送给客服
      Parameters:
      update - Telegram更新对象
      content - 消息内容
      visitor - 访客信息
      thread - 会话信息
      telegramEntity - Telegram配置实体
      messageType - 消息类型
    • processMessageContentByType

      private String processMessageContentByType(org.telegram.telegrambots.meta.api.objects.Update update, String content, MessageTypeEnum messageType, TelegramExtra visitorExtra)
      根据消息类型处理消息内容
      Parameters:
      update - Telegram更新对象
      content - 原始消息内容
      messageType - 消息类型
      visitorExtra - Telegram额外信息
      Returns:
      处理后的消息内容