Skip to content

Instantly share code, notes, and snippets.

@Jandev
Created March 2, 2019 13:32
Show Gist options
  • Select an option

  • Save Jandev/a2cbff7f3059b63c3c2adcae732c5b77 to your computer and use it in GitHub Desktop.

Select an option

Save Jandev/a2cbff7f3059b63c3c2adcae732c5b77 to your computer and use it in GitHub Desktop.
Azure Function implementation to send a message to Teams
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