-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathbetawebhook_test.go
More file actions
40 lines (36 loc) · 1.34 KB
/
betawebhook_test.go
File metadata and controls
40 lines (36 loc) · 1.34 KB
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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package anthropic_test
import (
"net/http"
"strconv"
"testing"
"time"
"github.com/anthropics/anthropic-sdk-go"
"github.com/anthropics/anthropic-sdk-go/option"
standardwebhooks "github.com/standard-webhooks/standard-webhooks/libraries/go"
)
func TestBetaWebhookUnwrap(t *testing.T) {
client := anthropic.NewClient(
option.WithWebhookKey("whsec_c2VjcmV0Cg=="),
option.WithAPIKey("my-anthropic-api-key"),
)
payload := []byte(`{"id":"wevt_011CZkZYZd9rLmz3ujAcsqEw","created_at":"2026-03-15T10:00:00Z","data":{"id":"sesn_011CZkZAtmR3yMPDzynEDxu7","organization_id":"org_011CZkZZAe0sMna4vkBdtrfx","type":"session.status_idled","workspace_id":"wrkspc_011CZkZaBF1tNoB5wlCeusgy"},"type":"event"}`)
wh, err := standardwebhooks.NewWebhook("whsec_c2VjcmV0Cg==")
if err != nil {
t.Fatal("Failed to sign test webhook message", err)
}
msgID := "1"
now := time.Now()
sig, err := wh.Sign(msgID, now, payload)
if err != nil {
t.Fatal("Failed to sign test webhook message:", err)
}
headers := make(http.Header)
headers.Set("webhook-signature", sig)
headers.Set("webhook-id", msgID)
headers.Set("webhook-timestamp", strconv.FormatInt(now.Unix(), 10))
_, err = client.Beta.Webhooks.Unwrap(payload, headers)
if err != nil {
t.Fatal("Failed to unwrap webhook:", err)
}
}