Bot:: Library Functions
The Bot:: class provides built-in helper functions to simplify working with your Telegram bots in PHP. Here's a list of available methods you can use inside your command code editor:
π¨ Bot::sendMessage()
Bot::sendMessage()
Bot::sendMessage($chatId, $message, $parse_type = 'HTML');
Description: Sends a text message to a user or group.
Parameters:
chatId
(int|string) β The Telegram chat ID to send the message tomessage
(string) β The message textparse_type
(string) β Message format ("HTML"
,"Markdown"
)
Example:
Bot::sendMessage($chatId, "Hello <b>World</b>!", "HTML");
πΎ Bot::setProperty()
Bot::setProperty()
Bot::setProperty('key', 'value');
Description: Stores a value using a key. This is useful for saving data like user states, progress, or preferences.
Parameters:
key
(string) β The identifier for the datavalue
(mixed) β The value to store
Example:
Bot::setProperty("status", "Under Development");
π Bot::getProperty()
Bot::getProperty()
$value = Bot::getProperty('status');
Description:
Retrieves a previously stored value using setProperty()
.
Parameters:
key
(string) β The key used when saving the value
Returns:
Stored value (or null
if not found)
Example:
$step = Bot::getProperty("status");
β Bot::deleteProperty()
Bot::deleteProperty()
Bot::deleteProperty('status');
Description: Deletes a previously stored property.
Parameters:
key
(string) β The key to delete
Example:
Bot::deleteProperty("status");
π€ Bot::getUser()
Bot::getUser()
$user = Bot::getUser($chat_id);
Description: Gets the stored data of another user by their Telegram chat ID.
Parameters:
chat_id
(int|string) β The Telegram chat ID of the user
Returns:
User data array or null
if user not found.
Example:
$user = Bot::getUser(123456789);
π Bot::getAllUser()
Bot::getAllUser()
$users = Bot::getAllUser();
Description: Retrieves a list of all users that have interacted with the bot.
Returns: Array of user data.
Example:
$allUsers = Bot::getAllUser();
π’ Bot::runAll()
Bot::runAll()
Bot::runAll($command, $chat_type = null, $time = null, $options = []);
Description: Schedules or runs a command for all users, optionally filtering by chat type.
Parameters:
command
(string) β The command to executechat_type
(string|null) β Optional: Filter byprivate
,group
,chanel
, etc.time
(int|null) β Optional: Unix timestamp of when to run the commandoptions
(array) β Optional: Extra data to pass to the command
Example:
Bot::runAll("start", "private", time() + 3600, ["promo" => "yes"]);
π§© Bot::runCommand()
Bot::runCommand()
Bot::runCommand($command, $userId, $time = null, $options = []);
Description: Runs a command as a specific user, optionally scheduled for later.
Parameters:
command
(string) β The command nameuserId
(int|string) β The user to run the command astime
(int|null) β Optional: Unix timestamp to delay executionoptions
(array) β Optional: Extra data to include
Example:
Bot::runCommand("checkStatus", 123456789, null, ["key" => "value"]);
π Bot::getPublicCommandUrl()
Bot::getPublicCommandUrl()
$url = Bot::getPublicCommandUrl($command_id);
Description: Generates a public webhook URL to execute a specific command with POST data.
Parameters:
command_id
(string) β The command ID to expose via public URL
Returns: A public URL string
Example:
$link = Bot::getPublicCommandUrl("externalWebhook");
π Bot::getBotLink()
Bot::getBotLink()
$link = Bot::getBotLink();
Description:
Gets the current bot's public Telegram link (e.g., https://t.me/MyBotName
).
Returns: A string URL of the bot.
Example:
$botUrl = Bot::getBotLink();
Last updated