Reputation: 1615
I'm trying to send some message from my API (built in .NET Core) to a teams channel. According to the documentation, I need to use this code, but I don't know how to create the authProvider
Object.
Grenter code hereaphServiceClient graphClient = new GraphServiceClient( authProvider );
var chatMessage = new ChatMessage {
Body = new ItemBody {
Content = "Hello World"
}
};
await graphClient.Teams["{team-id}"].Channels["{channel-id}"].Messages
.Request()
.AddAsync(chatMessage);
I´ve been reading the documentation but I don't undetstand what I have to do.
This is my controller
[HttpGet]
[Route("SendMessage")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(string))]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<IActionResult> SendMessageToTeams(string message) {
try {
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
var chatMessage = new ChatMessage {
Body = new ItemBody {
Content = "Hello World"
}
};
await graphClient.Teams["xxx"].Channels["xxx"].Messages
.Request()
.AddAsync(chatMessage);
return Ok();
}
catch (Exception ex) {
return BadRequest();
}
}
Could you help me with this please.
Thanks you.
Upvotes: 0
Views: 1477
Reputation: 10814
There are actually a number of ways to do this and which to choose depends on your wider application requirements. However, for the most simple way to send a message to a channel, I would suggest looking at Incoming Webhooks - see more at https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook
Upvotes: 1