Blocks - How to set global variables?
# support
j
Specifically how do i set global variables dynamically as a call is created to the blocks agent, for eg customer data to be used in the first conversation block
v
@Juicifer To set global variables dynamically as a call is created to the blocks agent, you can use the
assistantOverrides
feature with
variableValues
to pass the customer data. This allows you to personalize the conversation by setting variables that the blocks agent can use in the first conversation block. Here's how you can do it: 1. Define the variables you want to set in your conversation blocks. For example, you might have a variable called
{{customerName}}
that you want to populate with the customer's name. 2. When starting the call, pass the
assistantOverrides
object along with
variableValues
to the API or SDK. Include the variables you want to set with their corresponding values. For example, if you want to set the customer's name to "John", you would pass the following object:
Copy code
json
{
  "variableValues": {
    "customerName": "John"
  }
}
This would replace
{{customerName}}
with "John" in the first conversation block where the variable is used. If you need to set multiple variables, you can add them to the
variableValues
object, like so:
Copy code
json
{
  "variableValues": {
    "customerName": "John",
    "customerAccountNumber": "123456789",
    "lastInteractionDate": "2023-03-15"
  }
}
Each key in the
variableValues
object corresponds to a variable in your conversation blocks, and the value is what you want to set the variable to for the current call. Remember to ensure that the variables you are setting are defined in your conversation blocks and are used appropriately to personalize the conversation. If you need further assistance with setting up dynamic variables or have any other questions, please feel free to ask.
You can continue this conversation by mentioning me in the message.
j
when i do that in the blocks graph it says Invalid Liquid variable format: {{bruh}}. Expected formats: {{ input.propertyName }}, {{ stepName.input.propertyName }}, {{ stepName.output.propertyName }}, {{ workflow.input.propertyName }}, or {{ global.propertyName }}
@Vapi
v
@Juicifer I apologize for the confusion. It seems there was a misunderstanding regarding the format of the variables you need to use within the blocks graph. The correct format for using variables in the blocks graph should adhere to the following patterns: -
{{ input.propertyName }}
for accessing input properties. -
{{ stepName.input.propertyName }}
or
{{ stepName.output.propertyName }}
for accessing properties from specific steps. -
{{ workflow.input.propertyName }}
for accessing workflow-level input properties. -
{{ global.propertyName }}
for accessing global properties. To set a global variable dynamically for use in the first conversation block, you should ensure that you are using the
global
prefix. For example, if you want to set a global variable named
customerName
, you would reference it in the blocks graph as
{{ global.customerName }}
. When you start a call and want to set this global variable, you would pass the customer data in the
variableValues
object with the key corresponding to the variable name, like so:
Copy code
json
{
  "variableValues": {
    "global.customerName": "John"
  }
}
This will set the global variable
customerName
to "John", which you can then use in your conversation blocks as
{{ global.customerName }}
. If you need further clarification or assistance with setting global variables in your blocks graph, please let me know, and I'll be happy to help!
j
Nope doing that doesn't actually update the variables in the call for the blocks to use
@User
@Shubham Bajaj
Call id where I tested this: d7c4ca75-4194-4fde-b74f-010088286168
@User @Shubham Bajaj
s
@Juicifer allow me sometime let me check on this with team.
j
Alright
s
@Juicifer We are rewriting blocks so it will changed after next year February so it's not worth to use blocks for development and production work. So, I suggest using assistants instead.
12 Views