Botman: Discard message from received middleware

Created on 9 Nov 2017  路  5Comments  路  Source: botman/botman

  • BotMan Version: 2.1.0
  • PHP Version: 7.1.11
  • Messaging Service(s): Facebook
  • Cache Driver: Botman studio default

Hello, my received middleware receives some facebook messages multiple times (with same timestamp, text, everything). Is there any way to discard message from middleware / don't react to it? Something like return false instead of return $next($message)?

Thank you.

Most helpful comment

This way from @mpociot is working:

"The easiest way would be to just send a 200 OK response and stop the code execution."

Code is:

            http_response_code(200);
            die();

All 5 comments

There are multiple ways to ignore an incoming message inside the received middleware.
The easiest way would be to just send a 200 OK response and stop the code execution.
But it should also be possible to just pass $next(false) or $next(null).

I can't return anything else, because I get:

Type error: Argument 1 passed to BotMan\BotMan\Messages\Matcher::isMessageMatching() must be an instance of BotMan\BotMan\Messages\Incoming\IncomingMessage, boolean given, called in /Users/matej.minar/Web/knihozrut/vendor/botman/botman/src/Commands/ConversationManager.php on line 80 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Type error: Argument 1 passed to BotMan\\BotMan\\Messages\\Matcher::isMessageMatching() must be an instance of BotMan\\BotMan\\Messages\\Incoming\\IncomingMessage, boolean given, called in /Users/matej.minar/Web/knihozrut/vendor/botman/botman/src/Commands/ConversationManager.php on line 80 at /Users/matej.minar/Web/knihozrut/vendor/botman/botman/src/Messages/Matcher.php:31)

@matejminar Same problem for me.

Did you find a solution?

Did anyone ever figure this out?

This way from @mpociot is working:

"The easiest way would be to just send a 200 OK response and stop the code execution."

Code is:

            http_response_code(200);
            die();
Was this page helpful?
0 / 5 - 0 ratings