diff --git a/internal/chat/telegram/telegram.go b/internal/chat/telegram/telegram.go index 71ab677..072f907 100644 --- a/internal/chat/telegram/telegram.go +++ b/internal/chat/telegram/telegram.go @@ -14,6 +14,7 @@ import ( "log" "net/http" "strconv" + "strings" "time" "github.com/kamelion/ratatoskr-go/internal/chat" @@ -71,8 +72,12 @@ func (ch *Channel) Run(ctx context.Context) error { } } +// tgPrefix — префикс адреса чата в ratatoskr (см. handleUpdate). +// В Bot API chat_id передаётся без него. +const tgPrefix = "tg://" + func (ch *Channel) Send(_ context.Context, to chat.Address, m chat.Message) error { - return ch.sendMsg(string(to), formatOutgoing(m)) + return ch.sendMsg(strings.TrimPrefix(string(to), tgPrefix), formatOutgoing(m)) } func (ch *Channel) Ask(_ context.Context, to chat.Address, m chat.Message) error { diff --git a/internal/chat/telegram/telegram_test.go b/internal/chat/telegram/telegram_test.go index 679637a..dd814e1 100644 --- a/internal/chat/telegram/telegram_test.go +++ b/internal/chat/telegram/telegram_test.go @@ -79,6 +79,9 @@ func TestSend(t *testing.T) { if len(f.sent) != 1 { t.Fatal("не отправлено") } + if f.sent[0].ChatID != "123" { + t.Errorf("chat_id = %q, want 123 (без префикса tg://)", f.sent[0].ChatID) + } if f.sent[0].Text != "hello" { t.Errorf("text = %q", f.sent[0].Text) }