Event Streaming
ExternalMessageService.StreamSendRequestEvents is a server-streaming RPC that delivers real-time events for your send requests. It replaces webhooks: your server opens the connection, so there is no public endpoint to expose, and gRPC TLS provides authentication and integrity (no HMAC signatures to verify).
The stream yields SendRequestEventFrame — an envelope, not a bare event. See Stream frames before writing your read loop.
Event types
| Event type | Meaning |
|---|---|
RECIPIENT_DELIVERED | Message delivered to the recipient |
RECIPIENT_FAILED | Delivery failed |
RECIPIENT_PENDING_CONSENT | Held: the recipient has denied or revoked consent to your app. Not terminal — a RECIPIENT_FAILED follows |
REQUEST_COMPLETED | All recipients in a send request were processed — held ones included, whose RECIPIENT_FAILED arrives after this event |
REQUEST_FAILED | The request stopped before every recipient was processed; its summary counts are as of its last completed batch |
Every outcome reaches the stream. Each recipient ends with exactly one RECIPIENT_DELIVERED or RECIPIENT_FAILED, and each request with exactly one REQUEST_COMPLETED or REQUEST_FAILED. The one exception: after REQUEST_FAILED, a recipient the request never attempted has no event of its own and stays PENDING in GetSendRequestStatus.
Event payload
Stream frames
Every item on the stream is a SendRequestEventFrame, a oneof with three variants. Only one of them is content.
| Frame | Meaning | What to do |
|---|---|---|
event | A real lifecycle event (payload below) | Handle it, and advance your cursor |
keep_alive | Proof of life on an idle stream. Empty by design | Reset your idle timer; otherwise ignore |
cursor_expired | Your after_event_id is older than the 7-day replay window. Sent once, first | Reconcile with GetSendRequestStatus, then keep reading |
Three rules follow, and each of them prevents a real failure:
- Reset your idle timer on every frame, not just on events. A delivery feed is quiet most of the time, so "nothing arrived" and "the connection is dead" look identical without the keepalive. Set your bound to a comfortable multiple of the keepalive interval (20 s at time of writing).
- Advance your cursor only on an
eventframe. No other variant carries anevent_id. Persisting anything else — an empty string included — leaves you with a cursor the server cannot match, and it will resume you at the live edge instead of where you stopped. - Treat a frame kind you do not recognise as skippable. New variants may be added; skip them and continue. Do not stop the stream, and do not count them as events.
Event payload
Each event frame carries a SendRequestEvent:
| Field | Type | Description |
|---|---|---|
event_id | string | ULID — unique event id; use it as your cursor |
send_request_id | string | The send request this event belongs to |
event_type | enum | One of the types above |
recipient | optional | Present for per-recipient events (ppnum, error_code, …) |
summary | optional | Present for REQUEST_COMPLETED and REQUEST_FAILED (delivered, failed, …) |
occurred_at | string | Event timestamp (RFC 3339) |
Reconnection
Pass the last event_id you saw as after_event_id and the server replays every event after it, in order, then follows new ones. Without it, the stream starts at the live edge. Event IDs are ULIDs (chronologically sortable). Filter to a single send request with send_request_id, or omit it to receive all events for your app.
Delivery is at-least-once. A reconnect may re-deliver a few events near your cursor, so de-duplicate by event_id. The replay window is 7 days: a cursor older than that gets one cursor_expired frame, then the live edge — reconcile with GetSendRequestStatus. A cursor that is not an event_id is refused with INVALID_ARGUMENT.
let mut cursor = load_saved_cursor().await; // persisted last_event_id
loop {
let mut client = connect_client(&token).await;
if let Err(e) = stream_events(&mut client, cursor.clone()).await {
eprintln!("stream error: {e}; reconnecting…");
// back off before retrying
}
cursor = load_saved_cursor().await; // updated as events arrive
}Persist last_event_id durably, and write it only from an event frame — it's how the stream resumes. See Security.
Inbound channel events
ExternalChannelService.StreamChannelEvents is the face's one inbound door: every message accepted into a channel your app owns — a named channel under your prefix, or a direct channel your app's system ppnum is a party to — as a server stream, replayed from a cursor and then followed live. It is how a support DM becomes a conversation: the user's reply reaches your server the moment PCS accepts it.
| Field | Type | Description |
|---|---|---|
channel_ids (request) | repeated string | Narrow to these owned channels; empty means every one. An id outside the owned set is ignored, not refused — the set is the server's and may change while the stream is open |
after_message_id (request) | optional string | Cursor: replay after this message id (a ULID). Absent = live edge |
event.channel_id | string | The channel the message landed in |
event.message | ExtMessageInfo | The message, exactly as GetMessages reads it |
event.from_app | bool | true when the sender is your app's own system ppnum — the server's stamp, so you tell your own sends from inbound ones without configuring your number |
Every item is a ChannelEventFrame with the same three variants as above — event, keep_alive, cursor_expired — and the same three rules apply: reset your idle timer on every frame, advance your cursor only on an event (to message.id), skip a kind you do not recognise.
Replay reads the message table itself. Delivery is at-least-once, so de-duplicate by message.id. A cursor older than 7 days gets cursor_expired first; read the gap with GetMessages. A message a channel's storage mode already discarded is gone regardless of cursor, and an ephemeral channel yields nothing here. The owned set is re-derived every 30 s. One dial counts once against your per-minute allowance. Requires chat.read.
At most 4 open streams per stream kind, per server instance. The limit is counted separately for this stream and the delivery stream. The dial past it is RESOURCE_EXHAUSTED with a retry-after of 20 seconds. One stream of each kind is the normal shape, and the limit leaves room for a redeploy overlap and a dead connection the server has not yet noticed.
With the Rust SDK (ppoppo-pcs-external 0.52.0+), client.subscribe_channel_events(&[], None) returns a ChannelEventSubscription that reconnects, replays from the last message delivered and re-mints a credential once on its own; next() yields ChannelEventItem::{Event, CursorExpired}.
Held recipients
A recipient with no consent decision for your app receives the message: consent is recorded at delivery. A recipient whose consent to your app is denied or revoked is held (RECIPIENT_PENDING_CONSENT), and the message is kept for 24 hours. Calling GrantConsent does not release a hold — an app may not overrule its user's refusal — so every hold ends as RECIPIENT_FAILED:
error_code | When |
|---|---|
consent_denied | Your app calls DenyConsent for that user while the recipient is held |
consent_expired | Otherwise, when the held message expires — the usual end of a hold |
The bulk-messaging guide shows a handler.