pnp / pnpcore

The PnP Core SDK is a modern .NET SDK designed to work for Microsoft 365. It provides a unified object model for working with SharePoint Online and Teams which is agnostic to the underlying API's being called
https://aka.ms/pnp/coresdk/docs
MIT License
305 stars 192 forks source link

Added a method to get the body and reply of Teams in a single message. #1511

Open zrx1200s opened 2 months ago

zrx1200s commented 2 months ago

Category

Describe the domain model extension

First of all, thanks for providing us with a great library. What we would like to do is update the body of messages sent to Teams and reply to them.

Due to the current SDK specification, there is no way to retrieve Teams messages by themselves, First, a list of messages must be retrieved, and then the messages must be filtered to update the body of the message and reply to it. ex) Getting Chat Message replies

channel = await channel.GetAsync(o => o.Messages);
var chatMessage = channel.Messages.AsRequested().FirstOrDefault();// must be load all messages

// Get the replies
var replies = chatMessage.Replies;

If there are a large number of messages in the channel, the API call will take a large amount of time (even if only one reply is written) because the body of the message cannot be updated or replied to without first reading the entire volume of messages. Therefore, please implement a model for retrieving messages by themselves, specifying the message ID and reply ID.

We have considered the following method implementations, but you are free to change them if you find a more suitable form or implementation location

// get a message
ITeamChatMessage single_message = PnPContext.Team.Channels.GetByDisplayName("General")
.GetByMessageId("id_of_message");// and load ITeamChannel.Messages

//update message(exists method)
single_message.UpdateAsync();

// get a reply
ITeamChatMessageReply single_reply =  single_message
.GetByReplyId("id_of_reply");// and load ITeamChatMessage.Replies

Model

Model: Team, Team.Channels, Team.Channel.Messages

APIs

Microsoft Graph V1

Get a message in a chat API: https://graph.microsoft.com/v1.0/teams/{team-id}/channels/<channel-id>/messages/<message-id>

Get reply to a message API: https://graph.microsoft.com/v1.0/teams/{team-id}/channels/<channel-id>/messages/<message-id>/replies/<reply-id>

Additional Information

Get chatMessage in a channel or chat

jansenbe commented 2 months ago

Please submit a PR for this @zrx1200s , happy to merge it!