Hey,
I can't see how I would parse a message for a keyword. For example if I wanted to warn users about language it could parse there text for a keyword / sentance then be able to do {whatever} and reply to them.
Thanks
In what context?
Could you give concrete examples please?
You can manually override and handle any case.
GenericmessageCommand.php is where you should make such keyword checks.
I'll look into generic message now, (Is there any data on it?)
but for an example say I wanted the bot to reply to anyone who uses the work f*ck with "please refrain from that language or you'll be banned"
I'm fine with the bot reading all the messages in the chat.
@jacklul Is it possible to extend the generic message Command or will I need to just add to it. (Sorry PHP is not my first language)
Something like this:
<?php
namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Request;
class GenericmessageCommand extends SystemCommand
{
private $bannedWords = ['what', 'is', 'love'];
public function execute()
{
$message = $this->getMessage();
$message_id = $message->getMessageId();
$chat_id = $message->getChat()->getId();
$user_mention = $message->getFrom()->tryMention();
$text = $message->getText(true);
if (!$message->getChat()->isPrivateChat()) {
foreach ($this->bannedWords as $bannedWord) {
if (strpos($bannedWord, $text)) {
return Request::sendMessage(['chat_id' => $chat_id, 'text' => $user_mention . ', please do not use bad language!', 'reply_to_message_id' => $message_id]);
}
}
}
return Request::emptyResponse();
}
}
Most helpful comment
Something like this: