Skip to content

Commit 2499095

Browse files
committed
fix: support deleting on callback
1 parent 9aada1f commit 2499095

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

telegram/webhook_responder.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,28 @@ func (r tgWebhookResponder) DeleteMessage(ctx context.Context, messageID string)
3131
chatID := r.whc.chatID
3232
if chatID == "" {
3333
input := r.whc.Input()
34-
if tgInput, ok := input.(tgWebhookTextMessage); ok {
35-
if chat := tgInput.Chat(); chat != nil {
36-
chatID = chat.GetID()
37-
} else if tgInput.update.Message != nil {
38-
if tgInput.update.Message.Chat != nil && tgInput.update.Message.Chat.ID != 0 {
39-
chatID = strconv.FormatInt(tgInput.update.Message.Chat.ID, 10)
40-
}
34+
var chat botinput.WebhookChat
35+
if inputWithChat, ok := input.(interface{ Chat() botinput.WebhookChat }); ok {
36+
chat = inputWithChat.Chat()
37+
}
38+
if chat != nil {
39+
chatID = chat.GetID()
40+
} else {
41+
var message *tgbotapi.Message
42+
switch tgInput := input.(type) {
43+
case tgWebhookTextMessage:
44+
chat = tgInput.Chat()
45+
message = tgInput.update.Message
46+
case TgWebhookCallbackQuery:
47+
chat = tgInput.Chat()
48+
message = tgInput.update.Message
4149
}
50+
if message != nil && message.Chat != nil && message.Chat.ID != 0 {
51+
chatID = strconv.FormatInt(message.Chat.ID, 10)
52+
}
53+
}
54+
if chatID == "" && chat != nil {
55+
chatID = chat.GetID()
4256
}
4357
}
4458
if chatID == "" {

0 commit comments

Comments
 (0)