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

This example assumes a SIP Server integration (not the CTI connector).

This example shows how to extract user data sent by the SIP Server at the beggining of the call. The SIP server sends the user data in specific headers of the SIP INVITE message, typically the ones prefixed with X-Genesys-:

X-Genesys-CustomerName: Peter Johnson
X-Genesys-AccountNumber: 55534-53124-67110

GVP will map these headers to the session.com.genesyslab.userdata object, making it available to the VoiceXML application. We only need to use a Script to retrieve it:

Dialogue.java:

@Override
public VoiceXmlLastTurn run(VoiceXmlFirstTurn firstTurn, VoiceXmlDialogueContext context)
        throws Exception {

    VariableList variables = new VariableList();
    variables.addWithExpression("userData", "session.com.genesyslab.userdata");

    Script script = new Script("read-user-data");
    script.setVariables(variables);

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

    JsonObject result = (JsonObject) inputTurn.getJsonValue();
    JsonValue userDataValue = result.get("userData");

    if (userDataValue instanceof JsonObject) {
        JsonObject userData = (JsonObject) userDataValue;
        context.getLogger().info("User data:");
        for (Entry<String, JsonValue> entry : userData.entrySet()) {
            context.getLogger().info("  " + entry.getKey() + "=" + entry.getValue().toString());
        }
    } else {
        context.getLogger().info("No user data found.");
    }

    //end of dialogue
    return new Exit("exit");
}

Note that if user data are updated during the GVP call, the updated data cannot be read from the VoiceXML because it's only passed from SIP Server to GVP in the SIP INVITE at the beggining of the call.


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 genesys-gvp-read-user-data git@github.com: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.