Giter Site home page Giter Site logo

scala-slack's Introduction

scala-slack

scala-slack is a simple, extensible client library for Scala that provides an interface to the Slack API.

Note: scala-slack is a partial implementation of the Slack API. The Slack API is under heavy development, and this library is subject to frequent change.

Supported Methods

  • api.test
  • auth.test
  • channels.history
  • channels.list
  • channels.setTopic
  • chat.delete
  • chat.postMessage
  • chat.update
  • im.close
  • im.history
  • im.list
  • im.mark
  • im.open

Download

scala-slack is listed on Maven Central and can be included in your project by adding this line to your build.sbt:

libraryDependencies += "com.flyberrycapital" %% "scala-slack" % "0.3.0"

scala-slack supports Scala 2.10 and 2.11.

Usage

First, instantiate a SlackClient object.

import com.flyberrycapital.slack.SlackClient

val s = new SlackClient(<YOUR_API_TOKEN>)

You can then use Slack API methods:

s.chat.postMessage("#yourchannel", "Hello World!")

You can also edit and delete messages easily by using the returned PostMessageResponse object:

val response = s.chat.postMessage("#yourchannel", "Hello World!")

s.chat.update(response, "This is my update.")
s.chat.delete(response)

Message history can be retrieved with the channels.history and channels.historyStream methods:

val response = s.channels.list()
val channel = response.channels(0)

val history = s.channels.history(channel.id)
println(history.messages)

// get stream of messages in descending order
val historyStream = s.channels.historyStream(channel.id)

historyStream foreach println

All implemented API methods are documented in the code with Scaladoc.

Extending the library

scala-slack can easily be extended to accommodate new API methods and functionality.

For example, if Slack adds a chat.poke method, one could write a new version of the Chat class:

import com.flyberrycapital.slack.HttpClient
import com.flyberrycapital.slack.Methods.Chat

class PokeChat(httpClient: HttpClient, apiToken: String) extends Chat(httpClient, apiToken) {

   def poke(userID: String) = {
      val response = httpClient.post(
        "chat.poke",
        Map("user_id" -> userID, "token" -> apiToken)
      )

      // handle poke JSON response here...
   }

}

and then you can incorporate this into a custom version of SlackClient:

import com.flyberrycapital.slack.SlackClient

class PokeSlackClient(apiToken: String) extends SlackClient(apiToken) {

   override val chat = new PokeChat(httpClient, apiToken)

}

That being said, we hope that if you implement additional API methods yourself, you'll consider adding them to this project :)

License

This project is licensed under the MIT license.

scala-slack's People

Contributors

ksolan avatar sjednac avatar tisbutme avatar acvogel avatar

Watchers

Alejandro Diaz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.