1. Go to this page and download the library: Download natilosir/telegram-bot-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
natilosir / telegram-bot-sdk example snippets
use natilosir\bot\Route;
Route::add(['/start', 'Back'], 'start')
->add('purchase', 'buy') // Add route for the purchase command
->add('sale', 'sell'); // Add route for the sale command
// Define the default file to handle the start command
Route::def('start'); // Default file
// Handle the input text from the user
Route::handle($text); // Process the incoming text
Route::add(['/start', 'Back'], 'start')
Route::add('/start', 'start'); // This will open controller/start.php when /start is triggered.
Route::add('/send', 'user/send'); // This will open controller/user/send.php when /send is triggered.
// Define the default file to handle the start command
Route::def('start'); // Default file
Route::def('default_message'); // Opens controller/default_message.php if no patterns match
// Assuming you have set up your routes
Route::add('/start', 'start'); // This will open controller/start.php when /start is triggered.
Route::add('/send', 'user/send'); // This will open controller/user/send.php when /send is triggered.
Route::def('default_message'); // Opens controller/default_message.php if no patterns match
Route::handle($text); // Processes the user input
// Define chat ID and message ID
$chatID = 123456789; // Target chat ID
$message_id = 42; // Message ID to be deleted
// Use the deleteMessage method
bot::deleteMessage($chatID, $message_id);
// Define chat IDs and message ID
$chatID = 123456789; // Destination chat ID
$from_chat_id = 987654321; // Source chat ID
$message_id = 42; // Message ID to be forwarded
// Use the forwardMessage method
bot::forwardMessage($chatID, $from_chat_id, $message_id);
// Define the chat ID and message text
$chatID = 123456789; // The target chat ID
$messageText = "Hello! How can I assist you today?";
// Send a message to the chat
bot::sendMessage($chatID, $messageText);
namespace natilosir\bot\bot;
// Define chat IDs and message ID
$chatID = 123456789; // Destination chat ID
$from_chat_id = 987654321; // Source chat ID
$message_id = 42; // ID of the message to be copied
// Use the copyMessage method
bot::copyMessage($chatID, $from_chat_id, $message_id);
$response = Bot::row([
Bot::column('β What is this bot? What is it used for?', 'option_1'),
])
->row([
Bot::column('π How do I connect to a random stranger?', 'option_2'),
])
->row([
Bot::column('π How do I connect to a specific contact?', 'option_3'),
]);
// Display the inline keyboard with the given helper text
// Main message text with the quote formatted
$text = "πjust tap the desired button belowππ»";
// Send the message with reply
$response = Bot::inline($chatID, $text, $message_id);
$response = bot::row([
bot::column('Account Information'),
])
->row([
bot::column('Help'),
bot::column('Contact Us'),
]);
if ($text == 'Back') {
$text = 'You have returned to the main menu.
Please select one of the options below.';
} else {
$text = 'Please select an option from the menu below.';
}
$response = bot::keyboard($chatID, $text, $message_id);
bot::answerCallbackQuery($query_id, "Your action was successful!", true);
// Define the query ID and the message text
$query_id = '1234567890';
$message_text = 'This is an alert message!';
// Send an alert to the user
bot::alert($query_id, $message_text, true);
// Define the chat ID and action
$chatID = 123456789; // Target chat ID
$action = 'typing'; // Action to be sent
// Send the chat action
bot::sendChatAction($chatID, $action);
bash
composer atilosir/bot/install.php
bash
editor.php?file=controller/start.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.