Botman: Error retrieving user info: Bad Request: wrong user_id specified

Created on 14 Sep 2017  路  3Comments  路  Source: botman/botman

  • BotMan Version: 2.0.4
  • PHP Version: 7.1
  • Messaging Service(s): Telegram / Messenger
  • Cache Driver: redis

Description:

If I call $bot->getUser() inside a method of the middleware I receive this error for telegram:

BotMan\Drivers\Telegram\Exceptions\TelegramException: Error retrieving user info: Bad Request: wrong user_id specified in file /Applications/MAMP/htdocs/rank_bot/vendor/botman/driver-telegram/src/TelegramDriver.php on line 57

the same for messenger:

BotMan\Drivers\Facebook\Exceptions\FacebookException: Error sending payload: Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api in file /Applications/MAMP/htdocs/rank_bot/vendor/botman/driver-facebook/src/FacebookDriver.php on line 406

Steps To Reproduce:

botman.php

$authMiddleware = new Authorization();
$botman->middleware->received($authMiddleware);
$botman->fallback(BotManController::class.'@startConversation');

Authorization.php

class Authorization implements MiddlewareInterface
{
    public function captured(IncomingMessage $message, $next, BotMan $bot)
    {
        return $next($message);
    }

    public function heard(IncomingMessage $message, $next, BotMan $bot)
    {
        return $next($message);
    }

    public function matching(IncomingMessage $message, $pattern, $regexMatched)
    {
        return true;
    }

    public function received(IncomingMessage $message, $next, BotMan $bot)
    {
        $user=$bot->getUser();
        return $next($message);
    }

    public function sending($payload, $next, BotMan $bot)
    {
        return $next($payload);
    }

}

Most helpful comment

Retrieving users works by using the matched message. In your case, BotMan doesn't know which message might match, because it is inside a received middleware.

To get the user anyway, just pass the message to the driver getUser method.

$user = $bot->getDriver()->getUser($message);

All 3 comments

Retrieving users works by using the matched message. In your case, BotMan doesn't know which message might match, because it is inside a received middleware.

To get the user anyway, just pass the message to the driver getUser method.

$user = $bot->getDriver()->getUser($message);

And how to get user info in Conversation class.
Im using $username = $bot->getUser()->getUsername(); in ExampleConversation but have an error Undefined variable: bot

$bot is not defined, you need to use $this->bot

Was this page helpful?
0 / 5 - 0 ratings

Related issues

melihovv picture melihovv  路  4Comments

JABirchall picture JABirchall  路  4Comments

hossinasaadi picture hossinasaadi  路  4Comments

alvinmurimi picture alvinmurimi  路  4Comments

ghost picture ghost  路  3Comments