View Source TwitchEventSub.Plug (hello_twitch_eventsub v0.3.0)

Plug for TwitchEventSub webhooks.


For the plug to work, you need to add the :raw_body assign to the conn when your plugs read the body. We provide a custom body reader for you in TwitchEventSub.Plug.BodyReader and you should use this to read the body.

If you are using Phoenix (and Plug.Parsers), then it would look something like this:

# In Phoenix this would be in MyAppWeb.Endpoint.
plug Plug.Parsers,
  parsers: [:urlencoded, :json],
  pass: ["text/*"],
  body_reader: {TwitchEventSub.Plug.BodyReader, :read_body, []},
  json_decoder: Jason

Next, you would use this plug for a Twitch Webhook callback path. Something like this if you are using Phoenix:

# This passes some application config as the plug options.
forward "/twitch/callback", TwitchEventSub.Plug, Application.fetch_env!(:my_app, TwitchEventSub)

Options (required)

  • :webhook_secret - The secret you pass when you subscribe to an event.
  • :handler - The module that implements TwitchEventSub to handle events.