Skip to content

Ask everyone, tally the answers ​

Send one question to a topic and every holder gets their own copy to answer. The send returns a group handle. Collecting on it streams each person's answer as it arrives and ends once everyone has responded.

Good for: quick team polls, headcounts, go/no-go checks across a crew, "who is on site tomorrow?".

bash
export SP_API_TOKEN="your-token"

# send, then collect every answer as NDJSON; ends when everyone answered
sp task -t crew --format json --title "Team dinner on Friday?" \
  -c "Yes,No,Maybe" \
  | sp collect --inputs
python
import asyncio
from collections import Counter
from simplepush import Client, ChoiceInput, TaskCompleted

client = Client(api_token="YOUR_API_TOKEN")

group = client.send_task(
    topic="crew",
    title="Team dinner on Friday?",
    inputs=[ChoiceInput(options=["Yes", "No", "Maybe"])],
)

async def main():
    tally = Counter()
    async for g in group.inputs(timeout=3600):
        if isinstance(g.item, TaskCompleted):
            answer = g.item.uploads[0].value
            tally[answer] += 1
            print(f"{g.recipient}: {answer}")
    print(dict(tally))
    await client.aclose()

asyncio.run(main())
ts
import { Client } from '@simplepush/sdk'

const client = new Client({ apiToken: 'YOUR_API_TOKEN' })

const group = await client.sendTask({
  topic: 'crew',
  title: 'Team dinner on Friday?',
  inputs: [{ type: 'choice', options: ['Yes', 'No', 'Maybe'], required: true }],
})

const tally = new Map<string, number>()
for await (const { item, recipient } of group.inputs({ idleMs: 3_600_000 })) {
  if (item.kind === 'taskCompleted') {
    const choice = item.uploads.find((u) => u.kind === 'choice')
    if (choice?.kind === 'choice') {
      tally.set(choice.value, (tally.get(choice.value) ?? 0) + 1)
      console.log(`${recipient?.name}: ${choice.value}`)
    }
  }
}
console.log(tally)
client.close()
bash
# sending works fine over plain HTTP...
curl -i -X POST https://api.simplepu.sh/v1/tasks \
  -H "API-Token: $SP_API_TOKEN" \
  -H "Topic: crew" \
  -H "Title: Team dinner on Friday?" \
  -H "Choice-Input: Yes,No,Maybe"

# ...but `Wait: true` only returns the FIRST answer. To gather all of
# them, collect the group with `sp collect` or an SDK stream instead.

Each recipient answers on their own instance. Late answers do not block early ones, and you see who said what. The CLI pipe prints one JSON line per answer plus a final end line with counts ({"instances":{"total":5,"completed":5,...}}). That output is ready for jq or an agent to consume.

The timeouts above measure silence across the whole group. One quiet teammate does not end the stream. An hour with no new answers does.