public async Task <IActionResult> PostMessageToChannel(TeamMessageDisplayModel model) { try { var graphClient = GetGraphClientForScopes(teamScopes); // Initialize the chat message var newMessage = new ChatMessage { Body = new ItemBody { ContentType = BodyType.Text, Content = model.Message } }; // POST /teams/teamId/channelds/channelId/messages await graphClient.Teams[model.TeamId] .Channels[model.ChannelId] .Messages .Request() .AddAsync(newMessage); return(RedirectToAction("Display", new { teamId = model.TeamId }) .WithSuccess("Message posted")); } catch (ServiceException ex) { InvokeAuthIfNeeded(ex); return(RedirectToAction("Display", new { teamId = model.TeamId }) .WithError($"Error posting message", ex.Error.Message)); } }
// GET /Teams/PostMessageToChannel?channelId=""&teamId="" // channelId: The ID of the channel to post to // teamId: The ID of the team containing the channel // Gets the post message form public IActionResult PostMessageToChannel(string channelId, string teamId) { var model = new TeamMessageDisplayModel { ChannelId = channelId, TeamId = teamId }; return(View(model)); }