-
Notifications
You must be signed in to change notification settings - Fork 1
/
plugin.go
38 lines (32 loc) · 908 Bytes
/
plugin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package roomstart
import (
"context"
"encoding/json"
"github.com/go-telegram-bot-api/telegram-bot-api/v5"
"github.com/hibiken/asynq"
"github.com/rumorsflow/rumors/internal/consts"
"github.com/rumorsflow/rumors/internal/services/room"
"go.uber.org/zap"
)
const PluginName = consts.TaskRoomStart
type Plugin struct {
log *zap.Logger
service room.Service
}
func (p *Plugin) Init(log *zap.Logger, service room.Service) error {
p.log = log
p.service = service
return nil
}
// Name returns user-friendly plugin name
func (p *Plugin) Name() string {
return PluginName
}
func (p *Plugin) ProcessTask(ctx context.Context, task *asynq.Task) error {
var message tgbotapi.Message
if err := json.Unmarshal(task.Payload(), &message); err != nil {
p.log.Error("error due to unmarshal task payload", zap.Error(err))
return nil
}
return p.service.ChatMemberUpdated(ctx, *message.Chat, false)
}