Cr4shBarcode
Cr4shBarcode2mo ago

Best Way to List Multiple Responses (If They Exist) After API Call to Appointment Scheduler?

Currently working with Acuity Scheduling platform. After a GET request to fetch currently booked appointments for the user, the date and time of each appointment is listed as response.[i].date and response.[i].time where [i] is the appointment's position in the array. If the user has more than one appointment scheduled, what is the best method to relay the information while re-using the {date} and {time} variables? I'm trying to avoid creating dozens of unique variables in order to capture the information of each response.
No description
1 Reply
Tico | Voiceflow Assistant
Here’s a simple pattern that lets you surface any number of Acuity appointments without creating a new Voiceflow variable for every item. 1. API call ➜ capture the whole array
• In the API step, map the path that holds the list (usually just response) to a single VF variable, e.g. {appointments_raw}. • The value will come into Voiceflow as a JSON-encoded string. 2. Code / Function step ➜ build the message you need
export default async function main(args) {
// "appointments_raw" already exists – do not redeclare it
const apptArray = JSON.parse(args.inputVars.appointments_raw);

const listText = apptArray
.map(({ date, time }, i) => `• ${date} at ${time}`)
.join('\n');

return {
// show it to the user now …
trace: [{ type: 'text', payload: { message: `You have ${apptArray.length} upcoming appointment(s):\n${listText}` } }],
// …and/or store for later reuse
outputVars: { appointment_list: listText }
};
}
export default async function main(args) {
// "appointments_raw" already exists – do not redeclare it
const apptArray = JSON.parse(args.inputVars.appointments_raw);

const listText = apptArray
.map(({ date, time }, i) => `• ${date} at ${time}`)
.join('\n');

return {
// show it to the user now …
trace: [{ type: 'text', payload: { message: `You have ${apptArray.length} upcoming appointment(s):\n${listText}` } }],
// …and/or store for later reuse
outputVars: { appointment_list: listText }
};
}
3. Speak or display the result If you returned the trace above the user immediately sees the list. If you only returned outputVars, simply drop a Text step afterwards and reference {appointment_list}. Why this approach works
• You only ever store one raw array and (optionally) one formatted string.
• The function step can loop over any length array, so you never have to pre-create {date1}, {time1}, {date2} … variables.
• Need richer UI (buttons, cards, carousel)? In that same function build the corresponding traces – Voiceflow chat will render them automatically (see “Dynamically Render Voiceflow Steps”). Docs: https://docs.voiceflow.com

Did you find this page helpful?