I have been using "https://graph.microsoft.com/beta/chats/{id}/messages" this Ms-Graph API to retrieve the Chat Messages for (Direct/Group Chat) in Microsoft Teams. I get first set of response (i.e. 20 Messages) but when i try to get the next set of messages using the "#odata.nextLink" property i encountered "Bad Request" error.
Is there any other way to retrieve the Next set of Chat Messages from Group/Direct Chat in Microsoft Teams?
Please use the query parameters $skip in conjunction with $top to have finer control over the result if nextLink is not working ( could be because it's still in Beta).
For example, use the below query to get 30 entries after skipping 30 entries
https://graph.microsoft.com/beta/chats/{id}/messages?$top=30&$skip=30
Related
I try to get a list of events via List calendarView
It works as expected when users have Reviewer permissions in the exchange server, but as soon as they have only LimitedDetails - I have an error "access denied".
I assume that the problem is that with LimitedDetails I can only get subjects (without event body).
How can I request the list of events (I need Subject, ICallId and IsAllDayEvent properties) in this case?
Limited Details is a FreeBusy permission so it should work in https://learn.microsoft.com/en-us/graph/api/calendar-getschedule?view=graph-rest-1.0&tabs=http as this queries the users freebusy time but it won't work when trying to query the calendar which requires reviewer or greater.
I'm trying to implement the following solution: a web application that subscribes to all MS teams chat messages. If a message contains forbidden text, the application should somehow warn the user (Ideally by replying to the same message, or, if not possible, initiate a conversation with the user).
I'm able to receive all chat webhooks and process them, but I could not find any way to post a message back to the Teams channel using the Graph API (the operation described in https://learn.microsoft.com/en-us/graph/api/channel-post-messagereply?view=graph-rest-beta&tabs=http
is not supported for Application permissions - only delegated ones which isn't suitable for our case).
So I'm trying to send proactive messages using the Bot framework, However, the bot framework requires a teams conversation ID which I don't have (the graph API webhook provides the team, channel and user IDs, none of which are accepted by the Bot API).
Does anyone know of a way I can retrieve the teams conversation ID using the team ID and channel ID provided by the graph API?
Thanks,
Dan
ConversationId for channel messages are combination of channelId and messageId both can be found in payload you get webhook notification. You can reply to existing conversation by using following by building converstionId like this:
conversationId = $"{channelId};messageid={messageId}"
For reply to work, your Bot needs to installed in the team and should have serviceURL saved at some place to refer back. Here is sample code which show how you can reply to existing message.
var serviceURL = "YOUR Service URL- You get this in each bot payload";
MicrosoftAppCredentials.TrustServiceUrl(serviceURL, DateTime.MaxValue);
using var connector = new ConnectorClient(new Uri(serviceURL, MicrosoftAppId, MicrosoftAppPassword);
var conversationId = $"{channelId};messageid={messageId}";
var replyActivity = MessageFactory.Text($"This is simple reply to existing conversation.");
replyActivity.Conversation = new ConversationAccount(id: conversationId);
var response = await connector.Conversations.SendToConversationAsync(conversationId, replyActivity);
For 1:1 reply- please take a look at Sending Proactive Message documentation.
I am querying to get a single message from the Microsoft graph API like the following:
https://graph.microsoft.com/v1.0/users/<name>/messages/<id>
However, i am getting a response that is just an empty string. If i make the same request using the beta version of the api like the following:
https://graph.microsoft.com/beta/users/<name>/messages/<id>
The email in question is a calendar share invitation of content-type of "application/ms-tnef" and content-class of "Sharing" in the email headers.
I can't find any documentation indicating this is a known issue in the system. Is there any way to get this to work in the graph API or is the only work-around is to use the beta version instead?
Using Graph Explorer, and recreating your request using their demo accounts returns a result in v1.0. I assumed by name you meant the user's email address and I made the same request using the Guid id of the user.
https://graph.microsoft.com/v1.0/users/MeganB#M365x214355.onmicrosoft.com/messages/AAMkAGVmMDEzMTM4LTZmYWUtNDdkNC1hMDZiLTU1OGY5OTZhYmY4OABGAAAAAAAiQ8W967B7TKBjgx9rVEURBwAiIsqMbYjsT5e-T7KzowPTAAAAAAEMAAAiIsqMbYjsT5e-T7KzowPTAAHi4GJzAAA=
https://graph.microsoft.com/v1.0/users/48d31887-5fad-4d73-a9f5-3c356e68a038/messages/AAMkAGVmMDEzMTM4LTZmYWUtNDdkNC1hMDZiLTU1OGY5OTZhYmY4OABGAAAAAAAiQ8W967B7TKBjgx9rVEURBwAiIsqMbYjsT5e-T7KzowPTAAAAAAEMAAAiIsqMbYjsT5e-T7KzowPTAAIgOnGGAAA=
Have you attempted the same request using graph explorer?
I want to get all events in one of my calendar, so that I use “List calendars” first, find the corresponding calendar id, and send List events with this id.
However, the server always responses 404: ErrorItemNotFound after I send “List events”.
Is it any problem on this calendar or just a temporary server problem?
I am using the Microsoft Graph SDK as downloaded from NuGet (1.2). I authenticate to Azure AD (using ADAL).
I am using Client Credentials flow (not authenticated as any particular user) and am using Application Permission roles to access resources.
We are going to set up one service mailbox with a bunch of aliases. The aliases are given to the clients. This is so they are emailing an address that has a meaningful name to them.
My app will run as a service, and routinely scan new emails in this inbox. It should find the To address, and depending on what alias was used, file the email in a location relevant to that client.
The resource I want is: GET /users/<id | userPrincipalName>/messages
However, there doesn't appear to be a method in the SDK for it.
I can get users with this:
IGraphServiceUsersCollectionPage filteredUsers =
graphApi.Users.Request()
.Filter("userPrincipalName eq 'user#domain.com'")
.GetAsync().Result;
When I loop through the collection, I can see that the User has a 'Messages' property, but it is always null.
If I manually build a request message with HttpClient I can get the messages.
The second problem is that the Recipient property is always the userPrincipalName of the mailbox. How can I get the alias that was used by the sender?
While you are able to get your collection of users successfully, you have to make another request to receive the messages. This would look something like:
IUserMessagesCollectionPage userMessages =
graphApi.Users["user_id"].Messages.Request()
.GetAsync().Result;
To answer your second question, at this time you cannot access the original recipient through the Graph API, but you can do this through EWS. This is due to the fact that you can only retrieve the SMTP message headers through EWS. You can read more about how to do this here.
If this is something you believe is valuable to you in the Graph, I would encourage you to post it in our UserVoice.
If you want to get the email as a file, you can simply get the body as bytes through the SDK:
byte[] asBytes = Encoding.Unicode.GetBytes(message.Body.ToString());