Skip to content
This repository has been archived by the owner on Apr 14, 2024. It is now read-only.
Yuri Schimke edited this page Jul 18, 2018 · 5 revisions

Slack

Aliases

slackapi -> https://slack.com/api{0}

Authentication

Visit Your Apps and select an app. Ensure you configure http://localhost:3000/callback as a callback. Enter the Client ID and Client Secret when authorizing.

Otherwise a Test Token can be used to skip the auth flow.

$ okurl -s test --authorize slack
Authorising Slack API
Slack Client Id [999999.99999999]:
Slack Client Secret [********************************]:
Scopes [channels:history,channels:read,channels:write,chat:write:bot,chat:write:user,dnd:read,dnd:write,emoji:read,files:read,files:write:user,groups:history,groups:read,groups:write,im:history,im:read,im:write,mpim:history,mpim:read,mpim:write,pins:read,pins:write,reactions:read,reactions:write,reminders:read,reminders:write,search:read,stars:read,stars:write,team:read,usergroups:read,usergroups:write,users.profile:read,users.profile:write,users:read,users:write]:

$ okurl --authorize slack --token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Bash Completion

$ slackapi -s test /users.profile.get
{
  "ok": true,
  "profile": {
    "avatar_hash": "g9999999",
    "real_name": "",
    "real_name_normalized": "",
    "email": "bob@bonson.com",
...

RTM (Websocket)

Requires scopes: client,rtm:stream

https://github.com/yschimke/okurl/blob/master/commands/slackrtm

#!/usr/bin/env okscript

import com.baulsupp.okurl.kotlin.client
import com.baulsupp.okurl.kotlin.okshell
import com.baulsupp.okurl.kotlin.query
import com.baulsupp.okurl.kotlin.newWebSocket
import com.baulsupp.okurl.ws.WebSocketPrinter
import java.util.concurrent.TimeUnit
import kotlinx.coroutines.experimental.runBlocking
import com.baulsupp.okurl.services.slack.RtmConnect

val wsClient = client.newBuilder().readTimeout(0, TimeUnit.MINUTES).build();

val start = runBlocking { query<RtmConnect>("https://slack.com/api/rtm.connect") }

val printer = WebSocketPrinter(okshell.outputHandler)
val ws = newWebSocket(start.url, printer)

printer.waitForExit()
$ okurl --authorize slack
Authorising Slack API
Slack Client Id [999999.99999999]:
Slack Client Secret [********************************]:
Scopes [...]: client,rtm:stream

$ slackrtm | jq '. | select(.type == "presence_change")'
{
  "type": "presence_change",
  "presence": "active",
  "user": "999999999"
}
Clone this wiki locally