agora.observe.polls

Matrix polls (MSC3381) — construction and response parsing.

Element ships first-class UI for MSC3381 polls. We post m.poll.start with a disclosed kind and a small list of options keyed by stable answer ids. Observers click an option in Element; Element emits m.poll.response events that we parse back into PollResponse structs.

Both the stable namespace (m.poll.*) and the unstable MSC3381 v1 namespace (org.matrix.msc3381.poll.*) are handled, because older Element builds still emit the unstable form.

Functions

build_decision_poll(question, options, ...)

Poll used by the planner to ask the user a blocking design question.

build_poll(question, options, *[, fallback_verb])

Construct an MSC3381 stable-schema poll event content.

build_review_poll(project_name, current_phase)

Produce the content payload for a review poll (5 fixed options).

new_poll_fallback_event_id()

For tests / fakes that need a placeholder poll event id.

parse_poll_response(event)

Parse an m.poll.response (or unstable equivalent).

review_poll_event_type()

The Matrix event type to use when sending the poll.

Classes

PollResponse

Parsed m.poll.response event.

class agora.observe.polls.PollResponse[source]

Bases: object

Parsed m.poll.response event.

poll_event_id: str
user_id: str
answer_id: str
raw_event_id: str
__init__(poll_event_id, user_id, answer_id, raw_event_id)
agora.observe.polls.build_poll(question, options, *, fallback_verb='review')[source]

Construct an MSC3381 stable-schema poll event content.

options is a list of (answer_id, label) tuples. fallback_verb controls the plaintext /agora <verb> <id> hint embedded in the top-level m.text fallback block (for clients without poll UI).

Conforms to the MSC3381 stable schema: answer ids use the m.id field, text blocks use m.text arrays with {mimetype, body} variants, kind is m.disclosed, and the top-level fallback is an m.text array (not a body``+``msgtype pair). The unstable org.matrix.msc3381.poll.start dual-emit is NOT produced — current Element ignores it and earlier drafts of our own emitter included non-spec custom keys that caused Element to render empty bubbles.

agora.observe.polls.build_review_poll(project_name, current_phase)[source]

Produce the content payload for a review poll (5 fixed options).

agora.observe.polls.build_decision_poll(question, options, decision_id)[source]

Poll used by the planner to ask the user a blocking design question.

decision_id is NOT stamped into the event content — some Element builds reject poll events with unknown top-level keys. Instead the tool-side code maintains a poll_event_id → decision_id map in the OrchestratorControl, so responses route cleanly without polluting the wire event.

agora.observe.polls.parse_poll_response(event)[source]

Parse an m.poll.response (or unstable equivalent). Returns None if the event is malformed or not actually a poll response.

agora.observe.polls.review_poll_event_type()[source]

The Matrix event type to use when sending the poll.

agora.observe.polls.new_poll_fallback_event_id()[source]

For tests / fakes that need a placeholder poll event id.