The goal of teamr is to provide a wrapper library to send messages to Microsoft Teams through connectors(incoming webhooks)
You can install the released version of teamr from CRAN with:
install.packages("teamr")
And the development version from GitHub with:
# install.packages("devtools")
::install_github("wwwjk366/teamr") devtools
This is a basic example of send a simple titled message to MS Teams:
library(teamr)
# initiate new connector card object
<- connector_card$new(hookurl = "https://outlook.office.com/...")
cc # add text
$text("This is text of main body.")
cc# add title
$title("This is message title")
cc# add hyperlink button
$add_link_button("Read more", "https://www.google.com")
cc# change theme color
$color("#008000")
cc# print out the payload for checking
$print()
cc#> Card:
#> hookurl: https://outlook.office.com/webhook/...
#> payload: {"text":"This is text of main body.","title":"This is message title","potentialAction":[{"@context":"http://schema.org","@type":"ViewAction","name":"Read more","target":["https://www.google.com"]}],"themeColor":"#008000"}
# send to Teams
$send()
cc#> [1] TRUE
# initiate new connector card object
<- connector_card$new(hookurl = "https://outlook.office.com/...")
cc
# add text
$text("This is text of main body.")
cc# add title
$title("This is message title")
cc# initiate a new section
<- card_section$new()
sec
$text(sec_text = "2018-19 Finals MVP")
sec$add_fact(fname = "Position", fvalue = "Forward")
sec$title(sec_title = "Player Info")
sec$activity_image(sec_activitiy_image = "https://d2cwpp38twqe55.cloudfront.net/req/201905091/images/players/leonaka01.jpg")
sec$activity_title(sec_activity_title = "Kawhi Leonard")
sec$activity_sub_title(sec_activitiy_subtitle = "LA Clippers")
sec$activity_text(sec_activitiy_text = "Activity text")
sec$add_section(new_section = sec)
cc$send()
cc#> [1] TRUE
# create new action card
<- action_card$new(type = "ActionCard", name = "Add comment")
pa # add default actions to card
$add_actions()
pa# add text inputs
$add_text_inputs(id = "comment", title = "Add comment for this task", is_multi_line = TRUE)
pa# save to the card object
$add_potential_action(pa)
cc
<- action_card$new(type = "ActionCard", name = "Add Date")
pa2 $add_actions()
pa2$add_date_inputs(id = "date", title = "Add Date for this task")
pa2$add_potential_action(pa2)
cc
<- action_card$new(type = "ActionCard", name = "Add Options")
pa3 $add_actions()
pa3# add multiple choices. note that choices must be a nested named list
$add_mchoice_inputs(id = "mchoice",
pa3title = "Choice one",
is_multi_select = TRUE,
choices = list(
list(display="In Progress", value=1),
list(display="Active", value=2),
list(display="Close", value=3))
)$add_potential_action(pa3)
cc
$send()
cc#> [1] TRUE