Skip to content

joebew42/extensions_hello_world

Repository files navigation

ExtensionsHelloWorld

🚨 🚧 IT'S STILL A WORK IN PROGRESS 🚧 🚨

An example of a Twitch Extension written in Elixir.

The original source code is accessible here Extensions-Hello-World. You don't need to have the Extensions Developer Rig installed on your computer to play with this code. But if you consider to use this code as a base to build your own Twitch Extension, please consider to install the Rig, then.

Disclaimer

This example cover several topics regarding Clean Code, Clean Architecture, Crafted Design and Test-Driven Development. There are also [different points that are left deliberately open](issue page), which you can use to reflect and practice more. The code here is intented for an audience who wants to learn more about Clean Code and/or is looking for a new didactical content.

Setup

mix deps.get

Tests

mix test

Integration Tests

Remember to set the needed environment variables:

  • JWT_TOKEN_AUTHENTICATOR_SECRET is the Twitch Extension Secret
  • TWITCH_API_PUBLISHER_CLIENT_ID is the Twitch Client ID
  • TWITCH_API_PUBLISHER_OWNER_ID is the Twitch Owner ID
  • TWITCH_API_PUBLISHER_CHANNEL_ID is the Twitch Channel ID (needed to run TwitchAPIPublisherTest)
export JWT_TOKEN_AUTHENTICATOR_SECRET=<TWITCH EXTENSION SECRET>
export TWITCH_API_PUBLISHER_CLIENT_ID=<TWITCH EXTENSION CLIENT ID>
export TWITCH_API_PUBLISHER_OWNER_ID=<TWITCH OWNER ID>
export TWITCH_API_PUBLISHER_CHANNEL_ID=<TWITCH CHANNEL ID>

The run the integration tests

mix test --only integration

Start the application

Remember to set the needed environment variables:

  • JWT_TOKEN_AUTHENTICATOR_SECRET is the Twitch Extension Secret
  • TWITCH_API_PUBLISHER_CLIENT_ID is the Twitch Client ID
  • TWITCH_API_PUBLISHER_OWNER_ID is the Twitch Owner ID
export JWT_TOKEN_AUTHENTICATOR_SECRET=<TWITCH EXTENSION SECRET>
export TWITCH_API_PUBLISHER_CLIENT_ID=<TWITCH EXTENSION CLIENT ID>
export TWITCH_API_PUBLISHER_OWNER_ID=<TWITCH OWNER ID>

Start

mix run --no-halt

The server will listen at port 4001

Make a test call:

curl -v -X POST -H "Authorization: Bearer <JWT_TOKEN>" http://localhost:4001/color/cycle

The <JWT_TOKEN> is generated by the client and contains the information about channel_id and user_id

F.A.Q. on Twitch API

Q. What I've to specify as Twitch Channel Id ?

A. The Channel Id should be the same of Twitch Owner Id or can assume the value of all

For further information about Twitch Pub-System, consider to read the official documentation.

Q. How can I get my Twitch Owner Id ?

A. Make a call to Twitch:

curl -H "Client-ID: <TWITCH EXTENSION CLIENT ID>" -X GET "https://api.twitch.tv/helix/users?login=<YOUR CHANNEL NAME>"

You will get a response like that:

{
  "data": [
    {
      "id": <TWITCH OWNER ID>, <--- Bingo!
      "login": "YOUR CHANNEL NAME",
      "display_name": "YOUR DISPLAY NAME",
      "type": "",
      ...
    }
  ]
}

Q. How can I use Extensions Developer Rig ?

TBD