Chuyển đến nội dung

Câu trả lời cho thông báo

Đặt câu hỏi trong thông báo và đọc câu trả lời qua API. PushWard ghi lại nút mà người dùng đã nhấn hoặc nội dung họ đã nhập để trả lời, nên bạn không cần webhook của riêng mình.

Send an action without a url, and without foreground, and PushWard records the tap itself: which action the user chose, and when. Add text_input: true to the same kind of action and the user can type a reply, which is recorded with it. Your code then reads the answer from GET /notifications/answers/{id}.

Yêu cầu một quyết định
curl -X POST https://api.pushward.app/notifications \
  -H "Authorization: Bearer hlk_YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Deploy to production?",
    "body": "Build 1.11.0 passed staging.",
    "source": "ci",
    "actions": [
      { "id": "deploy", "title": "Deploy", "icon": "checkmark.circle" },
      { "id": "hold", "title": "Hold", "icon": "pause.circle", "destructive": true },
      {
        "id": "note",
        "title": "Reply",
        "icon": "arrowshape.turn.up.left",
        "text_input": true,
        "text_input_placeholder": "Why hold?"
      }
    ]
  }'

The response is the notification, with answerable: true when the server will record the answer. Keep its id:

{
  "id": 1234,
  "title": "Deploy to production?",
  "body": "Build 1.11.0 passed staging.",
  "source": "ci",
  "actions": [
    { "id": "deploy", "title": "Deploy", "icon": "checkmark.circle" },
    ...
  ],
  "answerable": true,
  "answer_cursor": "57",
  "pushed": true,
  "created_at": "2026-09-28T12:00:00Z",
  "delivery": "all"
}

The actions in the response are the ones you sent. The links PushWard adds to record the answer go only to your devices. answer_cursor is for reading answers from the answer stream.

Read the answer

Chờ câu trả lời
curl "https://api.pushward.app/notifications/answers/1234?wait=25" \
  -H "Authorization: Bearer hlk_YOUR_TOKEN"
{
  "notification_id": 1234,
  "status": "answered",
  "action_id": "note",
  "text": "Waiting for the database migration.",
  "answered_at": "2026-09-28T12:03:41Z"
}
FieldDescription
notification_idThe notification the answer belongs to.
statuspending until the user answers, then answered.
action_idThe id of the action the user tapped. Set once answered.
textWhat the user typed, for a text_input action.
answered_atWhen the answer was recorded (RFC 3339, UTC).
collapse_id, thread_idThe ones the notification was sent with, when it had them.

Without wait the request returns right away. With ?wait=N (0-25 seconds) it is held open while the answer is pending and returns as soon as it lands; if the time runs out first it returns with status: "pending". Repeat the request to wait longer. Agents on the MCP server can call wait_for_answer with the notification_id, which does this for them.

From Home Assistant, pushward.get_notification_answer does the same inside an automation. It keeps waiting for as long as its timeout allows (up to 24 hours) and hands action_id and text to the next step. See Home Assistant for an example.

The answer stream

Code that asks many questions, such as an automation hub, a chat bot or a deploy pipeline, should not hold one request open per notification. GET /notifications/answers returns the answers recorded after a cursor, oldest first, with the cursor to pass next, so one loop sees every answer to the notifications your key sent. Prefer it to polling GET /notifications/answers/{id} for each one. The Home Assistant integration's pushward_notification_action event (0.55.0 and later) is built on it.

Call it once without after. That first response holds no answers, only the current cursor, so a new reader starts from now instead of replaying the 30 days of answers PushWard keeps:

Take the cursor
curl "https://api.pushward.app/notifications/answers" \
  -H "Authorization: Bearer hlk_YOUR_TOKEN"
{ "items": [], "cursor": "57" }

Then wait for what comes after it:

Wait for the next answers
curl "https://api.pushward.app/notifications/answers?after=57&wait=25" \
  -H "Authorization: Bearer hlk_YOUR_TOKEN"
{
  "items": [
    {
      "notification_id": 1234,
      "status": "answered",
      "action_id": "note",
      "text": "Waiting for the database migration.",
      "answered_at": "2026-09-28T12:03:41Z",
      "collapse_id": "deploy-1-11-0",
      "thread_id": "deploys"
    }
  ],
  "cursor": "58"
}
ParameterDescription
afterThe cursor of your previous response. Leave it out on the first call. A cursor is an opaque string: store it as it is. A malformed one is a 400 with cursor.invalid.
wait0-25 seconds to hold the request open while nothing has arrived after the cursor. It returns as soon as an answer lands, or with no items and the same cursor when the time runs out. Ignored on the first call.
limit1-100 answers per response, 100 by default. When a page comes back full, call again at once with its cursor.

Each item has the shape of GET /notifications/answers/{id}, always with status: "answered". The stream carries no action title and none of the notification's text, so match on notification_id, action_id or the collapse_id you sent. Store the cursor after every response to pick up where you left off after a restart; answers older than 30 days are gone by then.

Not missing an answer

Take the first cursor when the reader is set up, before it sends anything it waits for. A reader that already holds a cursor keeps reading from it. A reader with no cursor yet takes the answer_cursor of its first answerable send (a POST /notifications response with answerable: true) as its cursor and keeps it; the answer_cursor of later sends adds nothing. Cursors are opaque and never compared. A scheduled send's response has no answer_cursor: its answers come after it fires, so a cursor taken when you scheduled it covers them.

Who sees what

  • An integration key reads only answers to notifications it sent. For an organization key that is every member's answer to its sends.
  • Waits on the stream have a limit of their own, apart from the single answer's ?wait: two at a time per integration key, and a limit per server. Past either, the call is a 429 with answer_wait.limit_exceeded and retry_after_ms. Retry after it, or call without wait.
  • Reading the stream needs notifications at send or above, like sending did.

From the CLI and MCP

The CLI reads the stream with pushward notification answers (CLI 1.8.0 and later). Without --after it prints only the current cursor. --after takes the cursor to read from, --wait 10m blocks until at least one answer comes in and exits 7 if none does, and --limit sets the page size (1-100). --follow keeps reading and prints the answers as they come in, one JSON page per line when piped, until you stop it; it then prints the cursor to resume from on stderr. It rides out network errors, 5xx responses and rate limits, waiting 2 seconds at first and doubling up to 30, with a line on stderr for each retry (none with -q). A key or cursor the server refuses, or a used-up quota, ends it with the CLI's usual exit code.

Take the cursor, ask two questions, act on their answers
cursor=$(pushward notification answers --jq .cursor)
api=$(pushward notify --title "Deploy api?" --body v2.4.0 --action go=Go --jq .id)
web=$(pushward notify --title "Deploy web?" --body v2.4.0 --action go=Go --jq .id)
pushward notification answers --after "$cursor" --follow \
  --jq ".items[] | select(.notification_id == $api or .notification_id == $web)"

The stream holds the answers to everything the key sent, so another script on the same key shows up in it too: keep the id of each send and skip the rest, as the filter above does. To wait for a single notification, pushward notify --wait or pushward notification answer <id> --wait 5m is simpler. The GitHub Action refuses --follow, which never ends.

On the MCP server (pushward-mcp 1.20.0 and later) the same call is list_notification_answers. It takes after (the cursor, passed as the string it came as), wait_seconds (0-25, ignored without after) and limit (1-100), and returns {"items", "cursor"} like the endpoint. An agent keeps one cursor for its whole loop, however many questions it sends; for one notification, wait_for_answer is simpler.

Rules

  • Only actions with no url and no foreground are recorded. A url-less foreground action still just opens the app, and an action with a url keeps calling that URL and is never recorded. One notification can mix all three.
  • The first answer wins. Once one device has answered, later taps on any device change nothing.
  • Answers are kept for 30 days.
  • An integration key can read only answers to notifications it sent. Reading an answer needs notifications at send or above, like sending the notification did.
  • A notification with nothing to record (none of its actions was url-less and silent), an unknown id and an answer past its 30 days all return 404 with code notification_answer.not_found.
  • Too many wait requests open at once for your account return 429 with code answer_wait.limit_exceeded. Retry shortly, or read without wait.
  • The recording links count toward the 4 KB push payload. If a long notification leaves no room for them, plain url-less actions go out unrecorded and the response has no answerable; a url-less text_input action fails with 400 instead.
  • Scheduled notifications are recorded the same way. Read the answer with the notification_id a sent schedule reports; each send of a repeating schedule is its own notification with its own answer.
ℹ Thông tin

Versions of the PushWard iOS app before 1.5 show a text_input action as a plain button. The tap is still recorded, without text.

Sắp có trong phiên bản ứng dụng 1.15.0

Phần này mô tả một tính năng trong bản cập nhật ứng dụng đang chờ App Store xét duyệt. Tính năng sẽ tự động mở khóa tại đây ngay khi bản cập nhật được phát hành.

For a question that should stay on the Lock Screen until someone answers it, use an approval Live Activity. Its url-less options are recorded the same way, and GET /activities/{slug}?wait=25 waits for the answer.