Skip to content

Latest commit

 

History

History
78 lines (55 loc) · 1.98 KB

README.md

File metadata and controls

78 lines (55 loc) · 1.98 KB

SimpleTelegramBotClient

Build Status codecov Packagist Version

Usages:

Installation

composer require franchuk/simple-telegram-client

Require php >= 7.3

Initialize

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

Get Updates

<?php
$telegramService->getUpdates();

Send message

<?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.

PROXY

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');