UNPKG

phonic

Version:

[![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2FPhonic-Co%2Fphonic-node) [![npm shield](htt

65 lines (64 loc) 3.31 kB
/** * This file was auto-generated by Fern from our API Definition. */ import * as core from "../../../../core/index.js"; import * as Phonic from "../../../index.js"; export declare namespace ConversationsSocket { interface Args { socket: core.ReconnectingWebSocket; } type Response = Phonic.ReadyToStartConversationPayload | Phonic.ConversationCreatedPayload | Phonic.InputTextPayload | Phonic.InputCancelledPayload | Phonic.AudioChunkResponsePayload | Phonic.UserStartedSpeakingPayload | Phonic.UserFinishedSpeakingPayload | Phonic.DtmfPayload | Phonic.ToolCallPayload | Phonic.ToolCallOutputProcessedPayload | Phonic.ToolCallInterruptedPayload | Phonic.AssistantChoseNotToRespondPayload | Phonic.AssistantEndedConversationPayload | Phonic.ErrorPayload; type EventHandlers = { open?: () => void; message?: (message: Response) => void; close?: (event: core.CloseEvent) => void; error?: (error: Error) => void; }; } export declare class ConversationsSocket { readonly socket: core.ReconnectingWebSocket; protected readonly eventHandlers: ConversationsSocket.EventHandlers; private messageBuffer; private handleOpen; private handleMessage; private handleClose; private handleError; constructor(args: ConversationsSocket.Args); /** The current state of the connection; this is one of the readyState constants. */ get readyState(): number; /** * @param event - The event to attach to. * @param callback - The callback to run when the event is triggered. * Usage: * ```typescript * this.on('open', () => { * console.log('The websocket is open'); * }); * ``` */ on<T extends keyof ConversationsSocket.EventHandlers>(event: T, callback: ConversationsSocket.EventHandlers[T]): void; sendConfig(message: Phonic.ConfigPayload): void; sendAudioChunk(message: Phonic.AudioChunkPayload): void; sendUpdateSystemPrompt(message: Phonic.UpdateSystemPromptPayload): void; sendSetExternalId(message: Phonic.SetExternalIdPayload): void; sendSetTwilioCallSid(message: Phonic.SetTwilioCallSidPayload): void; sendToolCallOutput(message: Phonic.ToolCallOutputPayload): void; /** Connect to the websocket and register event handlers. */ connect(): ConversationsSocket; /** Close the websocket and unregister event handlers. */ close(): void; /** Returns a promise that resolves when the websocket is open. */ waitForOpen(): Promise<core.ReconnectingWebSocket>; /** Asserts that the websocket is open. */ private assertSocketIsOpen; /** Send a message with buffering - if socket is not open, buffer the message. */ private sendWithBuffering; /** Flush all buffered messages when the socket opens. */ private flushMessageBuffer; /** Clear all buffered messages. */ private clearMessageBuffer; /** Send a binary payload to the websocket. */ protected sendBinary(payload: ArrayBufferLike | Blob | ArrayBufferView): void; /** Send a JSON payload to the websocket. */ protected sendJson(payload: Phonic.ConfigPayload | Phonic.AudioChunkPayload | Phonic.UpdateSystemPromptPayload | Phonic.SetExternalIdPayload | Phonic.SetTwilioCallSidPayload | Phonic.ToolCallOutputPayload): void; }