Skip to content

Instantly share code, notes, and snippets.

@marteinn
Created May 29, 2024 04:33
Show Gist options
  • Save marteinn/36c95aa7b24edfc9d8406cbd4d5dcde7 to your computer and use it in GitHub Desktop.
Save marteinn/36c95aa7b24edfc9d8406cbd4d5dcde7 to your computer and use it in GitHub Desktop.
Convert firebase BatchResponse to a JSON serializable struct
from typing import Dict, List
from firebase_admin.messaging import BatchResponse, SendResponse
def batch_response_to_dict(batch_response: BatchResponse) -> Dict:
responses: List[SendResponse] = batch_response.responses
return {
"responses": [
{
"message_id": x.message_id,
"success": x.success,
"exception": str(x.exception) if x.exception else None,
}
for x in responses
],
"success_count": batch_response.success_count,
"failure_count": batch_response.failure_count,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment