From d8ea78ea91115b5b2cc2c5833707d79b1d3ca82f Mon Sep 17 00:00:00 2001 From: kyo_ago Date: Thu, 4 Dec 2014 15:33:30 +0900 Subject: [PATCH 1/2] MessagesAPI is supported. --- README.md | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 16e698e..6d5f973 100644 --- a/README.md +++ b/README.md @@ -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. From de9cf3affd692614908d8d81bd84a4e7e0d23e65 Mon Sep 17 00:00:00 2001 From: kyo_ago Date: Thu, 4 Dec 2014 15:35:04 +0900 Subject: [PATCH 2/2] refactoring listen method. --- src/chatwork.coffee | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/chatwork.coffee b/src/chatwork.coffee index 8fef17f..685937e 100644 --- a/src/chatwork.coffee +++ b/src/chatwork.coffee @@ -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) =>