[R-pkgs] Introducing teamr Package

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[R-pkgs] Introducing teamr Package

Tanbing Yan
Today I am so pleased to introduce my first CRAN package for sending
formatted messages to Microsoft Teams, teamr
<https://github.com/wwwjk366/teamr>.

Motivation is simple here. For years I have been using Slack and built many
slash commands and apps using incoming webhooks with R, but ever since I
started to use Teams, I found that we will have the same needs for
communicating with R as well. So with some inspiration from the Python
package pymsteams <https://pypi.org/project/pymsteams/>. I created
teamr package
with the hope that this package will provide a simple and clean way to talk
to Teams from R.
Installation

You can install the released version of teamr from CRAN
<https://cran.r-project.org/> with:

install.packages("teamr")

And the development version from GitHub <https://github.com/> with:

# install.packages("devtools")
devtools::install_github("wwwjk366/teamr")

Example

This is a basic example of send a simple titled message to MS Teams:

library(teamr)
# initiate new connector card object
cc <- connector_card$new(hookurl =
"https://outlook.office.com/webhook/...")# add text
cc$text("This is text of main body.")# add title
cc$title("This is message title")# add hyperlink button
cc$add_link_button("Read more", "https://www.google.com")# change theme color
cc$color("#008000")

We can print out the payload that will be sending to given webhook using
printmethod

# print out the payload for checking
cc$print()

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"}

Our JSON payload looks good, time to send it out :)

# send to Teams
cc$send()

[1] TRUE

send menthod will return TRUE if send was successful (status code 200). If
it failed, it will return the reponse object for further investigation. Our
message with a link button will looks like this:

        [[alternative HTML version deleted]]

_______________________________________________
R-packages mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-packages

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.