Skip to content

Instantly share code, notes, and snippets.

@KyMidd
Created December 27, 2024 19:35
Show Gist options
  • Select an option

  • Save KyMidd/e63562d8386bed0fb63ea5c9ef74c4cb to your computer and use it in GitHub Desktop.

Select an option

Save KyMidd/e63562d8386bed0fb63ea5c9ef74c4cb to your computer and use it in GitHub Desktop.
# Check for duplicate events
def check_for_duplicate_event(headers, payload):
# Debug
if os.environ.get("VERA_DEBUG", "False") == "True":
print("πŸš€ Headers:", headers)
print("πŸš€ Payload:", payload)
# Check headers, if x-slack-retry-num is present, this is a re-send
# Really we should be doing async lambda model, but for now detecting resends and exiting
if "x-slack-retry-num" in headers:
print("❌ Detected a re-send, exiting")
logging.info("❌ Detected a re-send, exiting")
return True
# Check if edited message in local development
if "edited" in payload:
print("Detected a message edited event, responding with http 200 and exiting")
return True
# If bot_id is in event, this is a message from the bot, ignore
if "bot_id" in payload:
print("Message from bot detected, discarding")
logging.info("Detected a duplicate event, discarding")
return True
# If body event message subtype is tombstone, this is a message deletion event, ignore
if (
"subtype" in payload.get("message", {})
and payload["message"]["subtype"] == "tombstone"
):
print("Detected a tombstone event, discarding")
logging.info("Detected a tombstone event, discarding")
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment