No commit activity in last 3 years
No release in over 3 years
Rack middleware for Discord Interaction validation.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 13.0.3
~> 3.10.0
~> 1.9.1
~> 0.9.26

Runtime

>= 1.0.0, < 2.0.0
>= 2.0.0, < 3.0.0
 Project Readme

Rack::DiscordInteractions

Middleware to handle signature verification for Discord Interaction HTTP requests.

Installation

Add this line to your application's Gemfile:

gem 'rack-discord-interactions'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install rack-discord-interactions

Usage

require 'sinatra'
require 'rack/discord-interactions'
require 'json'

use Rack::DiscordInteractions::Verifier, ENV['INTERACTIONS_PUBLIC_KEY'], path: '/interactions'

post '/interactions' do
  body = JSON.parse(request.body.read)

  case body['type']
  when 2 # COMMAND
    { type: 5 }.to_json
  else
    halt 400, 'Invalid type'
  end
end

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/shardlab/rack-discord-interactions. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Rack::DiscordInteractions project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.