Last active
April 4, 2020 20:53
-
-
Save TheFo2sh/21705b410e07b121d72c89df6e28bfdf 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
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