Skip to content

Instantly share code, notes, and snippets.

@olliencc
Created May 1, 2020 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olliencc/9c60a5a4003ba23eb3835b1d79fe7b5c to your computer and use it in GitHub Desktop.
Save olliencc/9c60a5a4003ba23eb3835b1d79fe7b5c to your computer and use it in GitHub Desktop.
using System;
using System.Net.Http;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using MessageCardModel;
using System.Collections.Generic;
using System.IO;
using MessageCardModel.Actions;
using MessageCardModel.Actions.OpenUri;
using System.Threading;
using System.Collections.ObjectModel;
public async void sendtoTeams(string summary, string title = null, string text = null, string themeColor = "0078D7", Collection<Section> sections = null, string actions = null)
{
settings = new JsonSerializerSettings();
string IncomingWebhookUrl = "https://outlook.office.com/webhook/....";
var card = new MessageCard()
{
Title = title,
Originator = "Pypi TI Bot",
Summary = summary,
Text = text,
ThemeColor = themeColor,
Sections = sections,
Actions = ParseCollection<BaseAction>(actions)
};
var converted = JsonConvert.SerializeObject(card, settings);
var encoded = System.Text.Encoding.UTF8.GetBytes(converted);
HttpClient client = new HttpClient();
StringContent content = new StringContent(converted, Encoding.UTF8, "application/json");
var response = await client.PostAsync(IncomingWebhookUrl, content);
var responseString = await response.Content.ReadAsStringAsync();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment