Created
January 8, 2019 18:20
-
-
Save DaltonWebDev/b48094356817ece90d88192a3f14d5a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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