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 ¶
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.
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 ¶
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.
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.