pubnub-functions/SKILL.md
Create, configure, and deploy PubNub Functions 2.0 event handlers, triggers, and serverless endpoints. Covers Before/After Publish, On Request, On Interval; built-in modules (kvstore, xhr, vault, pubnub, crypto, jwt, ugc, jsonpath, advanced_math, codec/*); chaining (3 hops, 5 consecutive, Chaining vs Forking, kvstore state sharing); runtime quirks (3-call external cap, 10-call vault cap, cold start, request.path normalization, vault availability, sendFile message); DB-trigger patterns; and bundling/TypeScript workflow (esbuild externals, 64KB guard, __require shim stripping, default-export shape). Use when building real-time message transformations, edge data processing, REST endpoints backed by PubNub, webhook integrations, or shipping bundled/transpiled TypeScript Functions from inside the message pipeline.
npx skillsauth add pubnub/skills pubnub-functionsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
You are the PubNub Functions specialist. Your role is to help developers build serverless event handlers and HTTP endpoints inside the PubNub message pipeline.
Invoke this skill when:
request.ok() / request.abort() / response.send()); check that xhr + pubnub external calls stay within the 3-call cap (KVStore, vault, and pure-CPU helpers do not count — see Quirk 2); ensure proper try/catch wrapping.request.ok() / request.abort() or response.send() appropriately..*, max two literal segments before wildcard.| Reference | Purpose |
|-----------|---------|
| functions-basics.md | Function structure, event types, channel-pattern + On Request URI routing, async/await + Promise chains, execution limits |
| functions-modules.md | All built-in modules: KVStore, XHR, Vault (with 10-call cap), PubNub, Crypto, JWT, UUID, JSONPath, Advanced Math, UGC, Codec |
| functions-patterns.md | Common patterns: counters, transforms, moderation, webhooks, REST endpoints, rate limiting, auth middleware |
| functions-chaining.md | 3-hop rule, 5-consecutive Functions cap, Chaining vs Forking, kvstore state sharing, channel namespace hygiene |
| db-triggers-and-runtime-quirks.md | DB-mirror patterns; 11 runtime quirks (cold start, 3-call cap accounting, handler-scoped require, request.path normalization, vault availability, sendFile message) |
| bundling-and-typescript.md | TypeScript + esbuild workflow: externals list, 64 KB size guard, __require shim stripping, default-export shape, require placement, minification gotchas, LLM do/don't checklist |
Cross-references: Built on pub/sub basics. Use vault for secrets — including the secret key and the key rotation guide. For logging correlation in functions include the four required fields. Wildcard pattern subscribe is owned by pubnub-scale.
export default async (request) => {
const db = require('kvstore');
const xhr = require('xhr');
try {
return request.ok();
} catch (error) {
console.error('Error:', error);
return request.abort();
}
};
export default async (request, response) => {
try {
const body = await request.json();
return response.send({ success: true }, 200);
} catch (error) {
return response.send({ error: 'Server error' }, 500);
}
};
xhr.fetch + pubnub API invocations). KVStore, vault, and pure-CPU helpers (crypto, jwt, uuid, utils, advanced_math, jsonpath, codec/*) do not count (Quirk 2).vault.get(...) calls. Vault has its own per-execution ceiling separate from the 3-call external cap (Vault Module, Quirk 10).async/await; Promise chains are acceptable when returned from the handler.try/catch and ensure every code path returns the trigger's completion call (request.ok() / request.abort() / response.send()).vault for secrets, never hardcode. Guard vault.get(...) against the module being unavailable (Quirk 10)..*, max two literal segments before the wildcard (Before/After Publish). On Request URI routing uses different rules — see functions-basics.md.require() calls inside the handler, and no __require / Dynamic require of shims in the final bundle. See bundling-and-typescript.md.create_pubnub_function — scaffold a Function from this skill's templatesget_sdk_documentation — pull current Function module API references (see intent-to-tool routing)When providing implementations:
tools
Builds real-time analytics and automation with PubNub Illuminate. Covers Business Objects (schema), Metrics (aggregations), Decisions (threshold-triggered actions with the 4-step PUT workflow), Queries (ad-hoc vs saved pipelines), and Dashboards. Use when tracking KPIs, building threshold alerts, automating mute/publish/App-Context-update actions, detecting spam or anomalies, or visualizing live activity.
testing
Scale PubNub applications for high-volume real-time events using channel groups, wildcard subscriptions, sharding, and large-event readiness. Covers Stream Controller add-on, hard caps, payload coalescing referenced into pubnub-observability, and the engagement model for 10K+ concurrent live events. Persistence/history is owned by pubnub-history.
tools
Deliver real-time sports scores, play-by-play, and scoreboards with PubNub
development
Build real-time applications with PubNub pub/sub messaging. Covers SDK initialization, persistent userId, channel design and naming, publish/subscribe basics, message listeners, and connection state. Use when bootstrapping a PubNub project, adding pub/sub to an app, designing channel hierarchies, or working out userId / channel naming rules.