import { IncomingHttpHeaders } from 'http'; import { CallbackProcessor } from '@sinch/sdk-client'; import { WebhookRequest, WebhookResponse } from '../../../models/v2'; import { SvamlCommands } from '../../../models/v2/helpers/commands'; /** * Credentials used to validate Voice v2 webhook signatures. * * `serviceId` and `serviceSecret` are issued per Voice service in the dashboard. * The secret is a Base64 string; it is decoded to 16 bytes before HMAC. */ export interface VoiceV2CallbackWebhooksParameters { serviceId?: string; serviceSecret?: string; } /** * Parameters for a response to a `call.incoming` webhook. * * `name` is written to `callName`. * `onHangup` is written to `events.onHangup`. */ export interface IncomingCallResponseParameters { /** Ordered SVAML commands to execute for the incoming call. One command or a list. */ commands: SvamlCommands; /** Name of the call. Maps to `callName`. */ name?: string; /** SVAML commands executed when the call is hung up. One command or a list. */ onHangup?: SvamlCommands; } /** * Parameters for a webhook response other than `call.incoming`. */ export interface ResponseParameters { /** Ordered SVAML commands to execute. One command or a list. An empty array takes no action. */ commands: SvamlCommands; } export declare class CallbackWebhooks implements CallbackProcessor { private serviceId?; private serviceSecret?; constructor(params?: VoiceV2CallbackWebhooksParameters); /** * Updates the Voice service credentials used to validate webhook signatures. * @param {VoiceV2CallbackWebhooksParameters} credentials - The service ID and Base64 service secret. */ setCredentials(credentials: VoiceV2CallbackWebhooksParameters): void; /** * Validate the Authorization header of a Voice v2 webhook request. * * Voice v2 signs callbacks with `Authorization: service {serviceId}:{signature}`. * The signature is Base64(HMAC-SHA256(secretBytes, UTF8(stringToSign))) where * secretBytes is the Base64-decoded service secret. * * Use the raw request body exactly as delivered — do not re-serialize JSON before validation. * @param {IncomingHttpHeaders} headers - Incoming request's headers * @param {any} body - Incoming request's raw body * @param {string} path - Incoming request's path (no scheme, host, query or fragment) * @param {string} method - Incoming request's HTTP method * @return {boolean} - true if the authorization header is valid */ validateAuthenticationHeader(headers: IncomingHttpHeaders, body: any, path: string, method: string): boolean; /** * Reviver for a Voice v2 webhook event. * This method ensures the object can be treated as a Voice v2 webhook event and should be called before any action is taken to manipulate the object. * @param {any} eventBody - The event body containing the Voice v2 webhook notification. * @return {WebhookRequest} - The parsed webhook event object. */ parseEvent(eventBody: any): WebhookRequest; /** * Serialize a webhook response body to JSON. * @param {WebhookResponse} response - The SVAML commands to return to the Voice platform. * @return {string} - The JSON payload to send as the HTTP 200 body. */ serializeResponse(response: WebhookResponse): string; /** * Response to a webhook triggered by an incoming call. * `name` is written to `callName`. `callName` and `events` take effect only for `call.incoming`. * @param {IncomingCallResponseParameters} parameters - Commands, optional call name, and optional hangup commands. * @return {WebhookResponse} - The response body to serialize. */ static incomingCallResponse(parameters: IncomingCallResponseParameters): WebhookResponse; /** * Response to a webhook other than `call.incoming`. * Only `commands` are returned; `callName` and `events` are ignored by the Voice platform. * @param {ResponseParameters} parameters - Commands to execute. An empty array takes no action. * @return {WebhookResponse} - The response body to serialize. */ static response(parameters: ResponseParameters): WebhookResponse; /** * Static reviver for a Voice v2 webhook event. * @param {any} eventBody - The event body containing the Voice v2 webhook notification. * @return {WebhookRequest} - The parsed webhook event object. */ static parseEvent(eventBody: any): WebhookRequest; /** * Static serializer for a Voice v2 webhook response. * @param {WebhookResponse} response - The SVAML commands to return to the Voice platform. * @return {string} - The JSON payload to send as the HTTP 200 body. */ static serializeResponse(response: WebhookResponse): string; }