This variable is used to store the bot token that is used to interact with the Telegram API.
<?php
define("TOKEN", $TOKEN);
?>
This function is used to interact with the Telegram API. You can send a request to the online server to perform various activities.
function bot($method, $datas = []){
$iBadlz = http_build_query($datas);
$url = "https://api.telegram.org/bot" . TOKEN . "/" . $method . "?$iBadlz";
$iBadlz = file_get_contents($url);
return json_decode($iBadlz);
}
This variable is used to store the bot token that is used to interact with the Telegram API.
This function is used to interact with the Telegram API. You can send a request to the online server to perform various activities.
<?php
define("Here_TOKEN", $TOKEN);
?>
function bot($method, $datas = []){
$iBadlz = http_build_query($datas);
$url = "https://api.telegram.org/bot" . TOKEN . "/" . $method . "?$iBadlz";
$iBadlz = file_get_contents($url);
return json_decode($iBadlz);
}
This function is used to add content to a specific file on the server. It can be used to store data in text files or any other type of files.
function Add($path, $content){
$file = fopen("$path", "a") or die("Unable to open file!");
fwrite($file, "$content");
fclose($file);
}
This function is used to retrieve updates coming from the Telegram server. Parameters like the maximum number of updates and others can be specified.
function GetUpdates($offset = null, $limit = 100, $timeout = null, $allowed_updates = []){
return bot('getUpdates', [
'offset' => $offset,
'limit' => $limit,
'timeout' => $timeout,
'allowed_updates' => $allowed_updates
]);
}
This function is used to set a webhook address for the bot. This can be used to receive updates via the web instead of using server polling.
function SetWebhook($url, $certificate = null, $max_connections = 100, $allowed_updates = []){
return bot('setWebhook', [
'url' => $url,
'certificate' => $certificate,
'max_connections' => $max_connections,
'allowed_updates' => $allowed_updates,
]);
}
This function is used to send a message to a specific chat. It takes parameters like chat ID, message text, and optional parameters such as parse mode.
function SendMessage($chat_id, $text, $parse_mode = null, $disable_web_page_preview = false, $reply_to_message_id = null, $reply_markup = null){
return bot('sendMessage', [
'chat_id' => $chat_id,
'text' => $text,
'parse_mode' => $parse_mode,
'disable_web_page_preview' => $disable_web_page_preview,
'reply_to_message_id' => $reply_to_message_id,
'reply_markup' => $reply_markup
]);
}
This function forwards messages of any kind from one chat to another.
function ForwardMessage($chat_id, $from_chat_id, $message_id){
return bot('forwardMessage', [
'chat_id' => $chat_id,
'from_chat_id' => $from_chat_id,
'message_id' => $message_id
]);
}
This function sends photos to a specific chat.
function SendPhoto($chat_id, $photo, $caption = null, $parse_mode = null, $reply_to_message_id = null, $reply_markup = null){
return bot('sendPhoto', [
'chat_id' => $chat_id,
'photo' => $photo,
'caption' => $caption,
'parse_mode' => $parse_mode,
'reply_to_message_id' => $reply_to_message_id,
'reply_markup' => $reply_markup
]);
}
This function sends audio files to a specific chat.
function SendAudio($chat_id, $audio, $caption = null, $parse_mode = null, $duration = null, $performer = null, $title = null, $thumb = null, $reply_to_message_id = null, $reply_markup = null){
return bot('sendAudio', [
'chat_id' => $chat_id,
'audio' => $audio,
'caption' => $caption,
'parse_mode' => $parse_mode,
'duration' => $duration,
'performer' => $performer,
'title' => $title,
'thumb' => $thumb,
'reply_to_message_id' => $reply_to_message_id,
'reply_markup' => $reply_markup
]);
}
This function sends general files to a specific chat.
function SendDocument($chat_id, $document, $thumb = null, $caption = null, $parse_mode = null, $disable_content_type_detection = false, $reply_to_message_id = null, $reply_markup = null){
return bot('sendDocument', [
'chat_id' => $chat_id,
'document' => $document,
'thumb' => $thumb,
'caption' => $caption,
'parse_mode' => $parse_mode,
'disable_content_type_detection' => $disable_content_type_detection,
'reply_to_message_id' => $reply_to_message_id,
'reply_markup' => $reply_markup
]);
}
This function sends videos to a specific chat.
function SendVideo($chat_id, $video, $duration = null, $width = null, $height = null, $thumb = null, $caption = null, $parse_mode = null, $supports_streaming = false, $reply_to_message_id = null, $reply_markup = null){
return bot('sendVideo', [
'chat_id' => $chat_id,
'video' => $video,
'duration' => $duration,
'width' => $width,
'height' => $height,
'thumb' => $thumb,
'caption' => $caption,
'parse_mode' => $parse_mode,
'supports_streaming' => $supports_streaming,
'reply_to_message_id' => $reply_to_message_id,
'reply_markup' => $reply_markup
]);
}
This function sends voice messages to a specific chat.
function SendVoice($chat_id, $voice, $caption = null, $parse_mode = null, $duration = null, $reply_to_message_id = null, $reply_markup = null){
return bot('sendVoice', [
'chat_id' => $chat_id,
'voice' => $voice,
'caption' => $caption,
'parse_mode' => $parse_mode,
'duration' => $duration,
'reply_to_message_id' => $reply_to_message_id,
'reply_markup' => $reply_markup
]);
}
This function sends a location to a specific chat.
function SendLocation($chat_id, $latitude, $longitude, $live_period = null, $reply_to_message_id = null, $reply_markup = null){
return bot('sendLocation', [
'chat_id' => $chat_id,
'latitude' => $latitude,
'longitude' => $longitude,
'live_period' => $live_period,
'reply_to_message_id' => $reply_to_message_id,
'reply_markup' => $reply_markup
]);
}
This function sends a chat action to indicate that the bot is performing some activity (like typing, uploading, etc.).
function SendChatAction($chat_id, $action){
return bot('sendChatAction', [
'chat_id' => $chat_id,
'action' => $action
]);
}
This function retrieves a list of profile pictures for a specific user.
function GetUserProfilePhotos($user_id, $offset = null, $limit = 100){
return bot('getUserProfilePhotos', [
'user_id' => $user_id,
'offset' => $offset,
'limit' => $limit
]);
}
This function retrieves basic information about a file and prepares it for downloading.
function GetFile($file_id){
return bot('getFile', [
'file_id' => $file_id
]);
}
This function kicks a user from a group, a supergroup, or a channel.
function KickChatMember($chat_id, $user_id, $until_date = null){
return bot('kickChatMember', [
'chat_id' => $chat_id,
'user_id' => $user_id,
'until_date' => $until_date
]);
}
This function unbans a previously kicked user in a supergroup or channel.
function UnbanChatMember($chat_id, $user_id){
return bot('unbanChatMember', [
'chat_id' => $chat_id,
'user_id' => $user_id
]);
}
This function restricts a user in a supergroup. The bot must be an administrator in the supergroup for this to work.
function RestrictChatMember($chat_id, $user_id, $permissions, $until_date = null){
return bot('restrictChatMember', [
'chat_id' => $chat_id,
'user_id' => $user_id,
'permissions' => $permissions,
'until_date' => $until_date
]);
}
This function promotes or demotes a user in a supergroup or channel.
function PromoteChatMember($chat_id, $user_id, $can_change_info = false, $can_post_messages = false, $can_edit_messages = false, $can_delete_messages = false, $can_invite_users = false, $can_restrict_members = false, $can_pin_messages = false, $can_promote_members = false){
return bot('promoteChatMember', [
'chat_id' => $chat_id,
'user_id' => $user_id,
'can_change_info' => $can_change_info,
'can_post_messages' => $can_post_messages,
'can_edit_messages' => $can_edit_messages,
'can_delete_messages' => $can_delete_messages,
'can_invite_users' => $can_invite_users,
'can_restrict_members' => $can_restrict_members,
'can_pin_messages' => $can_pin_messages,
'can_promote_members' => $can_promote_members
]);
}
This function sets a custom title for an administrator in a supergroup.
function SetChatAdministratorCustomTitle($chat_id, $user_id, $custom_title){
return bot('setChatAdministratorCustomTitle', [
'chat_id' => $chat_id,
'user_id' => $user_id,
'custom_title' => $custom_title
]);
}
This function sets default chat permissions for all members.
function SetChatPermissions($chat_id, $permissions){
return bot('setChatPermissions', [
'chat_id' => $chat_id,
'permissions' => $permissions
]);
}
This function generates a new primary invite link for a chat; any previously generated primary link is revoked.
function ExportChatInviteLink($chat_id){
return bot('exportChatInviteLink', [
'chat_id' => $chat_id
]);
}
This function creates an additional invite link for a chat.
function CreateChatInviteLink($chat_id, $expire_date = null, $member_limit = null){
return bot('createChatInviteLink', [
'chat_id' => $chat_id,
'expire_date' => $expire_date,
'member_limit' => $member_limit
]);
}
This function edits a non-primary invite link created by the bot.
function EditChatInviteLink($chat_id, $invite_link, $expire_date = null, $member_limit = null){
return bot('editChatInviteLink', [
'chat_id' => $chat_id,
'invite_link' => $invite_link,
'expire_date' => $expire_date,
'member_limit' => $member_limit
]);
}
This function revokes an invite link created by the bot.
function RevokeChatInviteLink($chat_id, $invite_link){
return bot('revokeChatInviteLink', [
'chat_id' => $chat_id,
'invite_link' => $invite_link
]);
}
This function sets a new profile photo for the chat.
function SetChatPhoto($chat_id, $photo){
return bot('setChatPhoto', [
'chat_id' => $chat_id,
'photo' => $photo
]);
}
This function deletes a chat's profile photo.
function DeleteChatPhoto($chat_id){
return bot('deleteChatPhoto', [
'chat_id' => $chat_id
]);
}
This function sets a new title for the chat.
function SetChatTitle($chat_id, $title){
return bot('setChatTitle', [
'chat_id' => $chat_id,
'title' => $title
]);
}
This function sets a new description for the chat.
function SetChatDescription($chat_id, $description){
return bot('setChatDescription', [
'chat_id' => $chat_id,
'description' => $description
]);
}
This function pins a message in the chat.
function PinChatMessage($chat_id, $message_id, $disable_notification = false){
return bot('pinChatMessage', [
'chat_id' => $chat_id,
'message_id' => $message_id,
'disable_notification' => $disable_notification
]);
}
This function unpins a message in the chat.
function UnpinChatMessage($chat_id, $message_id){
return bot('unpinChatMessage', [
'chat_id' => $chat_id,
'message_id' => $message_id
]);
}
This function allows the bot to leave a group, supergroup, or channel.
function LeaveChat($chat_id){
return bot('leaveChat', [
'chat_id' => $chat_id
]);
}
This function gets up-to-date information about a chat.
function GetChat($chat_id){
return bot('getChat', [
'chat_id' => $chat
]);
}
This function returns a list of administrators in a chat.
function GetChatAdministrators($chat_id){
return bot('getChatAdministrators', [
'chat_id' => $chat_id
]);
}
This function returns the number of members in a chat.
function GetChatMembersCount($chat_id){
return bot('getChatMembersCount', [
'chat_id' => $chat_id
]);
}
This function returns information about a member of a chat.
function GetChatMember($chat_id, $user_id){
return bot('getChatMember', [
'chat_id' => $chat_id,
'user_id' => $user_id
]);
}
This function sets a new group sticker set for a supergroup.
function SetChatStickerSet($chat_id, $sticker_set_name){
return bot('setChatStickerSet', [
'chat_id' => $chat_id,
'sticker_set_name' => $sticker_set_name
]);
}
This function deletes a group sticker set from a supergroup.
function DeleteChatStickerSet($chat_id){
return bot('deleteChatStickerSet', [
'chat_id' => $chat_id
]);
}
This function sends answers to callback queries sent from inline keyboards.
function AnswerCallbackQuery($callback_query_id, $text = null, $show_alert = false, $url = null, $cache_time = 0){
return bot('answerCallbackQuery', [
'callback_query_id' => $callback_query_id,
'text' => $text,
'show_alert' => $show_alert,
'url' => $url,
'cache_time' => $cache_time
]);
}
This function changes the list of the bot's commands.
function SetMyCommands($commands){
return bot('setMyCommands', [
'commands' => $commands
]);
}
This function deletes the list of the bot's commands.
function DeleteMyCommands($scope = null, $language_code = null){
return bot('deleteMyCommands', [
'scope' => $scope,
'language_code' => $language_code
]);
}
This function gets the current list of the bot's commands.
function GetMyCommands($scope = null, $language_code = null){
return bot('getMyCommands', [
'scope' => $scope,
'language_code' => $language_code
]);
}
This function edits text and game messages sent by the bot.
function EditMessageText($chat_id, $message_id, $text, $parse_mode = null, $disable_web_page_preview = false, $reply_markup = null){
return bot('editMessageText', [
'chat_id' => $chat_id,
'message_id' => $message_id,
'text' => $text,
'parse_mode' => $parse_mode,
'disable_web_page_preview' => $disable_web_page_preview,
'reply_markup' => $reply_markup
]);
}
This function edits captions of messages sent by the bot.
function EditMessageCaption($chat_id, $message_id, $caption, $parse_mode = null, $caption_entities = null, $reply_markup = null){
return bot('editMessageCaption', [
'chat_id' => $chat_id,
'message_id' => $message_id,
'caption' => $caption,
'parse_mode' => $parse_mode,
'caption_entities' => $caption_entities,
'reply_markup' => $reply_markup
]);
}
This function edits animation, audio, document, photo, or video messages.
function EditMessageMedia($chat_id, $message_id, $media, $reply_markup = null){
return bot('editMessageMedia', [
'chat_id' => $chat_id,
'message_id' => $message_id,
'media' => $media,
'reply_markup' => $reply_markup
]);
}
This function edits only the reply markup of messages sent by the bot.
function EditMessageReplyMarkup($chat_id, $message_id, $reply_markup){
return bot('editMessageReplyMarkup', [
'chat_id' => $chat_id,
'message_id' => $message_id,
'reply_markup' => $reply_markup
]);
}
This function stops a poll which was sent by the bot.
function StopPoll($chat_id, $message_id, $reply_markup = null){
return bot('stopPoll', [
'chat_id' => $chat_id,
'message_id' => $message_id,
'reply_markup' => $reply_markup
]);
}
This function deletes a message, including service messages, with the following limitations: A message can only be deleted if it was sent less than 48 hours ago.
function DeleteMessage($chat_id, $message_id){
return bot('deleteMessage', [
'chat_id' => $chat_id,
'message_id' => $message_id
]);
}
With the functions provided, you can build a fully functional Telegram bot that can interact with users, manage groups and channels, send and receive various types of messages, and perform numerous administrative tasks. This guide covers the basic and some advanced functionalities required to create a versatile Telegram bot using PHP. As you become more familiar with these functions, you can customize and extend your bot to suit specific needs.