MCPcopy Index your code
hub / github.com/python-telegram-bot/python-telegram-bot / receive_poll_answer

Function receive_poll_answer

examples/pollbot.py:75–99  ·  view source on GitHub ↗

Summarize a users poll vote

(update: Update, context: ContextTypes.DEFAULT_TYPE)

Source from the content-addressed store, hash-verified

73
74
75async def receive_poll_answer(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
76 """Summarize a users poll vote"""
77 answer = update.poll_answer
78 answered_poll = context.bot_data[answer.poll_id]
79 try:
80 questions = answered_poll["questions"]
81 # this means this poll answer update is from an old poll, we can't do our answering then
82 except KeyError:
83 return
84 selected_options = answer.option_ids
85 answer_string = ""
86 for question_id in selected_options:
87 if question_id != selected_options[-1]:
88 answer_string += questions[question_id] + " and "
89 else:
90 answer_string += questions[question_id]
91 await context.bot.send_message(
92 answered_poll["chat_id"],
93 f"{update.effective_user.mention_html()} feels {answer_string}!",
94 parse_mode=ParseMode.HTML,
95 )
96 answered_poll["answers"] += 1
97 # Close poll after three participants voted
98 if answered_poll["answers"] == TOTAL_VOTER_COUNT:
99 await context.bot.stop_poll(answered_poll["chat_id"], answered_poll["message_id"])
100
101
102async def quiz(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:

Callers

nothing calls this directly

Calls 3

send_messageMethod · 0.45
mention_htmlMethod · 0.45
stop_pollMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…