Skip to content

Commit 5f0b132

Browse files
committed
Add script/console, fix channel inform on subscribe and unsubscribe.
1 parent 0f1aad2 commit 5f0b132

File tree

10 files changed

+57
-10
lines changed

10 files changed

+57
-10
lines changed

.env.sample

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
SLACK_CLIENT_ID=
2+
SLACK_CLIENT_SECRET=
3+
SLACK_VERIFICATION_TOKEN=
4+
SLACK_OAUTH_SCOPE=
5+
STRIPE_API_KEY=
6+
STRIPE_API_PUBLISHABLE_KEY=
7+
STRIPE_API_SUBSCRIPTION_PLAN_ID=

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ gem 'newrelic-slack-ruby-bot'
1010
gem 'slack-ruby-bot-server', github: 'slack-ruby/slack-ruby-bot-server'
1111
gem 'slack-ruby-bot-server-stripe', github: 'slack-ruby/slack-ruby-bot-server-stripe'
1212
gem 'unicorn'
13+
gem 'irb'
1314

1415
group :test do
1516
gem 'capybara'

Gemfile.lock

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
GIT
22
remote: git://github.com/slack-ruby/slack-ruby-bot-server-stripe.git
3-
revision: 72a04b49cc2911105e90abf079274307a1ce852c
3+
revision: 3c7e0de6c13ffab2a775a05a1c80e5847e12924e
44
specs:
55
slack-ruby-bot-server-stripe (0.1.0)
66
slack-ruby-bot-server (>= 0.12.0)
@@ -116,6 +116,9 @@ GEM
116116
domain_name (~> 0.5)
117117
i18n (1.8.2)
118118
concurrent-ruby (~> 1.0)
119+
io-console (0.5.6)
120+
irb (1.2.3)
121+
reline (>= 0.0.1)
119122
kaminari-core (1.2.0)
120123
kaminari-grape (1.0.1)
121124
grape
@@ -167,6 +170,8 @@ GEM
167170
raindrops (0.19.1)
168171
rake (13.0.1)
169172
regexp_parser (1.7.0)
173+
reline (0.1.4)
174+
io-console (~> 0.5)
170175
representable (3.0.4)
171176
declarative (< 0.1.0)
172177
declarative-option (< 0.2.0)
@@ -240,6 +245,7 @@ DEPENDENCIES
240245
database_cleaner
241246
fabrication
242247
faker
248+
irb
243249
mongoid
244250
mongoid-scroll
245251
newrelic-slack-ruby-bot

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@ Slack Ruby Bot Server Stripe Sample
77

88
A sample app based on [slack-ruby-bot-server-sample](https://github.com/slack-ruby/slack-ruby-bot-server-sample) that integrates with [Stripe](https://stripe.com) using [slack-ruby-bot-server-stripe](https://github.com/slack-ruby/slack-ruby-bot-server-stripe).
99

10+
### Running the Sample
11+
12+
Create `.env` file with the following settings.
13+
14+
```
15+
SLACK_CLIENT_ID=...
16+
SLACK_CLIENT_SECRET=...
17+
SLACK_VERIFICATION_TOKEN=...
18+
SLACK_OAUTH_SCOPE=bot,commands
19+
STRIPE_API_KEY=...
20+
STRIPE_API_PUBLISHABLE_KEY=...
21+
STRIPE_SUBSCRIPTION_PLAN_ID=...
22+
```
23+
24+
Run `bundle install` and `foreman start`.
25+
1026
### Copyright & License
1127

1228
Copyright [Daniel Doubrovkine](http://code.dblock.org), 2020

app.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
# frozen_string_literal: true
2+
ENV['RACK_ENV'] ||= 'development'
3+
4+
Bundler.require :default
25

36
Dir[File.expand_path('config/initializers', __dir__) + '/**/*.rb'].sort.each do |file|
47
require file
58
end
69

10+
Mongoid.load!(File.expand_path('config/mongoid.yml', __dir__), ENV['RACK_ENV'])
11+
712
require_relative 'lib/models'
813
require_relative 'lib/commands'

config.ru

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
# frozen_string_literal: true
22

3-
ENV['RACK_ENV'] ||= 'development'
4-
5-
Bundler.require :default
6-
73
require_relative 'app'
84

9-
Mongoid.load!(File.expand_path('config/mongoid.yml', __dir__), ENV['RACK_ENV'])
10-
115
NewRelic::Agent.manual_start
126

137
SlackRubyBotServer::App.instance.prepare!

config/initializers/slack_ruby_bot_server_stripe.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
SlackRubyBotServer::Stripe.configure do |config|
44
config.stripe_api_key ||= ENV['STRIPE_API_KEY']
55
config.stripe_api_publishable_key ||= ENV['STRIPE_API_PUBLISHABLE_KEY']
6-
config.subscription_plan_id ||= 'prod_HAevgsGOq8MCZZ'
6+
config.subscription_plan_id ||= 'plan_HAevT5j3xmP7a6'
77
config.subscription_plan_amount = 0
88
config.trial_duration = 2.weeks
99
config.root_url = ENV['URL'] || 'http://localhost:5000'

lib/commands/help.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ class Help < SlackRubyBot::Commands::Base
55
```
66
Sample bot that uses slack-ruby-bot-server-stripe.
77
8-
General
9-
-------
8+
Commands
9+
--------
1010
1111
help - get this helpful message
12+
subscription - get subscription info
13+
unsubscribe - unsubscribe
1214
1315
```
1416
EOS

lib/models/team.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ class Team
2323

2424
private
2525

26+
def slack_client
27+
@slack_client ||= Slack::Web::Client.new(token: token)
28+
end
29+
30+
def slack_channels
31+
slack_client.channels_list(
32+
exclude_archived: true,
33+
exclude_members: true
34+
)['channels'].select do |channel|
35+
channel['is_member']
36+
end
37+
end
38+
2639
def inform!(message)
2740
slack_channels.each do |channel|
2841
message_with_channel = message.merge(channel: channel['id'], as_user: true)

script/console

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
exec bundle exec irb -I . -r "app"

0 commit comments

Comments
 (0)