-
Notifications
You must be signed in to change notification settings - Fork 2
/
textOrSpeech.js
75 lines (62 loc) · 1.62 KB
/
textOrSpeech.js
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
/**
* dialog unit: textOrSpeech
*
* The dialog just test if user spoken or texted,
* inspecting the speech attribute in the RequestDataObject.
*
* Trick: To simulate a speech input with command line utility:
* naif test shell
*
* just input ALL CAPS
*
*
* askName:
* is the (output state) entry point of the dialog
*
* getSentence:
* is the input state that elaborate the user sentence
* when the user reply anything, the dialog end
*
*/
// get naif dialog manager DSL statements
const { say, next, end } = require('../../')
// define states of current dialog unit
const textOrSpeech = { askSentence, getSentence }
// defines tags
//const askNameState = 'textOrSpeech.askSentence'
const getSentenceState = 'textOrSpeech.getSentence'
/**
* askSentence
* output state handler, dialog entry point (start)
*/
function askSentence() {
say( 'Hello!' )
say( 'Tell me anything, speaking or writing' )
next(getSentenceState)
}
/**
* getSentence
* input state handler
*
* @param {requestDataObject} request
*
*/
function getSentence(request) {
if ( request.speech ) {
//
// end-user spoken -> reply with a speech and a text
//
say( { text: 'Ah! you spoken! I\'m happy your are speaking with your voice.', speech: true } )
say( `BTW, What do you mean with '${request.text.toLowerCase()}' ?` )
}
else {
//
// end-user texted -> reply with just text
//
say( 'Ah! You texted! I\'m happy yo enjoy writing.' )
say( `BTW, What do you mean with '${request.text}' ?` )
}
say( 'Never minds. See you later.' )
end()
}
module.exports = textOrSpeech