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;
}
}
}