Quick Start
The following example shows a basic example of creating an assistant to join a room and send a chat message
Getting Started
Create your assistant in the Whereby dashboard
Visit Configure > Assistant and create an assistant
Grab your assistant key

Import polyfills and initialize assistant
import "@whereby.com/assistant-sdk/polyfills";
const assistant = new Assistant({ assistantKey: "my-assistant-key" });
Have the assistant join the room:
assistant.joinRoom("https://your-subdomain.whereby.com/your-room-name");
Start using your assistant!
assistant.sendChatMessage("Hello! I'm your assistant, how can I help you?");
function main() {
const assistant = new Assistant({ assistantKey: "my-assistant-key" });
assistant.joinRoom("https://your-subdomain.whereby.com/your-room-name");
assistant.sendChatMessage("Hello! I'm your assistant, how can I help you?");
}
Using Trigger API
If you'd like the assistant to join the room automatically, you can make some small tweaks to our first example to use our webhook trigger API. This way, you can listen for certain webhook events and create your assistant whenever those webhooks are received! You should still follow step 1 in the above tutorial to obtain the assistant key.
Create your assistant in the Whereby dashboard
Visit Configure > Assistant and create an assistant
Grab your assistant key
❗Make sure to set the endpoint URL in the configuration steps to receive webhooks
Set up start trigger
let hasAssistantJoined = false;
const trigger = new Trigger({
webhookTriggers: {
"room.client.joined": () => !hasAssistantJoined,
},
port: 3000,
});
Start the trigger server
trigger.start();
Listen for the
TRIGGER_EVENT_SUCCESS
event - this indicates that the trigger predicate has been a match, and that your assistant should now join the room. Here, you can create the assistant and join the room and then listen for a ASSISTANT_JOINED_ROOM event before sending a chat message in to the connected room.
trigger.on(TRIGGER_EVENT_SUCCESS, ({ roomUrl }) => {
const assistant = new Assistant({ assistantKey: "my-assistant-key" });
assistant.joinRoom("https://your-subdomain.whereby.com/your-room-name");
assistant.on(ASSISTANT_JOINED_ROOM, () => {
assistant.sendChatMessage("Hello! I'm your assistant, how can I help you?");
})
});
If you’re using combined audio, wait for
AUDIO_STREAM_READY
- this event will return the a single track capturing all audio in a Whereby room.
assistant.on(AUDIO_STREAM_READY, ({ track }) => {
console.log("Assistant audio track ready!");
});
Start building! Here’s a minimal example, using the trigger API and creating an assistant that will send a chat message into the session.
let hasAssistantJoined = false;
function main() {
const trigger = new Trigger({
webhookTriggers: {
"room.client.joined": () => !hasAssistantJoined,
},
port: 3000,
});
trigger.start();
trigger.on(TRIGGER_EVENT_SUCCESS, ({ roomUrl }) => {
console.log("Webhook has been triggered!");
const assistant = new Assistant({ assistantKey: "my-assistant-key" });
assistant.joinRoom("https://your-subdomain.whereby.com/your-room-name");
assistant.on(ASSISTANT_JOINED_ROOM, () => {
assistant.sendChatMessage("Hello! I'm your assistant, how can I help you?");
assistant.on(AUDIO_STREAM_READY, ({ track }) => {
console.log("Assistant audio track ready!");
});
});
});
}
This demonstrates the most basic functionality of the library. From this example, you can go on to implement more advanced functionality that is explained in more detail in the next sections of the documentation: API Reference.
Additionally, you can take a look at the source code for an example Whereby Assistant that is published on Github here: https://github.com/whereby/whereby-assistant-audio-recorder.
Last updated
Was this helpful?