Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
bot-brain.php
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Methods: POST, GET, OPTIONS");
header("Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With");
header("Content-Type: application/json; charset=utf-8");
$command = mb_strtolower($_GET['command']);
$tokens = explode(" ", $command);
$response = [];
$items_tokens = [
'привет' => 'Привет',
'как' => 'Отлично',
'твои' => null,
'дела' => null,
'сколько' => 'мне',
'лет' => '20',
];
foreach ($tokens as $key => $item) {
$message[] = $items_tokens[$item];
}
$response = [
'request' => [
'command' => $command,
'tokens' => $tokens
],
'answer' => [
'message' => implode(" ", $message)
]
];
echo json_encode($response, JSON_UNESCAPED_UNICODE | JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.