Skip to content

Conversation

@dahlia
Copy link
Member

@dahlia dahlia commented Jun 30, 2025

Implements #7 by adding comprehensive poll functionality:

  • Add Poll and Vote interfaces for type definitions
  • Add Session.publish() overload with Question class support
  • Add Bot.onVote event handler for processing poll votes
  • Add comprehensive unit tests for poll creation and voting
  • Add documentation for poll publishing and vote handling
  • Support both single-choice and multiple-choice polls
  • Implement vote counting with Update activity broadcasting
  • Handle edge cases: expired polls, invalid options, author votes

dahlia and others added 3 commits June 30, 2025 11:26
Implements #7
by adding comprehensive poll functionality:

- Add Poll and Vote interfaces for type definitions
- Add Session.publish() overload with Question class support
- Add Bot.onVote event handler for processing poll votes
- Add comprehensive unit tests for poll creation and voting
- Add documentation for poll publishing and vote handling
- Support both single-choice and multiple-choice polls
- Implement vote counting with Update activity broadcasting
- Handle edge cases: expired polls, invalid options, author votes

Co-Authored-By: Claude <noreply@anthropic.com>
Adds a new example demonstrating how to implement one-time passcode
authentication using BotKit's poll functionality. The example creates
an emoji-based 2FA system where users authenticate by voting for
matching emojis in a direct message poll.

Co-Authored-By: Claude <noreply@anthropic.com>
@dahlia dahlia requested a review from Copilot June 30, 2025 09:03
@dahlia dahlia self-assigned this Jun 30, 2025
@dahlia dahlia added the enhancement New feature or request label Jun 30, 2025
@dahlia dahlia linked an issue Jun 30, 2025 that may be closed by this pull request
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @dahlia, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the BotKit library by introducing comprehensive poll functionality. Bots can now programmatically create and publish polls, handle incoming votes, and automatically update poll results, opening up new interactive possibilities for bot developers on the Fediverse. This includes new interfaces, an event handler for votes, and an updated publishing mechanism, all supported by new tests and documentation.

Highlights

  • New Poll Functionality: Introduces core interfaces (Poll, Vote) and an event handler (Bot.onVote) to enable bots to create and manage polls, and react to user votes.
  • Poll Publishing: Extends Session.publish() to allow bots to create single-choice or multiple-choice polls with specified options and end times, represented as ActivityPub Question objects.
  • Vote Processing & Updates: Implements logic to process incoming votes on bot-authored polls, update poll option counts, and broadcast these updates across the Fediverse using ActivityPub Update activities. It also handles edge cases like votes from the poll author, expired polls, and invalid options.
  • Comprehensive Testing & Documentation: Includes new unit tests covering various poll and voting scenarios, along with updated documentation for both poll creation and vote handling, providing clear examples and API details.
  • New Example Application: Adds an 'One-time passcode authentication bot' example (otp.tsx) demonstrating practical use of the new poll features for secure, emoji-based authentication within the Fediverse.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link

github-actions bot commented Jun 30, 2025

Test Results

  1 files    9 suites   5m 1s ⏱️
178 tests 178 ✅ 0 💤 0 ❌
235 runs  235 ✅ 0 💤 0 ❌

Results for commit 4eae51f.

♻️ This comment has been updated with latest results.

@codecov
Copy link

codecov bot commented Jun 30, 2025

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment

Thanks for integrating Codecov - We've got you covered ☂️

This comment was marked as outdated.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces comprehensive poll and voting functionality. The changes are well-structured, with new interfaces, event handlers, and extensive documentation and tests. I've found a few issues, including a critical race condition in vote counting that needs to be addressed, as well as some opportunities to improve robustness and correctness in other areas. Once these points are resolved, this will be a fantastic addition to the library.

- Fix race condition in vote counting by using repository.countVotes() instead
  of manual increment
- Add CAS  support in KvRepository for concurrent vote handling
- Add comprehensive tests for vote(), countVoters(), and countVotes() methods
- Add polls prefix to KvStoreRepositoryPrefixes
- Upgrade Fedify to 1.8.0-dev.910

Co-Authored-By: Claude <noreply@anthropic.com>
@dahlia dahlia requested a review from Copilot July 1, 2025 06:53
@dahlia
Copy link
Member Author

dahlia commented Jul 1, 2025

/gemini review

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request adds comprehensive poll functionality with voting support. Key changes include:

  • Defining new Poll and Vote interfaces and extending related type definitions.
  • Adding an overload of Session.publish to support polls attached to Question messages and implementing voting validation and counting.
  • Introducing the Bot.onVote event handler and updating repository and tests to support poll vote recording and counting.

Reviewed Changes

Copilot reviewed 21 out of 23 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/session.ts Added publish overload for questions with polls.
src/session-impl.ts Implemented poll validation and processing in the publish method.
src/session-impl.test.ts Added unit tests for single and multiple choice polls.
src/repository.ts Added vote, countVoters, and countVotes with support for polls.
src/repository.test.ts Added tests for poll vote counting and edge cases.
src/poll.ts Introduced Poll and Vote interfaces.
src/events.ts Added the VoteEventHandler type.
src/bot.ts Exposed the onVote event handler via getter and setter.
src/bot-impl.ts Updated onCreated processing to trigger onVote and vote-related updates.
src/bot-impl.test.ts Added tests for onVote behavior in various voting scenarios.
pnpm-workspace.yaml & package.json Updated dependencies and exports to include poll functionality.
examples/otp.tsx Provided an OTP demo example utilizing poll features.
docs/* Updated documentation and examples with poll and vote usage details.
deno.json, CHANGES.md, .claude/settings.local.json Updated configuration and changelog for poll support.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces comprehensive poll functionality with voting support, including new interfaces, an overload for Session.publish(), and a Bot.onVote event handler. The changes are well-documented and include thorough unit tests for the new features. However, there are a few areas that could be improved for maintainability and correctness, such as clarifying the logic for determining poll type and addressing the use of magic numbers and @ts-ignore.

@dahlia dahlia merged commit a1068dd into main Jul 1, 2025
6 of 8 checks passed
@dahlia dahlia deleted the poll branch July 1, 2025 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Polls in messages

2 participants