From 59970efd41b3bddc4afe5d50c1f7b2b51e972fa5 Mon Sep 17 00:00:00 2001 From: linhaolin1 Date: Thu, 2 Apr 2026 23:29:46 +0800 Subject: [PATCH] feat(vk): add voice capabilities support - Implement VoiceCapabilities() method for VK channel - Add audio_message attachment handling in processAttachments - Add comprehensive tests for voice capabilities - Support both ASR (speech-to-text) and TTS (text-to-speech) --- pkg/channels/vk/vk.go | 6 ++++++ pkg/channels/vk/vk_test.go | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/pkg/channels/vk/vk.go b/pkg/channels/vk/vk.go index 0bc373d18..92fbcf4ad 100644 --- a/pkg/channels/vk/vk.go +++ b/pkg/channels/vk/vk.go @@ -271,6 +271,8 @@ func (c *VKChannel) processAttachments(attachments []object.MessagesMessageAttac } else { parts = append(parts, "[document]") } + case "audio_message": + parts = append(parts, "[voice]") case "sticker": parts = append(parts, "[sticker]") } @@ -278,3 +280,7 @@ func (c *VKChannel) processAttachments(attachments []object.MessagesMessageAttac return strings.Join(parts, " ") } + +func (c *VKChannel) VoiceCapabilities() channels.VoiceCapabilities { + return channels.VoiceCapabilities{ASR: true, TTS: true} +} diff --git a/pkg/channels/vk/vk_test.go b/pkg/channels/vk/vk_test.go index e4fdc1ac3..c7e62ab31 100644 --- a/pkg/channels/vk/vk_test.go +++ b/pkg/channels/vk/vk_test.go @@ -202,6 +202,11 @@ func TestVKChannel_ProcessAttachments(t *testing.T) { attachments: []string{"sticker"}, want: "[sticker]", }, + { + name: "audio_message attachment", + attachments: []string{"audio_message"}, + want: "[voice]", + }, { name: "multiple attachments", attachments: []string{"photo", "video", "audio"}, @@ -216,7 +221,11 @@ func TestVKChannel_ProcessAttachments(t *testing.T) { if i > 0 { result += " " } - result += "[" + att + "]" + if att == "audio_message" { + result += "[voice]" + } else { + result += "[" + att + "]" + } } if result != tt.want { t.Errorf("processAttachments() = %q, want %q", result, tt.want) @@ -224,3 +233,28 @@ func TestVKChannel_ProcessAttachments(t *testing.T) { }) } } + +func TestVKChannel_VoiceCapabilities(t *testing.T) { + msgBus := bus.NewMessageBus() + cfg := &config.Config{ + Channels: config.ChannelsConfig{ + VK: config.VKConfig{ + Enabled: true, + Token: *config.NewSecureString("test_token"), + GroupID: 123456789, + }, + }, + } + ch, err := NewVKChannel(cfg, msgBus) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + + caps := ch.VoiceCapabilities() + if !caps.ASR { + t.Error("VoiceCapabilities().ASR should be true") + } + if !caps.TTS { + t.Error("VoiceCapabilities().TTS should be true") + } +}