Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

45
LINES

< > BotCompany Repo | #1002613 // Test Slack RTM API 2 (using Tyrus)

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Uses 569K of libraries. Click here for Pure Java version (1216L/8K/27K).

1  
!752
2  
//1002612 // javax.websocket + implementation (tyrus)
3  
!1002664 // JDK 7 tyrus
4  
5  
import javax.websocket.*;
6  
import org.glassfish.tyrus.client.*;
7  
8  
p {
9  
  S token = loadSecretTextFile("#1002653", "slack-token.txt");
10  
if (token == null)
11  
token = devChannelToken();
12  
token = token.trim();
13  
  S url = "https://slack.com/api/rtm.start";
14  
  Map postData = litmap("token", token, "no_unreads", "1");
15  
  S data = doPost(postData, url);
16  
  Map map = cast jsonDecode(data);
17  
  //printStructure(map);
18  
  
19  
  S websocketURL = getString(map, "url");
20  
  print("Websocket URL: " + websocketURL);
21  
  assertTrue(nempty(websocketURL));
22  
  
23  
  // open websocket
24  
  
25  
  //final CountDownLatch messageLatch = new CountDownLatch(1);
26  
27  
  final ClientEndpointConfig cec = ClientEndpointConfig.Builder.create().build();
28  
29  
  ClientManager client = ClientManager.createClient();
30  
  client.connectToServer(new Endpoint() {
31  
32  
    public void onOpen(Session session, EndpointConfig config) ctex {
33  
      session.addMessageHandler(new MessageHandler.Whole<String>() {
34  
35  
          @Override
36  
          public void onMessage(String message) {
37  
              System.out.println("Received message: " + message);
38  
              //messageLatch.countDown();
39  
          }
40  
      });
41  
      //session.getBasicRemote().sendText(SENT_MESSAGE);
42  
    }
43  
  }, cec, new URI(websocketURL));
44  
  //messageLatch.await(100, TimeUnit.SECONDS);
45  
}

Author comment

Began life as a copy of #1002611

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, nbgitpuheiab, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1002613
Snippet name: Test Slack RTM API 2 (using Tyrus)
Eternal ID of this version: #1002613/1
Text MD5: 6b15dc58ca55fca1228dde7033fc5c89
Transpilation MD5: c8bae2754213219287ab7ec09850638f
Author: stefan
Category: javax / eleu
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-02-11 00:14:23
Source code size: 1410 bytes / 45 lines
Pitched / IR pitched: No / No
Views / Downloads: 724 / 649
Referenced in: [show references]