Core: Commands without / only Plaintext

Created on 8 Apr 2017  路  15Comments  路  Source: php-telegram-bot/core

Can i create Commands without / ?
Only Plaintext.

Like: User send Text: Deutsch -> Command will be executed

Kind Regards

All 15 comments

Text messages are handled by GenericmessageCommand.
You will have to do your magic there.

i dont understand that ;(

it is very frustrating

The file
https://github.com/akalongman/php-telegram-bot/blob/master/src/Commands/SystemCommands/GenericmessageCommand.php is the file you need to edit.

For example, add this code to automaticly download photos and files.

$message = $this->getMessage();
if (in_array($message->getType(), ['audio', 'document', 'photo', 'video', 'voice'], true)) {
    $doc = call_user_func([$message, 'get' . ucfirst($message->getType())]);
    ($message->getType() === 'photo') && $doc = $doc[0];
        $file = Request::getFile(['file_id' => $doc->getFileId()]);
        if ($file->isOk()) {
            Request::downloadFile($file->getResult());
    }
}

I made it like this
https://pastebin.com/3N8yHC1s
But it doesnt work ;(

@InSide24 Make a copy of the GenericmessageCommand.php file and make your changes there, leaving the class name and namespace. Put that file in a custom folder and add that folder to the bot using $telegram->addCommandsPath(...);

@noplanman I allready made all that things you said
But it didnt worked ;(

https://pastebin.com/5uck4SzZ

...leaving the class name and namespace.

Class and file name must be GenericmessageCommand.

and what is if i need about 5-10 GenericmessageCommands ?
Caus they cant all have the same Filename

Inside the GenericmessageCommand you can do whatever you like, require new classes, add extra methods, etc. etc.

Any "generic message" points to the GenericmessageCommand, where you can then go crazy 馃帀

@noplanman thanks for the Help.

And greetings from Switzerland ;)

And greetings from Switzerland ;)

馃槂 vili gr眉ess zrugg!!

As soon as it's working for you, just close off or carry on asking 馃憤

@noplanman Hey 馃摝

German:
Also es funktioniert zwar, komischer Weise wird das aber bei jedem Text denn man eingibt ausgef眉hrt ;(
M枚chte es aber gerne so haben das wenn man z.b. denn Text 'Deutsch' sendet, das dann der Command ausgef眉hrt wird.
English:
It makes the Command every time when i send some text and not only when i send text 'Deutsch'

Pastebin: https://pastebin.com/T0LPJJw4
Screenshot: http://prntscr.com/etyr5v

I'll stick to English 馃槈

This behaviour is correct, because every generic message gets handled by this command!
So you'll have to add some if statements to handle specific commands.

Also, for what you're doing, I'd suggest you create a new command for that, like /config or something. Then you can handle all configurations much better.

Thanks for helping 馃槏

@InSide24 You're welcome!

P.S. You can post code and images on GitHub directly, makes it much easier to follow the thread 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

noplanman picture noplanman  路  3Comments

mohsenshahab picture mohsenshahab  路  4Comments

Bl0ck154 picture Bl0ck154  路  3Comments

ttvd94 picture ttvd94  路  4Comments

marcolino7 picture marcolino7  路  3Comments