Created
January 9, 2017 19:38
-
-
Save ahelland/de19507e6055410658ea5e904c764e11 to your computer and use it in GitHub Desktop.
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
using Newtonsoft.Json; | |
using System.Collections.Generic; | |
using System.Net; | |
using System.Net.Http; | |
using System.Net.Http.Headers; | |
using System.Threading.Tasks; | |
namespace BenderPreCompiled | |
{ | |
public class BenderDll | |
{ | |
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req) | |
{ | |
var statusMsg = "Bender says: Get up meatbag!"; | |
//Push message through Teams | |
using (var client = new HttpClient()) | |
{ | |
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | |
client.DefaultRequestHeaders.Add("User-Agent", "AzureFunctions"); | |
//Copy paste uri from Teams | |
var uri = "https://outlook.office365.com/webhook/{guid-01}/IncomingWebhook/{guid-02}"; | |
var targetUrl = new List<string> { "https://contos.io" }; | |
var action = new Action { context = "https://schema.org", type = "ViewAction", name = "Go to Contos.io", target = targetUrl }; | |
var actions = new List<Action> { action }; | |
var msg = new TeamHook { title = "Message from Bender", text = statusMsg, themeColor = "EA4300", potentialAction = actions }; | |
StringContent TeamMsg = new StringContent(JsonConvert.SerializeObject(msg)); | |
HttpResponseMessage response = client.PostAsync(uri, TeamMsg).Result; | |
var responseString = response.Content.ReadAsStringAsync().Result; | |
HttpResponseMessage res = new HttpResponseMessage(HttpStatusCode.OK); | |
res.Content = new StringContent(responseString); | |
return res; | |
} | |
} | |
} | |
internal class TeamHook | |
{ | |
public string title { get; set; } | |
public string text { get; set; } | |
public string themeColor { get; set; } | |
public List<Action> potentialAction { get; set; } | |
} | |
internal class Action | |
{ | |
[JsonProperty(PropertyName = "@content")] | |
public string context { get; set; } | |
[JsonProperty(PropertyName = "@type")] | |
public string type { get; set; } | |
public string name { get; set; } | |
public List<string> target { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment