publish_pubnub_message
Send data to a specified PubNub channel by providing the channel name and message payload. Returns a timetoken confirming successful message publication.
Instructions
Publishes a message to a specified PubNub channel. Call this tool whenever you need to send data through PubNub. Provide the channel name and message payload. Returns a timetoken confirming successful publication.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| channel | Yes | Name of the PubNub channel (string) to publish the message to | |
| message | Yes | Message payload as a string |
Implementation Reference
- index.js:530-555 (handler)The handler function that executes the 'publish_pubnub_message' tool logic. It uses the PubNub SDK to publish a message to the specified channel and returns the timetoken on success or an error message.toolHandlers['publish_pubnub_message'] = async ({ channel, message }) => { try { const result = await pubnub.publish({ channel, message, }); return { content: [ { type: 'text', text: `Message published successfully. Timetoken: ${result.timetoken}`, }, ], }; } catch (err) { return { content: [ { type: 'text', text: `Error publishing message: ${err}`, }, ], isError: true, }; } };
- index.js:558-565 (schema)The tool definition including name, description, and Zod schema for input parameters (channel and message).toolDefinitions['publish_pubnub_message'] = { name: 'publish_pubnub_message', description: 'Publishes a message to a specified PubNub channel. Call this tool whenever you need to send data through PubNub. Provide the channel name and message payload. Returns a timetoken confirming successful publication.', parameters: { channel: z.string().describe('Name of the PubNub channel (string) to publish the message to'), message: z.string().describe('Message payload as a string'), } };
- index.js:1363-1394 (registration)The registerAllTools function that registers the 'publish_pubnub_message' tool (along with others) by calling server.tool() with the definition and wrapped handler. Called for main server and HTTP sessions.function registerAllTools(serverInstance, chatSdkMode = false) { // Tools to exclude when in chat SDK mode const chatSdkExcludedTools = [ 'read_pubnub_sdk_docs', 'write_pubnub_app', 'read_pubnub_resources', 'manage_pubnub_account' ]; for (const toolName in toolDefinitions) { if (toolHandlers[toolName]) { // Skip excluded tools when in chat SDK mode if (chatSdkMode && chatSdkExcludedTools.includes(toolName)) { continue; } // Special handling for chat SDK docs tool if (toolName === 'read_pubnub_chat_sdk_docs' && (chatSdkLanguages.length === 0 || chatSdkTopics.length === 0)) { continue; // Skip this tool if chat SDK data isn't loaded } const toolDef = toolDefinitions[toolName]; serverInstance.tool( toolDef.name, toolDef.description, toolDef.parameters, wrapToolHandler(toolHandlers[toolName], toolName) ); } } }