Process Automation & Insights Across M365 Data Using Microsoft Graph & Azure by Ayça Baş
28K views
Nov 16, 2023
Conference Website: https://www.2020twenty.net/azure C# Corner - Global Community for Software and Data Developers https://www.c-sharpcorner.com
View Video Transcript
0:00
As we did the introduction already
0:04
I'm going to talk about process automation and insights across M365 data using Microsoft Graph in Azure today
0:12
Just to recap, my name is Aisha Bash and I live in Dubai
0:16
I'm working at Microsoft Developer Relations as a Cloud Advocate. I'm focusing on Microsoft Graph and Microsoft Teams specifically
0:25
I'm a developer and I'm trying to create projects around Microsoft Graph by using Azure
0:32
I'm posting a lot of stuff on Twitter in my own blog and also Microsoft official blogs too
0:39
If you are interested in learning more about it or if you have some other questions, you can always reach out to me on Twitter
0:48
Let's start with the agenda today. First of all, I'm going to talk about a little bit of overview of Microsoft Graph, and then we will jump into Microsoft Graph and Azure App Development
1:02
Actually, my speech is going to be pretty much 100% technical. After that, we will discover user interactive scenarios
1:11
Then we will check what we can do with non-interactive scenarios. And the last part we're going to cover is reporting, ytics, and insight scenarios
1:21
And at the end, I'm going to cover some links that might be useful for everyone
1:29
Okay, so let's quickly have an overview around M365 platform. As you know, M365 is quite big, and we have lots of documentation tools and lots of products we can consume
1:43
But today, specifically, we're going to discover what we can do with the data inside of those products
1:53
Let's think about, for example, Microsoft Teams or Outlook. We're using all of them day to day, and we have huge data in the background
2:01
Every company or individual has huge data in the background of Enter 65 platform
2:06
and actually by using them, we can create great bot projects, web apps, or demon apps, workflow automation
2:15
or we can also use these data in the ytics for auditing purposes or some business review perspective and so on
2:25
And to be able to reach out that data, we always use Microsoft Graph
2:30
Let's check out what is Microsoft Graph. it's a gateway to your data in the Microsoft Cloud
2:36
Let's say that we are using, again, day-to-day our tools like calendar tasks
2:43
We are joining groups. We are chatting on teams. And each time we use these products, your data is staying under Microsoft Cloud
2:53
That doesn't mean that Microsoft has access to your data. You actually have access to your own data
3:00
and by consuming all this data, you can create great projects around it
3:06
Like by consuming all these calendar, mail, tasks, information, for example, you can create a great agent assistant for you, bot assistant
3:15
which can gather all of the important events of the day, or you can just automate background provisioning processes by using Azure functions
3:25
and we are going to discover all these scenarios in this presentation
3:30
So quickly to be able to build an app by using Graph and Azure, first of all, you can check out docs. You can go to aka.ms slash m-graph, which you will find lots of documentation around each Graph-related product and how to consume that
3:50
Plus you can see there are lots of tutorials and quick starts documentation around languages you prefer
3:57
If you are a .NET developer, you can choose .NET and go through the entire tutorial
4:02
You can build an application from scratch. If you prefer Angular or React, you can choose React and you can again create an application by consuming Microsoft Graph from scratch
4:13
The second tool I highly recommend is Graph Explorer. It's a free tool that we can go ahead and sign in
4:20
When we sign in, we can start consuming our own data, and we can call any graph API we want directly
4:28
through the Graph Explorer. I'm going to show that in one of my demos today
4:32
And the third thing, we need to create an application in Identity Platform
4:37
We need to register an app in Azure Active Directory. By using that app, you're going to access to M365 data
4:45
Let's say you want to reach out to email data, then again, we need to create an application in the background
4:52
say that we need permissions for the email or calendar, and whenever user consents the permissions
5:00
or whenever admin consents, we will be able to reach out that data and continue our process
5:07
After configuring the app permissions, we need MSAL Microsoft Authentication Library for signing
5:15
in and getting the token, once we have the token of the person or of the app, then we
5:21
can call Graph API wherever we want, literally. It can be a mobile app
5:24
It can be functions, jobs running in the background. It can be web application or any kind of app
5:32
It's basically an API, REST API, you can call wherever you want. So this is a quick overview of Graph Explorer
5:41
Graph Explorer, as I mentioned, it's a tool I can actually quickly show you
5:45
It's a tool where we can authenticate quickly. After signing in and giving the consent to Graph Explorer
5:53
we can choose any API we want to try out on the left side
5:57
And we can see our data in the response preview. In addition to that, in the code snippets
6:03
you can find out how to implement data in your applications. If you are using C Sharp, you can copy paste
6:10
your C Sharp part in your application, and it's going to work
6:14
So I want to quickly go through the documentation with you as well as the Graph Explorer
6:22
because I'm assuming it's going to be the first time for some colleagues to see these kind of tools
6:33
So I opened the browser. I can zoom in a little bit
6:40
I did that again. I did it in the morning too. Zoom, okay
6:46
So first I'm gonna go to aka.ms slash m-graph. With that, I'll be directed to documentation
6:59
and in this documentation, you can find all of the REST API guidelines
7:05
API version one and beta is available. And if you're new to Microsoft Graph
7:10
you can check out quick starts and as well as the tutorials. Quick starts are the part
7:17
where you can pick the language you prefer. Let's say that I want to do the Angular web
7:21
application and it just showing you the prerequisites what you need to install And if you want to end to end walkthrough you can just click here and it going to direct you to documentation And it just three minutes quick start If you interested to have an application scenario running end and you
7:42
want to build something from scratch, then you can go to tutorials, choose the language you prefer
7:48
let's say I want to build something with SV.NET Core, then this is the entire documentation
7:57
You start with introduction. When you follow all the steps, at the end, you have an application
8:03
with Microsoft Graph up and running. Congrats, you built your first app by using the official
8:11
tutorial. This documentation, I find it quite useful. That's why I wanted to share
8:17
Another thing I want to quickly go through is a Graph Explorer
8:22
If you go to aka.ms slash g-explorer, you will be directed to Microsoft Graph Explorer
8:30
This is a free tool in open source as well. What I can do is I can quickly sign in
8:37
And my pull-up is here. I'm just going to choose the account I want to sign in
8:43
I'm choosing my demo account. Oops. Let's choose another demo account. And after that, you can see my profile here
9:02
Then if I want to get my profile, I just run the query from here by using related requests
9:10
I want to have a get. As you see, I have a response overview
9:16
you can see my display name, job description, email address, and so on. So you can run any
9:23
thing, any API you want. There are actually more than 5,000 API in the background of Microsoft Graph
9:31
So capability is huge. What we can do is really quite big. So you can just explore lots of things
9:39
from here. For example, I want to get all my calendar events. I just click here. It changed
9:45
the end point from here and it gets whatever I have in my calendar here. If you want to
9:54
implement this in your application, if you're using C-sharp, you can just grab this code
9:59
and paste it here. Same for JavaScript, Java, and Objective-C. Okay, this is it. I'm going
10:10
continue with how we are going to build something by using this data. So, our big data is going to
10:22
be here M365 data. By using Microsoft Graph, we are able to get lots of data in the background of
10:31
M365. We can consume, again, calendar data, anything related to your organization in the
10:38
directory, as I mentioned, there are more than 5,000 different APIs in the background of graph
10:46
So capability is huge. Literally any data in the M365, you can reach out to your own data
10:53
And after the authentication by using Oath 2.0, the rest is choosing your development environment
11:00
There's no limitation. By using the development environment, you can use Notepad or you can use
11:05
Visual Studio, Visual Studio Code, and you can choose your own language
11:10
In Graph, you don't have any restrictions of building your app in any language
11:16
If you're a JavaScript developer, you can consume the API in your JavaScript application
11:22
If you're an iOS developer, you can consume, again, the same API in your iOS mobile application
11:29
and you can host your app wherever you want. Today, we're going to discover Azure solutions
11:35
with Microsoft Graph, and hopefully you like it. So key scenarios when we use Microsoft Graph
11:45
is basically two things. That's why I divided the entire session into tool pieces plus the reporting
11:52
The first one is user interactive. The second one is non-interactive. First one is when we create application
12:00
in Azure Active Directory, think that the application we're working on is going to be consumed by end user. Let's say it
12:10
can be a web application where user clicks and log in. After that, they can see their own data
12:17
like profile information or get their email information, so on and so forth. Or it can be a
12:22
chatbot where chatbot can gather all the calendar data to you whenever you ask. These kind of
12:29
scenarios, we always ask end user to consent the permission. So when we first start, then we give a pop-up saying
12:38
that this application wants to reach out to your calendar data. You need to give consent, and then we
12:45
will be able to reach out. This application will reach out to your data
12:50
Second scenario we use is the non-interactive scenario. In non-interactive scenarios, it's common to have background automations, process automations, like provisioning scenarios
13:09
Let's say whenever a new person is added, then create a subscription and add that person in the onboarding teams and so on
13:18
So in this case, we need consent from the administration. administration. In Active Directory, we're asking admin to give consent because in this case
13:29
these kind of scenarios, we don't engage with the end user. All of the provisioning is going to be
13:35
in the background without any touch of the end user. And we will only notify maybe administrators
13:43
saying that we changed this, this happened today and so on so forth. Let's start with the first
13:50
scenario. It's the user interactive scenarios and it's the one that as a developer we really like
13:57
building like chatbot scenarios, web applications. I really like consuming graph API in those kind
14:04
of scenarios. So basically what we do is once we build the application and register in Azure Active
14:12
directory and once user logs in click on login button then user consents to the permission
14:23
required by app let's say calendar permission after that app uses user access token to make
14:30
api calls that means we reach out to users um token by using msal and the end result is going to be
14:39
your app by using the permissions and the token is going to get the data we
14:46
required. Common scenarios for that is generally email any person we want
14:52
calendar scheduler bots where it asks you to for example this is your calendar and you type botlet do this do that and bot is following your comments and calling Graph API in the background
15:07
and doing whatever you are asking to do. So in Azure Active Directory, for interactive app registration, we use delegated type of permissions
15:18
That means that we always ask end user to give consent to us
15:23
In this case, it's showing like read user files, sign in and read user profile
15:29
That means that, let's say on the top, we have sign in with Microsoft button
15:35
When a user clicks on that button, then after giving the email address and password, we ask with our application created in Active Directory
15:46
we show the end user saying that this application needs to read your emails and view your profile
15:55
information. If you accept that, then application will be able to do API calls, Graph API calls on
16:04
behalf of you. Then with that, you will be able to return your calendar data or email data through
16:13
the bot. Let's say that we are using Lydia's access token. We ask Lydia to give consent to us
16:21
When she gives the consent to us, then we are going to return response 200. Okay. And we get
16:29
Lydia's emails and all the email data in her inbox. But that doesn't mean that when Lydia
16:38
gives us an access, we can use other people's token. We cannot because every person who is using that application
16:48
that bot, needs to give consents on behalf of themselves. So whenever Lydia gives consent, if we try to call same application
16:57
with someone else's token, even in the same organization, it's going to return 403, forbidden error
17:06
and we will just see that access is denied because we don't have the credentials and the token
17:14
So Peter needs to give permission on behalf of himself. Very common scenario is bot calls Microsoft Graph
17:25
to access calendar mail tasks. This scenario is actually asked from many enterprise level customers
17:32
as well as the developers. They like working with bots and I also, I'm a big fan of bot framework too
17:41
Actually, the new skills are published by the bot framework. They just release a calendar skill
17:50
email skill and to-do skill. That means that these skills are pre-built for you
17:55
and they're consuming Microsoft Graph already. You can literally just get the SDK
18:00
I just shared a link here, ak.ms slash bot-skills. Here you can get the SDKs, whichever skill you want, and you can run the code and test it for yourself
18:15
And you can publish it to Azure bot service and your app is going to be ready
18:21
So you can have your to-do bot, you can have your email or calendar bot
18:25
Same thing can be done all together as well. These components, these skills can be attached to bot framework assistance too
18:36
So there is a bot framework solution called virtual assistant, and you can actually attach this productivity components like email skill, to do skill, and calendar skill in your virtual assistant, and your virtual assistant will be able to do all of them
18:52
So I highly recommend you to go ahead and check that. Let's continue with non-interactive scenarios
18:58
So, non-interactive scenarios are generally the scenarios where administrators will be quite interested
19:08
So we don't have any user in the scenario. Everything is happening in the background
19:13
We ask admin consents for the app for the specific permissions. Let's say I'm running functions in the background
19:22
I am saving all attached files sent by emails in our entire organization to a database
19:30
In this case, I need to register an app in Azure Active Directory. Then admin needs to consent the permissions, and we need to define which permissions we require
19:40
like files read all, users read all, mail read, and so on
19:46
Once admin gives the consent, then app uses its own credentials to authenticate
19:52
We don't need any user's authentication or token anymore. So, at the end, app has full privilege as long as we define here, app will be able to
20:05
reach out to files, user read, and mail read. So, in these kind of scenarios, we don't have a visibility of user
20:15
We just send notifications maybe in the administrator level saying that subscription provisioning is done and so on
20:25
Let me give you an example about it. During the COVID situation, we had lots of customers talking about moving entire working or education or healthcare environment to teams
20:40
and because we didn't know that it's coming, they need to do this entire move in a couple of weeks
20:49
We were really limited in the time. So what happened is that maybe thousands of users
20:55
needed to register in Azure Active Directory. After that, we need to assign them in certain teams groups
21:03
so they can communicate with their nurses, doctors, or their students, teachers, and so on
21:09
These kind of scenarios cannot be done manually by an administrator because it's, again, thousands of people, thousands of work
21:18
We need some kind of flow in the background running on behalf of the organization
21:25
So, these non-interactive app scenarios are quite useful for this kind of background workflow automations
21:32
In this case, in Azure Active Directory, once we create the application, application
21:40
permission level should be the permission type should be application. And at the end, our admin needs to consent this from Azure Active Directory
21:52
After that, our app will have full access of the data required
21:58
So let's take a look at that. calls API to access any mailbox. Since we give the permission to reach out any mailbox, it's given by
22:08
the admin, then our app can call any user token and get the data we require. Let's say that we
22:19
would like to gather everyone sign log and we want to check if people working from home are working after work times or if they comfortable if they working too much after work stuff if you want to do some kind of ysis again
22:37
we need to have our admin consent together, everyone's data, then we can create ytics
22:45
with this kind of data. Okay, let's say that we have an onboarding solution. Whoever is
22:55
added in the company, let's say I'm a new employee in company A, when I'm added in Azure
23:02
Active Directory, then I want to be automatically added in a Teams group, which is called onboarding
23:10
In this case, whenever new subscription is created, we are calling Microsoft Graph from
23:18
Azure Functions. This lightning symbol is Azure Functions. When we call Graph API, then Graph validates our app's endpoint, then saves subscription
23:31
information in the database. that we can either notify our administrator about the changes, or we can do provisioning
23:43
in the external system. External system can be, again, Microsoft Teams or somewhere else
23:49
We again call Graph API to do this provisioning. Let's think about a scenario like this
23:57
App managers users' calendar and replies the meeting invites. In this scenario, actually, I'm using a real-life reference
24:10
So this is the calendar from one of my colleagues, and she is literally working like this every single day
24:18
And since she is working with the customers, she does not have any time to check her emails during the day
24:25
That's why whenever a new email comes, it directly stays in the calendar, and she sometimes
24:32
missed that, and it's really quite a challenge for her. So we were just discussing this, and I built this, and it was really useful and created
24:43
lots of impact for others, too. So what we can do in these kind of scenarios, since she doesn't have any time to check teams
24:54
and say reschedule this, reschedule that, because it's, again, repetitive function. You can go to Outlook and do the same thing
25:03
What we want is the automation and the background system handling the calendar for us
25:11
In this case, we build the logic apps, and with logic apps, we are calling Microsoft Graph
25:18
to reach out users' calendar, and it is granted by the admin
25:24
because end user is not touching anything in the process. What we do is in the calendar
25:31
we first of all read whenever new event comes, whenever someone sends an invitation
25:38
then we view the calendar of the user. If there is a conflict, simply we call Graph API
25:44
API and we response back to the organizer with, if there is no conflict, we reply back
25:52
as, okay, we have accepted your event. If there is a conflict, then, again, we turn back to logic apps, we call the Graph API
26:03
to check her or him upcoming five days. If it is too busy, like if there are more than 10 events in the calendar, then we say
26:14
in the upcoming five days, I'm super busy, so I decline. And if there are less than 10 events in the calendar
26:25
then we send a rescheduled request to the organizer. So organizer will be informed that I have availability in upcoming days
26:33
So this kind of workflow, we only and only inform end user about what we are doing
26:41
So end user has no touch in this kind of workflow. We just send notification to the end user through Microsoft Teams flow bot and end user will have an idea what we are doing
26:57
So I'm going to quickly demonstrate how you can do it. let's say that
27:06
I can actually share this solution in my GitHub too. I build this flow
27:13
and I'm just going to send a calendar invitation by using Graph Explorer
27:22
So let's say we have an admin. An admin person is super busy
27:27
during the week and he has no time to reply anything and I am as Aychabash is sending the request to the admin and I would like to have a prioritization
27:39
meeting. I'm going to run my flow first. Then I'm going to send a request to my admin. I
27:50
can actually do that from my own calendar, but I really like using Explorer. Okay. This
27:57
This is my request, and this is my admin's email address. I ran the query and post this event in his calendar
28:10
And without touching end user, actually, I can show the email here
28:22
Since admin has a conflict, it returns that can be rescheduled
28:31
Let's check what we had in the flow. So here we see that we have prioritization meeting
28:46
And we have another prioritization meeting conflicting with that. So it returns me the can we reschedule because admins calendar actually on those days aren't quite easy
29:03
Let me show you. Okay. This is the admin calendar. If I create a request, let's say here, I want to, because it's an empty day, I just want to show you how access and acceptance process works
29:21
So what I'm going to do is when I run with Aicha, I'm going to say 8am and I will invite my admin in my company
29:35
I send the requests. I need to read on my process. Here is, let's turn back to my mailbox
29:50
and I get acceptance. What happens in the background is it's actually checking
29:56
in the filter if admin has anything or not. If not, then it directly goes to accept and responds back with the accept
30:06
Otherwise, it just goes to, I can show in the designer, it just goes to false because there's a conflict
30:15
Then it checks in upcoming five days, admin has how many meetings
30:22
If it is more than 10, then it just goes to true
30:30
Then it says, sorry, I have lots of meetings in the upcoming days
30:35
So I decline. If not, then it just sends the options. Like we want to reschedule to the same day, other times, or later this week or next week
30:45
And when all these are happening, admin is only getting, this is my admin
30:54
This is my admin. And admin is only getting information like 101 with Aicha, accept it
31:02
When am I meeting, reschedule, request it. Everything is just an information level
31:08
So my calendar manager running on Logic Apps is just managing everything on behalf of the person, admin
31:18
Okay, last but not least, I just want to mention that let the scenario draw your design choice
31:29
If your scenario is user interactive, if you're building web app where a user needs to log in and it's like personal stuff, then use delegated permissions
31:38
If it is a background process running in the function apps or logic apps in this case
31:45
it is just an automation and provisioning scenario it better to use application permissions and app auth Last part of my today presentation is reporting ytics and insights with Microsoft Graph
32:02
Let's think about the scenario where we need auditing process, but we are all working from home right now
32:10
and we are not at office, so we cannot check how many people are working
32:14
how many hours and if they're comfortable working overtime, and so on. So companies auditing processes are really needing these kind of
32:24
information. So for this kind of info, we can use Microsoft Graph Data Connect
32:30
Microsoft Graph Data Connect has specific data where we can connect by using
32:34
Azure Data Factory and we can get user profile messages, calendar events
32:40
So these are the specific data we can get and there are some others
32:44
And after that, with Azure Data Factory, we can transfer our data to Azure Data Lake or we can directly connect to Azure Snaps for ytics purposes where we can create special queries, let's say, between those days and these people under this group and specific information can be gathered by using Snaps
33:11
And if you have any purpose of creating reporting, then you can use Power BI snaps
33:18
Azure snaps has a direct connection with Power BI. We can actually show the data from Azure snaps to Power BI automatically
33:26
And you can create great charts and pie charts, great information for the business
33:32
Another scenario for insights and reporting, if you require more information, let's say, for example
33:39
call quality about teams or what's happening in the emails or in the Azure Active Directory in the directory for example how many people get subscription recently if they provisioned to officer sign up provisioned to teams
33:58
So these kind of information, if you're looking for, then we can use either logic apps or Azure Functions
34:04
Actually, logic apps are the ones we can, if you are looking for a low code environment, logic apps could be your friend
34:11
and if you're looking for jobs, then you can use Azure Functions
34:17
We can save our data. We can gather our data by using Microsoft Graph
34:21
and save the same data in Azure Blob Storage. And then we can transfer data to Data Lake or also Data Factory
34:33
With Azure Snaps ytics, we can, again, query data. But these kind of tools are quite important for admin level because sometimes they need specific information
34:45
And when a company has hundreds of employees, then this data, like teams or sign-in logs or auditing logs
34:54
are easily like millions of data weekly. So to be able to do some queries, searching by the dates or searching by the email address and so on
35:05
then the Azure Snaps ytics are a really great tool for us
35:11
Again, for the reporting purposes, Azure Snaps ytics has the direct connection with Power BI
35:17
Actually, even Azure Data Lake Storage has the connection with Power BI too
35:24
If you're looking for reporting and getting some insights about your organization
35:30
you can use Snaps Plus Power BI. and with the connection of graph
35:35
you can actually gather the entire M365 data. The Dutch I think I kind of over time but these are the documentations I talked to I think that they can be useful if you new to Graph and Azure You can find all of the Microsoft Graph documentation and the
35:59
solutions related to Azure under ak.ms slash m-graph. Again, if you would like to play around
36:06
a little bit before you implement anything to your app, you can go to Graph Explorer
36:12
It's g-explorer. If you want to discover what kind of solutions you can build
36:18
there is a great series of blog, which is called 30 Days MS Graph
36:23
You can go to aka.ms slash 30 days MS Graph, and you can reach out to all blog series
36:30
It's 30 different documentation talking about different scenarios. and Microsoft Graph has a huge GitHub repository open
36:40
If you want to search some solutions, if you want to get, for example
36:45
chatbot example or React application example, I highly recommend you to go ahead
36:50
and check the GitHub repository of the product team. And last but not least, if you have any questions
36:56
you can always go to Staker Flow with the tag Microsoft-graph-API. It's an up-to-date tag
37:03
You can always ask your questions there, and we will try to answer all of them
37:10
And thank you so much for joining my session today. If you have any questions about my presentation or you want to learn something specific about what I taught today or something related to graph and Azure, you can always reach out to me from Twitter
37:27
and if you tweet it I can try to answer it back too
#Business & Productivity Software
#Programming
#Software