Skip to content

Commit

Permalink
Merge pull request #3 from kyo-ago/master
Browse files Browse the repository at this point in the history
MessagesAPI is supported.
  • Loading branch information
akiomik committed Dec 5, 2014
2 parents 4c8b651 + de9cf3a commit e21661c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 32 deletions.
24 changes: 4 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,22 @@ A Hubot adapter for chatwork.

## Installation

1. Add `hubot-chatwork` to dependencies in your hubot's `package.json`.
```javascript
"dependencies": {
"hubot-chatwork": "0.0.5"
}
```

2. Install `hubot-chatwork`.
1. Install `hubot-chatwork`.
```sh
npm install
npm install hubot-chatwork --save
```

3. Set environment variables.
2. Set environment variables.
```sh
export HUBOT_CHATWORK_TOKEN="DEADBEEF" # see http://developer.chatwork.com/ja/authenticate.html
export HUBOT_CHATWORK_ROOMS="123,456" # comma separated
export HUBOT_CHATWORK_API_RATE="350" # request per hour
```

4. Run hubot with chatwork adapter.
3. Run hubot with chatwork adapter.
```sh
bin/hubot -a chatwork
```

## Note

`GET /rooms/{room_id}/messages` API is NOT provided yet from Chatwork.

* http://developer.chatwork.com/ja/endpoint_rooms.html#GET-rooms-room_id-messages

So Chatwork API will return `501` error response.


## License
The MIT License. See `LICENSE` file.
22 changes: 10 additions & 12 deletions src/chatwork.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,18 @@ class ChatworkStreaming extends EventEmitter
@post "#{baseUrl}/messages", body, callback

listen: =>
lastMessage = 0
setInterval =>
timeout = =>
@Room(id).Messages().show (err, messages) =>
for message in messages
if lastMessage < message.message_id
@emit 'message',
id,
message.message_id,
message.account,
message.body,
message.send_time,
message.update_time
lastMessage = message.message_id
, 1000 / (@rate / (60 * 60))
@emit 'message',
id,
message.message_id,
message.account,
message.body,
message.send_time,
message.update_time
setTimeout timeout, 1000 / (@rate / (60 * 60))
timeout()

Message: (mid) =>
show: (callback) =>
Expand Down

0 comments on commit e21661c

Please sign in to comment.