Skip to content

Instantly share code, notes, and snippets.

@greenplugin
Last active June 20, 2022 16:24
Show Gist options
  • Save greenplugin/09179bee606aa01b1ee00d049ab78fc4 to your computer and use it in GitHub Desktop.
Save greenplugin/09179bee606aa01b1ee00d049ab78fc4 to your computer and use it in GitHub Desktop.
parameters:
telegram.token: '%env(TELEGRAM_TOKEN)%'
telegram.webhook_secret: '%env(TELEGRAM_WEBHOOK_SECRET)%'
services:
GuzzleHttp\Client:
arguments:
- { timeout: 120}
Http\Factory\Guzzle\RequestFactory:
Http\Factory\Guzzle\StreamFactory:
Psr\Http\Message\RequestFactoryInterface: '@Http\Factory\Guzzle\RequestFactory'
Psr\Http\Message\StreamFactoryInterface: '@Http\Factory\Guzzle\StreamFactory'
Http\Adapter\Guzzle6\Client:
arguments:
- '@GuzzleHttp\Client'
Psr\Http\Client\ClientInterface: '@Http\Adapter\Guzzle6\Client'
TgBotApi\BotApiBase\BotApiNormalizer:
TgBotApi\BotApiBase\NormalizerInterface: '@TgBotApi\BotApiBase\BotApiNormalizer'
TgBotApi\BotApiBase\ApiClientInterface:
class: TgBotApi\BotApiBase\ApiClient
arguments:
- '@Psr\Http\Message\RequestFactoryInterface'
- '@Psr\Http\Message\StreamFactoryInterface'
- '@Psr\Http\Client\ClientInterface'
TgBotApi\BotApiBase\WebhookFetcherInterface:
class: TgBotApi\BotApiBase\WebhookFetcher
arguments:
- '@TgBotApi\BotApiBase\NormalizerInterface'
TgBotApi\BotApiBase\BotApiInterface:
class: TgBotApi\BotApiBase\BotApiComplete
arguments:
- '%telegram.token%'
- '@TgBotApi\BotApiBase\ApiClientInterface'
- '@TgBotApi\BotApiBase\NormalizerInterface'
@deepraybhatt1234
Copy link

How to create a new bot

@greenplugin
Copy link
Author

@osavchenko
Copy link

This config can be simplified with autowire option and Guzzle can be replaced with Symfony HttpClient. If it makes sense I can write a manual how to prepare this library with Symfony framework.

@greenplugin
Copy link
Author

Yep, it can be simplified, I'ts old example. Please, write if you will have a time, I'll update readme.
We have a symfony flex receipe.

@greenplugin
Copy link
Author

I think we can add another readme to repository named like README.SYMFONY.md and add link to main readme.

@ibrahiamm
Copy link

How to create a new bot

@ibrahiamm
Copy link

@NarenNare
Copy link

$botKey = '';

$requestFactory = new Http\Factory\Guzzle\RequestFactory();
$streamFactory = new Http\Factory\Guzzle\StreamFactory();
$client = new Http\Adapter\Guzzle6\Client();

$apiClient = new \TgBotApi\BotApiBase\ApiClient($requestFactory, $streamFactory, $client);
$bot = new \TgBotApi\BotApiBase\BotApi($botKey, $apiClient, new \TgBotApi\BotApiBase\BotApiNormalizer());

$userId = '';

$bot->send(\TgBotApi\BotApiBase\Method\SendMessageMethod::create($userId, 'Hi'));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment