@phonely-ai/web
v0.0.5
Published
Phonely Web SDK for AI voice calls
Readme
@phonely-ai/web
A professional SDK for integrating Phonely's AI voice call capabilities into web applications. Built on top of Daily.js, this SDK provides a simple and robust interface for managing AI voice calls.
Installation
npm install @phonely-ai/webQuick Start
import PhonelySDK, { PhonelyEvent } from '@phonely-ai/web';
// Initialize the SDK
const phonely = new PhonelySDK();
// Start a call
const callId = await phonely.call({
agentId: 'your_agent_id'
});
// Listen for events
phonely.on(PhonelyEvent.CALL_JOINED, () => {
console.log('Call joined successfully');
});
// End the call
await phonely.endCall();React Hook Example
import { PhonelySDK, PhonelyEvent } from '@phonely-ai/web';
function usePhonely(agentId: string) {
const [isCalling, setIsCalling] = useState(false);
const phonelyRef = useRef<PhonelySDK | null>(null);
useEffect(() => {
// Initialize SDK
phonelyRef.current = new PhonelySDK({
apiKey: 'your_api_key'
});
// Set up event listeners
phonelyRef.current.on(PhonelyEvent.CALL_JOINED, () => {
setIsCalling(true);
});
return () => {
if (phonelyRef.current) {
phonelyRef.current.endCall().catch(console.error);
}
};
}, []);
const startCall = async () => {
try {
await phonelyRef.current?.call({ agentId });
} catch (error) {
console.error('Call failed:', error);
}
};
const endCall = async () => {
try {
await phonelyRef.current?.endCall();
setIsCalling(false);
} catch (error) {
console.error('End call failed:', error);
}
};
return { isCalling, startCall, endCall };
}API Reference
PhonelySDK Configuration
interface PhonelyConfig {
apiKey?: string; // Optional for now
voiceApiBaseUrl?: string;
dailyConfig?: {
avoidEval?: boolean;
alwaysIncludeMicInPermissionPrompt?: boolean;
};
dailyCallObject?: {
audioSource?: boolean | MediaStreamTrack;
videoSource?: boolean | MediaStreamTrack;
startAudioOff?: boolean;
};
}Methods
call(options: CallOptions): Promise<string>
Initiates a call with an AI assistant.
options.agentId: ID of the agent to calloptions.metadata?: Additional metadata for the call- Returns: Promise resolving to the call ID
endCall(): Promise<void>
Ends the current call.
setAudioEnabled(enabled: boolean): Promise<void>
Enables or disables the local audio.
getParticipants(): Participant[]
Gets all participants in the call.
sendMessage(content: string): Promise<void>
Sends a message to the call.
Events
enum PhonelyEvent {
CALL_JOINED = 'call-joined',
CALL_LEFT = 'call-left',
PARTICIPANT_JOINED = 'participant-joined',
PARTICIPANT_LEFT = 'participant-left',
PARTICIPANT_UPDATED = 'participant-updated',
MESSAGE = 'message',
VOLUME_LEVEL = 'volume-level',
SPEECH_START = 'speech-start',
SPEECH_END = 'speech-end',
CALL_START_PROGRESS = 'call-start-progress',
ERROR = 'error'
}License
MIT
