Skip to content

Commit 0f2021c

Browse files
committed
Merge pull request #119 from nishimaki10/ability-edited
Add ability to respond to edited messages
2 parents 092ef35 + 9d9788a commit 0f2021c

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ ROCKETCHAT_AUTH | defaults to 'password' if undefinied, or set to 'ldap' if your
132132
ROCKETCHAT_ROOM | the channel/channels names the bot should listen to message from. This can be comma separated list.
133133
LISTEN_ON_ALL_PUBLIC | if 'true' then bot will listen and respond to messages from all public channels, as well as respond to direct messages. Default to 'false'. ROCKETCHAT_ROOM should be set to empty (with `ROCKETCHAT_ROOM=''` ) when using `LISTEN_ON_ALL_PUBLIC`. *IMPORTANT NOTE*: This option also allows the bot to listen and respond to messages _from all newly created private groups_ that the bot's user has been added as a member.
134134
RESPOND_TO_DM | if 'true' then bot will listen and respond to direct messages. When setting the option to 'true', be sure to also set ROCKETCHAT_ROOM. This option needs not be set if you are including LISTEN_ON_ALL_PUBLIC. Default is 'false'.
135+
RESPOND_TO_EDITED | if 'true' then bot will respond to edited messages. Default is 'false'.
135136
ROOM_ID_CACHE_SIZE | The maximum number of room IDs to cache. You can increase this if your bot usually sends messages to a large number of different rooms. Default value: 10
136137
DM_ROOM_ID_CACHE_SIZE | The maximum number of Direct Message room IDs to cache. You can increase this if your bot usually sends a large number of Direct Messages. Default value: 100
137138
ROOM_ID_CACHE_MAX_AGE | Room IDs and DM Room IDS are cached for this number of seconds. You can increase this value to improve performance in certain scenarios. Default value: 300

src/rocketchat.coffee

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ RocketChatUser = process.env.ROCKETCHAT_USER or "hubot"
2020
RocketChatPassword = process.env.ROCKETCHAT_PASSWORD or "password"
2121
ListenOnAllPublicRooms = process.env.LISTEN_ON_ALL_PUBLIC or "false"
2222
RespondToDirectMessage = process.env.RESPOND_TO_DM or "false"
23+
RespondToEditedMessage = (process.env.RESPOND_TO_EDITED or "false").toLowerCase()
2324
SSLEnabled = "false"
2425

2526
# Custom Response class that adds a sendPrivate and sendDirect method
@@ -128,6 +129,9 @@ class RocketChatBotAdapter extends Adapter
128129
if (newmsg.u._id isnt userid) || (newmsg.t is 'uj')
129130
if (newmsg.rid in room_ids) || (ListenOnAllPublicRooms.toLowerCase() is 'true') || ((RespondToDirectMessage.toLowerCase() is 'true') && (newmsg.rid.indexOf(userid) > -1))
130131
curts = new Date(newmsg.ts.$date)
132+
if (RespondToEditedMessage is 'true') and (newmsg.editedAt?.$date?)
133+
edited = new Date(newmsg.editedAt.$date)
134+
curts = if edited > curts then edited else curts
131135
@robot.logger.info "Message receive callback id " + newmsg._id + " ts " + curts
132136
@robot.logger.info "[Incoming] #{newmsg.u.username}: #{newmsg.msg}"
133137

0 commit comments

Comments
 (0)