Closed erkinov-wtf closed 4 months ago
Hi! Apparently, that's intended behavior by the Telegram API: external replies (the ones made with the Reply in other chat options) are handled by Telegram as normal messages with a custom struct.
So, if you want to handle external replies, you might want to check for the ExternalReply
(type ExternalReplyInfo
) struct in Message
.
You can find more info about it here: https://core.telegram.org/bots/api#message:~:text=is%20a%20reply.-,external_reply,-ExternalReplyInfo https://core.telegram.org/bots/api#externalreplyinfo
Also, here's the ExternalReplyInfo
struct in Echotron's docs:
https://pkg.go.dev/github.com/NicoNex/echotron/v3#ExternalReplyInfo
Hi! Apparently, that's intended behavior by the Telegram API: external replies (the ones made with the Reply in other chat options) are handled by Telegram as normal messages with a custom struct.
So, if you want to handle external replies, you might want to check for the
ExternalReply
(typeExternalReplyInfo
) struct inMessage
.You can find more info about it here: https://core.telegram.org/bots/api#message:~:text=is%20a%20reply.-,external_reply,-ExternalReplyInfo https://core.telegram.org/bots/api#externalreplyinfo
Also, here's the
ExternalReplyInfo
struct in Echotron's docs: https://pkg.go.dev/github.com/NicoNex/echotron/v3#ExternalReplyInfo
aha it really is that. i tried to implement it but still cant do it fully, so it would be great if you would help me out here. so here's the func that decided what type of the message is:
func HandleMessage(api *echotron.API, message *echotron.Message, chatID int64, mediaGroupMap *map[string][]echotron.GroupableInputMedia, originalMessages *map[int64]int, mu *sync.Mutex) {
if message == nil {
fmt.Println("Received nil message")
return
}
switch {
case message.Text != "":
// If the message is a text, send it to the channel without sender information
sentMsg, err := api.SendMessage(message.Text, chatID, nil)
if err == nil && sentMsg.Result != nil {
mu.Lock()
(*originalMessages)[int64(message.ID)] = sentMsg.Result.ID
mu.Unlock()
} else {
fmt.Println("Error sending message or sentMsg.Result is nil:", err)
}
case message.Photo != nil:
// If the message is a photo, handle media group
media.HandleMediaGroup(api, message, chatID, mediaGroupMap, mu, types.Photo)
case message.Document != nil:
// If the message is a document, handle media group
media.HandleMediaGroup(api, message, chatID, mediaGroupMap, mu, types.Doc)
}
// Check if message.ReplyToMessage is nil before accessing it
if message.ExternalReply != nil {
fmt.Println(message.ExternalReply)
reply.HandleReplyMessage(api, message, chatID, originalMessages, mu)
}
// Reply to the user
handlers.ReplyMessage(api, message)
}
and here's HandleReplyMessage func:
func HandleReplyMessage(api *echotron.API, message *echotron.Message, chatID int64, originalMessages *map[int64]int, mu *sync.Mutex) {
mu.Lock()
originalMsgID, ok := (*originalMessages)[int64(message.ReplyToMessage.ID)]
mu.Unlock()
if ok {
externalReplyInfo := echotron.ExternalReplyInfo{
MessageID: originalMsgID,
Chat: echotron.Chat{
ID: chatID,
},
Origin: echotron.MessageOrigin{
Type: "channel",
Date: message.Date,
},
}
options := &echotron.MessageOptions{
ReplyParameters: echotron.ReplyParameters{
MessageID: originalMsgID,
ChatID: chatID,
},
ParseMode: echotron.MarkdownV2,
ExternalReplyInfo: &externalReplyInfo,
}
_, err := api.SendMessage(message.Text, chatID, options)
if err != nil {
// Log the error if sending the message fails
api.SendMessage("Error sending the external reply.", message.Chat.ID, nil)
}
} else {
// Handle case where the original message is not found
api.SendMessage("Original message not found.", message.Chat.ID, nil)
}
}
i tried to use externalreply strcut inside of the messageOptions but there is error saying no ExternalReplyInfo field (as expected). but SendMessage func only accepts MessageOptions struct so cant think how to proceeed.
Yeah, there's no external_reply_info
parameter for send_message
in the official API:
https://core.telegram.org/bots/api#sendmessage
I'm not really sure what you're trying to do here, can you please explain?
Yeah, there's no
external_reply_info
parameter forsend_message
in the official API: https://core.telegram.org/bots/api#sendmessageI'm not really sure what you're trying to do here, can you please explain?
okay, so users can send messages/photos/documents to the bot and bot then sends it to the channel. the idea is to ensure the anonymus comminication. currently it is working fine. but users want to reply messages sent to the channel. since users dont have access to the channel, i thought it would be possible for users to reply any messages via my bot by just using that "reply in another chat" feature
since users dont have access to the channel, i thought it would be possible for users to reply any messages via my bot by just using that "reply in another chat" feature
I'm not sure that's actually feasible, as far as I know a bot does not receive any kind of update when a message from the bot is answered in an external chat (I also just tested it, just to be sure).
I think you might want to implement a custom way to reply to messages through your bot for your use case.
hello folks, ive been creating a bot that will publish everything sent to the bot to the channel. the code was working fine until i noticed smth. when users want to reply to messages from channel and selecting reply in another chat option then choosing the bot to send, the messages is not showing the reply message, it is sending just a message. so i added debug messsages and indeed it is reply to message struct is nil. here's my part of code:
and here's the debug messages: