Creating Charts/Graphs with Powershell for Slack - Pt3

on Monday, April 15, 2019

Continued from Creating Charts/Graphs with Powershell for Slack – Pt2.

Send the Graph Back Into Slack

Since ChartJs was able to create a .png image of the chart, now we just have to figure out how to get the image into a message and send it back to slack.

In my imagination, the best possible approach would be to use Slack APIs files.upload endpoint to push the image up to slack and simply reference the image using slack’s private urls. However, I could not get this to work. Maybe someday in the future.

The PSSlack module (which is great!) does have an upload feature built into the New-SlackMessageAttachment command. But, in my experimentation I was only able to upload files or large text blocks; when I tried to upload images they never appeared as image. They just appeared as files that could be downloaded. Maybe I was doing something wrong.

So, I went a third route and did something which is pretty bad design. I used a website that I had access to in order to host the images and reference them as urls. This comes with the drawback that the images hosted on the website would need to be monitored for retention periods and cleanup. But, it’s a quick and easy way to get the image up there.

Below is a wrapper command which will use the image url in an PSSlack message. This will display the newly created graph in chat just as you would hope.

Script using the functions together:

Send-SlackHubotImageUrl:

0 comments:

Post a Comment


Creative Commons License
This site uses Alex Gorbatchev's SyntaxHighlighter, and hosted by herdingcode.com's Jon Galloway.