48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
// Backfill an existing elder using the same provisioner as POST /subjects.
|
|||
|
|
package main
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"flag"
|
||
|
|
"fmt"
|
||
|
|
"os"
|
||
|
|
|
||
|
|
"data-terminal-cloud/internal/config"
|
||
|
|
"data-terminal-cloud/internal/database"
|
||
|
|
"data-terminal-cloud/internal/elderagent"
|
||
|
|
)
|
||
|
|
|
||
|
|
func main() {
|
||
|
|
subject := flag.String("subject", "", "existing elder public ID")
|
||
|
|
flag.Parse()
|
||
|
|
if *subject == "" {
|
||
|
|
fmt.Fprintln(os.Stderr, "--subject is required")
|
||
|
|
os.Exit(2)
|
||
|
|
}
|
||
|
|
cfg, err := config.Load("api")
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
ctx := context.Background()
|
||
|
|
p, err := database.Open(ctx, cfg.DatabaseURL, "elder-agent")
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
defer p.Close()
|
||
|
|
path := os.Getenv("DIRECT_CHAT_TEMPLATE_FILE")
|
||
|
|
if path == "" {
|
||
|
|
path = cfg.VolcVoiceChatTemplate
|
||
|
|
}
|
||
|
|
template, err := os.ReadFile(path)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
s := elderagent.Service{Pool: p, Provider: elderagent.NewClient(cfg.VolcAccessKeyID, cfg.VolcSecretAccessKey, cfg.VolcSessionToken, cfg.VolcRTCBaseURL, cfg.VolcRTCRegion).ForProduct(cfg.VolcHardwareInstanceID, cfg.VolcHardwareProductKey), Template: template, CallbackURL: cfg.SubtitleCallbackURL, CallbackSecret: []byte(cfg.SubtitleCallbackSecret)}
|
||
|
|
info, err := s.Ensure(ctx, *subject)
|
||
|
|
if err != nil {
|
||
|
|
fmt.Fprintln(os.Stderr, err)
|
||
|
|
os.Exit(1)
|
||
|
|
}
|
||
|
|
fmt.Printf("subject=%s bot_id=%s status=%s\n", *subject, info.BotID, info.Status)
|
||
|
|
}
|