Prise en main
Copiez un prompt de configuration incluant les étapes d'installation et le 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
Section intitulée « Installation »Vous pouvez utiliser notre configuration assistée par IA pour installer le plugin. Ajoutez les skills Capgo à votre outil d'IA avec la commande suivante :
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsUtilisez ensuite le prompt suivant :
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 une installation manuelle, installez le plugin en exécutant les commandes suivantes et suivez les instructions spécifiques à chaque plateforme ci-dessous :
npm install @capgo/capacitor-twilio-voicenpx cap syncImporter
Section intitulée « Import »import { CapacitorTwilioVoice } from '@capgo/capacitor-twilio-voice';Démarrage rapide
Section intitulée « Démarrage rapide »import { CapacitorTwilioVoice } from '@capgo/capacitor-twilio-voice';
await CapacitorTwilioVoice.login({ accessToken: tokenFromBackend });await CapacitorTwilioVoice.makeCall({ to: '+15551234567' });Erreurs courantes
Section intitulée « Erreurs courantes »- TTL du token: rafraîchir les tokens Twilio avant expiration.
- Entrant: configurer les push VoIP sur iOS.
- Permission micro: à demander avant de passer des appels.
Aperçu de API
Section intitulée « Aperçu API »Authentifiez l'utilisateur avec Twilio Voice à l'aide d'un access token.
L'access token doit être généré sur votre serveur backend en utilisant vos identifiants Twilio. Ce token est requis pour passer et recevoir des appels via Twilio Voice.
import { CapacitorTwilioVoice } from '@capgo/capacitor-twilio-voice';
const result = await CapacitorTwilioVoice.login({ accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'});console.log('Login successful:', result.success);Déconnectez l'utilisateur actuel et désinscrivez-le de Twilio Voice.
Cela coupera tous les appels en cours et empêchera l'appareil 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 « isLoggedIn »Vérifie si l'utilisateur est actuellement connecté et possède un token 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 »Initie un 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 routé via votre configuration 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 »Accepte un appel entrant.
Cette méthode doit être appelée 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.
Cette méthode doit être appelée en réponse à un événement « callInviteReceived ». L'appelant entendra une tonalité occupée ou sera redirigé vers la messagerie vocale.
import { CapacitorTwilioVoice } from '@capgo/capacitor-twilio-voice';
CapacitorTwilioVoice.addListener('callInviteReceived', async (data) => { if (shouldRejectCall(data.from)) { await CapacitorTwilioVoice.rejectCall({ callSid: data.callSid }); }});Terminer un appel en cours.
Si le callSid n'est pas fourni, cela terminera l'appel actuellement actif.
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 »Couper ou réactiver le micro pendant un appel en cours.
Lorsque le micro est coupé, l'autre partie n'entendra pas votre audio.
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.
Une fois activé, l'audio sera diffusé par le haut-parleur de l'appareil 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 »Récupérer le statut actuel de l'appel actif.
Cela fournit des informations en temps réel sur l'état de l'appel, le statut de la mise en sourdine, l'état de la ligne 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érifier si la permission du microphone a été accordée.
Ceci ne demande pas de permission, cela vérifie seulement l'état actuel des permissions.
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 »Demander l'autorisation d'utiliser le microphone à l'utilisateur.
Sur iOS et Android, cela affichera la boîte de dialogue système si l'autorisation n'a pas encore été accordée. Si l'autorisation a été refusée précédemment, l'utilisateur devra peut-être l'activer dans les paramètres du 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 « CallInvite »Le plugin Capacitor pour intégrer les fonctionnalités Twilio Voice dans vos 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 de src/definitions.ts. Relancez la synchronisation lorsque l’API public change en amont.
Continuer depuis Getting Started
Section intitulée « Continuer après Prise en main »Si vous utilisez Prise en main pour planifier les opérations du dashboard et de API, connectez-l’avec Utiliser @capgo/capacitor-twilio-voice pour la capacité native dans Utiliser @capgo/capacitor-twilio-voice, Aperçu de API pour les détails d'implémentation dans « Vue d'ensemble de API », Introduction pour les détails d'implémentation dans l'introduction, Clés API pour les détails d'implémentation dans « Clés API », et Appareils pour les détails d'implémentation dans Devices.