kkohoutek / cleverbot-laravel
Cleverbot.com API 的 Laravel 封装
v1.0.0
2022-04-24 16:57 UTC
Requires
- php: >=7.4.0
README
Cleverbot API 的 Laravel 封装。
https://www.cleverbot.com/api/
安装
composer require kkohoutek/cleverbot-laravel
php artisan vendor:publish --force
从列表中选择 KKohoutek\Cleverbot\CleverbotServiceProvider。然后在您的 .env 文件中,添加一行包含您的 Cleverbot API 密钥
CLEVERBOT_API_KEY="your-api-key"
用法
使用依赖注入来访问 Cleverbot 单例。使用 'query' 方法与 API 通信。
Route::get('/', function (Kkohoutek\Cleverbot\Cleverbot $cb) { $response = $cb->query('Hello Cleverbot!'); logger($response->output); // Keep passing ´cs´ to continue the same conversation $response = $cb->query('How are you doing?', $response->cs); logger($response->output); // ... Return ... });
// 嗨,Cleverbot!
[2022-04-23 18:20:15] local.DEBUG: 那不是我的名字。
// 你好吗?
[2022-04-23 18:20:16] local.DEBUG: 不告诉你。
有效的解析 JSON 响应看起来像这样(更多信息,请访问 https://www.cleverbot.com/api/howto/)
{ "cs":"76nxdxIJO2...AAA", "interaction_count":"1", "input":"", "output":"Good afternoon.", "conversation_id":"AYAR1E3ITW", ... }