New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ignore echo messages from facebook #10097
base: main
Are you sure you want to change the base?
Conversation
According to messenger API documentation https://developers.facebook.com/docs/messenger-platform/reference/webhook-events/message-echoes/?locale=en_En, an echo message is also triggered for image, video, file, and audio attachments. These changes ignore those echo messages.
This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aristidednd Thank you for your contribution! 💯
Could you please add a changelog entry specifying the why and how of your improvement.
Also if possible please add unit test coverage.
@@ -45,6 +45,7 @@ def _is_audio_message(message: Dict[Text, Any]) -> bool: | |||
"message" in message | |||
and "attachments" in message["message"] | |||
and message["message"]["attachments"][0]["type"] == "audio" | |||
and not message["message"].get("is_echo") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think adding this in the different _is_<type>_message
checks leads to these methods having more than 1 purpose. I suggest instead extracting this boolean variable in a separate function _is_echo_message
and then adding this check once only at the top of the message
method before all the other checks:
async def message(
self, message: Dict[Text, Any], metadata: Optional[Dict[Text, Any]]
) -> None:
"""Handle an incoming event from the fb webhook."""
if self._is_echo_message(message):
logger.warning("Received a message echo from Facebook which will be ignored.")
return None
# quick reply and user message both share 'text' attribute
# so quick reply should be checked first
if self._is_quick_reply_message(message):
...
Tui chả hiểu hì :))) |
According to Facebook Messenger API documentation https://developers.facebook.com/docs/messenger-platform/reference/webhook-events/message-echoes/?locale=en_En, an echo message is also triggered for image, video, file, and audio attachments.
These changes ignore those echo messages.
Proposed changes:
Status (please check what you already did):
black
(please check Readme for instructions)