vendredi 9 février 2018

Call to a member function getBotUsername() on null in ...vendor/longman/telegram-bot/src/Request.php

I'am trying to send a Telegram message with Telegram Bot (longman/telegram-bot) and Laravel Lumen jobs.

So, first I'am install a Telegram bot with composer require longman/telegram-bot and add to composer.json "Longman\\TelegramBot\\": "vendor/longman/telegram-bot/src". Then create a job

<?php

namespace App\Jobs;
use Longman\TelegramBot\Request;
use Longman\TelegramBot\Telegram;
use Longman\TelegramBot\Exception\TelegramException;

class ProcessTelegramMessageJob extends Job
{
    const TELEGRAM_API_KEY = 'BOTKEY';
    const TELEGRAM_BOT_NAME = 'BOTNAME';

    protected $telegram;
    protected $data;

    public function __construct($data)
    {
        $this->data = $data;

        try {

            $this->telegram = new Telegram(self::TELEGRAM_API_KEY, self::TELEGRAM_BOT_NAME);
            $this->telegram->handle();

        } catch (TelegramException $e) {}
    }

    public function handle()
    {
        $data = [

            'chat_id' => $this->data['user_id'],
            'text' => $this->data['message'],
        ];

        $result = Request::sendMessage($data);
    }
}

But, when job try to dispatch, I see in log Call to a member function getBotUsername() on null in ...vendor/longman/telegram-bot/src/Request.php. As I understand Request is not see Telegram instance.

How to fix this error? Thanks in advance!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire