gr2m / helpdesk

Answering all your GitHub API/automation questions live on Twitch
https://twitch.tv/gregorcodes
Creative Commons Zero v1.0 Universal
22 stars 11 forks source link

πŸ“… 5/17 @ noon PT - Automating gr2m/helpdesk, Episode II #14

Closed gr2m closed 3 years ago

gr2m commented 3 years ago

πŸ’πŸ» Automating gr2m/helpdesk, Episode II πŸ“… Monday, May 17th, 2021 πŸ• noon Pacific Time (in your timezone) πŸŽ™οΈ no guests 🏷️ Automation


Subscribe to this issues to get a notification before the show begins and a summary after the show concludes.

Automating gr2m/helpdesk

I've laid out the current process for this repository at https://github.com/gr2m/helpdesk/tree/f085060fb98f61a005c9e79df15fdad6466c6a1a#how-i-use-this-repository. It's mostly manual. Time to spice it up a bit with some automation!

In this show, I'll try to automate the tweeting and comments on the issue belonging to the show.

Outline

  1. Quick review of what I've build so far in episode I
  2. Walkthrough of how I currently do the tweets and comments manually
  3. Figure out a way to automate it :grin:

Preparation

Recording

image

Shownotes

gr2m commented 3 years ago

Some notes ahead of the show 😁

In order to send scheduled tweets from your own account, you need to

  1. Register a GitHub App (these twitter-together docs might help
  2. Apply for the Twitter Ads API (these twitter-together docs might help

No idea why scheduling a tweet requires access to a dedicated Ads API but here we are. The twitter-together docs might be outdated, twitter is changing things all the time. pull requests welcome :)

Here are some snippets.

instantiate twitter and set userId and add account ID

const Twitter = require("twitter");
const twitter = new Twitter({
  consumer_key: process.env.TWITTER_CONSUMER_KEY,
  consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
  access_token_key: process.env.TWITTER_ACCESS_TOKEN_KEY,
  access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET,
});

// get account ID at https://ads.twitter.com/, press on "Create an ad", then
// copy the part the 2nd segment of the URL path, e.g.
// https://ads.twitter.com/onboarding/6zy0c/welcome?onboarding=true => 6zy0c
const accountId = "6zy0c";

// Get your Twitter account's user ID at https://codeofaninja.com/tools/find-twitter-id
const userId = "11754732";

List scheduled tweets

twitter.get(
  `https://ads-api.twitter.com/9/accounts/${accountId}/scheduled_tweets`,
  (error, result) => {
    if (error) {
      console.log(error);
      return;
    }

    console.log(result);
  }
);

Create a new scheduled tweet

twitter.post(
  `https://ads-api.twitter.com/9/accounts/${accountId}/scheduled_tweets`,
  {
    scheduled_at: "2021-05-17T18:30:00Z",
    as_user_id: userId,
    text:
      "πŸ”΄ Going live in 30 minutes: Automating gr2m/helpdesk, Episode II\n\nhttps://github.com/gr2m/helpdesk/issues/14",
    nullcast: true,
  },
  (error, result) => {
    if (error) {
      console.log(`error`);
      console.log(error);
      return;
    }

    console.log(result);
  }
);
gr2m commented 3 years ago

Twitter API documentation for scheduled tweets: https://developer.twitter.com/en/docs/twitter-ads-api/creatives/api-reference/scheduled-tweets

gr2m commented 3 years ago

I mentioned https://github.com/octokit/webhooks/ in the show. It has very complete JSON schemas and payload examples for all of GitHub's webhook event requests. Much more complete than what GitHub has on its own developer docs. It's a great @octokit community initiative by @wolfy1339 and other contributors

gr2m commented 3 years ago

Recording is now available on twitch: https://www.twitch.tv/videos/1026105427

image

gr2m commented 3 years ago

The video is now archived on YouTube: https://youtu.be/9Y68cC7nR68

Feel free to add comments if you have more questions