Created
March 2, 2019 13:32
-
-
Save Jandev/a2cbff7f3059b63c3c2adcae732c5b77 to your computer and use it in GitHub Desktop.
Azure Function implementation to send a message to Teams
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private static readonly HttpClient HttpClient = new HttpClient(); | |
| [FunctionName("InvokeTeamsHook")] | |
| public static async Task Run( | |
| [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "InvokeTeams")] | |
| HttpRequestMessage req, | |
| ILogger log) | |
| { | |
| var message = await req.Content.ReadAsAsync<IncomingTeamsMessage>(); | |
| var address = Environment.GetEnvironmentVariable("WebhookUrl", EnvironmentVariableTarget.Process); | |
| var plainTeamsMessage = new PlainTeamsMessage { Title = message.Title, Text = message.Text }; | |
| var content = new StringContent(JsonConvert.SerializeObject(plainTeamsMessage), Encoding.UTF8, "application/json"); | |
| await HttpClient.PostAsync(address, content); | |
| } | |
| public class IncomingTeamsMessage | |
| { | |
| public string Title { get; set; } | |
| public string Text { get; set; } | |
| } | |
| private class PlainTeamsMessage | |
| { | |
| public string Title { get; set; } | |
| public string Text { get; set; } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment