Skip to content

Instantly share code, notes, and snippets.

@TheFo2sh
Last active April 4, 2020 20:53
Show Gist options
  • Save TheFo2sh/21705b410e07b121d72c89df6e28bfdf to your computer and use it in GitHub Desktop.
Save TheFo2sh/21705b410e07b121d72c89df6e28bfdf to your computer and use it in GitHub Desktop.
public static class Function1
{
[FunctionName("kofi")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]
HttpRequest req,
ILogger log)
{
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
requestBody = HttpUtility.UrlDecode(requestBody);
requestBody = requestBody.Split('=').Last();
log.Log(LogLevel.Information, requestBody);
var payload = JsonConvert.DeserializeObject<Payload>(requestBody);
var notificationHubClient = new NotificationHubClient("Endpoint=sb://webhooksample.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=53M3mioz9i1xgReCjJ", "koofihub");
var notificationResult =
await notificationHubClient.SendNotificationAsync(
new FcmNotification("{\"data\":{\"message\":\"" + payload.Message + "\"}}"));
log.Log(LogLevel.Information, "Notification delivered to {0} devices and failed {1} devices",
notificationResult.Success, notificationResult.Failure);
return new OkObjectResult(new object());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment