fix: Chat via agentId statt sessionKey + reply aus details parsen
- SendChatMessageAsync: sessions_send nutzt agentId (nicht sessionKey) - Reply parsen aus result.details.reply (sessions_send Antwort-Struktur) - ChatRequest.Model: SessionKey → AgentId - Controller default: 'iris' → Agent-ID (nicht Session-Key)
This commit is contained in:
@@ -95,11 +95,11 @@ public class DashboardController(OpenClawGatewayClient gateway, ILogger<Dashboar
|
||||
|
||||
try
|
||||
{
|
||||
var sessionKey = string.IsNullOrWhiteSpace(request.SessionKey)
|
||||
var agentId = string.IsNullOrWhiteSpace(request.AgentId)
|
||||
? "iris"
|
||||
: request.SessionKey.Trim();
|
||||
: request.AgentId.Trim();
|
||||
|
||||
return await gateway.SendChatMessageAsync(sessionKey, request.Message.Trim());
|
||||
return await gateway.SendChatMessageAsync(agentId, request.Message.Trim());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -17,7 +17,7 @@ public sealed record MessageEntry(
|
||||
|
||||
public sealed record ChatRequest(
|
||||
string Message,
|
||||
string? SessionKey
|
||||
string? AgentId
|
||||
);
|
||||
|
||||
public sealed record ChatResponse(
|
||||
|
||||
@@ -173,18 +173,21 @@ public sealed class OpenClawGatewayClient(HttpClient httpClient, IConfiguration
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ChatResponse> SendChatMessageAsync(string sessionKey, string message)
|
||||
public async Task<ChatResponse> SendChatMessageAsync(string agentId, string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await InvokeToolAsync("sessions_send", new { sessionKey, message });
|
||||
var result = await InvokeToolAsync("sessions_send", new { agentId, message });
|
||||
if (result is null) return new ChatResponse(false, null, "Gateway nicht erreichbar");
|
||||
|
||||
var ok = result["ok"]?.GetValue<bool>() ?? false;
|
||||
var reply = result["reply"]?.GetValue<string>()
|
||||
// sessions_send reply is in details.reply or content[0].text
|
||||
var details = result["details"];
|
||||
var ok = (details?["status"]?.GetValue<string>() ?? result["status"]?.GetValue<string>()) == "ok";
|
||||
var reply = details?["reply"]?.GetValue<string>()
|
||||
?? result["reply"]?.GetValue<string>()
|
||||
?? result["response"]?.GetValue<string>()
|
||||
?? result["content"]?[0]?["text"]?.GetValue<string>();
|
||||
var error = result["error"]?.GetValue<string>();
|
||||
var error = details?["error"]?.GetValue<string>() ?? result["error"]?.GetValue<string>();
|
||||
|
||||
return new ChatResponse(ok, reply, error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user