ExBot v0.1.1 ExBot.Slack

This module provides access to a few Slack Web API calls, as well as maintaining a cache of user and channel information for quick lookups.

Link to this section Summary

Functions

Add a reaction to a message. The timestamp of the message should be part of the message’s event

Fetch channel information by the channel’s ID, ex. “C2147483705”

Fetch channel information by the channel’s name, ex. “general”

Requests a Real Time Messaging session from Slack. Returns a tuple containing the websocket URL, the id of the bot requesting the session, and the name of the bot requesting the session

Get information about the user identified by user_id

Posts a message through the Slack REST API instead of via Websocket

Link to this section Functions

Link to this function add_reaction(channel, message_timestamp, reaction)
add_reaction(String.t(), String.t(), String.t()) :: %{}

Add a reaction to a message. The timestamp of the message should be part of the message’s event.

Example

msg = %{
  type: "message",
  channel: "C2147483705",
  user: "U2147483697",
  text: "Hello world",
  ts: "1355517523.000005"
}
ExBot.Slack.add_reaction(msg.channel, msg.ts, "thumbsup")
Link to this function get_channel(channel_id)
get_channel(String.t()) :: %{}

Fetch channel information by the channel’s ID, ex. “C2147483705”.

Link to this function get_channel_by_name(channel_name)
get_channel_by_name(String.t()) :: %{}

Fetch channel information by the channel’s name, ex. “general”.

Link to this function get_rtm_connection(bot_token)
get_rtm_connection(String.t()) :: {String.t(), String.t(), String.t()}

Requests a Real Time Messaging session from Slack. Returns a tuple containing the websocket URL, the id of the bot requesting the session, and the name of the bot requesting the session.

Example

{url, bot_id, bot_name} = ExBot.Slack.get_rtm_connection("xo-my-token")
Link to this function get_user(user_id)

Get information about the user identified by user_id.

Link to this function post_message(token, author, channel, text, attachments \\ [])
post_message(String.t(), String.t(), String.t(), String.t(), []) :: %{}

Posts a message through the Slack REST API instead of via Websocket.

Helpful if you need to post a message with fancy formatting, which is not currently supported via the RTM API.