Skip to content

Intents

Alex Volchetsky edited this page Jan 27, 2021 · 3 revisions

Prerequisites

Assume you configured intent using example from official documentation. https://yandex.ru/dev/dialogs/alice/doc/nlu-docpage/

# Описание интента "turn.on" для включения устройств.
# Эта грамматика позволит распознавать такие фразы как "включи свет на кухне"
# или "включи кондиционер в спальне". 

# Корневой элемент грамматики. Описывает шаблон, по которому будет
# отбираться реплика.
root:
    включи $What $Where

# Описание слотов. Диалоги будут отправлять это описание навыку.
slots:
    what:
        source: $What                   
    where:
        source: $Where
$What:
    свет | кондиционер
$Where:
    в ванной | на кухне | в спальне

After that Alice made request with intent:

{
  ...  
  "request": {
    ...
    "nlu": {
      ...
      "intents": {
        "turn.on": {
          "slots": {
            "what": {
              "type": "YANDEX.STRING",
              "tokens": {
                "start": 1,
                "end": 2
              },
              "value": "свет"
            },
            "where": {
              "type": "YANDEX.STRING",
              "tokens": {
                "start": 2,
                "end": 4
              },
              "value": "в ванной"
            }
          }
        }
      }
    }
  },
  ...
} 

After that you need to configure your models to properly receive requests

Configuration

To make skill process such request correctly create new class for your intent:

public class CustomIntents
{
    [JsonPropertyName("turn.on")]
    public AliceIntentModel<CustomTurnOnSlots> TurnOn { get; set; }
}

And new class for slot:

public class CustomTurnOnSlots
{
    [JsonPropertyName("what")]
    [JsonConverter(typeof(AliceEntityModelConverter))]
    public AliceEntityStringModel What { get; set; }

    [JsonPropertyName("where")]
    [JsonConverter(typeof(AliceEntityModelConverter))]
    public AliceEntityStringModel Where { get; set; }
}

Usage

After that use in your action method generic version of AliceRequest class

For instance:

[HttpPost]
[Route("/alice")]
public IActionResult Get(AliceRequest<CustomIntents> aliceRequest)
{
    ...
}

Example

Implementation of aforementioned code you can find here yandex.alice.sdk.demo

Clone this wiki locally