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

38
LINES

< > BotCompany Repo | #1002169 // slackSlurp

JavaX fragment (include)

static class SlackMsg {
  S user, botName; // one of these is going to be set
  S userName; // looked up if user != null
  S type, text, ts;
  O reactions;
  S channelID;
}

static L<SlackMsg> slackSlurp(S channelID, S token, int limit, S oldest, S latest, boolean inclusive) {
  S url = "https://slack.com/api/channels.history";
  Map postData = litmap(
    "token", token,
    "channel", channelID,
    "count", limit,
    "oldest", oldest,
    "latest", latest,
    "inclusive", inclusive ? 1 : 0);
  S data = doPost(postData, url);
  Map map = cast jsonDecode(data);
  assertTrue(map.get("ok"));
  List<Map> _msgs = cast map.get("messages");
  new L<SlackMsg> msgs;
  for (Map msg : reversedList(_msgs)) {
    new SlackMsg m;
    m.type = (S) msg.get("type");
    m.user = (S) msg.get("user");
    m.botName = (S) msg.get("username");
    m.text = htmldecode((S) msg.get("text"));
    m.ts = (S) msg.get("ts");
    m.reactions = msg.get("reactions");
    m.channelID = channelID;
    m.userName = slackGetUserName(token, m.user);
    msgs.add(m);
    //print(structure(m));
  }
  //print(l(msgs) + " messages sucked from slack channel.");
  ret msgs;
}

Author comment

Began life as a copy of #1001926

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: #1002169
Snippet name: slackSlurp
Eternal ID of this version: #1002169/1
Text MD5: 494d365315abd1efa7121d9d0c82aedb
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-12-23 04:36:27
Source code size: 1195 bytes / 38 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 642 / 918
Referenced in: #1002427 - Accellerating 629 (SPIKE)
#1006654 - Standard functions list 2 (LIVE, continuation of #761)
#3000202 - Answer for stefanreich (>> T conversion bot)
#3000238 - Answer for stefanreich (>> t power bot)
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)