These functions use the connection to Microsoft Teams set up with connect_teams().

teams_projects_channel(
  projects_channel_id = read_secret("teams.projects.channel_id"),
  overwrite = FALSE,
  account = connect_teams()
)

teams_new_project(
  task,
  channel = teams_projects_channel(),
  planner = connect_planner()
)

teams_browse_project(
  task,
  channel = teams_projects_channel(),
  planner = connect_planner()
)

teams_list_project_files(
  task,
  channel = teams_projects_channel(),
  planner = connect_planner()
)

teams_download_project_file(
  file,
  task,
  channel = teams_projects_channel(),
  planner = connect_planner()
)

teams_get_project_file(
  file,
  task,
  channel = teams_projects_channel(),
  planner = connect_planner()
)

teams_open_project_analysis_file(
  task,
  channel = teams_projects_channel(),
  planner = connect_planner()
)

teams_render_project_file(
  file,
  task,
  output_file = NULL,
  fun = rmarkdown::render,
  ...,
  channel = teams_projects_channel(),
  planner = connect_planner()
)

teams_view_project_file(
  file,
  task,
  channel = teams_projects_channel(),
  planner = connect_planner()
)

teams_upload_project_file(
  files,
  task,
  channel = teams_projects_channel(),
  planner = connect_planner()
)

teams_download_file(
  full_teams_path = NULL,
  account = connect_teams(),
  destination_dir = getwd(),
  overwrite = FALSE
)

teams_download_folder(
  full_teams_path = NULL,
  account = connect_teams(),
  destination_dir = getwd(),
  recursive = TRUE,
  overwrite = FALSE
)

teams_upload_file(
  file_path,
  full_teams_path = NULL,
  account = connect_teams(),
  file_name = NULL
)

teams_upload_folder(
  folder_path,
  full_teams_path = NULL,
  account = connect_teams(),
  recursive = TRUE
)

pick_teams_item(
  full_teams_path = NULL,
  account = connect_teams(),
  only_folders = FALSE
)

teams_name(account = connect_teams())

teams_channels_list(account = connect_teams(), plain = TRUE)

teams_view_sharepoint(channel, account = connect_teams())

teams_send_message(
  body,
  channel,
  content_type = c("text", "html"),
  attachments = NULL,
  account = connect_teams()
)

teams_open(teams_path, channel = NULL, account = connect_teams())

teams_get_link(
  teams_path,
  share_type = c("view", "edit"),
  expire_after = "1 month",
  password = NULL,
  channel = NULL,
  account = connect_teams()
)

Arguments

projects_channel_id

Teams channel ID of the projects

overwrite

a logical to overwrite an existing connection, useful for switching accounts

account

a Microsoft 365 account to use for looking up properties. This has to be an object as returned by connect_teams() or Microsoft365R::get_team().

task

any task title, task ID, or ms_plan_task object (e.g. from planner_task_find())

channel

a Teams folder object. This has to be an object as returned by teams_projects_channel().

planner

a Microsoft 365 account for Planner. This has to be an object as returned by connect_planner().

file

the file name to open

output_file

path of the output file

fun

function to use for rendering. Can be e.g. rmarkdown::render or quarto::quarto_render.

...

arguments passed on to fun

files

the files to upload

full_teams_path

a full path in Teams, including the Team name and the channel name. Leave blank to use interactive mode, which allows file/folder picking from a list in the console.

destination_dir

a folder to download the file or folder to, defaults to the current working directory.

recursive

download/upload all files within the folder

file_path

local path of the file to upload. Can also be an R object to save it as RDS to Teams.

file_name

a file name to use if file_path is an R object

folder_path

local path of the folder to upload

only_folders

only show folders, not files

plain

return as plain names, not as Azure objects

body

text of the message

content_type

type of content, must be "text" or "html"

attachments

vector of file locations of attachments to add to the message

teams_path

file location in Microsoft Teams, may also contain the channel name if channel is NULL, e.g., teams_path = "channel name/test.xlsx"

share_type

type of share, must be "view" (default) or "edit"

expire_after

time span after which the share link expires, defaults to "1 month", can also be e.g. "7 days"

password

password to set for share link, defaults to blank

Details

The teams_new_project() function:

  1. Checks if there is a Planner task with the correct task title

  2. Creates a new folder in Teams in the projects channel

  3. Updates the task to contain the project folder URL as an attachment

The teams_download_project_file() function will download the given project file to a temporary location, and will return the path of this location. This makes it possible to use source(), rmarkdown::render() or quarto::quarto_render() using the teams_download_project_file() function as input.

The teams_render_project_file() function allows to render a Teams file. It downloads the Teams file using teams_download_project_file(), runs the rendering function set in fun, and uploads the resulting output file back to Teams using the same file name a file, but with the new file extension (such as pdf, html, or docx). It invisibly returns the temporary local file location, so that the output of teams_render_project_file() can be given to e.g. certemail::mail() as an attachment.

The teams_download_file() and teams_download_folder() functions use pick_teams_item() to select a file or folder, after which they will be downloaded to the destination folder.

The teams_upload_file() and teams_upload_folder() functions use pick_teams_item() to select the destination folder on Teams. Notice that these upload functions have not overwrite argument - Microsoft365R does not support them since overwrite means that a new file version will be created on Teams.

The pick_teams_item() function provides an interactive way to select a file in any Team, any channel. It returns a list with the properties group_id, is_private, channel_id, item_id, item_name, item_path, and full_path of the Team item.

teams_send_message() can also take a data.frame, which will be converted to HTML with plain_html_table(). If the input is a vector length > 1, the input will be collapsed with linebreaks.

Examples

if (FALSE) { # \dontrun{
# PROJECT-RELATED ------------------------------------------------------

# Project-related Teams function rely on existing Planner tasks.

# create a new project, which will be a folder in the Teams channel
# for this, the task 'My Planner task' must already exist
teams_new_project("My Planner task")

# the task 'My Planner task' will now contain the URL to the project

# upload a file there
teams_upload_project_file("analysis.Rmd", "My Planner task")

# render R markdown or Quarto from and to the cloud
teams_render_project_file("analysis.Rmd", "My Planner task")
# this will put the output file in the same Teams folder as 'analysis.Rmd'

teams_open("test.xlsx", "My Channel")
teams_open("my channel/test.xlsx") # shorter version, tries to find channel


# PROJECT-UNRELATED ----------------------------------------------------

# by not specifying a remote location, a file picker will show in the console:
teams_download_file()
teams_download_folder("MyTeamName/MyChannelName/MySubFolder/")

teams_upload_file("myfile.docx", full_teams_path = "MyTeamName/MyChannelName/MySubFolder/")

# also supports data frames, they will be saved as RDS
mtcars |> 
  teams_upload_file("MyTeamName/MyChannelName/MySubFolder/")
} # }