Skip to content

feat(onebot): enhance OneBot channel#192

Open
alexhoshina wants to merge 4 commits intosipeed:mainfrom
alexhoshina:feat/onebot-enhancements
Open

feat(onebot): enhance OneBot channel#192
alexhoshina wants to merge 4 commits intosipeed:mainfrom
alexhoshina:feat/onebot-enhancements

Conversation

@alexhoshina
Copy link
Contributor

概述

实现了对 OneBot 频道的全面增强,添加了富媒体支持、API 回调机制和语音转文字功能。

主要功能

媒体和富内容支持

  • 支持图片、视频、音频、文件等消息段类型
  • 支持消息回复,带有适当的消息 ID 跟踪

API 回调系统

  • 实现异步 API 请求/响应模式,使用 echo 进行关联
  • 添加 sendAPIRequest() 用于可靠的命令执行和超时支持
  • 使用基于 channel 的等待模式跟踪待处理 API 响应
  • 频道关闭时正确清理待处理请求

连接可靠性

  • 添加 WebSocket ping/pong 心跳机制(30 秒间隔)
  • 正确的读取截止时间处理(60 秒超时)
  • 在连接和重新连接时自动获取机器人 self ID
  • 改进的连接状态验证

语音转文字功能

  • 集成 Groq 语音转文字支持

消息处理改进

  • 将 parseMessageContentEx 重构为支持上下文的 parseMessageSegments
  • 支持回复检测和跟踪

代码质量

  • 使用原子操作实现计数器和 self ID 的线程安全访问
  • 使用 sync.Map 进行消息 ID 跟踪
  • 改进的错误处理和日志记录
  • 使用 strings.HasPrefix 简化字符串前缀检查
  • 消息处理后的临时文件正确清理

Bug 修复

  • 修复 BotStatus 解析以处理字符串和对象状态响应
  • 使用 isAPIResponse() 区分 API 响应和常规事件
  • 改进的连接错误处理和状态验证

Overview

Implemented comprehensive enhancements to the OneBot channel, adding rich media support, an API callback mechanism, and voice transcription capabilities.

Key Features

Media and Rich Content Support

  • Supports message segment types including images, videos, audio, and files
  • Supports message replies with proper message ID tracking

API Callback System

  • Implements an asynchronous API request/response pattern using echo for correlation
  • Adds sendAPIRequest() for reliable command execution with timeout support
  • Uses a channel-based waiting mechanism to track pending API responses
  • Properly cleans up pending requests when the channel is stopped

Connection Reliability

  • Adds WebSocket ping/pong keepalive mechanism (30-second interval)
  • Proper read deadline handling (60-second timeout)
  • Automatically fetches the bot’s self ID on connect and reconnect
  • Improved connection state validation

Voice Transcription Capability

  • Integrates Groq-powered voice transcription support

Message Handling Improvements

  • Refactors parseMessageContentEx into context-aware parseMessageSegments
  • Supports reply detection and tracking

Code Quality

  • Uses atomic operations for thread-safe access to counters and self ID
  • Employs sync.Map for message ID tracking
  • Enhanced error handling and logging
  • Simplifies string prefix checks using strings.HasPrefix
  • Ensures proper cleanup of temporary files after message processing

Bug Fixes

  • Fixes BotStatus parsing to handle both string and object-form status responses
  • Uses isAPIResponse() to distinguish API responses from regular events
  • Improves connection error handling and status validation

…cription

   Comprehensive improvements to the OneBot channel for better NapCatQQ
   compatibility:

   - Add echo-based API callback mechanism (sendAPIRequest) for
     request/response correlation via pending map
   - Add WebSocket ping/pong keepalive (30s ping, 60s read deadline)
   - Fetch bot self ID via get_login_info on connect/reconnect
   - Refactor parseMessageContentEx into parseMessageSegments supporting
     image, record, video, file, reply, face, forward segments
   - Add voice transcription via Groq transcriber (SetTranscriber)
   - Switch to message segment array format for sending with auto reply
     quote via lastMessageID tracking
   - Add message_sent event handling and detailed notice event processing
     (recall, poke, group increase/decrease, friend add, etc.)
   - Use sync/atomic for echoCounter, optimize listen() lock pattern
   - Clean up pending callbacks on Stop(), defer temp file cleanup
   - Mount Groq transcriber on OneBot channel in main.go gateway
@alexhoshina alexhoshina marked this pull request as ready for review February 15, 2026 06:23
- Currently, the agent does not respond to messages sent by users outside the allowlist.
@Leeaandrob
Copy link
Collaborator

@Zepan Enhanced OneBot channel implementation (+501/-206). OneBot was recently merged (#165) — this PR improves on that initial implementation.

Recommendation: Review and merge. Follow-up improvements to a recently-merged channel are expected and welcome. The Chinese user community likely relies on QQ/OneBot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants