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($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 to

  • message (string) – The message text

  • parse_type (string) – Message format ("HTML", "Markdown")

Example:

Bot::sendMessage($chatId, "Hello <b>World</b>!", "HTML");

πŸ’Ύ 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 data

  • value (mixed) – The value to store

Example:

Bot::setProperty("status", "Under Development");

πŸ” 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('status');

Description: Deletes a previously stored property.

Parameters:

  • key (string) – The key to delete

Example:

Bot::deleteProperty("status");

πŸ‘€ 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()

$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($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 execute

  • chat_type (string|null) – Optional: Filter by private, group, chanel, etc.

  • time (int|null) – Optional: Unix timestamp of when to run the command

  • options (array) – Optional: Extra data to pass to the command

Example:

Bot::runAll("start", "private", time() + 3600, ["promo" => "yes"]);

🧩 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 name

  • userId (int|string) – The user to run the command as

  • time (int|null) – Optional: Unix timestamp to delay execution

  • options (array) – Optional: Extra data to include

Example:

Bot::runCommand("checkStatus", 123456789, null, ["key" => "value"]);

🌐 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");

$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