feat: Implement core voicebot functionality with TeamSpeak 3 and xAI integration.
This commit is contained in:
@@ -129,6 +129,35 @@ func (c *Client) SendAudio(pcm []int16) error {
|
||||
return c.sendJSON(msg)
|
||||
}
|
||||
|
||||
// SendText sends a text message to trigger a Grok response
|
||||
func (c *Client) SendText(text string) error {
|
||||
// Create conversation item with text
|
||||
createMsg := ConversationItemCreate{
|
||||
Type: "conversation.item.create",
|
||||
Item: ConversationItem{
|
||||
Type: "message",
|
||||
Role: "user",
|
||||
Content: []ItemContent{
|
||||
{Type: "input_text", Text: text},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if err := c.sendJSON(createMsg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Request response
|
||||
responseMsg := ResponseCreate{
|
||||
Type: "response.create",
|
||||
Response: ResponseSettings{
|
||||
Modalities: []string{"text", "audio"},
|
||||
},
|
||||
}
|
||||
|
||||
return c.sendJSON(responseMsg)
|
||||
}
|
||||
|
||||
// Close closes the WebSocket connection
|
||||
func (c *Client) Close() {
|
||||
c.mu.Lock()
|
||||
@@ -179,6 +208,13 @@ func (c *Client) receiveLoop() {
|
||||
|
||||
_, message, err := c.conn.ReadMessage()
|
||||
if err != nil {
|
||||
// Check if closed intentionally
|
||||
select {
|
||||
case <-c.done:
|
||||
return
|
||||
default:
|
||||
}
|
||||
|
||||
if websocket.IsCloseError(err, websocket.CloseNormalClosure) {
|
||||
log.Println("[xAI] Connection closed normally")
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user