0

I looked on google and found botman and when I read the documentation, I found that I will do something great and cool with this framework But when I did my first hello world application, I was faced with a problem is that my bot does not answer me. Here is my code:

<?php

require __DIR__ . '/vendor/autoload.php';

use Mpociot\BotMan\BotManFactory;
use Mpociot\BotMan\BotMan;


$config = [
    'facebook_token' => 'MY_facebook_token_ generated',
    'facebook_app_secret' => 'MY_facebook_app_secret_given',
];

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

$botman->verifyServices('My_key_verification');

// give the bot something to listen for.
$botman->hears('hi', function (BotMan $bot) {
    $bot->reply('hello world.');
});

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

I noticed from here that my facebook token was checked and it is exactly the same as facebook generated, my facebook_app_secret also is the same, as well as my verify services and I do not know where the problem lies.

So I looked in a forum and found that I have to use doctrine cache but I do not know how to use it properly Here is my code:

<?php

require __DIR__ . '/vendor/autoload.php';

use Mpociot\BotMan\BotManFactory;
use Mpociot\BotMan\BotMan;
use Mpociot\BotMan\Cache\DoctrineCache;


$config = [
    'facebook_token' => 'MY_facebook_token_ generated',
    'facebook_app_secret' => 'MY_facebook_app_secret_given',
];

$doctrineCacheDriver = 'ApcCache';

// create an instance
$botman = BotManFactory::create($config, new DoctrineCache($doctrineCacheDriver));

$botman->verifyServices('My_key_verification');

// give the bot something to listen for.
$botman->hears('hi', function (BotMan $bot) {
    $bot->reply('hello world.');
});

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

And there is an error, here is the error:

Catchable fatal error: Argument 1 passed to Mpociot\BotMan\Cache\DoctrineCache::__construct() must be an instance of Doctrine\Common\Cache\Cache, string given, called in C:\wamp64\www\bot\index.php on line 19 and defined in C:\wamp64\www\bot\vendor\mpociot\botman\src\Mpociot\BotMan\Cache\DoctrineCache.php on line 18

And here is my file composer.json

{
    "require": {
        "mpociot/botman": "^1.4",
        "phpunit/phpunit": "~4.8|~5.0",
        "doctrine/cache": "^1.6",
        "satooshi/php-coveralls": "~0.6",
        "predis/predis": "~1.0",
        "illuminate/support": "~5.0",
        "orchestra/testbench": "~3.0",
        "mockery/mockery": "dev-master",
        "sllh/php-cs-fixer-styleci-bridge": "^2.1",
        "mpociot/slack-client": "^0.2.6",
        "ext-curl": "*"
    }
}
Lapa Ny Aina Tanjona
  • 1,138
  • 1
  • 9
  • 19
  • 1
    Have you subscribed to a Page that will receive webhook calls on the Facebook Developers Platform? I haven't worked with PHP and bots but most of the times that's the reason you're not getting back any message. – sotirelisc Apr 06 '17 at 08:23
  • Agreed, you don't need cache for this simple example your code should work fine the first time providing it's setup correctly on FB side. – fire Apr 06 '17 at 08:27
  • Yes, i think i have my application subscribed with my page. Is that what you mean! @sotirelisc – Lapa Ny Aina Tanjona Apr 06 '17 at 08:34
  • Choose Messenger from the left sidebar and then scroll down to the Webhooks panel. Check there if you have a Page subscribed. – sotirelisc Apr 06 '17 at 08:42
  • Yes, and the callback url is fine and my application is subscribed exactly with my application page. And I also wonder why it does not work when I followed the instructions at the fingertips. – Lapa Ny Aina Tanjona Apr 06 '17 at 08:54

0 Answers0