Adding MSGraph Authentication to a teams bot generated using yo teams - microsoft-graph-api

How do i add authentication to a teams app (bot + Messaging extension) generated using the 'Yo Teams' yeoman generator? I am using typescript and there are no samples out there for auth. Secondly, since the yo teams generator generates a single bot.ts file and the auth for bots are a little different with respect to invoke activity, how do i handle the invoke activity in a msteams bot provisioned with yo teams geenrator?

currently messaging extension authentication sample is not available in typescript. You can raise user voice here.

Related

Does Graph API support POSTing a Bot app feature to Microsoft Teams?

I am trying to use Graph API to automate the process of creating a Microsoft Teams app with a Bot app feature.
I found this Graph API endpoint called publish teamsapp which allows me to POST a Teams app package and instantiate a Teams app. Below, the "Appr 4 - MS Teams Test" app was created by uploading an app package to the aforementioned endpoint.
App published through Graph API
However, in order to complete this automation, I need to create a Bot app feature under "Configure > App features" of my Teams app.
My problem is that the publish teamsapp doesn't seem to support creating the Bot app feature. The app package' that you upload contains a manifest.json. The schema of this manifest only allows you to provide a Bot ID (presumably for an existing bot). You cannot specify the webhook URL for this bot and there do not appear to be any APIs to generate the bot's client secret.
App features
My question is, are there any Microsoft APIs that would allow me to create, read from, and write to bot app features? Ideally, I would like to be able to do the following:
Create the bot app feature
Retrieve the bot ID associated with the bot
Set the webhook URL of the bot
Create a client secret associated with the bot
Retrieve the client secret so I can store in my own database.
Is this step 1 to step a loop you would like to follow? I will consider Azure Logic APP to do the bot API call to create a bot - https://learn.microsoft.com/en-us/azure/logic-apps/quickstart-create-first-logic-app-workflow
Also, there is a forum actively monitoring by Teams-dev member you may want to check there as well - https://learn.microsoft.com/en-us/answers/questions/topics/single/58062.html

Bot Framework v4 C# - Proactive messages

I'm using Microsoft Graph in C# to interact with the Azure AD, now I need to build a teams bot that sends a welcome message to the user that was added to the directory, even if the user hasn't had a previous conversation with the bot. How can I implement that if the conversation reference is null?
You would require to install the bot app using Graph API and then get the conversation reference to send welcome message.
See following reference: https://learn.microsoft.com/en-us/microsoftteams/platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages?tabs=dotnet
If the bot app is meant to be pre-installed for all users or a defined set of users in the organization, you can use Setup policies to install it - see https://learn.microsoft.com/en-us/microsoftteams/teams-app-setup-policies . It will require the Teams administrator(s) in your organization to configure this.

MS Graph API Authentication | MS Teams | Bot framework

I am new to bot development. I am working on creating a MS Teams bot using bot framework. The bot will be installed in ‘Personal’ scope in Teams, and it doesn’t have any tab / messaging extension etc. Once installed, I want to get the list of all the members/ channels/ Notification updates (i.e. members added/deleted etc.). As per the different documentation, I can get the list using Graph API.
List members of team - Microsoft Graph v1.0 | Microsoft Docs
List members of a channel - Microsoft Graph v1.0 | Microsoft Docs
To achieve this, I need the token that will be passed in API. I am not sure how to implement that. I have followed the instructions mentioned in Add authentication to a bot in Bot Framework SDK - Bot Service | Microsoft Docs. There was a step to add ‘Add OAuth Connection Settings’ and there were multiple options in ‘Service Provider’. I selected ‘Azure Active Directory v2’. After doing that, it works and I can get the token, but it only works if during login, I user my azure directory credentials. I have a Microsoft account linked with my MS Teams which id different than the Azure account. A user in team can have a Microsoft account / work / office account so this needs to work for everyone so what would be the correct ‘Service Provider’ option that will work for all accounts?
I was thinking that the flow should be like:
When clicks on ‘Add’ button to install the app in Teams
Once added, bot will prompt for Graph API permission using OAuth.
Once user gives the permission, I can use the token to call graph APIs.
I have also looked at the following tutorials:
How to use Bot Framework Composer to build low-code Microsoft Teams bots (Part 1)
Get user profile information in your Microsoft Teams bot with Microsoft Graph (Part 2) - YouTube
But after performing all the steps, when I try to login, it says – ‘This action can't be performed since the app does not exist or has been uninstalled.’.
I am not getting a clear approach on how to proceed with it.
As #Maxim has also suggested, if you want to have a bot that should run multitenant you need to put tenant Id as common in OAuth Setting in Azure bot. As the value suggest it isn't going to specific to single tenant and Redirect Uri should be set to https://token.botframework.com/.auth/web/redirect in app registration.
This is it, you don't need to add anything.
This is also mention in the doc --
We have some sample around it as well that shows how to use Graph API with the bot -
https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/csharp_dotnetcore/24.bot-authentication-msgraph
You can setup this one and update the Graph calls to get member of team or channels.

generate SLACK_APP_TOKEN for slack application

let's say I've created slack app and I have client id and secret.
What is the easiest way to get SLACK_APP_TOKEN in my hands that will be able to create channel?
If you want a proper access token that is related to your Slack App the only way to get it is to install your Slack app with the OAuth process as described here in the Slack documentation. You will need a mini website with a script (e.g. PHP) to perform the installation.
The so called test token will also allow you use the Slack API (e.g. to create a channel), provided that the user that created the test token has that right on your Slack. It is the easiest to obtain, but it will always be linked to a user account, not a Slack app. And you can not request specific scopes for it. So for most applications its better to use a Slack App and get a proper access token by installing it.
If you are looking for an example for an installer script, here is a complete script in PHP. It will run on any webserver that supports PHP. Its very basic, but it will work just fine.

Create slack channel using slack app

I have a private slack application (developed by user 'X' from team 'XT')
I have a web server knows how to complete the Oauth process and generate tokens per teams
Now- as a user Y from team YT I am installing the slack app on my YT team and get a token,
using that token I perform API call for channels.create ,
I got into my team (aka YT) and indeed I see that the channel was created ,
BUT
it's written that the channel was created by the specific user that installed the slack app, meaning user Y.
I would expect to see that channel was created by the application not by specific user.
Is there any way to do that ?
thought about using bot token (got from the app instllation) but channels.create cannot be performed by a bot
I am afraid there is no solution for your problem. Every "write" action on Slack has to be attached to either a bot or a user. And since channels.create can not be used by a bot, it has to be a user.
The master access token of your Slack app is linked to the user that installed it, which is why that user will appear as creator of the channel when you use it.
I use a generic admin user ("slackadmin") for that purpose on my own Slack, but that will of course not work as general solution for each Slack team that want to install your app from the Slack App Directory.

Resources