GithubHelp home page GithubHelp logo

eugenganshorn / telegrambotbundle Goto Github PK

View Code? Open in Web Editor NEW

This project forked from boshurik/telegrambotbundle

0.0 1.0 0.0 126 KB

Symfony Telegram Bot Bundle

License: MIT License

PHP 100.00%

telegrambotbundle's Introduction

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.

telegrambotbundle's People

Contributors

boshurik avatar bigfoot90 avatar akuzia avatar martcor avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.