Skip to content

Commit

Permalink
Merge pull request #311 from hinoguma/feature/add-webhook-redelivery
Browse files Browse the repository at this point in the history
add webhook redelivery
  • Loading branch information
kkdai authored Apr 29, 2022
2 parents f1daf67 + 79aa593 commit 23b8e0c
Show file tree
Hide file tree
Showing 4 changed files with 300 additions and 7 deletions.
13 changes: 13 additions & 0 deletions linebot/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ const (
StickerResourceTypeNameText StickerResourceType = "CUSTOM"
)

// DeliveryContext type
type DeliveryContext struct {
IsRedelivery bool `json:"isRedelivery"`
}

// Event type
type Event struct {
ReplyToken string
Expand All @@ -206,6 +211,8 @@ type Event struct {
Members []*EventSource
Unsend *Unsend
VideoPlayComplete *VideoPlayComplete
WebhookEventID string
DeliveryContext DeliveryContext
}

type rawEvent struct {
Expand All @@ -223,6 +230,8 @@ type rawEvent struct {
Things *rawThingsEvent `json:"things,omitempty"`
Unsend *Unsend `json:"unsend,omitempty"`
VideoPlayComplete *VideoPlayComplete `json:"videoPlayComplete,omitempty"`
WebhookEventID string `json:"webhookEventId"`
DeliveryContext DeliveryContext `json:"deliveryContext"`
}

type rawMemberEvent struct {
Expand Down Expand Up @@ -299,6 +308,8 @@ func (e *Event) MarshalJSON() ([]byte, error) {
Postback: e.Postback,
Unsend: e.Unsend,
VideoPlayComplete: e.VideoPlayComplete,
WebhookEventID: e.WebhookEventID,
DeliveryContext: e.DeliveryContext,
}
if e.Beacon != nil {
raw.Beacon = &rawBeaconEvent{
Expand Down Expand Up @@ -423,6 +434,8 @@ func (e *Event) UnmarshalJSON(body []byte) (err error) {
e.Mode = rawEvent.Mode
e.Timestamp = time.Unix(rawEvent.Timestamp/milliSecPerSec, (rawEvent.Timestamp%milliSecPerSec)*nanoSecPerMilliSec).UTC()
e.Source = rawEvent.Source
e.WebhookEventID = rawEvent.WebhookEventID
e.DeliveryContext = rawEvent.DeliveryContext

switch rawEvent.Type {
case EventTypeMessage:
Expand Down
8 changes: 4 additions & 4 deletions linebot/get_ids_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,11 @@ func TestGetGroupMemberIDsScanner(t *testing.T) {
}

testCases := []struct {
FirstResponse *MemberIDsResponse
FirstResponse *MemberIDsResponse
SecondResponse *MemberIDsResponse
}{
{
FirstResponse: res1,
FirstResponse: res1,
SecondResponse: res2,
},
{
Expand Down Expand Up @@ -497,11 +497,11 @@ func TestGetRoomMemberIDsScanner(t *testing.T) {
}

testCases := []struct {
FirstResponse *MemberIDsResponse
FirstResponse *MemberIDsResponse
SecondResponse *MemberIDsResponse
}{
{
FirstResponse: res1,
FirstResponse: res1,
SecondResponse: res2,
},
{
Expand Down
6 changes: 3 additions & 3 deletions linebot/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (client *Client) NewRawCall(method string, endpoint string) (*RawCall, erro
return nil, err
}
return &RawCall{
c: client,
c: client,
req: req,
}, nil
}
Expand All @@ -39,7 +39,7 @@ func (client *Client) NewRawCallWithBody(method string, endpoint string, body io
return nil, err
}
return &RawCall{
c: client,
c: client,
req: req,
}, nil
}
Expand All @@ -49,7 +49,7 @@ type RawCall struct {
c *Client
ctx context.Context

req *http.Request
req *http.Request
}

// AddHeader method
Expand Down
Loading

0 comments on commit 23b8e0c

Please sign in to comment.