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": "*"
}
}