All Projects → BoShurik → TelegramBotBundle

BoShurik / TelegramBotBundle

Licence: MIT license
Symfony Telegram Bot Bundle

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to TelegramBotBundle

symbok-bundle
Symfony annotations bundle
Stars: ✭ 50 (-1.96%)
Mutual labels:  symfony-bundle
firebase-bundle
A Symfony Bundle for the Firebase PHP Admin SDK
Stars: ✭ 112 (+119.61%)
Mutual labels:  symfony-bundle
OpcacheBundle
Displays the PHP OPcache status in the Symfony profiler toolbar.
Stars: ✭ 21 (-58.82%)
Mutual labels:  symfony-bundle
WhiteOctoberSwiftMailerDBBundle
A bundle to facilitate SwiftMailer spooling messages to a database
Stars: ✭ 31 (-39.22%)
Mutual labels:  symfony-bundle
breadcrumb-bundle
Symfony bundle for easy breadcrumbs management
Stars: ✭ 26 (-49.02%)
Mutual labels:  symfony-bundle
socketio
No description or website provided.
Stars: ✭ 23 (-54.9%)
Mutual labels:  symfony-bundle
connect-bundle
No description or website provided.
Stars: ✭ 35 (-31.37%)
Mutual labels:  symfony-bundle
SpBundle
SAML2 SP Symfony Bundle based on LightSAML
Stars: ✭ 62 (+21.57%)
Mutual labels:  symfony-bundle
awsBundle
Symfony AWS Bundle (supports Symfony 2, 3 and 4)
Stars: ✭ 18 (-64.71%)
Mutual labels:  symfony-bundle
queue-bundle
Symfony Queue Bundle
Stars: ✭ 31 (-39.22%)
Mutual labels:  symfony-bundle
CoopTilleulsSyliusClickNCollectPlugin
Sell and deliver securely during the COVID-19 pandemic!
Stars: ✭ 77 (+50.98%)
Mutual labels:  symfony-bundle
LiipSoapRecorderBundle
[DEPRECATED] Recorder/Player for SOAP communications
Stars: ✭ 12 (-76.47%)
Mutual labels:  symfony-bundle
phpfastcache-bundle
The symfony 3/Flex bundle for PhpFastCache integrating a phpfastcache service, a twig cache tag and a powerfull cache profiler integrated to the symfony profile
Stars: ✭ 19 (-62.75%)
Mutual labels:  symfony-bundle
RapidFormBundle
Create Symfony forms at record speed using PHP 8 attributes!
Stars: ✭ 33 (-35.29%)
Mutual labels:  symfony-bundle
wordpress-bundle
Use Wordpress and Symfony together using a Symfony bundle
Stars: ✭ 30 (-41.18%)
Mutual labels:  symfony-bundle
NucleosDompdfBundle
📜 This bundle provides a wrapper for using dompdf inside symfony.
Stars: ✭ 29 (-43.14%)
Mutual labels:  symfony-bundle
BeelabTagBundle
🏷 A simple implementation of tags for Symfony and Doctrine ORM
Stars: ✭ 45 (-11.76%)
Mutual labels:  symfony-bundle
workflower-bundle
A Symfony bundle for Workflower
Stars: ✭ 23 (-54.9%)
Mutual labels:  symfony-bundle
ContentfulBundle
Symfony Bundle for the Contentful SDK.
Stars: ✭ 29 (-43.14%)
Mutual labels:  symfony-bundle
facade-bundle
Support Facades for Symfony service
Stars: ✭ 17 (-66.67%)
Mutual labels:  symfony-bundle

TelegramBotBundle

Telegram bot bundle on top of telegram-bot/api library

Examples

See example project

Installation

Composer

$ composer require boshurik/telegram-bot-bundle

If you are using symfony/flex all you need is to set TELEGRAM_BOT_TOKEN environment variable

Register the bundle

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new BoShurik\TelegramBotBundle\BoShurikTelegramBotBundle,
    );
    // ...
}

Add routing for webhook

BoShurikTelegramBotBundle:
    resource: "@BoShurikTelegramBotBundle/Resources/config/routing.yml"
    prefix: /_telegram/<some-secret>

Configuration

boshurik_telegram_bot:
    api:
        token: "%telegram_bot_api_token%"
        proxy: "socks5://127.0.0.1:8888"

Usage

API

    $api = $this->container->get(TelegramBot\Api\BotApi::class);

For more info see Usage section in telegram-bot/api library

Getting updates

bin/console telegram:updates

For more information see official documentation

Webhook

Set
bin/console telegram:webhook:set <url> [<path-to-certificate>]
Unset
bin/console telegram:webhook:unset

For more information see official documentation

Async command processing

To improve performance, you can leverage Messenger to process webhooks later via a Messenger transport.

composer req symfony/messenger
# config/packages/messenger.yaml
framework:
    messenger:
        transports:
            async: "%env(MESSENGER_TRANSPORT_DSN)%"

        routing:
            'BoShurik\TelegramBotBundle\Messenger\TelegramMessage': async

Adding commands

Commands must implement \BoShurik\TelegramBotBundle\Telegram\Command\CommandInterface

There is \BoShurik\TelegramBotBundle\Telegram\Command\AbstractCommand you can start with

To register command: add tag boshurik_telegram_bot.command to service definition

app.telegram.command:
    class: AppBundle\Telegram\Command\SomeCommand
    tags:
        - { name: boshurik_telegram_bot.command }

If you use autoconfigure tag will be added automatically

There is predefined \BoShurik\TelegramBotBundle\Telegram\Command\HelpCommand. You need to register it:

app.telegram.command.help:
    class: BoShurik\TelegramBotBundle\Telegram\Command\HelpCommand
    arguments:
        - '@BoShurik\TelegramBotBundle\Telegram\Command\CommandRegistry'
    tags:
        - { name: boshurik_telegram_bot.command }

It displays commands which additionally implement \BoShurik\TelegramBotBundle\Telegram\Command\PublicCommandInterface

Events

For more complex application (e.g. conversations) you can listen for BoShurik\TelegramBotBundle\Event\UpdateEvent event

/**
 * @param UpdateEvent $event
 */
public function onUpdate(UpdateEvent $event)
{
    $update = $event->getUpdate();
    $message = $update->getMessage();
}

Login with Telegram

This bundle supports login through Telegram Api

If you want allow your Bot's users to login without requiring them to register again follow these instructions.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].