From 4e3e3b9d85406419395481cc870897945f342877 Mon Sep 17 00:00:00 2001 From: Ivan Zuev Date: Fri, 28 Jan 2022 12:46:46 +0300 Subject: [PATCH] feat(telegram): command to get chat id --- bridge/telegram/handlers.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/bridge/telegram/handlers.go b/bridge/telegram/handlers.go index 80a7185c..73056a89 100644 --- a/bridge/telegram/handlers.go +++ b/bridge/telegram/handlers.go @@ -1,6 +1,7 @@ package btelegram import ( + "fmt" "html" "path/filepath" "strconv" @@ -15,8 +16,21 @@ import ( func (b *Btelegram) handleUpdate(rmsg *config.Message, message, posted, edited *tgbotapi.Message) *tgbotapi.Message { // handle channels if posted != nil { - message = posted - rmsg.Text = message.Text + if posted.Text == "/chatId" { + chatID := strconv.FormatInt(posted.Chat.ID, 10) + + _, err := b.Send(config.Message{ + Channel: chatID, + Text: fmt.Sprintf("ID of this chat: %s", chatID), + }) + + if err != nil { + b.Log.Warnf("Unable to send chatID to %s", chatID) + } + } else { + message = posted + rmsg.Text = message.Text + } } // edited channel message