Last active
February 28, 2023 18:18
-
-
Save salvatorecordiano/2fd5f4ece35e75ab29b49316e6b6a273 to your computer and use it in GitHub Desktop.
Sample Telegram Bot (1)
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 | |
$content = file_get_contents("php://input"); | |
$update = json_decode($content, true); | |
if(!$update) | |
{ | |
exit; | |
} | |
$message = isset($update['message']) ? $update['message'] : ""; | |
$messageId = isset($message['message_id']) ? $message['message_id'] : ""; | |
$chatId = isset($message['chat']['id']) ? $message['chat']['id'] : ""; | |
$firstname = isset($message['chat']['first_name']) ? $message['chat']['first_name'] : ""; | |
$lastname = isset($message['chat']['last_name']) ? $message['chat']['last_name'] : ""; | |
$username = isset($message['chat']['username']) ? $message['chat']['username'] : ""; | |
$date = isset($message['date']) ? $message['date'] : ""; | |
$text = isset($message['text']) ? $message['text'] : ""; | |
$text = trim($text); | |
$text = strtolower($text); | |
header("Content-Type: application/json"); | |
$response = ''; | |
if(strpos($text, "/start") === 0 || $text=="ciao") | |
{ | |
$response = "Ciao $firstname, benvenuto!"; | |
} | |
elseif($text=="domanda 1") | |
{ | |
$response = "risposta 1"; | |
} | |
elseif($text=="domanda 2") | |
{ | |
$response = "risposta 2"; | |
} | |
else | |
{ | |
$response = "Comando non valido!"; | |
} | |
$parameters = array('chat_id' => $chatId, "text" => $response); | |
$parameters["method"] = "sendMessage"; | |
echo json_encode($parameters); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ciao, non ho esperienza di programmazione . Vorrei creare un bot che pone una domanda alla persona che accede e in automatico la risposta viene salvata ad esempio in uno sheet di google dopodichè all' utente appare un bottone che lo porta in un canale telegram.E' fattibile?