Tropo WebAPI Development Guide Home  |  Frameset Home

  Creating a Conference Call  |  TOC  |  Concepts & Vocabulary  

Working with Simple Grammar


Grammar is just a fancy word for telling Tropo what to expect from the user; Simple Grammar is the term we use for the built-in default way of expressing input requirements in Tropo.

In the Asking for Digits QuickStart, we introduced the [DIGITS] grammar and used it to tell Tropo to expect 1 digit. You can also express a range of digits by using [4-5 DIGITS] instead (the number values are defined by you; it could be [10-20 DIGITS], [1-2 DIGITS], and so on). If your caller enters 4 digits instead of 5, Tropo will wait 3 seconds before considering the input complete. If you want to allow your callers to press a key to tell Tropo they're done, just add the terminator parameter to your ask statement and set it to the key they should press.

Because there are two primary ways of interacting with users over the phone (keypad and voice) and by default Tropo will listen for input in both modes, we'll want to specify "keypad" input for our pin number request. This behavior can be controlled using the mode parameter. Possible values are "keypad", "speech" or "any" - as with the other ask examples, these will be library only; note that if you use PHP, the following example includes the Limonade framework, so you would need to define the end of the start URL in Tropo to include the resource name, like http://www.example.com/test.php?uri=start::

require 'tropo-webapi-ruby'
require 'sinatra'

post '/index.json' do
  
  t = Tropo::Generator.new
  
  t.ask :name => 'digits', 
        :timeout => 60, 
        :say => {:value => "What's your four or five digit pin? Press pound when finished."},
        :choices => {:value => "[4-5 DIGITS]", :mode => "dtmf", :terminator => "#"}        
  
  t.on :event => 'continue', :next => '/continue.json'
  
  t.response
  
end

post '/continue.json' do
  
  t = Tropo::Generator.new
  
  t.say(:value => "Thank you.")
  
  t.response
  
end
var http = require('http');
var express = require('express');
var app = express.createServer();
var tropo_webapi = require('tropo-webapi');

// Required to process the HTTP body.
// req.body has the Object while req.rawBody has the JSON string.

app.configure(function(){
	app.use(express.bodyParser());
});

app.post('/', function(req, res){
	
    var tropo = new TropoWebAPI();
    
    var say = new Say("What's your four or five digit pin? Press pound when finished.");

    // (value, mode, terminator)
    var choices = new Choices("[4-5 DIGITS]", "dtmf", "#");

    // (choices, attempts, bargein, minConfidence, name, recognizer, required, say, timeout, voice);
	
    tropo.ask(choices, null, null, null, "digits", null, null, say, 60, null);
	
    tropo.on("continue", null, "/continue", true);
	
    res.send(TropoJSON(tropo));
	
});

app.post('/continue', function(req, res){
	
    var tropo = new TropoWebAPI();

    tropo.say("Thank you.");
		
    res.send(TropoJSON(tropo));

});

app.listen(8000);
console.log('Server running on port :8000');
<?php

require 'tropo.class.php';
require 'lib/limonade.php';
 
dispatch_post('/', 'app_start');
function app_start() {
 
    $tropo = new Tropo();

    $options = array("choices" => "[4-5 DIGITS]", "name" => "digits", "timeout" => 60, "mode" => "dtmf", "terminator" => "#");

    $tropo->ask("What's your four or five digit pin? Press pound when finished.", $options);
 
    $tropo->on(array("event" => "continue", "next" => "hello_world.php?uri=continue"));
 
    $tropo->RenderJson();
}
 
dispatch_post('/continue', 'app_continue');
function app_continue() {
 
    $tropo = new Tropo();
     
    $tropo->say("Thank you!");
     
    $tropo->RenderJson();
 
}
 
run();
 
?>
from itty import *
from tropo import Tropo, Choices

@post('/index.json')
def index(request):

	t = Tropo()
	
	choices = Choices("[4-5 DIGITS]", mode="dtmf", terminator = "#")
	t.ask(choices, timeout=60, name="digit", say = "What's your four or five digit pin? Press pound when finished.")
	
	t.on(event = "continue", next ="/continue")

	return t.RenderJson()
	
@post("/continue")
def index(request):
	
	t = Tropo()
	
	t.say("Thank you!")
	
	return t.RenderJson()
	
run_itty(server='wsgiref', host='0.0.0.0', port=8888)

Note that if you set the mode parameter to 'dtmf', you can set the choices to * or # as well; it's not restricted to numbers alone.

Tropo is capable of so much more than just digits and dtmf input - you can also use Tropo’s simple grammar notation to recognize words and even entire phrase.

Next Step: Concepts & Vocabulary



  ANNOTATIONS: EXISTING POSTS
0 posts - click the button below to add a note to this page

login
  Creating a Conference Call  |  TOC  |  Concepts & Vocabulary  

© 2012 Voxeo Corporation  |  Voxeo IVR  |  VoiceXML & CCXML IVR Developer Site