!752

// L<SlackMsg> slackSlurp: S channelID, S token, int limit, S oldest, S latest, boolean inclusive

p {
  S token = loadRelpToken();
  Map<S, S> channels = slackGetChannelIDs(token);
  S channel = "talkingbots";
  int limit = 1000;
  S latest = null;
  L<SlackMsg> l;
  int n = 0; // safety switch #1 - never suck more than 100.000 msgs
  do {
    // TODO: special case when there are no more messages.
    l = slackSlurp(channels.get(channel), token, limit, null, latest, false);
    S newLatest = first(l).ts;
    assertNotNull(newLatest);
    
    // safety switch #2
    if (latest != null) assertTrue(cmp(latest, newLatest) > 0);
    
    latest = newLatest;
    print("latest=" + latest);
    print(l(l) + " messages slurped from #" + channel);
  } while (l(l) == limit && ++n < 100);
}