Skip to main content

Dynamic Payload

When calling sendMessage, the payload field accepts either a value or a function. Functions are invoked lazily at send time, so every call produces a fresh payload — perfect for timestamps, random IDs, or contextual state.

Send Payload

Click each button a few times and compare the resulting payloads. The static payload is fixed at module load time; the dynamic payload is produced fresh on every call.

Payload Logs

No payloads sent yet.

Comparison

Static payloadDynamic payload (lambda)
EvaluatedWhen definedOn every call
Ideal forFixed dataTimestamps, random IDs
Multiple sendsIdentical each timeUnique each time

Code Example

// Static payload — values are frozen at the moment of definition
sendMessage({
text: "Hello",
payload: {
createdAt: Date.now(),
randomId: "abc123",
},
});

// Dynamic payload — values are produced at send time
sendMessage({
text: "Hello",
payload: () => ({
createdAt: Date.now(),
randomId: Math.random().toString(36).slice(2),
}),
});