System.Web.UI.DataVisualization.Charting and Bot Framework
Posted by Tom Cole on October 12, 2017
Building an interesting user experience through bots frequently requires the use of images, differing channels have varying capabilities and you can use the Channel Inspector web page to get an idea of what these are for your target platform.
One thing all the image presentations (Hero Card, Thumbnail Card, Attachment etc) have in common is that they ask for a URL to the image. In dynamic scenarios, like generating a chart image, a web facing URL to the image is not necessarily easy. You could create a one-off URL on your web app but that might have security implications and brings caching and other potential headaches. Another option is to generate a base64 string for the image and return a data url as you might in a HTML img tag i.e.
Since a bot built on Bot Framework is just an extended web app a quick way to generate a dynamic chart is to use System.Web.UI.DataVisualization.Charting. This can be found by adding a reference to the System.Web.DataVisualization assembly in your project.
To generate your chart you might use code similar to:
To then add this to a card in your dialog code you would do something like:
Or to return as an attachment, which may be preferable on some channels from a zoom perspective (an attachment can be opened full size in Teams / Skype whereas a Hero Card might be scaled down and hard to read).