in chatterbox-slack/chatterbox-slack-impl/src/main/java/org/apache/tomee/chatterbox/slack/adapter/SlackResourceAdapter.java [153:207]
public void handleMessage(final JsonNode jsonNode) {
String commandLine = jsonNode.get("text").textValue();
final String userPrefix = "<@" + userId + ">";
if (!commandLine.startsWith(userPrefix)) {
return;
}
// chop off the user: prefix
commandLine = commandLine.replaceAll("^" + userPrefix + ":?\\s*", "");
final String channel = jsonNode.get("channel").textValue();
String[] args;
final Arguments[] arguments = ArgumentsParser.parse(commandLine);
if (arguments == null || arguments.length == 0) {
args = new String[]{"help"};
} else {
args = arguments[0].get();
}
final ByteArrayOutputStream os = new ByteArrayOutputStream();
final PrintStream ps = new PrintStream(os);
final Environment environment = new Environment() {
@Override
public PrintStream getOutput() {
return ps;
}
@Override
public PrintStream getError() {
return ps;
}
@Override
public InputStream getInput() {
return null;
}
@Override
public Properties getProperties() {
return System.getProperties();
}
};
try {
main.main(environment, args);
} catch (Exception e) {
e.printStackTrace(ps);
}
ChatPostMessageMethod postMessage = new ChatPostMessageMethod(channel, new String(os.toByteArray()));
postMessage.setUsername(user);
webApiClient.postMessage(postMessage);
}