简体   繁体   中英

Microsoft Teams: How to set the author of a chat message?

The Teams Beta Chat API allows posting messages to a channel. Good. I want to specify the author of this message (which shall not be me, but an arbitraryly chosen user). Can this be done? How?

More context

We need to set the author in a migration scenario where messages from another system must be migrated to Teams.

The documentation of the chatMessage resource type (used by the /chatmessage endpoint) lists some properties as read-only, but the from field is none of them. This leaves the impression that the author can be set.

This is the POST body I tried:

{
  "body": {
    "contentType": "html",
    "content": "Hello World",
    "from": {
      "user": {
        "displayName": "Heinrich Ulbricht"
      }
    }
  }
}

This gives me a 500 response from the server. I also tried setting the id of the user. Same result: error 500.

Removing the from property succeeds and posts the message. This is the endpoint I used: https://graph.microsoft.com/beta/teams/<id>/channels/<id>/messages

So is it possible to set the author of a chat message?

It is not yet possible to impersonate another user in any API, Graph or Bot. We are planning to do this at some point but it will require elevated privilege and the ability to annotate the message as having been created by an API as opposed to a user and making it possible to audit for these types of annotations later. Otherwise it's a huge security hole.

Building these underlying capabilities is why we don't support migration scenarios.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM