GithubHelp home page GithubHelp logo

Comments (8)

filippotoso avatar filippotoso commented on June 10, 2024

Log the entire $message payload and start from there.

If getSender() returns 0, then getUser() will fail.

from botman.

chimit avatar chimit commented on June 10, 2024

Here is the $message content when it happens:

[2023-09-03 15:27:08] production.INFO: BotMan\BotMan\Messages\Incoming\IncomingMessage::__set_state(array(
   'message' => NULL,
   'sender' => 0,
   'recipient' => NULL,
   'bot_id' => '',
   'images' => 
  array (
  ),
   'videos' => 
  array (
  ),
   'payload' => 
  Illuminate\Support\Collection::__set_state(array(
     'items' => 
    array (
      'from' => 
      array (
        'id' => 0,
      ),
    ),
     'escapeWhenCastingToString' => false,
  )),
   'extras' => 
  array (
  ),
   'audio' => 
  array (
  ),
   'files' => 
  array (
  ),
   'location' => NULL,
   'contact' => NULL,
   'isFromBot' => false,
))  

from botman.

filippotoso avatar filippotoso commented on June 10, 2024

There's nothing there. Someone or something (ie. a crawler) is calling the endpoint without passing any data.

from botman.

chimit avatar chimit commented on June 10, 2024

This happens when a bot is added or removed from a group. Looks like Received middleware captures such service messages:

{
    "update_id": 22069942,
    "my_chat_member": {
        "chat": {
            "id": -222222222,
            "title": "Test",
            "type": "group",
            "all_members_are_administrators": true
        },
        "from": {
            "id": 111111111,
            "is_bot": false,
            "first_name": "Example",
            "username": "Example",
            "language_code": "fr"
        },
        "date": 1693746567,
        "old_chat_member": {
            "user": {
                "id": 3333333333,
                "is_bot": true,
                "first_name": "Botname",
                "username": "botnamebot"
            },
            "status": "left"
        },
        "new_chat_member": {
            "user": {
                "id": 3333333333,
                "is_bot": true,
                "first_name": "Botname",
                "username": "botnamebot"
            },
            "status": "member"
        }
    }
}

Is there a way to skip such messages?

from botman.

filippotoso avatar filippotoso commented on June 10, 2024

Just write some code in your Middleware to exclude the processing of this kind of messages.

from botman.

chimit avatar chimit commented on June 10, 2024

Yes, I did it this way:

public function received(IncomingMessage $message, $next, BotMan $bot)
{
    // Ignore service messages
    if (! $message->getSender()) {
        return $next($message);
    }

For those who are looking how to capture service messages here are the list of supported Telegram events. Usage is described here.

from botman.

chimit avatar chimit commented on June 10, 2024

Another way to ignore service messages is not to use the Received middleware but instead use Heard and Captured.

from botman.

chimit avatar chimit commented on June 10, 2024

I realized that one of the reasons for this error is when users add a bot into a channel. Messages from channel admins are anonymous so getUser() method fails. I had to ignore channels in the middleware.

from botman.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.