fakewebhook

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package fakewebhook is the fake receiver of outgoing webhooks. It answers POST /hook/{name}, and any method on any path below /hook/{name}/, with 200 and an empty JSON object, and the harness records each request; below /chat/ it is a small chat API for the template mode (chat.go). The control endpoints under /_fake/ register the Signing secrets of a name, list what a name received, with the number of signatures that verify per the Standard Webhooks specification against the secrets registered at that moment, and show a chat.

Index

Constants

View Source
const ChatPrefix = "/chat/"

ChatPrefix starts the paths of the fake chat behind the receiver (C-01.FR-13), a small REST API for the recipes of the template mode of outgoing webhooks: one chat per {name}, whose messages take replies in one step, or in two steps through a thread created first.

POST /chat/{name}/messages                    posts a message: {"data":{"id":"m<N>"}}
PUT  /chat/{name}/messages/{id}               edits it: {"data":{"id":"<id>"}}; 404 for an unknown message
POST /chat/{name}/messages/{id}/replies       replies to it (one-step threads): {"data":{"id":"r<N>"}}
POST /chat/{name}/threads                     creates a thread: {"thread":{"id":"t<N>"}}
POST /chat/{name}/threads/{id}/messages       posts into it (two-step threads): {"data":{"id":"r<N>"}}

The text of each is the field text of its JSON body, the whole body as a string otherwise. GET /_fake/chat/{name} lists the messages with their replies, the edits and the threads with their messages; DELETE /_fake/chat/{name} empties the chat. The harness records the requests and applies its faults as for every path.

View Source
const (
	// HookPrefix starts the paths the fake receives on: /hook/{name} and below it.
	HookPrefix = "/hook/"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Chat

type Chat struct {
	Messages []*ChatMessage `json:"messages"`
	Edits    []ChatEntry    `json:"edits"`
	Threads  []*ChatThread  `json:"threads"`
	// contains filtered or unexported fields
}

Chat is the state of one chat as GET /_fake/chat/{name} lists it.

type ChatEntry

type ChatEntry struct {
	ID   string          `json:"id"`
	Text string          `json:"text"`
	Body json.RawMessage `json:"body"`
}

ChatEntry is a message, an edit, a reply or a message of a thread: its id, its text and the body it was sent with.

type ChatMessage

type ChatMessage struct {
	ChatEntry
	Replies []ChatEntry `json:"replies"`
}

ChatMessage is a message of the chat as posted, with its replies; its edits are listed apart.

type ChatThread

type ChatThread struct {
	ID       string          `json:"id"`
	Body     json.RawMessage `json:"body"`
	Messages []ChatEntry     `json:"messages"`
}

ChatThread is a thread created in two steps: the body it was created with and its messages.

type Fake

type Fake struct {
	*fakeserver.Server
	// contains filtered or unexported fields
}

Fake is the fake receiver of outgoing webhooks.

func New

func New() *Fake

New returns the fake with no Signing secrets.

func (*Fake) Chat

func (f *Fake) Chat(name string) Chat

Chat is the state of the fake chat name.

func (*Fake) Received

func (f *Fake) Received(name string) []Received

Received lists the requests to /hook/{name} and below it in arrival order, verifying their signatures with the Signing secrets registered for name now.

func (*Fake) SetSecrets

func (f *Fake) SetSecrets(name string, secrets []string) error

SetSecrets replaces the Signing secrets of name; each is whsec_ and a key in standard base64.

type Received

type Received struct {
	Method string `json:"method"`
	Path   string `json:"path"`
	Query  string `json:"query"`
	// Headers are keyed by the lower-case header name, with the values of a repeated header joined by ", ".
	Headers map[string]string `json:"headers"`
	// Body is the body parsed as JSON when it is valid JSON, and the body as a string otherwise.
	Body      any    `json:"body"`
	AtMs      int64  `json:"at_ms"`
	Status    int    `json:"status"`
	WebhookID string `json:"webhook_id"`
	// SignaturesValid is how many signatures of webhook-signature verify with one of the name's Signing secrets.
	SignaturesValid int `json:"signatures_valid"`
}

Received is a request to /hook/{name} or below it, as GET /_fake/received/{name} lists it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL