Skip to content

Getting CLID and DNIS

Jean-Philippe Gariépy edited this page Apr 25, 2015 · 2 revisions

This example shows how to get the CLID (also known as ANI) and DNIS from the VoiceXML platform. To do that, we need to read two read-only variables specified by the VoiceXML specification:

session.connection.local.uri

This variable is a URI which addresses the local interpreter context device.

session.connection.remote.uri

This variable is a URI which addresses the remote caller device.

To create a VoiceXML document reading platform variables, we use the Script turn. This turn will generate a VoiceXML document that will perform the following step:

  1. Initialize some variables with some optional expression.
  2. Execute an optional script
  3. Send back the variables to the server

Here, we will only need to initialize two variables and send the result back to our dialogue, no need for a script here as initial value assignment is enough. To define the variables and initial expression, we use the VariableList class:

Dialogue.java:

VariableList variables = new VariableList();
variables.addWithExpression("clid", "session.connection.remote.uri");
variables.addWithExpression("dnis", "session.connection.local.uri");

Then we create the Script turn with theses variable definitions:

Dialogue.java:

Script script = new Script("clid-dnis");
script.setVariables(variables);

We execute the turn:

Dialogue.java:

VoiceXmlInputTurn inputTurn = DialogueUtils.doTurn(script, context);

To retrieve the result, we cast the result from getValue into a JsonObject. The affected values for the variables can be obtained as property of this object:

Dialogue.java:

JsonObject object = (JsonObject) inputTurn.getJsonValue();
String clid = object.getString("clid");
String dnis = object.getString("dnis");
context.getLogger().info("CLID: {}, DNIS: {}", clid, dnis);

Note that the CLID and DNIS obtained this way are URI. If you have a SIP IVR platform integrated with the PSTN, you are likely to get SIP URI (e.g. sip:[email protected]) so you probably need to do some parsing in order to extract the numeric value of the SIP URI.


Running this example

You can download or browse the complete code for this example at GitHub.This is a complete working application that you can build and run for yourself.

You can also clone the Rivr Cookbook repository and checkout this example:

git clone -b clid-dnis [email protected]:nuecho/rivr-cookbook.git

Then, to build and run it:

cd rivr-cookbook

./gradlew jettyRun

The VoiceXML dialogue should be available at http://localhost:8080/rivr-cookbook/dialogue

To stop the application, press Control-C in the console.