botman / docs

BotMan documentation
33 stars 52 forks source link

$botman->receivesImages NOT WORKING. #68

Closed alvinmurimi closed 6 years ago

alvinmurimi commented 6 years ago

I tried getting the URL of an image sent by the user to the bot so that i can pass it for other functions but i keep getting this error

Uncaught Error: Call to a member function getUrl() and this other one

/app/vendor/mpociot/botman/src/Mpociot/BotMan/BotMan.php(371): call_user_func_array(Object(Closure), Array) Here is my code:

require 'vendor/autoload.php';
use Mpociot\BotMan\Messages\Message;
use Mpociot\BotMan\BotManFactory;
use Mpociot\BotMan\BotMan;
use BotMan\BotMan\Messages\Attachments\File;
use BotMan\BotMan\Messages\Attachments\Image;
use BotMan\BotMan\Messages\Outgoing\OutgoingMessage;
use BotMan\Drivers\DriverManager;
$config = [

    // Your driver-specific configuration
     'telegram_token'=>"<token>",
];

// create an instance
$botman = BotManFactory::create($config);

// give the bot something to listen for.
$botman->hears('/start', function (BotMan $bot) {
    $bot->reply('Hello yourself.');
});
   $botman->receivesImages(function($bot,$images) {
  foreach($images as $image){
   $url=$image->getUrl();
   $title=$image->getTitle();
   $bot->reply("hello: ".$url);
  }
});
// start listening
$botman->listen();

When the bot receives an image, it fails to respond. What might be the problem?

mpociot commented 6 years ago

Hi - you are using the old version of BotMan (1.5) but mix it with 2.0 code. Please remove the 1.5 (The Mpociot namespace references) from your code and update to version 2.x

alvinmurimi commented 6 years ago

Hi! Thank you for the suggestion but when i upgared to botman 2.1, i get this Uncaught Error: Class 'Botman\BotMan\BotManFactory not found.All namespaces references are perfect but the code fails with that error. It forced me to downgrade.

alvinmurimi commented 6 years ago

I solved it. I had some few errors with the namespace case