Maak kennis met Eleven v4Maak kennis met Eleven v4, ons meest expressieve model tot nu toe.

Naar content

Voeg in enkele minuten een Santa-stemagent toe aan je React-app

Gepubliceerd

LuisterenLuister naar dit artikel

Voeg deze feestdagen Santa toe aan je app.

Met ElevenLabs Agents Platform en de @elevenlabs/react SDK kun je in slechts enkele minuten een Santa Claus-stemagent toevoegen aan je React-app. In deze handleiding gaan we:

  1. Een Santa Agent maken in het ElevenLabs-dashboard
  2. Deze koppelen in een React-component met WebRTC
  3. Een eenvoudige knop ‘Bel Santa’ toevoegen

1. Registreren en het Agents Platform openen

  1. Registreer je / log in bij ElevenLabs.
  2. Open bovenaan in de linkerzijbalk de platform switcher.
  3. Kies Agents Platform.

Je ziet een zijbalk met Agents, Knowledge Base, Tools en Voices onder het gedeelte ‘Build’.

2. Je Santa Agent maken

Vervolgens maken we een agent die zich gedraagt als Santa en spreekt met een Santa-stem.

  1. Klik in de zijbalk op Agents.
  2. Klik op + New Agent.
  3. Kies Blank Agent om vanaf nul te beginnen.

Noem hem: Santa.

Systeemprompt

Plak het volgende in het veld System Prompt:

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.

Eerste bericht

Stel First Message in op:

Ho, ho, ho! Vrolijk kerstfeest, mijn vriend. Vertel eens, hoe heet je?

Dit horen gebruikers wanneer het gesprek begint.

Stem

In het gedeelte Voice:

  • Kies ‘Jerry B. – Santa Claus’
  • Stem-ID: MDLAMJ0jxkpYkjXbmG4t

Nu klinkt Santa ook echt als Santa.

Beveiliging

Voor dit voorbeeld laten we de toegang open:

  • Controleer onder Security of Enable authentication is uitgeschakeld.

Voor je eerste demo kun je Enable Authentication gerust uitgeschakeld laten, zodat iedereen zonder beperkingen verbinding kan maken met de Agent. Dit versnelt onboarding en is ideaal voor snelle prototypes, hackathonprojecten of interne presentaties.

Voor elke productie- of extern toegankelijke applicatie mag je je Agent echter nooit open laten staan. Gebruik in plaats daarvan de ElevenLabs Token Endpoint om kortdurende, afgebakende toegangstokens voor elke gebruikerssessie te genereren. Zo houd je volledige controle over wie verbinding kan maken, hoelang de toegang duurt en welke acties de gebruiker mag uitvoeren. Door authenticatie in te schakelen bescherm je je Agent tegen ongeautoriseerde gesprekken, misbruik of gebruik buiten je beoogde limieten — en dat wordt sterk aanbevolen voordat je live gaat.

3. Je Agent ID ophalen

Bovenaan de Agent-pagina zie je een veld Agent ID.

Noteer deze waarde — in een latere stap plakken we deze in onze React-component:

agentId: "<AGENT_ID>"

4. De React SDK installeren

Installeer de ElevenLabs React SDK in je React- / Next.js-project:

npm install @elevenlabs/react

Daarna kunnen we de useConversation hook gebruiken om spraakgesprekken te starten en te stoppen.

5. De knop ‘Bel Santa’ toevoegen

Maak een nieuwe component, bijvoorbeeld CallSantaButton.tsx, en plak deze code:

"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>
  );
}

Vervang "<AGENT_ID>" nu door de daadwerkelijke Agent ID die je uit het dashboard hebt gekopieerd.

Render de knop vervolgens ergens in je UI, bijvoorbeeld:

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. Probeer het

Open het in je browser en klik op Start Call:

  1. Je browser vraagt om microfoonrechten.
  2. Er wordt een WebRTC-sessie gestart met je Santa Agent.
  3. Je hoort:

    ‘Ho, ho, ho! Vrolijk kerstfeest, mijn vriend. Vertel eens, hoe heet je?’

Daarna vraagt Santa naar je naam, verlanglijstje en wat je dit jaar hebt gedaan om op de Nice List te blijven.

Volgende stappen

Zodra de basis werkt, kun je:

  • De toegang tot Santa beperken met de beveiligingsinstellingen van de Agent
  • Van taal wisselen door de gebruikerslocale door te geven en dit door de prompt te laten afhandelen
  • De UI vormgeven met aangepaste knoppen, animaties of een volledig scherm ‘Bel Santa’

Maar de kern van de integratie bestaat alleen uit:

  • Eén Agent in het Agents Platform
  • Eén agentId
  • Een useConversation hook en een knop

Dat is alles wat je nodig hebt om realtime, conversationele Santa-magie naar je React-app te brengen.

Vergelijkbare artikelen

Creëer met AI-audio van de hoogste kwaliteit