Skip to content

Instantly share code, notes, and snippets.

@salvatorecordiano
Last active February 28, 2023 18:18
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save salvatorecordiano/2fd5f4ece35e75ab29b49316e6b6a273 to your computer and use it in GitHub Desktop.
Save salvatorecordiano/2fd5f4ece35e75ab29b49316e6b6a273 to your computer and use it in GitHub Desktop.
Sample Telegram Bot (1)
<?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);
@massimocascone
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment