Commit b86b1ad

mokha <mokha@cisco.com>
2018-04-27 17:15:00
start ngrok tunnel.
1 parent a5e0116
Changed files (3)
lib/incognito/cli/sms_command.rb
@@ -26,7 +26,7 @@ module Incognito
       def server
         require 'incognito/sms_server'
         SmsServer.set :shell, self
-        SmsServer.run!
+        SmsServer.boot_up!
       end
 
       private
lib/incognito/sms_server.rb
@@ -1,11 +1,14 @@
 require 'sinatra'
 require 'sinatra/base'
+require 'ngrok/tunnel'
 
 class SmsServer < Sinatra::Base
+  PORT=ENV.fetch("PORT", 4567)
   configure do
     disable :logging
     set :server, :puma
     set :shell, $shell
+    set :port, PORT
   end
 
   get '/' do
@@ -25,6 +28,28 @@ class SmsServer < Sinatra::Base
     end
   end
 
+  def self.boot_up!
+    Ngrok::Tunnel.start(addr: "localhost:#{PORT}")
+    puts "***" * 10
+    banner = <<-BANNER
+Configure your webhook URL
+For Twilio to know where to look, you need to configure your Twilio phone number
+to call your webhook URL whenever a new message comes in.
+
+1. Log into twilio.com and go to the Numbers page in the Console.
+2. Click on your SMS-enabled phone number.
+3. Find the Messaging section. The default “CONFIGURE WITH” is what you’ll need: "Webhooks/TwiML."
+4. In the “A MESSAGE COMES IN” section, select "Webhook" and paste in the URL you want to use:
+#{Ngrok::Tunnel.ngrok_url_https}
+5. Set the HTTP verb to GET.
+
+
+    BANNER
+    puts banner
+    puts "***" * 10
+    run!
+  end
+
   private
 
   def shell
incognito.gemspec
@@ -22,10 +22,11 @@ Gem::Specification.new do |spec|
   spec.require_paths = ["lib"]
 
   spec.add_dependency "dotenv", "~> 2.2"
-  spec.add_dependency "twilio-ruby", "~> 5.8"
-  spec.add_dependency "thor", "~> 0.20"
-  spec.add_dependency "sinatra", "~> 2.0"
+  spec.add_dependency "ngrok-tunnel", "~> 2.1"
   spec.add_dependency "puma", "~> 3.11"
+  spec.add_dependency "sinatra", "~> 2.0"
+  spec.add_dependency "thor", "~> 0.20"
+  spec.add_dependency "twilio-ruby", "~> 5.8"
   spec.add_development_dependency "bundler", "~> 1.16"
   spec.add_development_dependency "rake", "~> 10.0"
   spec.add_development_dependency "minitest", "~> 5.0"