Skip to content

Commit

Permalink
Separate routes & controllers for messages and calls
Browse files Browse the repository at this point in the history
  • Loading branch information
emorissettegregoire committed Aug 9, 2024
1 parent da51f07 commit fff945d
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 8 deletions.
32 changes: 32 additions & 0 deletions app/controllers/stealth/call_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Stealth
class CallController < ApplicationController
# skip the default Rails CSRF protection for webhook calls...
skip_before_action :verify_authenticity_token, only: [:call_handler]

def call_handler
service = params[:service]

case service
when 'bandwidth'
handle_bandwidth(request)
# else
# WIP will add more services here...
end
end

private

def handle_bandwidth(request)
event = Stealth::Services::Bandwidth::CallEventHandler.determine_event_type(request)

case event[:type]
when :call_received
Stealth.trigger_event(:phone_call, :call_receive, event[:service_call])
# when :text_message_unsubscribe
end

head :no_content
end

end
end
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module Stealth
class ServiceController < ApplicationController
class MessageController < ApplicationController
# skip the default Rails CSRF protection for webhook calls...
skip_before_action :verify_authenticity_token, only: [:service_handler]
skip_before_action :verify_authenticity_token, only: [:message_handler]

def service_handler
def message_handler
service = params[:service]

case service
Expand All @@ -17,10 +17,10 @@ def service_handler
private

def handle_bandwidth(request)
event = Stealth::Services::Bandwidth::EventHandler.determine_event_type(request)
event = Stealth::Services::Bandwidth::MessageEventHandler.determine_event_type(request)

case event[:type]
when :text_message_receive
when :text_received
Stealth.trigger_event(:text_message, :receive, event[:service_message])
# when :text_message_unsubscribe
end
Expand Down
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
# Stealth Development Dashboard

# Stealth Default Service Routes
post 'incoming/:service', to: 'service#service_handler'
post ':service/text_received', to: 'message#message_handler'
post ':service/call_received', to: 'call#call_handler'
end
1 change: 1 addition & 0 deletions lib/stealth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require "stealth/event_manager"
require "stealth/event_triggers"
require "stealth/service_message"
require "stealth/service_call"

module Stealth
class << self
Expand Down
5 changes: 4 additions & 1 deletion lib/stealth/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ module Stealth
class Engine < ::Rails::Engine
isolate_namespace Stealth

# Will have to avoid loading driver files in the engine
initializer 'stealth' do
require 'stealth/services/bandwidth/event_handler'
require 'stealth/services/bandwidth/message_event_handler'
require 'stealth/services/bandwidth/call_event_handler'
require 'stealth/services/bandwidth/service_message'
require 'stealth/services/bandwidth/service_call'
end
end
end
12 changes: 12 additions & 0 deletions lib/stealth/service_call.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Stealth
class ServiceCall

attr_accessor :call_id, :call_url, :sender_id, :target_id, :timestamp,
:service, :direction, :service_event_type

def initialize(service:)
@service = service
end

end
end
2 changes: 1 addition & 1 deletion lib/stealth/service_message.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Stealth
class ServiceMessage

attr_accessor :sender_id, :target_id, :timestamp, :service, :message, :event_type,
attr_accessor :sender_id, :target_id, :timestamp, :service, :message, :service_event_type,
:location, :attachments, :payload, :referral, :nlp_result,
:catch_all_reason, :confidence

Expand Down

0 comments on commit fff945d

Please sign in to comment.