Skip to content

Commit

Permalink
Merge pull request #529 from crossroads/master
Browse files Browse the repository at this point in the history
#July2018Release2
  • Loading branch information
namrataukirde authored Jul 17, 2018
2 parents bd92a3c + eae9e6b commit 9a97f0c
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ BRAINTREE_ENVIRONMENT=
BRAINTREE_MERCHANT_ID=
BRAINTREE_PUBLIC_KEY=
BRAINTREE_PRIVATE_KEY=

SLACK_API_TOKEN=
SLACK_PIN_CHANNEL=
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ gem 'kaminari'
gem 'sidekiq-scheduler'
gem 'rake-progressbar'
gem 'codeclimate-test-reporter'
gem 'slack-ruby-client'

group :development do
unless ENV["CI"]
Expand All @@ -75,7 +76,7 @@ group :development do
gem "spring-commands-rspec", group: :development
gem 'guard-rspec', require: false
gem 'foreman', require: false
#gem 'ruby-graphviz' # only enable when needed for workflow diagram generation
gem 'ruby-graphviz' # only enable when needed for workflow diagram generation
end
end

Expand Down
27 changes: 23 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,16 @@ GEM
factory_girl_rails (4.6.0)
factory_girl (~> 4.5.0)
railties (>= 3.0.0)
faraday (0.15.2)
multipart-post (>= 1.2, < 3)
faraday_middleware (0.12.2)
faraday (>= 0.7.4, < 1.0)
ffaker (2.8.1)
ffi (1.9.10)
foreman (0.78.0)
thor (~> 0.19.1)
formatador (0.2.5)
gli (2.17.1)
globalid (0.3.7)
activesupport (>= 4.1.0)
guard (2.13.0)
Expand Down Expand Up @@ -200,13 +205,14 @@ GEM
mini_portile2 (2.3.0)
minitest (5.10.3)
multi_json (1.12.2)
multipart-post (2.0.0)
nenv (0.3.0)
net-scp (1.2.1)
net-ssh (>= 2.6.5)
net-ssh (3.0.2)
netrc (0.11.0)
newrelic_rpm (3.15.0.314)
nokogiri (1.8.2)
nokogiri (1.8.4)
mini_portile2 (~> 2.3.0)
notiffany (0.0.8)
nenv (~> 0.1)
Expand Down Expand Up @@ -235,8 +241,8 @@ GEM
slop (~> 3.4)
puma (3.0.2)
rack (1.6.10)
rack-cors (0.4.0)
rack-protection (2.0.1)
rack-cors (1.0.2)
rack-protection (2.0.3)
rack
rack-test (0.6.3)
rack (>= 1.0)
Expand Down Expand Up @@ -327,6 +333,7 @@ GEM
rspec_junit_formatter (0.2.3)
builder (< 4)
rspec-core (>= 2, < 4, != 2.12.0)
ruby-graphviz (1.2.3)
rufus-scheduler (3.3.4)
tzinfo
safe_yaml (1.0.4)
Expand Down Expand Up @@ -355,6 +362,13 @@ GEM
sinatra (1.2.8)
rack (~> 1.1)
tilt (>= 1.2.2, < 2.0)
slack-ruby-client (0.11.1)
activesupport
faraday (>= 0.9)
faraday_middleware
gli
hashie
websocket-driver
slop (3.6.0)
spring (1.6.4)
spring-commands-rspec (1.0.4)
Expand Down Expand Up @@ -393,6 +407,9 @@ GEM
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff
websocket-driver (0.7.0)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.3)

PLATFORMS
ruby
Expand Down Expand Up @@ -454,13 +471,15 @@ DEPENDENCIES
rollbar
rspec-rails
rspec_junit_formatter
ruby-graphviz
shoulda-callback-matchers
shoulda-matchers
sidekiq
sidekiq-scheduler
sidekiq-statistic
simplecov (= 0.9.0)
sinatra
slack-ruby-client
spring
spring-commands-rspec
sprockets (~> 3.7.2)
Expand All @@ -475,4 +494,4 @@ RUBY VERSION
ruby 2.2.2p95

BUNDLED WITH
1.13.6
1.16.0
9 changes: 9 additions & 0 deletions app/jobs/slack_message_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class SlackMessageJob < ActiveJob::Base
queue_as :low

def perform(message, channel)
client = Slack::Web::Client.new
client.chat_postMessage(channel: channel, text: message, as_user: true)
end

end
2 changes: 1 addition & 1 deletion app/jobs/twilio_job.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class TwilioJob < ActiveJob::Base
queue_as :default
queue_as :high

rescue_from(Twilio::REST::RequestError) do
retry_job wait: 30.seconds
Expand Down
5 changes: 5 additions & 0 deletions app/models/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ def set_initial_state
if order.detail_type == "GoodCity"
order.designate_orders_packages
order.send_new_order_notificationen
order.send_new_order_sms
end
end
end
Expand All @@ -212,6 +213,10 @@ def send_new_order_notificationen
}
end

def send_new_order_sms
TwilioService.new(submitted_by).send_new_order_sms(self)
end

def nullify_columns(*columns)
columns.map { |column| send("#{column}=", nil) }
end
Expand Down
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def online?
def send_verification_pin
most_recent_token.cycle_otp_auth_key!
EmailFlowdockService.new(self).send_otp
SlackPinService.new(self).send_otp
TwilioService.new(self).sms_verification_pin
end

Expand Down
16 changes: 16 additions & 0 deletions app/services/slack_pin_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class SlackPinService

attr_accessor :user

def initialize(user)
@user = user
end

def send_otp
channel = ENV['SLACK_PIN_CHANNEL']
token = @user.most_recent_token
message = "[#{Rails.env}] " + I18n.t('twilio.sms_verification_pin', pin: token.otp_code)
SlackMessageJob.perform_later(message, channel)
end

end
11 changes: 11 additions & 0 deletions app/services/twilio_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ def send_welcome_msg
TwilioJob.perform_later(options)
end

def send_new_order_sms(order)
return unless allowed_to_send?
options = { to: @user.mobile, body: new_order_text(order) }
TwilioJob.perform_later(options)
end

def new_offer_alert(offer)
return unless allowed_to_send?
options = {to: @user.mobile, body: new_offer_message(offer)}
Expand Down Expand Up @@ -50,4 +56,9 @@ def welcome_sms_text
I18n.t('twilio.charity_user_welcome_sms',
full_name: User.current_user.full_name)
end

def new_order_text(order)
I18n.t('twilio.new_order_submitted_sms',
code: order.code)
end
end
3 changes: 3 additions & 0 deletions config/initializers/slack.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Slack.configure do |config|
config.token = ENV['SLACK_API_TOKEN']
end
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ en:
your quality goods. (If you didn't request this message, please ignore)
charity_user_welcome_sms: |
%{full_name} has added you to the GoodCity for Charities platform. Please download the app and log in using this mobile number.
new_order_submitted_sms: |
Thank you for placing order %{code} on GoodCity. Our team will be in touch with you soon.
input_offer_id_message: "Please input an offer ID and we will forward you to the donor's number."
thank_you_calling_message: "Thank you for calling GoodCity.HK, operated by Crossroads Foundation. Please wait a moment while we try to connect you to one of our staff."
activerecord:
Expand Down
4 changes: 3 additions & 1 deletion config/locales/zh-tw.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ zh-tw:
一次性驗證碼為 %{pin}。好人好市歡迎您!我們期待您的善心捐獻。
(如你並沒有要求驗證碼,請忽略此信息)
charity_user_welcome_sms: |
%{full_name} has added you to the GoodCity for Charities platform. Please download the app and log in using this mobile number.
%{full_name} 已將閣下登記於好人好巿平台。請下載該應用程式及以此電話號碼登入。
new_order_submitted_sms: |
Thank you for placing order %{code} on GoodCity. Our team will be in touch with you soon.
input_offer_id_message: "請輸入捐獻號碼,提取捐贈人士的號碼。"
thank_you_calling_message: "感謝致電十字路會主辦物資捐獻系統,好人好市。請稍候片刻,職員將儘快接聽你的電話。"
activerecord:
Expand Down

0 comments on commit 9a97f0c

Please sign in to comment.