Source:
public void doWork() throws Exception { final HierarchicalINIConfiguration settings = Utilities.parseConfig(configFile); final PostgreSQL db = new PostgreSQL(settings); final SlackSession session = SlackSessionFactory.createWebSocketSlackSession(settings.getString(Constants.REPORT_TOKEN)); session.addMessagePostedListener(new SlackMessagePostedListener() { @Override public void onEvent(SlackMessagePosted event, SlackSession session) { System.out.println(event.toString()); String namespace = settings.getString(Constants.REPORT_NAMESPACE).toUpperCase(Locale.CANADA); if (event.getSender().getUserName().equalsIgnoreCase(namespace)) { return; } String message = event.getMessageContent().toUpperCase(Locale.CANADA); boolean validMessage = false; String dmIdentifer = "<@" + session.sessionPersona().getId() + ">"; if (message.startsWith(dmIdentifer)) { message = message.replaceFirst(dmIdentifer, "").trim(); if (message.startsWith(":")) { message = message.replaceFirst(":", "").trim(); } validMessage = true; } if (message.startsWith(namespace)) { validMessage = true; message = message.replaceFirst(namespace, "").trim(); System.out.println("message was *" + message + "* "); if (message.startsWith(":")) { message = message.substring(1).trim(); } } if (validMessage) { ReportAPI reportAPI = ReportAPIFactory.makeReportAPI(settings, db); SlackRenderer renderer = new SlackRenderer(reportAPI); SlackRenderer.FormattedMessage result = renderer.convertToResult(message); if (result.attachment != null) { result.attachment.addMarkdownIn("text"); } session.sendMessage(session.findChannelById(event.getChannel().getId()), result.message, result.attachment); } } }); session.connect(); do { Thread.sleep(SLEEP_IN_MILLISECONDS); } while (options.has(this.endlessSpec)); }

Target:
public void doWork() throws Exception { final HierarchicalINIConfiguration settings = Utilities.parseConfig(configFile); final PostgreSQL db = new PostgreSQL(settings); final SlackSession session = SlackSessionFactory.createWebSocketSlackSession(settings.getString(Constants.REPORT_TOKEN)); session.addMessagePostedListener(new SlackMessagePostedListener() { @Override public void onEvent(SlackMessagePosted event, SlackSession session) { Log.debug(event.toString()); String namespace = settings.getString(Constants.REPORT_NAMESPACE).toUpperCase(Locale.CANADA); if (event.getSender().getUserName().equalsIgnoreCase(namespace)) { return; } String message = event.getMessageContent().toUpperCase(Locale.CANADA); boolean validMessage = false; String dmIdentifer = "<@" + session.sessionPersona().getId() + ">"; if (message.startsWith(dmIdentifer)) { message = message.replaceFirst(dmIdentifer, "").trim(); if (message.startsWith(":")) { message = message.replaceFirst(":", "").trim(); } validMessage = true; } if (message.startsWith(namespace)) { validMessage = true; message = message.replaceFirst(namespace, "").trim(); Log.info("message was *" + message + "* "); if (message.startsWith(":")) { message = message.substring(1).trim(); } } if (validMessage) { ReportAPI reportAPI = ReportAPIFactory.makeReportAPI(settings, db); SlackRenderer renderer = new SlackRenderer(reportAPI); SlackRenderer.FormattedMessage result = renderer.convertToResult(message); if (result.attachment != null) { result.attachment.addMarkdownIn("text"); } session.sendMessage(session.findChannelById(event.getChannel().getId()), result.message, result.attachment); } } }); session.connect(); do { Thread.sleep(SLEEP_IN_MILLISECONDS); } while (options.has(this.endlessSpec)); }