slackline/fetch
Send Web API calls with gleam_fetch
on the JavaScript target.
let client = slackline.new(token)
auth.test_()
|> fetch.send(client)
|> promise.map(fn(result) { ... })
Values
pub fn fold_pages(
call: slackline.Call(m, a),
client: slackline.Client,
from initial: b,
with fold: fn(b, a) -> b,
metadata metadata: fn(a) -> option.Option(
slackline.ResponseMetadata,
),
) -> promise.Promise(Result(b, slackline.Error))
Sends a call and every following page, folding each response into an
accumulator. metadata finds a response’s response_metadata, which
holds the cursor of the next page. Stops at the first error.
pub fn retrying(
attempts attempts: Int,
run run: fn() -> promise.Promise(Result(a, slackline.Error)),
) -> promise.Promise(Result(a, slackline.Error))
Runs run again while Slack answers RateLimited, waiting the
retry_after seconds Slack asks for each time. Gives up after
attempts tries in total and returns the last result. Other errors
return at once.
use <- fetch.retrying(attempts: 3)
chat.post_message(channel:, text: "hi") |> fetch.send(client)
pub fn send(
call: slackline.Call(m, a),
client: slackline.Client,
) -> promise.Promise(Result(a, slackline.Error))
Sends a call and decodes its response.
pub fn upload(
upload_url: String,
contents: BitArray,
) -> promise.Promise(Result(Nil, slackline.Error))
Uploads file contents to an upload_url from
files.getUploadURLExternal.
pub fn upload_files(
client: slackline.Client,
uploads: List(slackline.FileUpload),
share share: fn(
slackline.Call(
files.CompleteUploadExternal,
files.CompleteUploadExternalResponse,
),
) -> slackline.Call(
files.CompleteUploadExternal,
files.CompleteUploadExternalResponse,
),
) -> promise.Promise(
Result(files.CompleteUploadExternalResponse, slackline.Error),
)
Uploads files and shares them in one message: the three steps of
files.getUploadURLExternal, upload and files.completeUploadExternal.
share adjusts the last call, for example to set the channel with
complete_upload_external.channel_id. Without a channel the files are
uploaded but not shared. Each file’s content_type is not sent; Slack
detects the type. Run the three steps yourself for alt_txt,
snippet_type, or to retry only the upload.
pub fn webhook(
url: String,
body: json.Json,
) -> promise.Promise(Result(Nil, slackline.Error))
Posts a message to an incoming webhook or response_url.