### Install PhpGram via Composer Source: https://github.com/sh20raj/phpgram/blob/main/README.md Use Composer to install the PhpGram library. This is the recommended method for managing dependencies. ```bash composer require sh20raj/phpgram ``` -------------------------------- ### Get Webhook Info Source: https://github.com/sh20raj/phpgram/blob/main/README.md Retrieve information about the currently configured webhook, including its URL and pending updates. ```php // Get webhook info $response = $bot->getWebhookInfo(); ``` -------------------------------- ### Get Bot Information Source: https://github.com/sh20raj/phpgram/blob/main/README.md Retrieve information about the bot using the getMe method. ```php // Example: Get bot information $botInfo = $bot->getMe(); echo 'Bot Username: ' . $botInfo['result']['username'] . PHP_EOL; ``` -------------------------------- ### Get Bot Information Source: https://github.com/sh20raj/phpgram/blob/main/README.md Retrieve information about the bot itself. ```APIDOC ## Get Bot Information Example: Get bot information ```php // Example: Get bot information $botInfo = $bot->getMe(); echo 'Bot Username: ' . $botInfo['result']['username'] . PHP_EOL; ``` ``` -------------------------------- ### Get Updates Source: https://github.com/sh20raj/phpgram/blob/main/README.md Fetch updates from the Telegram server. This is typically used when not using webhooks. ```php // Get updates $updates = $bot->getUpdates(); ``` -------------------------------- ### Get Game High Scores Source: https://github.com/sh20raj/phpgram/blob/main/README.md Retrieve the high scores for a specific user in a game. ```php // Get game high scores $response = $bot->getGameHighScores($userId); ``` -------------------------------- ### Initialization Source: https://github.com/sh20raj/phpgram/blob/main/README.md Include the library and initialize PhpGram with your bot token. ```APIDOC ## Initialization First, include the library in your PHP file and initialize `PhpGram` with your bot token: ```php require __DIR__ . '/../src/PhpGram.php'; use PhpGram\PhpGram; $token = 'YOUR_BOT_TOKEN'; $bot = new PhpGram($token); ``` ``` -------------------------------- ### Initialize PhpGram Bot Source: https://github.com/sh20raj/phpgram/blob/main/README.md Include the library and initialize the PhpGram class with your bot token. ```php require __DIR__ . '/../src/PhpGram.php'; use PhpGram\PhpGram; $token = 'YOUR_BOT_TOKEN'; $bot = new PhpGram($token); ``` -------------------------------- ### Send a Game Source: https://github.com/sh20raj/phpgram/blob/main/README.md Initiate sending a game to a chat by providing the game's short name. ```php // Send a game $gameShortName = 'game_short_name'; $response = $bot->sendGame($chatId, $gameShortName); ``` -------------------------------- ### Set a Webhook Source: https://github.com/sh20raj/phpgram/blob/main/README.md Configure a webhook URL to receive updates from Telegram. Replace the placeholder with your actual domain and webhook path. ```php // Set a webhook $response = $bot->setWebhook('https://yourdomain.com/webhook'); ``` -------------------------------- ### Handle Stickers Source: https://github.com/sh20raj/phpgram/blob/main/README.md Send, manage, and create sticker sets using the provided methods. ```php // Send a sticker $stickerPath = 'path/to/sticker.webp'; $response = $bot->sendSticker($chatId, $stickerPath); // Get a sticker set $stickerSetName = 'sticker_set_name'; $response = $bot->getStickerSet($stickerSetName); // Upload a sticker file $stickerFilePath = 'path/to/sticker.png'; $response = $bot->uploadStickerFile($userId, $stickerFilePath); // Create a new sticker set $stickerParams = [ 'name' => 'sticker_set_name', 'title' => 'Sticker Set Title', 'png_sticker' => 'path/to/sticker.png', 'emojis' => '😀', ]; $response = $bot->createNewStickerSet($userId, $stickerParams); // Add a sticker to a set $response = $bot->addStickerToSet($userId, 'sticker_set_name', 'path/to/sticker.png', '😀'); // Set sticker position in a set $response = $bot->setStickerPositionInSet('sticker_file_id', 0); // Delete a sticker from a set $response = $bot->deleteStickerFromSet('sticker_file_id'); ``` -------------------------------- ### Send Video Note Source: https://github.com/sh20raj/phpgram/blob/main/README.md Send a video note to a chat. Video notes are circular video messages. ```php // Send a video note $videoNotePath = 'path/to/video_note.mp4'; $response = $bot->sendVideoNote($chatId, $videoNotePath); ``` -------------------------------- ### Answer a Shipping Query Source: https://github.com/sh20raj/phpgram/blob/main/README.md Respond to a shipping query with this snippet. Set the second parameter to true to indicate that shipping is available. ```php // Answer a shipping query $shippingQueryId = 'SHIPPING_QUERY_ID'; $response = $bot->answerShippingQuery($shippingQueryId, true); ``` -------------------------------- ### Answer a Pre-Checkout Query Source: https://github.com/sh20raj/phpgram/blob/main/README.md Acknowledge a pre-checkout query using this code. Set the second parameter to true to confirm the query. ```php // Answer a pre-checkout query $preCheckoutQueryId = 'PRE_CHECKOUT_QUERY_ID'; $response = $bot->answerPreCheckoutQuery($preCheckoutQueryId, true); ``` -------------------------------- ### Send an Invoice Source: https://github.com/sh20raj/phpgram/blob/main/README.md Use this snippet to send an invoice to a chat. Ensure all required parameters like title, description, payload, provider_token, start_parameter, currency, and prices are correctly set. ```php // Send an invoice $invoiceParams = [ 'title' => 'Product Name', 'description' => 'Description of the product', 'payload' => 'unique_payload', 'provider_token' => 'PROVIDER_PAYMENT_TOKEN', 'start_parameter' => 'start_param', 'currency' => 'USD', 'prices' => json_encode([ ['label' => 'Product Price', 'amount' => 1000] ]), ]; $response = $bot->sendInvoice($chatId, $invoiceParams); ``` -------------------------------- ### Sending Video Notes Source: https://github.com/sh20raj/phpgram/blob/main/README.md Send a video note to a specified chat. ```APIDOC ## Sending Video Notes ```php // Send a video note $videoNotePath = 'path/to/video_note.mp4'; $response = $bot->sendVideoNote($chatId, $videoNotePath); ``` ``` -------------------------------- ### Inline Mode Source: https://github.com/sh20raj/phpgram/blob/main/README.md Methods for handling inline queries and responding with results. ```APIDOC ## Inline Mode ```php // Answer an inline query $inlineQueryId = 'INLINE_QUERY_ID'; $results = [ /* Array of InlineQueryResult objects */ ]; $response = $bot->answerInlineQuery($inlineQueryId, $results); ``` ``` -------------------------------- ### Send Video Source: https://github.com/sh20raj/phpgram/blob/main/README.md Send a video file to a chat. Supports an optional caption. ```php // Send a video $videoPath = 'path/to/video.mp4'; $response = $bot->sendVideo($chatId, $videoPath, ['caption' => 'Watch this video!']); ``` -------------------------------- ### Sending Videos Source: https://github.com/sh20raj/phpgram/blob/main/README.md Send a video to a specified chat, optionally with a caption. ```APIDOC ## Sending Videos ```php // Send a video $videoPath = 'path/to/video.mp4'; $response = $bot->sendVideo($chatId, $videoPath, ['caption' => 'Watch this video!']); ``` ``` -------------------------------- ### Send Media Group Source: https://github.com/sh20raj/phpgram/blob/main/README.md Send a group of photos or videos to a chat. ```php // Send a media group $mediaGroup = [ ['type' => 'photo', 'media' => 'path/to/photo1.jpg'], ['type' => 'photo', 'media' => 'path/to/photo2.jpg'], ]; $response = $bot->sendMediaGroup($chatId, $mediaGroup); ``` -------------------------------- ### Send Location Source: https://github.com/sh20raj/phpgram/blob/main/README.md Send a live location or a static location to a chat using latitude and longitude. ```php // Send a location $response = $bot->sendLocation($chatId, 40.712776, -74.005974); // New York City coordinates ``` -------------------------------- ### Answer Inline Query Source: https://github.com/sh20raj/phpgram/blob/main/README.md Respond to an inline query with a list of results. ```php // Answer an inline query $inlineQueryId = 'INLINE_QUERY_ID'; $results = [ /* Array of InlineQueryResult objects */ ]; $response = $bot->answerInlineQuery($inlineQueryId, $results); ``` -------------------------------- ### Send Venue Source: https://github.com/sh20raj/phpgram/blob/main/README.md Send information about a venue to a chat, including location, name, and address. ```php // Send a venue $response = $bot->sendVenue($chatId, 40.712776, -74.005974, 'Venue Name', 'Venue Address'); ``` -------------------------------- ### Send Audio Source: https://github.com/sh20raj/phpgram/blob/main/README.md Send an audio file to a chat. Supports an optional caption. ```php // Send an audio file $audioPath = 'path/to/audio.mp3'; $response = $bot->sendAudio($chatId, $audioPath, ['caption' => 'Listen to this audio!']); ``` -------------------------------- ### Sending Audio Source: https://github.com/sh20raj/phpgram/blob/main/README.md Send an audio file to a specified chat, optionally with a caption. ```APIDOC ## Sending Audio ```php // Send an audio file $audioPath = 'path/to/audio.mp3'; $response = $bot->sendAudio($chatId, $audioPath, ['caption' => 'Listen to this audio!']); ``` ``` -------------------------------- ### Handling Stickers Source: https://github.com/sh20raj/phpgram/blob/main/README.md Methods for sending, retrieving, and managing stickers and sticker sets. ```APIDOC ## Handling Stickers ```php // Send a sticker $stickerPath = 'path/to/sticker.webp'; $response = $bot->sendSticker($chatId, $stickerPath); // Get a sticker set $stickerSetName = 'sticker_set_name'; $response = $bot->getStickerSet($stickerSetName); // Upload a sticker file $stickerFilePath = 'path/to/sticker.png'; $response = $bot->uploadStickerFile($userId, $stickerFilePath); // Create a new sticker set $stickerParams = [ 'name' => 'sticker_set_name', 'title' => 'Sticker Set Title', 'png_sticker' => 'path/to/sticker.png', 'emojis' => '😀', ]; $response = $bot->createNewStickerSet($userId, $stickerParams); // Add a sticker to a set $response = $bot->addStickerToSet($userId, 'sticker_set_name', 'path/to/sticker.png', '😀'); // Set sticker position in a set $response = $bot->setStickerPositionInSet('sticker_file_id', 0); // Delete a sticker from a set $response = $bot->deleteStickerFromSet('sticker_file_id'); ``` ``` -------------------------------- ### Sending Media Groups Source: https://github.com/sh20raj/phpgram/blob/main/README.md Send a group of photos or videos to a specified chat. ```APIDOC ## Sending Media Groups ```php // Send a media group $mediaGroup = [ ['type' => 'photo', 'media' => 'path/to/photo1.jpg'], ['type' => 'photo', 'media' => 'path/to/photo2.jpg'], ]; $response = $bot->sendMediaGroup($chatId, $mediaGroup); ``` ``` -------------------------------- ### Send Document Source: https://github.com/sh20raj/phpgram/blob/main/README.md Send a document file to a chat. Supports an optional caption. ```php // Send a document $documentPath = 'path/to/document.pdf'; $response = $bot->sendDocument($chatId, $documentPath, ['caption' => 'Here is your document.']); ``` -------------------------------- ### Send Contact Source: https://github.com/sh20raj/phpgram/blob/main/README.md Send contact information to a chat. ```php // Send a contact $response = $bot->sendContact($chatId, 'PHONE_NUMBER', 'FirstName', ['last_name' => 'LastName']); ``` -------------------------------- ### Set Game Score Source: https://github.com/sh20raj/phpgram/blob/main/README.md Update a user's score in a game. Provide the user ID and the new score. ```php // Set game score $response = $bot->setGameScore($userId, 100); ``` -------------------------------- ### Send Photo Source: https://github.com/sh20raj/phpgram/blob/main/README.md Send a photo file to a chat. Supports an optional caption. ```php // Send a photo $photoPath = 'path/to/photo.jpg'; $response = $bot->sendPhoto($chatId, $photoPath, ['caption' => 'Check out this photo!']); ``` -------------------------------- ### Sending Venues Source: https://github.com/sh20raj/phpgram/blob/main/README.md Send a venue (location with name and address) to a specified chat. ```APIDOC ## Sending Venues ```php // Send a venue $response = $bot->sendVenue($chatId, 40.712776, -74.005974, 'Venue Name', 'Venue Address'); ``` ``` -------------------------------- ### Clone PhpGram Repository Source: https://github.com/sh20raj/phpgram/blob/main/README.md Alternatively, clone the PhpGram repository directly from GitHub if you prefer not to use Composer. ```bash git clone https://github.com/SH20RAJ/phpgram.git ``` -------------------------------- ### Manage Chat Members Source: https://github.com/sh20raj/phpgram/blob/main/README.md Perform actions on chat members such as kicking, unbanning, restricting, and promoting. ```php // Kick a member from a chat $userId = 'USER_ID_TO_KICK'; $response = $bot->kickChatMember($chatId, $userId); // Unban a member from a chat $response = $bot->unbanChatMember($chatId, $userId); // Restrict a member in a chat $permissions = ['can_send_messages' => false]; $response = $bot->restrictChatMember($chatId, $userId, $permissions); // Promote a member to an admin $response = $bot->promoteChatMember($chatId, $userId); // Set custom title for an admin $response = $bot->setChatAdministratorCustomTitle($chatId, $userId, 'Custom Title'); ``` -------------------------------- ### Send Animation Source: https://github.com/sh20raj/phpgram/blob/main/README.md Send an animation (e.g., GIF) to a chat. Supports an optional caption. ```php // Send an animation $animationPath = 'path/to/animation.gif'; $response = $bot->sendAnimation($chatId, $animationPath, ['caption' => 'Enjoy this animation!']); ``` -------------------------------- ### Managing Chats and Members Source: https://github.com/sh20raj/phpgram/blob/main/README.md Methods for managing chat members, including kicking, unbanning, restricting, promoting, and setting custom titles. ```APIDOC ## Managing Chats and Members ```php // Kick a member from a chat $userId = 'USER_ID_TO_KICK'; $response = $bot->kickChatMember($chatId, $userId); // Unban a member from a chat $response = $bot->unbanChatMember($chatId, $userId); // Restrict a member in a chat $permissions = ['can_send_messages' => false]; $response = $bot->restrictChatMember($chatId, $userId, $permissions); // Promote a member to an admin $response = $bot->promoteChatMember($chatId, $userId); // Set custom title for an admin $response = $bot->setChatAdministratorCustomTitle($chatId, $userId, 'Custom Title'); ``` ``` -------------------------------- ### Sending Documents Source: https://github.com/sh20raj/phpgram/blob/main/README.md Send a document to a specified chat, optionally with a caption. ```APIDOC ## Sending Documents ```php // Send a document $documentPath = 'path/to/document.pdf'; $response = $bot->sendDocument($chatId, $documentPath, ['caption' => 'Here is your document.']); ``` ``` -------------------------------- ### Sending Animations Source: https://github.com/sh20raj/phpgram/blob/main/README.md Send an animation (GIF) to a specified chat, optionally with a caption. ```APIDOC ## Sending Animations ```php // Send an animation $animationPath = 'path/to/animation.gif'; $response = $bot->sendAnimation($chatId, $animationPath, ['caption' => 'Enjoy this animation!']); ``` ``` -------------------------------- ### Send Text Message Source: https://github.com/sh20raj/phpgram/blob/main/README.md Send a simple text message to a specified chat ID. ```php // Send a text message $chatId = 'YOUR_CHAT_ID'; $message = 'Hello from PhpGram!'; $response = $bot->sendMessage($chatId, $message); ``` -------------------------------- ### Sending Photos Source: https://github.com/sh20raj/phpgram/blob/main/README.md Send a photo to a specified chat, optionally with a caption. ```APIDOC ## Sending Photos ```php // Send a photo $photoPath = 'path/to/photo.jpg'; $response = $bot->sendPhoto($chatId, $photoPath, ['caption' => 'Check out this photo!']); ``` ``` -------------------------------- ### Sending Locations Source: https://github.com/sh20raj/phpgram/blob/main/README.md Send a location (latitude and longitude) to a specified chat. ```APIDOC ## Sending Locations ```php // Send a location $response = $bot->sendLocation($chatId, 40.712776, -74.005974); // New York City coordinates ``` ``` -------------------------------- ### Sending Contacts Source: https://github.com/sh20raj/phpgram/blob/main/README.md Send a contact (phone number and name) to a specified chat. ```APIDOC ## Sending Contacts ```php // Send a contact $response = $bot->sendContact($chatId, 'PHONE_NUMBER', 'FirstName', ['last_name' => 'LastName']); ``` ``` -------------------------------- ### Send Voice Message Source: https://github.com/sh20raj/phpgram/blob/main/README.md Send a voice message to a chat. Supports an optional caption. ```php // Send a voice message $voicePath = 'path/to/voice.ogg'; $response = $bot->sendVoice($chatId, $voicePath, ['caption' => 'Listen to this voice message!']); ``` -------------------------------- ### Sending Polls Source: https://github.com/sh20raj/phpgram/blob/main/README.md Send a poll with a question and options to a specified chat. ```APIDOC ## Sending Polls ```php // Send a poll $response = $bot->sendPoll($chatId, 'Your Question?', ['Option 1', 'Option 2']); ``` ``` -------------------------------- ### Sending Voice Messages Source: https://github.com/sh20raj/phpgram/blob/main/README.md Send a voice message to a specified chat, optionally with a caption. ```APIDOC ## Sending Voice Messages ```php // Send a voice message $voicePath = 'path/to/voice.ogg'; $response = $bot->sendVoice($chatId, $voicePath, ['caption' => 'Listen to this voice message!']); ``` ``` -------------------------------- ### Sending Text Messages Source: https://github.com/sh20raj/phpgram/blob/main/README.md Send a text message to a specified chat. ```APIDOC ## Sending Text Messages ```php // Send a text message $chatId = 'YOUR_CHAT_ID'; $message = 'Hello from PhpGram!'; $response = $bot->sendMessage($chatId, $message); ``` ``` -------------------------------- ### Send Poll Source: https://github.com/sh20raj/phpgram/blob/main/README.md Send a poll to a chat with a question and options. ```php // Send a poll $response = $bot->sendPoll($chatId, 'Your Question?', ['Option 1', 'Option 2']); ``` -------------------------------- ### Send Dice Source: https://github.com/sh20raj/phpgram/blob/main/README.md Send a dice emoji to a chat, which will roll and return a random value. ```php // Send a dice $response = $bot->sendDice($chatId); ``` -------------------------------- ### Delete a Webhook Source: https://github.com/sh20raj/phpgram/blob/main/README.md Remove the configured webhook. This will revert the bot to polling for updates. ```php // Delete a webhook $response = $bot->deleteWebhook(); ``` -------------------------------- ### Sending Dice Source: https://github.com/sh20raj/phpgram/blob/main/README.md Send a dice emoji to a specified chat. ```APIDOC ## Sending Dice ```php // Send a dice $response = $bot->sendDice($chatId); ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.