Table of Contents
- Introduction
- Understanding the Workflow
- Step-by-Step Guide to Building the Team Creation Copilot
- Conclusion
Introduction
Efficiently managing the creation of new Teams using a Teams hosted solution can significantly enhance productivity and collaboration. Leveraging the power of Microsoft Copilot combined with Power Automate and Graph API, you can automate this process with ease. This blog will guide you through creating a Copilot in Teams that validates whether a user is a manager and, if so, provisions a new Team based on user input.
Understanding the Workflow
- User Interaction: The user initiates the process by interacting with the Copilot in Microsoft Teams.
- Validation: Copilot checks if the user is a manager using Office 365 actions.
- Input Collection: The user provides the desired Team name and description.
- Automation: If validated as a manager, Copilot triggers a Power Automate flow to create the Team using the Graph API.
- Confirmation: The user receives a confirmation message once the Team is created.
Step-by-Step Guide to Building the Team Creation Copilot
Step 1: Creating the Copilot in Copilot Studio
Head over to Copilot Studio and click on Create.
This will provide the option to create a copilot based on an existing template or create a blank copilot from scratch. Let’s select New copilot.
This will take us to the page where we can:
- Describe the copilot functionality and provide any specific instructions to the copilot.
- Once done, click on Create to provision the copilot.
Step 2: Enable Generative Selection of Topics
The copilot is now created. We can then make the needed configuration changes:
- Click on Edit, edit the copilot details like name, icon, and description.
- Click on Settings to enable the Generative selection of topics so that without relying on triggers, the topics will be auto-selected based on user conversation resulting in a much smoother user experience.
To enable the automatic detection of topics from user interaction:
- Click on Generative AI.
- Select Generative (preview).
- Click on Save to update the settings.
- Click on the Close icon to go back to the home page of this custom copilot.
Step 3: Create Topics
Now let’s go ahead and create the topics that will automatically redirect the conversation flow to appropriate topics based on the question the user posts. Click on Topics from the navigation menu.
To add the topic, we can either go with the option to create a blank topic or use Copilot to create the topic with an initial set of prepopulated conversation nodes based on the topic description that we provide.
- Click on Add a Topic.
- Select Create from description with Copilot.
Provide the topic description details in the pop-up that opened when we clicked the Add a Topic button previously. Then, click on Create, which will provision the topic skeleton based on the provided description.
Copilot Studio has created the trigger based on the description of the topic that we gave and, as we have enabled Generative selection of topics, whenever the user starts a conversation, the topics are generatively auto-selected based on the user activity text and the conversation flows to the respective topic.
Based on the topic description, Copilot Studio has also auto-created 2 question nodes that will accept the Team Name and Description and store them in the variables TeamName and TeamDescription which we will use down the line for team creation.
Before we proceed, we will add a condition check just after the trigger node to ensure if the current user is a manager so that we can bring in strong governance on who can create a team to control the team creation process.
To add an Office 365 Action:
- Click the + sign to add a new node.
- Select Call an action.
- Click the Connector tab and search for Office 365 actions.
- Select Get my profile (V2).
It adds the action which will output 30+ User Profile properties of the current user. We will be interested in the jobTitle property.
Just after the Office 365 connector, let’s add a condition to check if the jobTitle is equal to manager.
In the condition variable check, select the jobTitle output from the Office 365 action and compare it against the value Manager. If it evaluates to true, we will provide the option for the user to enter the Team Name and Description.
Step 4: Configure Manual Authentication
Before we add the next step of calling Power Automate where we will use Graph API to create the team, we will enable Manual authentication by creating an Azure App registration. This will enable us to generate an authentication token within the copilot which we can pass to Power Automate and use it to authenticate Team Creation Graph API.
To do this, click on Settings of the copilot.
Let’s configure the security settings by:
- Selecting Security.
- Clicking on Authentication.
- Selecting the Authenticate manually option.
- Copying the Redirect URL as we will need it in Azure Portal while registering the app.
Now, head over to Azure Portal’s Entra ID and select App registrations -> New registration.
This will open up the page where we can:
- Name the app registration.
- Specify who can access the app registration (e.g., users in the current tenant or external tenant). For this demo, we will specify Accounts in this organizational directory only.
- Mention the platform as Web and paste the Redirect URL copied from Copilot Studio.
- Click on Register.
Next, we can add the permissions for the app which will dictate what kind of activities this app can do on the user’s behalf.
- Select API Permissions.
- Click on Add Permissions.
- Select Microsoft Graph.
Now we can select the specific Graph API permissions needed by the app.
- Select Delegated Permissions.
- Search for Team.Create in the search bar and select it.
- Click on Add permissions.
Now let’s provide the consent for the permissions by clicking on Grant admin consent.
Next, we will secure the app by adding a client secret.
- From Certificates and Secrets, select New client secret.
- Specify the name and expiry of the certificate.
- Click on Add.
Copy the value of the client secret and head back to the copilot that we were creating.
In Copilot Studio, paste it in the client secret section.
Head back to the Azure Apps overview page and copy the Application ID.
Finally, head back to the copilot and paste it in the Client ID section and click on save.
This will provide us with the bot authentication token which we can pass to Power Automate for Graph API authentication.
Step 5: Create Power Automate Flow
As the next step, let’s create the flow by:
- Clicking on the + to add a new node.
- Selecting Call an action.
- From Basic action, select Create a flow.
This will open up the Power Automate site. Select the trigger and add 4 text inputs which will be used in the Team provisioning action.
Now we will add an HTTP action.
- Click on the + Sign to add a new action.
- Search for HTTP action.
- Click on HTTP.
We will then configure the HTTP action with the below parameters:
- Add the URI as:
https://graph.microsoft.com/v1.0/teams
. - Method will be POST.
- In the Body add the below payload.
{
"template@odata.bind": "https://graph.microsoft.com/v1.0/teamsTemplates('standard')",
"displayName": "@{triggerBody()?['text']}",
"description": "@{triggerBody()?['text_1']}",
"members": [
{
"@@odata.type": "#microsoft.graph.aadUserConversationMember",
"roles": [
"owner"
],
"user@odata.bind": "https://graph.microsoft.com/v1.0/users('@{triggerBody()?['text_2']}')"
}
],
"memberSettings": {
"allowCreateUpdateChannels": true,
"allowDeleteChannels": true,
"allowAddRemoveApps": true,
"allowCreateUpdateRemoveTabs": true,
"allowCreateUpdateRemoveConnectors": true
}
}
In the Authentication section, mention the authentication type as Raw and value as **Bearer
With this, we are done with the Power Automate. Click on Publish.
Heading back to the copilot, we can now add the newly created flow as an action. Click on Call an action and select the flow Create Team from Copilot.
We can now configure the input parameters of the flow:
- The user inputted Team Name and Description are present in the respective question node variables, pass them as the First and Second parameter.
- We also need to pass the owner email which we have received from the Office 365 connector. Search for mail and select it to pass it as the third parameter.
The final parameter is the authentication token which we can get hold of as we have enabled manual authentication. This is present in the system variable User.AccessToken which we can add as the fourth parameter.
We will also provide back a team creation message back to the user.
Thus, we have completed the creation of the copilot that creates a Microsoft Teams Team leveraging Power Automate and Graph API.
Step 6: Publish to Microsoft Teams
Now let’s publish the copilot to Teams by going to Channels -> Microsoft Teams -> Turn On Teams.
The Teams channel is now added and we can:
- Make edits to the copilot Teams icon and other publisher details in the Edit Details section.
- Once done, click on Availability options to decide how to distribute the app.
We can either:
- Make this available in the Teams app store so that everyone can start using it.
- Or, if we want to test or use it for ourselves, we can download the zip and upload the package to Teams as a custom app. In our case, we will submit it to the admin for org-wide rollout by clicking on Show to everyone in my org.
Click on Submit for admin approval so that the app goes to the admin for approval.
The admin can head over to Teams Admin Center and find the app for approval. Click on Publish to make it available for everyone in the organization.
Users can now access the app by searching for it in the catalog.
Step 7: Test the Copilot
We can start the conversation with the copilot and it will check if the current user is a manager. If so, we can provide the team name and team description.
We can also see that the new team has been created in Teams.
Conclusion
Automating the creation of Teams within Microsoft Teams can greatly streamline collaboration and enhance productivity across your organization. By leveraging Microsoft Copilot, Power Automate, and the Graph API, this solution provides a seamless and efficient way for managers to set up new Teams with minimal effort. From validating user roles to provisioning Teams and confirming actions, this integrated approach ensures a smooth user experience and strong governance over team creation.