Use variables in code
If you need more flexibility in how you handle information in Botpress Studio, you can use variables in code (for example, in an Execute Code Card).
Here are a few examples of how you might use variables in code:
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
variabletype.variablename.workflow.orderNumber = 12345
conversation.cartTotal = 59.99
user.lastName = 'Smith'
bot.version = '1.2.3'
env.databaseURL = 'https://example.com/db'
if (user.firstName === 'John') {
console.log('Hello John!')
} else {
console.log('Welcome, user!')
}
function greetUser(firstName) {
console.log('Hello, ' + firstName + '!')
}
greetUser(user.firstName)
var fullName = user.firstName + ' ' + user.lastName
// or
var welcomeMessage = 'Hello, ' + user.firstName + ' ' + user.lastName + '!'
if (typeof workflow.userAcctId === 'number') {
workflow.userAcctId = 67890
} else {
console.error('Invalid type for userAcctId!')
}
const apiKey = env.API_KEY
const apiUrl = env.API_URL
const config = {
headers: {
Authorization: `Bearer ${apiKey}`,
},
}
const response = await axios.get(apiUrl, config)
const data = response.data
// Process the data as needed
// ...
// Example: Log the response data
console.log(data)
``` |
Was this page helpful?