This repository was archived by the owner on May 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInputSample.java
More file actions
98 lines (76 loc) · 2.89 KB
/
InputSample.java
File metadata and controls
98 lines (76 loc) · 2.89 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package samples;
import java.util.ArrayList;
import java.util.List;
import com.rayo.client.SimpleXmppConnection;
import com.rayo.client.XmppConnection;
import com.rayo.client.listener.RayoMessageListener;
import com.rayo.client.xmpp.extensions.Extension;
import com.rayo.client.xmpp.stanza.IQ;
import com.rayo.client.xmpp.stanza.Stanza;
import com.rayo.core.verb.Choices;
import com.rayo.core.verb.Input;
import com.rayo.core.verb.InputCompleteEvent;
import com.rayo.core.verb.InputMode;
import com.rayo.core.verb.Output;
import com.rayo.core.verb.Ssml;
import com.rayo.core.AnswerCommand;
public class InputSample {
private String callId;
public void run() throws Exception {
XmppConnection connection = new SimpleXmppConnection("localhost");
connection.addStanzaListener(new RayoMessageListener("offer") {
@Override
@SuppressWarnings("rawtypes")
public void messageReceived(Object object) {
Stanza stanza = (Stanza)object;
callId = stanza.getFrom().substring(0, stanza.getFrom().indexOf('@'));
}
});
connection.connect();
connection.login("userc", "1", "voxeo");
connection.waitForExtension("offer");
AnswerCommand answer = new AnswerCommand();
IQ iq = new IQ(IQ.Type.set)
.setFrom(buildFrom(connection))
.setTo(buildTo(connection,callId))
.setChild(Extension.create(answer));
connection.send(iq);
Ssml item = new Ssml("Welcome to our Application. Please enter 5 digits.");
Output output = new Output();
output.setPrompt(item);
iq = new IQ(IQ.Type.set)
.setFrom(buildFrom(connection))
.setTo(buildTo(connection,callId))
.setChild(Extension.create(output));
connection.sendAndWait(iq);
Thread.sleep(5000);
Input input = new Input();
List<Choices> list = new ArrayList<Choices>();
Choices grammars = new Choices();
grammars.setContent("[4-5 DIGITS]");
grammars.setContentType("application/grammar+voxeo");
list.add(grammars);
input.setGrammars(list);
input.setTerminator('#');
input.setMode(InputMode.DTMF);
iq = new IQ(IQ.Type.set)
.setFrom(buildFrom(connection))
.setTo(buildTo(connection,callId))
.setChild(Extension.create(input));
System.out.println(String.format("sending out iq: %s",iq));
connection.sendAndWait(iq);
System.out.println("Waiting for the complete event. Type some digits in the keypad.");
Extension extension = connection.waitForExtension("complete");
InputCompleteEvent complete = (InputCompleteEvent)extension.getObject();
System.out.println("Success: " + complete.isSuccess());
}
private String buildFrom(XmppConnection connection) {
return connection.getUsername() + "@" + connection.getServiceName() + "/" + connection.getResource();
}
private String buildTo(XmppConnection connection, String callid) {
return callid + "@" + connection.getServiceName();
}
public static void main(String[] args) throws Exception {
new InputSample().run();
}
}