Send a Channel Message
Prerequisites
- Delegated login.
- Team and channel IDs.
ChannelMessage.Sendconsent.
teams message send --team "$TEAM_ID" --channel "$CHANNEL_ID" --body "Hello from teams-cli" --output json
Give the post a subject line — the bold title Teams renders above the body, the same field the client offers behind "Add a subject":
teams message send --team "$TEAM_ID" --channel "$CHANNEL_ID" --subject "Release plan" --body "Details inside." --output json
Only channel root messages carry a subject. Chat messages have none, so --subject with --chat
is rejected as invalid input (exit 2) before anything is sent. The subject comes back on
message list and message get; human-readable lists show it in a Subject column, and JSON omits
it for messages that have none.
message update keeps the subject and the importance (a post marked important in Teams stays
important). Graph resets both when an edit leaves them out, so the CLI reads the post first and
sends them back. --subject replaces the subject and --subject "" removes it:
teams message update --team "$TEAM_ID" --channel "$CHANNEL_ID" "$MESSAGE_ID" \
--subject "Release plan (moved to Friday)" --body "Details inside." --output json
Reading the post needs ChannelMessage.Read.All as well as the ChannelMessage.ReadWrite the edit
needs. Without it, an edit of a post without --subject would clear the subject, so it fails with
PERMISSION_DENIED (exit 4) and changes nothing; pass --subject to edit without the read. A reply
is edited without the read, and its importance is not kept. Before v0.13.0 every edit cleared the
subject and reset the importance.
Send an inline image:
teams message send --team "$TEAM_ID" --channel "$CHANNEL_ID" --image ./screenshot.png --output json
Attach a file. Channel attachments upload to the team's SharePoint-backed file store and require Files.ReadWrite.All.
teams message send \
--team "$TEAM_ID" \
--channel "$CHANNEL_ID" \
--body "Logs attached" \
--attach ./logs.zip \
--output json
Verify with:
teams message list --team "$TEAM_ID" --channel "$CHANNEL_ID" --page-size 1 --output json
That listing returns thread roots only. To read the replies under a post, pass its ID with
--message-id; see Read and Watch Channels.
To take a post back, soft-delete it, and restore it with message undelete. Add --reply REPLY_ID
to target a reply in the thread, with the root post as the message ID:
teams message delete --team "$TEAM_ID" --channel "$CHANNEL_ID" --message "$MESSAGE_ID" --yes --output json
teams message undelete --team "$TEAM_ID" --channel "$CHANNEL_ID" --message "$MESSAGE_ID" --output json
Channel deletion needs the delegated ChannelMessage.ReadWrite scope. It is not in the default
set because Microsoft marks it admin-consent required, so an administrator grants it first
(teams auth consent-url --scopes ...) and you then sign in with it. A PERMISSION_DENIED on a
channel target says so unless your token already carries the scope.
Inline images are capped at 3 MB each and 4 MB combined after base64 encoding. File attachments use Microsoft Graph's 250 MB simple-upload limit. See Message Attachments for storage, scope, and download details.