question

SupriyaSaraogi-8007 avatar image
0 Votes"
SupriyaSaraogi-8007 asked saldana-msft edited

How to send a message to MS teams from standalone application

I'm trying to send message to MS teams channel from my application. The documentation sending chat message to msteams channel is all over the place. It's not helpful for developers. I understand that to send message to MS teams first I'll have to configure an auth provider.

Things tried so far:
1. created an auth provider. In my case I used client auth provider

```
// Create an auth provider
final ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder()
.clientId(vaultSecretProvider.getSecret(MSTEAMS_CLIENTID))
.clientSecret(vaultSecretProvider.getSecret(MSTEAMS_CLIENT_SECRET))
.tenantId(vaultSecretProvider.getSecret(MSTEAMS_TENANTID))
.build();

   List<String> scopes = Arrays.asList(MSTEAMS_SCOPE);

   final TokenCredentialAuthProvider tokenCredentialAuthProvider =
       new TokenCredentialAuthProvider(scopes, clientSecretCredential);

```
2. Created graph client object
```
final GraphServiceClient<Request> graphClient =
GraphServiceClient
.builder()
.authenticationProvider(tokenCredentialAuthProvider)
.buildClient();
```
3. Trying to send chat message to Ms Teams
```
graphClient.teams("groupId")
.channels("ChannelId").messages()
.buildRequest()
.post(chatMessage);
```
When I'm trying to send the message the code gets stuck at AuthenticationHandler.java
this is part of - package com.microsoft.graph.httpcore; in line
```
final CompletableFuture<String> future = authProvider.getAuthorizationTokenAsync(originalRequest.url().url());
```
there is no error thrown. Can someone help me understand what am I missing.

PS: I have added the delegated permissions and I'm using my work account to send the request. Also already referred to following documentation
https://docs.microsoft.com/en-us/graph/api/channel-post-messages?view=graph-rest-1.0&tabs=java
https://docs.microsoft.com/en-us/graph/api/chatmessage-post?view=graph-rest-1.0&tabs=http
https://docs.microsoft.com/en-us/graph/sdks/choose-authentication-providers?tabs=Java












office-teams-windows-itprooffice-teams-app-devmicrosoft-graph-sdkmicrosoft-graph-groups
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @SupriyaSaraogi-8007

Office-teams-windows-itpro is mainly focused on the general issue of Microsoft Teams troubleshooting. According to your description, your question is related to Teams development, which is not in our support scope. So I will also add office-teams-app-dev tag to your thread. Thanks for your understanding and patience!

0 Votes 0 ·

0 Answers