EventSubEvents
EventSub is a Ruby library for Twitch EventSub webhooks. It is built on the ActiveSupport::Notifications API.
This is forked from stripe_event and modified for use with Twitch EventSub.
Install
# Gemfile
gem "event_sub_events"
# config/routes.rb
mount EventSubEvents::Engine, at: "/my-chosen-path"
Usage
# config/initializers/event_sub_events.rb
EventSubEvents.signing_secret = ENV['TWITCH_SIGNING_SECRET']
EventSubEvents.configure do |events|
events.subscribe "channel.ban" do |event|
event.subscription
event.event
end
events.all do |event|
# Handle all event types - logging, etc.
end
end
When a webhook_callback_verification_pending
event is received, the event_sub_events
engine will return the
challenge
response automatically.
Subscriber objects that respond to #call
class CustomerCreated
def call(event)
# Event handling
end
end
class BillingEventLogger
def initialize(logger)
@logger = logger
end
def call(event)
@logger.info "BILLING:#{event.type}:#{event.id}"
end
end
EventSubEvents.configure do |events|
events.all BillingEventLogger.new(Rails.logger)
events.subscribe 'customer.created', CustomerCreated.new
end
Securing your webhook endpoint
Authenticating webhooks with signatures
Twitch will cryptographically sign webhook events with a signature which is included with a header sent with the request. Verifying this signature lets your application properly authenticate the request originated from Twitch.
Please set the signing_secret
configuration value:
EventSubEvents.signing_secret = "abc123"
Please refer to Twitch's documentation for more details
Support for multiple signing secrets
You can also supply multiple secrets by sending an array to signing_secrets
like so:
EventSubEvents.signing_secrets = [
"abc123",
"123abc"
]
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/deanpcmad/eventsub-events.
License
The gem is available as open source under the terms of the MIT License.