public async Task<IActionResult> SendNotification([FromBody] NotificationRequest request)
{
// Validate the request
if (string.IsNullOrEmpty(request.Token) || string.IsNullOrEmpty(request.Title) || string.IsNullOrEmpty(request.Body))
{
return BadRequest("Invalid request.");
}
try
{
// Create a message to send
var message = new Message()
{
Token = request.Token,
Notification = new Notification()
{
Title = request.Title,
Body = request.Body
}
};
// Send the message
string response = await FirebaseMessaging.DefaultInstance.SendAsync(message);
// Return the response
return Ok(new { messageId = response });
}
catch (FirebaseMessagingException ex)
{
// Handle errors related to Firebase Messaging
return StatusCode(500, new
{
error = ex.Message,
status = ex.HttpResponse.StatusCode,
response = await ex.HttpResponse.Content.ReadAsStringAsync()
});
}
}
public class NotificationRequest
{
public string Token { get; set; }
public string Title { get; set; }
public string Body { get; set; }
}
that is my code but always have firebase messaging exception if anyone have firebase push notification video tutorial for .net core version 8 web api please send i am totally frusted now
firebase push notification for check by swagger
New contributor
Sanchay Gaurav is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.