From dfbbb03073519942a6b16bbcb1aebbddbb500d72 Mon Sep 17 00:00:00 2001 From: sphantix Date: Tue, 2 Apr 2024 22:08:12 +0800 Subject: [PATCH 1/2] feat: add topic message --- configs.go | 2 ++ helpers.go | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/configs.go b/configs.go index 1831337b..9b6f194d 100644 --- a/configs.go +++ b/configs.go @@ -265,6 +265,7 @@ func (CloseConfig) params() (Params, error) { // BaseChat is base type for all chat config types. type BaseChat struct { ChatID int64 // required + ThreadID int // optional ChannelUsername string ProtectContent bool ReplyToMessageID int @@ -278,6 +279,7 @@ func (chat *BaseChat) params() (Params, error) { params.AddFirstValid("chat_id", chat.ChatID, chat.ChannelUsername) params.AddNonZero("reply_to_message_id", chat.ReplyToMessageID) + params.AddNonZero("message_thread_id", chat.ThreadID) params.AddBool("disable_notification", chat.DisableNotification) params.AddBool("allow_sending_without_reply", chat.AllowSendingWithoutReply) params.AddBool("protect_content", chat.ProtectContent) diff --git a/helpers.go b/helpers.go index 3a0e8187..18ec5d4e 100644 --- a/helpers.go +++ b/helpers.go @@ -25,6 +25,21 @@ func NewMessage(chatID int64, text string) MessageConfig { } } +// NewTopicMessage creates a new Message which will be sent to a topic thread. +// +// chatID is where to send it, topicID is the topic thread id, text is the message text. +func NewTopicMessage(chatID int64, topicID int, text string) MessageConfig { + return MessageConfig{ + BaseChat: BaseChat{ + ChatID: chatID, + ThreadID: topicID, + ReplyToMessageID: 0, + }, + Text: text, + DisableWebPagePreview: false, + } +} + // NewDeleteMessage creates a request to delete a message. func NewDeleteMessage(chatID int64, messageID int) DeleteMessageConfig { return DeleteMessageConfig{ From aa5cbfe417d625b425772a80334126bf26a1bcc7 Mon Sep 17 00:00:00 2001 From: sphantix Date: Sat, 18 May 2024 08:02:02 +0800 Subject: [PATCH 2/2] feat: support message thread id in Message got from server --- types.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/types.go b/types.go index 36c174b8..9235a888 100644 --- a/types.go +++ b/types.go @@ -361,6 +361,8 @@ func (c Chat) ChatConfig() ChatConfig { type Message struct { // MessageID is a unique message identifier inside this chat MessageID int `json:"message_id"` + // Optional. Unique identifier of a message thread to which the message belongs; for supergroups only + MessageThreadID int `json:"message_thread_id"` // From is a sender, empty for messages sent to channels; // // optional