Files
lukaszraczylo 1ff26006f7 chore(examples): use api.Ptr for optional pointer fields
Replace the throwaway-local-var-then-take-address pattern with
api.Ptr in the polls and moderation examples. Net effect: 14 lines
gone, the pointer wrangling no longer steals visual focus from the
actual API call.
2026-05-09 18:20:00 +01:00
..
2026-05-09 13:09:27 +01:00

polls

Create polls and tally answers in real time via OnPollAnswer.

What it shows

  • api.SendPoll with []api.InputPollOption and IsAnonymous: false
  • router.OnPollAnswer to receive vote updates (PollAnswer.OptionIds, PollAnswer.User)
  • Concurrent-safe in-memory tally with sync.Mutex

Commands

Command Description
/poll <question> Creates a poll with four preset options (A/B/C/D)
/tally <poll_id> Shows current vote counts for a poll

Notes

  • OnPollAnswer only fires for non-anonymous polls. For anonymous polls, Telegram does not send user identifiers.
  • The poll ID is logged when the poll is created; copy it to use with /tally.
  • Vote tallies are in-memory and reset on restart.

Running

export TELEGRAM_BOT_TOKEN=123456:ABC...
go run ./examples/polls