library yandex-dialogs-php-sdk
Yandex dialogs API PHP-wrapper
mesilov/yandex-dialogs-php-sdk
Yandex dialogs API PHP-wrapper
- Wednesday, March 14, 2018
- by mesilov
- Repository
- 2 Watchers
- 7 Stars
- 5 Installations
- PHP
- 0 Dependents
- 0 Suggesters
- 0 Forks
- 0 Open issues
- 1 Versions
- 400 % Grown
yandex-dialogs-php-sdk
Π Π΅ΠΏΠΎΠ·ΠΈΡΠΎΡΠΈΠΉ PHP-Π±ΠΈΠ±Π»ΠΈΠΎΡΠ΅ΠΊΠΈ Π΄Π»Ρ ΠΎΠ±Π»Π΅Π³ΡΠ΅Π½ΠΈΡ ΡΠ°Π±ΠΎΡΡ Ρ Π΄ΠΈΠ°Π»ΠΎΠ³Π°ΠΌΠΈ, (*1)
ΠΡΠΈΠΌΠ΅Ρ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ΠΈΡ
// ΠΏΠΎΠ»ΡΡΠ°Π΅ΠΌ Π²Ρ
ΠΎΠ΄ΡΡΠΈΠΉ API-Π·Π°ΠΏΡΠΎΡ
$apiRequestArray = json_decode(trim(file_get_contents('php://input')), true);
$dialogRequest = Yandex\Dialogs\Webhook\Request\Fabric::initFromArray($apiRequestArray);
$responseFabric = new Yandex\Dialogs\Webhook\Response\Fabric($dialogRequest);
$button1 = new Yandex\Dialogs\Webhook\Response\DTO\Buttons\Button();
$button1
->setTitle('ΠΠ½ΠΎΠΏΠΊΠ°1')
->setUrl('https://ya.ru');
$button2 = new Yandex\Dialogs\Webhook\Response\DTO\Buttons\Button();
$button2
->setTitle('ΠΠ½ΠΎΠΏΠΊΠ°2');
$response = $responseFabric
->setText('ΠΡΠΈΠ²Π΅Ρ')
->setTts('ΠΡΠΈΠ²Π΅Ρ')
->addButton($button1)
->addButton($button2)
->buildResponse();
header('Content-Type: application/json');
print(json_encode(Yandex\Dialogs\Webhook\Response\Formatters\Formatter::toArray($response), JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT));