public void InitCtorTest(string name) { var data = new PotentialAction(name); Assert.NotNull(data.Targets); Assert.Equal("OpenUri", data.Type); Assert.Equal(name, data.Name); }
public void InitEmptyCtorTest() { var data = new PotentialAction(); Assert.NotNull(data.Targets); Assert.Equal("OpenUri", data.Type); Assert.Null(data.Name); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) { var stackexchangeResponseItem = new StackExchangeResponseItem(); log.LogInformation("C# HTTP trigger function processed a request."); log.LogInformation($"Received event: {req.Body}"); string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); EventGridSubscriber eventGridSubscriber = new EventGridSubscriber(); EventGridEvent eventGridEvent = eventGridSubscriber.DeserializeEventGridEvents(requestBody)[0]; var data = JsonConvert.SerializeObject(eventGridEvent.Data); stackexchangeResponseItem = JsonConvert.DeserializeObject <StackExchangeResponseItem>(data); var card = new ToTeams(); var tags = string.Join('|', stackexchangeResponseItem.tags); var section1 = new Section() { activityTitle = stackexchangeResponseItem.title, activityText = stackexchangeResponseItem.owner.user_id.ToString(), activitySubtitle = "Tags used: " + tags, activityImage = "stackexchangeResponseItem.owner.profile_image" }; var image = new Image(); image.image = stackexchangeResponseItem.owner.profile_image; var potentialAction = new PotentialAction(); potentialAction.context = "http://shema.org"; potentialAction.type = "ViewAction"; potentialAction.name = "Open in browser"; potentialAction.target = new List <string>(); potentialAction.target.Add(stackexchangeResponseItem.link); potentialAction.id = "SELink"; card.content = new Content() { title = "New Question", summary = "Summary", sections = new List <Section>() }; card.content.sections.Add(section1); card.content.potentialAction = new List <PotentialAction>(); card.content.potentialAction.Add(potentialAction); var contentJson = ""; log.LogInformation("content json: " + contentJson); try { contentJson = JsonConvert.SerializeObject(card.content, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); } catch (Exception ex) { log.LogInformation(ex.Message); throw; } var requestUri = "https://outlook.office.com/webhook/cd95bc39-d4b6-47f5-af91-d1bb60673ea5@72f988bf-86f1-41af-91ab-2d7cd011db47/IncomingWebhook/34d5542e15ea4494a397f6081eb1ffbf/ccd20272-10db-42f9-81ff-7ef56c960fc0"; var content = new StringContent(contentJson); HttpRequestMessage request = new HttpRequestMessage { Content = content }; var postResponse = await httpClient.PostAsync(requestUri, content); var postResponseContent = await postResponse.Content.ReadAsStringAsync(); var postResponseHeaders = postResponse.Headers; return((ActionResult) new OkObjectResult(requestBody)); }
static void notifyTeamsPIR(MessageValue message) { // My Teams LInk var client = new RestClient(teamsWebhookPIR); var request = new RestRequest(Method.POST); request.AddHeader("cache-control", "no-cache"); request.AddHeader("Connection", "keep-alive"); request.AddHeader("accept-encoding", "gzip, deflate"); request.AddHeader("Host", "outlook.office.com"); request.AddHeader("Cache-Control", "no-cache"); request.AddHeader("Accept", "*/*"); request.AddHeader("Content-Type", "application/json"); List <Fact> facts = new List <Fact>(); facts.Add(new Fact() { Name = "Title", Value = message.Title }); facts.Add(new Fact() { Name = "Id", Value = message.Id }); facts.Add(new Fact() { Name = "Severity", Value = message.Severity }); facts.Add(new Fact() { Name = "Start Time", Value = message.StartTime.ToString() }); if (message.EndTime != null) { facts.Add(new Fact() { Name = "End Time", Value = message.EndTime.ToString() }); } foreach (var item in message.Messages) { facts.Add(new Fact() { Name = item.PublishedTime.ToString(), Value = item.MessageText }); } Section section = new Section() { ActivityTitle = message.Id + " - " + message.Title, ActivitySubtitle = message.WorkloadDisplayName, ActivityImage = "https://teamsnodesample.azurewebsites.net/static/img/image5.png", Markdown = true, Facts = facts }; List <Target> targets = new List <Target>(); targets.Add(new Target() { Os = "default", Uri = message.PostIncidentDocumentUrl }); //List<Section> sections = new List<Section>(); //sections.Add(section); PotentialAction potentialAction = new PotentialAction() { Type = "OpenUri", Name = "Post Incident Document Url", Targets = targets }; List <PotentialAction> potentialActions = new List <PotentialAction>() { potentialAction }; Root root = new Root() { Type = "MessageCard", Context = "http://schema.org/extensions", ThemeColor = "0076D7", Summary = message.Status, Sections = new List <Section>() { section }, PotentialAction = new List <PotentialAction>() { potentialAction } }; request.AddParameter("undefined", JsonConvert.SerializeObject(root), ParameterType.RequestBody); IRestResponse response = client.Execute(request); //if (response.StatusCode != StatusCodes.Status200OK) //{ logger.LogInformation(response.ErrorMessage); if (response.ErrorException != null) { logger.LogInformation(response.ErrorException.ToString()); } }
public MessageCard SetupConnector() { MessageCard payload = new MessageCard(); payload.type = "MessageCard"; payload.context = "http://schema.org/extensions"; payload.themeColor = "0076D7"; payload.summary = "Russel Rillema started running Margins Daily Calculator"; Section section = new Section() { activityTitle = "Russel Rillema started running Margins Daily Calculator", activitySubtitle = "On McCloud", activityImage = "https://teamsnodesample.azurewebsites.net/static/img/image5.png", markdown = true }; Fact assignee = new Fact() { name = "Assigned to", value = "Unassigned" }; Fact dueDate = new Fact() { name = "Due date", value = "Mon May 01 2017 17:07:18 GMT-0700 (Pacific Daylight Time)" }; Fact status = new Fact() { name = "Status", value = "Not started" }; section.facts.Add(assignee); section.facts.Add(dueDate); section.facts.Add(status); PotentialAction comment = new PotentialAction() { type = "ActionCard", name = "Add a comment", inputs = new List <Input>() { new TextInput() { id = "comment", isMultiline = false, title = "Add a comment here for this task" } }, actions = new List <ConnectorWebHook.Models.Action>() { new ConnectorWebHook.Models.Action() { type = "HttpPOST", name = "Add comment", target = "http://..." } } }; PotentialAction setDueDate = new PotentialAction() { type = "ActionCard", name = "Set due date", inputs = new List <Input>() { new DateInput() { id = "dueDate", title = "Enter a due date for this task" } }, actions = new List <ConnectorWebHook.Models.Action>() { new ConnectorWebHook.Models.Action() { type = "HttpPOST", name = "Add comment", target = "http://..." } } }; MultichoiceInput multichoiceInput = new MultichoiceInput() { id = "list", title = "Select a status", isMultiSelect = "false" }; multichoiceInput.choices.Add(new MultichoiceInputChoice() { display = "In Progress", value = "1" }); multichoiceInput.choices.Add(new MultichoiceInputChoice() { display = "Active", value = "2" }); multichoiceInput.choices.Add(new MultichoiceInputChoice() { display = "Closed", value = "3" }); PotentialAction changeStatus = new PotentialAction() { type = "ActionCard", name = "Change status", inputs = new List <Input>() { multichoiceInput }, actions = new List <ConnectorWebHook.Models.Action>() { new ConnectorWebHook.Models.Action() { type = "HttpPOST", name = "Add comment", target = "http://..." } } }; payload.sections.Add(section); payload.potentialAction.Add(comment); payload.potentialAction.Add(setDueDate); payload.potentialAction.Add(changeStatus); return(payload); }