feat: add 'channel test' command for direct messaging channel verification

This commit is contained in:
DBT
2026-02-12 08:56:20 +00:00
parent 8f3340e1de
commit 1bd7e1370a
2 changed files with 91 additions and 0 deletions

View File

@@ -102,6 +102,8 @@ func main() {
cronCmd()
case "login":
loginCmd()
case "channel":
channelCmd()
case "skills":
if len(os.Args) < 3 {
skillsHelp()
@@ -171,6 +173,7 @@ func printHelp() {
fmt.Println(" status Show clawgo status")
fmt.Println(" cron Manage scheduled tasks")
fmt.Println(" login Configure CLIProxyAPI upstream")
fmt.Println(" channel Test and manage messaging channels")
fmt.Println(" skills Manage skills (install, list, remove)")
fmt.Println(" version Show version information")
}
@@ -1186,3 +1189,91 @@ func loginCmd() {
func configureProvider(cfg *config.Config, provider string) {
// Deprecated: Migrated to CLIProxyAPI logic in loginCmd
}
func channelCmd() {
if len(os.Args) < 3 {
channelHelp()
return
}
subcommand := os.Args[2]
switch subcommand {
case "test":
channelTestCmd()
default:
fmt.Printf("Unknown channel command: %s\n", subcommand)
channelHelp()
}
}
func channelHelp() {
fmt.Println("\nChannel commands:")
fmt.Println(" test Send a test message to a specific channel")
fmt.Println()
fmt.Println("Test options:")
fmt.Println(" --to Recipient ID")
fmt.Println(" --channel Channel name (telegram, discord, etc.)")
fmt.Println(" -m, --message Message to send")
}
func channelTestCmd() {
to := ""
channelName := ""
message := "This is a test message from ClawGo 🦞"
args := os.Args[3:]
for i := 0; i < len(args); i++ {
switch args[i] {
case "--to":
if i+1 < len(args) {
to = args[i+1]
i++
}
case "--channel":
if i+1 < len(args) {
channelName = args[i+1]
i++
}
case "-m", "--message":
if i+1 < len(args) {
message = args[i+1]
i++
}
}
}
if channelName == "" || to == "" {
fmt.Println("Error: --channel and --to are required")
return
}
cfg, err := loadConfig()
if err != nil {
fmt.Printf("Error loading config: %v\n", err)
os.Exit(1)
}
msgBus := bus.NewMessageBus()
mgr, err := channels.NewManager(cfg, msgBus)
if err != nil {
fmt.Printf("Error creating channel manager: %v\n", err)
os.Exit(1)
}
ctx := context.Background()
// Start the manager to initialize channels
if err := mgr.StartAll(ctx); err != nil {
fmt.Printf("Error starting channels: %v\n", err)
os.Exit(1)
}
fmt.Printf("Sending test message to %s (%s)...\n", channelName, to)
if err := mgr.SendToChannel(ctx, channelName, to, message); err != nil {
fmt.Printf("✗ Failed to send message: %v\n", err)
os.Exit(1)
}
fmt.Println("✓ Test message sent successfully!")
}