@hamsa-ai/voice-agents-sdk 0.5.2 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/types/classes/types.d.ts +5 -0
- package/types/main.d.ts +70 -2
package/package.json
CHANGED
package/types/classes/types.d.ts
CHANGED
|
@@ -408,3 +408,8 @@ export type LiveKitAgentMetadata = {
|
|
|
408
408
|
voiceAgentId: string;
|
|
409
409
|
apiKey: string;
|
|
410
410
|
};
|
|
411
|
+
/**
|
|
412
|
+
* Valid DTMF (Dual-Tone Multi-Frequency) digits that can be sent during a call.
|
|
413
|
+
* Includes digits 0-9, asterisk (*), and pound (#) characters.
|
|
414
|
+
*/
|
|
415
|
+
export type DTMFDigit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '*' | '#';
|
package/types/main.d.ts
CHANGED
|
@@ -2,9 +2,9 @@ import { EventEmitter } from 'events';
|
|
|
2
2
|
import type { ConnectionState, LocalTrack, LocalTrackPublication, Participant, RemoteParticipant, RemoteTrack, Room } from 'livekit-client';
|
|
3
3
|
import LiveKitManager, { type AgentState, type AudioLevelsResult, type CallAnalyticsResult, type ConnectionStatsResult, type ParticipantData, type PerformanceMetricsResult, type TrackStatsResult } from './classes/livekit-manager';
|
|
4
4
|
import ScreenWakeLock from './classes/screen-wake-lock';
|
|
5
|
-
import type { AudioCaptureCallback, AudioCaptureOptions, ConnectionQualityData, TrackSubscriptionData, TrackUnsubscriptionData } from './classes/types';
|
|
5
|
+
import type { AudioCaptureCallback, AudioCaptureOptions, ConnectionQualityData, DTMFDigit, TrackSubscriptionData, TrackUnsubscriptionData } from './classes/types';
|
|
6
6
|
export type { AgentState } from './classes/livekit-manager';
|
|
7
|
-
export type { AudioCaptureCallback, AudioCaptureFormat, AudioCaptureMetadata, AudioCaptureOptions, AudioCaptureSource, } from './classes/types';
|
|
7
|
+
export type { AudioCaptureCallback, AudioCaptureFormat, AudioCaptureMetadata, AudioCaptureOptions, AudioCaptureSource, DTMFDigit, } from './classes/types';
|
|
8
8
|
/**
|
|
9
9
|
* Custom error class that includes both human-readable message and machine-readable messageKey
|
|
10
10
|
* for internationalization and programmatic error handling
|
|
@@ -190,6 +190,8 @@ type HamsaVoiceAgentEvents = {
|
|
|
190
190
|
listening: () => void;
|
|
191
191
|
/** Emitted when agent state changes (idle, initializing, listening, thinking, speaking) */
|
|
192
192
|
agentStateChanged: (state: AgentState) => void;
|
|
193
|
+
/** Emitted when a DTMF digit is successfully sent */
|
|
194
|
+
dtmfSent: (digit: DTMFDigit) => void;
|
|
193
195
|
/** Emitted when an error occurs */
|
|
194
196
|
error: (error: Error | HamsaApiError) => void;
|
|
195
197
|
/** Emitted when a remote track is subscribed */
|
|
@@ -550,6 +552,72 @@ declare class HamsaVoiceAgent extends EventEmitter {
|
|
|
550
552
|
* ```
|
|
551
553
|
*/
|
|
552
554
|
sendContextualUpdate(context: string): void;
|
|
555
|
+
/**
|
|
556
|
+
* Sends a DTMF (Dual-Tone Multi-Frequency) digit to the voice agent
|
|
557
|
+
*
|
|
558
|
+
* Simulates pressing a key on a phone keypad during the call. This enables
|
|
559
|
+
* browser-based call testing with DTMF input simulation, allowing users to
|
|
560
|
+
* test IVR flows and DTMF transitions without making actual phone calls.
|
|
561
|
+
*
|
|
562
|
+
* Uses LiveKit's native DTMF API (publishDtmf) which properly integrates with
|
|
563
|
+
* telephony systems and SIP infrastructure per RFC 4733 standard.
|
|
564
|
+
*
|
|
565
|
+
* @param digit - A single DTMF digit: '0'-'9', '*', or '#'
|
|
566
|
+
* @throws {Error} If called when not connected (no active call)
|
|
567
|
+
* @throws {Error} If the digit is not a valid DTMF character
|
|
568
|
+
* @fires dtmfSent When a DTMF digit is successfully sent to the agent
|
|
569
|
+
*
|
|
570
|
+
* @example Basic usage
|
|
571
|
+
* ```typescript
|
|
572
|
+
* const agent = new HamsaVoiceAgent(apiKey, config);
|
|
573
|
+
* await agent.start({ agentId, params });
|
|
574
|
+
*
|
|
575
|
+
* // Listen for DTMF send confirmations
|
|
576
|
+
* agent.on('dtmfSent', (digit) => {
|
|
577
|
+
* console.log(`Sent DTMF digit: ${digit}`);
|
|
578
|
+
* highlightKeypadButton(digit);
|
|
579
|
+
* });
|
|
580
|
+
*
|
|
581
|
+
* // Later, when user presses a key on the UI keypad:
|
|
582
|
+
* agent.sendDTMF('1'); // Simulates pressing "1"
|
|
583
|
+
* agent.sendDTMF('*'); // Simulates pressing "*"
|
|
584
|
+
* agent.sendDTMF('#'); // Simulates pressing "#"
|
|
585
|
+
* ```
|
|
586
|
+
*
|
|
587
|
+
* @example With UI keypad
|
|
588
|
+
* ```typescript
|
|
589
|
+
* // Create keypad buttons
|
|
590
|
+
* const digits = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '*', '0', '#'];
|
|
591
|
+
*
|
|
592
|
+
* digits.forEach(digit => {
|
|
593
|
+
* const button = document.createElement('button');
|
|
594
|
+
* button.textContent = digit;
|
|
595
|
+
* button.onclick = () => {
|
|
596
|
+
* try {
|
|
597
|
+
* agent.sendDTMF(digit);
|
|
598
|
+
* playKeyTone(digit); // Optional: play local tone feedback
|
|
599
|
+
* } catch (error) {
|
|
600
|
+
* console.error('Failed to send DTMF:', error.message);
|
|
601
|
+
* }
|
|
602
|
+
* };
|
|
603
|
+
* keypadContainer.appendChild(button);
|
|
604
|
+
* });
|
|
605
|
+
* ```
|
|
606
|
+
*
|
|
607
|
+
* @example Error handling
|
|
608
|
+
* ```typescript
|
|
609
|
+
* try {
|
|
610
|
+
* agent.sendDTMF('1');
|
|
611
|
+
* } catch (error) {
|
|
612
|
+
* if (error.message.includes('not connected')) {
|
|
613
|
+
* showConnectionError();
|
|
614
|
+
* } else if (error.message.includes('Invalid DTMF')) {
|
|
615
|
+
* showInvalidInputError();
|
|
616
|
+
* }
|
|
617
|
+
* }
|
|
618
|
+
* ```
|
|
619
|
+
*/
|
|
620
|
+
sendDTMF(digit: DTMFDigit): void;
|
|
553
621
|
/**
|
|
554
622
|
* Gets frequency data from the user's microphone input
|
|
555
623
|
*
|