Class: Whatsapp::Webhook::Installer
- Inherits:
-
Object
- Object
- Whatsapp::Webhook::Installer
- Defined in:
- lib/ruby/whatsapp/webhook/installer.rb
Overview
Copies a personalizable webhook controller into a host Rails app. Plain
Ruby with no Rails dependency of its own, so it can be unit tested against
a plain directory — lib/tasks/whatsapp.rake is the thin Rails-facing
wrapper around this.
Constant Summary collapse
- TEMPLATE_PATH =
File.("templates/webhooks_controller.rb.tt", __dir__)
- DESTINATION =
"app/controllers/whatsapp/webhooks_controller.rb"- NEXT_STEPS =
<<~TEXT Next steps: 1. Add these routes to config/routes.rb: get "/whatsapp/webhooks", to: "whatsapp/webhooks#verify" post "/whatsapp/webhooks", to: "whatsapp/webhooks#receive" 2. Configure your verify token and app secret, e.g. in config/initializers/whatsapp.rb: Whatsapp.configure do |config| config.verify_token = Rails.application.credentials.whatsapp_verify_token config.app_secret = Rails.application.credentials.whatsapp_app_secret end 3. Personalize app/controllers/whatsapp/webhooks_controller.rb — it's your file now. TEXT
Class Method Summary collapse
-
.call(root: Dir.pwd, output: $stdout) ⇒ Symbol
:createdor:skipped(an existing controller is never overwritten).
Class Method Details
.call(root: Dir.pwd, output: $stdout) ⇒ Symbol
Returns :created or :skipped (an existing controller is never overwritten).
35 36 37 38 39 40 41 42 43 |
# File 'lib/ruby/whatsapp/webhook/installer.rb', line 35 def call(root: Dir.pwd, output: $stdout) destination = File.join(root, DESTINATION) result = write_controller(destination, output) output.puts output.puts NEXT_STEPS result end |