github.com/anthropics/anthropic-sdk-go@v1.70.1/betawebhook_test.go (about) 1 // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 2 3 package anthropic_test 4 5 import ( 6 "net/http" 7 "strconv" 8 "testing" 9 "time" 10 11 "github.com/anthropics/anthropic-sdk-go" 12 "github.com/anthropics/anthropic-sdk-go/option" 13 standardwebhooks "github.com/standard-webhooks/standard-webhooks/libraries/go" 14 ) 15 16 func TestBetaWebhookUnwrap(t *testing.T) { 17 client := anthropic.NewClient( 18 option.WithWebhookKey("whsec_c2VjcmV0Cg=="), 19 option.WithAPIKey("my-anthropic-api-key"), 20 ) 21 payload := []byte(`{"id":"whe_0f1e2d3c4b5a69788796a5b4c3d2e1f0","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"}`) 22 wh, err := standardwebhooks.NewWebhook("whsec_c2VjcmV0Cg==") 23 if err != nil { 24 t.Fatal("Failed to sign test webhook message", err) 25 } 26 msgID := "1" 27 now := time.Now() 28 sig, err := wh.Sign(msgID, now, payload) 29 if err != nil { 30 t.Fatal("Failed to sign test webhook message:", err) 31 } 32 headers := make(http.Header) 33 headers.Set("webhook-signature", sig) 34 headers.Set("webhook-id", msgID) 35 headers.Set("webhook-timestamp", strconv.FormatInt(now.Unix(), 10)) 36 _, err = client.Beta.Webhooks.Unwrap(payload, headers) 37 if err != nil { 38 t.Fatal("Failed to unwrap webhook:", err) 39 } 40 }