isamarin/alisa

This package is abandoned and no longer maintained. No replacement package was suggested.

Yandex Alice (Dialogs) skill framework for PHP — triggers, NLU helpers, session state

Maintainers

Package info

github.com/isamarin/alisa

Homepage

Issues

pkg:composer/isamarin/alisa

Transparency log

Statistics

Installs: 104

Dependents: 0

Suggesters: 0

Stars: 5

1.0.2 2019-11-28 16:09 UTC

README

PHP-фреймворк для навыков Яндекс.Алисы (Dialogs webhook): триггеры, распознавание фраз, кнопки, сессии.

CI

Status: archived (maintenance snapshot)

State Archived on GitHub — read-only history + last green CI
Last meaningful work 2026: PHP 8.1+, protocol fixup (end_session, url, application_id, session_state), tests
Core idea 2019 rule-based skill runtime (token groups ≈ bag-of-words / lemmas)

Good for

  • Tiny closed-set skills (десяток команд, keyword intents)
  • Learning the shape of an Alice webhook in PHP
  • Historical / portfolio context

Not for (2026+)

  • Production multi-turn NLU or “understanding”
  • Serverless-first skills (file sessions are legacy)
  • New products — prefer Dialogs built-in NLU / thin webhook + your own state machine / LLM where it fits

BoW here answers “which keywords appeared?”, not “what does the user want?”.
Morphology and Damerau–Levenshtein only normalize or rank surface forms; they are not a language model.

No further feature work planned. Fork if you need evolution; issues on this repo are closed with the archive.

Install

composer require isamarin/alisa

Опционально:

# морфология (MorphyRecognition «как раньше»)
composer require nqxcode/phpmorphy

# HTTP-hop для substituteTriggerTo()
composer require guzzlehttp/guzzle

Словари phpMorphy (русский):
https://sourceforge.net/projects/phpmorphy/files/phpmorphy-dictionaries/

Quick start

<?php

use isamarin\Alisa\Alisa;
use isamarin\Alisa\Response;
use isamarin\Alisa\Trigger;

require __DIR__ . '/vendor/autoload.php';

$bot = new Alisa('my-skill'); // body из php://input
// $bot->setSessionsPath(__DIR__ . '/sessions');
// $bot->setDictionaryPath(__DIR__ . '/dicts'); // если есть phpmorphy + словари

$hello = (new Trigger('HELLO'))->setAsInit();
$mistake = (new Trigger('MISTAKE'))->setAsMistake();
$default = (new Trigger('DEFAULT'))->setAsDefault();

$bye = (new Trigger('BYE'))->linkTokens(['пока', 'до свидания', 'прощай']);

$bot->addTrigger($hello, $mistake, $default, $bye);

$bot->sendResponse($hello, static function () {
    return (new Response())->addText('Привет! Чем помочь?');
});

$bot->sendResponse($bye, static function () {
    return (new Response())
        ->addText('До встречи!')
        ->endSession(); // protocol: end_session
});

$bot->sendResponse($mistake, static function () {
    return (new Response())->addText('Не поняла. Попробуйте иначе.');
});

Cloud Functions / тесты (без exit)

$bot->setExitOnSend(false);
$json = $bot->sendResponse($hello, fn () => (new Response())->addText('ok'));
// return $json; // Yandex Cloud Functions raw integration

Состояние протокола Алисы

Вместо (или вместе с) файловыми сессиями:

$bot->sendResponse($tea, static function () use ($bot) {
    $prev = $bot->getRequest()->getSessionState();
    return (new Response())
        ->addText('Запомнила')
        ->setSessionState(['count' => ($prev['count'] ?? 0) + 1]);
});

Стандартные триггеры

Обязательны три роли (иначе skill ответит подсказкой):

Роль Метод Когда
Init setAsInit() Новая сессия / message_id === 0
Mistake setAsMistake() Команда не распознана (morphy-режим)
Default setAsDefault() Fallback (кнопки без NAME и т.п.)

Распознавание

Morphy (группы токенов)

Все группы должны «попасть» в запрос (по словам, в base form если есть словари):

$blackTea->linkTokens(['дай', 'хочу', 'налей'], ['чай'], ['зеленый']);

Без словарей сравнение идёт по mb_strtoupper токенам NLU — для демо/CI достаточно.

Damerau–Levenshtein

use isamarin\Alisa\DistanceRecognition;

$bot->setAlgorithm(new DistanceRecognition());
$coffee->linkTokens(['налей кофе'], ['хочу кофе']);

Кнопки

use isamarin\Alisa\Button;

$btn = new Button('Сайт');
$btn->addLink('https://example.com'); // → protocol field `url`
$btn->linkTrigger($someTrigger);
$answer->addButton($btn);

Breaking changes (1.x → 2.x)

Было Стало
PHP ^7.1 PHP ^8.1
guzzle / mysqli / phpmorphy required optional / removed hard deps
кнопка link url (по протоколу)
ответ без end_session end_session всегда
только die(json) setExitOnSend(false) → return string
session.user_id only application.application_id (+ BC alias)

Package name на Packagist: isamarin/alisa (репозиторий yandex-alice-php).

Dev

composer install
composer test
composer phpstan

License

MIT · Igor Samarin