Library
Module
Module type
Parameter
Class
Class type
An OCaml binding to the REST API of Slack. Each function triggers an HTTP request, so it returns immediately and returns an Lwt.t
value.
To use the API you first need to either apply for a token
from Slack, or get one via the OAuth2 API. This string can then be converted into a session
by means of start_session
. With this session
most other methods from the binding can be called. The result of each API call is a variant type containing either the JSON result or an error type describing what kind of error occured.
The binding exposes a number of errors that can happen. As not every function returns every possible API error, the possible errors are grouped into more convenient sets of errors that can be composed together to get the exact error types.
API calls that take timestamp
arguments can signal errors when the timestamp is invalid. The binding does its best to make sure that invalid timestamps are avoided.
API calls that require channel
inputs can signal this error if the channel does not exist.
API calls that require user
inputs signal this error if the user was not found.
Inviting might fail because invitation is impossible for some reason or because attempting to invite oneself.
Some API calls require the user
not to be in channel
for the action to suceed. The opposite of not_in_channel_error
.
Channels might be archived, so modification attempts will fail with this error.
When creating channels, names have to be unique, an attempt to create a duplicate one will result in this error.
Kick (in general) might fail, because kicking oneself is not supported.
Kicking users from channels might fail, because channels have additional restrictions on kicking: users can't be kicked from the #general channel and they cannot be kicked from the last channel they are in.
If an action was attempted that the user does not have permission to, this error is returned.
Leaving the #general channel is not supported by Slack, an attempt do do so will trigger this error.
The message
might not exist or be impossible to delete for other reasons.
When posting a message with attachments, you may receive this error if you post too many. The Slack API documentation states that attempting to post a message with more than 100 attachments will fail with this error, but also that no message should ever have more than 20 attachments. Slacko doesn't check the number of attachments sent.
Doing too many API requests in a certain timespan might cause a rate limitation to be applied by Slack. This is the error that results in that case.
Updating a message
might fail because the message was not found, couldn't be updated for some reason or because the time in which a message can be edited has passed.
Handling files can result in multiple problems: the file wasn't found in the first place or it might have been deleted in the maintime.
This error shouldn't ever be returned but serves as a catch-all in case the Slack API returns a new, unknown error type that Slacko doesn't yet understand.
When trying to archive something that was already archived before, this error is returned.
Doing an action in a group
when not being part of the group can fail.
An error when the user is the last member and can't do what he planned to do because that would cause the channel
not to have members anymore.
These errors might be returned when the exchange of oauth authorization for a token has failed.
Setting an invalid presence information is not supported.
User is not visible, so action cannot be performed on them.
API calls which require authentication will always return (at least) these error types.
type topic_result = [
| `Success of string
| parsed_auth_error
| channel_error
| archive_error
| not_in_channel_error
| `User_is_restricted
]
Setting topics or purposes will result either in a success or one of these errors. Convenience type composed of subtypes.
In Slack, timestamps are represented as float, same as in OCaml, so the timestamp
type is following suit, so all timestamp-related functions can be used.
The topic type represents a topic or a purpose message. Both are limited deliberately to have at most 250 UTF-8 encoded codepoints.
A place one can post messages to.
Search result can be ordered in ascending or descending order.
type user_obj = {
id : user;
name : string;
deleted : bool;
color : string;
real_name : string;
tz : string option;
tz_label : string;
tz_offset : int;
profile : Yojson.Safe.json;
is_admin : bool;
is_owner : bool;
is_primary_owner : bool;
is_restricted : bool;
is_ultra_restricted : bool;
is_bot : bool;
has_files : bool;
}
Object representing lots of information about a Slack user.
type group_obj = {
id : group;
name : string;
is_group : bool;
created : timestamp;
creator : user;
is_archived : bool;
members : user list;
topic : topic_obj;
purpose : topic_obj;
is_open : bool option;
last_read : timestamp option;
unread_count : int option;
unread_count_display : int option;
latest : Yojson.Safe.json option;
}
Object representing information about a Slack group.
type channel_obj = {
id : channel;
name : string;
is_channel : bool;
created : timestamp;
creator : user;
is_archived : bool;
is_general : bool;
is_member : bool;
members : user list;
topic : topic_obj;
purpose : topic_obj;
last_read : timestamp option;
latest : Yojson.Safe.json option;
unread_count : int option;
unread_count_display : int option;
num_members : int option;
}
Object representing information about a Slack channel.
Object representing a message attachment field.
type attachment_obj = {
fallback : string option;
color : string option;
pretext : string option;
title : string option;
title_link : string option;
text : string option;
fields : field_obj list option;
image_url : string option;
thumb_url : string option;
ts : timestamp option;
mrkdwn_in : string list option;
}
Object representing a message attachment.
type message_obj = {
type' : string;
ts : timestamp;
user : user option;
bot_id : bot option;
text : string option;
is_starred : bool option;
}
Object representing a message. Can be of a number of types.
Authentication information from the current user.
Response to renaming of a channel.
Response to a channel invite.
Response to opening a group.
Response to rename of a group
type im_obj = {
id : string;
is_im : bool;
user : user;
created : timestamp;
is_user_deleted : bool;
unread_count : int option;
unread_count_display : int option;
}
Information about a direct conversation with a person.
Information about an direct conversation channel.
When requesting an OAuth token, you get a token and the scope for which this token is valid.
Represents a comment on an item.
Paging information for requests that might have multi page results.
type file_obj = {
id : string;
created : timestamp;
timestamp : timestamp;
name : string option;
title : string;
mimetype : string;
pretty_type : string;
user : user;
mode : string;
editable : bool;
is_external : bool;
external_type : string;
size : int;
url_private : string;
url_private_download : string;
thumb_64 : string option;
thunb_80 : string option;
thumb_360 : string option;
thumb_360_gif : string option;
thumb_360_w : int option;
thumb_360_h : int option;
permalink : string;
edit_link : string option;
preview : string option;
preview_highlight : string option;
lines : int option;
lines_more : int option;
is_public : bool;
channels : channel list;
groups : group list;
ims : conversation list;
initial_comment : Yojson.Safe.json option;
num_stars : int option;
}
Information about a file.
Metainformation about a file.
A list of files.
Information about starred items.
type search_obj = {
query : string;
messages : message_search_obj option;
files : file_search_obj option;
}
type team_obj = {
id : string;
name : string;
domain : string;
email_domain : string;
icon : Yojson.Safe.json;
}
type history_result = [
| `Success of history_obj
| parsed_auth_error
| channel_error
| timestamp_error
]
Return value of a history related request.
To build the types required in the API calls, you can use these helper functions.
val start_session : ?base_url:string -> string -> session
Create a session from a token string and an optional base_url.
val token_of_string : string -> session
Deprecated wrapper for backcompat.
val field : ?title:string -> ?short:bool -> string -> field_obj
val attachment :
?fallback:string ->
?color:string ->
?pretext:string ->
?author_name:string ->
?author_link:string ->
?author_icon:string ->
?title:string ->
?title_link:string ->
?text:string ->
?fields:field_obj list ->
?image_url:string ->
?thumb_url:string ->
?footer:string ->
?footer_icon:string ->
?ts:timestamp ->
?mrkdwn_in:string list ->
unit ->
attachment_obj
val message_of_string : string -> message
Build a message from a string.
val topic_of_string : string -> topic option
Build a topic out of a string. topic
types are also used to set purposes. Also validates the length of the topic, since Slack has a 250 UTF-8 codepoint length limit on purposes and topics.
val topic_of_string_exn : string -> topic
Same as topic_of_string
but throws an exception if it fails to convert the text data into a topic
.
val group_of_string : string -> group
Construct a group out of a given string. This can be either a group id, starting with capital 'G' character which is the preferred way or it can be a group name for convenience. In the latter case, each API call with requires a group will perform an additional request to determine the group id from the name.
val user_of_string : string -> user
Constructs a user out of a given string. The string can either be an user id starting with a capital 'U' which is the preferred way or it can be a simple user name in which case every API call will look up the user name to an id in an additional request.
val bot_of_string : string -> bot
val channel_of_string : string -> channel
Constructs a channel out of a given string. Can either be a channel id starting with a capital 'C' which is the preferred way or a channel name starting with a '#'. If a channel name was provided, each consecutive API call using it will first need to resolve the channel name into a channel id by means of an additional request.
val conversation_of_string : string -> conversation
Create a conversation type out of a given string. The string is usually starting with a capital 'D' and represents an IM conversation channel.
val api_test :
?base_url:string ->
?foo:string ->
?error:string ->
unit ->
[ `Success of Yojson.Safe.json | api_error ] Lwt.t
Checks API calling code.
val auth_test : session -> [ `Success of authed_obj | parsed_auth_error ] Lwt.t
Checks authentication & identity.
val channels_archive :
session ->
channel ->
[ `Success
| parsed_auth_error
| channel_error
| already_archived_error
| `Cant_archive_general
| `Last_restricted_channel
| restriction_error
| `User_is_restricted
| bot_error ]
Lwt.t
Archives a channel.
val channels_create :
session ->
string ->
[ `Success of channel_obj
| parsed_auth_error
| name_error
| `User_is_restricted
| bot_error ]
Lwt.t
Creates a channel.
val channels_history :
session ->
?latest:timestamp ->
?oldest:timestamp ->
?count:int ->
?inclusive:bool ->
channel ->
history_result Lwt.t
Fetches history of messages and events from a channel.
val channels_info :
session ->
channel ->
[ `Success of channel_obj | parsed_auth_error | channel_error ] Lwt.t
Gets information about a channel.
val channels_invite :
session ->
channel ->
user ->
[ `Success of channel_obj
| parsed_auth_error
| channel_error
| user_error
| invite_error
| not_in_channel_error
| already_in_channel_error
| archive_error
| `User_is_ultra_restricted
| bot_error ]
Lwt.t
Invites a user to a channel.
val channels_join :
session ->
channel ->
[ `Success of channel_obj
| parsed_auth_error
| channel_error
| name_error
| archive_error
| `User_is_restricted
| bot_error ]
Lwt.t
Joins a channel, creating it if needed.
val channels_kick :
session ->
channel ->
user ->
[ `Success
| parsed_auth_error
| channel_error
| user_error
| channel_kick_error
| not_in_channel_error
| restriction_error
| `User_is_restricted
| bot_error ]
Lwt.t
Removes a user from a channel.
val channels_leave :
session ->
channel ->
[ `Success of channel_leave_obj
| parsed_auth_error
| channel_error
| archive_error
| leave_general_error
| `User_is_restricted
| bot_error ]
Lwt.t
Leaves a channel.
val channels_list :
?exclude_archived:bool ->
session ->
[ `Success of channel_obj list | parsed_auth_error ] Lwt.t
Lists all channels in a Slack team.
val channels_mark :
session ->
channel ->
timestamp ->
[ `Success
| parsed_auth_error
| channel_error
| archive_error
| not_in_channel_error ]
Lwt.t
Sets the read cursor in a channel.
val channels_rename :
session ->
channel ->
string ->
[ `Success of channel_rename_obj
| parsed_auth_error
| channel_error
| not_in_channel_error
| name_error
| invalid_name_error
| `Not_authorized
| `User_is_restricted
| bot_error ]
Lwt.t
Renames a team channel.
val channels_set_purpose : session -> channel -> topic -> topic_result Lwt.t
Sets the purpose for a channel.
val channels_set_topic : session -> channel -> topic -> topic_result Lwt.t
Sets the topic for a channel.
val channels_unarchive :
session ->
channel ->
[ `Success
| parsed_auth_error
| channel_error
| `Not_archived
| `User_is_restricted
| bot_error ]
Lwt.t
Unarchives a channel.
val chat_delete :
session ->
timestamp ->
chat ->
[ `Success of chat_obj | parsed_auth_error | channel_error | message_error ]
Lwt.t
Deletes a message.
val chat_post_message :
session ->
chat ->
?as_user:bool ->
?link_names:bool ->
?mrkdwn:bool ->
?reply_broadcast:bool ->
?thread_ts:timestamp ->
?unfurl_links:bool ->
?unfurl_media:bool ->
?username:string ->
?parse:string ->
?icon_url:string ->
?icon_emoji:string ->
?attachments:attachment_obj list ->
message ->
[ `Success of chat_obj
| parsed_auth_error
| channel_error
| archive_error
| message_length_error
| attachments_error
| rate_error
| bot_error ]
Lwt.t
Sends a message to a channel.
val chat_update :
session ->
timestamp ->
chat ->
?as_user:bool ->
?attachments:attachment_obj list ->
?link_names:bool ->
?parse:string ->
message ->
[ `Success of chat_obj
| parsed_auth_error
| channel_error
| message_update_error
| message_length_error
| attachments_error ]
Lwt.t
Updates a message.
val emoji_list :
session ->
[ `Success of emoji list | parsed_auth_error ] Lwt.t
Lists custom emoji for a team.
val files_delete :
session ->
string ->
[ `Success | parsed_auth_error | `Cant_delete_file | file_error | bot_error ]
Lwt.t
val files_info :
session ->
?count:int ->
?page:int ->
string ->
[ `Success of files_info_obj | parsed_auth_error | file_error | bot_error ]
Lwt.t
Gets information about a team file.
val files_list :
?user:user ->
?ts_from:timestamp ->
?ts_to:timestamp ->
?types:string ->
?count:int ->
?page:int ->
session ->
[ `Success of files_list_obj
| parsed_auth_error
| user_error
| unknown_type_error
| bot_error ]
Lwt.t
Lists & filters team files.
val files_upload :
session ->
?filetype:string ->
?filename:string ->
?title:string ->
?initial_comment:string ->
?channels:string ->
Cohttp_lwt.Body.t ->
[ `Success of file_obj | parsed_auth_error | bot_error ] Lwt.t
Uploads or creates a file.
val groups_archive :
session ->
group ->
[ `Success
| parsed_auth_error
| channel_error
| already_archived_error
| `Group_contains_others
| `Last_restricted_channel
| restriction_error
| `User_is_ultra_restricted
| bot_error ]
Lwt.t
Archives a private group.
val groups_close :
session ->
group ->
[ `Success of chat_close_obj | parsed_auth_error | channel_error ] Lwt.t
Closes a private group.
val groups_create :
session ->
group ->
[ `Success of group_obj
| parsed_auth_error
| name_error
| restriction_error
| `User_is_ultra_restricted
| bot_error ]
Lwt.t
Creates a private group.
val groups_create_child :
session ->
group ->
[ `Success of group_obj
| parsed_auth_error
| channel_error
| already_archived_error
| restriction_error
| `User_is_ultra_restricted
| bot_error ]
Lwt.t
Clones and archives a private group.
val groups_history :
session ->
?latest:timestamp ->
?oldest:timestamp ->
?count:int ->
?inclusive:bool ->
group ->
history_result Lwt.t
Fetches history of messages and events from a private group.
val groups_invite :
session ->
group ->
user ->
[ `Success of groups_invite_obj
| parsed_auth_error
| channel_error
| user_error
| invite_error
| archive_error
| `User_is_ultra_restricted
| bot_error ]
Lwt.t
Invites a user to a private group.
val groups_kick :
session ->
group ->
user ->
[ `Success
| parsed_auth_error
| channel_error
| user_error
| kick_error
| not_in_group_error
| restriction_error
| `User_is_restricted
| bot_error ]
Lwt.t
Removes a user from a private group.
val groups_leave :
session ->
group ->
[ `Success
| parsed_auth_error
| channel_error
| archive_error
| leave_last_channel_error
| last_member_error
| `User_is_ultra_restricted
| bot_error ]
Lwt.t
Leaves a private group.
val groups_list :
?exclude_archived:bool ->
session ->
[ `Success of group_obj list | parsed_auth_error ] Lwt.t
Lists private groups that the calling user has access to.
val groups_mark :
session ->
group ->
timestamp ->
[ `Success
| parsed_auth_error
| channel_error
| archive_error
| not_in_channel_error ]
Lwt.t
Sets the read cursor in a private group.
val groups_open :
session ->
group ->
[ `Success of groups_open_obj | parsed_auth_error | channel_error ] Lwt.t
Opens a private group.
val groups_rename :
session ->
group ->
string ->
[ `Success of groups_rename_obj
| parsed_auth_error
| channel_error
| name_error
| invalid_name_error
| `User_is_restricted
| bot_error ]
Lwt.t
Renames a private group.
val groups_set_purpose : session -> group -> topic -> topic_result Lwt.t
Sets the purpose for a private group.
val groups_set_topic : session -> group -> topic -> topic_result Lwt.t
Sets the topic for a private group.
val groups_unarchive :
session ->
group ->
[ `Success
| parsed_auth_error
| channel_error
| `Not_archived
| `User_is_restricted
| bot_error ]
Lwt.t
Unarchives a private group.
val im_close :
session ->
conversation ->
[ `Success of chat_close_obj
| parsed_auth_error
| channel_error
| `User_does_not_own_channel ]
Lwt.t
Close a direct message channel.
val im_history :
session ->
?latest:timestamp ->
?oldest:timestamp ->
?count:int ->
?inclusive:bool ->
conversation ->
history_result Lwt.t
Fetches history of messages and events from direct message channel.
val im_list : session -> [ `Success of im_obj list | parsed_auth_error ] Lwt.t
Lists direct message channels for the calling user.
val im_mark :
session ->
conversation ->
timestamp ->
[ `Success | parsed_auth_error | channel_error | not_in_channel_error ] Lwt.t
Sets the read cursor in a direct message channel.
val im_open :
session ->
user ->
[ `Success of im_open_obj
| parsed_auth_error
| user_error
| user_visibility_error ]
Lwt.t
Opens a direct message channel.
val oauth_access :
?base_url:string ->
string ->
string ->
?redirect_url:string ->
string ->
[ `Success of oauth_obj | `ParseFailure of string | oauth_error ] Lwt.t
Exchanges a temporary OAuth code for an API session.
val search_all :
session ->
?sort:sort_criterion ->
?sort_dir:sort_direction ->
?highlight:bool ->
?count:int ->
?page:int ->
string ->
[ `Success of search_obj | parsed_auth_error | bot_error ] Lwt.t
Searches for messages and files matching a query.
val search_files :
session ->
?sort:sort_criterion ->
?sort_dir:sort_direction ->
?highlight:bool ->
?count:int ->
?page:int ->
string ->
[ `Success of search_obj | parsed_auth_error | bot_error ] Lwt.t
Searches for files matching a query.
val search_messages :
session ->
?sort:sort_criterion ->
?sort_dir:sort_direction ->
?highlight:bool ->
?count:int ->
?page:int ->
string ->
[ `Success of search_obj | parsed_auth_error | bot_error ] Lwt.t
Searches for messages matching a query.
val stars_list :
?user:user ->
?count:int ->
?page:int ->
session ->
[ `Success of stars_list_obj | parsed_auth_error | user_error | bot_error ]
Lwt.t
Lists stars for a user.
val team_access_logs :
?count:int ->
?page:int ->
session ->
[ `Success of team_access_log_obj
| parsed_auth_error
| `Paid_only
| bot_error ]
Lwt.t
Gets the access logs for the current team.
val team_info :
session ->
[ `Success of team_obj | parsed_auth_error | bot_error ] Lwt.t
Gets information about the current team.
val users_get_presence :
session ->
user ->
[ `Success of presence | user_error | parsed_auth_error ] Lwt.t
Gets user presence information.
val users_info :
session ->
user ->
[ `Success of user_obj
| parsed_auth_error
| user_error
| user_visibility_error ]
Lwt.t
Gets information about a user.
val users_list :
session ->
[ `Success of user_obj list | parsed_auth_error ] Lwt.t
Lists all users in a Slack team.
val users_set_active :
session ->
[ `Success | parsed_auth_error | bot_error ] Lwt.t
Marks a user as active.
val users_set_presence :
session ->
presence ->
[ `Success | parsed_auth_error | presence_error ] Lwt.t
Manually sets user presence.