我看了google并发现了botman,当我阅读文档时,我发现我会用这个框架做一些很棒的事情 但是当我第一次打开hello world应用程序时,我遇到的问题是我的机器人没有回答我。 这是我的代码:
<?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();
我从这里注意到我的facebook令牌已经过检查,它与facebook生成的完全相同,我的facebook_app_secret也是一样的,以及我的验证服务,我不知道问题出在哪里。
所以我查看了一个论坛,发现我必须使用doctrine缓存,但我不知道如何正确使用它 这是我的代码:
<?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();
有错误,这是错误:
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
这是我的文件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": "*"
}
}