Skip to content

πŸ“… 10/21 @ 10:00am PT - Automating gr2m/helpdesk: Twitch EventsΒ #52

@gr2m

Description

@gr2m

πŸ’πŸ» Automating gr2m/helpdesk: Twitch Events
πŸ“… Thursday, October 21, 2021
πŸ• 10:00am Pacific Time
πŸŽ™οΈ no guests
πŸ“ https://www.twitch.tv/gregorcodes
🏷️ automation


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

Automating gr2m/helpdesk: πŸ“… 10/21 @ 10:00am PT - Automating gr2m/helpdesk: Twitch Events

Instead of using a schedule-based trigger for when a show starts, I'll start using webhooks sent from Twitch itself, whenever I start a stream.

Outline

  • Create a new repository handle-twitch-events-using-github-actions with a Netlify Function that responds to /.netlify/functions/ping
  • Setup continuous deployment of the repository using Netlify's GitHub App
  • Add a script to list, create, and delete Twitch subscriptions
  • Add a Netlify Function that will handle Twitch EventSub requests at POST /.netlify/functions/twitch and create repository dispatch events
  • Add a GitHub Action that gets triggered by the repository dispatch events

Bonus

  • In the gr2m/helpdesk repository, rreplace the current schedule trigger for the Handle show start workflow with the custom trigger when the webhook is received
  • Replace the current issues.closed trigger for the Handle show done workflow with the custom trigger when the webhook is received. Close the show issue

TODOs

Before the show

I already setup the Netlify function and the twitch subscription in the gr2m/helpdesk. I'll prepare the pieces so we can create a new repository from scratch step-by-step.

When show begins

After the show

Recording

screenshot of YouTube video player showing the recording of this episode

Shownotes

  • Demo repository I created during the show: https://github.com/gr2m/handle-twitch-events-using-github-actions
  • Netlify CLI: https://docs.netlify.com/cli/get-started/
    I used netlify dev to start a local server, netlify dev --live to start a local server with an http tunnel, so it's reachable by others, and netlify init to setup continuous deployment for the demo repository using Netlify
  • Twitch CLI: https://github.com/twitchdev/twitch-cli#readme
    • Send request to test subscription verification. -F is the URL the simulated webhook request should be sent to.
      twitch event verify-subscription subscribe -F http://localhost:8888/.netlify/functions/twitch
      
    • Get user account ID by login. You'll need your Twitch User Account ID to set the condition when creating the Twitch event subscription
      twitch api get users -q login=gregorcodes
      
    • Trigger a "stream.online" event. -s is the secret you defined when you created the subscription. -t is your account ID.
      twitch event trigger streamup -F http://localhost:8888/.netlify/functions/twitch -s secret -t 581268875
      
    • Trigger a "stream.offline" event
      twitch event trigger streamdown -F http://localhost:8888/.netlify/functions/twitch -s secret -t 581268875
      
  • To create/list/delete Twitch subscriptions, check out the script I added to the test repository at https://github.com/gr2m/handle-twitch-events-using-github-actions/blob/main/scripts/twitch-subscriptions.js

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions