farmstar-survey-backend/internal/worker/telegram.go

40 lines
653 B
Go
Raw Normal View History

2024-02-05 14:05:28 +01:00
package worker
import (
"context"
"github.com/grassrootseconomics/farmstar-survey-backend/pkg/telegram"
"github.com/riverqueue/river"
)
type TgMessage string
type (
TelegramArgs struct {
Msg string `json:"msg"`
}
TelegramWorker struct {
river.WorkerDefaults[TelegramArgs]
TgClient *telegram.TelegramClient
ChatID string
}
)
func (TelegramArgs) Kind() string {
return "telegram"
}
func (w *TelegramWorker) Work(ctx context.Context, job *river.Job[TelegramArgs]) error {
_, err := w.TgClient.SendMessage(ctx, telegram.MessageInput{
ChatID: w.ChatID,
Text: job.Args.Msg,
})
if err != nil {
return err
}
return nil
}