-
Notifications
You must be signed in to change notification settings - Fork 90
Available methods
##Available methods
- Constructor
- getMe
- sendMessage
- forwardMessage
- sendPhoto
- sendAudio
- sendDocument
- sendSticker
- sendVideo
- sendVoice
- sendChatAction
- getUserProfilePhotos
- getUpdates
- setwebhook
- getWebhookUpdates
- ReplyKeyboardMarkup
- ReplyKeyboardHide
- ForceReply
$tg = new telegramBot($token);
A simple method for testing your bot's auth token. Returns basic information about the bot in form of a User object.
$tg->getMe();
Use this method to send text messages. On success, the sent Message is returned.
$tg->sendMessage($chat_id, $text);
You can use Markdown in your message too:
$tg->sendMessage($chat_id, $text, 'Markdown');
More info. about Markdown support
Use this method to forward messages of any kind. On success, the sent Message is returned.
$tg->forwardMessage($chat_id, $from_chat_id, $message_id);
Use this method to send photos. On success, the sent Message is returned.
Supported image types: jpg, jpeg, png, gif, bmp and tif
$tg->sendPhoto($chat_id, $image, $caption);
Use this method to send audio files, if you want Telegram clients to display them in the music player. Your audio must be in the .mp3 format. On success, the sent Message is returned. Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future.
For backward compatibility, when the fields title and performer are both empty and the mime-type of the file to be sent is not audio/mpeg, the file will be sent as a playable voice message. For this to work, the audio must be in an .ogg file encoded with OPUS. This behavior will be phased out in the future. For sending voice messages, use the sendVoice method instead.
$tg->sendAudio($chat_id, $audio)
Use this method to send general files. On success, the sent Message is returned. Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future.
$tg->sendDocument($chat_id, $document);
Use this method to send .webp stickers. On success, the sent Message is returned.
$tg->sendSticker($chat_id, $sticker);
Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document). On success, the sent Message is returned. Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future.
$tg->sendVideo($chat_id, $video);
Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Audio or Document). On success, the sent Message is returned. Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future.
$tg->sendVoice($chat_id, $audio);
Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status).
Type of action to broadcast. Choose one, depending on what the user is about to receive: typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_audio or upload_audio for audio files, upload_document for general files, find_location for location data.
$tg->sendChatAction($chat_id, $action);
Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object.
$tg->getUserProfilePhotos($user_id);
Use this method to receive incoming updates using long polling (Use this method to receive incoming updates using long polling (wiki)). An Array of Update objects is returned.
$tg->getUpdates();
The library supports all the methods listed on Bot API docs page. More examples coming soon.
Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. In case of an unsuccessful request, we will give up after a reasonable amount of attempts.
If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the URL, e.g. www.example.com/. Since nobody else knows your bot‘s token, you can be pretty sure it’s us.
$tg->setWebhook($url);
You can upload your public key certificate so that the root certificate in use can be checked.
$tg->setWebhook($url, 'myCert.crt');
When you set your webhook URL, Telegram will start sending POST requests whenever there's any incoming message/update with your bot.
Below function will help you retrieve the updates. Returns an Update
object.
$tg->getWebhookUpdates();
This object represents a custom keyboard with reply options.
Example:
$customKeyboard = [
['7', '8', '9'],
['4', '5', '6'],
['1', '2', '3'],
['0']
];
$reply_markup = $tg->replyKeyboardMarkup($customKeyboard, true, true);
$tg->sendMessage($chat_id, $text, false, null, $reply_markup);
Upon receiving a message with this object, Telegram clients will hide the current custom keyboard and display the default letter-keyboard. By default, custom keyboards are displayed until a new keyboard is sent by a bot. An exception is made for one-time keyboards that are hidden immediately after the user presses a button
$selective
: Use this parameter if you want to hide keyboard for specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message.
$reply_markup = $tg->replyKeyboardHide();
$tg->sendMessage($chat_id, $text, false, null, $reply_markup);
Upon receiving a message with this object, Telegram clients will display a reply interface to the user (act as if the user has selected the bot‘s message and tapped ’Reply'). This can be extremely useful if you want to create user-friendly step-by-step interfaces without having to sacrifice privacy mode.
$selective
: Use this parameter if you want to force reply from specific users only.
Targets:
-
users that are @mentioned in the text of the Message object;
-
if the bot's message is a reply (has reply_to_message_id), sender of the original message.
$reply_markup = $tg->forceReply();
$tg->sendMessage($chat_id, $text, false, null, $reply_markup);
:)