GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - pschroen/slack-api-android: Android client for the Slack Web API, Incoming Webhooks, Slackbot Remote Control and RTM (Real Time Messaging) API

BranchesTags
Open more actions menu

Latest commit

 

History

20 Commits
20 Commits

Folders and files

NameName
Last commit message
Last commit date
gradle/wrapper
gradle/wrapper
 
 
slack-api @ fc9bda1
slack-api @ fc9bda1
 
 
.gitignore
.gitignore
 
 
.gitmodules
.gitmodules
 
 
.travis.yml
.travis.yml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
build.gradle
build.gradle
 
 
gradle.properties
gradle.properties
 
 
gradlew
gradlew
 
 
gradlew.bat
gradlew.bat
 
 
jitpack.yml
jitpack.yml
 
 
settings.gradle
settings.gradle
 
 

Repository files navigation

slack-api-android Release Build Status

Port of allbegray's slack-api. Used in the production app Amp.

https://jitpack.io/#pschroen/slack-api-android

Add it to your build.gradle with:

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

and:

dependencies {
    compile 'com.github.pschroen:slack-api-android:c66cc8d997'
}

Differences

  • Compiled with Java 7.
  • Commons Logging replaced with Android Logging.
  • org.apache.http classes replaced with HttpClient for Android maintained by Marek Sebera.
  • org.asynchttpclient classes replaced with OkHttp Web Sockets and Socket.IO's WebSocket.java as a reference.

Usage

final String slackToken = mSharedPref.getString("slack_token", "");

mWebApiClient = SlackClientFactory.createWebApiClient(slackToken);
String webSocketUrl = mWebApiClient.startRealTimeMessagingApi().findPath("url").asText();
mRtmClient = new SlackRealTimeMessagingClient(webSocketUrl);

mRtmClient.addListener(Event.HELLO, new EventListener() {

    @Override
    public void onMessage(JsonNode message) {
        Authentication authentication = mWebApiClient.auth();
        mBotId = authentication.getUser_id();

        System.out.println("User id: " + mBotId);
        System.out.println("Team name: " + authentication.getTeam());
        System.out.println("User name: " + authentication.getUser());
    }
});

mRtmClient.addListener(Event.MESSAGE, new EventListener() {

    @Override
    public void onMessage(JsonNode message) {
        String channelId = message.findPath("channel").asText();
        String userId = message.findPath("user").asText();
        String text = message.findPath("text").asText();

        if (userId != null && !userId.equals(mBotId)) {
            Channel channel;
            try {
                channel = mWebApiClient.getChannelInfo(channelId);
            } catch (SlackResponseErrorException e) {
                channel = null;
            }
            User user = mWebApiClient.getUserInfo(userId);
            String userName = user.getName();

            System.out.println("Channel id: " + channelId);
            System.out.println("Channel name: " + (channel != null ? "#" + channel.getName() : "DM"));
            System.out.println("User id: " + userId);
            System.out.println("User name: " + userName);
            System.out.println("Text: " + text);

            // Copy cat
            mWebApiClient.meMessage(channelId, userName + ": " + text);
        }
    }
});

mRtmClient.connect();

If you need to catch the close and failure events you can add listeners:

mRtmClient.addCloseListener(new CloseListener() {

    @Override
    public void onClose() {
        System.out.println("Connection closed");
    }
});

mRtmClient.addFailureListener(new FailureListener() {

    @Override
    public void onFailure(Throwable t) {
        Exception e = (Exception) t;

        System.out.println("Failure message: " + e.getMessage());
    }
});

ProGuard

-dontwarn allbegray.slack.**
-keep class allbegray.slack.** {*;}
-dontwarn com.fasterxml.**
-keep class com.fasterxml.** {*;}
-dontwarn okio.**
-keep class okio.** {*;}

About

Android client for the Slack Web API, Incoming Webhooks, Slackbot Remote Control and RTM (Real Time Messaging) API

Resources

Readme
MIT license
Activity

Stars

17 stars

Watchers

4 watching

Forks

6 forks
Report repository

Releases

Packages

Contributors

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.