Question: Our errbot is providing links to JIRA tickets when it sees the right ticket patterns. Unfortunately, in slack it is common for users to edit their posts, and if both edits contain the JIRA ticket pattern, errbot provides the link twice, it is annoying. 

Can I detect when a message is an edit as opposed to the original message?

Answer: 
Now you can because from the .extra argument on the messages you can get the message ID from slack.
My bot watches for and expands references to Jira issues too; one of the things I did was keep track of how many messages had been seen in the channel, and when the last time was that I responded to any given issue. Issues expanded within the last N (I use 10) messages are ignored. That way, if they edit the issue key itself they usually get a new expansion, but not if they edit other parts of the message.

```
def activate(self):
    self.messages_seen={} # room: messages seen
    self.last_shown={} # issue_key : { room : message number last shown }
    super().activate()

def callback_message(self, msg):
    if msg.is_group:
        try:
            self.messages_seen[msg.to.id] += 1
        except KeyError:
            self.messages_seen[msg.to.id] = 1

def record_expanded(self, msg, key, orig_key=None):
    if msg.is_group:
        channel=msg.to.id
        keys = [ key, orig_key ] if orig_key and orig_key != key else [ key ]
        for k in keys:
            if k in self.last_shown:
                self.last_shown[ k ][ channel ] = self.messages_seen[ channel ]
            else:
                self.last_shown[ k ] = { channel : self.messages_seen[ channel ] }

def should_expand(self, msg, key):
    expand=False
    if msg.body.split()[0] == 'jira':
        # User said 'jira <key>', so always expand
        expand=True
    if msg.is_group:
        channel=msg.to.id
        message_number=self.messages_seen.get(channel, 1)

        expanded_in = self.last_shown.get(key, {})
        if expanded_in:
            if channel not in expanded_in: # key has been expanded, but not in this channel
                expand=True
            else:
                expanded_last_here = message_number - expanded_in[channel]
                if expanded_last_here >= self.bot_config.JIRA_EXPAND_ONLY_EVERY: # not recently enough
                    expand=True
                else:
                    self.log.debug("not expanding '%s' because expanded %d messages ago" % (key, expanded_last_here))
        else:
            # this key has not been seen anywhere before
            expand=True
    else:
        # direct IM - always expand
        expand=True
    if not expand:
        self.log.debug("Recently expanded %s, suppressing" % key)
    return expand

```