Skip to content

Instantly share code, notes, and snippets.

@DaltonWebDev
Created January 8, 2019 18:20
Show Gist options
  • Save DaltonWebDev/b48094356817ece90d88192a3f14d5a7 to your computer and use it in GitHub Desktop.
Save DaltonWebDev/b48094356817ece90d88192a3f14d5a7 to your computer and use it in GitHub Desktop.
<?php
session_start();
header("Content-type: application/json; charset=utf-8");
$username = !empty($_POST["username"]) ? strtolower($_POST["username"]) : false;
$message = !empty($_POST["message"]) ? $_POST["message"] : false;
$sticky = false;
if ($username === false) {
$botMessage = "Who are you?";
} else if ($message === false) {
$botMessage = "Please write something before hitting send.";
} else {
$json = json_decode(file_get_contents("https://catfact.ninja/fact?max_length=1000"), true);
$botMessage = $json["fact"];
}
$outputArray = [
"message" => $botMessage,
"sticky" => $sticky
];
echo json_encode($outputArray);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment