farmstar-survey-backend/internal/worker/telegram.go
2024-02-05 16:05:28 +03:00

40 lines
653 B
Go

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
}