[R-pkgs] Introducing teamr Package
Tanbing Yan
t@nb|ngy @end|ng |rom gm@||@com
Mon Jul 22 20:23:31 CEST 2019
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]]
More information about the R-packages
mailing list