private async Task <string> SendSurvey(string surveyId, Survey survey, string recipient, string token, string closingTime, GraphServiceClient graphClient) { // Build up the card Card card = new Card(); card.ThemeColor = "00B200"; card.Title = survey.Name; card.Text = "Survey closes at **" + closingTime + " (UTC)**"; card.HideOriginalBody = true; card.Sections = new List <Section>(); Section section = new Section(); section.Title = survey.QuestionTitle; section.Actions = new List <MessageCard.Action>(); ActionCard actionCard = new ActionCard(); actionCard.Name = "Respond"; actionCard.Inputs = new List <Input>(); MultichoiceInput input = new MultichoiceInput(); input.Id = "input"; input.IsRequired = true; input.Title = "Select an option"; input.Choices = new List <Choice>(); string[] choices = survey.QuestionChoices.Split(';'); for (int i = 0; i < choices.Length; i++) { input.Choices.Add(new Choice() { Display = choices[i], Value = (i + 1).ToString() }); } actionCard.Inputs.Add(input); actionCard.Actions = new List <ExternalAction>() { // This HttpPOST action is defined so the following request is sent to the service: // // POST <service URL> // <Other HTTP headers> // ContentType: application/json // // { // "UserId": "<id of user>", // "SurveyId": "<id of the survey being responded to>", // "Response": "{{input.value}}" // } new HttpPOST() { Name = "Submit", Target = "https://...", // TODO: Fix this with the real URL to web API Body = "{ \"UserId\": \"" + recipient + "\", \"SurveyId\": \"" + surveyId + "\", \"LimitedToken\": \"" + token + "\", \"Response\": \"{{input.value}}\" }", BodyContentType = "application/json" } }; section.Actions.Add(actionCard); card.Sections.Add(section); Recipient toRecip = new Recipient() { EmailAddress = new EmailAddress() { Address = recipient } }; // Create the message Message actionableMessage = new Message() { Subject = "RESPONSE REQUESTED: " + survey.Name, ToRecipients = new List <Recipient>() { toRecip }, Body = new ItemBody() { ContentType = BodyType.Html, Content = LoadSurveyMessageBody(card) } }; try { await graphClient.Me.SendMail(actionableMessage, true).Request().PostAsync(); } catch (ServiceException graphEx) { return(string.Format("Send to {0} failed - {1}: {2}", recipient, graphEx.Error.Code, graphEx.Error.Message)); } return(string.Empty); }
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); }