err = errors.Join(err, tokens.Close())
}()
+ whatsappSetDeviceProps()
whatsapp, err := openWhatsApp(ctx, dir, time.Now, log.New(out, "whatsapp: ", log.LstdFlags), whatsappNewClient)
if err != nil {
return err
err = errors.Join(err, memory.Close())
}()
+ schedules, err := openSchedules(filepath.Join(agent.dir, scheduleFileName), time.Now)
+ if err != nil {
+ return err
+ }
+
subagents := newSubagents(filepath.Join(agent.dir, subagentDirName), time.Now, subagentNameRandom)
defer func() {
err = errors.Join(err, subagents.Close())
}
return daemonServe(ctx, listener, telegram, whatsapp, func(notify func(Event)) (*TurnLoop, error) {
- return newTurnLoop(agent, memory, subagents, client, time.Now, notify)
+ return newTurnLoop(agent, memory, subagents, whatsapp, schedules, client, time.Now, notify)
})
}
// daemonServe runs the loop that start makes and serves the clients of listener
// until ctx ends or the loop fails. It closes listener. It runs whatsapp, which
-// logs its notes in the loop and tells all clients its notices. When bot is not nil, it runs the bot too, and a failure of the bot
-// stops the agent.
+// logs its batches and notes in the loop and tells all clients its notices, and
+// a failure of whatsapp stops the agent. When bot is not nil, it runs the bot
+// too, and a failure of the bot stops the agent.
func daemonServe(ctx context.Context, listener net.Listener, bot *TelegramBot, whatsapp *WhatsApp, start func(notify func(Event)) (*TurnLoop, error)) error {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
hub.Accept(ctx, listener, l)
}()
+ var whatsappErr error
go func() {
defer workers.Done()
- whatsapp.Run(ctx, l, notify)
+ whatsappErr = whatsapp.Run(ctx, l, notify)
+ cancel()
}()
var botErr error
hub.CloseAll()
workers.Wait()
- return errors.Join(err, botErr)
+ return errors.Join(err, whatsappErr, botErr)
}
// daemonRunRequest runs one request of a client. The answers of a WhatsApp