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)
This commit is contained in:
linhaolin1 2026-04-02 23:29:46 +08:00
parent f0fdcf19ac
commit 59970efd41
2 changed files with 41 additions and 1 deletions

View file

@ -271,6 +271,8 @@ func (c *VKChannel) processAttachments(attachments []object.MessagesMessageAttac
} else { } else {
parts = append(parts, "[document]") parts = append(parts, "[document]")
} }
case "audio_message":
parts = append(parts, "[voice]")
case "sticker": case "sticker":
parts = append(parts, "[sticker]") parts = append(parts, "[sticker]")
} }
@ -278,3 +280,7 @@ func (c *VKChannel) processAttachments(attachments []object.MessagesMessageAttac
return strings.Join(parts, " ") return strings.Join(parts, " ")
} }
func (c *VKChannel) VoiceCapabilities() channels.VoiceCapabilities {
return channels.VoiceCapabilities{ASR: true, TTS: true}
}

View file

@ -202,6 +202,11 @@ func TestVKChannel_ProcessAttachments(t *testing.T) {
attachments: []string{"sticker"}, attachments: []string{"sticker"},
want: "[sticker]", want: "[sticker]",
}, },
{
name: "audio_message attachment",
attachments: []string{"audio_message"},
want: "[voice]",
},
{ {
name: "multiple attachments", name: "multiple attachments",
attachments: []string{"photo", "video", "audio"}, attachments: []string{"photo", "video", "audio"},
@ -216,11 +221,40 @@ func TestVKChannel_ProcessAttachments(t *testing.T) {
if i > 0 { if i > 0 {
result += " " result += " "
} }
if att == "audio_message" {
result += "[voice]"
} else {
result += "[" + att + "]" result += "[" + att + "]"
} }
}
if result != tt.want { if result != tt.want {
t.Errorf("processAttachments() = %q, want %q", result, tt.want) t.Errorf("processAttachments() = %q, want %q", result, tt.want)
} }
}) })
} }
} }
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")
}
}