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 Summary
FieldsModifier and TypeFieldDescriptionprivate Stringprivate Stringprivate final IMessageSendServiceprivate TelegramMessageServiceprivate final TelegramRestServiceprivate final UidUtilsprivate final UploadRestServiceprivate final VisitorRestServiceFields inherited from interface org.telegram.telegrambots.longpolling.util.LongPollingSingleThreadUpdateConsumer
updatesProcessorExecutor -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate VisitorRequestbuildVisitorRequest(org.telegram.telegrambots.meta.api.objects.Update update, String text, TelegramEntity telegramEntity) 根据Telegram用户信息构建访客请求对象voidconsume(org.telegram.telegrambots.meta.api.objects.Update update) This method is called when an update is received.static TelegramDefaultConsumercreateInstance(TelegramRestService telegramRestService, VisitorRestService visitorRestService, IMessageSendService messageSendService, UidUtils uidUtils, UploadRestService uploadRestService) 创建TelegramDefaultConsumer实例的工厂方法获取当前消费者的bot tokenprivate org.telegram.telegrambots.meta.api.objects.PhotoSizegetPhoto(org.telegram.telegrambots.meta.api.objects.Update update) 获取消息中最大的照片private TelegramEntity根据当前bot token获取对应的Telegram配置private voidprocessAttachmentMessage(org.telegram.telegrambots.meta.api.objects.Update update, org.telegram.telegrambots.meta.api.objects.PhotoSize photo) 处理附件消息private voidprocessAudioMessage(org.telegram.telegrambots.meta.api.objects.Update update, org.telegram.telegrambots.meta.api.objects.Audio audio) 处理音频消息private voidprocessContactMessage(org.telegram.telegrambots.meta.api.objects.Update update, org.telegram.telegrambots.meta.api.objects.Contact contact) 处理联系人消息private voidprocessDocumentMessage(org.telegram.telegrambots.meta.api.objects.Update update, String fileId, String fileName, String mimeType) 处理文档消息private voidprocessLocationMessage(org.telegram.telegrambots.meta.api.objects.Update update, org.telegram.telegrambots.meta.api.objects.Location location) 处理位置消息private StringprocessMessageContentByType(org.telegram.telegrambots.meta.api.objects.Update update, String content, MessageTypeEnum messageType, TelegramExtra visitorExtra) 根据消息类型处理消息内容private voidprocessStickerMessage(org.telegram.telegrambots.meta.api.objects.Update update, String fileId) 处理贴纸消息private voidprocessVideoMessage(org.telegram.telegrambots.meta.api.objects.Update update, org.telegram.telegrambots.meta.api.objects.Video video) 处理视频消息private voidprocessVisitorMessage(TelegramEntity telegramEntity, org.telegram.telegrambots.meta.api.objects.Update update, String text) 处理访客消息,对接到微语系统中private voidprocessVoiceMessage(org.telegram.telegrambots.meta.api.objects.Update update, org.telegram.telegrambots.meta.api.objects.Voice voice) 处理语音消息private voidsendToCustomerService(org.telegram.telegrambots.meta.api.objects.Update update, String content, VisitorResponse visitor, ThreadProtobuf thread, TelegramEntity telegramEntity) 将Telegram访客消息发送给客服private voidsendToCustomerService(org.telegram.telegrambots.meta.api.objects.Update update, String content, VisitorResponse visitor, ThreadProtobuf thread, TelegramEntity telegramEntity, MessageTypeEnum messageType) 将Telegram访客消息发送给客服voidsetBotToken(String botToken, String orgUid) 设置当前消费者的bot tokenvoidsetTelegramMessageService(TelegramMessageService telegramMessageService) 设置TelegramMessageServiceMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.telegram.telegrambots.longpolling.util.LongPollingSingleThreadUpdateConsumer
consume
-
Field Details
-
telegramMessageService
-
telegramRestService
-
visitorRestService
-
messageSendService
-
uidUtils
-
uploadRestService
-
currentBotToken
-
currentOrgUid
-
-
Constructor Details
-
TelegramDefaultConsumer
public TelegramDefaultConsumer()
-
-
Method Details
-
setBotToken
设置当前消费者的bot token- Parameters:
botToken- bot token
-
getBotToken
获取当前消费者的bot token- Returns:
- bot token
-
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
设置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:
consumein interfaceorg.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
根据当前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- 文件IDfileName- 文件名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:
- 处理后的消息内容
-