55import com .slack .api .Slack ;
66import com .slack .api .SlackConfig ;
77import com .slack .api .methods .SlackApiException ;
8+ import com .slack .api .methods .response .chat .ChatPostMessageResponse ;
89import com .slack .api .methods .response .conversations .ConversationsInviteResponse ;
910import com .slack .api .model .Conversation ;
1011import com .slack .api .model .User ;
1112import com .slack .api .model .event .HelloEvent ;
13+ import com .slack .api .model .event .MessageBotEvent ;
1214import com .slack .api .model .event .UserTypingEvent ;
1315import com .slack .api .rtm .*;
1416import com .slack .api .rtm .message .Message ;
@@ -68,6 +70,17 @@ public void handle(HelloEvent event) {
6870 }
6971 }
7072
73+ @ Slf4j
74+ public static class BotMessageHandler extends RTMEventHandler <MessageBotEvent > {
75+ public final AtomicInteger counter = new AtomicInteger (0 );
76+
77+ @ Override
78+ public void handle (MessageBotEvent event ) {
79+ log .info ("bot message event: {}" , event );
80+ counter .incrementAndGet ();
81+ }
82+ }
83+
7184 public static class SubHelloHandler extends HelloHandler {
7285 }
7386
@@ -109,6 +122,16 @@ public void test() throws Exception {
109122 assertThat (hello .counter .get (), is (1 ));
110123 assertThat (hello2 .counter .get (), is (1 ));
111124
125+ BotMessageHandler bot = new BotMessageHandler ();
126+ dispatcher .register (bot );
127+
128+ ChatPostMessageResponse chatPostMessage = slack .methods (classicAppBotToken )
129+ .chatPostMessage (r -> r .channel (channelId ).text ("Hi!" ));
130+ assertThat (chatPostMessage .getError (), is (nullValue ()));
131+
132+ Thread .sleep (1000L );
133+ assertThat (bot .counter .get (), is (1 ));
134+
112135 rtm .reconnect ();
113136 Thread .sleep (1000L );
114137 assertThat (hello .counter .get (), is (2 ));
@@ -120,6 +143,7 @@ public void test() throws Exception {
120143 Thread .sleep (1000L );
121144 assertThat (hello .counter .get (), is (2 )); // should not be incremented
122145 assertThat (hello2 .counter .get (), is (3 ));
146+
123147 }
124148
125149 } finally {
0 commit comments