Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

ms_channel

Teams channel


Description

Class representing a Microsoft Teams channel.

Format

An R6 object of class ms_channel, inheriting from ms_object.

Fields

  • token: The token used to authenticate with the Graph host.

  • tenant: The Azure Active Directory tenant for the parent drive.

  • type: Always "channel" for a channel object

  • team_id: The ID of the parent team.

  • properties: The item properties (metadata).

Methods

  • new(...): Initialize a new object. Do not call this directly; see 'Initialization' below.

  • delete(confirm=TRUE): Delete this channel. By default, ask for confirmation first.

  • update(...): Update the channel's properties (metadata) in Microsoft Graph.

  • do_operation(...): Carry out an arbitrary operation on the channel.

  • sync_fields(): Synchronise the R object with the channel metadata in Microsoft Graph.

  • send_message(body, content_type, attachments): Sends a new message to the channel. See below.

  • list_messages(n=50): Retrieves the messages in the channel. By default, this is limited to the 50 most recent messages; set the n argument to change this.

  • get_message(message_id): Retrieves a specific message in the channel.

  • delete_message(message_id, confirm=TRUE): Deletes a message. Currently the Graph API does not support deleting Teams messages, so this method is disabled.

  • list_files(): List the files for the channel. See ms_drive for the arguments available for this and the file upload/download methods.

  • upload_file(): Uploads a file to the channel.

  • download_file(): Downloads a file from the channel.

  • get_folder(): Retrieves the files folder for the channel, as a ms_drive_item object.

Initialization

Creating new objects of this class should be done via the get_channel and list_channels methods of the ms_team class. Calling the new() method for this class only constructs the R object; it does not call the Microsoft Graph API to retrieve or create the actual channel.

Messaging

To send a message to a channel, use the send_message() method. This has arguments:

  • body: The body of the message. This should be a character vector, which will be concatenated into a single string with newline separators. The body can be either plain text or HTML formatted.

  • content_type: Either "text" (the default) or "html".

  • attachments: Optional vector of filenames.

  • inline: Optional vector of image filenames that will be inserted into the body of the message. The images must be PNG or JPEG, and the content_type argument must be "html" to include inline content.

Note that message attachments are actually uploaded to the channel's file listing (a directory in the team's primary shared document folder). Support for attachments is somewhat experimental, so if you want to be sure that it works, upload the file separately using the upload_file() method.

See Also

Examples

## Not run: 

myteam <- get_team("my team")
myteam$list_channels()

chan <- myteam$get_channel()
chan$list_messages()
chan$send_message("hello from R")

# a multi-line message with an attachment
msg_text <- c(
    "message line 1",
    "message line 2",
    "message line 3"
)
chan$send_message(msg_text, attachments="myfile.csv")

# sending an inline image
chan$send_message("", content_type="html", inline="graph.png")

chan$upload_file("mydocument.docx")

chan$list_files()


## End(Not run)

Microsoft365R

Interface to the 'Microsoft 365' Suite of Cloud Services

v2.1.0
MIT + file LICENSE
Authors
Hong Ooi [aut, cre], Microsoft [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.