Add logging to Matrix channel and update refactor
Co-authored-by: hobbyistlabs-coder <267281733+hobbyistlabs-coder@users.noreply.github.com>
This commit is contained in:
parent
e31ba85fae
commit
2af558cebd
2 changed files with 28 additions and 0 deletions
|
|
@ -136,6 +136,13 @@ func (c *MatrixChannel) handleMessageEvent(ctx context.Context, evt *event.Event
|
|||
"is_group": fmt.Sprintf("%t", isGroup),
|
||||
"sender_raw": senderID,
|
||||
}
|
||||
|
||||
logger.DebugCF("matrix", "Received message", map[string]any{
|
||||
"sender_id": senderID,
|
||||
"room_id": roomID,
|
||||
"is_group": isGroup,
|
||||
})
|
||||
|
||||
if replyTo := msgEvt.GetRelatesTo().GetReplyTo(); replyTo != "" {
|
||||
metadata["reply_to_msg_id"] = replyTo.String()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import (
|
|||
|
||||
"jane/pkg/bus"
|
||||
"jane/pkg/channels"
|
||||
"jane/pkg/logger"
|
||||
)
|
||||
|
||||
func markdownToHTML(md string) string {
|
||||
|
|
@ -38,8 +39,16 @@ func (c *MatrixChannel) Send(ctx context.Context, msg bus.OutboundMessage) error
|
|||
|
||||
_, err := c.client.SendMessageEvent(ctx, roomID, event.EventMessage, c.messageContent(content))
|
||||
if err != nil {
|
||||
logger.ErrorCF("matrix", "Failed to send message", map[string]any{
|
||||
"room_id": roomID.String(),
|
||||
"error": err.Error(),
|
||||
})
|
||||
return fmt.Errorf("matrix send: %w", channels.ErrTemporary)
|
||||
}
|
||||
|
||||
logger.DebugCF("matrix", "Sent message", map[string]any{
|
||||
"room_id": roomID.String(),
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -93,5 +102,17 @@ func (c *MatrixChannel) EditMessage(ctx context.Context, chatID string, messageI
|
|||
editContent.SetEdit(id.EventID(messageID))
|
||||
|
||||
_, err := c.client.SendMessageEvent(ctx, roomID, event.EventMessage, editContent)
|
||||
if err != nil {
|
||||
logger.ErrorCF("matrix", "Failed to edit message", map[string]any{
|
||||
"room_id": roomID.String(),
|
||||
"message_id": messageID,
|
||||
"error": err.Error(),
|
||||
})
|
||||
} else {
|
||||
logger.DebugCF("matrix", "Edited message", map[string]any{
|
||||
"room_id": roomID.String(),
|
||||
"message_id": messageID,
|
||||
})
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue