mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-11 18:42:54 +00:00
perf: 机器人支持新会话
This commit is contained in:
parent
0b86fa7bee
commit
4cec0a7350
@ -3304,7 +3304,6 @@ class DialogController extends AbstractController
|
|||||||
//
|
//
|
||||||
$session = WebSocketDialogSession::create([
|
$session = WebSocketDialogSession::create([
|
||||||
'dialog_id' => $dialog->id,
|
'dialog_id' => $dialog->id,
|
||||||
'title' => '',
|
|
||||||
]);
|
]);
|
||||||
$session->save();
|
$session->save();
|
||||||
$dialog->session_id = $session->id;
|
$dialog->session_id = $session->id;
|
||||||
|
|||||||
@ -475,7 +475,6 @@ class UserBot extends AbstractModel
|
|||||||
if ($sessionSupported) {
|
if ($sessionSupported) {
|
||||||
$dialogSession = WebSocketDialogSession::create([
|
$dialogSession = WebSocketDialogSession::create([
|
||||||
'dialog_id' => $dialog->id,
|
'dialog_id' => $dialog->id,
|
||||||
'title' => 'Default',
|
|
||||||
]);
|
]);
|
||||||
$dialogSession->save();
|
$dialogSession->save();
|
||||||
$dialog->session_id = $dialogSession->id;
|
$dialog->session_id = $dialogSession->id;
|
||||||
|
|||||||
@ -868,7 +868,6 @@ class WebSocketDialog extends AbstractModel
|
|||||||
if ($user->isAiBot() || User::find($receiver)?->isAiBot()) {
|
if ($user->isAiBot() || User::find($receiver)?->isAiBot()) {
|
||||||
$session = WebSocketDialogSession::create([
|
$session = WebSocketDialogSession::create([
|
||||||
'dialog_id' => $dialog->id,
|
'dialog_id' => $dialog->id,
|
||||||
'title' => '',
|
|
||||||
]);
|
]);
|
||||||
$session->save();
|
$session->save();
|
||||||
$dialog->session_id = $session->id;
|
$dialog->session_id = $session->id;
|
||||||
|
|||||||
@ -656,7 +656,7 @@ class WebSocketDialogMsg extends AbstractModel
|
|||||||
* @param bool $preserveHtml 保留html格式
|
* @param bool $preserveHtml 保留html格式
|
||||||
* @return string|string[]|null
|
* @return string|string[]|null
|
||||||
*/
|
*/
|
||||||
private static function previewTextMsg($msgData, $preserveHtml = false)
|
public static function previewTextMsg($msgData, $preserveHtml = false)
|
||||||
{
|
{
|
||||||
$text = $msgData['text'] ?? '';
|
$text = $msgData['text'] ?? '';
|
||||||
if (!$text) return '';
|
if (!$text) return '';
|
||||||
|
|||||||
@ -66,15 +66,14 @@ class WebSocketDialogSession extends AbstractModel
|
|||||||
if ($dialogMsg->type != 'text') {
|
if ($dialogMsg->type != 'text') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if ($dialogMsg->msg['text'] === '...') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
$cacheKey = 'dialog_session_title_' . $sessionId;
|
$cacheKey = 'dialog_session_title_' . $sessionId;
|
||||||
if (Cache::has($cacheKey)) {
|
if (Cache::has($cacheKey)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$originalTitle = $dialogMsg->key ?: $dialogMsg->msg['text'] ?: 'Untitled';
|
$title = $dialogMsg->key ?: WebSocketDialogMsg::previewTextMsg($dialogMsg->msg) ?: 'Untitled';
|
||||||
$title = Base::cutStr($originalTitle, 100);
|
|
||||||
if ($title == '...') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$session = self::whereId($sessionId)->first();
|
$session = self::whereId($sessionId)->first();
|
||||||
if (!$session) {
|
if (!$session) {
|
||||||
return;
|
return;
|
||||||
@ -82,6 +81,6 @@ class WebSocketDialogSession extends AbstractModel
|
|||||||
$session->title = $title;
|
$session->title = $title;
|
||||||
$session->save();
|
$session->save();
|
||||||
Cache::forever($cacheKey, true);
|
Cache::forever($cacheKey, true);
|
||||||
Task::deliver(new UpdateSessionTitleViaAiTask($session->id, $originalTitle));
|
Task::deliver(new UpdateSessionTitleViaAiTask($session->id, $dialogMsg->msg['text']));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user