Skip to content
This repository has been archived by the owner on Sep 29, 2021. It is now read-only.

Commit

Permalink
fix(adapter): allow sending of MessageML
Browse files Browse the repository at this point in the history
adapter#send can be called with an object to send MessageML
  • Loading branch information
jonfreedman committed Aug 2, 2016
1 parent 316172f commit 34a2830
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ You must pass the following environment variables to hubot

These arguments are passed through to the NodeJs request module as described [here](https://github.com/request/request#tlsssl-protocol).

If you want to send a rich message you can call send with an Object instead of a String
```
module.exports = (robot) ->
robot.respond /pug me/i, (msg) ->
msg.http("http://pugme.herokuapp.com/random")
.get() (err, res, body) ->
pug = JSON.parse(body).pug
msg.send pug
msg.send {
format: 'MESSAGEML'
text: "<a href=\"#{pug}\"/>"
}
```

### Diagnostics
A simple diagnostic script is included to help confirm that you have all the necessary pieces to get started. You can run this as follows:

Expand Down
14 changes: 8 additions & 6 deletions src/adapter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ class SymphonyAdapter extends Adapter
throw new Error('HUBOT_SYMPHONY_PRIVATE_KEY undefined') unless process.env.HUBOT_SYMPHONY_PRIVATE_KEY
throw new Error('HUBOT_SYMPHONY_PASSPHRASE undefined') unless process.env.HUBOT_SYMPHONY_PASSPHRASE

send: (envelope, strings...) ->
send: (envelope, messages...) ->
@robot.logger.debug "Send"
for string in strings
@symphony.sendMessage(envelope.room, string, 'TEXT')
for message in messages
format = message.format ? 'TEXT'
text = message.text ? message
@symphony.sendMessage(envelope.room, text, format)

reply: (envelope, strings...) ->
reply: (envelope, messages...) ->
@robot.logger.debug "Reply"
for string in strings
@symphony.sendMessage(envelope.room, "<messageML><mention email=\"#{envelope.user.emailAddress}\"/> #{string}</messageML>", 'MESSAGEML')
for message in messages
@symphony.sendMessage(envelope.room, "<messageML><mention email=\"#{envelope.user.emailAddress}\"/> #{message}</messageML>", 'MESSAGEML')

run: =>
@robot.logger.info "Initialising..."
Expand Down
16 changes: 16 additions & 0 deletions test/adapter-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ describe 'Adapter test suite', () ->
done()
adapter.run()

it 'should send MESSAGEML', (done) ->
robot = new FakeRobot
adapter = SymphonyAdapter.use(robot)
adapter.on 'connected', () ->
assert.isDefined(adapter.symphony)
envelope = {room: nock.streamId}
adapter.send(envelope, {
format: 'MESSAGEML'
text: '<messageML><b>foo bar</b></messageML>'
})
adapter.close()
nock.on 'received', () ->
assert.isAtLeast((m for m in nock.messages when m.message is '<messageML><b>foo bar</b></messageML>').length, 1)
done()
adapter.run()

it 'should reply with @mention', (done) ->
robot = new FakeRobot
adapter = SymphonyAdapter.use(robot)
Expand Down

0 comments on commit 34a2830

Please sign in to comment.