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

40
LINES

< > BotCompany Repo | #1001904 // Try finding bot responses in Slack channel

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (832L/7K/21K).

1  
!752
2  
3  
static class Msg {
4  
  // either user (internal user ID) is set or botName
5  
  S type, user, text, ts;
6  
  S botName;
7  
  O reactions;
8  
}
9  
10  
static S data;
11  
static new L<Msg> msgs; // Note: They're in reverse order!
12  
13  
static S token;
14  
static S channelID = "C0FH9PY8J"; // #talkingbots
15  
//static S oldest = "1449245380.000382"; // timestamp of first msg to get
16  
static int limit = 10; // get n messages max
17  
18  
p {
19  
  token = loadSecretTextFileMandatory("#1001889", "relp-slack-botstuff-token").trim();
20  
  S url = "https://slack.com/api/channels.history";
21  
  S postData = "token=" + urlencode(token) + "&channel=" + urlencode(channelID) + /*"&oldest=" + urlencode(oldest) +*/ "&count=" + limit;
22  
  data = doPost(postData, url);
23  
  print(data);
24  
  Map map = cast jsonDecode(data);
25  
  assertTrue(map.get("ok"));
26  
  List<Map> _msgs = cast map.get("messages");
27  
  msgs = new ArrayList<Msg>();
28  
  for (Map msg : _msgs) {
29  
    new Msg m;
30  
    m.type = (S) msg.get("type");
31  
    m.user = (S) msg.get("user");
32  
    m.botName = (S) msg.get("username");
33  
    m.text = (S) msg.get("text");
34  
    m.ts = (S) msg.get("ts");
35  
    m.reactions = msg.get("reactions");
36  
    msgs.add(m);
37  
    print(structure(m));
38  
  }
39  
  print(l(msgs) + " messages sucked from slack channel.");
40  
}

Author comment

Began life as a copy of #1001888

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1001904
Snippet name: Try finding bot responses in Slack channel
Eternal ID of this version: #1001904/1
Text MD5: e2c70bf059cf00a5f7310ef71775d7ac
Transpilation MD5: 69ad52010ad8ce4ab7658133fdcfe465
Author: stefan
Category:
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-12-06 18:45:56
Source code size: 1267 bytes / 40 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 515 / 566
Referenced in: [show references]