Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<parent>
<groupId>com.hubspot</groupId>
<artifactId>basepom</artifactId>
<version>63.8</version>
<version>65.1</version>
</parent>

<groupId>com.hubspot.slack</groupId>
<artifactId>slack-client</artifactId>
<version>1.16.19-SNAPSHOT</version>
<version>1.17.0-SNAPSHOT</version>
<packaging>pom</packaging>

<name>${project.groupId}:${project.artifactId}</name>
Expand All @@ -25,9 +25,7 @@
</modules>

<properties>
<horizon.version>0.1.1</horizon.version>
<dep.netty3.version>3.10.6.Final</dep.netty3.version>
<dep.plugin.spotbugs.version>4.9.3.2</dep.plugin.spotbugs.version>
<horizon.version>0.5.0</horizon.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -82,12 +80,6 @@
<artifactId>slack-request-verifier</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.ning</groupId>
<artifactId>async-http-client</artifactId>
<version>1.9.40</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
2 changes: 1 addition & 1 deletion slack-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.hubspot.slack</groupId>
<artifactId>slack-client</artifactId>
<version>1.16.19-SNAPSHOT</version>
<version>1.17.0-SNAPSHOT</version>
</parent>

<artifactId>slack-base</artifactId>
Expand Down
22 changes: 17 additions & 5 deletions slack-java-client-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.hubspot.slack</groupId>
<artifactId>slack-client</artifactId>
<version>1.16.19-SNAPSHOT</version>
<version>1.17.0-SNAPSHOT</version>
</parent>

<artifactId>slack-java-client-examples</artifactId>
Expand All @@ -29,10 +29,6 @@
<groupId>com.hubspot</groupId>
<artifactId>HorizonCore</artifactId>
</dependency>
<dependency>
<groupId>com.hubspot</groupId>
<artifactId>HorizonNing</artifactId>
</dependency>
<dependency>
<groupId>com.hubspot.slack</groupId>
<artifactId>slack-base</artifactId>
Expand All @@ -41,6 +37,22 @@
<groupId>com.hubspot.slack</groupId>
<artifactId>slack-java-client</artifactId>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-common</artifactId>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-codec-http</artifactId>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-buffer</artifactId>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package com.hubspot.slack.server.example;

import com.hubspot.horizon.shaded.org.jboss.netty.buffer.ChannelBuffer;
import com.hubspot.horizon.shaded.org.jboss.netty.channel.Channel;
import com.hubspot.horizon.shaded.org.jboss.netty.channel.ChannelHandlerContext;
import com.hubspot.horizon.shaded.org.jboss.netty.channel.ExceptionEvent;
import com.hubspot.horizon.shaded.org.jboss.netty.channel.MessageEvent;
import com.hubspot.horizon.shaded.org.jboss.netty.channel.SimpleChannelHandler;
import com.hubspot.horizon.shaded.org.jboss.netty.handler.codec.http.HttpRequest;
import com.hubspot.slack.client.SlackClient;
import com.hubspot.slack.client.examples.BasicRuntimeConfig;
import com.hubspot.slack.client.jackson.ObjectMapperUtils;
Expand All @@ -20,14 +13,19 @@
import com.hubspot.slack.client.models.interaction.SlackInteractiveCallback;
import com.hubspot.slack.client.models.response.views.ModalViewCommandResponse;
import com.hubspot.slack.client.models.views.ModalViewPayload;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.HttpContent;
import io.netty.handler.codec.http.HttpObject;
import java.io.IOException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collections;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SlackMessageHandler extends SimpleChannelHandler {
public class SlackMessageHandler extends SimpleChannelInboundHandler<HttpObject> {

private static final Logger LOG = LoggerFactory.getLogger(SlackMessageHandler.class);

Expand All @@ -38,36 +36,42 @@ public SlackMessageHandler() {
}

@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
HttpRequest request = (HttpRequest) e.getMessage();
ChannelBuffer content = request.getContent();
try {
String jsonContent = URLDecoder
.decode(content.toString(StandardCharsets.UTF_8), "utf-8")
.substring(8);
SlackInteractiveCallback callback = ObjectMapperUtils
.mapper()
.readValue(jsonContent, SlackInteractiveCallback.class);
LOG.info("Received raw JSON: {}", jsonContent);
LOG.info("Deserialized Callback: {}", callback);
if (callback instanceof BlockActions) {
sendResponse((BlockActions) callback);
protected void channelRead0(
ChannelHandlerContext channelHandlerContext,
HttpObject msg
) throws Exception {
if (msg instanceof HttpContent) {
HttpContent httpContent = (HttpContent) msg;
ByteBuf content = httpContent.content();

try {
String jsonContent = URLDecoder
.decode(content.toString(StandardCharsets.UTF_8), StandardCharsets.UTF_8)
.substring(8);
SlackInteractiveCallback callback = ObjectMapperUtils
.mapper()
.readValue(jsonContent, SlackInteractiveCallback.class);
LOG.info("Received raw JSON: {}", jsonContent);
LOG.info("Deserialized Callback: {}", callback);
if (callback instanceof BlockActions) {
sendResponse((BlockActions) callback);
}
} catch (IOException ex) {
LOG.error("Could not decode message", ex);
}
} catch (IOException ex) {
LOG.error("Could not decode message", ex);
}
}

@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
LOG.error("Got an error", e.getCause());
Channel ch = e.getChannel();
ch.close();
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
throws Exception {
LOG.error("Got an error", cause.getCause());
ctx.close();
}

private void sendResponse(BlockActions blockActions) {
for (BlockElementAction action : blockActions.getElementActions()) {
LOG.info("You interaced with: {}", action);
LOG.info("You interacted with: {}", action);
}

ModalViewCommandResponse response = slackClient
Expand All @@ -76,7 +80,7 @@ private void sendResponse(BlockActions blockActions) {
blockActions.getTriggerId(),
ModalViewPayload.of(
Text.of(TextType.PLAIN_TEXT, "Hi " + blockActions.getUser().getUsername()),
Arrays.asList(
Collections.singletonList(
Section
.of(Text.of(TextType.MARKDOWN, "Thanks for clicking on _something_!"))
.withAccessory(DatePicker.of("my-date-picker"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,51 @@
package com.hubspot.slack.server.example;

import com.hubspot.horizon.shaded.org.jboss.netty.bootstrap.ServerBootstrap;
import com.hubspot.horizon.shaded.org.jboss.netty.channel.ChannelFactory;
import com.hubspot.horizon.shaded.org.jboss.netty.channel.Channels;
import com.hubspot.horizon.shaded.org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
import com.hubspot.horizon.shaded.org.jboss.netty.handler.codec.http.HttpChunkAggregator;
import com.hubspot.horizon.shaded.org.jboss.netty.handler.codec.http.HttpServerCodec;
import java.net.InetSocketAddress;
import java.util.concurrent.Executors;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.codec.http.HttpRequestDecoder;

public class SlackServer {

public static void main(String[] args) {
ChannelFactory factory = new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()
);
public static void main(String[] args) throws Exception {
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b
.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 100)
.localAddress(8080)
.childOption(ChannelOption.TCP_NODELAY, true)
.childOption(ChannelOption.SO_KEEPALIVE, true)
.childHandler(
new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new HttpRequestDecoder(), new SlackMessageHandler());
}
}
);

ServerBootstrap bootstrap = new ServerBootstrap(factory);
// Start the server.
ChannelFuture f = b.bind().sync();

bootstrap.setPipelineFactory(() ->
Channels.pipeline(
new HttpServerCodec(),
new HttpChunkAggregator(2 << 10),
new SlackMessageHandler()
)
);
// Wait until the server socket is closed.
f.channel().closeFuture().sync();
} finally {
// Shut down all event loops to terminate all threads.
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();

bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.keepAlive", true);

bootstrap.bind(new InetSocketAddress(8080));
// Wait until all threads are terminated.
bossGroup.terminationFuture().sync();
workerGroup.terminationFuture().sync();
}
}
}
2 changes: 1 addition & 1 deletion slack-java-client-guice/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.hubspot.slack</groupId>
<artifactId>slack-client</artifactId>
<version>1.16.19-SNAPSHOT</version>
<version>1.17.0-SNAPSHOT</version>
</parent>

<artifactId>slack-java-client-guice</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion slack-java-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.hubspot.slack</groupId>
<artifactId>slack-client</artifactId>
<version>1.16.19-SNAPSHOT</version>
<version>1.17.0-SNAPSHOT</version>
</parent>

<artifactId>slack-java-client</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion slack-request-verifier/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.hubspot.slack</groupId>
<artifactId>slack-client</artifactId>
<version>1.16.19-SNAPSHOT</version>
<version>1.17.0-SNAPSHOT</version>
</parent>

<artifactId>slack-request-verifier</artifactId>
Expand Down