我试图用这个package上,但我得到这个错误:调用一个成员函数听到()非对象
Call to a member function hears() on a non-object
这是我的代码:
$slackbot = new SlackBot();
$slackbot = SlackBot::initialize('xoxb');
// give the bot something to listen for.
$slackbot->hears('hello', function (SlackBot $bot, $message) {
$bot->reply('Hello yourself.');
});
我该如何解决这个问题?
编辑
这是我在文件:
routes.php文件
<?php
use SlackBot;
Route::post('/slack', function(\Illuminate\Http\Request $request)
{
$payload = $request->all();
if (isset($payload['type']) && isset($payload['challenge']))
{
if ($payload['type'] == 'url_verification')
{
return $payload['challenge'];
}
}
$slackbot = new SlackBot();
$slackbot = SlackBot::initialize('xoxb-xxx');
// give the bot something to listen for.
$slackbot->hears('hello', function (SlackBot $bot, $message) {
$bot->reply('Hello yourself.');
});
});
https://github.com/mpociot/slackbot#basic-usage – Farkie