Closed esomkin closed 6 years ago
I'am trying to initialize Request by telegram object manually, but code $result = Request::initialize($this->telegram)->sendMessage($data);
gives an error Call to a member function sendMessage() on null
Hi @esomkin
When you create a new Telegram object, the Request class gets initialised already, no need to manually do that. You get the error because Request::initialize(...)
does not return anything.
Try just using Request::sendMessage(...)
after you've created your Telegram object!
Also, in your initial message, I think you want $this->telegram->handle();
to be $this->handle();
, right?
Or does the webhook call link into your job?
Hi @noplanman
Thank you for answer, I'am using Request::sendMessage(...)
too, as you can see in my question. Handle
method of a Job class start automatically, $this->telegram->handle()
is removed, but result is the same - error in console.
@noplanman It is strange but, message send successful only if I place send code into __construct
.
I think you didn't read my comment properly...
You want $this->telegram->handle();
to be $this->handle();
.
Otherwise the method obviously isn't called.
Are you new to PHP programming?
@noplanman I read your comment, and I understand it good. Handle
method of a Laravel job is called automatically by Laravel, that is why I place sendMessage here. $this->telegram->handle();
I add as in hook.php
(https://github.com/php-telegram-bot/example-bot/blob/master/hook.php), it can be removed and it does not matter. The question is why it works only if place creating new Telegram object and Request::messageSend in __construct
together?
@noplanman Please check discussion about this problem https://stackoverflow.com/questions/48702352/call-to-a-member-function-getbotusername-on-null-in-vendor-longman-telegram/48702699?noredirect=1#48702699
Riiight @ Laravel calling handle()
method 👍
You could also just call Request::initialize($this->telegram);
first in your handle()
method, before sending the message.
Then it should work.
(Also for next time, best come here first instead of SO, so that we can do something about issues that come up)
Suggestion: Could we add an exception throw when Request is not initialized @noplanman ? 🤔
@noplanman Ok, thank you for your answers!
So we can close off here then, right?
@noplanman I think, yes
Required Information
Expected behaviour
I have a Telegram bot, which is located on
domain1.com
. Telegram bot tested and works fine. Also I have a system (build with Laravel Lumen), which is located ondomain2.com
and it is try to send Telegram messages without user interaction as described in wiki (https://github.com/php-telegram-bot/core/wiki/How-to-send-message-to-channel-user-without-user-interaction). Both domains has valid SSL certificates.So, to teach system send Telegram messages, I'am using a tutorial from wiki too (https://github.com/php-telegram-bot/core/wiki/Install-on-Laravel). Messages is send by Laravel jobs, so my job is
Actual behaviour
When Laravel queue try to dispatch a job ProcessTelegramMessageJob it is process infinitelly. In log I see a message
Call to a member function getBotUsername() on null in …vendor/longman/telegram-bot/src/Request.php
. How can I fix this problem? Thank you in advance!