Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

make the #goto_EXT{} record work with #function_EXT{}

  • Loading branch information...
commit 5db471f18c6ed925f43f8645a27946d3b92693fe 1 parent ea6bc9c
@hypernumbers hypernumbers authored
View
17 src/phonecall_srv.erl
@@ -304,9 +304,9 @@ apply_function(Module, Function, State) ->
{BumpedState, NewCState} = twiml:compile(NewTwiML, fsm, CS),
NewFSM1 = orddict:erase(CS, FSM),
NewFSM2 = shift(NewFSM1, CS, BumpedState, []),
- NewFSM3 = store(NewCState, NewFSM2),
- NewCBs = lists:merge(CBs, CBs2),
- NewState = State#state{fsm = NewFSM3, history = NewHist,
+ NewFSM3 = store(NewCState, NewFSM2),
+ NewCBs = lists:merge(CBs, CBs2),
+ NewState = State#state{fsm = NewFSM3, history = NewHist,
eventcallbacks = NewCBs},
NewState.
@@ -323,7 +323,8 @@ to_list(X) when is_atom(X) -> atom_to_list(X).
shift([], _, _, Acc) -> lists:reverse(Acc);
shift([{State, Rec} | T], CurrentState, BumpedState, Acc) ->
NewState = shift2(State, CurrentState, BumpedState),
- NewAcc = [{NewState, Rec} | Acc],
+ Rec2 = shift_rec(Rec, CurrentState, BumpedState),
+ NewAcc = [{NewState, Rec2} | Acc],
shift(T, CurrentState, BumpedState, NewAcc).
shift2(State, CurrentState, BumpedState) ->
@@ -332,6 +333,12 @@ shift2(State, CurrentState, BumpedState) ->
State =< CurrentState -> State
end.
+shift_rec({#goto_EXT{}, Goto}, CS, BS) ->
+ NewGoto = shift2(Goto, CS, BS),
+ {#goto_EXT{goto = NewGoto}, NewGoto};
+shift_rec(Rec, _, _) ->
+ Rec.
+
bump(State, CurrentState, BumpedState) ->
Diff = diff(CurrentState, BumpedState),
NState = state_to_num(State),
@@ -351,7 +358,7 @@ bump2([H1 | T1], [H2 | T2], Acc) ->
diff(A, B) -> [A2 | A3] = lists:reverse(state_to_num(A)),
[B2 | _B3] = lists:reverse(state_to_num(B)),
Len = length(A3),
- lists:reverse([B2 - A2 | lists:duplicate(Len, 0)]).
+ lists:reverse([B2 - A2 - 1 | lists:duplicate(Len, 0)]).
state_to_num(A) -> [list_to_integer(X) || X <- string:tokens(A, ".")].
View
1  src/twilio_ext.erl
@@ -72,4 +72,3 @@ handle(Params, Path) ->
%% _ ->
%% error
%% end.
-
View
6 src/twiml.erl
@@ -176,8 +176,7 @@ comp2(Elements, Rank, Fun) ->
% and terminate here
comp3([H | _T], _ExitType, Type, Fun, Rank, Acc)
when is_record(H, hangup)
- orelse is_record(H, reject)
- orelse is_record(H, goto_EXT) ->
+ orelse is_record(H, reject) ->
Rank2 = bump(Rank),
{Type, Rank2, lists:flatten(lists:reverse([Fun(H, Rank) | Acc]))};
% gather is also a terminal- our gathers always have a default or a repeat
@@ -228,7 +227,8 @@ comp3([H | T], ExitType, Type, Fun, Rank, Acc)
orelse is_record(H, number)
orelse is_record(H, client)
orelse is_record(H, conference)
- orelse is_record(H, function_EXT) ->
+ orelse is_record(H, function_EXT)
+ orelse is_record(H, goto_EXT) ->
Rank2 = bump(Rank),
comp3(T, ExitType, Type, Fun, Rank2, [Fun(H, Rank) | Acc]);
comp3([#dial{} = D | T], ExitType, _Type, Fun, Rank, Acc) ->
View
15 src/twiml_ext_recipies.erl
@@ -22,7 +22,7 @@
random() ->
{A, B, C} = now(),
random:seed(A, B, C),
- N = random:uniform(14),
+ N = random:uniform(15),
recipe(N).
recipe(N) ->
@@ -139,14 +139,23 @@ recipe2(13) ->
% add a call out which is on a sub-menu
recipe2(14) ->
- % get yer bits sorted out
EXT = #function_EXT{title = "call out to function",
module = 'twiml_ext_recipies',
fn = 'external_function'},
[#say{text="welcome to a simple conference call. "
++ "Have someone else call this number"},
- #dial{body = [EXT]}].
+ #dial{body = [EXT]}];
+
+% add a call out which is on a sub-menu
+recipe2(15) ->
+ SAY = #say{text="Smoot"},
+ EXT = #function_EXT{title = "call out to function",
+ module = 'twiml_ext_recipies',
+ fn = 'external_function'},
+ GOTO = #goto_EXT{goto = "4"},
+ SAY2 = #say{text="Backflip"},
+ [SAY, EXT, GOTO, SAY2].
% the function that is called gets the whole phonecall_srv state
%
Please sign in to comment.
Something went wrong with that request. Please try again.