/**
  * Initialize Telegram Bot SDK Library with Default Config.
  */
 public function registerTelegram()
 {
     $this->app->singleton('telegram', function ($app) {
         $config = $app['config'];
         $telegram = new Api($config->get('telegram.bot_token', false), $config->get('telegram.async_requests', false), $config->get('telegram.http_client_handler', null));
         // Register Commands
         $telegram->addCommands($config->get('telegram.commands', []));
         return $telegram;
     });
 }
 /**
  * Initialize Telegram Bot SDK Library with Default Config.
  *
  * @param Application $app
  */
 protected function registerTelegram(Application $app)
 {
     $app->singleton(Api::class, function ($app) {
         $config = $app['config'];
         $telegram = new Api($config->get('telegram.bot_token', false), $config->get('telegram.async_requests', false), $config->get('telegram.http_client_handler', null));
         // Register Commands
         $telegram->addCommands($config->get('telegram.commands', []));
         return $telegram;
     });
     $app->alias(Api::class, 'telegram');
 }
 /**
  * Initialize Telegram Bot SDK Library with Default Config.
  *
  * @param Application $app
  */
 protected function registerTelegram(Application $app)
 {
     $app->singleton(Api::class, function ($app) {
         $config = $app['config'];
         $telegram = new Api($config->get('telegram.bot_token', false), $config->get('telegram.async_requests', false), $config->get('telegram.http_client_handler', null));
         // Register Commands
         $telegram->addCommands($config->get('telegram.commands', []));
         // Check if DI needs to be enabled for Commands
         if ($config->get('telegram.inject_command_dependencies', false)) {
             $telegram->setContainer($app);
         }
         return $telegram;
     });
     $app->alias(Api::class, 'telegram');
 }
示例#4
0
 /**
  * Make the bot instance.
  *
  * @param string $name
  *
  * @return Api
  */
 protected function makeBot($name)
 {
     $config = $this->getBotConfig($name);
     $token = array_get($config, 'token');
     $commands = array_get($config, 'commands', []);
     $telegram = new Api($token, $this->getConfig('async_requests', false), $this->getConfig('http_client_handler', null));
     // Check if DI needs to be enabled for Commands
     if ($this->getConfig('resolve_command_dependencies', true)) {
         $telegram->setContainer($this->app);
     }
     $commands = $this->parseBotCommands($commands);
     // Register Commands
     $telegram->addCommands($commands);
     return $telegram;
 }
<?php

use Telegram\Bot\Api;
use Commands;
require 'vendor/autoload.php';
require 'config.php';
if (getenv('MODE_ENV') == 'develop') {
    class mockApi extends Api
    {
        public function getWebhookUpdates()
        {
            $json = '{}';
            return new Telegram\Bot\Objects\Update(json_decode($json, true));
        }
    }
    $telegram = new mockApi($config['token']);
} else {
    error_log(file_get_contents('php://input'));
    $telegram = new Api($config['token']);
}
// Standalone
$telegram->addCommands([Telegram\Bot\Commands\HelpCommand::class, Commands\StartCommand::class, Commands\RegisterCommand::class, Commands\RemoveCommand::class, Commands\RankingCommand::class, Commands\ListUsersCommand::class]);
$telegram->commandsHandler(true);
<?php

use Telegram\Bot\Api;
use Commands;
require 'vendor/autoload.php';
require 'config.php';
$telegram = new Api($config['token']);
// Standalone
$telegram->addCommands([Telegram\Bot\Commands\HelpCommand::class]);
$telegram->commandsHandler(true);