Skip to content

Commit

Permalink
updates from upstream
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 4fad58d9ed107b52f2caf3a6242d0fa59fda5c6f
Author: Ben Robbins <[email protected]>
Date:   Mon Feb 23 14:44:39 2015 -0600

    merge fixes

commit f7b62edcf39e21d284c8a097e6e9e98c4cb337a0
Author: Ben Robbins <[email protected]>
Date:   Mon Feb 23 14:29:44 2015 -0600

    fix merge

commit 286bcdf31ee7ddd297d59cf7c1d4854c13b22581
Merge: a9ddb13 743fa06
Author: Ben Robbins <[email protected]>
Date:   Mon Feb 23 14:24:29 2015 -0600

    Merge branch 'master' of github.com:slackhq/hubot-slack into hubot-slack

    Conflicts:
    	README.md
    	package.json
    	src/slack.coffee
    	test/slack.coffee

commit 743fa06
Author: Evan Solomon <[email protected]>
Date:   Tue Feb 17 11:06:27 2015 -0800

    Make min message length a static property and add a test

    Fixes slackapi#156

commit 1773263
Author: bouzuya <[email protected]>
Date:   Tue Feb 17 21:26:41 2015 +0900

    ignore empty message

commit 7b2bd56
Merge: db92398 dc2ded2
Author: Paul Hammond <[email protected]>
Date:   Fri Jan 30 16:35:04 2015 -0800

    Merge pull request slackapi#145 from charlessuh/real-name

    Store real name in Hubot brain

commit db92398
Merge: c4b1b91 4d4a0b4
Author: Paul Hammond <[email protected]>
Date:   Fri Jan 30 16:21:55 2015 -0800

    Merge pull request slackapi#141 from shokai/error_tostring

    use JSON.stringify to print Error object

commit dc2ded2
Author: Charles Suh <[email protected]>
Date:   Fri Jan 23 12:51:48 2015 -0800

    Store real name in Hubot brain

commit 4d4a0b4
Author: Sho Hashimoto <[email protected]>
Date:   Sun Jan 11 16:51:17 2015 +0900

    use JSON.stringify to print Error object

commit c4b1b91
Merge: 3c915db 1c49e4d
Author: Paul Hammond <[email protected]>
Date:   Mon Jan 5 18:37:44 2015 -0800

    Merge pull request slackapi#133 from kballard/bot-messages

    Create new Message types for slack messages

commit 1c49e4d
Author: Kevin Ballard <[email protected]>
Date:   Mon Dec 22 16:31:40 2014 -0800

    Use Hubot.Message directly with Hubot >= 2.11.0

    Hubot 2.11.0 now exports Message directly, so we can stop pulling out
    TextMessage's superclass. We still need the workaround when using older
    versions of Hubot.

commit 3c915db
Merge: 4d8bc12 2256e70
Author: Paul Hammond <[email protected]>
Date:   Mon Dec 22 11:57:32 2014 -0800

    Merge pull request slackapi#130 from paulhammond/close-fix

    Rename close handler (fixes slackapi#126)

commit e823160
Author: Kevin Ballard <[email protected]>
Date:   Fri Dec 19 00:30:14 2014 -0800

    Add a bunch more message tests

commit 5b86509
Author: Kevin Ballard <[email protected]>
Date:   Fri Dec 19 00:29:18 2014 -0800

    Tweak SlackTextMessage, SlackRawMessage to have .rawMessage

    Add `rawMessage` property to `SlackTextMessage` that contains the
    original message. This is in addition to `rawText` which we're keeping.

    Change `SlackRawMessage` to use the same `rawMessage` property instead
    of copying all the message properties onto itself.

commit f02fd01
Author: Kevin Ballard <[email protected]>
Date:   Thu Dec 18 18:39:24 2014 -0800

    Add a couple of basic tests for SlackTextMessage

    More tests are coming.

commit a8ce172
Author: Kevin Ballard <[email protected]>
Date:   Thu Dec 18 18:38:28 2014 -0800

    Tweak SlackRawMessage to only copy own properties

    SlackRawMessage copies its properties from the slack-client Message
    object. It should only be copying own properties, though, or it ends up
    with functions that Message defines (which it turns out are enumerable).

commit 9ad99ee
Author: Kevin Ballard <[email protected]>
Date:   Thu Dec 18 18:37:01 2014 -0800

    Expand the test stubs

    * Add more information to the stubs.
    * Tweak the stubbed functions to behave slightly more like the real ones
      (e.g. test channel name / id before returning).
    * Fix the channel name used in some of the tests to match our stub
      channel.
    * Attach a real Hubot Brain to the stub robot.
    * Call SlackBot.loggedIn before each test, to ensure more of the bot is
      initialized.

commit c522e95
Author: Kevin Ballard <[email protected]>
Date:   Thu Dec 18 18:36:39 2014 -0800

    Fix some miscellaneous typos in the test descriptions

commit 04ae085
Author: Kevin Ballard <[email protected]>
Date:   Thu Dec 18 14:14:23 2014 -0800

    Extract test stubs into their own file

commit 4f79aec
Author: Kevin Ballard <[email protected]>
Date:   Thu Dec 18 14:02:24 2014 -0800

    Convert test stubs to @vars

    This makes it possible to add more test files later and still get at the
    stubs.

commit 178896a
Author: Kevin Ballard <[email protected]>
Date:   Thu Dec 18 12:49:03 2014 -0800

    Add some comments on how to use the new listeners

commit 47b4c0b
Author: Kevin Ballard <[email protected]>
Date:   Wed Dec 17 21:37:07 2014 -0800

    Create new Message types for slack messages

    Regular text messages now use a TextMessage subclass called
    SlackTextMessage, which includes both the parsed text (as `text`) and
    the unparsed text (as `rawText`).

    Other messages that used to be ignored are now received as either
    SlackRawMessage or SlackBotMessage. These do not descend from
    TextMessage so they won't be seen by normal `hear` or `respond`
    listeners.

    A few new Listener classes were created, SlackRawListener and
    SlackBotListener, to make it slightly easier to write code tailored for
    these new message types.

commit 4d8bc12
Merge: 64d7c57 ea562ae
Author: Paul Hammond <[email protected]>
Date:   Wed Dec 17 22:36:50 2014 -0800

    Merge pull request slackapi#131 from slackhq/better-formatting-removal

    Better formatting code

commit ea562ae
Author: Paul Hammond <[email protected]>
Date:   Wed Dec 17 19:05:39 2014 -0800

    Correctly decode entities from messages

commit a01dbc0
Author: Paul Hammond <[email protected]>
Date:   Wed Dec 17 19:01:24 2014 -0800

    Much better link formatting based on feedback from @kballard

commit 2256e70
Author: Paul Hammond <[email protected]>
Date:   Wed Dec 17 18:45:28 2014 -0800

    Rename close handler (fixes slackapi#126)

commit 64d7c57
Merge: f3a288b d9c8d1c
Author: Paul Hammond <[email protected]>
Date:   Wed Dec 17 11:57:51 2014 -0800

    Merge pull request slackapi#125 from paulhammond/mailto-fix

    Strip mailto: from mailto: links

commit d9c8d1c
Author: Paul Hammond <[email protected]>
Date:   Wed Dec 17 09:25:57 2014 -0800

    Strip mailto: from mailto: links

commit f3a288b
Author: Myles Grant <[email protected]>
Date:   Tue Dec 16 21:34:02 2014 -0800

    release 3.2.1

commit ea8c35b
Merge: d8c2342 c9f6870
Author: Paul Hammond <[email protected]>
Date:   Tue Dec 16 21:30:55 2014 -0800

    Merge pull request slackapi#124 from paulhammond/issue-123-fix

    Handle existing hubot brains with incomplete user data

commit c9f6870
Author: Paul Hammond <[email protected]>
Date:   Tue Dec 16 21:21:10 2014 -0800

    Handle existing hubot brains with incomplete user data

commit d8c2342
Author: Myles Grant <[email protected]>
Date:   Tue Dec 16 14:16:28 2014 -0800

    release 3.2.0

commit 7284bba
Author: Paul Hammond <[email protected]>
Date:   Tue Dec 16 14:09:22 2014 -0800

    Document HUBOT_AUTH_ADMIN (fixes slackapi#95)

commit 08ac424
Merge: 86163dc 426f16d
Author: Paul Hammond <[email protected]>
Date:   Tue Dec 16 14:07:51 2014 -0800

    Merge pull request slackapi#122 from paulhammond/remove-formatting

    More formatting fixes

commit 426f16d
Author: Paul Hammond <[email protected]>
Date:   Tue Dec 16 13:59:46 2014 -0800

    Better comments on link regex

commit c1fec0c
Author: Paul Hammond <[email protected]>
Date:   Tue Dec 16 13:50:51 2014 -0800

    Remove formatting around non-slack links

commit 274dc28
Author: Paul Hammond <[email protected]>
Date:   Tue Dec 16 13:25:34 2014 -0800

    Remove all special slack formatting, not just <@U1234>

commit 86163dc
Merge: 29fd355 7d7aa62
Author: Evan Solomon <[email protected]>
Date:   Tue Dec 16 13:14:07 2014 -0800

    Merge pull request slackapi#121 from bnied/master

    terminate Hubot when Slack disconnects

commit 29fd355
Merge: ff7685e 703533d
Author: Paul Hammond <[email protected]>
Date:   Tue Dec 16 13:03:41 2014 -0800

    Merge pull request slackapi#120 from paulhammond/reply-fix

    Fix @user mentions

commit 703533d
Author: Paul Hammond <[email protected]>
Date:   Tue Dec 16 08:46:43 2014 -0800

    Get users from client when removing message formatting

commit 90205dc
Author: Paul Hammond <[email protected]>
Date:   Mon Dec 15 19:36:34 2014 -0800

    Remove <@U1234> formatting before passing message onto hubot

commit ff7685e
Merge: aadb994 db20579
Author: Paul Hammond <[email protected]>
Date:   Mon Dec 15 16:08:59 2014 -0800

    Merge pull request slackapi#113 from paulhammond/user-changes

    User changes (fixes slackapi#56, slackapi#94, slackapi#118)

commit aadb994
Author: Paul Hammond <[email protected]>
Date:   Mon Dec 15 15:59:52 2014 -0800

    Better documentation on channel management

commit db20579
Author: Paul Hammond <[email protected]>
Date:   Mon Dec 15 15:53:38 2014 -0800

    Merge users with hubot brain instead of overwriting

commit 7d7aa62
Author: Benjamin Nied <[email protected]>
Date:   Sun Dec 14 15:26:15 2014 -0500

    terminate Hubot when Slack disconnects us

commit 4693ccd
Author: Paul Hammond <[email protected]>
Date:   Wed Dec 10 21:53:50 2014 -0800

    Remove outdated attachments docs (this will be coming back, see slackapi#108 for details)

commit d9fc654
Author: Paul Hammond <[email protected]>
Date:   Tue Dec 9 23:08:14 2014 -0800

    Better fetching & checking of message users

commit df9519c
Author: Paul Hammond <[email protected]>
Date:   Tue Dec 9 22:36:16 2014 -0800

    Store all users in hubot brain on login, keep them updated as they change

commit cf2db2f
Merge: 940fad0 5338f91
Author: Evan Solomon <[email protected]>
Date:   Wed Dec 10 00:32:29 2014 -0800

    Merge pull request slackapi#112 from slackhq/die-on-error

    Fail harder on errors

commit 5338f91
Author: Evan Solomon <[email protected]>
Date:   Wed Dec 10 00:29:40 2014 -0800

    Wait 1 second to exit to give in flight requests some chance to succeed

commit 940fad0
Author: Evan Solomon <[email protected]>
Date:   Tue Dec 9 22:28:28 2014 -0800

    This trailing space was really annoying me

commit 107752f
Author: Evan Solomon <[email protected]>
Date:   Tue Dec 9 22:19:28 2014 -0800

    Fail harder on errors

    Currently if the client emits an error we log it but just hang around.
    The app is in an undefined state at that point so it's hard to say
    what exactly will happen, but it's probably not ideal.

    At least this way a process monitor can tell that it died and restart
    it, ship the logs somewhere, or something.

commit 12c1f5e
Merge: c57f7ec 3ef146f
Author: Evan Solomon <[email protected]>
Date:   Tue Dec 9 22:16:50 2014 -0800

    Merge pull request slackapi#111 from slackhq/long-messages

    Improve long message splitting and add tests

commit 3ef146f
Author: Evan Solomon <[email protected]>
Date:   Tue Dec 9 22:11:04 2014 -0800

    Try to split long messages on word breaks if there are no line breaks

commit 6fec098
Author: Evan Solomon <[email protected]>
Date:   Tue Dec 9 21:47:18 2014 -0800

    Add tests for long message splitting

commit c57f7ec
Merge: ae6f0ad c6982ee
Author: Evan Solomon <[email protected]>
Date:   Tue Dec 9 21:45:04 2014 -0800

    Merge pull request slackapi#107 from redhotvengeance/split-long-messages

    Split up messages if longer than 4000 chars

commit ae6f0ad
Merge: f6a7c71 40de33f
Author: Paul Hammond <[email protected]>
Date:   Tue Dec 9 21:42:32 2014 -0800

    Merge pull request slackapi#110 from paulhammond/users

    Better handling of users (fixes slackapi#93)

commit 40de33f
Author: Paul Hammond <[email protected]>
Date:   Tue Dec 9 21:31:10 2014 -0800

    Better handling of users (fixes slackapi#93)

commit c6982ee
Author: Ian Lollar <[email protected]>
Date:   Tue Dec 9 19:37:18 2014 -0800

    Avoid splitting messages w/ new lines <= 4000 char

commit 218012d
Author: Ian Lollar <[email protected]>
Date:   Tue Dec 9 17:57:37 2014 -0800

    Refactor and reorganize message splitting

commit 5f8ba72
Merge: 6d7b44f f6a7c71
Author: Ian Lollar <[email protected]>
Date:   Tue Dec 9 16:13:22 2014 -0800

    Merge branch 'master' into split-long-messages

commit 6d7b44f
Author: Ian Lollar <[email protected]>
Date:   Tue Dec 9 15:53:56 2014 -0800

    Split up messages if longer than 4000 chars

commit f6a7c71
Author: Paul Hammond <[email protected]>
Date:   Tue Dec 9 15:28:53 2014 -0800

    Add hubot to dev dependencies so tests pass on travis

commit 6afbc1b
Author: Myles Grant <[email protected]>
Date:   Tue Dec 9 07:17:58 2014 -0800

    release 3.1.0

commit 9ff48a5
Merge: dd265c8 cf62a2a
Author: Myles Grant <[email protected]>
Date:   Tue Dec 9 07:16:39 2014 -0800

    Merge branch 'master' of github.com:slackhq/hubot-slack

commit cf62a2a
Merge: 1b79c65 3320c36
Author: Myles Grant <[email protected]>
Date:   Tue Dec 9 07:15:21 2014 -0800

    Merge pull request slackapi#103 from danielsmink/patch-1

    Update package.json

commit 3320c36
Author: Daniël Smink <[email protected]>
Date:   Tue Dec 9 07:12:27 2014 +0100

    Update package.json

    Update version number.

commit 1b79c65
Merge: 15c84de 2c916ce
Author: Evan Solomon <[email protected]>
Date:   Mon Dec 8 14:35:47 2014 -0800

    Merge pull request slackapi#101 from wingrunr21/fix_topic_signature

    Fix topic function signature

commit 15c84de
Merge: b0d49f0 0ae3f90
Author: Paul Hammond <[email protected]>
Date:   Mon Dec 8 11:53:03 2014 -0800

    Merge pull request slackapi#100 from technicalpickles/patch-1

    Update Upgrade instructions to use npm from npm instead of from git

commit 0ae3f90
Author: Josh Nichols <[email protected]>
Date:   Mon Dec 8 14:45:05 2014 -0500

    Update Upgrade instructions to use npm from npm instead of from git

commit 2c916ce
Author: Stafford Brunk <[email protected]>
Date:   Mon Dec 8 14:40:39 2014 -0500

    Fix topic function signature

commit dd265c8
Author: Myles Grant <[email protected]>
Date:   Mon Dec 8 10:12:34 2014 -0800

    release 3.0.0

commit b0d49f0
Author: Paul Hammond <[email protected]>
Date:   Mon Dec 8 09:06:54 2014 -0800

    Update URLs to github.com/slackhq

commit 79acbcf
Author: Paul Hammond <[email protected]>
Date:   Sat Dec 6 16:48:05 2014 -0800

    Begin to update tests

commit 6a9e10e
Author: Paul Hammond <[email protected]>
Date:   Sat Dec 6 16:00:31 2014 -0800

    Update README to reflect new yeoman based hubot install system

commit 0e2eaf7
Author: Paul Hammond <[email protected]>
Date:   Thu Oct 23 11:15:39 2014 -0700

    Handle Topic changes correctly

commit d52c86b
Author: Paul Hammond <[email protected]>
Date:   Thu Oct 23 10:53:36 2014 -0700

    Don't crash when recieving file_comment messages

commit e55a305
Author: Paul Hammond <[email protected]>
Date:   Wed Oct 22 11:36:11 2014 -0700

    Don't log the secret token

commit 8950b23
Author: Paul Hammond <[email protected]>
Date:   Wed Oct 22 11:35:49 2014 -0700

    Fail gracefully if someone provides a old integration token

commit 9a7f5ba
Author: Paul Hammond <[email protected]>
Date:   Wed Oct 22 11:23:58 2014 -0700

    Update README with upgrade instructions

commit 0a0c0d3
Author: Paul Hammond <[email protected]>
Date:   Wed Oct 22 10:22:08 2014 -0700

    Don't crash when recieving a bot_message

commit ef1e2c7
Author: Paul Hammond <[email protected]>
Date:   Tue Oct 21 19:37:13 2014 -0700

    Update README

commit c599dde
Author: Paul Hammond <[email protected]>
Date:   Tue Oct 21 19:29:27 2014 -0700

    Update Copyright statements to reflect our new legal name

commit 76a00f6
Author: Paul Hammond <[email protected]>
Date:   Mon Sep 22 09:36:26 2014 -0700

    Remove dev path hacks

commit f2a62bf
Author: Paul Hammond <[email protected]>
Date:   Mon Sep 22 09:36:00 2014 -0700

    slack-client is a runtime dependency

commit 6e425ad
Author: Myles Grant <[email protected]>
Date:   Fri Sep 19 22:08:30 2014 -0700

    We want the most recent version of node-slack

commit 9386ffa
Author: Myles Grant <[email protected]>
Date:   Thu Aug 28 16:21:55 2014 -0700

    Pretend that DM messages were really addressed to us

commit 101f526
Author: Myles Grant <[email protected]>
Date:   Thu Aug 28 14:17:50 2014 -0700

    Add some TODOs

commit 24eaa9f
Author: Myles Grant <[email protected]>
Date:   Wed Jul 30 10:02:27 2014 -0700

    Pedantry

commit 09aa88c
Author: Myles Grant <[email protected]>
Date:   Sat May 10 16:54:19 2014 -0700

    Whoops, process slack user into hubot user before running through the enter/leave/topic functions

commit 3e237a5
Author: Myles Grant <[email protected]>
Date:   Sat May 10 13:52:47 2014 -0700

    Fix support for channel/group join/leave, and add support for channel/group topic notifications

commit 02b45b8
Author: Myles Grant <[email protected]>
Date:   Sat May 10 13:39:20 2014 -0700

    Support for channel/group join/leave notifications

commit 7095a76
Author: Myles Grant <[email protected]>
Date:   Fri May 9 22:53:44 2014 -0700

    Fix typo references to the client

commit f7cec4e
Author: Myles Grant <[email protected]>
Date:   Fri May 9 22:52:23 2014 -0700

    Some cleanup, and a hacky hubot path to get around stupid local npm issues

commit d95097a
Author: Myles Grant <[email protected]>
Date:   Mon May 5 10:52:44 2014 -0700

    Clean

commit 326b3f0
Author: Myles Grant <[email protected]>
Date:   Sun May 4 20:32:46 2014 -0700

    Sending messages, setting topics

commit c14b4d1
Author: Myles Grant <[email protected]>
Date:   Sun May 4 19:31:51 2014 -0700

    Dumping almost everything and starting over. Have the basics of connecting and receiving messages working

commit f181a19
Author: Myles Grant <[email protected]>
Date:   Sun Apr 13 10:26:49 2014 -0700

    Starting to move things around for the new client adapter
  • Loading branch information
b3nj4m committed Feb 23, 2015
1 parent a9ddb13 commit f6c7e36
Show file tree
Hide file tree
Showing 11 changed files with 712 additions and 660 deletions.
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) Tiny Speck, Inc.
Copyright (c) Slack Technologies, Inc.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand All @@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
97 changes: 30 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ This is a [Brobbot](https://npmjs.org/package/brobbot) adapter to use with [Slac

#### Adding Slack adapter

- `npm install brobbot-slack --save`
- Check out the [brobbot docs](https://github.com/b3nj4m/hubot/tree/master/docs/README.md) for further guidance on how to build your bot
In your [brobbot-instance](https://github.com/b3nj4m/brobbot-instance):

```bash
npm install brobbot-slack --save
```

Check out the [brobbot docs](https://github.com/b3nj4m/hubot/tree/master/docs/README.md) for further guidance on how to build your bot

#### Testing your bot instance locally

- `./index.sh -a slack`
- `BROBBOT_SLACK_TOKEN=xoxb-1234-5678-91011-00e4dd ./index.sh -a slack`

#### Deploying to Heroku

Expand All @@ -20,7 +25,7 @@ This is a modified set of instructions based on the [instructions on the Brobbot
- Make sure `brobbot-slack` is in your `package.json` dependencies
- Edit your `Procfile` and change it to use the `slack` adapter:

web: ./index.sh --adapter slack
web: ./index.sh -a slack

- Install [heroku toolbelt](https://toolbelt.heroku.com/) if you haven't already.
- `heroku create my-company-slackbot`
Expand All @@ -30,8 +35,6 @@ This is a modified set of instructions based on the [instructions on the Brobbot

% heroku config:add HEROKU_URL=http://soothing-mists-4567.herokuapp.com
% heroku config:add BROBBOT_SLACK_TOKEN=dqqQP9xlWXAq5ybyqKAU0axG
% heroku config:add BROBBOT_SLACK_TEAM=myteam
% heroku config:add BROBBOT_SLACK_BOTNAME=slack-brobbot

- Deploy and start the bot:

Expand All @@ -40,72 +43,32 @@ This is a modified set of instructions based on the [instructions on the Brobbot

- Profit!

## Adapter configuration

This adapter uses the following environment variables:

#### BROBBOT\_SLACK\_TOKEN

This is the service token you are given when you add Brobbot to your Team Services.

#### BROBBOT\_SLACK\_TEAM

This is your team's Slack subdomain. For example, if your team is `https://myteam.slack.com/`, you would enter `myteam` here.

#### BROBBOT\_SLACK\_BOTNAME

Optional. What your Brobbot is called on Slack. If you entered `slack-brobbot` here, you would address your bot like `slack-brobbot: help`. Otherwise, defaults to `slackbot`.

#### BROBBOT\_SLACK\_CHANNELMODE

Optional. If you entered `blacklist`, Brobbot will not post in the rooms specified by BROBBOT_SLACK_CHANNELS, or alternately *only* in those rooms if `whitelist` is specified instead. Defaults to `blacklist`.

#### BROBBOT\_SLACK\_CHANNELS
## Upgrading from earlier versions of Hubot

Optional. A comma-separated list of channels to either be blacklisted or whitelisted, depending on the value of BROBBOT_SLACK_CHANNELMODE.
Version 3 of the brobbot-slack adapter requires different server support to
previous versions. If you have an existing "hubot" integration set up you'll
need to upgrade:

#### BROBBOT\_SLACK\_LINK\_NAMES
- Go to https://my.slack.com/services/new/hubot and create a new hubot
integration
- Run `npm install brobbot-slack --save`
to update your code.
- Test your bot instance locally using:
`BROBBOT_SLACK_TOKEN=xoxb-1234-5678-91011-00e4dd ./index.sh -a slack`
- Update your production startup scripts to pass the new `BROBBOT_SLACK_TOKEN`.
You can remove the other `BROBBOT_SLACK_*` environment variables if you want.
- Deploy your new brobbot to production.
- Once you're happy it works, remove the old hubot integration from
https://my.slack.com/services

Optional. By default, Slack will not linkify channel names (starting with a '#') and usernames (starting with an '@'). You can enable this behavior by setting BROBBOT_SLACK_LINK_NAMES to 1. Otherwise, defaults to 0. See [Slack API : Message Formatting Docs](https://api.slack.com/docs/formatting) for more information.
## Configuration

## Under the Hood

#### Receiving Messages:

The slack adapter adds a path to the robot's router that will accept POST requests to:

`/hubot/slack-webhook`

Expected parameters:

- text
- user_id
- user_name
- channel_id
- channel_name

If there is a message and it can deduce an author from those paramters, it'll create a new `TextMessage` object and have the robot receive it, from there proceeding down the regular brobbot path.

#### Sending Messages

When a script calls `send()` or `reply()` this adapter makes a POST request to your team's specific URL webhook:

`https://<your_team_name>.slack.com/services/hooks/hubot`

with a JSON-formatted body including the following dictionary:

- username
- channel
- text
- link_names (optionally)
This adapter uses the following environment variables:

#### Message to a specific room:
- `BROBBOT_SLACK_TOKEN` - this is the API token for the Slack user you would like to run Hubot under.

Sometime, it's useful to send a message regardless of the channel's activity (like `robot.hear` or `robot.response`). Brobbot has `robot.messageRoom` available for this use case.
To add or remove your bot from specific channels or private groups, you can use the /kick and /invite slash commands that are built into Slack.

Slack API uses channel ID's by default, which uses computer-friendly alphanumeric ID. To use the pretty names, prefix it with a hash.
## Copyright

```coffeescript
robot.respond /hello$/i, (msg) ->
robot.messageRoom '#general', 'hello there'
```
Copyright &copy; Slack Technologies, Inc. MIT License; see LICENSE for further details.
62 changes: 0 additions & 62 deletions docs/attachements.md

This file was deleted.

15 changes: 15 additions & 0 deletions index.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
SlackBot = require './src/slack'
{SlackTextMessage, SlackRawMessage, SlackBotMessage} = require './src/message'
{SlackRawListener, SlackBotListener} = require './src/listener'

module.exports = exports = {
SlackBot
SlackTextMessage
SlackRawMessage
SlackBotMessage
SlackRawListener
SlackBotListener
}

exports.use = (robot) ->
new SlackBot robot
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,26 @@
"url": "https://github.com/b3nj4m/hubot-slack/issues"
},
"peerDependencies": {
"brobbot": "3.x - 4.x"
"brobbot": "^4.0.4"
},
"devDependencies": {
"brobbot": "^4.0.4",
"coffee-script": "~1.7.1",
"grunt": "~0.4.1",
"grunt-contrib-watch": "~0.5.3",
"grunt-release": "~0.6.0",
"should": "~2.0.2",
"grunt-shell": "~0.5.0",
"mocha": "~1.13.0",
"brobbot": "~3.5.2",
"grunt-contrib-watch": "~0.5.3",
"grunt-shell": "~0.5.0"
"should": "~2.0.2"
},
"main": "./src/slack",
"main": "./index",
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "mocha --compilers coffee:coffee-script/register --reporter spec"
},
"dependencies": {
"slack-client": "~1.2.0"
}
}
46 changes: 46 additions & 0 deletions src/listener.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{Listener} = require 'brobbot'
{SlackRawMessage, SlackBotMessage} = require './message'

class SlackRawListener extends Listener
# SlackRawListeners receive SlackRawMessages from the Slack adapter
# and decide if they want to act on it.
#
# robot - A Robot instance.
# matcher - A Function that determines if this listener should trigger the
# callback. The matcher takes a SlackRawMessage.
# callback - A Function that is triggered if the incoming message matches.
#
# To use this listener in your own script, you can say
#
# robot.listeners.push new SlackRawListener(robot, matcher, callback)
constructor: (@robot, @matcher, @callback) ->

# Public: Invokes super only for instances of SlackRawMessage
call: (message) ->
if message instanceof SlackRawMessage
super message
else
false

class SlackBotListener extends Listener
# SlackBotListeners receive SlackBotMessages from the Slack adapter
# and decide if they want to act on it. SlackBotListener will only
# match instances of SlackBotMessage.
#
# robot - A Robot instance.
# regex - A Regex that determines if this listener should trigger the
# callback.
# callback - A Function that is triggered if the incoming message matches.
#
# To use this listener in your own script, you can say
#
# robot.listeners.push new SlackBotListener(robot, regex, callback)
constructor: (@robot, @regex, @callback) ->
@matcher = (message) =>
if message instanceof SlackBotMessage
message.match @regex

module.exports = {
SlackRawListener
SlackBotListener
}
50 changes: 50 additions & 0 deletions src/message.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{Message, TextMessage} = require 'brobbot'

class SlackTextMessage extends TextMessage
# Represents a TextMessage created from the Slack adapter
#
# user - The User object
# text - The parsed message text
# rawText - The unparsed message text
# rawMessage - The Slack Message object
constructor: (@user, @text, @rawText, @rawMessage) ->
super @user, @text, @rawMessage.ts

class SlackRawMessage extends Message
# Represents Slack messages that are not suitable to treat as text messages.
# These are hidden messages, or messages that have no text / attachments.
#
# Note that the `user` property may be a "fake" user, i.e. one that does not
# exist in brobbot's brain and that contains little to no data.
#
# user - The User object
# text - The parsed message text, if any, or ""
# rawText - The unparsed message text, if any, or ""
# rawMessage - The Slack Message object
constructor: (@user, @text = "", @rawText = "", @rawMessage) ->
super @user

class SlackBotMessage extends SlackRawMessage
# Represents a message sent by a bot. Specifically, this is any message
# with the subtype "bot_message". Expect the `user` property to be a
# "fake" user.

# Determines if the message matches the given regex.
#
# regex - A Regex to check.
#
# Returns a Match object or null.
match: (regex) ->
@text.match regex

# String representation of a SlackBotMessage
#
# Returns the message text
toString: () ->
@text

module.exports = {
SlackTextMessage
SlackRawMessage
SlackBotMessage
}
Loading

0 comments on commit f6c7e36

Please sign in to comment.