go-telegram / bot

Telegram Bot API Go framework
MIT License
507 stars 46 forks source link

Cannot set SendPollParams.IsAnonymous to false #25

Closed srgustafson8 closed 1 year ago

srgustafson8 commented 1 year ago

You are unable to send a new poll that is non-anonymous. This seems to be because the IsAnonymous field on the SendPollParams type is a non-pointer bool, set to omitempty and defaults to true on the Telegram API. I believe this is why - false boolean is treated as empty and therefore omitted.

To reproduce

func main() {
    b, _ := bot.New(telegram_token)

    poll := &bot.SendPollParams{
        ChatID: chat_id,
        Question: "Test poll",
        Options: []string{"1", "2", "3"},
        AllowsMultipleAnswers: true,
        IsAnonymous: false,
    }

    msg, _ := b.SendPoll(context.TODO(), poll)
    log.Printf("Poll is anonymous?: %t", msg.Poll.IsAnonymous)
}
[stdout]
2023/04/08 20:10:20 Poll is anonymous?: true

I'll open a PR soon to set the type to be a *bool which I believe will fix it in this case.