Skip to content

Commit

Permalink
Allow optional voicemail rerecording
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinAiken committed Oct 18, 2013
1 parent 3a263dc commit 97d8a67
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#v1.0.0..
* FEATURE - Optional rerecording of voicemail messages
* FEATURE - I18n numeric methods
* FEATURE - I18n support for keys
* FEATURE - Seperate pin_checking into seperate matcher class, so that it can be overriden if desired
Expand Down
42 changes: 35 additions & 7 deletions lib/voicemail/call_controllers/voicemail_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
module Voicemail
class VoicemailController < ApplicationController

attr_accessor :recording

def run
answer if config.when_to_answer == :before_greeting
if mailbox
play_greeting
answer if config.when_to_answer == :after_greeting
handle_recording
record_message
hangup
else
mailbox_not_found
Expand All @@ -16,14 +19,39 @@ def play_greeting
play mailbox[:greeting_message] || config.default_greeting
end

def handle_recording
@from = call.from
record_comp = record config.recording.to_hash
save_recording record_comp.complete_event.recording
def record_message
@recording = record config.recording.to_hash

config.allow_rerecording ? recording_menu : save_recording
end

def recording_menu
ensure_message_saved_if_hangup
menu recording_url, config.after_record, tries: 3, timeout: 10 do
match('1') { save_recording }
match('2') { record_message }

invalid { }
timeout { save_recording }
failure { save_recording }
end
end

private

def ensure_message_saved_if_hangup
call.on_end do
save_recording unless @saved
end
end

def save_recording
storage.save_recording mailbox[:id], call.from, recording.complete_event.recording
@saved = true
end

def save_recording(recording_object)
storage.save_recording mailbox[:id], @from, recording_object
def recording_url
recording.complete_event.recording.uri
end
end
end
3 changes: 3 additions & 0 deletions lib/voicemail/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class Plugin < Adhearsion::Plugin
default_greeting "You have reached voicemail", desc: "What to use to greet users"
mailbox_not_found "Mailbox not found", desc: "Message to use for a missing mailbox"

allow_rerecording true, desc: "Allow caller to rerecord their voicemail"
after_record "Press 1 to save your voicemail. Press 2 to rerecord.", desc: "Message to play if allow_rerecording is set"

desc "Voicemail recording options"
recording {
interruptible true, desc: "Whether you can stop the recording with a DTMF input"
Expand Down
43 changes: 31 additions & 12 deletions spec/voicemail/call_controllers/voicemail_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
context "without a greeting message" do
it "plays the default greeting if one is not specified" do
should_play config.default_greeting
subject.should_receive(:handle_recording).and_return(true)
subject.should_receive :record_message
controller.run
end
end
Expand All @@ -55,22 +55,41 @@

it "plays the specific greeting message" do
should_play greeting_message
subject.should_receive(:handle_recording).and_return(true)
subject.should_receive :record_message
controller.run
end
end
end
end
end

context "handling a recording" do
let(:recording_component) { flexmock 'Record' }
let(:recording_object) { flexmock 'complete_event.recording' }
describe "#record_message" do
context "handling a recording" do
let(:recording_component) { flexmock 'Record' }
let(:recording_object) { flexmock 'complete_event.recording', uri: "http://some_file.wav" }

it "saves the recording" do
recording_component.should_receive("complete_event.recording").and_return recording_object
subject.should_receive(:record).with(config.recording.to_hash).and_return recording_component
storage_instance.should_receive(:save_recording).with mailbox[:id], call.from, recording_object
should_play
controller.run
end
after { subject.record_message }

context "without allow_rerecording" do
before { config.allow_rerecording = false }

it "saves the recording" do
recording_component.should_receive("complete_event.recording").and_return recording_object
subject.should_receive(:record).with(config.recording.to_hash).and_return recording_component
storage_instance.should_receive(:save_recording).with mailbox[:id], call.from, recording_object
end
end

context "without allow_rerecording" do
before { config.allow_rerecording = true }

it "sets up a callback, plays a menu, and eventually saves the message" do
call.should_receive :on_end
recording_object.should_receive :uri
subject.should_receive(:menu)
recording_component.should_receive("complete_event.recording").and_return recording_object
subject.should_receive(:record).with(config.recording.to_hash).and_return recording_component
storage_instance.should_receive(:save_recording).with mailbox[:id], call.from, recording_object
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions templates/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ en:
menu_invalid_message: "Please enter valid input"
menu_failure_message: "Sorry, unable to understand your input."

after_record: "Press 1 to save your voicemail. Press 2 to rerecord."

set_greeting:
prompt: "Press 1 to listen to your current greeting, 2 to record a new greeting, 9 to return to the main menu"
before_record: "Please speak after the beep. The prompt will be played back after."
Expand Down

0 comments on commit 97d8a67

Please sign in to comment.