The Microsoft Teams developer platform makes it easy for developers to integrate their own apps and services to improve productivity, make decisions faster, provide focus (by reducing context switching), and create collaboration around existing content and workflows. I am researching the Microsoft Teams and graph API possibilities and would like to know if it is on the roadmap to be able to create and configure Tabs through the graph API. I have seen that teams are in the graph API beta, but can't find any information about creating or configuring tabs programmatically.
Latest version Released:
Format messages and post to Microsoft Teams.
Project description
Python Wrapper Library to send requests to Microsoft Teams Webhooks.Microsoft refers to these messages as Connector Cards. A message can be sent with only the main Connector Card, or additional sections can be included into the message. Using planner in teams office. Anna prime video cast.
This library uses Webhook Connectors for Microsoft Teams. Please visit the following Microsoft Documentation link for instructions on how to obtain the correct url for your Channel: https://dev.outlook.com/Connectors/GetStarted#creating-messages-through-office-365-connectors-in-microsoft-teams
Please refer to the Microsoft Documentation for the most up to date screenshots.https://dev.outlook.com/connectors/reference
Installation
Install with pip:
Usage
Creating ConnectorCard Messages
This is the simplest implementation of pymsteams. It will send a message to the teams webhook url with plain text in the message.
Optional Formatting Methods for Cards
Add a title
Add a link button
Change URL
This is useful in the event you need to post the same message to multiple rooms.
Set Color Theme
This sets the theme color of the card. The parameter is expected to be a hex color code without the hash or the string red.
Preview your object
This is a simple print command to view your connector card message object before sending.
Adding sections to the Connector Card Message
To create a section and add various formatting elements
You may also add multiple sections to a connector card message as well.
Adding potential actions to the Connector Card Message
To create a actions on which the user can interect with in MS TeamsTo find out more information on what actions can be used, please visit https://docs.microsoft.com/en-us/microsoftteams/platform/concepts/connectors/connectors-using#setting-up-a-custom-incoming-webhook
Please use Github issues to report any bugs or request enhancements.
Troubleshooting HTTP response
This module is really just a nice wrapper pointed at the Microsoft API. To help troubleshoot missing messages, the requests response content is saved to the connectorcard class attribute
last_http_status
.To get the last http status code:
More info on the Repsponse Conent is available in the requests documentation, link.
Exceptions
If the call to the Microsoft Teams webhook service fails, a
TeamsWebhookException
will be thrown.Testing
In order to test in your environment with pytest, set the environment variable
MS_TEAMS_WEBHOOK
to the Microsoft Teams Webhook url you would like to use.Then, from the root of the repo, install the requirements and run pytest.
This will send two MS Teams messages describing how they are formatted. Manually validate that the message comes through as expected.
Certificate Validation
In some situations, a custom CA bundle must be used. This can be set on class initialization, by setting the verify parameter.
Set to either the path of a custom CA bundle or False to disable.
The requests documentation can be referenced for full details: https://2.python-requests.org/en/master/user/advanced/#ssl-cert-verification
Release historyRelease notifications | RSS feed
0.1.15
0.1.14
0.1.13
0.1.12
0.1.11
0.1.10
0.1.9
0.1.8
0.1.7
0.1.6
0.1.5
0.1.3
0.1.2
0.1.1
0.1
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size pymsteams-0.1.15.tar.gz (7.5 kB) | File type Source | Python version None | Upload date | Hashes |
Hashes for pymsteams-0.1.15.tar.gz
Algorithm | Hash digest |
---|---|
SHA256 | 170529a3909d84b517e8b0770beba382482fbd663f78c2f4db820bec2a5e4052 |
MD5 | 3763fdab2184eac0c79028f7a3df3143 |
BLAKE2-256 | 2aa7b3998bd59e509b1de38d53a43202c8f17b5f4fc005b69c9b63691c3f8beb |
I was asked to deliver a daily extract of information about our organization’s Microsoft Teams adoption. It was to include the Team’s settings, its owners, its members (separated by internal members and guests), and when it was to expire. Ideally, I’d be able to schedule this to run each morning and drop the resulting file in a Team’s Channel document library.
The first approach
My first approach to the problem was to just see what I could do without thinking too hard. So, with the
Getting the team members would be a little more difficult because the commands that get that info are in the Exchange Remote Admin module.
MicrosoftTeams
module, I knew I could retrieve info about all the teams. The downside is that I would have to be elevated to something like “Team Services Administrator” in Azure AD.$Teams = Get-Team
Getting the team members would be a little more difficult because the commands that get that info are in the Exchange Remote Admin module.
The last requirement was to provide a list of the Teams currently in the recycle bin along with when they’d been deleted. That took the AzureADPreview module.
There are a few problems with these parts to a solution:
- None of those modules are natively Core compatible.
- The “Classic” Exchange Module requires the use of basic authentication.
- Running as myself, I would have to elevate to something like “Team Services Administrator” in Azure AD to use the Teams module.
- The report, capturing info for about 2300 Teams, takes around 45 minutes to run.
Solution:
Could I use an App Registration in Azure AD to connect to Teams and AzureAD? Yes! But… Neither the classic Exchange Admin module nor the new ExchangeOnline module support App Registration authentication. What do all these modules really have in common? The Microsoft Graph API.
So, I started with the great guest post by Alex Asplund on the Adam The Automator blog. His post walks through creating the App Registration. I hadn’t created an App Registration before, but I had the rights to elevate to Global Admin to create one and assign the right application permissions for Graph API:
So, I started with the great guest post by Alex Asplund on the Adam The Automator blog. His post walks through creating the App Registration. I hadn’t created an App Registration before, but I had the rights to elevate to Global Admin to create one and assign the right application permissions for Graph API:
- Directory.Read.All
- Group.Read.All
- GroupMember.Read.All
- Team.ReadBasic.All
- TeamMember.Read.All
- User.Read.All
I chose to use the certificate method of authenticating for the OAuth token and thus created a self-signed Certificate, then exported and uploaded it to the App Registration.Again, I used the code snippets in the blog to create an OAuth token to use with Graph API requests.
One of the requirements was to provide the expiration date of each group. Researching the outputs of various teams- and groups-related graph endpoints, the creation date and the last-renewed date are returned. We need to be able to calculate the expiration date, and for that we need to know what the lifecycle policy is for the groups.
One of the requirements was to provide the expiration date of each group. Researching the outputs of various teams- and groups-related graph endpoints, the creation date and the last-renewed date are returned. We need to be able to calculate the expiration date, and for that we need to know what the lifecycle policy is for the groups.
The request returns you a collection (of one, in my case) of Group Lifecycle Policies with all of the policy’s properties including the
Now we want to get the groups. We want to end up with the Teams, and Teams are “Unified” groups in Azure AD. The following will get the Unified groups in your organization:
groupLifetimeInDays
value that we’re after.Now we want to get the groups. We want to end up with the Teams, and Teams are “Unified” groups in Azure AD. The following will get the Unified groups in your organization:
Note: When using the OData queries via PowerShell, you need to be careful to include the backtick that escapes the dollar sign, otherwise PowerShell is going to try and evaluate
$filter
.Another thing to be aware of is the Graph endpoints generally return just 100 items per page, but that response includes a link to get the next page. So, to deal with that and get all of the groups, use a
while
loop:That gives us all of the Unified groups, but not all Unified groups are Teams!
We know that going and getting the Team object, the members, and the owners is going to involve a lot of waiting for
Inovke-RestMethod
responses, so let’s start by leveraging some parallelism with:Another point where we can achieve some efficiency is with making batch requests to the Graph API using the
'https://graph.microsoft.com/v1.0/$batch'
endpoint. Again, be mindful of your single vs. double quotes here. By using single quotes in this case, we avoid the dollar sign issue. Using the batch endpoint is well documented at https://docs.microsoft.com/en-us/graph/json-batching?view=graph-rest-1.0 . Create a hashtable key-value pair that is a collection of hashtables, one for each of the requests you want to submit in the batch. Convert that to JSON, and submit it as the body of the request.You can see above that we’re getting the Team, the members, and the owners, all keyed by the
ID
property. Submit that block of JSON to the $batch
endpoint and parse the results:The advantage here is that we only make one request instead of three transactions. For the members, we’ll deal with pagination in the same way as with the Teams themselves.
Teams Api Python
Distinguishing the “guests” from the internal “members” is just a matter of examining the User Principal Name (UPN); AzureAD guests will have “EXT” in middle of the UPN.
Tor browser ipa. We’ve collected all the information we need for the team, we only need to calculate that expiration date before we generate some output:
It’s a matter of outputting a
[pscustomobject]
with all of the team properties.The last requirement I was presented with was to provide a listing of all of the Groups that were in the recycle bin. That’s found with the Graph endpoint
$DeletedGroupsURI = 'https://graph.microsoft.com/v1.0/directory/deletedItems/microsoft.graph.group'
As with the Groups themselves and the members, the results are paginated and are handled the same ways as before. My organization wanted an Excel spreadsheet so I used Doug Finke’s ImportExcel module to export the collections.Conclusion
Working with the Graph API can allow you to customize your approach to AzureAD and Teams management. Using the modern App Registration authentication acts not unlike JEA, in that an unprivileged account can be enabled to perform specific limited tasks. In this case we were able to efficiently gather all of the information we needed about the state of our Teams environment, while managing and maintaining control over access. With no elevated access required, “who” the script runs as becomes less important, as long as that entity has access to the file location.
Ms Teams Api Integration
The full code for this solution will be available as TeamsReportByGraph.ps1
Teams Call Control Api
Edited by AJ Lewis