Created
May 1, 2020 19:51
-
-
Save olliencc/9c60a5a4003ba23eb3835b1d79fe7b5c to your computer and use it in GitHub Desktop.
This file contains 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
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