Botman: No responses to facebook attachments

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

BotMan Version: 2.1.9
PHP Version: 7.1.13
Messaging Service(s): Facebook

Description:

I appear to have problem recognising any attachements from facebook using the standalone install, this is my index.php below. I have installed the driver but never get responses to sending attachments? Am I missing something? Plain text works fine.

Steps To Reproduce:

            <?php

            use BotMan\BotMan\BotMan;
            use BotMan\BotMan\BotManFactory;
            use BotMan\BotMan\Interfaces\CacheInterface;
            use BotMan\BotMan\Drivers\DriverManager;
            use BotMan\BotMan\Messages\Incoming;
            use BotMan\BotMan\Messages\Incoming\Answer;
            use BotMan\BotMan\Messages\Attachments;
            use BotMan\BotMan\Messages\Attachments\Image;
            use BotMan\BotMan\Messages\Attachments\Location;
            use BotMan\BotMan\Messages\Outgoing\Question;
            use BotMan\BotMan\Messages\Outgoing\Actions\Button;
            use BotMan\BotMan\Messages\Conversations\Conversation;
            use BotMan\Drivers\Facebook;
            use BotMan\Drivers\Facebook\Extensions\ButtonTemplate;
            use BotMan\Drivers\Facebook\Extensions\ElementButton;
            use BotMan\Drivers\Facebook\Extensions\GenericTemplate;
            use BotMan\Drivers\Facebook\Extensions\Element;
            use BotMan\BotMan\Messages\Incoming\IncomingMessage;

            require 'vendor/autoload.php';

            $config = [
                'facebook' => [
                    'token'        => 'xxx',
                    'verification' => 'xxx',
                ]
            ];

            // Load the driver(s) you want to use
            DriverManager::loadDriver(\BotMan\Drivers\Facebook\FacebookDriver::class);

            $botman = BotManFactory::create($config);

            $botman->hears('hi', function($bot) {
                $bot->reply('hi there');
            });

            $botman->receivesImages(function($bot, $images) {
                foreach ($images as $image) {
                    // never runs
                    $bot->reply('images');
                }
            });

            $botman->receivesLocation(function($bot, $location) {
                    // never runs
                $bot->reply('location');
            });

            // Start listening
            $botman->listen();

Most helpful comment

Hi,

in order to listen for attachments, you need to load the additional attachment drivers too.

DriverManager::loadDriver(\BotMan\\Drivers\\Facebook\\FacebookAudioDriver::class);
DriverManager::loadDriver(\BotMan\\Drivers\\Facebook\\FacebookFileDriver::class);
DriverManager::loadDriver(\BotMan\\Drivers\\Facebook\\FacebookImageDriver::class);
DriverManager::loadDriver(\BotMan\\Drivers\\Facebook\\FacebookLocationDriver::class);
DriverManager::loadDriver(\BotMan\\Drivers\\Facebook\\FacebookVideoDriver::class);

All 4 comments

Hi,

in order to listen for attachments, you need to load the additional attachment drivers too.

DriverManager::loadDriver(\BotMan\\Drivers\\Facebook\\FacebookAudioDriver::class);
DriverManager::loadDriver(\BotMan\\Drivers\\Facebook\\FacebookFileDriver::class);
DriverManager::loadDriver(\BotMan\\Drivers\\Facebook\\FacebookImageDriver::class);
DriverManager::loadDriver(\BotMan\\Drivers\\Facebook\\FacebookLocationDriver::class);
DriverManager::loadDriver(\BotMan\\Drivers\\Facebook\\FacebookVideoDriver::class);

Instantly works, thanks Marcel!

@mpociot what about slack? I can not find anyother classes for class apart from \BotMan\Drivers\Slack\SlackDriver::class

This should be in the documentation, I think

Was this page helpful?
0 / 5 - 0 ratings