Skip to content

Commit

Permalink
Merge pull request #801 from 2600hz/pivot2015
Browse files Browse the repository at this point in the history
Pivot2015
  • Loading branch information
lazedo committed Feb 27, 2015
2 parents 4119df6 + 805bdb6 commit db20007
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 15 deletions.
2 changes: 1 addition & 1 deletion applications/callflow/src/module/cf_tts.erl
@@ -1,5 +1,5 @@
%%%-------------------------------------------------------------------
%%% @copyright (C) 2014, 2600Hz INC
%%% @copyright (C) 2014-2015, 2600Hz INC
%%% @doc
%%% "data":{
%%% "text":"This is what should be said"
Expand Down
29 changes: 19 additions & 10 deletions applications/crossbar/src/modules/cb_pivot.erl
Expand Up @@ -109,16 +109,25 @@ read(Id, Context) ->
-spec debug_read(ne_binary(), cb_context:context()) -> cb_context:context().
debug_read(CallId, Context) ->
AccountModb = wh_util:format_account_mod_id(cb_context:account_id(Context)),
crossbar_doc:load_view(?CB_DEBUG_LIST
,[{'endkey', [CallId]}
,{'startkey', [CallId, wh_json:new()]}
,'descending'
,'include_docs'
,{'reduce', 'false'}
]
,cb_context:set_account_db(Context, AccountModb)
,fun normalize_debug_read/2
).
Context1 =
crossbar_doc:load_view(
?CB_DEBUG_LIST
,[{'endkey', [CallId]}
,{'startkey', [CallId, wh_json:new()]}
,'descending'
,'include_docs'
,{'reduce', 'false'}
]
,cb_context:set_account_db(Context, AccountModb)
,fun normalize_debug_read/2
),
case cb_context:resp_status(Context1) of
'success' ->
RespData = cb_context:resp_data(Context1),
cb_context:set_resp_data(Context1, lists:reverse(RespData));
_ -> Context1
end.


%%--------------------------------------------------------------------
%% @private
Expand Down
126 changes: 126 additions & 0 deletions applications/pivot/doc/kazoo/index.md
@@ -0,0 +1,126 @@
/*
Section: Pivot
Title: Build your callflows on-demand
Language: en-US
*/

# Overview

Sometimes Kazoo's callflow builder doesn't match your needs, integrate with your applications, or provide the experience for your caller that you desire. Fortunately, the building blocks are available for you to play with as you see fit!

By routing a call to a Pivot callflow action, Kazoo will make an HTTP request to your web server asking for the callflow to process for that specific call (versus the one-size-fits-all approach in the normal callflow builder).

This could be best illustrated with an example, no?

## Building Time-based routing

We want to add time-based rules when deciding how to route our office's main number (this exists with the `temporal_route` callflow action already, but we're trying to make a point!). Following a "typical" office's hours, we are open 9am-5pm (9:00 to 17:00). During that time, we'd like to ring the front desk's phone. Outside of those hours, we'd like calls to go directly to the company's voicemail box.

### Build the Kazoo Things

Based on the above goals, we need to build:

* Front Desk's device
* Company Voicemail box
* Main number callflow

Once you've made those, note the IDs for the device and voicemail box (using the developer tool is a good way to find those).

The main number callflow should be:

```
[NUMBER] -> Pivot
Url: http://your.webserver.com/path/to/main_number_tod.php
```

Now, whenever this number is called, Kazoo will query your URL for callflow to execute.

### Build `main_number_tod.php`

The first thing needed is to set the content-type to application/json.

```php
<?php

header('content-type:application/json');
```

Now we need to know what time it is and determine what to do:

```php
$now = time();

$hour = date("G", $now);

if ( $hour >= 9 && $hour < 17 ) {
business_hours();
} else {
after_hours();
}
```

Now we have two functions to build the JSON for the callflow to execute:

* `business_hours()`:
```php
function business_hours() {
?>
{"module":"device"
,"data":{"id":"{FRONT_DESK_DEVICE_ID}"}
,"children":{
"_":{
"module":"voicemail"
,"data":{"id":"{COMPANY_VM_BOX_ID}"}
}
}
<?php
}
```

* `after_hours()`:
```php
function after_hours() {
?>
{"module":"voicemail"
,"data":{"id":"{COMPANY_VM_BOX_ID}"}
}
<?php
}
```

Bring it all together:

```php
<?php
header('content-type:application/json');
$now = time();
$hour = date("G", $now);

if ( $hour > 8 && $hour < 17 ) {
business_hours();
} else {
after_hours();
}

function business_hours() {
?>
{"module":"device"
,"data":{"id":"{FRONT_DESK_DEVICE_ID}"}
,"children":{
"_":{
"module":"voicemail"
,"data":{"id":"{COMPANY_VM_BOX_ID}"}
}
}
<?php
}

function after_hours() {
?>
{"module":"voicemail"
,"data":{"id":"{COMPANY_VM_BOX_ID}"}
}
<?php
}
?>
```
2 changes: 1 addition & 1 deletion applications/pivot/doc/kazoo/play.md
Expand Up @@ -10,7 +10,7 @@ It is pretty easy to play files, either hosted in your account or accessible via

# Play sample

The initial Kazoo JSON to collect DTMF could look something like:
The initial Kazoo JSON to play a file could look something like:

<?php

Expand Down
31 changes: 31 additions & 0 deletions applications/pivot/doc/kazoo/say.md
@@ -0,0 +1,31 @@
/*
Section: Pivot
Title: Saying Text
Language: en-US
*/

# Overview

Text-to-speech is an easy way to read text to the caller

# Play sample

The initial Kazoo JSON to

<?php

header('content-type:application/json');

?>

{"module":"tts"
,"data":{"text":"Pivot is pretty awesome. Have a great day."}
,"children":{
"_":{
"module":"response"
,"data":{}
}
}
}

Here the TTS engine will read the text to the caller and then hang up.
7 changes: 4 additions & 3 deletions core/kazoo_translator-1.0.0/src/convertors/kzt_kazoo.erl
Expand Up @@ -47,15 +47,16 @@ req_params(Call) ->
[{<<"Call-ID">>, whapps_call:call_id(Call)}
,{<<"Account-ID">>, whapps_call:account_id(Call)}
,{<<"From">>, whapps_call:from_user(Call)}
,{<<"FromRealm">>, whapps_call:from_realm(Call)}
,{<<"From-Realm">>, whapps_call:from_realm(Call)}
,{<<"To">>, whapps_call:to_user(Call)}
,{<<"ToRealm">>, whapps_call:to_realm(Call)}
,{<<"To-Realm">>, whapps_call:to_realm(Call)}
,{<<"Call-Status">>, kzt_util:get_call_status(Call)}
,{<<"ApiVersion">>, <<"2013-05-01">>}
,{<<"Api-Version">>, <<"2015-03-01">>}
,{<<"Direction">>, <<"inbound">>}
,{<<"Caller-ID-Name">>, whapps_call:caller_id_name(Call)}
,{<<"Caller-ID-Number">>, whapps_call:caller_id_number(Call)}
,{<<"User-ID">>, Owners}
,{<<"Language">>, whapps_call:language(Call)}
,{<<"Recording-Url">>, kzt_util:get_recording_url(Call)}
,{<<"Recording-Duration">>, kzt_util:get_recording_duration(Call)}
,{<<"Recording-ID">>, kzt_util:get_recording_sid(Call)}
Expand Down

0 comments on commit db20007

Please sign in to comment.