I have seen New API for bots are enabled to create custome bots,I have seen some sources such as this and this I have also read about @fatherbot
which is about registering bots,I also searched about some examples about telegram bots such as this one,I know how write codes in php
and python
but can not find out how to call api methods and where to get start.Does any one has any idea how to get start?
You'll see a list of commands that help you create, edit, and manage your bots. Since it's your first time, you'll want /newbot . Compared to the process for building a Twitter bot, a Mastodon bot, or any other kind of bot I've experimented with, Telegram makes the initial setup super easy.
Telegram API This API allows you to build your own customized Telegram clients. It is 100% open for all developers who wish to create Telegram applications on our platform.
Not exactly a private bot With Telegram bots are not private. Everybody can find them. The difference is that a certain communication channel with the bot can be made private. This is a group with the bot that you and the bot are members of.
You can use this basic example to get you going. I would suggest adding a bit more polish using like curl and adding some error handling.
<?php
$bot_id = "<bot ID generated by BotFather>";
# Note: you want to change the offset based on the last update_id you received
$url = 'https://api.telegram.org/bot' . $bot_id . '/getUpdates?offset=0';
$result = file_get_contents($url);
$result = json_decode($result, true);
foreach ($result['result'] as $message) {
var_dump($message);
}
# You can send a message like this:
# The chat_id variable will be provided in the getUpdates result
# TODO: urlencode your message
$url = 'https://api.telegram.org/bot' . $bot_id . '/sendMessage?text=message&chat_id=0';
$result = file_get_contents($url);
$result = json_decode($result, true);
var_dump($result['result']);
According to Official Bot API:
Getting updates
There are two mutually exclusive ways of receiving updates for your bot
— the getUpdates method on one hand and Webhooks on the other.
So PHP bot script works different way by receive schema
The accessing of bot API is through HTTP GET/POST, detail in official help.
If there are new messages
When using WebHook(and well configured), new message to your bot will trigger a HTTP POST request from telegram server to your configured url, on your own server, parsed by your PHP script.
In your PHP script, parse new message come from HTTP POST, and send message back with HTTP POST to telegram server.
So, the difference only exists when getting messages from telegram, all response send to telegram is via HTTP GET/POST, detail in Making requests part in official API.
Some people have mad some unofficial PHP api on github:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With