PHP code example of blue_skies / telegram-bot-helper

1. Go to this page and download the library: Download blue_skies/telegram-bot-helper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

blue_skies / telegram-bot-helper example snippets


use BlueSkies\TelegramBotHelper\Traits\TelegramBotHelper;

class TestController extends Controller
{
    use TelegramBotHelper;
    public  function index()
    {
      return  self::SendTelegramMessage('chat_id','Test');
    }
}




Route::post('/telegram/message',[\App\Http\Controllers\TestController::class,'index']);

   public static function SendTelegramMessage(
        int|string $chatId,
        string     $text,
        ?string    $messageThreadId = null,
        string     $parseMode = 'HTML',
        ?array     $entities = null,
        ?bool      $disableNotification = null,
        ?bool      $protectContent = null,
                   $linkPreviewOptions = null,
                   $replyParameters = null,
                   $replyMarkup = null
    ): JsonResponse

 public static function SendTelegramForwardMessage(
        int|string $chatId,
        int        $messageThreadId = null,
        int|string $fromChatId = null,
        ?bool      $disableNotification = null,
        ?bool      $protectContent = null,
        int        $messageId
    ): JsonResponse

    public static function SendTelegramForwardMessages(
        int|string $chatId,
        int        $messageThreadId,
        int|string $fromChatId,
        array|int  $messageIds,
        bool       $disable_notification = false,
        bool       $protectContent = false
    ): JsonResponse

      public static function SendTelegramCopyMessage(
        int|string $chatId,
        int        $messageThreadId,
        int|string $fromChatId,
        array|int  $messageIds,
        ?bool      $disable_notification = null,
        ?bool      $protectContent = null,
        ?bool      $removeCaption = null
    ): JsonResponse

      public static function SendTelegramCopyMessages(
        int|string $chatId,
        int        $messageThreadId,
        int|string $fromChatId,
        array|int  $messageIds,
        ?bool      $disable_notification = null,
        ?bool      $protectContent = null,
        ?bool      $removeCaption = null
    ): JsonResponse

   public function SendTelegramPhoto(
        int|string $chatId,
        ?int       $messageThreadId = null,
        string     $photo,
        ?string    $caption = null,
        ?string    $parseMode = 'HTML',
        ?array     $captionEntities = null,
        bool       $hasSpoiler = null,
        bool       $disableNotification = null,
        ?bool      $protectContent = null,
                   $replyParameters = null,
                   $replyMarkup = null
    ): JsonResponse

      public static function SendTelegramAudio(
        int|string $chatId,
        ?int       $messageThreadId = null,
        string     $audio,
        ?string    $caption = null,
        ?string    $parseMode = 'HTML',
        ?array     $captionEntities = null,
        ?int       $duration = null,
        ?string    $performer = null,
        ?string    $title = null,
        ?string    $thumbnail = null,
        ?bool      $disableNotification = null,
        ?bool      $protectContent = null,
                   $replyParameters = null,
                   $replyMarkup = null
    ): JsonResponse

      public static function SendTelegramDocument(
        int|string $chatId,
        ?int       $messageThreadId = null,
        string     $document,
        ?string    $thumbnail = null,
        ?string    $caption = null,
        ?string    $parseMode = 'HTML',
        ?array     $captionEntities = null,
        ?bool      $disableContentTypeDetection = null,
        ?bool      $disableNotification = null,
        ?bool      $protectContent = null,
        ?string    $title = null,


                   $replyParameters = null,
                   $replyMarkup = null
    ): JsonResponse

    public static function SendTelegramVideo(
        int|string $chatId,
        ?int       $messageThreadId = null,
        string     $video,
        ?int       $duration = null,
        ?int       $width = null,
        ?int       $height = null,
        ?string    $thumbnail = null,
        ?string    $caption = null,
        ?string    $parseMode = 'HTML',
        ?array     $captionEntities = null,
        ?bool      $hasSpoiler = null,
        ?bool      $supportsStreaming = null,
        ?bool      $disableNotification = null,
        ?bool      $protectContent = null,
                   $replyParameters = null,
                   $replyMarkup = null,

    ): JsonResponse

    public static function SendTelegramAnimation(
        int|string $chatId,
        ?int       $messageThreadId = null,
        string     $animation,
        ?int       $duration = null,
        ?int       $width = null,
        ?int       $height = null,
        ?string    $thumbnail = null,
        ?string    $caption = null,
        ?string    $parseMode = 'HTML',
        ?array     $captionEntities = null,
        ?bool      $hasSpoiler = null,
        ?bool      $disableNotification = null,
        ?bool      $protectContent = null,
                   $replyParameters = null,
                   $replyMarkup = null
    ): JsonResponse

    public static function SendTelegramVoice(
        int|string $chatId,
        ?int       $messageThreadId = null,
        string     $voice,
        ?string    $caption = null,
        ?string    $parseMode = 'HTML',
        ?array     $captionEntities = null,
        ?int       $duration = null,
        ?bool      $disableNotification = null,
        ?bool      $protectContent = null,
                   $replyParameters = null,
                   $replyMarkup = null
    ): JsonResponse

    public static function SendTelegramVideoNote(
        int|string $chatId,
        ?int       $messageThreadId = null,
        string     $videoNote,
        ?int       $duration = null,
        ?int       $length = null,
        ?int       $thumbnail = null,
        ?bool      $disableNotification = null,
        ?bool      $protectContent = null,
                   $replyParameters = null,
                   $replyMarkup = null
    ): JsonResponse

    public static function SendTelegramMediaGroup(
        int|string $chatId,
        ?int       $messageThreadId = null,
        array      $media,
        ?bool      $disableNotification = null,
        ?bool      $protectContent = null,
        ?array     $captionEntities = null,
        ?bool      $supportsStreaming = null,
                   $replyParameters = null,
                   $replyMarkup = null,

    ): JsonResponse

    public static function SendTelegramLocation(
        int|string $chatId,
        ?int       $messageThreadId = null,
        float      $latitude,
        float      $longitude,
        float      $horizontalAccuracy = null,
        float      $livePeriod = null,
        float      $heading = null,
        float      $proximityAlertRadius = null,
        ?bool      $disableNotification = null,
        ?bool      $protectContent = null,
                   $replyParameters = null,
                   $replyMarkup = null,
    ): JsonResponse

    public static function SendTelegramVenue(
        int|string $chatId,
        ?int       $messageThreadId = null,
        float      $latitude,
        float      $longitude,
        string     $title,
        string     $address,

        ?string    $foursquareId = null,
        ?string    $foursquareType = null,
        ?string    $googlePlaceId = null,
        ?string    $googlePlaceType = null,
        ?bool      $disableNotification = null,
        ?bool      $protectContent = null,
                   $replyParameters = null,
                   $replyMarkup = null
    ): JsonResponse

    public static function SendTelegramContact(
        int|string $chatId,
        ?int       $messageThreadId = null,
        string     $phoneNumber,
        string     $firstName,
        ?string    $lastName = null,
        ?string    $vcard = null,
        ?bool      $disableNotification = null,
        ?bool      $protectContent = null,
                   $replyParameters = null,
                   $replyMarkup = null
    ): JsonResponse

    public static function SendTelegramPoll(
        int|string $chatId,
        ?int       $messageThreadId = null,
        string     $question,
        array      $options,
        ?bool      $isAnonymous = null,
        ?string    $type = null,
        ?bool      $allowsMultipleAnswers = null,
        ?int       $correctOptionId = null,
        ?string    $explanation = null,
        ?string    $explanationParseMode = null,
        ?array     $explanationEntities = null,
        ?int       $openPeriod = null,
        ?int       $closeDate = null,
        ?bool      $isClosed = null,
        ?bool      $disableNotification = null,
        ?bool      $protectContent = null,
                   $replyParameters = null,
                   $replyMarkup = null
    ): JsonResponse

    public static function SendTelegramDice(
        int|string $chatId,
        ?int       $messageThreadId = null,
        string     $emoji,
        ?bool      $disableNotification = null,
        ?bool      $protectContent = null,
                   $replyParameters = null,
                   $replyMarkup = null
    ): JsonResponse

    public static function SendTelegramChatAction(
        int|string $chatId,
        ?int       $messageThreadId = null,
        string     $action
    ): JsonResponse

    public static function SendTelegramMessageReaction(
        int|string $chatId,
        int        $messageId,
        ?array     $reaction = null,
        ?bool      $isBig = null,

    ): JsonResponse

    public static function getTelegramUserProfilePhotos(
        int  $userId,
        ?int $offset = null,
        ?int $limit = null
    ): JsonResponse

    public static function getTelegramFile(
        string $fileId,
    ): JsonResponse

    public static function banTelegramChatMember(
        int|string $chatId,
        int        $userId,
        ?int       $untilDate = null,
        ?bool      $revokeMessages = null
    ): JsonResponse

    public static function unbanTelegramChatMember(
        int|string $chatId,
        int        $userId,
        ?bool      $onlyIfBanned = null
    ): JsonResponse

    public static function restrictTelegramChatMember(
        int|string $chatId,
        int        $userId,
        array      $permissions,
        ?bool      $useIndependentChatPermissions = null,
        ?int       $untilDate = null
    ): JsonResponse

    public static function promoteTelegramChatMember(
        int|string $chatId,
        int        $userId,
        ?bool      $isAnonymous = null,
        ?bool      $canManageChat = null,
        ?bool      $canPostMessages = null,
        ?bool      $canEditMessages = null,
        ?bool      $canDeleteMessages = null,
        ?bool      $canManageVoiceChats = null,
        ?bool      $canRestrictMembers = null,
        ?bool      $canPromoteMembers = null,
        ?bool      $canChangeInfo = null,
        ?bool      $canInviteUsers = null,
        ?bool      $canPinMessages = null,
        ?bool      $canPostStories = null,
        ?bool      $canEditStories = null,
        ?bool      $canDeleteStories = null,
        ?bool      $canManageTopics = null,
    ): JsonResponse

    public static function setTelegramChatAdministratorCustomTitle(
        int|string $chatId,
        int        $userId,
        string     $customTitle,
    ): JsonResponse

    public static function banTelegramChatSenderChat(
        int|string $chatId,
        int        $senderChatId,
    ): JsonResponse

    public static function unbanTelegramChatSenderChat(
        int|string $chatId,
        int        $senderChatId
    ): JsonResponse

    public static function setTelegramChatPermissions(
        int|string $chatId,
        array      $permissions,
        ?bool      $useIndependentChatPermissions = null
    ): JsonResponse

    public static function exportTelegramChatInviteLink(
        int|string $chatId,
    ): JsonResponse

    public static function createTelegramChatInviteLink(
        int|string $chatId,
        ?string    $name = null,
        ?int       $expireDate = null,
        ?int       $memberLimit = null,
        ?bool      $createsJoinRequest = null
    ): JsonResponse

    public static function editTelegramChatInviteLink(
        int|string $chatId,
        string     $inviteLink,
        ?string    $name = null,
        ?int       $expireDate = null,
        ?int       $memberLimit = null,
        ?bool      $createsJoinRequest = null
    ): JsonResponse

    public static function revokeTelegramChatInviteLink(
        int|string $chatId,
        string     $inviteLink
    ): JsonResponse

    public static function approveTelegramChatJoinRequest(
        int|string $chatId,
        int        $userId,
    ): JsonResponse

    public static function declineTelegramChatJoinRequest(
        int|string $chatId,
        int        $userId,
    ): JsonResponse

    public static function setTelegramChatPhoto(
        int|string $chatId,
        string     $photo,
    ): JsonResponse

    public static function deleteTelegramChatPhoto(
        int|string $chatId,
    ): JsonResponse

    public static function setTelegramChatTitle(
        int|string $chatId,
        string     $title,
    ): JsonResponse

    public static function setTelegramChatDescription(
        int|string $chatId,
        string     $description,
    ): JsonResponse

    public static function pinTelegramChatMessage(
        int|string $chatId,
        int        $messageId,
        ?bool      $disableNotification = null,
    ): JsonResponse

    public static function unpinTelegramChatMessage(
        int|string $chatId,
        ?int       $messageId = null,
    ): JsonResponse

    public static function unpinAllTelegramChatMessages(
        int|string $chatId,

    ): JsonResponse

    public static function leaveTelegramChat(
        int|string $chatId,

    ): JsonResponse

    public static function getTelegramChat(
        int|string $chatId,

    ): JsonResponse

    public static function getTelegramChatAdministrators(
        int|string $chatId,

    ): JsonResponse

    public static function getTelegramChatMemberCount(
        int|string $chatId,

    ): JsonResponse

    public static function getTelegramChatMember(
        int|string $chatId,
        int        $userId

    ): JsonResponse

    public static function setTelegramChatStickerSet(
        int|string $chatId,
        string     $stickerSetName

    ): JsonResponse

    public static function deleteTelegramChatStickerSet(
        int|string $chatId,

    ): JsonResponse

    public static function createTelegramForumTopic(
        int|string $chatId,
        string     $name,
        ?int       $iconColor = null,
        ?string    $iconCustomEmojiId = null
    ): JsonResponse

    public static function editTelegramForumTopic(
        int|string $chatId,
        string     $name,
        int        $messageThreadId,
        ?int       $iconColor = null,
        ?string    $iconCustomEmojiId = null
    ): JsonResponse

    public static function closeTelegramForumTopic(
        int|string $chatId,
        int        $messageThreadId
    ): JsonResponse

    public static function reopenTelegramForumTopic(
        int|string $chatId,
        int        $messageThreadId
    ): JsonResponse

    public static function deleteTelegramForumTopic(
        int|string $chatId,
        int        $messageThreadId
    ): JsonResponse

    public static function unpinAllTelegramForumTopicMessages(
        int|string $chatId,
        int        $messageThreadId
    ): JsonResponse

    public static function editTelegramGeneralForumTopic(
        int|string $chatId,
        int        $name
    ): JsonResponse

    public static function closeTelegramGeneralForumTopic(
        int|string $chatId,
    ): JsonResponse

    public static function reopenTelegramGeneralForumTopic(
        int|string $chatId,
    ): JsonResponse

    public static function hideTelegramGeneralForumTopic(
        int|string $chatId,
    ): JsonResponse

    public static function unhideTelegramGeneralForumTopic(
        int|string $chatId,
    ): JsonResponse

    public static function unpinAllTelegramGeneralForumTopicMessages(
        int|string $chatId,
    ): JsonResponse

    public static function answerTelegramCallbackQuery(
        string  $callbackQueryId,
        ?string $text = null,
        ?bool   $showAlert = null,
        ?string $urlTG = null,
        ?int    $cacheTime = 0
    ): JsonResponse

    public static function getTelegramUserChatBoosts(
        int|string $chatId,
        int        $userId
    ): JsonResponse

    public static function setTelegramMyCommands(
        int|string $chatId,
        array      $commands,
                   $scope = null,
        ?string    $language_code = null
    ): JsonResponse

    public static function deleteTelegramMyCommands(
        int|string $chatId,
                   $scope = null,
        ?string    $language_code = null
    ): JsonResponse

    public static function getTelegramMyCommands(
        int|string $chatId,
                   $scope = null,
        ?string    $language_code = null
    ): JsonResponse

    public static function setTelegramMyName(
        int|string $chatId,
        ?string    $name = null,
        ?string    $language_code = null
    ): JsonResponse

    public static function getTelegramMyName(
        int|string $chatId,
        ?string    $language_code = null
    ): JsonResponse

    public static function setTelegramMyDescription(
        int|string $chatId,
        ?string    $description = null,
        ?string    $language_code = null
    ): JsonResponse

    public static function getTelegramMyDescription(
        int|string $chatId,
        ?string    $language_code = null
    ): JsonResponse

    public static function setTelegramMyShortDescription(
        int|string $chatId,
        ?string    $short_description = null,
        ?string    $language_code = null
    ): JsonResponse

    public static function getTelegramMyShortDescription(
        int|string $chatId,
        ?string    $language_code = null
    ): JsonResponse

    public static function setTelegramChatMenuButton(
        int|string $chatId,
        ?array     $menuButton = null,
        ?string    $language_code = null
    ): JsonResponse

    public static function setTelegramMyDefaultAdministratorRights(
        int|string $chatId,
                   $rights = null,
        ?bool      $for_channels = null
    ): JsonResponse

    public static function getTelegramMyDefaultAdministratorRights(
        int|string $chatId,
        ?bool      $for_channels = null
    ): JsonResponse

    public static function editTelegramMessageText(
        int|string $chatId,
        ?int       $messageId = null,
        ?string    $inlineMessageId = null,
        string     $text,
        ?string    $parseMode = null,
        ?array     $entities = null,
                   $linkPreviewOptions = null,
                   $replyMarkup = null
    ): JsonResponse

    public static function editTelegramMessageCaption(
        null|int|string $chatId = null,
        ?int            $messageId = null,
        ?string         $inlineMessageId = null,
        ?string         $caption = null,
        ?string         $parseMode = null,
        ?array          $captionEntities = null,
                        $replyMarkup = null
    ): JsonResponse

    public static function editTelegramMessageMedia(
        int|string $chatId = null,
        ?int       $messageId = null,
        ?string    $inlineMessageId = null,
                   $media,
                   $replyMarkup = null
    ): JsonResponse

    public static function editTelegramMessageLiveLocation(
        int|string $chatId = null,
        ?int       $messageId = null,
        ?string    $inlineMessageId = null,
        float      $latitude,
        float      $longitude,
        ?float     $horizontalAccuracy = null,
        ?int       $heading = null,
        ?int       $proximityAlertRadius = null,
                   $replyMarkup = null
    ): JsonResponse

    public static function stopTelegramMessageLiveLocation(
        int|string $chatId = null,
        ?int       $messageId = null,
        ?string    $inlineMessageId = null,
                   $replyMarkup = null
    ): JsonResponse

    public static function editTelegramMessageReplyMarkup(
        int|string $chatId = null,
        ?int       $messageId = null,
        ?string    $inlineMessageId = null,
                   $replyMarkup = null
    ): JsonResponse

    public static function stopTelegramPoll(
        int|string $chatId = null,
        ?int       $messageId = null,
                   $replyMarkup = null
    ): JsonResponse

    public static function deleteTelegramMessage(
        int|string $chatId,
        int        $messageId
    ): JsonResponse

    public static function deleteTelegramMessages(
        int|string $chatId,
        array      $messageIds
    ): JsonResponse

    public static function SendTelegramReply(
    string $chatId, 
    string $message, 
    string $replyId, 
    string $parseMode = 'HTML'
    ): JsonResponse

    public static function SendDeleteTelegramMessage(
    string $chatId, 
    string $messageId, 
    ?int $seconds = 0
    ): JsonResponse

    public static function SendTelegramMessageEntity(
    string $chatId, 
    string $messageText, 
    array $entities
    ): JsonResponse


Route::controller(\App\Http\Controllers\TelegramWebhookController::class)->group(function () {
    Route::post('/telegram-bot/handle', 'handle');
});

use BlueSkies\TelegramBotHelper\Traits\TelegramBotHelper;

class TelegramWebhookController extends Controller
{
    use TelegramBotHelper;
    public function handle(Request $request)
    {
        $bodyContent = $request->getContent();
        return self::SendTelegramMessage('chat_id',"<pre>$bodyContent</pre>");
    }
}
bash
 php artisan make:controller TestController 
bash
   php artisan make:controller TelegramWebhookController