Skip to content

Instantly share code, notes, and snippets.

@seratch
Last active September 17, 2020 07:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seratch/fa84c639aaa3e678ccadc333dd4f174d to your computer and use it in GitHub Desktop.
Save seratch/fa84c639aaa3e678ccadc333dd4f174d to your computer and use it in GitHub Desktop.
Slack app built with Sinatra
require 'sinatra'
require 'slack-ruby-client'
Slack.configure do |config|
config.token = ENV['SLACK_BOT_TOKEN']
end
client = Slack::Web::Client.new
modal = {
'type': 'modal',
'title': {
'type': 'plain_text',
'text': 'My App'
},
'submit': {
'type': 'plain_text',
'text': 'Submit'
},
'blocks': [
{
'type': 'input',
'block_id': 'b',
'element': {
'type': 'plain_text_input'
},
'label': {
'type': 'plain_text',
'text': 'Label'
}
}
]
}
post '/slack/events' do
# TODO: verify signature here
if request.params['command']
client.views_open(
trigger_id: request.params['trigger_id'],
view: modal
)
[200, {}, '']
else
body = JSON.parse(request.params['payload'])
if body['type'] == 'view_submission'
response_body = {
'response_action': 'errors',
'errors': {
'b': 'The value is not valid'
}
}
[200, {'Content-Type' => 'application/json'}, JSON.dump(response_body)]
else
[200, {}, '']
end
end
end
# ruby app.rb -p 3000
# frozen_string_literal: true
source "https://rubygems.org"
gem "sinatra"
gem "slack-ruby-client"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment