-
Notifications
You must be signed in to change notification settings - Fork 0
/
Function.cs
37 lines (29 loc) · 1.28 KB
/
Function.cs
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
31
32
33
34
35
36
37
using System.Text;
using Amazon.Lambda.Core;
using Newtonsoft.Json;
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
namespace EsepWebhook;
public class Function
{
/// <summary>
/// A simple function that takes a string and does a ToUpper
/// </summary>
/// <param name="input"></param>
/// <param name="context"></param>
/// <returns></returns>
public string FunctionHandler(object input, ILambdaContext context)
{
context.Logger.LogInformation($"FunctionHandler received: {input}");
dynamic json = JsonConvert.DeserializeObject<dynamic>(input.ToString());
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();
}
}