-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Intents and slots prompts confirmation #366
base: master
Are you sure you want to change the base?
Changes from all commits
3d7cb6d
3a599d2
958782a
45a6d73
a24af77
8ae8818
c6444d2
39abf5e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -312,6 +312,7 @@ alexa.intent = function(name, schema, handler) { | |
this.dialog = (schema && typeof schema.dialog !== "undefined") ? schema.dialog : {}; | ||
this.slots = (schema && typeof schema["slots"] !== "undefined") ? schema["slots"] : null; | ||
this.utterances = (schema && typeof schema["utterances"] !== "undefined") ? schema["utterances"] : null; | ||
this.prompts = schema && typeof schema["prompts"] !== "undefined" ? schema["prompts"] : null; | ||
|
||
this.isDelegatedDialog = function() { | ||
return this.dialog.type === "delegate"; | ||
|
@@ -684,12 +685,26 @@ alexa.app = function(name) { | |
if (intent.slots && Object.keys(intent.slots).length > 0) { | ||
intentSchema["slots"] = []; | ||
for (key in intent.slots) { | ||
// It's unclear whether `samples` is actually used for slots, | ||
// but the interaction model will not build without an (empty) array | ||
const slot = intent.slots[key]; | ||
const type = slot.type ? slot.type : slot; | ||
const samples = []; | ||
if (slot.samples) { | ||
slot.samples.forEach(function(sample) { | ||
var list = AlexaUtterances( | ||
sample, | ||
intent.slots, | ||
self.dictionary, | ||
self.exhaustiveUtterances | ||
); | ||
list.forEach(function(utterance) { | ||
samples.push(utterance); | ||
}); | ||
}); | ||
} | ||
intentSchema.slots.push({ | ||
"name": key, | ||
"type": intent.slots[key], | ||
"samples": [] | ||
name: key, | ||
type, | ||
samples | ||
}); | ||
} | ||
} | ||
|
@@ -733,9 +748,13 @@ alexa.app = function(name) { | |
if (intent.slots && Object.keys(intent.slots).length > 0) { | ||
intentSchema["slots"] = []; | ||
for (key in intent.slots) { | ||
const slot = intent.slots[key]; | ||
const type = slot.type ? slot.type : slot; | ||
const samples = slot.type ? slot.samples : []; | ||
intentSchema.slots.push({ | ||
"name": key, | ||
"type": intent.slots[key] | ||
"type": type, | ||
"samples": samples | ||
}); | ||
} | ||
} | ||
|
@@ -750,16 +769,92 @@ alexa.app = function(name) { | |
}, | ||
askcli: function(invocationName) { | ||
var model = skillBuilderSchema(); | ||
var { prompts, dialog } = skillBuilderDialog(); | ||
model.invocationName = invocationName || self.invocationName || self.name; | ||
var schema = { | ||
interactionModel: { | ||
languageModel: model | ||
languageModel: model, | ||
dialog, | ||
prompts | ||
} | ||
}; | ||
return JSON.stringify(schema, null, 3); | ||
} | ||
}; | ||
|
||
var skillBuilderDialog = function() { | ||
var schema = { | ||
dialog: { | ||
intents: [] | ||
}, | ||
prompts: [] | ||
}, | ||
intentName, | ||
intent, | ||
key; | ||
|
||
var creatPrompt = function(promptId, variations) { | ||
return { | ||
id: promptId, | ||
variations: variations.map(prompt => ({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if this should check if the user's passed in an already-constructed response object, and if so just use that instead of string-concatenating SSML for them? I'm not sure if I'm being silly, and maybe there's no reason anyone would want to do that in practice, but seeing SSML being manually constructed like this usually gives me pause. |
||
type: "SSML", | ||
value: "<speak>" + prompt + "</speak>" | ||
})) | ||
}; | ||
}; | ||
|
||
for (intentName in self.intents) { | ||
intent = self.intents[intentName]; | ||
var intentSchema = { | ||
name: intent.name, | ||
confirmationRequired: false, | ||
prompts: {}, | ||
slots: [] | ||
}; | ||
|
||
if (intent.prompts) { | ||
var intentConfirmPromptId = "Confirm.Intent." + schema.prompts.length; | ||
schema.prompts.push(creatPrompt(intentConfirmPromptId, intent.prompts)); | ||
intentSchema.prompts.confirmation = intentConfirmPromptId; | ||
intentSchema.confirmationRequired = true; | ||
} | ||
|
||
if (intent.slots && Object.keys(intent.slots).length > 0) { | ||
for (key in intent.slots) { | ||
var slot = intent.slots[key]; | ||
var dialogIntentSlot = { | ||
name: key, | ||
type: slot.type || slot, | ||
prompts: {}, | ||
elicitationRequired: false, | ||
confirmationRequired: false | ||
}; | ||
if (slot.elicitationPrompts) { | ||
var elicitPromptId = "Elicit.Slot." + schema.prompts.length; | ||
schema.prompts.push( | ||
creatPrompt(elicitPromptId, slot.elicitationPrompts) | ||
); | ||
dialogIntentSlot.elicitationRequired = true; | ||
dialogIntentSlot.prompts.elicitation = elicitPromptId; | ||
} | ||
if (slot.confirmationPrompts) { | ||
var confirmPromptId = "Confirm.Slot." + schema.prompts.length; | ||
schema.prompts.push( | ||
creatPrompt(confirmPromptId, slot.confirmationPrompts) | ||
); | ||
dialogIntentSlot.confirmationRequired = true; | ||
dialogIntentSlot.prompts.confirmation = confirmPromptId; | ||
} | ||
|
||
intentSchema.slots.push(dialogIntentSlot); | ||
} | ||
} | ||
schema.dialog.intents.push(intentSchema); | ||
} | ||
|
||
return schema; | ||
}; | ||
|
||
// extract the schema and generate a schema JSON object | ||
this.schema = function() { | ||
return this.schemas.intent(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be named
createPrompt
, yeah?