I’m trying to get voiceflow to pass variable onto a pipedream, and then return some results back, ive tried using the built in api response but it dosnt seem to work in voiceflow using the repsponse or response.form values (ive tried get and post)
heres the code anyone any experiance in doing this back to voiceflow?
// To return a custom HTTP response, use $.respond() [requires HTTP trigger]
export default defineComponent({
async run({ steps, $ }) {
await $.respond({
status: 200,
header: {},
“body”: “hello world!”,
It seems like you’re trying to use Pipedream to receive data from Voiceflow and return a response. To achieve this, you’ll need to use an HTTP trigger in your Pipedream workflow. Here’s an example of how you can set up a Pipedream component to receive data from Voiceflow and return a custom HTTP response:
export default defineComponent({
async run({ steps, $ }) {
// You can access the data sent by Voiceflow using steps.trigger.event
const voiceflowData = steps.trigger.event;
// Process the data as needed and prepare the response
const responseBody = {
message: "Hello, world!",
voiceflowData: voiceflowData,
};
// Return the custom HTTP response
await $.respond({
status: 200,
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(responseBody),
});
},
});
Make sure to use an HTTP trigger for your Pipedream workflow. Once you’ve set up the workflow, you can use the unique URL provided by the HTTP trigger to send data from Voiceflow to Pipedream. In Voiceflow, use the API block to make a request to the Pipedream URL, and then you can access the response data in Voiceflow using the response variables.
I’m a bot powered by Pipedream and GPT-4. I’m still learning, so please double check my answers and code! Learn how to build your own.
Thanks a lot for that fantastic pointer, ive changed the code to send back the data i need, however in voiceflow when i store it in a variable it only shows [object,object] Instead of the text values any ideas
export default defineComponent({
async run({ steps, $ }) {
// You can access the data sent by Voiceflow using steps.trigger.event
const voiceflowData = steps.trigger.event;
// Process the data as needed and prepare the response
const responseBody = {
message: "Hello, world!",
events: steps.query_free_busy_calendars,
count: steps.query_free_busy_calendars.$return_value.calendars.primary.busy,
amount: steps.query_free_busy_calendars.$return_value.calendars.primary.busy[2],
voiceflowData: voiceflowData,
};
// Return the custom HTTP response
await $.respond({
status: 200,
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(responseBody),
});
},
});
so im trying to get from g-calendar a date and what busy periods there are, so that i can then offer a meeting on non busy times, here are the outputs sent back to voiceflow (in picture
Hi @4webster,
Would you mind trying again with this tweaked version:
export default defineComponent({
async run({ steps, $ }) {
// You can access the data sent by Voiceflow using steps.trigger.event
const voiceflowData = steps.trigger.event.body;
// Process the data as needed and prepare the response
const responseBody = {
message: "Hello, world!",
events: steps.query_free_busy_calendars,
count: steps.query_free_busy_calendars.$return_value.calendars.primary.busy,
amount: steps.query_free_busy_calendars.$return_value.calendars.primary.busy[2],
voiceflowData: voiceflowData,
};
// Return the custom HTTP response
await $.respond({
status: 200,
headers: {
"Content-Type": "application/json",
},
body: responseBody,
});
},
});
There are only two minor changes:
send only the body of the event (voiceflowData = steps.trigger.event.body)
send as JSON, not as stringified JSON (body: responseBody)
Thanks I’ve now sorted that now however i’ve found a “bug”, which i think is related to how pipedream uses some javascript calculating commands differently than running it on a pure javascript platform.
After not getting the results I wanted in pipedream I used a tool to run the javascript and used the console.log to see the values of the variables doing the calculations, and it calculates as it should , see Javascript Tester
I wanted to get whatever busy periods from a date in a calendar and calculate what free periods are left
these are the inputs busyCalendar = [
{“start”:“2023-08-13T09:00:00+01:00”,“end”:“2023-08-13T09:15:00+01:00”},
{“start”:“2023-08-13T10:15:00+01:00”,“end”:“2023-08-13T11:15:00+01:00”},
{“start”:“2023-08-13T12:30:00+01:00”,“end”:“2023-08-13T13:30:00+01:00”},
{“start”:“2023-08-13T14:50:00+01:00”,“end”:“2023-08-13T15:50:00+01:00”}
];
this script correctly ouputs ```
[{“start”:“2023-08-13T08:00:00.000Z”,“end”:“2023-08-13T08:59:00.000Z”},{“start”:“2023-08-13T09:16:00.000Z”,“end”:“2023-08-13T10:14:00.000Z”},{“start”:“2023-08-13T11:16:00.000Z”,“end”:“2023-08-13T12:29:00.000Z”},{“start”:“2023-08-13T13:31:00.000Z”,“end”:“2023-08-13T14:49:00.000Z”}]
but when I use the same code in a node script (including setting the variable in pipedream it incorrectly outputs [{"start":"2023-08-13T08:16:00.000Z","end":"2023-08-13T09:14:00.000Z"},{"start":"2023-08-13T10:16:00.000Z","end":"2023-08-13T11:29:00.000Z"},{"start":"2023-08-13T12:31:00.000Z","end":"2023-08-13T13:49:00.000Z"}]
ANY IDEAS?
Also is there any way to get code to output a variable to the screen, OR step though each line of code and interograte the variables so i can identfy where the changes in the code occur?
Many thanks for your time
The values contained in busyCalendar, etc. are strings. If you wrap them in Date objects, e.g., new Date(“2023-08-13T09:00:00+01:00”) then the function getTimezoneOffset() will be available in them.