Closed thomasgroch closed 8 years ago
triggerCommand()
this method cannot be used outside of the command class as it's a protected method.
@irazasyed, I put this function only to illustrate the problem.
Someone had any different approach?
I see. Well, I think i didn't quite understand what was the problem here then?
Are you asking how to debug?
The SDK throws various Exceptions. So you can use try/catch method to catch any exceptions and handle the error accordingly.
Check out the Exceptions directory for all the exception it throws.
The problem is I can not trigger the command when the user did not enter a command. All I'm trying to do is take advantage of the command code "/music {youtube}-link" to handle messages that are youtube links so it be a default behavior.
In that case, I'd recommend you to setup a class or a trait that you can use it inside your command class as well as inside your controller.
Something like this:
public function webhook($token = null) {
$update = Telegram::commandsHandler(true);
$chat_id = $update->getMessage()->getChat()->getId();
$text_message = $update->getMessage()->getText();
if( $this->_isYoutubeLink($text_message) && FALSE === strpos($text_message, 'music') ) {
Telegram::sendMessage([
'chat_id' => $chat_id,
'text' => 'By default I will allways return the audio from link you send me. :)'
]);
$music = new App\Services\Music($text_message);
$response = $music->getMusic();
}
}
Obviously, the above code is roughly done based on your code. I have no idea what your bot does. But you get the idea.
This way I won't be able to call $this->replyWithAudio for instance. I was thinking that with the same say I could do something like:
public function webhook($token = null) {
$update = Telegram::commandsHandler(true);
$text_message = $update->getMessage()->getText();
$commandClass = "app\TelegramCommands\MusicCommand";
if( class_exists($commandClass) ){
$obj = new $commandClass($update);
$obj->handle( $text_message );
}
}
But it's also not possible.
Yeah! You won't be able to do that but all the replyWith<Method>
methods are simply wrappers that use the current message's chat id. You can just manually pass that which you get from the update object anyway.
But I'll see if we can open that trigger method in next release.
Closed in last commit. Will be released in V3.
I am developing a bot that responds to the command /music {youtube_link}. So far my command works perfectly. I would like the system invoked by default "/music" when it found a link on the user menssage.
I realized in the documentation that I implement this in the controller after:
$update = Telegram::commandsHandler(true);
So, on my Controller I try:
I got no error message is recorded in the storage files / logs / laravel.log and /var/log/nginx/error.log And unfortunately the command is not triggered.
Note: The message "By default I will... " is sent normally.
Since this is a very common scenario, I decided to open this topic to know the solution that you have given.