Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cmdlet Get-PnPTeamsChannelMessageReply #1885

Merged
merged 7 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added `TimeZone` parameter to `New-PnPSite` cmdlet which allows setting of the site collection in the specified timezone.
- Added `Stop-PnPFlowRun` cmdlet to stop/cancel a specific Power Automate flow run. [#1838](https://github.com/pnp/powershell/pull/1838)
- Added `Remove-PnPTeamsChannelUser` cmdlet to remove a user from a private channel. [#1840](https://github.com/pnp/powershell/pull/1840)
- Added `Get-PnPTeamsChannelMessageReply` to retrieve all replies or a specific reply of a message in a Teams channel [#1885](https://github.com/pnp/powershell/pull/1885)
- Added `-Identity` parameter to `Get-PnPTeamsChannelMessage` cmdlet to retrieve a specific message [#1887](https://github.com/pnp/powershell/pull/1887)
- Added new `PnP.PowerShell` image which also gets published to Docker Hub. [#1580](https://github.com/pnp/powershell/pull/1794)
- Added capability to Debug the module in Visual Studio. [#1880](https://github.com/pnp/powershell/pull/1880)
Expand Down
121 changes: 121 additions & 0 deletions documentation/Get-PnPTeamsChannelMessageReply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
Module Name: PnP.PowerShell
title: Get-PnPTeamsChannelMessageReply
schema: 2.0.0
applicable: SharePoint Online
external help file: PnP.PowerShell.dll-Help.xml
online version: https://pnp.github.io/powershell/cmdlets/Get-PnPTeamsChannelMessageReply.html
---

# Get-PnPTeamsChannelMessageReply

## SYNOPSIS

**Required Permissions**

* Microsoft Graph API: ChannelMessage.Read.All

Returns replies from the specified Microsoft Teams channel message.

## SYNTAX

```powershell
Get-PnPTeamsChannelMessageReply -Team <TeamsTeamPipeBind> -Channel <TeamsChannelPipeBind> -Message <TeamsChannelMessagePipeBind>
[-Identity <TeamsChannelMessageReplyPipeBind>] [-IncludeDeleted]
[<CommonParameters>]
```

## DESCRIPTION

## EXAMPLES

### EXAMPLE 1

```powershell
Get-PnPTeamsChannelMessageReply -Team MyTestTeam -Channel "My Channel" -Message 1653089769293 -IncludeDeleted
```

Gets all (active and deleted) replies of the specified channel message.

### EXAMPLE 2
```powershell
Get-PnPTeamsChannelMessageReply -Team MyTestTeam -Channel "My Channel" -Message 1653089769293 -Identity 1653086004630
```

Gets a specific reply of the specified channel message.

## PARAMETERS

### -Team
Specify the group id, mailNickname or display name of the team to use.

```yaml
Type: TeamsTeamPipeBind
Parameter Sets: (All)

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Channel
Specify id or name of the channel to use.

```yaml
Type: TeamsChannelPipeBind
Parameter Sets: (All)

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Message
Specify the id of the message to use.

```yaml
Type: TeamsChannelMessagePipeBind
Parameter Sets: (All)

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Identity
Specify the id of the message reply to use.

```yaml
Type: TeamsChannelMessageReplyPipeBind
Parameter Sets: (All)

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -IncludeDeleted
Specify to include deleted messages

```yaml
Type: SwitchParameter
Parameter Sets: (All)

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

## RELATED LINKS

[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
25 changes: 25 additions & 0 deletions src/Commands/Base/PipeBinds/TeamsChannelMessageReplyPipeBind.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using PnP.PowerShell.Commands.Model.Teams;

namespace PnP.PowerShell.Commands.Base.PipeBinds
{
public class TeamsChannelMessageReplyPipeBind
{
private readonly string _id;
private readonly TeamChannelMessageReply _reply;

public TeamsChannelMessageReplyPipeBind(string input)
{
_id = input;
}

public TeamsChannelMessageReplyPipeBind(TeamChannelMessageReply input)
{
_reply = input;
}

public string GetId()
{
return _reply?.Id ?? _id;
}
}
}
3 changes: 0 additions & 3 deletions src/Commands/Model/Teams/TeamChannelMessage.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Globalization;
using System.Reflection;
using System.Text.Json.Serialization;

namespace PnP.PowerShell.Commands.Model.Teams
{
Expand Down
23 changes: 23 additions & 0 deletions src/Commands/Model/Teams/TeamChannelMessageReply.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;

namespace PnP.PowerShell.Commands.Model.Teams
{
public class TeamChannelMessageReply
{
public string Id { get; set; }

public string ReplyToId { get; set; }

public DateTime? CreatedDateTime { get; set; }

public DateTime? DeletedDateTime { get; set; }

public DateTime? LastModifiedDateTime { get; set; }

public string Importance { get; set; } = "normal";

public TeamChannelMessageBody Body { get; set; } = new TeamChannelMessageBody();

public TeamChannelMessageFrom From { get; set; } = new TeamChannelMessageFrom();
}
}
74 changes: 74 additions & 0 deletions src/Commands/Teams/GetTeamsChannelMessageReply.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using PnP.PowerShell.Commands.Attributes;
using PnP.PowerShell.Commands.Base;
using PnP.PowerShell.Commands.Base.PipeBinds;
using PnP.PowerShell.Commands.Utilities;
using System.Management.Automation;

namespace PnP.PowerShell.Commands.Teams
{
[Cmdlet(VerbsCommon.Get, "PnPTeamsChannelMessageReply")]
[RequiredMinimalApiPermissions("ChannelMessage.Read.All")]
public class GetTeamsChannelMessageReply : PnPGraphCmdlet
{
[Parameter(Mandatory = true)]
public TeamsTeamPipeBind Team;

[Parameter(Mandatory = true)]
public TeamsChannelPipeBind Channel;

[Parameter(Mandatory = true)]
public TeamsChannelMessagePipeBind Message;

[Parameter(Mandatory = false)]
public TeamsChannelMessageReplyPipeBind Identity;

[Parameter(Mandatory = false)]
public SwitchParameter IncludeDeleted;

protected override void ExecuteCmdlet()
{
var groupId = Team.GetGroupId(HttpClient, AccessToken);
if (groupId == null)
{
throw new PSArgumentException("Group not found");
}

var channelId = Channel.GetId(HttpClient, AccessToken, groupId);
if (channelId == null)
{
throw new PSArgumentException("Channel not found");
}

var messageId = Message.GetId();
if (messageId == null)
{
throw new PSArgumentException("Message not found");
}

try
{
if (ParameterSpecified(nameof(Identity)))
{
if (ParameterSpecified(nameof(IncludeDeleted)))
{
throw new PSArgumentException($"Don't specify {nameof(IncludeDeleted)} when using the {nameof(Identity)} parameter.");
}

var reply = TeamsUtility.GetMessageReplyAsync(HttpClient, AccessToken, groupId, channelId, messageId, Identity.GetId()).GetAwaiter().GetResult();
WriteObject(reply);
}
else
{
var replies = TeamsUtility.GetMessageRepliesAsync(HttpClient, AccessToken, groupId, channelId, messageId, IncludeDeleted).GetAwaiter().GetResult();
WriteObject(replies, true);
}
}
catch
{
// Exception thrown by Graph is quite unclear.
var message = ParameterSpecified(nameof(Identity)) ? "Failed to retrieve reply." : "Failed to retrieve replies.";
throw new PSArgumentException(message);
}
}
}
}
18 changes: 18 additions & 0 deletions src/Commands/Utilities/TeamsUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,24 @@ public static async Task<List<TeamChannelMessage>> GetMessagesAsync(HttpClient h
}
}

/// <summary>
/// List all the replies to a message in a channel of a team.
/// </summary>
public static async Task<List<TeamChannelMessageReply>> GetMessageRepliesAsync(HttpClient httpClient, string accessToken, string groupId, string channelId, string messageId, bool includeDeleted = false)
{
var replies = await GraphHelper.GetResultCollectionAsync<TeamChannelMessageReply>(httpClient, $"v1.0/teams/{groupId}/channels/{channelId}/messages/{messageId}/replies", accessToken);

return includeDeleted ? replies.ToList() : replies.Where(r => r.DeletedDateTime.HasValue).ToList();
}

/// <summary>
/// Get a specific reply of a message in a channel of a team.
/// </summary>
public static async Task<TeamChannelMessageReply> GetMessageReplyAsync(HttpClient httpClient, string accessToken, string groupId, string channelId, string messageId, string replyId)
{
return await GraphHelper.GetAsync<TeamChannelMessageReply>(httpClient, $"v1.0/teams/{groupId}/channels/{channelId}/messages/{messageId}/replies/{replyId}", accessToken);
}

public static async Task<TeamChannel> UpdateChannelAsync(HttpClient httpClient, string accessToken, string groupId, string channelId, TeamChannel channel)
{
return await GraphHelper.PatchAsync(httpClient, accessToken, $"beta/teams/{groupId}/channels/{channelId}", channel);
Expand Down