Botman: "RECEIVES IMAGES" NOT WORKING

Created on 15 Feb 2018  路  4Comments  路  Source: botman/botman

  • BotMan Version: 2.0
  • PHP Version:7.2.2
  • Messaging Service(s): Telegram
  • Cache Driver:

I've been trying to retrive the url of an image sent by a user using the code below:

require 'vendor/autoload.php';

use BotMan\BotMan\BotMan;
use BotMan\BotMan\Messages\Message;
use BotMan\BotMan\BotManFactory;
use BotMan\BotMan\Messages\Attachments\File;
use BotMan\BotMan\Messages\Attachments\Image;
use BotMan\BotMan\Messages\Outgoing\OutgoingMessage;
use BotMan\BotMan\Drivers\DriverManager;
$config = [
    'telegram' => [
      'token' => '<token>'
    ]
  ];

// create an instance
$driver=DriverManager::loadDriver(\BotMan\Drivers\Telegram\TelegramDriver::class);

$botman = BotManFactory::create($config);
$botman->receivesImages(function($bot,$image) {
   $url=$image->getUrl();
      $bot->reply($url);
});

However, the bot doesn't seem to respond with anything. I also tried this:

$botman->receivesImages(function($bot, $images) {

    foreach ($images as $image) {

        $url = $image->getUrl(); // The direct url
        $title = $image->getTitle(); // The title, if available
        $payload = $image->getPayload(); // The original payload
            $bot->reply($url);
    }

});

But both codes still result to the bot replying with nothing.
What might be the problem?

Most helpful comment

Hi @alvinmurimi ,

if you load the driver manually, make sure to also load the Telegram driver that takes care of receiving image attachments.

Add this code, to load the appropriate driver:

DriverManager::loadDriver(\BotMan\Drivers\Telegram\TelegramDriver::class);
DriverManager::loadDriver(\BotMan\Drivers\Telegram\ TelegramPhotoDriver::class);

All 4 comments

Hi @alvinmurimi ,

if you load the driver manually, make sure to also load the Telegram driver that takes care of receiving image attachments.

Add this code, to load the appropriate driver:

DriverManager::loadDriver(\BotMan\Drivers\Telegram\TelegramDriver::class);
DriverManager::loadDriver(\BotMan\Drivers\Telegram\ TelegramPhotoDriver::class);

Hi @alvinmurimi ,

if you load the driver manually, make sure to also load the Telegram driver that takes care of receiving image attachments.

Add this code, to load the appropriate driver:

DriverManager::loadDriver(\BotMan\Drivers\Telegram\TelegramDriver::class);
DriverManager::loadDriver(\BotMan\Drivers\Telegram\ TelegramPhotoDriver::class);

Please update this to Documentation as well.

DriverManager::loadDriver(\BotMan\Drivers\Telegram\TelegramDriver::class);
DriverManager::loadDriver(\BotMan\Drivers\Telegram\TelegramPhotoDrive::class);
DriverManager::loadDriver(\BotMan\Drivers\Telegram\TelegramFileDrive::class);

You loaded \TelegramPhotoDrive::class and \TelegramFileDrive::class instead of \TelegramPhotoDriver::class and \TelegramFileDriver::class
It's "Driver" not "Drive"

@alvinmurimi omg!!! Thx bro!!!

Was this page helpful?
0 / 5 - 0 ratings