Telegram\Bot\Api::__construct PHP Method

__construct() public method

Instantiates a new Telegram super-class object.
public __construct ( string $token = null, boolean $async = false, Telegram\Bot\HttpClients\HttpClientInterface $httpClientHandler = null )
$token string The Telegram Bot API Access Token.
$async boolean (Optional) Indicates if the request to Telegram will be asynchronous (non-blocking).
$httpClientHandler Telegram\Bot\HttpClients\HttpClientInterface (Optional) Custom HTTP Client Handler.
    public function __construct($token = null, $async = false, $httpClientHandler = null)
    {
        $this->accessToken = isset($token) ? $token : getenv(static::BOT_TOKEN_ENV_NAME);
        if (!$this->accessToken) {
            throw new TelegramSDKException('Required "token" not supplied in config and could not find fallback environment variable "' . static::BOT_TOKEN_ENV_NAME . '"');
        }
        if (isset($async)) {
            $this->setAsyncRequest($async);
        }
        $this->client = new TelegramClient($httpClientHandler);
        $this->commandBus = new CommandBus($this);
    }

Usage Example

Example #1
0
 /**
  * Client constructor.
  */
 public function __construct($token)
 {
     parent::__construct($token);
     $container = new Container();
     self::setContainer($container);
     $this->addCommand(StartCommand::class);
     $this->addCommand(RouteCommand::class);
     $this->addCommand(StopCommand::class);
     $this->addCommand(GetCommand::class);
     $this->addCommand(EnableUpdatesCommand::class);
     $this->addCommand(StopUpdatesCommand::class);
     $this->addCommand(ResetCommand::class);
     $this->addCommand(SaveFavCommand::class);
     $this->addCommand(LoadFavCommand::class);
     $this->addCommand(FavsCommand::class);
     $this->addCommand(DelFavCommand::class);
     $this->addCommand(GetLinkCommand::class);
     $this->addCommand(RoutesCommand::class);
     $this->addCommand(CreditsCommand::class);
 }