try { // Send the original date and timezone offset to the server, which will perform the date conversion const result = await fetch("https://api-date.voiceflow.fr/date", { method: 'POST', headers: { "Content-Type": "application/json", }, body: JSON.stringify({ date: originalDate, tz: Number(timezoneOffset) }) });
// SUCCESS - Output the parsed dates const responseBody = result?.json; if (responseBody.date) { let date = new Date(responseBody.date); return { outputVars: { ISODate: responseBody.date, humanReadableDate: date.toLocaleString() }, next: { path: 'success' }, trace: [ { type: 'debug', payload: { message: `Converting string "${originalDate}" to ${responseBody.date}` } } ], } }
// FAILURE - The server gave an error response, so report that back to the designer return { outputVars: { error: `Unable to convert the given date` }, next: { path: 'error' }, trace: [ { type: 'debug', payload: { message: `API response error while trying to convert the given date` } } ], } } catch (error) { return { outputVars: { error }, next: { path: 'error' }, trace: [ { type: 'debug', payload: { message: error } } ], } } }