wwwjk366 / teamr

R package to send requests to Microsoft Teams through Webhooks
Other
47 stars 3 forks source link

Send local images #1

Open trinker opened 4 years ago

trinker commented 4 years ago

Hi. Is there a way to send local images to the team channel? It appears like urls. it'd be nice to send a local image like so:

libary(teamr)

temp <- tempdir()
outfile <- file.path(temp, "out.png")

png(outfile, units="in", width=width, height=height, res=300)

library(ggplot2)
ggplot(mpg, aes(y = class)) +
   geom_bar(aes(fill = drv))

dev.off()

cc <- teamr::connector_card$new(hookurl = MyWebhookUrl)
cc$text('Some Text!')
sec <- card_section$new()
sec$add_image(sec_image = outfile)
cc$add_section(new_section = sec)
cc$send()

But the resulting image is blank. I could use a 3rd party like imgur but was wondering, for data security reasons, if a local image can be sent instead of a url?

elfrinjo commented 4 years ago

The teams webhook also accepts base64 encoded images. So this (kind of) works:

image <- ggplot(#Things)

fn <- tempfile(fileext='.png')
png(fn)
print(image)
dev.off()

library(base64enc)
imageB64 <- base64enc::base64encode(fn)
imageB64 <- paste("data:image/png;base64,", imageB64, sep = "")

library(teamr)
cc <- connector_card$new(hookurl = "https://outlook.office.com/webhook.......")
cc$title("Some Title")
cc$text("Some Text")
   sec <- card_section$new()
   sec$add_image(sec_image=imageB64)
cc$add_section(new_section = sec)

cc$send()

How ever, the image is terribly small and I have yet to figure out how to change this. (Probably in teamr)

wwwjk366 commented 4 years ago

For security it is normally not the best practice to send files from local and I will think about this. Thanks for the suggestion.

rdatasculptor commented 4 years ago

I use teamr for communicating data analyses outcomes to all our colleagues of our company. It would be very interesting to be able to add plots without needing to put them on internet somewhere first.

timoschd commented 4 years ago

I second that, it would be nice to send plots as images as well as attached files to automatically communicate results to colleagues.

bibauer commented 3 years ago

Just found this issue. Would love to see this implemented. Is this planned? :)

tylerlittlefield commented 3 years ago

+1 on this

SteMc74 commented 2 years ago

Was this ever implemented? Would really be a nice feature.

rdatasculptor commented 2 years ago

@SteMc74 to my knowledge it wasn't.