private static SlackChannelUnarchived extractChannelUnarchiveEvent(
     SlackSession slackSession, JSONObject obj) {
   String channelId = (String) obj.get("channel");
   String userId = (String) obj.get("user");
   return new SlackChannelUnarchivedImpl(
       slackSession.findChannelById(channelId), slackSession.findUserById(userId));
 }
Ejemplo n.º 2
0
  @RequestMapping(
      value = "/api/broadcast",
      method = RequestMethod.POST,
      produces = "application/json")
  public List<BroadcastGroup> broadcastMessage(
      @RequestParam("name") String name,
      @RequestParam("set") Integer setId,
      @RequestParam("message") String message) {
    BroadcastGroup group = broadcastRepository.findOne(name);
    if (group != null) {
      Optional<BroadcastSet> setOptional =
          group.getBroadcastSets().stream().filter(set -> set.getId() == setId).findFirst();
      if (setOptional.isPresent()) {
        BroadcastSet set = setOptional.get();
        set.getMessages().add(new BroadcastMessage(message, new Date()));
        broadcastRepository.save(group);
        executorService.execute(
            () -> {
              set.getUsers()
                  .forEach(
                      userId -> {
                        SlackUser user = session.findUserById(userId);
                        session.sendMessageToUser(user, message, null);
                      });
            });
      } else {
        log.error("Can't find set with id {}", setId);
      }

    } else {
      log.error("Can't find group with name {}", name);
    }
    return broadcastRepository.findAll();
  }
 private static SlackChannelCreated extractChannelCreatedEvent(
     SlackSession slackSession, JSONObject obj) {
   JSONObject channelJSONObject = (JSONObject) obj.get("channel");
   SlackChannel channel = parseChannelDescription(channelJSONObject);
   String creatorId = (String) channelJSONObject.get("creator");
   SlackUser user = slackSession.findUserById(creatorId);
   return new SlackChannelCreatedImpl(channel, user);
 }
 private static SlackMessagePostedImpl parseMessagePublished(
     JSONObject obj, SlackChannel channel, String ts, SlackSession slackSession) {
   String text = (String) obj.get("text");
   String userId = (String) obj.get("user");
   String botId = (String) obj.get("bot_id");
   SlackUser user = userId != null ? slackSession.findUserById(userId) : null;
   SlackBot bot = botId != null ? slackSession.findBotById(botId) : null;
   return new SlackMessagePostedImpl(text, bot, user, channel, ts);
 }
Ejemplo n.º 5
0
 @RequestMapping(
     value = "/slack/availability",
     method = RequestMethod.GET,
     produces = MediaType.TEXT_PLAIN_VALUE)
 @ResponseBody
 public String getAvailability(@Valid SlashSlackMessage message, Model model) {
   log.debug("Incoming Slack request: {}", message.toString());
   if (!message.getToken().equals(slackProperties.getSlashCommandToken())) {
     throw new AccessDeniedException(
         "Token in request " + message.getToken() + " did not match configured token.");
   }
   return slackMessageService.respondToMessage(
       Optional.of(slackSession)
           .map(slackSession -> slackSession.findUserById(message.getUserId())),
       message.getText());
 }