The DTMF element is used to send digits on a live call. This will usually be used to automate the process of navigating through an external phone tree (IVR).
Digits are sent in the background when the async parameter is set to true, so the call will jump to the next XML element when the first digit is sent. Use the character w for a 0.5 second delay and the character W for a 1 second delay. Allowed values: 1234567890*#wW
Let’s assume your web server is located at example.com
. Below is a snippet to set up a route on your webserver. Let’s call it, /dtmf/
. Now when we send an HTTP
request to example.com/dtmf/
this route will be invoked.
dtmf
.
example.com
.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import plivoxml
from flask import Flask, Response
app = Flask(__name__)
@app.route('/dtmf/', methods=['GET','POST'])
def dtmf():
r = plivoxml.Response()
r.addSpeak("Sending Digits")
r.addDTMF("12345")
print r.to_xml()
return Response(str(r), mimetype='text/xml')
if __name__=='__main__':
app.run(host='0.0.0.0',debug='True')
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
require 'rubygems'
require 'sinatra'
require 'plivo'
include Plivo
get '/dtmf/' do
r = Response.new()
r.addSpeak("Sending Digits")
r.addDTMF("12345")
puts r.to_xml()
content_type 'text/xml'
return r.to_s()
end
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var plivo = require('plivo');
var plivo = require('plivo');
var express = require('express');
var app = express();
app.set('port', (process.env.PORT || 5000));
app.all('/dtmf/', function(request, response) {
var r = plivo.Response();
r.addSpeak("Sending Digits");
r.addDTMF("12345");
console.log (r.toXML());
response.set({'Content-Type': 'text/xml'});
response.send(r.toXML());
});
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
require 'vendor/autoload.php';
use Plivo\Response;
$r = new Response();
// Add Speak tag
$body = "Sending Digits";
$r->addSpeak($body);
// Add DTMF tag
$dtmf = "12345";
$r->addDTMF($dtmf);
Header('Content-type: text/xml');
echo($r->toXML());
?>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package plivoexample;
import java.io.IOException;
import com.plivo.helper.exception.PlivoException;
import com.plivo.helper.xml.elements.Dtmf;
import com.plivo.helper.xml.elements.PlivoResponse;
import com.plivo.helper.xml.elements.Speak;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
public class dtmfXml extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
PlivoResponse response = new PlivoResponse();
Dtmf dt = new Dtmf("12345");
Speak speak = new Speak("Sending digits");
try {
response.append(speak);
response.append(dt);
System.out.println(response.toXML());
resp.addHeader("Content-Type", "text/xml");
resp.getWriter().print(response.toXML());;
} catch (PlivoException e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
String port = System.getenv("PORT");
if(port==null)
port ="8000";
Server server = new Server(Integer.valueOf(port));
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
server.setHandler(context);
context.addServlet(new ServletHolder(new dtmfXml()),"/dtmf/");
server.start();
server.join();
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using System.Collections.Generic;
using System.Diagnostics;
using RestSharp;
using Plivo.XML;
using Nancy;
namespace custom_tone
{
public class Program : NancyModule
{
public Program()
{
Get["/dtmf/"] = x =>
{
Plivo.XML.Response resp = new Plivo.XML.Response();
// Add Speak XML Tag
resp.AddSpeak("Sending digits", new Dictionary<string, string>() { });
// Add DTMF XML Tag
resp.AddDTMF("12345", new Dictionary<string, string>() { });
Debug.WriteLine(resp.ToString());
var output = resp.ToString();
var res = (Nancy.Response)output;
res.ContentType = "text/xml";
return res;
};
}
}
}
New Application
or by using Plivo’s Application API.DTMF XML
. Enter your server URL (e.g., http://www.example.com/dtmf/
) in the Answer URL
field and set the method as POST
. See our Application API docs to learn how to use our API to modify your application.Create
to save your application.DTMF XML
(name of the app) from the Plivo App dropdown list.If you don’t have a number, go to the Buy Number page to purchase a Plivo phone number.
When you make a call to your Plivo number, the call will be answered by Plivo and the message will be played.
<Response>
<Speak>Connecting your call..</Speak>
<DTMF>12345</DTMF>
</Response>
Learn how to set Dynamic Caller ID.