mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
feat: format message from telegram and upload attachments (#1924)
* feat: format message from telegram and download documents * fix: remove bool in expression * refactor: convert to markdown * refactor: resolve remarks and add support new message types * refactor: resolve remarks * feat: add test for mime type --------- Co-authored-by: Александр Тумайкин <AATumaykin@tsum.ru>
This commit is contained in:
committed by
GitHub
parent
f074bb1be2
commit
c5a1f4c839
@ -1,14 +1,26 @@
|
||||
package telegram
|
||||
|
||||
import "fmt"
|
||||
|
||||
type Message struct {
|
||||
MessageID int `json:"message_id"`
|
||||
From User `json:"from"`
|
||||
Date int `json:"date"`
|
||||
Text *string `json:"text"`
|
||||
Chat *Chat `json:"chat"`
|
||||
MediaGroupID *string `json:"media_group_id"`
|
||||
Photo []PhotoSize `json:"photo"`
|
||||
Caption *string `json:"caption"`
|
||||
MessageID int `json:"message_id"` // MessageID is a unique message identifier inside this chat
|
||||
From User `json:"from"` // From is a sender, empty for messages sent to channels;
|
||||
Date int `json:"date"` // Date of the message was sent in Unix time
|
||||
Text *string `json:"text"` // Text is for text messages, the actual UTF-8 text of the message, 0-4096 characters;
|
||||
Chat *Chat `json:"chat"` // Chat is the conversation the message belongs to
|
||||
ForwardFromChat *Chat `json:"forward_from_chat"` // ForwardFromChat for messages forwarded from channels, information about the original channel;
|
||||
ForwardFromMessageID int `json:"forward_from_message_id"` // ForwardFromMessageID for messages forwarded from channels, identifier of the original message in the channel;
|
||||
MediaGroupID *string `json:"media_group_id"` // MediaGroupID is the unique identifier of a media message group this message belongs to;
|
||||
Photo []PhotoSize `json:"photo"` // Photo message is a photo, available sizes of the photo;
|
||||
Caption *string `json:"caption"` // Caption for the animation, audio, document, photo, video or voice, 0-1024 characters;
|
||||
Entities []MessageEntity `json:"entities"` // Entities are for text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text;
|
||||
CaptionEntities []MessageEntity `json:"caption_entities"`
|
||||
Document *Document `json:"document"` // Document message is a general file, information about the file;
|
||||
Video *Video `json:"video"` // Video message is a video, information about the video;
|
||||
VideoNote *VideoNote `json:"video_note"` // VideoNote message is a video note, information about the video message;
|
||||
Voice *Voice `json:"voice"` // Voice message is a voice message, information about the file;
|
||||
Audio *Audio `json:"audio"` // Audio message is an audio file, information about the file;
|
||||
Animation *Animation `json:"animation"` // Animation message is an animation, information about the animation. For backward compatibility, when this field is set, the document field will also be set;
|
||||
}
|
||||
|
||||
func (m Message) GetMaxPhotoFileID() string {
|
||||
@ -22,3 +34,16 @@ func (m Message) GetMaxPhotoFileID() string {
|
||||
|
||||
return photoSize.FileID
|
||||
}
|
||||
|
||||
func (m Message) GetMessageLink() string {
|
||||
if m.ForwardFromChat != nil && m.ForwardFromChat.Type == Channel {
|
||||
return fmt.Sprintf("https://t.me/%s/%d", m.ForwardFromChat.UserName, m.ForwardFromMessageID)
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m Message) IsSupported() bool {
|
||||
return m.Text != nil || m.Caption != nil || m.Document != nil || m.Photo != nil || m.Video != nil ||
|
||||
m.Voice != nil || m.VideoNote != nil || m.Audio != nil || m.Animation != nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user