我正在使用simple-slack-api使用Java,但我找不到从特定 channel 读取消息的方法。我的代码如下:
public void getChannelMessages(String channelName) throws IOException{
SlackChannel channel = slackSession_.findChannelByName(channelName);
}
最佳答案
要从某个 channel 读取消息,您需要获取该 channel 的历史记录。
来自示例:
/**
* 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());
}
请参阅full example从 git 获取更多详细信息。
关于java - 如何使用 simple-slack-api 读取 channel 消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48607795/