X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/d8f3785bb69288663f4cc46bf4d609c6770452d5..f4509310b5abe5012cb83bed3960404e8fa92217:/telegram.go diff --git a/telegram.go b/telegram.go index e3e33c9..78a1c7a 100644 --- a/telegram.go +++ b/telegram.go @@ -264,7 +264,7 @@ func (b *TelegramBot) send(ctx context.Context) { func (b *TelegramBot) poll(ctx context.Context, l *TurnLoop, whatsapp *WhatsApp) error { offset, err := telegramLoadOffset(b.offsetPath) if err != nil { - return err + return fmt.Errorf("load Telegram offset: %w", err) } outage := &TelegramOutage{ @@ -313,7 +313,7 @@ poll: continue poll } - return err + return fmt.Errorf("handle Telegram update: %w", err) } imageOutage.End() @@ -323,7 +323,7 @@ poll: offset = update.UpdateID + 1 err = telegramSaveOffset(b.offsetPath, offset) if err != nil { - return err + return fmt.Errorf("save Telegram offset: %w", err) } } } @@ -349,7 +349,8 @@ func (b *TelegramBot) next() (Event, bool) { // typing shows the typing action once. A failure is not logged, because the // next message or poll logs the state of the network. func (b *TelegramBot) typing(ctx context.Context) { - _ = b.api.SendTyping(ctx, b.owner) + // The next message or poll reports a network failure. + b.api.SendTyping(ctx, b.owner) // nolint: errcheck } // post sends event to the chat. A reply goes as rich messages of its Markdown, @@ -475,7 +476,7 @@ func (b *TelegramBot) handle(ctx context.Context, l *TurnLoop, whatsapp *WhatsAp default: _, err := l.Submit(telegramSource, message.Text) if err != nil { - return err + return fmt.Errorf("submit Telegram text: %w", err) } err = l.Flush(context.WithoutCancel(ctx)) @@ -584,13 +585,13 @@ func (b *TelegramBot) sendOutage() *TelegramOutage { } // Notify queues event for the chat. It never blocks, so a slow network does not -// stop the agent. The WhatsApp batches and the runs of the schedules do not go -// to the chat: the reply of the agent tells the user what needs the user. +// stop the agent. External events, WhatsApp batches, and schedule runs do not +// go to the chat: the reply of the agent tells the user what needs the user. func (b *TelegramBot) Notify(event Event) { switch event.Kind { case "busy", "idle", "reply", "error", "notice", "subagent": case "work": - if event.Source == whatsappSource || event.Source == scheduleSource { + if event.Source == whatsappSource || event.Source == scheduleSource || event.Source == notifySource { return } case "user":