Skip to navigation

readHandle

View as MarkdownOpen in Claude

Returns the conversation id inside a handle from mintHandle(). The signature is checked first and the expiry second, both before the id is used.

Parameters

handle
stringRequired

A handle this gateway issued.

Returns

string — the conversation id.

Throws

GatewayRejection, with a status and a coarse reason:

StatusReasonCause
400malformed handleThe handle isn’t in the expected shape.
403invalid handleThe signature doesn’t verify.
403expired handleThe handle is older than handleTtl.

Examples

import { ChatGateway, GatewayRejection } from '@signalwire/sdk';
const gateway = new ChatGateway({
configUrl: 'https://bayview-taxi.example.com/dispatch',
key: '<YOUR_PUBLISHABLE_KEY>',
secret: process.env.SIGNALWIRE_CHAT_GATEWAY_SECRET,
});
function conversationFor(handle: string): string | null {
try {
return gateway.readHandle(handle);
} catch (err) {
if (err instanceof GatewayRejection) {
console.warn(`handle refused: ${err.status} ${err.reason}`);
return null;
}
throw err;
}
}
console.log(conversationFor(gateway.mintHandle('chat-8f21'))); // chat-8f21
console.log(conversationFor('not-a-handle')); // null