Functions

request

fn (method: Str, url: Str): ::hot::http/HttpResponse
fn (method: Str, url: Str, additional-headers: Map): ::hot::http/HttpResponse
fn (method: Str, url: Str, additional-headers: Map, body: Any): ::hot::http/HttpResponse
fn (method: Str, url: Str, additional-headers: Map, body: Any, opts: Map): ::hot::http/HttpResponse
fn (method: Str, url: Str, additional-headers: Map, body: Any, api-key: Str): ::hot::http/HttpResponse

Make an authenticated HTTP request to the Slack API. Automatically adds the Bearer token from the slack.api.key context variable and sets Content-Type for JSON bodies. Additional headers can be provided to merge/override defaults. With no key from either place, the call returns an Err (see resolve).

Example

::api ::slack::api

// Simple GET request
response ::api/request("GET", "https://slack.com/api/auth.test")

// POST with JSON body
response ::api/request("POST", "https://slack.com/api/chat.postMessage", {}, {channel: "C1234", text: "Hello"})

url "https://slack.com/api/chat.postMessage"
body {channel: "C1234", text: "Hello"}
api-key ::hot::ctx/get("tenant-b.slack.api.key")

// With explicit API key override
response ::api/request("POST", url, {}, body, api-key)

// With per-call opts
response ::api/request("POST", url, {}, body, {api-key: api-key})
Context Vars: slack.api.key

resolve

fn (opts: Map): Map

The credential for one call: opts over the slack.api.key context variable (see resolve-from). Per-call credentials stay in the call; nothing is written to ctx, so parallel flows and tenants never share them. A credential from opts is masked in the run's call records.

Example

::slack::api/resolve({api-key: "tenant-b-credential"}).api-key  // "tenant-b-credential"
Context Vars: slack.api.key

resolve-from

fn (opts: Map, ctx-values: Map): Map

The one resolver, pure: the credential for a call from opts first, then ctx-values (a Map of context variables). Returns {api-key: ...}, or an Err when there is none.

A api-key key in opts always decides the call. If its value is null or blank that is an Err, never a fallback to context, so a tenant whose stored credential is missing can't silently run on the project's credential. Nothing is written to ctx. Exposed for testing; resolve feeds it the context.

Example

::slack::api/resolve-from({}, {"slack.api.key": "project-key"})  // {api-key: "project-key"}
::slack::api/resolve-from({api-key: "tenant-key"}, {"slack.api.key": "project-key"})  // {api-key: "tenant-key"}

// A blank key in opts never falls back to context
is-err(::slack::api/resolve-from({api-key: ""}, {"slack.api.key": "project-key"}))  // true

sanitize-url

fn (url: Str): Str

Remove legacy token query params and normalize URL separators. Strips any token= query parameters to ensure authentication is only sent via the Authorization header.

Example

::slack::api/sanitize-url("https://slack.com/api/users.list?token=abc&limit=5")  // "https://slack.com/api/users.list?limit=5"

::slack::api/sanitize-url("https://slack.com/api/auth.test?token=abc")  // "https://slack.com/api/auth.test"

Types

HttpError

HttpError type {
    status: Int,
    headers: Map,
    body: Any
}