-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHelpPrompt.java
81 lines (73 loc) · 2.91 KB
/
HelpPrompt.java
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
import java.util.HashMap;
import java.util.Map;
import org.sample.aws.lex.request.Bot;
import org.sample.aws.lex.request.Intent;
import org.sample.aws.lex.request.LexRequest;
import org.sample.aws.lex.response.DialogAction;
import org.sample.aws.lex.response.LexResponse;
import org.sample.aws.lex.response.Message;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
public class HelpPrompt implements RequestHandler<Map<String,Object>, Object> {
static Bot bot;
public HelpPrompt() {
try {
init();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void init() throws Exception {
bot = new Bot();
bot.setName("SpeechTherapyBot");
bot.setVersion("$LATEST");
}
@Override
public Object handleRequest(Map<String, Object> input, Context context) {
// TODO Auto-generated method stub
context.getLogger().log("Received request: " + context);
LexRequest lexRequest = createLexRequest(input);
try {
init();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
DialogAction dialogAction = new DialogAction();
String response = "You can say start to start a session and quit at any time to stop. "
+ "You can also say skip or repeat for each phrase.";
dialogAction.setType(DialogAction.ELICIT_INTENT_TYPE);
Message message = new Message(Message.CONTENT_TYPE_PLAIN_TEXT, response);
dialogAction.setMessage(message);
return new LexResponse(dialogAction,lexRequest.getSessionAttributes());
}
private static LexRequest createLexRequest(Map<String,Object> input){
LexRequest req = new LexRequest();
req.setBot(bot);
req.setCurrentIntent(createIntent((Map<String,Object>)input.get("currentIntent")));
if(input.containsKey("confirmationStatus"))
req.setConfirmationStatus((String)input.get("confirmationStatus"));
if(input.containsKey("inputTranscript"))
req.setInputTranscript((String)input.get("inputTranscript"));
if(input.containsKey("invocationSource"))
req.setInvocationSource((String)input.get("invocationSource"));
if(input.containsKey("messageVersion"))
req.setMessageVersion((String)input.get("messageVersion"));
if(input.containsKey("outputDialogMode"))
req.setOutputDialogMode((String)input.get("outputDialogMode"));
if(input.containsKey("sessionAttributes"))
req.setSessionAttributes((Map<String,String>)input.get("sessionAttributes"));
if(input.containsKey("userId"))
req.setUserId((String)input.get("userId"));
return req;
}
private static Intent createIntent(Map<String,Object> m){
Intent i = new Intent();
if(m.containsKey("name"))
i.setName((String)m.get("name"));
if(m.containsKey("slots"))
i.setSlots((Map<String,String>)m.get("slots"));
return i;
}
}