Skip to content

Instantly share code, notes, and snippets.

@Conobi
Last active November 9, 2016 14:27
Show Gist options
  • Save Conobi/f40ce1f1e08a898455cc66f7d5538fdf to your computer and use it in GitHub Desktop.
Save Conobi/f40ce1f1e08a898455cc66f7d5538fdf to your computer and use it in GitHub Desktop.
Toupie Minimale
<?php
// On initie l'accès à l'api
$botToken = "123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$website = "https://api.telegram.org/bot".$botToken;
// On lit les informations et on les formate
$update = json_decode(file_get_contents('php://input'), TRUE);
// On défini les variables utiles
$chatId = $update["message"]["chat"]["id"];
$id = $update["message"]["from"]["id"];
if($update["message"]["text"] != "") {
$message = $update["message"]["text"];
switch($message) {
case("/about"):
sendMessage($chatId, "Je suis une version minimale de Toupie.")
break;
case(preg_match("#toupie#i", $message) == true):
if(rand(0,1) == 1) {
sendMessage($chatId,'oui');
} else {
sendMessage($chatId,'non');
}
break;
}
}
// -+-+-+-+-+-+-+-
// FONCTIONS
// -+-+-+-+-+-+-+-
function sendMessage ($chatId, $message) {
$url = $GLOBALS['website']."/sendMessage?chat_id=".$chatId."&parse_mode=HTML&text=".urlencode($message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment