/dff-alice-connector

Primary LanguagePythonApache License 2.0Apache-2.0

Dff Alice Connector

Df Alice Connector is an extension to the Dialogflow Engine, a minimalistic open-source engine for conversational services.

Df Alice Connector allows you to program FSM-based skills for Yandex's Alice using df_engine. Using this add-on, you can take advantage of the features Alice offers, like the recognition of entities and intents, and incorporate them in your script as conditions for FSM transitions.

Codestyle Tests License Apache 2.0 Python 3.6, 3.7, 3.8, 3.9

Quick Start

Installation

pip install df-alice-connector

Conditions

Entities & intents

import df_alice_connector as AliceConn
from df_alice_connector.request import GeoEntity, FioEntity, DateTimeEntity, YandexDefaultIntents, Intent

# Use this method to filter out requests that include one or several entities of a certain type.
AliceConn.cnd.has_geo(entities=[GeoEntity(...), GeoEntity(...)], full_match=...)
AliceConn.cnd.has_fio(entities=[FioEntity(...), FioEntity(...)], full_match=...)
AliceConn.cnd.has_datetime(entities=[DatetimeEntity(...), DatetimeEntity(...)], full_match=...)
AliceConn.cnd.has_number(enities=[1.0, 1.2])

# Use `has_intents` to filter requests that include a certain standard yandex intent.
AliceConn.cnd.has_intents(intents=[YandexDefaultIntents.HELP, YandexDefaultIntents.REPEAT])

intent: Intent
AliceConn.cnd.has_intents(func = lambda intent: intent.slots["some_slot"]["value"] == "y")

Request properties

import df_alice_connector as AliceConn
from df_alice_connector.request import YandexRequestType

# Use `has_request_type` to filter requests depending on the type.
AliceConn.cnd.has_request_type(types=[YandexRequestType.SIMPLEUTTERANCE, ...])

# Use `has_payload` to process requests sent on button press. 
AliceConn.cnd.has_payload(func = lambda x: x["key"] == "value", payload={"key": "value"})

Other conditions

import df_alice_connector as AliceConn
from df_alice_connector.request import YandexRequestModel

# Use `has_tokens` to filter requests depending on whether or not they include `tokens` or `banned_tokens`.
AliceConn.cnd.has_tokens(tokens=["token_1", ...], banned_tokens=["token_3", ...])

# Use the `apply` method to compare the request against any boolean function.
request: YandexRequestModel
AliceConn.cnd.apply(func=lambda request: request.command.startswith("включи свет"))

To get more advanced examples, take a look at examples on GitHub.

Contributing to the Dialog Flow Engine

Please refer to CONTRIBUTING.md.