-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
41 lines (32 loc) · 999 Bytes
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require "dotenv"
require "json"
require "roda"
require_relative "setupdb"
require_relative "handle_slash_command_request_job"
Dotenv.load
class App < Roda
route do |r|
r.root do
"Hello!"
end
r.post "nowplaying" do
slack_id = "#{r['user_id']}-#{r['team_id']}"
response_url = r['response_url']
HandleSlashCommandRequestJob.perform_async(slack_id:, response_url:)
response['Content-Type'] = 'application/json'
response.status = 200
{ response_type: "in_channel", text: "" }.to_json
end
r.get "spotify-callback" do
slack_id = r['state']
code = r['code']
refresh_token = Spotify.fetch_refresh_token_from(code:)
user = User.first(slack_id:)
user.spotify_token = refresh_token
user.save
response['Content-Type'] = 'application/json'
response.status = 200
JSON.generate({ message: "Authorization successful. You are now ready to use the /nowplaying command!" })
end
end
end