Skip to content

New command: Send a Microsoft Teams chat message #2916

@martinlingstuyl

Description

@martinlingstuyl

Usage

m365 teams chat message send [options]

Description

Send a Microsoft Teams chat message to a person or group or meeting chat

Options

Option Description
--chatId [chatId] The Id of the Chat conversation. Specify either chatId or userEmails or chatName.
-e, --userEmails [userEmails] One or more emailaddresses to send the chat message to. Specify either chatId or userEmails or chatName.
--chatName [chatName] The name of the chat conversation. Specify either chatId or userEmails or chatName.
-m, --message <message> The message to send.

Additional Info

We are creating a few commands to get chat messages (e.g. #2860). Wouldn't it be nice to be able to send something easily as well? I would propose a command to send like this one. We could also add a command to create a chat conversation first (before sending to it), but I'm thinking a command that did everything at once (create if necessary, and send) would be handy as well.

We will have to use the Graph API end point - v1.0/chats/<chatId>/messages.

When using the chatId property

The command will send a message as described here

When using the userEmails property

  1. when using a single emailaddress, the inferred chat type will be oneOnOne. That command will use the Create endpoint (as described here) to ensure a chat conversation. Microsoft Graph will return an existing oneOnOne conversation if it is available and create a new one if it is not.

  2. when using multiple emailaddresses, the inferred chat type will be group. For group messages, the Microsoft Graph Create endpoint currently does not resolve to existing conversations. So this command will first query the chats endpoint (as described here) to get all chat conversations of type group with expanded members. It will try to get an existing chat with given members and use that chatId. (Unfortunately you cannot $filter on the expanded members/email to kind of search for conversations.) This command might take more time depending on the number of chats to filter.

When using the chatName property

The command will use the chats endpoint (as described here) and filter on the chat topic to get the correct chat conversation. If a chat conversation can be found, a message is sent.
If multiple chat conversations with the same topic are available, the command prompts the user to disambiguate the choice by providing them with a list of IDs and members to help them make a choice.

Permissions

We'll need Chat.ReadWrite permissions for this to work. These permissions are currently not part of the PnP App Registration.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions