Include unique id and timestamp with webhook events (#291)
Resolves #230
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/livekit/protocol/livekit"
|
"github.com/livekit/protocol/livekit"
|
||||||
"github.com/livekit/protocol/logger"
|
"github.com/livekit/protocol/logger"
|
||||||
|
"github.com/livekit/protocol/utils"
|
||||||
"github.com/livekit/protocol/webhook"
|
"github.com/livekit/protocol/webhook"
|
||||||
"google.golang.org/protobuf/types/known/timestamppb"
|
"google.golang.org/protobuf/types/known/timestamppb"
|
||||||
|
|
||||||
@@ -201,6 +202,9 @@ func (t *telemetryService) notifyEvent(ctx context.Context, event *livekit.Webho
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event.CreatedAt = time.Now().Unix()
|
||||||
|
event.Id = utils.NewGuid("EV_")
|
||||||
|
|
||||||
t.webhookPool.Submit(func() {
|
t.webhookPool.Submit(func() {
|
||||||
if err := t.notifier.Notify(ctx, event); err != nil {
|
if err := t.notifier.Notify(ctx, event); err != nil {
|
||||||
logger.Warnw("failed to notify webhook", err, "event", event.Event)
|
logger.Warnw("failed to notify webhook", err, "event", event.Event)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/livekit/protocol/auth"
|
"github.com/livekit/protocol/auth"
|
||||||
"github.com/livekit/protocol/livekit"
|
"github.com/livekit/protocol/livekit"
|
||||||
@@ -42,6 +43,9 @@ func TestWebhooks(t *testing.T) {
|
|||||||
// first participant join should have started the room
|
// first participant join should have started the room
|
||||||
started := ts.GetEvent(webhook.EventRoomStarted)
|
started := ts.GetEvent(webhook.EventRoomStarted)
|
||||||
require.Equal(t, testRoom, started.Room.Name)
|
require.Equal(t, testRoom, started.Room.Name)
|
||||||
|
require.NotEmpty(t, started.Id)
|
||||||
|
require.Greater(t, started.CreatedAt, time.Now().Unix()-100)
|
||||||
|
require.GreaterOrEqual(t, time.Now().Unix(), started.CreatedAt)
|
||||||
joined := ts.GetEvent(webhook.EventParticipantJoined)
|
joined := ts.GetEvent(webhook.EventParticipantJoined)
|
||||||
require.Equal(t, "c1", joined.Participant.Identity)
|
require.Equal(t, "c1", joined.Participant.Identity)
|
||||||
ts.ClearEvents()
|
ts.ClearEvents()
|
||||||
|
|||||||
Reference in New Issue
Block a user