-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunction.cs
More file actions
30 lines (22 loc) · 1.02 KB
/
Function.cs
File metadata and controls
30 lines (22 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System.Text;
using Amazon.Lambda.Core;
using Newtonsoft.Json;
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
namespace EsepWebhook;
public class Function
{
public string FunctionHandler(object input, ILambdaContext context)
dynamic json = JsonConvert.DeserializeObject<dynamic>(input.ToString());
// string issueUrl = json?.issue?.html_url;
context.Logger.LogInformation($"FunctionHandler received: {input}");
string payload = $"{{'text':'Issue Created: {json.issue.html_url}'}}";
var client = new HttpClient();
var webRequest = new HttpRequestMessage(HttpMethod.Post, Environment.GetEnvironmentVariable("SLACK_URL"))
{
Content = new StringContent(payload, Encoding.UTF8, "application/json")
};
var response = client.Send(webRequest);
using var reader = new StreamReader(response.Content.ReadAsStream());
return reader.ReadToEnd();
}
}