Salta al contenuto

Aggiungi un Agente Voce di Babbo Natale alla tua app React in pochi minuti

Crea un agente vocale IA di Babbo Natale in tempo reale nella tua app React con ElevenLabs. Segui questa guida rapida passo dopo passo per offrire un'esperienza vocale natalizia, interattiva e coinvolgente con WebRTC e la piattaforma ElevenLabs Agents.

Agent Snippet

Per queste feste, aggiungi Babbo Natale alla tua app.

Con ElevenLabs Piattaforma Agents e l’SDK @elevenlabs/react, puoi inserire un agente vocale di Babbo Natale nella tua app React in pochi minuti. In questa guida vedrai come:

  1. Creare un Agente Babbo Natale nella dashboard di ElevenLabs
  2. Collegarlo a un componente React usando WebRTC
  3. Aggiungere un semplice pulsante “Chiama Babbo Natale”

1. Registrati e apri la Agents Platform

  1. Registrati / accedi a ElevenLabs.
  2. Nella barra laterale a sinistra, apri il selettore piattaforma in alto.
  3. Seleziona Piattaforma Agents.

Dovresti vedere una barra laterale con Agent, Knowledge Base, Strumenti e Voci nella sezione “Build”.

2. Crea il tuo Agente Babbo Natale

Ora creiamo un agente che si comporta come Babbo Natale e parla con la sua voce.

  1. Nella barra laterale, clicca su Agent.
  2. Clicca su + Nuovo Agente.
  3. Seleziona Agente Vuoto per partire da zero.

Chiamalo: Babbo Natale.

Prompt di sistema

Nel campo Prompt di sistema, incolla quanto segue:

You are a helpful assistant. You are Santa Claus, a jolly, warm, and humorous character from the North Pole. Christmas is just around the corner, and you love reminding everyone of the festive season with your hearty "Ho, ho, ho!" You are deeply in love with Mrs. Claus, often mentioning her incredible cookies.

When speaking to someone, keep your answers short and magical—just one festive sentence. Make it your top priority to ask for their name to check your naughty or nice list. Once you have their name, immediately ask about their wish-list, as it's crucial for your preparations. Always be warm and gentle.

Once their name and wish-list are covered, guide the conversation toward learning more about what they've done throughout the year and why they believe they deserve to be on Santa's Nice List. Use this opportunity to celebrate their kindness or achievements, reinforcing the importance of spreading goodness and holiday cheer. You also love asking about their plans for the holidays and showing genuine interest in their answers. Compliment them if you know they've done something kind or helpful recently, reinforcing the importance of spreading goodness.

Talk about your favorite gifts you've delivered or share quick, magical details about life at the North Pole, like mischievous elves or your reindeer team. Sprinkle in lighthearted jokes about your endless to-do list or how you struggle to resist cookies left out for you on Christmas Eve. Always express how much you love seeing people happy during the holidays and how their smiles make all your efforts worthwhile.

If the user makes a request involving inappropriate, harmful, or dangerous items such as weapons or items that go against the spirit of Christmas. Politely remind the user to make kind and festive wishes instead.

End every conversation with a warm farewell, suggesting you must return to your holiday preparations to ensure everyone gets their gifts on time. Wish them a Merry Christmas and encourage them to spread kindness and holiday cheer. Stay cheerful, engaging, and full of festive energy, spreading Christmas magic through humor, warmth, and storytelling.

Be sure to maintain the conversation in the user's selected language.

Primo messaggio

Imposta Primo Messaggio su:

Ho, ho, ho! Buon Natale, amico mio. Dimmi, come ti chiami?

Questo è ciò che gli utenti sentiranno quando inizia la chiamata.

Voce

Nella sezione Voce:

  • Seleziona “Jerry B. – Babbo Natale”
  • ID Voce: MDLAMJ0jxkpYkjXbmG4t

Ora Babbo Natale suonerà davvero come Babbo Natale.

Sicurezza

Per questo esempio, lasciamo tutto aperto:

  • Nella sezione Sicurezza, assicurati che Abilita autenticazione sia disattivato.

Per la tua prima demo, va benissimo lasciare Abilita autenticazione disattivato così chiunque può collegarsi all’Agente senza restrizioni. Questo velocizza l’onboarding ed è ideale per prototipi rapidi, hackathon o demo interne.

Tuttavia, per qualsiasi applicazione in produzione o accessibile dall’esterno, non dovresti mai lasciare il tuo Agente aperto. Usa invece l’Endpoint token di ElevenLabs per generare token di accesso temporanei e limitati per ogni sessione utente. In questo modo hai il pieno controllo su chi può collegarsi, per quanto tempo e quali azioni può eseguire. Abilitare l’autenticazione protegge il tuo Agente da chiamate non autorizzate, abusi o utilizzi fuori dai limiti previsti — ed è fortemente consigliato prima di andare live.

3. Recupera l’ID dell’Agente

In alto nella pagina dell’Agente, vedrai un campo ID dell’Agente.

Annota questo valore — lo incolleremo nel nostro componente React in uno dei prossimi passaggi:

agentId: "<AGENT_ID>"

4. Installa l’SDK React

Nel tuo progetto React / Next.js, installa l’SDK React di ElevenLabs:

npm install @elevenlabs/react

A questo punto puoi usare l’hook useConversation per avviare e terminare le chiamate vocali.

5. Aggiungi il pulsante "Chiama Babbo Natale"

Crea un nuovo componente, ad esempio CallSantaButton.tsx, e incolla questo codice:

"use client";

import { useConversation } from "@elevenlabs/react";
import { useCallback, useState } from "react";

export function CallButton() {
  const [hasPermission, setHasPermission] = useState(false);
  const [permissionError, setPermissionError] = useState<string | null>(null);

  const conversation = useConversation();

  const requestMicrophonePermission = useCallback(async () => {
    try {
      await navigator.mediaDevices.getUserMedia({ audio: true });
      setHasPermission(true);
      setPermissionError(null);
      return true;
    } catch {
      setPermissionError("Microphone access is required");
      return false;
    }
  }, []);

  const startCall = useCallback(async () => {
    const permitted = hasPermission || (await requestMicrophonePermission());
    if (!permitted) return;

    try {
      await conversation.startSession({
        agentId: "<AGENT_ID>",
        connectionType: "webrtc",
      });
    } catch (error) {
      console.error("Failed to start conversation:", error);
    }
  }, [conversation, hasPermission, requestMicrophonePermission]);

  const endCall = useCallback(async () => {
    await conversation.endSession();
  }, [conversation]);

  const isConnected = conversation.status === "connected";

  return (
    <div className="flex flex-col items-center gap-4">
      <button
        onClick={isConnected ? endCall : startCall}
        className={`px-6 py-3 rounded-lg text-white font-medium ${
          isConnected
            ? "bg-red-600 hover:bg-red-700"
            : "bg-green-600 hover:bg-green-700"
        }`}
      >
        {isConnected ? "End Call" : "Start Call"}
      </button>

      {isConnected && (
        <p className="text-sm text-gray-600">
          {conversation.isSpeaking ? "Agent speaking..." : "Listening..."}
        </p>
      )}

      {permissionError && (
        <p className="text-sm text-red-500">{permissionError}</p>
      )}
    </div>
  );
}

Ora sostituisci "<AGENT_ID>" con l’ID dell’Agente che hai copiato dalla dashboard.

Poi inserisci il pulsante dove preferisci nella tua UI, ad esempio:

import { CallButton } from "./CallSantaButton";

export default function HomePage() {
  return (
    <main className="min-h-screen flex flex-col items-center justify-center gap-6">
      <h1 className="text-3xl font-bold text-center">
        Call Santa 🎅
      </h1>
      <p className="text-gray-600">
        Press the button and talk to Santa in real time.
      </p>
      <CallButton />
    </main>
  );
}

6. Provalo

Apri la pagina nel browser e clicca su Avvia chiamata:

  1. Il browser ti chiederà il permesso per il microfono.
  2. Si avvia una sessione WebRTC con il tuo Agente Babbo Natale.
  3. Sentirai:

    “Ho, ho, ho! Buon Natale, amico mio. Dimmi, come ti chiami?”

Da qui, Babbo Natale ti chiederà il nome, la lista dei desideri e cosa hai fatto quest’anno per restare nella Lista dei Buoni.

Cosa fare dopo

Quando la base funziona, puoi:

  • Proteggere Babbo Natale con autenticazione usando le impostazioni di Sicurezza dell’Agente
  • Cambiare lingua passando la lingua utente e lasciando che il prompt la gestisca
  • Personalizzare la UI con pulsanti, animazioni o una schermata “Chiama Babbo Natale” su misura

Ma l’integrazione di base è solo:

  • Un Agente nella Piattaforma Agents
  • Un ID dell'agente
  • Un hook useConversation e un pulsante

Ti basta questo per portare la magia di Babbo Natale in tempo reale nella tua app React.

Scopri gli articoli del team ElevenLabs

Crea con l'audio IA della massima qualità