Reputation: 69
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
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