# EventSub EventSub is a Ruby library for Twitch EventSub webhooks. It is built on the [ActiveSupport::Notifications API](http://api.rubyonrails.org/classes/ActiveSupport/Notifications.html). This is forked from [stripe_event](https://github.com/integrallis/stripe_event) and modified for use with Twitch EventSub. ## Install ```ruby # Gemfile gem "eventsub" ``` ```ruby # config/routes.rb mount EventSub::Engine, at: "/my-chosen-path" ``` ## Usage ```ruby # config/initializers/event_sub.rb EventSub.signing_secret = ENV['TWITCH_SIGNING_SECRET'] EventSub.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 ``` ### Subscriber objects that respond to #call ```ruby 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 ``` ```ruby EventSub.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: ```ruby EventSub.signing_secret = "abc123" ``` Please refer to [Twitch's documentation](https://dev.twitch.tv/docs/eventsub/handling-webhook-events/#verifying-the-event-message) for more details ### Support for multiple signing secrets You can also supply multiple secrets by sending an array to `signing_secrets` like so: ```ruby EventSub.signing_secrets = [ "abc123", "123abc" ] ``` ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/deanpcmad/eventsub-gem. ## License The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).