Getting Started
Copiez une commande de configuration avec les étapes d'installation et la guide markdown complet pour ce plugin.
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-twilio-voice`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/twilio-voice/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
Installer
InstallationVous pouvez utiliser notre configuration assistée par l'IA pour installer le plugin. Ajoutez les Capgo compétences à votre outil IA à l'aide de la commande suivante :
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsEnsuite, utilisez la prompt suivante :
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-twilio-voice` plugin in my project.Si vous préférez la configuration manuelle, installez le plugin en exécutant les commandes suivantes et suivez les instructions spécifiques à la plateforme ci-dessous :
bun add @capgo/capacitor-twilio-voicebunx cap syncImporter
Section intitulée “Importer”import { CapacitorTwilioVoice } from '@capgo/capacitor-twilio-voice';API Vue d'ensemble
Section intitulée “API Présentation”Authentifier l'utilisateur avec Twilio Voice à l'aide d'un jeton d'accès.
Le jeton d'accès doit être généré sur votre serveur backend à l'aide de vos identifiants Twilio. Ce jeton est requis pour passer et recevoir des appels à l'aide de Twilio Voice.
import { CapacitorTwilioVoice } from '@capgo/capacitor-twilio-voice';
const result = await CapacitorTwilioVoice.login({ accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'});console.log('Login successful:', result.success);Se déconnecter de l'utilisateur actuel et se désinscrire de Twilio Voice.
Cela déconnectera tous les appels actifs et arrêtera le dispositif de recevoir de nouvelles notifications d'appels entrants.
import { CapacitorTwilioVoice } from '@capgo/capacitor-twilio-voice';
const result = await CapacitorTwilioVoice.logout();console.log('Logout successful:', result.success);isLoggedIn
Section intitulée “estConnecté”Vérifier si l'utilisateur est actuellement connecté et possède un jeton d'accès valide.
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
Section intitulée “makeCall”Initier une appel sortant vers un numéro de téléphone ou un client.
L'utilisateur doit être connecté avant de passer un appel. L'appel sera acheminé à travers votre configuration de backend Twilio.
import { CapacitorTwilioVoice } from '@capgo/capacitor-twilio-voice';
// Call a phone numberconst result = await CapacitorTwilioVoice.makeCall({ to: '+1234567890'});console.log('Call SID:', result.callSid);
// Call another Twilio client with a readable name for CallKit Recentsawait CapacitorTwilioVoice.makeCall({ to: 'client:alice', displayName: 'Alice Smith'});
// Call a PSTN number using a specific caller IDawait CapacitorTwilioVoice.makeCall({ to: '+1234567890', callerId: '+10987654321'});acceptCall
Section intitulée “acceptCall”Accepter un appel entrant.
Cela doit être appelé en réponse à un événement ‘callInviteReceived’.
import { CapacitorTwilioVoice } from '@capgo/capacitor-twilio-voice';
CapacitorTwilioVoice.addListener('callInviteReceived', async (data) => { console.log('Incoming call from:', data.from); const result = await CapacitorTwilioVoice.acceptCall({ callSid: data.callSid }); console.log('Call accepted:', result.success);});rejectCall
Section intitulée “rejectCall”Rejeter un appel entrant.
Cela doit être appelé en réponse à un événement ‘callInviteReceived’. Le appelant entendra un signal occupé ou sera redirigé vers le messagerie vocale.
import { CapacitorTwilioVoice } from '@capgo/capacitor-twilio-voice';
CapacitorTwilioVoice.addListener('callInviteReceived', async (data) => { if (shouldRejectCall(data.from)) { await CapacitorTwilioVoice.rejectCall({ callSid: data.callSid }); }});endCall
Section intitulée “endCall”Terminer une appel en cours.
Si callSid n'est pas fourni, cela terminera l'appel en cours.
import { CapacitorTwilioVoice } from '@capgo/capacitor-twilio-voice';
// End the current active callawait CapacitorTwilioVoice.endCall({});
// End a specific callawait CapacitorTwilioVoice.endCall({ callSid: 'CA1234567890abcdef'});muteCall
Section intitulée “muteCall”Mettre le microphone en mode sur/mous ou le désactiver pendant une appel en cours.
Lorsque le microphone est mis en mode sur/mous, la partie adverse ne pourra pas entendre l'audio provenant de votre microphone.
import { CapacitorTwilioVoice } from '@capgo/capacitor-twilio-voice';
// Mute the microphoneawait CapacitorTwilioVoice.muteCall({ muted: true});
// Unmute the microphoneawait CapacitorTwilioVoice.muteCall({ muted: false});setSpeaker
Section intitulée “setSpeaker”Activer ou désactiver le mode haut-parleur.
Lorsque le mode haut-parleur est activé, l'audio sera acheminé vers le haut-parleur du dispositif au lieu de l'écouteur.
import { CapacitorTwilioVoice } from '@capgo/capacitor-twilio-voice';
// Enable speakerphoneawait CapacitorTwilioVoice.setSpeaker({ enabled: true});
// Disable speakerphoneawait CapacitorTwilioVoice.setSpeaker({ enabled: false});getCallStatus
Section intitulée “getCallStatus”Obtenez l'état actuel d'appel en cours.
Cela fournit des informations en temps réel sur l'état d'appel, le statut de la souris, le statut de mise en attente, et les identifiants d'appel.
import { CapacitorTwilioVoice } from '@capgo/capacitor-twilio-voice';
const status = await CapacitorTwilioVoice.getCallStatus();if (status.hasActiveCall) { console.log('Call SID:', status.callSid); console.log('Call State:', status.callState); console.log('Is Muted:', status.isMuted); console.log('Is On Hold:', status.isOnHold);}checkMicrophonePermission
Section intitulée “checkMicrophonePermission”Vérifiez si la permission de microphone a été accordée.
Cela ne demande pas la permission, mais vérifie uniquement le statut de permission actuel.
import { CapacitorTwilioVoice } from '@capgo/capacitor-twilio-voice';
const result = await CapacitorTwilioVoice.checkMicrophonePermission();if (!result.granted) { console.log('Microphone permission not granted');}requestMicrophonePermission
Section intitulée “requestMicrophonePermission”Demandez la permission de microphone à l'utilisateur.
Sur iOS et Android, cela affichera le dialogue de permission système si la permission n'a pas encore été accordée. Si la permission a été précédemment refusée, l'utilisateur doit peut-être la accorder dans les paramètres système.
import { CapacitorTwilioVoice } from '@capgo/capacitor-twilio-voice';
const result = await CapacitorTwilioVoice.requestMicrophonePermission();if (result.granted) { console.log('Microphone permission granted');} else { console.log('Microphone permission denied');}Référence de type
Section intitulée « Référence de type »CallInvite
Section intitulée « Appel d'invitation »Capacitor plugin pour intégrer la fonctionnalité de voix Twilio dans les applications mobiles.
export interface CallInvite { /** Unique identifier for the incoming call invitation */ callSid: string; /** Phone number or client identifier of the caller (may include custom caller name) */ from: string; /** Phone number or client identifier being called */ to: string; /** Custom parameters passed with the call invitation */ customParams: Record<string, string>;}Source de vérité
Section intitulée « Source de vérité »Cette page est générée à partir du plugin's src/definitions.tsRe-run la synchronisation lorsque les modifications publiques API se produisent en amont.
Continuer depuis Getting Started
Section intitulée « Continuer depuis Getting Started »Si vous utilisez Démarrage pour planifier le tableau de bord et les opérations API, connectez-le à Utilisation de @capgo/capacitor-twilio-voice pour la capacité native dans Utilisation de @capgo/capacitor-twilio-voice, Présentation de API pour le détail d'implémentation dans Présentation de API, Introduction pour le détail d'implémentation dans Introduction, Clés de API pour le détail d'implémentation dans Clés de API, et Appareils pour le détail d'implémentation dans Appareils.