Comments (7)
Rivr has no knowledge of APIs whatsoever. You have to provide the API client and invoke it from your Java code with the input provided by the user.
Rivr is all about centralising everything on the Java server side. Thus, you should do the integration of the API from the Java code.
from rivr.
Thanks for the response.
we want to construct data tag as below which is calling any URL.
-- data name="return_data" srcexpr="some_url" method="post" namelist="var1 var2 var3"
Looks like we dont have any class in rivr to construct it directly .
from rivr.
Once again, you shouldn't use the <data>
element to do API calls. Instead, you should prefer make the call from the Java code, which allows you to do many things not possible with the <data>
element:
- handle timeout
- add HTTP headers (for authentication, for instance)
- use a method different from
POST
orGET
(which are the only 2 values allowed by the VoiceXML 2.1 recommendation).
from rivr.
I am confused. my understanding is data tag is part of vxml , system which is executing vxml and the data tag will call the api directly and get response ? or how can vxml call our java code to make api call ? , any sample code we can refer?
from rivr.
Yes, you are right when you say that <data>
is part of VoiceXML 2.1. However, it has not been exposed in Rivr because there is a much better way to do it on the server side.
With Rivr, when you do an application, you do not generate a large VoiceXML document. Instead, Rivr generates a series of small VoiceXML document and posts the result of the document execution back to the server every time.
Here's a very basic code sample. I'm using HttpURLConnection
but you should really use something better (there are many options when it comes to API clients in Java):
package com.nuecho.rivr.cookbook.dialogue;
import java.io.*;
import java.net.*;
import java.nio.charset.*;
import javax.json.*;
import com.nuecho.rivr.core.channel.*;
import com.nuecho.rivr.core.dialogue.*;
import com.nuecho.rivr.core.util.*;
import com.nuecho.rivr.voicexml.dialogue.*;
import com.nuecho.rivr.voicexml.turn.first.*;
import com.nuecho.rivr.voicexml.turn.input.*;
import com.nuecho.rivr.voicexml.turn.last.*;
import com.nuecho.rivr.voicexml.turn.output.*;
import com.nuecho.rivr.voicexml.turn.output.audio.*;
import com.nuecho.rivr.voicexml.turn.output.grammar.*;
public class Menu implements VoiceXmlDialogue {
@Override
public VoiceXmlLastTurn run(VoiceXmlFirstTurn firstTurn, VoiceXmlDialogueContext context) throws Timeout,
InterruptedException {
String number = getNumber(context);
try {
String processedNumber = invokeApi(number);
Message resultMessage = new Message("resultMessage",
new SpeechSynthesis("The result is: " + processedNumber));
DialogueUtils.doTurn(resultMessage, context);
} catch (IOException exception) {
Message errorMessage = new Message("errorMessage",
new SpeechSynthesis("An error occured: "
+ exception.getMessage()));
DialogueUtils.doTurn(errorMessage, context);
}
return new Exit("exit");
}
private String getNumber(VoiceXmlDialogueContext context) throws Timeout, InterruptedException {
String number = null;
do {
DtmfRecognition dtmfRecognition = new DtmfRecognition(new GrammarReference("builtin:dtmf/digits"));
SpeechSynthesis promptText = new SpeechSynthesis("Enter a number.");
Interaction interaction = OutputTurns.interaction("askNumber")
.addPrompt(dtmfRecognition, promptText)
.build(dtmfRecognition, Duration.milliseconds(5));
VoiceXmlInputTurn inputTurn = DialogueUtils.doTurn(interaction, context);
if (inputTurn.getRecognitionInfo() != null) {
JsonArray recognitionResult = inputTurn.getRecognitionInfo().getRecognitionResult();
number = recognitionResult.getJsonObject(0).getString("interpretation");
}
} while (number != null); //loop until valid value is provided
return number;
}
public static String invokeApi(String number) throws IOException {
URL apiUrl = new URL("http://localhost:8080/api/x/v1/numbers/" + number);
HttpURLConnection connection = (HttpURLConnection) apiUrl.openConnection();
connection.setRequestMethod("GET");
int responseCode = connection.getResponseCode();
if (responseCode != 200) throw new IOException("Non-200 reponse from API: " + responseCode);
return readAllStream(connection.getInputStream());
}
public static String readAllStream(InputStream inputStream) throws IOException {
int bufferSize = 1024;
char[] buffer = new char[bufferSize];
StringBuilder out = new StringBuilder();
Reader in = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
for (int numRead; (numRead = in.read(buffer, 0, buffer.length)) > 0;) {
out.append(buffer, 0, numRead);
}
return out.toString();
}
}
This will generate a first document where user will be prompted for a number. Once the number is provided, the result will be sent back to Rivr and the Dialogue will continue where we left off (in the doTurn
method). Then the call to the API can be done in the Java code. Following that, we create another VoiceXML document that reads the result back to the user. Then we terminate the dialogue (with an <exit>
element).
from rivr.
Thanks, this helps to understand the rivr better.
what is the equivalent vxml to this , to run the vxml from any system ?
from rivr.
"to run the vxml from any system"
Not sure what you mean by that.
from rivr.
Related Issues (20)
- for single servlet request, can we call multiple dialogue classes one after another based on business need? (spring based) HOT 10
- Generating two <form> elements with fillVoiceXmlDocument HOT 2
- Can we generate our own voiceXml forms by passing parametes like string using voicexmloutputTurn or VoiceXmlDialogue ? Is there any other method?like VoiceXmlLastTurn run(VoiceXmlFirstTurn,VoiceXmlDialogueContext, String) HOT 2
- VoiceXmlDocumentAdapter usage HOT 1
- how to get dialogue response content-type as application/xml instead of application/voicexml+xml ? HOT 2
- Avaya throws error HOT 3
- Avaya Experience Portal tack_trace":"c.n.r.c.s.s.SessionNotFoundException: Unable to find session [error] HOT 2
- How to add audio file in the prompt as part of Interaction HOT 1
- adding multiple audio links (refer) in a single prompt tag? HOT 2
- Rivr app : Multiple instances (images) on Docker container HOT 1
- Rivr support on call flow routing other IVR application (non-Rivr VoiceXML application) HOT 1
- Subdialogue - Request method 'POST' not supported HOT 1
- how to write java code for return namelist in subdialogue HOT 2
- what is default time out set for rivr application HOT 10
- Speech and DTMF recognition together HOT 2
- Get/Print VXML in run method of dialogue class? HOT 1
- message is not getting interrupted even if barge-in is set to true
- how to set content-type in run method response or in return/exit? HOT 1
- InterDigitTimeout property for multiple grammar files HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rivr.