fix(telegram): update Send parameters to properly proxy OutboundMessage to SendMessageWithID

This commit is contained in:
Dmitrii Balabanov 2026-03-07 23:27:22 +02:00
parent 0b65f7d31c
commit eeabdd098f
2 changed files with 32 additions and 32 deletions

View file

@ -164,29 +164,29 @@ func (c *TelegramChannel) Stop(ctx context.Context) error {
}
func (c *TelegramChannel) Send(ctx context.Context, msg bus.OutboundMessage) error {
_, err := c.SendMessageWithID(ctx, msg.ChatID, msg.Content)
_, err := c.SendMessageWithID(ctx, msg)
return err
}
// SendMessageWithID implements an optional interface for AgentLoop to send a message synchronously and get the MessageID.
func (c *TelegramChannel) SendMessageWithID(ctx context.Context, chatID string, content string) (string, error) {
func (c *TelegramChannel) SendMessageWithID(ctx context.Context, msg bus.OutboundMessage) (string, error) {
if !c.IsRunning() {
return "", channels.ErrNotRunning
}
cid, err := parseChatID(chatID)
cid, err := parseChatID(msg.ChatID)
if err != nil {
return "", fmt.Errorf("invalid chat ID %s: %w", chatID, channels.ErrSendFailed)
return "", fmt.Errorf("invalid chat ID %s: %w", msg.ChatID, channels.ErrSendFailed)
}
if content == "" {
if msg.Content == "" {
return "", nil
}
// The Manager already splits messages to ≤4000 chars (WithMaxMessageLength),
// so msg.Content is guaranteed to be within that limit. We still need to
// check if HTML expansion pushes it beyond Telegram's 4096-char API limit.
queue := []string{content}
queue := []string{msg.Content}
var lastMsgID int
for len(queue) > 0 {

View file

@ -106,7 +106,7 @@ func TestSendMessageWithID_EmptyContent(t *testing.T) {
}
ch := newTestChannel(t, caller)
msgID, err := ch.SendMessageWithID(context.Background(), "12345", "")
msgID, err := ch.SendMessageWithID(context.Background(), bus.OutboundMessage{ChatID: "12345", Content: ""})
assert.NoError(t, err)
assert.Empty(t, msgID)
@ -121,7 +121,7 @@ func TestSendMessageWithID_ShortMessage_SingleCall(t *testing.T) {
}
ch := newTestChannel(t, caller)
msgID, err := ch.SendMessageWithID(context.Background(), "12345", "Hello, world!")
msgID, err := ch.SendMessageWithID(context.Background(), bus.OutboundMessage{ChatID: "12345", Content: "Hello, world!"})
assert.NoError(t, err)
assert.Equal(t, "1", msgID)
@ -138,7 +138,7 @@ func TestSendMessageWithID_LongMessage_SingleCall(t *testing.T) {
longContent := strings.Repeat("a", 4000)
msgID, err := ch.SendMessageWithID(context.Background(), "12345", longContent)
msgID, err := ch.SendMessageWithID(context.Background(), bus.OutboundMessage{ChatID: "12345", Content: longContent})
assert.NoError(t, err)
assert.Equal(t, "1", msgID)
@ -158,7 +158,7 @@ func TestSendMessageWithID_HTMLFallback_PerChunk(t *testing.T) {
}
ch := newTestChannel(t, caller)
msgID, err := ch.SendMessageWithID(context.Background(), "12345", "Hello **world**")
msgID, err := ch.SendMessageWithID(context.Background(), bus.OutboundMessage{ChatID: "12345", Content: "Hello **world**"})
assert.NoError(t, err)
assert.Equal(t, "1", msgID)
@ -173,7 +173,7 @@ func TestSendMessageWithID_HTMLFallback_BothFail(t *testing.T) {
}
ch := newTestChannel(t, caller)
msgID, err := ch.SendMessageWithID(context.Background(), "12345", "Hello")
msgID, err := ch.SendMessageWithID(context.Background(), bus.OutboundMessage{ChatID: "12345", Content: "Hello"})
assert.Error(t, err)
assert.Empty(t, msgID)
@ -191,7 +191,7 @@ func TestSendMessageWithID_LongMessage_HTMLFallback_StopsOnError(t *testing.T) {
longContent := strings.Repeat("x", 4001)
msgID, err := ch.SendMessageWithID(context.Background(), "12345", longContent)
msgID, err := ch.SendMessageWithID(context.Background(), bus.OutboundMessage{ChatID: "12345", Content: longContent})
assert.Error(t, err)
assert.Empty(t, msgID)
@ -209,7 +209,7 @@ func TestSendMessageWithID_MarkdownShortButHTMLLong_MultipleCalls(t *testing.T)
markdownContent := strings.Repeat("**a** ", 600)
assert.LessOrEqual(t, len([]rune(markdownContent)), 4000)
msgID, err := ch.SendMessageWithID(context.Background(), "12345", markdownContent)
msgID, err := ch.SendMessageWithID(context.Background(), bus.OutboundMessage{ChatID: "12345", Content: markdownContent})
assert.NoError(t, err)
assert.Equal(t, "1", msgID)
@ -226,7 +226,7 @@ func TestSendMessageWithID_NotRunning(t *testing.T) {
ch := newTestChannel(t, caller)
ch.SetRunning(false)
msgID, err := ch.SendMessageWithID(context.Background(), "12345", "Hello")
msgID, err := ch.SendMessageWithID(context.Background(), bus.OutboundMessage{ChatID: "12345", Content: "Hello"})
assert.ErrorIs(t, err, channels.ErrNotRunning)
assert.Empty(t, msgID)
@ -242,7 +242,7 @@ func TestSendMessageWithID_InvalidChatID(t *testing.T) {
}
ch := newTestChannel(t, caller)
msgID, err := ch.SendMessageWithID(context.Background(), "not-a-number", "Hello")
msgID, err := ch.SendMessageWithID(context.Background(), bus.OutboundMessage{ChatID: "not-a-number", Content: "Hello"})
assert.Error(t, err)
assert.Empty(t, msgID)