0
votes

I want to call a messaging extension (with action command) and access Graph API via a bot for getting different resources of the channel (e.g. retrieve all messages or get replies for my message). In the examples from Microsoft it is stated as a prerequisite that I have to do the "Bot channels registration" so that the access of the bot to the Graph API via OAuth2 works. Do I really need this channel registration? Or is there another way?

As a test, I had created a azure free trial, with which I performed the "Bot channels registration" and could also save the ID and secret for the Graph Api access in the registration. With this I had success. Now the 30 days testing period is over and I'm interested in whether it would work without.

Thanks for your help

Update: Thats my code to initialize graph api:

IConfidentialClientApplication app = ConfidentialClientApplicationBuilder.Create(AppId)
            .WithClientSecret(AppSecret)
            .WithAuthority(new Uri($"https://login.microsoftonline.com/{Tenant}"))
            .Build();
string[] scopes = new string[] { "https://graph.microsoft.com/.default" };
AuthenticationResult authenticationResult = await app.AcquireTokenForClient(scopes).ExecuteAsync();

var graphServiceClient = new GraphServiceClient(new DelegateAuthenticationProvider((requestMessage) =>
        {
            requestMessage
                .Headers
                .Authorization = new AuthenticationHeaderValue("Bearer", authenticationResult.AccessToken);
return Task.FromResult(0);
        }));
1
Yes, To get the access token your bot need to registered in azure.VaraPrasad-MSFT
Thanks for the feedback. In the meantime, I have changed my code so that access with the graph api partially works (see update in question) The following call is executed successfully and also returns the expected result: var channels = graphServiceClient.Teams["123"].Channels.Request().GetAsync().Result; But the following call returns an UnknownError var messages = graphServiceClient.Teams["123"].Channels["456"].Messages.Request().GetAsync().Result; I assume this is related to the access type (delegated or application permissions). Can someone explain why it doesn't work?Anne
yes, it is necessary to enable required graph delegated or application permissions for respective API to get results. Could you please check on that refer documentMallipriya-MSFT
thanks for your answer. I'll check the provided link.Anne
Ok, so thanks for your response. I will use an azure account.Anne

1 Answers

0
votes

For OAuth authentication, you need to register the bot with azure for sure.