コード例 #1
0
ファイル: WebhookRouter.cs プロジェクト: x0rzkov/tweetinvi
        public async Task <bool> Route(HttpContext context, IWebhookConfiguration configuration)
        {
            var matchingWebhooks = GetWebhooksMatching(context.Request, configuration).ToArray();
            var isCrcChallenge   = context.Request.Query["crc_token"].Any();


            if (isCrcChallenge)
            {
                if (matchingWebhooks.Length > 1)
                {
                    context.Response.StatusCode = 500;
                    return(await Task.FromResult(true));
                }

                var matchingEnvironment = configuration.RegisteredWebhookEnvironments[0];

                return(await _webhooksRoutes.CRCChallenge(context, matchingEnvironment.Credentials));
            }

            context.Request.EnableRewind();
            var jsonBody = new StreamReader(context.Request.Body).ReadToEnd();

            _webhookDispatcher.WebhookMessageReceived(new WebhookMessage(jsonBody));

            return(await Task.FromResult(true));
        }
コード例 #2
0
ファイル: WebhookRouter.cs プロジェクト: tinsoldier/tweetinvi
        public async Task <bool> TryRouteRequestAsync(IWebhooksRequest request, IConsumerOnlyCredentials credentials)
        {
            var isCrcChallenge = _webhooksHelper.IsCrcChallenge(request);

            if (isCrcChallenge)
            {
                return(await _webhooksRoutes.TryToReplyToCrcChallengeAsync(request, credentials).ConfigureAwait(false));
            }

            var jsonBody = await request.GetJsonFromBodyAsync().ConfigureAwait(false);

            _webhookDispatcher.WebhookMessageReceived(new WebhookMessage(jsonBody));

            return(await Task.FromResult(true).ConfigureAwait(false));
        }