[英]Botman laravel REST API setup
Im new to Botman.我是 Botman 的新手。
I try to implement a simple function to test how it works, but I keep getting empty response, it look like botman do not hears my message.我尝试实现一个简单的 function 来测试它是如何工作的,但我一直得到空响应,看起来 botman 没有听到我的消息。
I installed botman without studio since, I'm trying to keep things simple.我在没有工作室的情况下安装了 botman,因为我试图让事情变得简单。 I also installed a webdriver as it says in documentation.正如文档中所说,我还安装了一个 webdriver。
In my project I use JWT as an authentification, so i created a protected route like this:在我的项目中,我使用 JWT 作为身份验证,所以我创建了一个这样的受保护路由:
Route::group(['middleware' => ['assign.guard:user', 'jwt.auth']], function () {
Route::post(
'/',
'UserBotManController@startConversation'
)->name('botman.user.start');
});
The controller looks like this: controller 看起来像这样:
<?php
namespace Project\UI\Api\Controllers\User\Botman;
use App\Http\Controllers\Controller;
use BotMan\BotMan\BotMan;
use BotMan\BotMan\BotManFactory;
use BotMan\BotMan\Drivers\DriverManager;
class UserBotManController extends Controller
{
public function startConversation()
{
$config = [];
DriverManager::loadDriver(\BotMan\Drivers\Web\WebDriver::class);
$botman = BotManFactory::create($config);
$botman->hears('hello', function (BotMan $bot) {
$bot->reply('Hello yourself.');
});
$botman->listen();
}
}
No when I send a request to this route a get empty response:不,当我向此路由发送请求时,得到空响应:
Looks like botman can't hear my message...看来botman听不到我的消息了...
I try to looked inside with: dd($botman->getDriver());
我尝试用以下方法查看内部: dd($botman->getDriver());
And I see that the content has all the data:我看到内容包含所有数据:
Can any one help me to understand, how I can make it work?任何人都可以帮助我理解,我怎样才能使它工作?
Ok, so finally I found a solution.好的,所以最后我找到了解决方案。 I have checked what request it sends from https://botman.io website and it is Form Data, not JSON.我检查了它从https://botman.io网站发送的请求,它是表单数据,而不是 JSON。
diver
field must be set to web
! diver
字段必须设置为web
!
Hope it will help someone.希望它会帮助某人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.