Exemple #1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "tygerbytes/mailgun/webhook")] HttpRequest req,
            [Queue("email-outbox")] IAsyncCollector <EmailMessage> emailQueue,
            ILogger log)
        {
            var config  = FuncConfig.Instance;
            var context = new FuncContext
            {
                Config     = config,
                EmailQueue = emailQueue,
                Logger     = log,
                SpamFilter = SpamFilter.GetInstance()
            };

            var payload = await DeserializeRequestPayload(req);

            log.LogInformation(Utils.ToJson(payload));

            if (!payload.Signature.IsValid(config.MailgunWebhookSigningKey))
            {
                return(new ObjectResult("Invalid signature")
                {
                    // Mailgun will keep retrying unless we send a 406
                    StatusCode = 406
                });
            }

            var responseStrategy = ResponseStrategyFactory.GetStrategy(payload.EventData.Event);
            var result           = await responseStrategy.Execute(context, payload);

            return(result);
        }
Exemple #2
0
        internal static SpamFilter GetInstance()
        {
            if (_filter == null)
            {
                _filter = new SpamFilter();
            }

            return(_filter);
        }