Skip to content

Add Polls #25

@st0o0

Description

@st0o0

📊 Implement Poll API Support

Description

Add support for Signal's Poll API endpoints to enable creating, closing, and voting on polls through the Signal.Bot library.

API Endpoints to Implement

1. Create Poll

Endpoint: POST /v1/polls/{number}

Request:

{
  "allow_multiple_selections": true,
  "answers": [
    "apple",
    "banana",
    "orange"
  ],
  "question": "What's your favourite fruit?",
  "recipient": "<phone number> OR <username> OR <group id>"
}

Response (201):

{
  "timestamp": "1769271479"
}

2. Close Poll

Endpoint: DELETE /v1/polls/{number}

Request:

{
  "poll_timestamp": "1769271479",
  "recipient": "<phone number> OR <username> OR <group id>"
}

Response: 204 No Content


3. Vote on Poll

Endpoint: POST /v1/polls/{number}/vote

Request:

{
  "poll_author": "<phone number> OR <uuid>",
  "poll_timestamp": "1769271479",
  "recipient": "<phone number> OR <username> OR <group id>",
  "selected_answers": [1]
}

Response: 204 No Content


Implementation Tasks

  • Create PollRequest model with properties:

    • AllowMultipleSelections (bool)
    • Answers (List)
    • Question (string)
    • Recipient (string)
  • Create PollResponse model with properties:

    • Timestamp (string/long)
  • Create ClosePollRequest model with properties:

    • PollTimestamp (string/long)
    • Recipient (string)
  • Create VotePollRequest model with properties:

    • PollAuthor (string)
    • PollTimestamp (string/long)
    • Recipient (string)
    • SelectedAnswers (List)
  • Add methods to main API client:

    • CreatePollAsync(string number, PollRequest request)
    • ClosePollAsync(string number, ClosePollRequest request)
    • VotePollAsync(string number, VotePollRequest request)
  • Add error handling for 400 Bad Request responses

  • Add unit tests for all new endpoints

  • Add integration tests if possible

  • Update documentation/README with poll examples

Example Usage (Proposal)

// Create a poll
var pollRequest = new PollRequest
{
    Question = "What's your favourite fruit?",
    Answers = new List<string> { "apple", "banana", "orange" },
    AllowMultipleSelections = true,
    Recipient = "+1234567890"
};

var response = await client.CreatePollAsync(phoneNumber, pollRequest);
Console.WriteLine($"Poll created with timestamp: {response.Timestamp}");

// Vote on a poll
var voteRequest = new VotePollRequest
{
    PollAuthor = "+1234567890",
    PollTimestamp = response.Timestamp,
    Recipient = "+1234567890",
    SelectedAnswers = new List<int> { 0 } // Vote for "apple"
};

await client.VotePollAsync(phoneNumber, voteRequest);

// Close a poll
var closeRequest = new ClosePollRequest
{
    PollTimestamp = response.Timestamp,
    Recipient = "+1234567890"
};

await client.ClosePollAsync(phoneNumber, closeRequest);

Notes

  • All error responses return { "error": "string" } with 400 status code
  • Recipients can be phone numbers, usernames, or group IDs
  • Poll timestamps are returned as strings and should be stored for later operations

References

  • Signal API Documentation: swagger

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions