Botpress Cloud: Toolbox

Execute Code

This instruction is to execute custom code in a node. For example, fetching and displaying a user-submitted city’s weather information using an API.

Generative AI

Using natural language you can instruct AI to generate the needed code for your bot.

Example 1:

"I want to find the difference between the variables startDate and the endDate"

Generated Output:

1
const startDate = luxon.fromISO(workflow.startDate) // convert the startDate string to a luxon DateTime object
2
const endDate = luxon.fromISO(workflow.endDate) // convert the endDate string to a luxon DateTime object
3
const diffInDays = endDate.diff(startDate, 'days').toObject().days // find the difference between the two dates in days
4
// store the difference in days in the workflow variable 'dateDiff' as requested
5
workflow.dateDiff = diffInDays

Example 2:

"I want to get all my issues from Jira filtered by what is not done"

Generated Output:

1
const jiraUrl = 'https://your-jira-url.com'
2
const jiraUsername = 'your-jira-username'
3
const jiraPassword = 'your-jira-password'
4
5
// get the current date and time in ISO format
6
const now = luxon.local().toISO()
7
8
// create the JQL query to get all issues that are not done
9
const jql = `status != Done AND updated >= "${now}" ORDER BY updated DESC`
10
11
// set the request headers for Jira API
12
const headers = {
13
'Content-Type': 'application/json',
14
Authorization: `Basic ${Buffer.from(`${jiraUsername}:${jiraPassword}`).toString('base64')}`,
15
}
16
17
// make the request to Jira API to get all issues that are not done
18
const response = await axios.get(`${jiraUrl}/rest/api/2/search?jql=${jql}`, { headers })
19
20
// filter the response to only keep the issues that are not done
21
const issues = _.filter(response.data.issues, (issue) => issue.fields.status.name !== 'Done')

Advanced

You can build your own code here, using below node packages:

Using the above packages, you will be able fetch and display the user-submitted city's weather information using an API.