Receiving Messages

When your webhook receives inbound messages from Pinnacle, the raw request body lacks type information. The process method will validate incoming events by checking the signing secret and transforms the request into a fully typed MessageEvent objects.

Parameters

ParameterTypeDescription
reqRequest | ExpressLikeRequestStandard Fetch API Request object or Express-like request that must contain both a headers and body field.
secretstring (optional)Signing secret for webhook validation. If not provided, uses PINNACLE_SIGNING_SECRET environment variable. Throws an error if neither is provided.

Returns

Returns a fully typed MessageEvent object containing the inbound message data.

Errors

ErrorDescription
UnauthorizedErrorWebhook secret validation failed
BadRequestErrorRequest body validation failed

Example Implementation

1import express from 'express';
2import { PinnacleClient } from 'rcs-js';
3
4const app = express();
5const client = new PinnacleClient({ apiKey: PINNACLE_API_KEY });
6
7app.post('/webhook', express.json(), async (req, res) => {
8 try {
9 // Process and validate the webhook
10 // Returns a fully typed MessageEvent object
11 const messageEvent: Pinnacle.MessageEvent = await client.messages.process(req);
12
13 // messageEvent is now typed as Pinnacle.MessageEvent
14 // Your business logic here
15 await handleInboundMessage(messageEvent);
16
17 res.status(200).json({ status: 'processed' });
18 } catch (error) {
19 throw error
20 }
21});
22
23async function handleInboundMessage(event: Pinnacle.MessageEvent) {
24 // event is fully typed with autocomplete support
25 // Your message handling logic
26}