Richtlinie
Twilio Voice-Tutorial
Mit @capgo/capacitor-twilio-voice
Integriert den Twilio Voice SDK in Capacitor.
Installieren
bun add @capgo/capacitor-twilio-voice
bunx cap sync
Was diese Erweiterung offenlegt
login- Authentifiziert den Benutzer mit Twilio Voice mithilfe eines Zugriffstokens.logout- Meldet den aktuellen Benutzer ab und registriert ihn nicht mehr bei Twilio Voice.isLoggedIn- Überprüft, ob der Benutzer derzeit angemeldet ist und ein gültiges Zugriffstoken besitzt.makeCall- Eine ausgehende Anrufverbindung zu einer Telefonnummer oder einem Client starten.
Beispielanwendung
login
Authentifizieren Sie den Benutzer mit Twilio Voice mithilfe eines Zugriffstokens.
import { CapacitorTwilioVoice } from '@capgo/capacitor-twilio-voice';
const result = await CapacitorTwilioVoice.login({
accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
});
console.log('Login successful:', result.success);
logout
Beenden Sie den aktuellen Benutzer und registrieren Sie sich nicht mehr bei Twilio Voice.
import { CapacitorTwilioVoice } from '@capgo/capacitor-twilio-voice';
const result = await CapacitorTwilioVoice.logout();
console.log('Logout successful:', result.success);
isLoggedIn
Überprüfen Sie, ob der Benutzer derzeit angemeldet ist und ein gültiges Zugriffstoken besitzt.
import { CapacitorTwilioVoice } from '@capgo/capacitor-twilio-voice';
const status = await CapacitorTwilioVoice.isLoggedIn();
if (status.isLoggedIn && status.hasValidToken) {
console.log('User identity:', status.identity);
} else {
// Re-authenticate the user
}
makeCall
Eine ausgehende Anrufverbindung zu einer Telefonnummer oder einem Client starten.
import { CapacitorTwilioVoice } from '@capgo/capacitor-twilio-voice';
// Call a phone number
const result = await CapacitorTwilioVoice.makeCall({
to: '+1234567890'
});
console.log('Call SID:', result.callSid);
// Call another Twilio client with a readable name for CallKit Recents
await CapacitorTwilioVoice.makeCall({
to: 'client:alice',
displayName: 'Alice Smith'
});
// Call a PSTN number using a specific caller ID
await CapacitorTwilioVoice.makeCall({
to: '+1234567890',
callerId: '+10987654321'
});
Vollständige Referenz
- GitHub https://github.com/Cap-go/capacitor-twilio-voice/
- Dokumentation: /docs/plugins/twilio-voice/