-
-
Save KyMidd/e63562d8386bed0fb63ea5c9ef74c4cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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