itchy-amethyst
itchy-amethyst15mo ago

Integrating Squads into the Web Snippet

I need some help with integrating a squad into the web snippet. For reference, the current web snippet in the docs is as below: <script> var vapiInstance = null; const assistant = "<assistant_id>"; // Substitute with your assistant ID const apiKey = "<your_public_api_key>"; // Substitute with your Public key from Vapi Dashboard. const buttonConfig = {}; // Modify this as required (function (d, t) { var g = document.createElement(t), s = d.getElementsByTagName(t)[0]; g.src = "https://cdn.jsdelivr.net/gh/VapiAI/html-script-tag@latest/dist/assets/index.js"; g.defer = true; g.async = true; s.parentNode.insertBefore(g, s); g.onload = function () { vapiInstance = window.vapiSDK.run({ apiKey: apiKey, // mandatory assistant: assistant, // mandatory config: buttonConfig, // optional }); }; })(document, "script"); </script> Right now, I have a web snippet like the above in my web page that activates an assistant I created in the dashboard. But now I have updated my assistant to be part of a squad, meaning my original assistant now has a couple of other assistants its able to pass on the call to. I want to add this new squad into the web snippet. How? I'm aware that I can replace the <assistant_id> section with JSON for a complete assistant. But for a squad, should I simply replace the 'const asssistant' part with 'const squad' and then insert the JSON for the squad?
19 Replies
Vapi
Vapi15mo ago
Relevant threads
These are relevant threads you might take a look into before continuing further: - <#1227945181240758292> - <#1247544016275505192> - <#1238077741903904828> - <#1241519757941805279> - <#1243678715129495683> - <#1248214911050317834> - <#1248212984518672435> - <#1248134802859757618> - <#1243281525731102720>
Vapi
Vapi15mo ago
@JM Absolutely, you're on the right track! To integrate your squad into the web snippet, you will indeed replace the const assistant with const squad and then provide the JSON configuration for the squad. Here's how you can modify your existing snippet:
<script>
var vapiInstance = null;
const squad = {
"squadId": "<squad_id>", // Substitute with your squad ID
"assistants": [
// Add your assistant configurations here
{
"assistantId": "<assistant_id_1>",
"publicApiKey": "<public_api_key_1>"
},
{
"assistantId": "<assistant_id_2>",
"publicApiKey": "<public_api_key_2>"
}
// ... add more assistants as needed
]
};
const buttonConfig = {}; // Modify this as required

(function (d, t) {
var g = document.createElement(t),
s = d.getElementsByTagName(t)[0];
g.src =
"https://cdn.jsdelivr.net/gh/VapiAI/html-script-tag@latest/dist/assets/index.js";
g.defer = true;
g.async = true;
s.parentNode.insertBefore(g, s);

g.onload = function () {
vapiInstance = window.vapiSDK.run({
squad: squad, // Use the squad configuration instead of a single assistant
config: buttonConfig, // optional
});
};
})(document, "script");
</script>
<script>
var vapiInstance = null;
const squad = {
"squadId": "<squad_id>", // Substitute with your squad ID
"assistants": [
// Add your assistant configurations here
{
"assistantId": "<assistant_id_1>",
"publicApiKey": "<public_api_key_1>"
},
{
"assistantId": "<assistant_id_2>",
"publicApiKey": "<public_api_key_2>"
}
// ... add more assistants as needed
]
};
const buttonConfig = {}; // Modify this as required

(function (d, t) {
var g = document.createElement(t),
s = d.getElementsByTagName(t)[0];
g.src =
"https://cdn.jsdelivr.net/gh/VapiAI/html-script-tag@latest/dist/assets/index.js";
g.defer = true;
g.async = true;
s.parentNode.insertBefore(g, s);

g.onload = function () {
vapiInstance = window.vapiSDK.run({
squad: squad, // Use the squad configuration instead of a single assistant
config: buttonConfig, // optional
});
};
})(document, "script");
</script>
Make sure to replace <squad_id>, <assistant_id_1>, <public_api_key_1>, <assistant_id_2>, and <public_api_key_2> with the actual IDs and keys from your Vapi dashboard. This configuration will allow your main assistant to pass the call to other assistants within the squad as needed. If you need any further assistance or have additional questions, feel free to ask! You can continue this conversation by mentioning me in the message. Got it. Tagging @Vapi Team for additional help.
itchy-amethyst
itchy-amethystOP15mo ago
@Sahil just want to be sure the AI assistant got the above right. If not, hope you can help.
yelping-magenta
yelping-magenta15mo ago
You need to use Web SDK not the web snippet.
itchy-amethyst
itchy-amethystOP15mo ago
Is there a way at all to have squads working using the snippet/the web widget? I followed the video for the snippet/widget by @Jannis | Integraticus here: https://youtu.be/XOVt1qHmrlg?si=dSJBKJxsp4DZrhIo&t=375. It shows that the assistant will work if I paste in the assistant JSON, and am wondering if there's a way to do the same but with the squads JSON within the widget/snippet somewhere?
Jannis Moore | AI Automation
YouTube
How to Talk to Your Website Using AI | Vapi Tutorial
0Learn how to integrate AI voice assistants into your website with this step-by-step VAPI tutorial. No coding knowledge is required! Follow along as we build a custom dashboard, interact with the AI, and explore different setup options. Perfect for businesses looking to enhance user interaction on their websites. My resource hub: https://hub.i...
yelping-magenta
yelping-magenta15mo ago
I will ask the team to add it to the web snippet.
itchy-amethyst
itchy-amethystOP15mo ago
That would be awesome. I work in education, and I can tell you that this web widget feature, because it’s much more user friendly then the sdk, is going to get used by lots of people in the industry. Hi @Sahil . Great developments with getting squads in the dashboard. Would it work via the web snippet now, and if so, any tips on how?
yelping-magenta
yelping-magenta15mo ago
Yeah, it is supported via web snippet. You create a squad through dashboard and just pass the squadID
itchy-amethyst
itchy-amethystOP15mo ago
That's awesome news. I created a squad through the dashboard and created a web snippet which I added to the html of my page. It's as follows: <!-- Vapi Web Snippet with Squad --> <script> var vapiInstance = null; const squad = "<I-put-my-squad-ID-here>"; // Your squad ID const apiKey = "<I-put-my-public-api-key-here>"; // Substitute with your Public key from Vapi Dashboard. const buttonConfig = { // ... (button configuration remains the same) }; (function (d, t) { var g = document.createElement(t), s = d.getElementsByTagName(t)[0]; g.src = "https://cdn.jsdelivr.net/gh/VapiAI/html-script-tag@latest/dist/assets/index.js"; g.defer = true; g.async = true; s.parentNode.insertBefore(g, s); g.onload = function () { vapiInstance = window.vapiSDK.run({ apiKey: apiKey, // mandatory squad: squad, // Use 'squad' instead of 'assistant', maintaining the same structure config: buttonConfig, // optional }); }; })(document, "script"); </script> Unfortunately, the call appears to connect and then immediately fail. In the logs, I get an error, but it doesn't even appear to be the assistant/squad I'm trying to call (there's no 'Mary' assistant I'm using)? I know the squad is working in the dashboard. Call ID if you need it is: eb053500-61c6-47d4-a5f2-bb0a61061598. Is my snippet written correctly? Is there something else I'm missing?
No description
exotic-emerald
exotic-emerald15mo ago
11Labs Voice Id: uCn98X6tKa49TnMFbwg6 The voice_id_does_not_exist so try to syncing the voice.
itchy-amethyst
itchy-amethystOP15mo ago
That’s what I thought but the squad and assistants in them work via the dashboard fine. And the assistant mentioned in the error (Mary) is not my assistant. Is my code for the web snippet correct?
yelping-magenta
yelping-magenta15mo ago
@JM Can you provide the squad configuration that you are sending?
exotic-emerald
exotic-emerald15mo ago
Yes your code is correct.
Linear
Linear15mo ago
Issue VAP-1558 created.
VAP-1558 - Cannot create call using web snippet and squad
using web snippet to create call by passing squad_id into squad input parameter results into pipeline-error-11labs-voice-not-found although it is working using dashboard and api, and same is visible over call logs for call created using web snippet and squad_id.
Status
Todo
Assignee
shubham@vapi.ai
Vapi
itchy-amethyst
itchy-amethystOP15mo ago
I set up the squad via the dashboard, not the API. Below is the configuration returned when I ran a 'Get Squad' API call. For context, my squad only has two assistants, the first passes the call onto the second: { "id": "c2fb7360-b4c8-4ea3-8074-09237307d6b3", "orgId": "cea49a9a-9b51-482c-9ae9-38f7ef1cd8b1", "createdAt": "2024-06-24T12:58:40.230Z", "updatedAt": "2024-06-24T12:59:03.817Z", "members": [ { "assistantId": "468ccfc1-a4bc-4d8c-b934-47fcb776d02b", "assistantDestinations": [ { "type": "assistant", "assistantName": "[redacted for Discord]" } ] }, { "assistantId": "ec7ce717-312d-41f7-937c-bd13e70c26cb", "assistantDestinations": [] } ] }
exotic-emerald
exotic-emerald15mo ago
The config is correct.
adverse-sapphire
adverse-sapphire14mo ago
Hi, this code did not work here is a configuration that did work but the call was not being transfered to other assistants and it only stayed on the first assistant <script> var vapiInstance = null; const squad = { "members": [ { "assistantId": "<First assistant ID>"
}, { "assistantId": "<Second assistant ID>""
}, { "assistantId": "<Thiirst assistant ID>"
} ] }; const buttonConfig = { }; (function (d, t) { var g = document.createElement(t), s = d.getElementsByTagName(t)[0]; g.src = "https://cdn.jsdelivr.net/gh/VapiAI/html-script-tag@latest/dist/assets/index.js"; g.defer = true; g.async = true; s.parentNode.insertBefore(g, s); g.onload = function () { vapiInstance = window.vapiSDK.run({ apiKey: "<my-api-key>", // Public api key squad: squad, config: buttonConfig }); }; })(document, "script"); </script> Can you tell me what am I missing?
Vapi
Vapi14mo ago
@Nehal Azhar It seems like there might be a misunderstanding in the squad configuration within the web snippet. The squad configuration should include the squadId rather than the individual assistantId values. Here's how you can adjust your snippet:
<script>
var vapiInstance = null;
const squadId = "<Your-Squad-ID>"; // Replace with your actual squad ID
const apiKey = "<Your-Public-API-Key>"; // Replace with your actual Public API key

const buttonConfig = {
// ... (button configuration remains the same)
};

(function (d, t) {
var g = document.createElement(t),
s = d.getElementsByTagName(t)[0];
g.src = "https://cdn.jsdelivr.net/gh/VapiAI/html-script-tag@latest/dist/assets/index.js";
g.defer = true;
g.async = true;
s.parentNode.insertBefore(g, s);

g.onload = function () {
vapiInstance = window.vapiSDK.run({
apiKey: apiKey,
squad: squadId, // Pass the squadId here
config: buttonConfig
});
};
})(document, "script");
</script>
<script>
var vapiInstance = null;
const squadId = "<Your-Squad-ID>"; // Replace with your actual squad ID
const apiKey = "<Your-Public-API-Key>"; // Replace with your actual Public API key

const buttonConfig = {
// ... (button configuration remains the same)
};

(function (d, t) {
var g = document.createElement(t),
s = d.getElementsByTagName(t)[0];
g.src = "https://cdn.jsdelivr.net/gh/VapiAI/html-script-tag@latest/dist/assets/index.js";
g.defer = true;
g.async = true;
s.parentNode.insertBefore(g, s);

g.onload = function () {
vapiInstance = window.vapiSDK.run({
apiKey: apiKey,
squad: squadId, // Pass the squadId here
config: buttonConfig
});
};
})(document, "script");
</script>
Make sure to replace <Your-Squad-ID> with the actual squad ID you obtained from the dashboard and <Your-Public-API-Key> with your public API key. If the call is not being transferred to other assistants within the squad, it could be due to the logic defined in your assistants or the squad settings. Ensure that the transfer conditions are set correctly and that the assistants are configured to handle transfers as expected. If you continue to experience issues, please provide the squad ID and the specific error messages you're encountering so that we can assist you further.
exotic-emerald
exotic-emerald14mo ago
please create a new ticket for this.

Did you find this page helpful?