@hamsa-ai/voice-agents-sdk 0.5.2 → 0.5.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hamsa-ai/voice-agents-sdk",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "description": "Hamsa AI - Voice Agents JavaScript SDK",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -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,73 @@ 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
+ * The DTMF digit is sent through the LiveKit data channel to the server,
563
+ * which processes it as a DTMF input event that can trigger DTMF transitions
564
+ * in the agent flow.
565
+ *
566
+ * @param digit - A single DTMF digit: '0'-'9', '*', or '#'
567
+ * @throws {Error} If called when not connected (no active call)
568
+ * @throws {Error} If the digit is not a valid DTMF character
569
+ * @fires dtmfSent When a DTMF digit is successfully sent to the agent
570
+ *
571
+ * @example Basic usage
572
+ * ```typescript
573
+ * const agent = new HamsaVoiceAgent(apiKey, config);
574
+ * await agent.start({ agentId, params });
575
+ *
576
+ * // Listen for DTMF send confirmations
577
+ * agent.on('dtmfSent', (digit) => {
578
+ * console.log(`Sent DTMF digit: ${digit}`);
579
+ * highlightKeypadButton(digit);
580
+ * });
581
+ *
582
+ * // Later, when user presses a key on the UI keypad:
583
+ * agent.sendDTMF('1'); // Simulates pressing "1"
584
+ * agent.sendDTMF('*'); // Simulates pressing "*"
585
+ * agent.sendDTMF('#'); // Simulates pressing "#"
586
+ * ```
587
+ *
588
+ * @example With UI keypad
589
+ * ```typescript
590
+ * // Create keypad buttons
591
+ * const digits = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '*', '0', '#'];
592
+ *
593
+ * digits.forEach(digit => {
594
+ * const button = document.createElement('button');
595
+ * button.textContent = digit;
596
+ * button.onclick = () => {
597
+ * try {
598
+ * agent.sendDTMF(digit);
599
+ * playKeyTone(digit); // Optional: play local tone feedback
600
+ * } catch (error) {
601
+ * console.error('Failed to send DTMF:', error.message);
602
+ * }
603
+ * };
604
+ * keypadContainer.appendChild(button);
605
+ * });
606
+ * ```
607
+ *
608
+ * @example Error handling
609
+ * ```typescript
610
+ * try {
611
+ * agent.sendDTMF('1');
612
+ * } catch (error) {
613
+ * if (error.message.includes('not connected')) {
614
+ * showConnectionError();
615
+ * } else if (error.message.includes('Invalid DTMF')) {
616
+ * showInvalidInputError();
617
+ * }
618
+ * }
619
+ * ```
620
+ */
621
+ sendDTMF(digit: DTMFDigit): void;
553
622
  /**
554
623
  * Gets frequency data from the user's microphone input
555
624
  *