Slack API Docs - nsftx/incubator-2019-slack-bot-services GitHub Wiki

Slack API Implementation provides app developers with options to:

  • Send messages (public, private),
  • Create polls,
  • Update messages,
  • Delete messages,
  • Create schedules (non-repeating and repeating),
  • Delete schedules,
  • Get the list of channels.

Some methods require arguments to be passed in order to use them.

1. Send messages

PUBLIC MESSAGE

void sendMessage(String channel, String text, boolean isSmallImage) throws SlackApiException;

Method accepts 2 arguments + 1 optional:

String channel - ID/Name of channel on which message will be posted,

String text - Text of the message being send.

OPTIONAL boolean isSmallImage - Boolean to indicate which type of image to send, true - small image | false - large image. DEFAULT - FALSE.

If message sending fails, method throws exception.

PRIVATE MESSAGE

void sendMessage(String channel, String text, String user, boolean isSmallImage) throws SlackApiException;

Method accepts 3 arguments + 1 optional:

String channel - ID/Name of channel on which message will be posted,

String text - Text of the message being send,

String user - User to whom message will be sent.

OPTIONAL boolean isSmallImage - Boolean to indicate which type of image to send, true - small image | false - large image. DEFAULT - FALSE.

If message sending fails, method throws exception.

2. Create polls

String createPoll(String channel, String text, HashMap<Integer,String> choices, UUID pollID, Date pollCloseTime) throws SlackApiException;

Method accepts 5 arguments:

String channel - ID/Name of channel on which poll will be posted,

String text - Text of the poll being send,

HashMap<Integer,String> choices, - Map of id/value pairs that will be presented to users as options for voting,

UUID pollID - Unique ID of poll to create, used to map votes with right poll, and differentiate polls from each other,

Date pollCloseTime - Time and date at which poll will be closed.

Method returns poll timestamp (used for closing poll) if poll is sent successfully. ELSE, it throws exception.

3. Update messages

void updateMessage(String channel, String text, String messageTimestamp) throws SlackApiException;

Method accepts 3 arguments:

String channel - Name of channel where message was posted,

String text - New text that will replace previous message text,

String messageTimestamp - Time stamp of message (time at which message was posted).

If message updating fails, method throws exception.

4. Delete messages

void deleteMessage(String channel, String messageTimestamp) throws SlackApiException;

Method accepts 2 arguments:

String channel - Name of channel where message was posted,

String messageTimestamp - Time stamp of message (time at which message was posted).

If message deleting fails, method throws exception.

5. Create schedules

NON-REPEATING SCHEDULES

String createSchedule(String channel, String text, Date postAt) throws SlackApiException;

Method accepts 3 arguments:

String channel - ID/Name of channel to which to schedule message,

String text - Text of the message being scheduled,

Date postAt - Date and Time at which message will be posted.

Method returns ID of the scheduled message if message was scheduled successfully. ELSE, it throws exception.

REPEATING SCHEDULES

String createRepeatedSchedule(String channel, String text, Date postAt) throws SlackApiException;

Method accepts 3 arguments:

String channel - ID/Name of channel to which to schedule message,

String text - Text of the message being scheduled,

Date postAt - Date and Time at which message will be posted,

Method returns all scheduled messages IDs in one String if message was scheduled successfully. ELSE, it throws exception.

6. Delete schedules

void deleteSchedule(String channel, String scheduleID) throws SlackApiException;

Method accepts 2 arguments:

String channel - ID/Name of channel where message was scheduled,

String scheduleID - ID of the schedule user wants to delete.

If schedule deleting fails, method throws exception.

7. Get list of channels

List<Channel> getChannelsList();

Method doesn't accept any arguments.

Method returns a list of Channel objects with name and id of each channel.

⚠️ **GitHub.com Fallback** ⚠️