1

I'm using simple-slack-api with Java, but I can not find a way to read messages from a specific channel. My code is the following:

public void getChannelMessages(String channelName) throws IOException{

    SlackChannel channel = slackSession_.findChannelByName(channelName);


}
Erik Kalkoken
  • 30,467
  • 8
  • 79
  • 114
user5872256
  • 69
  • 11

1 Answers1

1

To read message from a channel you need to fetch the history of that channel.

From the examples:

    /**
     * This method how to get the message history from a given channel (by default, 1000 max messages are fetched)
     */
    public void fetchSomeMessagesFromChannelHistory(SlackSession session, SlackChannel slackChannel)
    {
        //build a channelHistory module from the slack session
        ChannelHistoryModule channelHistoryModule = ChannelHistoryModuleFactory.createChannelHistoryModule(session);

        List<SlackMessagePosted> messages = channelHistoryModule.fetchHistoryOfChannel(slackChannel.getId());
}

See the full example from the git for more details.

Erik Kalkoken
  • 30,467
  • 8
  • 79
  • 114