2017 © Pedro Peláez
 

library silex-tg-service-provider

Silex Service Provider for the Telegram SDK

image

ahoulgrave/silex-tg-service-provider

Silex Service Provider for the Telegram SDK

  • Saturday, November 19, 2016
  • by ahoulgrave
  • Repository
  • 1 Watchers
  • 3 Stars
  • 29 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Telegram PHP SDK Silex Service Provider

Build status, (*1)

Overview

A Silex service provider to integrate the Telegram PHP SDK, (*2)

Requirements

Installation

composer require ahoulgrave/silex-tg-service-provider dev-master

Usage

<?php
use Telegram\Bot\Silex\Provider\TelegramServiceProvider;

$app = new Silex\Application();

$app->register(new TelegramServiceProvider(), [
    'telegram.bot_api' => '<Your bot api token>',
    'telegram.commands' => [
        \My\Telegram\Command\AwesomeCommand::class,
    ]
]);

Webhook

If your are using a webhook to fetch the updates, you can register the Controller Provider to handle the request for you., (*3)

$app->mount('/telegram-web-hook', new TelegramControllerProvider());

Your webhook should be https://youdomain.com/telegram-web-hook/ (Note the trailing slash), (*4)

Now, when telegram sends you the updates, the controller will look for the right command and handle it., (*5)

Commands

You can extend the Telegram\Bot\Silex\ApplicationAwareCommand class, so your command can access the container., (*6)

For example:, (*7)

<?php
namespace My\Telegram\Command;

use Telegram\Bot\Silex\ApplicationAwareCommand;

class AwesomeCommand extends ApplicationAwareCommand
{
    /**
     * @inheritdoc
     */
    protected $name = 'hello';

    /**
     * @inheritdoc
     */
    public function handle($arguments)
    {
        $update = $this->getUpdate();
        $app = $this->getApplication();
        $app['monolog']->info($update->getMessage()->getText());
        $this->replyWithMessage(['text' => 'Hi there!']);
    }
}

Remember to register all of your commands (see Usage), (*8)

Read this for more details on the commands system, (*9)

More information

License

(The MIT License), (*10)

Copyright (C) 2016 by Agustin Houlgrave, (*11)

The Versions

19/11 2016

dev-master

9999999-dev

Silex Service Provider for the Telegram SDK

  Sources   Download

The Requires

 

The Development Requires

by Agustin Houlgrave