-
Notifications
You must be signed in to change notification settings - Fork 28
/
message_whatsapp.go
42 lines (34 loc) · 956 Bytes
/
message_whatsapp.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
39
40
41
42
package messaging
import (
"github.com/authgear/authgear-server/pkg/api/event/nonblocking"
"github.com/authgear/authgear-server/pkg/lib/infra/task"
"github.com/authgear/authgear-server/pkg/lib/infra/whatsapp"
)
type WhatsappMessage struct {
message
taskQueue task.Queue
events EventService
Type nonblocking.MessageType
Options whatsapp.SendTemplateOptions
IsNotCounted bool
}
type WhatsappSender interface {
SendTemplate(opts *whatsapp.SendTemplateOptions) error
}
func (m *WhatsappMessage) Send(sender WhatsappSender) error {
err := m.events.DispatchEventImmediately(&nonblocking.WhatsappSentEventPayload{
Recipient: m.Options.To,
Type: m.Type,
IsNotCountedInUsage: m.IsNotCounted,
})
if err != nil {
return err
}
// We call whatsapp api immediately to know if there is any error
err = sender.SendTemplate(&m.Options)
if err != nil {
return err
}
m.isSent = true
return nil
}