This topic was automatically generated from Slack. You can find the original thread here.
can you give an example about how to use pipedream sse ?
This topic was automatically generated from Slack. You can find the original thread here.
can you give an example about how to use pipedream sse ?
Sure! Pipedream supports Server-sent Events (SSE) for subscribing to events from a server. Here’s an example of how to use Pipedream SSE in a browser: const eventSource = new EventSource("https://rt.pipedream.com/sse/YOUR_SOURCE_ID"); eventSource.onmessage = (event) => { console.log("New event received:", event.data); }; eventSource.onerror = (error) => { console.error("Error occurred:", error); };
Replace YOUR_SOURCE_ID
with the actual source ID of your Pipedream source. This code will listen for new events and log them to the console. For more information on Pipedream SSE, you can visit the documentation at https://pipedream.com/docs/sources/logs.
can you provide an example of a nodeJS step to send sse messages ?
Sure! Here’s an example of a Node.js step in a Pipedream workflow that sends SSE messages using the $.send.sse()
function: ```
import { defineComponent } from “pipedream”; export default defineComponent({ async run({ steps, $ }) { $.send.sse({ channel: “events”, // Required, corresponds to the event in the SSE spec payload: { // Required, the event payload name: “Luke Skywalker” } }); } });
i have an error when running this code :
const eventSource = new EventSource("https://rt.pipedream.com/sse/YOUR_SOURCE_ID");
eventSource.onmessage = (event) => {
console.log("New event received:", event.data);
};
eventSource.onerror = (error) => {
console.error("Error occurred:", error);
};
The error is it can’t GET the path.
I apologize for the confusion earlier. It seems there was a mistake in the URL format. Please update the URL in your code to the correct format: const eventSource = new EventSource("https://rt.pipedream.com/sse/YOUR_SOURCE_ID"); eventSource.onmessage = (event) => { console.log("New event received:", event.data); }; eventSource.onerror = (error) => { console.error("Error occurred:", error); };
Make sure to replace YOUR_SOURCE_ID
with the actual source ID of your Pipedream source. If you still encounter issues, please let me know and I’ll be happy to help.