yuya373 / emacs-slack

slack client for emacs
1.12k stars 117 forks source link
emacs slack

DEPRECATED

Please note, this project is deprecated and no longer being maintained


MELPA

Emacs Slack

GNU Emacs client for Slack.


Preview

You can see some gifs on the wiki.

Dependencies

Extensions

Configuration

How to get token and cookie

;; I'm using use-package and el-get and evil

(el-get-bundle slack)
(el-get-bundle yuya373/helm-slack) ;; optional
(use-package helm-slack :after (slack)) ;; optional
(use-package slack
  :commands (slack-start)
  :init
  (setq slack-buffer-emojify t) ;; if you want to enable emoji, default nil
  (setq slack-prefer-current-team t)
  :config
  (slack-register-team
   :name "emacs-slack"
   :default t
   :token "xoxs-sssssssssss-88888888888-hhhhhhhhhhh-jjjjjjjjjj"
   :subscribed-channels '(test-rename rrrrr)
   :full-and-display-names t)

  (slack-register-team
   :name "test"
   :token "xoxs-yyyyyyyyyy-zzzzzzzzzzz-hhhhhhhhhhh-llllllllll"
   :subscribed-channels '(hoge fuga))

  (evil-define-key 'normal slack-info-mode-map
    ",u" 'slack-room-update-messages)
  (evil-define-key 'normal slack-mode-map
    ",c" 'slack-buffer-kill
    ",ra" 'slack-message-add-reaction
    ",rr" 'slack-message-remove-reaction
    ",rs" 'slack-message-show-reaction-users
    ",pl" 'slack-room-pins-list
    ",pa" 'slack-message-pins-add
    ",pr" 'slack-message-pins-remove
    ",mm" 'slack-message-write-another-buffer
    ",me" 'slack-message-edit
    ",md" 'slack-message-delete
    ",u" 'slack-room-update-messages
    ",2" 'slack-message-embed-mention
    ",3" 'slack-message-embed-channel
    "\C-n" 'slack-buffer-goto-next-message
    "\C-p" 'slack-buffer-goto-prev-message)
   (evil-define-key 'normal slack-edit-message-mode-map
    ",k" 'slack-message-cancel-edit
    ",s" 'slack-message-send-from-buffer
    ",2" 'slack-message-embed-mention
    ",3" 'slack-message-embed-channel))

(use-package alert
  :commands (alert)
  :init
  (setq alert-default-style 'notifier))

How to get token and cookie

  1. Using Chrome, open and sign into the slack customization page, e.g. https://my.slack.com/customize
  2. Right click anywhere on the page and choose "inspect" from the context menu. This will open the Chrome developer tools.
  3. Find the console (it's one of the tabs in the developer tools window)
  4. At the prompt ("> ") type the following: window.prompt("your api token is: ", TS.boot_data.api_token)
  5. Copy the displayed token elsewhere.
  6. If your token starts with xoxc then keep following the other steps below, otherwise you are done and can close the window.
  7. Now switch to the Applications tab in the Chrome developer tools (or Storage tab in Firefox developer tools).
  8. Expand Cookies in the left-hand sidebar.
  9. Click the cookie entry named d and copy its value. Note, use the default encoded version, so don't click the Show URL decoded checkbox.
  10. Now you're done and can close the window.

For further explanation, see the documentation for the emojme project: (github.com/jackellenberger/emojme)

Note that it is only possible to obtain the cookie manually, not through client-side javascript, due to it being set as HttpOnly and Secure. See OWASP HttpOnly.

How to secure your token

If someone steals your token they can use the token to impersonate you, reading and posting to Slack as if they were you. It's important to take reasonable precautions to secure your token.

One way to do this is by using the Emacs auth-source library. Read the auth-source documentation to learn how to use it to store login information for remote services.

Then configure the auth-sources variable to select a "backend" store. The default backend is ~/.authinfo file, which is simple but also un-encrypted. A more complex option is to encrypt that .~/authinfo file with gnupg and configure auth-sources to use ~/.authinfo.gpg as the source for all passwords and secrets. Other backends exist beyond these; read the documentation for details.

How to store your slack tokens in your auth-source backend will vary depending which backend you chose. See documentation for details. The "host" and "user" fields can be whatever you like as long as they are unique; as a suggestion use "myslackteam.slack.com" for host, and use your email address for user. The "secret" or "password" field should contain the token you obtained earlier (How to get token and cookie).

Do the same for the cookie, however for the "user" field append ^cookie, so if for the token you picked user@email.com then for the cookie use user@email.com^cookie.

Then finally, in your Emacs init read the token from your auth-source:

(slack-register-team
 :name "myslackteam"
 :token (auth-source-pick-first-password
         :host "myslackteam.slack.com"
         :user "me@example.com")
 :subscribed-channels '((channel1 channel2)))

If your token starts with xoxc you'll also need to manually obtain the cookie as described in How to get token and cookie and make sure the "user" has ^cookie in it as described above in How to secure your token:

(slack-register-team
 :name "myslackteam"
 :token (auth-source-pick-first-password
         :host "myslackteam.slack.com"
         :user "me@example.com")
 :cookie (auth-source-pick-first-password
         :host "myslackteam.slack.com"
         :user "me@example.com^cookie")
 :subscribed-channels '((channel1 channel2)))

If you do not specify :cookie then you'll automatically be prompted for one if you are using an xoxc token.

How to use

I recommend to chat with slackbot for tutorial using slack-im-select.

Some terminology in the slack- functions:

Notification

See alert.