This is a simple example of telegram bot using php without any dependencies. Can work with HTTP proxy.
Your site have to use https protocol.
- Copy files on your site
- Open in browser file bot.php
- Open dialog with @BotFather (https://t.me/BotFather) in your telegram client
- Send /newbot command
- Enter your bot title
- Enter your bot name (ex: @test_bot)
- Copy token to clipboard
- Paste token to form in browser and submit form
- Edit test_bot.php, paste token and bot name
- Talk to your bot
Channel and group chats methods
Inline Keyboards support and callbacks for inline buttons
- answerCallbackQuery() method - Reaction of inline keyboard click
- deleteMessage() method - Deleting message
- editMessageText() method - Editing message
- callbackAnswer() method - Answer method on click for inline button
- callback_default() method - Default callback for inline button
- sendAudio() method - sends audio file with audioplayer (20Mb max)
- HTTP proxy support.
var $commands = [
"/start" => "cmd_start",
"/help" => "cmd_help",
"/hi" => "cmd_hi"
];
function cmd_hi(){
$this->api->sendMessage( "Hi, @" . $this->result["message"]["from"]["username"] . "." );
}
If you want to call telegram API-method not implemented in this repo (i.e. sendLocation: https://core.telegram.org/bots/api#sendlocation) you can call it like this:
$params = [
'chat_id' => 123,
'latitude' => 0,
'longitude' => 0
];
$this->api->call("sendLocation", $params);
example_bot.php - example of the telegram bot, demonstrating main features of this repo. Sorry of russian comments. Test this bot you can here: http://t.me/kpg_test_bot (http://t.kpg.me/kpg_test_bot if blocked t.me)