mirror of
https://github.com/grassrootseconomics/farmstar-survey-backend.git
synced 2024-11-05 18:36:47 +01:00
40 lines
653 B
Go
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
|
|
}
|