-
Notifications
You must be signed in to change notification settings - Fork 0
/
webhooks.go
58 lines (44 loc) · 1.21 KB
/
webhooks.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package gometawebhooks
import (
"context"
"errors"
"fmt"
)
var (
ErrApplyingOption = errors.New("error applying option")
)
// Webhooks instance contains all methods needed to process object events
type Webhooks struct {
token string
secret string
headerSigName string
instagramMessageHandler InstagramMessageHandler
instagramPostbackHandler InstagramPostbackHandler
instagramReferralHandler InstagramReferralHandler
instagramMentionHandler InstagramMentionHandler
instagramStoryInsightsHandler InstagramStoryInsightsHandler
ignoreEchoMessages bool
}
type WebhooksHandler interface {
Handle(context.Context, Event) error
}
var _ WebhooksHandler = (*Webhooks)(nil)
// Creates and returns a webhooks instance
func New(options ...Option) (*Webhooks, error) {
hooks := &Webhooks{}
for _, opt := range options {
if err := opt(hooks); err != nil {
return nil, wrapErr(err, ErrApplyingOption)
}
}
if hooks.headerSigName == "" {
hooks.headerSigName = HeaderSignatureName
}
return hooks, nil
}
func wrapErr(err, target error) error {
return fmt.Errorf("%w: %w", err, target)
}
// func unixTime(timeMs int64) time.Time {
// return time.Unix(0, timeMs*int64(time.Millisecond))
// }