如何使用simple-slack-api读取通道消息?

时间:2018-02-04 11:58:38

标签: java slack

我正在使用simple-slack-api和Java,但我找不到从特定频道读取消息的方法。我的代码如下:

public void getChannelMessages(String channelName) throws IOException{

    SlackChannel channel = slackSession_.findChannelByName(channelName);


}

1 个答案:

答案 0 :(得分:1)

要从频道中读取消息,您需要获取该频道的历史记录。

来自示例:

    /**
     * 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());
}

有关详细信息,请参阅git中的full example