PHP code example of sergio-item / telegram

1. Go to this page and download the library: Download sergio-item/telegram 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/ */

    

sergio-item / telegram example snippets


use SergioItem\Telegram\Facades\Telegram;

Telegram::sendNotification($message);



namespace App\Services;

use SergioItem\Telegram\Interfaces\TelegramBotWebhookManagerInterface;

class TelegramBotWebhookManagerService implements TelegramBotWebhookManagerInterface
{
    /**
     * @param string $text
     * @param null $data
     * @return string
     */
    public function manageResponseMessage(string $text, $data = null)
    {
        switch (strtolower($text)) {
            case 'hi':
            case 'hello':
                return 'Hi ' . $data->firstName . '! welcome to this bot';
                break;
            case 'chat':
            case 'id':
                return 'Your chat id is: ' . $data->chatId;
                break;

            default:
                // return null; // No message will be sent
                return 'Sorry, I couldn\'t understand your message.';
                break;
        }
    }

}

$data->chatId
$data->isBot
$data->firstName
$data->lastName
$data->username
$data->languageCode
$data->date
$data->messageId
bash
php artisan telegram:set-webhook {url?}
php artisan telegram:remove-webhook
php artisan telegram:get-webhook-info
bash
php artisan telegram:get-updates
php artisan telegram:get-updates --offset {updateId}
php artisan telegram:get-updates -O {updateId}
bash
php artisan telegram:send-notification {message}
bash
php artisan telegram:set-webhook {url?}