Tout d'abord, le dialogState
se trouve dans le IntentRequest
. J'utilise la version 1.3.1 de la dépendance suivante (maven). Pour obtenir la valeur, utilisez yourIntentRequestObject.getDialogState()
.
<dependency>
<groupId>com.amazon.alexa</groupId>
<artifactId>alexa-skills-kit</artifactId>
<version>1.3.1</version>
</dependency>
Vous trouverez ci-dessous un exemple d'utilisation d'un Speechlet
dans le onIntent
méthode :
if ("DoSomethingSpecialIntent".equals(intentName))
{
// If the IntentRequest dialog state is STARTED
// This is where you can pre-fill slot values with defaults
if (dialogueState == IntentRequest.DialogState.STARTED)
{
// 1.
DialogIntent dialogIntent = new DialogIntent(intent);
// 2.
DelegateDirective dd = new DelegateDirective();
dd.setUpdatedIntent(dialogIntent);
List<Directive> directiveList = new ArrayList<Directive>();
directiveList.add(dd);
SpeechletResponse speechletResp = new SpeechletResponse();
speechletResp.setDirectives(directiveList);
// 3.
speechletResp.setShouldEndSession(false);
return speechletResp;
}
else if (dialogueState == IntentRequest.DialogState.COMPLETED)
{
String sampleSlotValue = intent.getSlot("sampleSlotName").getValue();
String speechText = "found " + sampleSlotValue;
// Create the Simple card content.
SimpleCard card = new SimpleCard();
card.setTitle("HelloWorld");
card.setContent(speechText);
// Create the plain text output.
PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
speech.setText(speechText);
return SpeechletResponse.newTellResponse(speech, card);
}
else
{
// This is executed when the dialog is in state e.g. IN_PROGESS. If there is only one slot this shouldn't be called
DelegateDirective dd = new DelegateDirective();
List<Directive> directiveList = new ArrayList<Directive>();
directiveList.add(dd);
SpeechletResponse speechletResp = new SpeechletResponse();
speechletResp.setDirectives(directiveList);
speechletResp.setShouldEndSession(false);
return speechletResp;
}
}
- Créer un nouveau
DialogIntent
- Créer un
DelegateDirective
et l'assigner à la updatedIntent
propriété
- Définissez le
shoulEndSession
pour false
sinon, Alexa met fin à la session
Dans le SkillBuilder, sélectionnez votre intention. Elle doit comporter au moins un emplacement marqué comme requis. Configurez les énoncés et les invites. Vous pouvez également utiliser des {noms d'emplacement} dans les invites.
-Sal