OCaml client for the Slack Web API
OCaml 98.9%
Dune 0.3%
Other 0.8%
17 1 0

Clone this repository

https://tangled.org/gazagnaire.org/ocaml-slack https://tangled.org/did:plc:jhift2vwcxhou52p3sewcrpx/ocaml-slack
git@git.recoil.org:gazagnaire.org/ocaml-slack git@git.recoil.org:did:plc:jhift2vwcxhou52p3sewcrpx/ocaml-slack

For self-hosted knots, clone URLs may differ based on your setup.

Download tar.gz
README.md

slack#

OCaml client for the Slack Web API.

Typed bindings for the Slack Web API covering channels, messages, users, files, reactions, emoji, reminders, pins, stars, audit logs, and more. Uses requests for HTTP, jsont for JSON encoding/decoding, and Eio for concurrency. Includes a Mrkdwn parser for Slack's markup format and bidirectional Markdown/mrkdwn conversion.

The package also provides a slack command-line tool for interacting with Slack workspaces from the terminal: list channels, browse history with threaded replies, send and delete messages, list users, and join channels.

Installation#

opam install slack

Usage#

Library#

Eio_main.run @@ fun env ->
Eio.Switch.run @@ fun sw ->
let api = Slack.Api.v ~sw env (Sys.getenv "SLACK_TOKEN") in

(* Send a message *)
let _ts = Slack.Api.send_message ~channel:"C01EXAMPLE" ~text:"Hello!" api in

(* List channels *)
let _channels = Slack.Api.list_channels api in

(* Fetch history *)
let _messages = Slack.Api.history ~channel:"C01EXAMPLE" ~limit:10 api in
()

CLI#

export SLACK_TOKEN=xoxb-...
slack channels
slack history '#general' -n 20
slack send -c '#general' -m 'Hello from the CLI'
slack users
slack info '#general'
slack join '#random'

The send command accepts --format markdown (default) to convert CommonMark input to Slack mrkdwn, or --format mrkdwn to send raw Slack markup.

API#

  • Slack.Api -- API client: create with a token, then call typed methods for chat, conversations, users, files, reactions, emoji, reminders, pins, stars, audit logs, and admin operations.
  • Slack.Channel -- Channel type with id, name, private/archived status, and JSON codec.
  • Slack.Message -- Message type with timestamp, text, user, thread info, file attachments, and JSON codec.
  • Slack.User -- User type with id, name, real name, bot flag, and JSON codec.
  • Slack.Mrkdwn -- Parser for Slack's mrkdwn markup into a block/inline AST.
  • Slack.Markdown -- Bidirectional CommonMark/mrkdwn conversion.
  • Slack.History -- Terminal display formatting for message history with threaded replies.
  • Slack.Block, Slack.Attachment, Slack.File, Slack.Reaction, Slack.Reminder, Slack.Pin, Slack.Star, Slack.Emoji, Slack.Team, Slack.Audit -- Supporting types for the corresponding API resources.

References#