[csharp] HttpTrigger Function
Viewer
- public class ZiflowEventListener
- {
- [FunctionName("ZiflowEventListener")]
- public static async Task<IActionResult> Run(
- [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger logger)
- {
- string requestBody = string.Empty;
- try
- {
- requestBody = await new StreamReader(req.Body).ReadToEndAsync();
- if (!string.IsNullOrEmpty(requestBody))
- {
- string entryCode = req.Query["Key"];
- string token = req.Headers["x-ziflow-signature"];
- if (SignatureValidator.IsValid(token, requestBody))
- {
- await using var producerClient = new EventHubProducerClient("EVENTHUB-CONNECTIONSTRING", "EVENTHUBNAME");
- using EventDataBatch eventBatch = await producerClient.CreateBatchAsync();
- eventBatch.TryAdd(new EventData(Encoding.UTF8.GetBytes(requestBody)));
- await producerClient.SendAsync(eventBatch);
- }
- else
- {
- return new UnauthorizedResult();
- }
- }
- }
- catch (Exception ex)
- {
- logger.LogError($"AE_Exception:Exception : {ex.Message}");
- throw;
- }
- return new OkResult();
- }
- }
Editor
You can edit this paste and save as new: