Files
agents_and_robots/tools/matrix.go
T
egutierrez 828eb175fe feat: renderizar Markdown a HTML en mensajes Matrix con goldmark
Se reemplaza SendText por SendMarkdown en todos los puntos donde el agente
envía respuestas: runtime.go (comandos built-in y tareas orquestadas),
effects/runner.go (acciones Reply) y tools/matrix.go (matrix_send tool).

shell/matrix/client.go ahora usa goldmark para convertir Markdown a HTML real
en el campo FormattedBody del evento Matrix, cumpliendo con la spec de Matrix
para mensajes formateados. El Body conserva el markdown raw como fallback.

Se añade dependencia github.com/yuin/goldmark v1.7.16.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 02:21:06 +00:00

41 lines
1.2 KiB
Go

package tools
import (
"context"
"fmt"
)
// MatrixSender is the interface for sending Matrix messages.
// Satisfied by shell/matrix.Client.
type MatrixSender interface {
SendText(ctx context.Context, roomID, text string) error
SendMarkdown(ctx context.Context, roomID, markdown string) error
}
// NewMatrixSend creates a matrix_send tool that sends a message to a Matrix room.
func NewMatrixSend(sender MatrixSender) Tool {
return Tool{
Def: Def{
Name: "matrix_send",
Description: "Send a text message to a Matrix room.",
Parameters: []Param{
{Name: "room_id", Type: "string", Description: "The Matrix room ID to send to", Required: true},
{Name: "message", Type: "string", Description: "The text message to send", Required: true},
},
},
Exec: func(ctx context.Context, args map[string]any) Result {
roomID := getString(args, "room_id")
message := getString(args, "message")
if roomID == "" || message == "" {
return Result{Err: fmt.Errorf("matrix_send: room_id and message are required")}
}
if err := sender.SendMarkdown(ctx, roomID, message); err != nil {
return Result{Err: fmt.Errorf("matrix_send: %w", err)}
}
return Result{Output: fmt.Sprintf("message sent to %s", roomID)}
},
}
}