Secure Realtime Publish Receipts for Support Chat

Zusammenfassung

Pixel’s announcement explains how to build secure realtime publish receipts for customer support conversations. It covers signed, replay-safe acknowledgements, idempotency keys, token authorization, and separate accepted, delivered, and read states to improve reliability and auditability without claiming a message was seen.

DEV Community

How to Build Secure Realtime Publish Receipts for Customer Support Conversations

Short answer: treat a publish acknowledgement as a signed, replay-safe receipt, and keep token authority, subscription state, and business delivery as separate records. That decision gives a support agent a useful answer to “did my message arrive?” without turning an untrusted browser acknowledgement into proof that a customer saw it. In a customer support chat, presence accuracy is a business property, not a green dot. A browser can reconnect while an agent is away, a mobile network can duplicate a publish, and a tab can close after the server has accepted bytes but before the receipt reaches the user. The backend therefore needs a stable event identifier, an explicit acknowledgement state, and an audit trail that survives reconnects. What should secure realtime publish acknowledgements prove? The receipt should prove only the narrow fact the server can establish: an authenticated principal was authorized to publish event evt_8f2, and the service durably accepted that event for the conversation. It should not claim delivery to every subscriber, rendering in a browser, or human reading. Those are later observations with different evidence. I use three monotonic states: accepted, delivered, and read. Each transition carries the event ID, actor ID, conversation ID, server time, and a hash of the canonical payload. An idempotency key binds retries to one event. If the same key arrives with a different payload hash, reject it and log the security decision; silently replacing a financial or support record is unacceptable. The authorization check also has two dimensions. The access token must be valid and unexpired, and its scope must include the specific conversation action. Subscription membership is not authorization to publish. This distinction matters after a role change, when an agent may remain connected to a channel but lose permission to send. How do authentication, token scope, and acknowledgements fit together? Issue short-lived, conversation-scoped credentials from a server-side authority. The browser never receives the long-lived application secret. The generic realtime API surface exposes token issuance and revocation at /v1/realtime/token/issue and /v1/realtime/token/revoke; keep those calls behind your own authorization service so a support role, tenant, and conversation are checked before a token is minted. Here is the critical path in Go. The transport can be WebSocket, WebRTC data channels, or another realtime protocol; the receipt contract stays the same. package receipts

import (
"crypto/sha256"
"encoding/hex"
"errors"
"time"
)

type Publish struct {
EventID string
IdempotencyKey string
Conversation string
Actor string
Payload []byte
}

type Receipt struct {
EventID string
State string
Hash string
At time.Time
}

func Accept(p Publish, authorized func(string, string) bool, seen func(string) (string, bool), store func(Publish, string) error) (Receipt, error) {
if p.EventID == "" || p.IdempotencyKey == "" || p.Conversation == "" {
return Receipt{}, errors.New("missing publish identity")
}
if !authorized(p.Actor, p.Conversation) {
return Receipt{}, errors.New("publish scope denied")
}
h := sha256.Sum256(p.Payload)
hash := hex.EncodeToString(h[:])
if old, ok := seen(p.IdempotencyKey); ok {
if old != hash {
return Receipt{}, errors.New("idempotency key payload conflict")
}
return Receipt{EventID: p.EventID, State: "accepted", Hash: hash, At: time.Now().UTC()}, nil
}
if err := store(p, hash); err != nil {
return Receipt{}, err
}
return Receipt{EventID: p.EventID, State: "accepted", Hash: hash, At: time.Now().UTC()}, nil
}
The durable write and the acknowledgement must have a clear boundary. Write the event and its audit record in one transaction, then emit the receipt. If the process dies before emission, the client retries with...
Secure Realtime Publish Receipts for Support Chat
Powered by Readybot.io

Das Neueste von Pixel

Incident Response: Look Beyond the Red Alert

Pixel’s DEV Community announcement explores how teams can fixate on one failing service while overlooking the real cause of an outage, such as a full …

Sach: AI Fact-Checks WhatsApp Forwards in India

Pixel’s announcement introduces Sach, a tool that checks forwarded messages in English, Hindi, Telugu, and 14 other Indian languages against official sources. It gives cited …

Java 25 Removes SecurityManager: What to Fix

Pixel’s announcement explains how Java 24’s JEP 486 permanently disabled the SecurityManager, breaking test workarounds that intercept System.exit. It recommends returning exit codes or throwing …