composer require franchuk/simple-telegram-client
Require php >= 7.3
Basic initialize with
<?php
use SimpleTelegramBotClient\Config;
use SimpleTelegramBotClient\TelegramServiceFactory;
require './vendor/autoload.php';
$config = new Config('some-telegram-api-key');
$telegramService = TelegramServiceFactory::create($config);
If you want more control use these:
<?php
use SimpleTelegramBotClient\Config;
use SimpleTelegramBotClient\TelegramService;
use GuzzleHttp\Client;
use JMS\Serializer\SerializerBuilder;
require './vendor/autoload.php';
$config = new Config('some-telegram-api-key');
Doctrine\Common\Annotations\AnnotationRegistry::registerLoader('class_exists');
$serializer = SerializerBuilder::create()->build();
$telegramService = new TelegramService($config, new Client(), $serializer);
<?php
$telegramService->getUpdates();
<?php
use SimpleTelegramBotClient\Builder\Action\SendMessageBuilder;
$chatId = '1234';
$sendMessageBuilder = new SendMessageBuilder($chatId, 'Hello World!');
$message = $sendMessageBuilder->build();
$telegramService->sendMessage($message);
More examples you can find in ./examples
folder.
Add file .telegramkey
in ./examples
and put telegram key into it.
If you have problems with telegram connection you can use proxy.
<?php
use SimpleTelegramBotClient\Config;
$config = new Config('some key');
$config->setProxy('socks4://ip:port');