Is it possible to create a Pipedream workflow for leaving comments on YouTube?

Hi.

Is it possible to create a simple workflow to leave comments on YouTube when a new video is uploaded?

Thanks.

Hi @slishnevsky,

To create a workflow that leaves comments on YouTube videos when a new video is uploaded, you’ll need to use YouTube’s API to monitor for new videos and to post comments. However, based on the Pipedream documentation provided, there isn’t a direct mention of a pre-built YouTube trigger or action for monitoring new video uploads or posting comments.

Given this, you would typically follow these steps to achieve your goal, using custom code steps within a Pipedream workflow:

  1. Trigger: Use a Scheduler trigger to periodically check for new videos from a specific YouTube channel. Alternatively, if YouTube posts to a webhook on new video uploads, you could use an HTTP trigger.
  2. Action to Check for New Videos: Use a custom Node.js code step to call the YouTube Data API’s search.list method, filtering by the channel ID and ordering by date to find the most recent videos. You’ll need to store the ID of the last video you’ve processed (using Pipedream’s built-in data store or another method) to determine if there are any new videos since the last check.
  3. Action to Post Comments: For any new videos found, use another custom Node.js code step to call the YouTube Data API’s commentThreads.insert method to leave a comment on the video.

Here’s a simplified example of how you might write the code for the second and third steps in Node.js, assuming you have the necessary OAuth tokens and permissions to access the YouTube Data API:

// Step 2: Check for new videos
import { axios } from "@pipedream/platform";

async run({ steps, $ }) {
  const channelId = "CHANNEL_ID_HERE";
  const response = await axios($, {
    url: `https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=${channelId}&order=date&maxResults=1`,
    headers: {
      Authorization: `Bearer YOUR_ACCESS_TOKEN`,
    },
  });
  
  const latestVideoId = response.items[0].id.videoId;
  // Compare latestVideoId with the last stored video ID to determine if it's new
  // If new, proceed to post a comment using the code below
}

// Step 3: Post a comment on the new video
async run({ steps, $ }) {
  const videoId = "NEW_VIDEO_ID_HERE";
  const comment = "Your comment here";
  const response = await axios

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](https://pipedream.com/blog/build-your-own-chat-bot-with-openai-and-pipedream/).