From 7b90b8e4ae9c138f767641fbfa8ad700e8e27b55 Mon Sep 17 00:00:00 2001 From: Bohdan Horbeshko Date: Sat, 5 Feb 2022 11:33:53 -0500 Subject: [PATCH] Support poll messages --- telegram/utils.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/telegram/utils.go b/telegram/utils.go index 910bfd6..dbb65d7 100644 --- a/telegram/utils.go +++ b/telegram/utils.go @@ -489,6 +489,28 @@ func (c *Client) messageToText(message *client.Message) string { case client.TypeMessageDice: dice, _ := message.Content.(*client.MessageDice) return fmt.Sprintf("%s 1d6: [%v]", dice.Emoji, dice.Value) + case client.TypeMessagePoll: + poll, _ := message.Content.(*client.MessagePoll) + + rows := []string{} + rows = append(rows, fmt.Sprintf("*%s*", poll.Poll.Question)) + for _, option := range poll.Poll.Options { + var tick string + if option.IsChosen { + tick = "x" + } else { + tick = " " + } + rows = append(rows, fmt.Sprintf( + "[%s] %s | %v%% | %v vote", + tick, + option.Text, + option.VotePercentage, + option.VoterCount, + )) + } + + return strings.Join(rows, "\n") } return fmt.Sprintf("unknown message (%s)", message.Content.MessageContentType())