我試圖用這個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