Alexa задает вопрос и получает ответ от внешнего API - программирование
Подтвердить что ты не робот

Alexa задает вопрос и получает ответ от внешнего API

Я настроил простое намерение

{
  "interactionModel": {
    "languageModel": {
      "invocationName": "viva bank",
      "intents": [
        ...builtin intents...{
          "name": "ask",
          "slots": [{
            "name": "question",
            "type": "AMAZON.SearchQuery"
          }],
          "samples": [
            "when {question}",
            "how to {question}",
            "what {question}"
          ]
        }
      ],
      "types": []
    }
  }
}
4b9b3361

Ответ 1

В AskIntentHandler вы должны установить свой "canHandle" на имя намерения, например, в дополнение к проверке слота вопроса.

const AskIntentHandler = {
  canHandle (handlerInput) {
  return handlerInput.requestEnvelope.request.type === 'IntentRequest' &&
      handlerInput.requestEnvelope.request.intent.name === 'AskIntent' &&
      !!handlerInput.requestEnvelope.request.intent.slots['question'].value
  },
  handle (handlerInput) {
     // API Request Here
  }
}

Также, если для выполнения намерения всегда требуется "вопрос", вы можете настроить диалоговое окно, чтобы Alexa спросила пользователя "вопрос", если она его не распознает.

https://developer.amazon.com/docs/custom-skills/delegate-dialog-to-alexa.html