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.
Related
The organization that I work for previously used Slack as our collaboration tool. With Slack, I was able to register an app in the workspace and use the provided access tokens to invoke the API to send a message to a user from our external web application. It was very straightforward. There was no intermediate app that needed to be coded to enable this messaging.
Recently, we've transitioned from Slack to MS Teams, and in looking over the Graph API documentation, there does not currently appear to be a way to proactively send a message from an external application to a user. The available permissions for the chatMessage endpoint indicate the availability of only a delegated permission to send a message on behalf of a specific user; no permission exists to send a message on behalf of an external application.
Is it possible to use the Graph API to directly send a message from an external application to a user? Or must a bot application be created in order to achieve this?
It must be a bot application to achieve above mentioned requirement. ChatMessage endpoint works to send a message on behalf of user only.
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
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.
I retrieved an access token from my server and have connected the JavaScript SDk chat client like so. I have created a channel like so. The next step I'd like to invite a user like this. In that example they invite the user 'elmo'. Where do I get 'elmo' or how do I present the user with a selection of possible 'elmo's? The client sdk has no list users functionality.
Edit:
It looks like the REST API has a list users method. But can't find any examples of it used. Should the 1st person chat client be using the REST API as well to supplement gaps in the client SDK or should it get the identity from backend? Our team has different interpretations of the docs: twilio REST API is strictly for backend vs. twilio REST API can and should be used any where. Moved to twilio REST API: strictly backend?
Twilio developer evangelist here.
In my opinion Twilio's Chat API should not be the central source of truth of the users in your system. I don't know anything more about your application than what you've written here, but I would expect that you have a user model within your own system that you have used to generate or create an identity that is then used by the Chat API as well as how your user logs in to your system. I would then use that user model to connect users and provide their identities so that they can join chats together.
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