user5872256
user5872256

Reputation: 69

How to read channel messages with simple-slack-api?

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);


}

Upvotes: 1

Views: 1735

Answers (1)

Erik Kalkoken
Erik Kalkoken

Reputation: 32852

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.

Upvotes: 1

Related Questions