Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

35
LINES

< > BotCompany Repo | #1001907 // slackReadTalkingBots

JavaX fragment (include)

1  
static class SlackMsg {
2  
  S user, botName; // one of these is going to be set
3  
  S type, text, ts;
4  
  O reactions;
5  
}
6  
7  
static L<SlackMsg> slackReadTalkingBots(int limit) {
8  
  ret slackReadTalkingBots(limit, null);
9  
}
10  
11  
static L<SlackMsg> slackReadTalkingBots(int limit, S oldest) {
12  
  S channelID = "C0FH9PY8J"; // #talkingbots
13  
  S token = loadSecretTextFileMandatory("#1001889", "relp-slack-botstuff-token").trim();
14  
  S url = "https://slack.com/api/channels.history";
15  
  S postData = "token=" + urlencode(token) + "&channel=" + urlencode(channelID) + "&count=" + limit
16  
    + (oldest != null ? "&oldest=" + urlencode(oldest) : "");
17  
  S data = doPost(postData, url);
18  
  Map map = cast jsonDecode(data);
19  
  assertTrue(map.get("ok"));
20  
  List<Map> _msgs = cast map.get("messages");
21  
  new L<SlackMsg> msgs;
22  
  for (Map msg : reversedList(_msgs)) {
23  
    new SlackMsg m;
24  
    m.type = (S) msg.get("type");
25  
    m.user = (S) msg.get("user");
26  
    m.botName = (S) msg.get("username");
27  
    m.text = (S) msg.get("text");
28  
    m.ts = (S) msg.get("ts");
29  
    m.reactions = msg.get("reactions");
30  
    msgs.add(m);
31  
    //print(structure(m));
32  
  }
33  
  print(l(msgs) + " messages sucked from slack channel.");
34  
  ret msgs;
35  
}

Author comment

Began life as a copy of #1001888

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1001907
Snippet name: slackReadTalkingBots
Eternal ID of this version: #1001907/1
Text MD5: af8cd2bedad766eb034d134b6d0a4b0c
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-12-06 19:17:15
Source code size: 1221 bytes / 35 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 722 / 957
Referenced in: [show references]