pubnub
The pubnub built-in module is available only inside a PubNub Function. It provides PubNub client SDK capabilities and Functions-specific publishing methods.
1const pubnub = require('pubnub');
Full parameter and response documentation for each capability lives on its own canonical page:
| Capability | Representative methods | Canonical reference |
|---|---|---|
| Pub/Sub | publish(), fire(), signal() | Publish overview. Also documented in full below |
| Access Manager | grantToken(), parseToken() | Access control overview |
| Presence | hereNow(), whereNow(), setState(), getState() | Presence overview |
| Channel Groups | addChannels(), listChannels(), removeChannels(), deleteGroup() | Channel Groups API reference |
| Message Persistence | history(), fetchMessages(), deleteMessages(), messageCounts() | Message history overview |
| App Context | objects.* methods | Metadata overview |
| Message Actions | addMessageAction() and related methods | Message actions overview |
| Mobile Push | push.addChannels() and related methods | Mobile Push API reference |
| File Sharing | listFiles(), getFileUrl(), publishFile() | Files overview |
The legacy grant() (Access Manager v2) method is out of scope. grantToken() supersedes it.
File Sharing methods from the pubnub module cover file metadata operations only. Uploading and downloading file content requires a PubNub client SDK. A Function cannot perform the transfer itself.
The following capabilities are Functions-specific and are not documented elsewhere.
Publish, fire, and signal
publish({message, channel}) sends a message to subscribers and Functions. fire({message, channel}) triggers Functions without delivering to subscribers.
| Parameter | Description |
|---|---|
message *Type: Object | The message to send. |
channel *Type: String | The channel to publish to. |
Both return a Promise. The published or fired payload must be valid JSON. A string payload doesn't trigger Functions.
1const pubnub = require('pubnub');
2pubnub.publish({
3 channel: 'hello_universe',
4 message: request.message
5}).then((publishResponse) => {
6 console.log(`Publish Status: ${publishResponse[0]}:${publishResponse[1]} with TT ${publishResponse[2]}`);
7});
signal({message, channel}) sends a signal to subscribers and Functions.
| Parameter | Description |
|---|---|
message *Type: Object | The signal payload. |
channel *Type: String | The channel to signal on. |
Returns a Promise. Signal payloads are limited to 64 bytes. The payload must also be valid JSON. A string payload doesn't trigger Functions.
1const pubnub = require('pubnub');
2pubnub.signal({
3 channel: 'hello_universe',
4 message: request.message
5}).then((signalResponse) => {
6 console.log(`Signal Status: ${signalResponse[0]}:${signalResponse[1]} with TT ${signalResponse[2]}`);
7});
Functions support chaining up to 3 hops, so a Function can trigger at most two more Functions downstream. Trigger each hop using publish(), fire(), or signal().
Related reference
- Modules and libraries. Every built-in module available inside a Function.
- Function types. Per-trigger reference for every Function type.
- API limits. Per-execution operation caps, including PubNub API calls and chain depth.