Send message to personal Chat via Graph API - microsoft-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.

Related

Inquiry of Bot Framework "ChannelAccount object"

Following this document:
Bot Framework REST API > API reference > Get conversation members
https://learn.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-connector-api-reference?view=azure-bot-service-4.0#get-conversation-members
We have noticed that the ChannelAccount object for some members, who have never sent a message, cannot be obtained from the "Get conversation members" API.
Is this the product design originally?
If so, could you advise how to mention with never interact users? By MS Graph API?
https://learn.microsoft.com/en-us/graph/api/resources/chatmessagemention?view=graph-rest-1.0
Or any advise to send mention message if we only know AADObject of users in teams?
Thank you in advance.

Post Message to a Microsoft Teams Channel using App

I'm trying to post messages to specific Microsoft Teams Channels using Graph REST API (from my app). I'm looking at the following API endpoint, but it says it doesn't support Application permission type: Create chatMessage in a channel
Is there a better way than using the webhook/bots?
Currently, we don't have plans for posting messages with application permissions. Only option to send a message to channel using Graph API would be using delegated permission.
Please use Bot / Connectors to send messages.

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

how to send a message with a attachment to Teams through Graph API?

Microsoft has provided updated API for sending messages to channel in Teams.
Post Message in Teams
after this update, now we can give importance, mention the user in sending a message to Teams.
curious to know, can we send messages with attachment in this new update?
have a look on below link for the chatMessageAttchment resource type that is used for sending a message with an attachment.
chatMessageAttchment
I want to know what all we can be achieve in this new endpoint.
POST https://graph.microsoft.com/beta/teams/{id}/channels/{id}/messages
This is not currently supported, I'll add a note to the docs clarifying this.

Teams chat belong to conversation

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

Resources