Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChannelHistoryModule always get blank #49

Closed
sleepykid opened this issue Feb 10, 2016 · 7 comments
Closed

ChannelHistoryModule always get blank #49

sleepykid opened this issue Feb 10, 2016 · 7 comments
Assignees

Comments

@sleepykid
Copy link

Are there any examples with the Channel History? I tried to use both the channel name and channel id, but get nothing back.

I'm trying to do the following, but get an empty list every time:

SlackSession session = SlackSessionFactory.createWebSocketSlackSession("token");
ChannelHistoryModule history = ChannelHistoryModuleFactory.createChannelHistoryModule(session);

session.addMessagePostedListener(new SlackMessagePostedListener()
{
    @Override
    public void onEvent(SlackMessagePosted event, SlackSession session)
    {
      System.out.println(event.getMessageContent()+" timestamp:"+event.getTimestamp());
      ChannelHistoryModule history = ChannelHistoryModuleFactory.createChannelHistoryModule(session);
      System.out.println(history);
      System.out.println("history:");
      System.out.println(history.fetchHistoryOfChannel(event.getChannel().getId()));
      List <SlackMessagePosted> messages = history.fetchHistoryOfChannel(event.getChannel().getId());
      for (int i = 0; i < messages.size(); i++) {
        SlackMessagePosted message=messages.get(i);
                    System.out.println(message.getChannel()+": "+message.getMessageContent()+" sender:"+message.getSender().getUserName());
    }
@bcorne
Copy link
Contributor

bcorne commented Feb 15, 2016

Hi,

I should add some example on how to use it. But are you using a bot token or a full user token? Slack is not allowing bots to fetch history of channels, this might be the reason it is not working in your case.

Best regards,

Benoit

@bcorne bcorne self-assigned this Feb 15, 2016
@sleepykid
Copy link
Author

Hi Benoit,

Some examples would be really helpful. I'm using a bot token and able to do it in python via the python slacker wrapper api. But this java api seems to much more rich with features and wanted to migrate over. If bot tokens can't do it, a full user token would still be helpful.
thanks!
Andrew

@ggs-jan
Copy link

ggs-jan commented Feb 16, 2016

Hi,

Slack is not allowing bots to fetch history of channels

I can't confirm that. We are using bots to do just that: fetch the history of (public) channels.
Fetching the history even works when the bot is not a member of the channel.
However, when the bot should listen to channel events such as new messages, the bot needs to be added to the channel.

@andrew
Have you tried to fetch the history of a channel or of a group? I believe the ChannelHistoryModule currently only works for channels.

Regards,
Jan

@sleepykid
Copy link
Author

Thanks for the suggestions.

Ok, so I got it down to 2 cases:

  1. able to get the channel history of a channel that the bot is *_not *_a member of.
  2. not able to get channel history of a channel that the bot is a member of

is this a configuration issue? or some sort of feature?

also, related, is there a way to get IM history of the bot?

@bcorne
Copy link
Contributor

bcorne commented Mar 7, 2016

I'm working on this now

@bcorne
Copy link
Contributor

bcorne commented Mar 7, 2016

ok, I've identified the issue, I confirm that this is only working fine for public channel, the issue beinf that the command to send to slack is different for private channels, I'll fix that soon then

bcorne added a commit that referenced this issue Mar 7, 2016
@bcorne
Copy link
Contributor

bcorne commented Mar 7, 2016

fixed with last commit

@bcorne bcorne closed this as completed Mar 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants