Teams chat belong to conversation - microsoft-graph-api

I'm using the Microsoft Graph API for my application.
I read that Microsoft Teams chat is stored in the Outlook of the sender.
To retrieve all the Teams Chat I use this request https://graph.microsoft.com/v1.0/me/messages (I know that it also return me all the outlook but I use some filter to return me only Teams Chat).
Now my question is how to know which Chats belong to the same conversation, I did not find in the metadata some property to help me.

The Graph API for reading Teams conversations is not yet available but should be by around the end of June.
The API you are trying to use will not work.

The APIs to read messages from a Microsoft Teams channel are available in preview. I've created a multi-platform .NET Core application that demonstrates its use. You can use it to download all of the messages from a specific channel within a Team, or all the channels in a Team.
https://github.com/tamhinsf/QuickTeams
Here are the underlying APIs that it uses:
To read the messages in a given channel. This will return a paginated list of messages, each with a unique ID.
https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/api/channel_list_messages
Given a unique message ID, this will enable you to get the replies to the message.
https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/api/channel_list_messagereplies

Related

Missing Permissions for Microsoft Graph Add Chat message

I am trying to use Microsoft.Graph to send add a message to a chat. I have successfully found my team and created a channel for the messages to go into but when I try to actually send the message, I get a Forbidden error message. This is covered by the ticket:
Microsoft Graph API for Teams: Send Channel/ Chat messages and I am getting the same problem that #Koelier originaly got.
The reason that this is not fixed is that following the answer does not fix my problem. Indeed, the ChannelMessage.ReadWrite.All does not appear in my list. I am looking for the app to run as a service, in the background so the Application Permissions is the method I need to use.
I note that I am not alone in this as #johnnycardy notes that he has had exactly the same problem as me. Furthermore, I linked to the document referenced by #nastassiar and it did not reference the ChannelMessage.ReadWrite.All at all. I can assume it did once but not anymore.
Any guidance would be gratefully received.
Just checked the permissions to perform the same using graph explorer and the below are the ones that I had to add.
ChannelMessage.Send - Allows the app to send channel messages in Microsoft Teams, on your behalf.
Chat.ReadWrite - Allows an app to read and write your 1 on 1 or group chat messages in Microsoft Teams, on your behalf.
ChatMessage.Send - Allows an app to send one-to-one and group chat messages in Microsoft Teams, on your behalf.
Group.ReadWrite.All - Allows the app to create groups and read all group properties and memberships on your behalf. Additionally allows the app to manage your groups and to update group content for groups you are a member of.
enter image description here

Are there Teams API endpoints available to get channel/call info, such as participant lists?

I'm just wondering if there is currently a production version API for Microsoft Teams available, specifically to gather retrospective participant info from calls/meetings (after the meeting had ended) from an external app? I'm aware of some Teams endpoints being available in Microsoft Graph, but am not sure to what extent these are available?
Thanks for reaching us!
Teams by default generate attendees report and meeting report after completion of meeting call. We can able to see the list of attendees and the report. But at present we don't have any API to fetch list of attendees and their timings.
As this feature is not available at present, could you please raise an User Voice if this needs to be consider as a future request.

Posting to a teams channel from a logic app or flow which includes an banner alert / activity feed item

I have a logic app which posts a channel chat message to teams automatically when a new item is created in SharePoint. This I have working but our client requires that all the team members receive a banner alert and activity feed which I am having a lot of difficulty with.
What I've already tried...
Using a Incoming web hook on the teams channel - this was a very simple way to post from the logic app but the incoming webhook don't seem to support mentions.
Using the msft graph api - The /team/channel/message endpoint can post messages and user mentions but the this endpoint doesnt support channel or team mentions. It also appears that the graph API needs to use delegated permissions to post messages in teams. I'm using application permissions as this is a logic app. The logic app HTTP post connector doesnt offer the "connect as username#tenant.com" some of the other connectors use.
Using the flowbot post message - Like the above channel and team mentions are supported here so the post is added to the channel but with no notification to the team members
Using a notification only bot - I thought I nearly had it with this one. Microsoft's node bot sample number 57 looked like it can do most of what I want, it iterates through the users in the team and messages them this a customisable alert message...
https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/javascript_nodejs/57.teams-conversation-bot
However I can't see how this bot can be triggered from my logic app as it seems to require an existing conversation context or an #mention from within teams to start communicating with users.
What I'm considering trying next
Iterating users within the logic app - Next I plan to try and get team membership from the graph API and iterate the members in the Logic App, posting a message to each user separately. I had hoped to utilise the group #mention feature as a simpler way so I'd be grateful if anyone had any thoughts on other ways of doing this, or maybe there's something wrong with what I've already tried that you could give me some expertise on.
Thanks in advance ;)
Andy
You're on the right track with the Bot, but you're wanting to send something called a "Pro-active" message. You need the bot registered in the channel in order to get access to a few key properties (conversation id, service url, etc.), but you can use those to send a message from -outside- your bot (e.g. in an Azure Function). You might be able to do this directly from a Logic App, but I haven't tested that specifically.
To find out more, see my answer at Programmatically sending a message to a bot in Microsoft Teams but I've also got a recent blog post that you might find interesting for background on this at How Bots Actually Work.
Hope that helps
You can use Graph to post a message in 1:1 chat as long as you have the chat it. You can find the answer in this post Send message to personal Chat via Graph API
You can also call Graph API from Logic Apps. (https://techcommunity.microsoft.com/t5/integrations-on-azure-blog/calling-graph-api-from-azure-logic-apps-using-delegated/ba-p/1997666#:~:text=Calling%20Graph%20API%20from%20Azure%20Logic%20Apps%20using,Manage%20-%3E%20Certificates%20%26%20secrets%20More%20items...%20)

Accessing and creating Teams Chats via Graph API

I'm going over the Microsoft Teams section of the Graph API and trying to find out how to do two things:
Create a new chat, giving it a topic that correlates to an entity in our app (essentially creating a chat around an entity), invite specific users into it, and send messages to the chat.
Access the currently logged-in user's private chats, filtered by their topic, and show their contents inside our app.
For #2, it looks like it should be possible using beta endpoint of the Graph API, but I get 403 Forbidden errors both in the Graph Explorer when trying to access https://graph.microsoft.com/beta/me/chats, and in my own app, after enabling the Chat.Read permissons for it.
For #1, it looks like the API doesn't officially support creating new chats at all.
Is there any approach we can use to create and manage chats? Is there an alternative, perhaps not MicrosoftGraph-based API?
as you mention, the ms graph doesn't yet support initiating group chat. You would use the MS Bot Framework for this: https://learn.microsoft.com/en-us/microsoftteams/platform/concepts/bots/bot-conversations/bots-conv-proactive
I see the docs on these Chat api do exist, but they are not present in the Graph Explorer. I tired testing them in the OfficeApiEditor tool with a v2.0 App Registration and Delegated permissions (Chat.Read) and i get this:
Failure - Status Code 500
"code": "InternalServerError",
"message": "Error while processing response.",
so maybe it will take some time before they are really available in beta.
In MS teams, there is a api called ChatMessage to post a message to a chat(only if the chat already exist or started). But, there is no api to create/start a new chat. I have raised a feature request. Do vote for this to suggest this idea to Microsoft.
https://microsoftteams.uservoice.com/forums/913786-microsoft-teams-free/suggestions/38776681-it-would-be-awesome-l-if-there-is-an-api-functiona

Send message to personal Chat via Graph API

I read from here that getting a user's Teams chats that occurred outside the scope of a team or channel (1-to-1 chat conversation), you need to use this request
GET /users/id/messages
and Teams chat messages have "IM" as their subject.
My question now is whether it is possible to send a new message to this conversation via the Graph API and that the message will be displayed on the Teams application?
I tried to reply to this message via the graph API, but the reply message was sent to Outlook, not in the Microsoft Teams application.
It is now possible to send messages to personal chat(1:1) or to group chat in Microsoft Teams using Microsoft Graph API. And yes, the messages will be displayed in the Teams application using Microsoft Graph API.
Please refer the "1:1 and group chat messages" section from the below microsoft documentation link:
chatMessage resource type
Also, below is the graph API to send a message to any conversation you want using Post HTTP method :
https://graph.microsoft.com/beta/users/{user-id}/chats/{chat-id}/messages
To fetch {user-id} and {chat-id}, please follow the below steps using Get HTTP method:
Fetch the user id of a logged-in user or user id of other user using below graph API's:
https://graph.microsoft.com/v1.0/me
https://graph.microsoft.com/v1.0/users
Fetch the conversation/chat id of a user:
https://graph.microsoft.com/beta/me/chats
https://graph.microsoft.com/beta/users/{id}/chats
As of now, there is no graph API to reply to a personal chat but we can reply to any team's channel message using Microsoft Graph API.
The answer, for now, is no. The docs have stated
"In both the v1 and beta endpoints, the response of GET /users/id/messages includes the user's Microsoft Teams chats that occurred outside the scope of a team or channel. These chat messages have "IM" as their subject."
You may submit/vote an feature request in the UserVoice or just wait the update from the Product Team.
Here is a detailed explanation to answers that #parvin provided if you are trying to do this using Graph Explorer. There is one difference that in this method you don't need to have user-id anymore and chat-id would suffice. Simply Post HTTP method:
https://graph.microsoft.com/v1.0/chats/{chat-id}/messages
if you don't know how to get the chat-id, pleaser refer to answer provided by Parvin. Make sure your message is in the json format and you can put that in request body.
Then you can go to "Request headers" tab and add "Content-type" as Key and "application/json" as value.

Resources