Is it possible to add dynamic variables while call...
# support
r
I know one can simply override the variables in the create call api in order to add the dynamic variable to the system model prompt of the assistant but how does one do it in a vapi web sdk ?
got my answer !
v
@Richard In the VAPI Web SDK, you can add dynamic variables to the system model prompt of the assistant by passing them as part of the configuration when you initialize a new call. Here's how you can do it: 1. Define your dynamic variables that you want to include in the system model prompt. 2. When you create a new call with the VAPI Web SDK, include these variables in the
customVariables
field of the call configuration object. Here's a sample code snippet to illustrate this:
Copy code
javascript
const vapi = new Vapi({
  // ... other configuration options
});

const customVariables = {
  userName: "John",
  accountNumber: "123456789"
};

vapi.createCall({
  // ... other call options
  customVariables: customVariables
});
In this example,
userName
and
accountNumber
are the dynamic variables that you want to pass to the assistant's system model prompt. When the call is created, these variables will be available for the assistant to use. Remember to replace
userName
and
accountNumber
with the actual variables you want to use, and ensure that the assistant's system model prompt is configured to utilize these variables appropriately. If you need more detailed instructions or have any issues, please ask support for more info on this.
You can continue this conversation by mentioning me in the message.
s
@Bowen
Copy code
ts
start(
    assistant?: CreateAssistantDTO | string,
    assistantOverrides?: AssistantOverrides,
    squad?: CreateSquadDTO | string,
  )
You need to pass your assistant as first parameter, overrides into second parameter.
Copy code
ts
start(assistantIdInsertsHere, assistantOverridesInsertsHere)
This is how a web call is created.
Copy code
ts
  async start(
    assistant?: CreateAssistantDTO | string,
    assistantOverrides?: AssistantOverrides,
    squad?: CreateSquadDTO | string,
  ): Promise<Call | null> {
    if (!assistant && !squad) {
      throw new Error('Assistant or Squad must be provided.');
    }

    if (this.started) {
      return null;
    }
    this.started = true;

    try {
      const webCall = (
        await client.call.callControllerCreateWebCall({
          assistant: typeof assistant === 'string' ? undefined : assistant,
          assistantId: typeof assistant === 'string' ? assistant : undefined,
          assistantOverrides,
          squad: typeof squad === 'string' ? undefined : squad,
          squadId: typeof squad === 'string' ? squad : undefined,
        })
      ).data;
@Richard do let me know if you require further help.
29 Views