Hi @Th3TV
Sending messages in a chat doesn't support application-only contexts, the endpoint only supports delegated permissions, so the user must sign in.
using Microsoft.Graph;
using Azure.Identity;
var scopes = new[] { "Chat.ReadWrite" };
var tenantId = "tenant id";
// Value from app registration
var clientId = "YOUR_CLIENT_ID";
// using Azure.Identity;
var options = new TokenCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};
var userName = "user name";
var password = "password";
// https://learn.microsoft.com/dotnet/api/azure.identity.usernamepasswordcredential
var userNamePasswordCredential = new UsernamePasswordCredential(
userName, password, tenantId, clientId, options);
var graphClient = new GraphServiceClient(userNamePasswordCredential, scopes);
var chatMessage = new ChatMessage
{
Body = new ItemBody
{
Content = "Hello world"
}
};
await graphClient.Chats["{chat-id}"].Messages
.Request()
.AddAsync(chatMessage);
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.