Esempio n. 1
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation($"GitHubWebHook endpoint triggered.");
            var body = await req.ReadAsStringAsync();

            var signature = req.Headers["X-Hub-Signature-256"].FirstOrDefault();
            var response  = await _adapter.ProcessWebhookPayloadAsync(signature, body, _bot.OnTurnAsync, default(CancellationToken)).ConfigureAwait(false);

            return(new OkResult());
        }
Esempio n. 2
0
        public async Task TestTrigger(string triggerName)
        {
            var testScript = new TestScript()
            {
                Dialog = dialog
            };

            var dataFolder = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, "..", "..", "..", "Data"));

            foreach (var jsonFile in Directory.EnumerateFiles(dataFolder, $"{triggerName}.*.json"))
            {
                var name = Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(jsonFile));
                System.Diagnostics.Debug.WriteLine(Path.GetFileName(jsonFile));
                var payload = File.ReadAllText(jsonFile);
                await adapter.ProcessWebhookPayloadAsync(null, payload, async (tc, ct) =>
                {
                    //System.Diagnostics.Debug.WriteLine(name);
                    //System.Diagnostics.Debug.WriteLine((string)((dynamic)tc.Activity.Value).action);
                    //System.Diagnostics.Debug.WriteLine((string)((dynamic)tc.Activity.Value).signature);
                    //System.Diagnostics.Debug.WriteLine(String.Join(",", ((JObject)tc.Activity.Value).Properties().Select(p => p.Name).Where(p => p != "signature").OrderBy(p => p)));
                    //System.Diagnostics.Debug.WriteLine(JsonConvert.SerializeObject(tc.Activity, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.Indented }));

                    // should return with correct trigger name
                    try
                    {
                        await testScript
                        .Send(tc.Activity)
                        .AssertReply(name)
                        .ExecuteAsync(tc.TurnState.Get <ResourceExplorer>());
                    }
                    catch (Exception err)
                    {
                        Assert.Fail($"{Path.GetFileName(jsonFile)} failed: {err.Message}");
                    }
                });
            }
        }