!752 static S channelID = "C0FH9PY8J"; // relp, #talkingbots static S token; static PersistentLog msgs; static new Map lastSeenByChannel; p { if (token == null) token = loadSecretTextFileMandatory("#1001889", "relp-slack-botstuff-token").trim(); msgs = new PersistentLog("msgs"); for (SlackMsg msg : msgs) { S s = lastSeenByChannel.get(msg); if (s == null || msg.ts.compareTo(s) > 0) lastSeenByChannel.put(channelID, msg.ts); } while true { pcall { int limit = 1000; L newMsgs = slackReadChannel(channelID, token, limit, lastSeenByChannel.get(channelID)); msgs.addAll(newMsgs); if (!newMsgs.isEmpty()) { print(l(newMsgs) + " new messages in " + channelID + "."); lastSeenByChannel.put(channelID, last(newMsgs).ts); } } sleepSeconds(5); } }