The Corona pandemic made lots of people start working from home and the importance of instant messaging apps has increased quite dramatically since.
As a result more people are logged into Slack, Microsoft Teams and similar tools. This is good as it opens up for using these tools as a communication channel also from Qlik Sense apps to end users.
In this post we’ll take a look at how messages can be sent from Sense load scripts to Microsoft Teams. The same concept can be applied also to Slack and other IM tools that support webhooks from external tools to the IM tool – usually called “incoming webhooks”.
Why posting from Qlik Sense to MS Teams?
You can of course send emails to notify users. Most people however tend to pay more attention to IM tools than to their overflowing email inbox. Blame Facebook, Instagram or Twitter – but that’s just the way things seem to be.
It can therefore be quite effective to send newsflashes from Sense apps when they reload, with info such as:
- Tell users that apps they are interested in have reloaded with new data. Maybe even including some key metrics in the Teams message.
- Use as a debug tool for app developers. Trace messages in the app’s load script work ok, but it can be hard to find them in the reload log window. Better is to send the messages to Teams – there they can be easily viewed.
- Alert stakeholders and/or app developers that some metric has gone out of bounds. A kind of “poor mans alerting”, if you like.
Show me the messages!
Sure – a basic message looks like this:
Note how markdown syntax is used to format the message. The Qlik script for sending this message looks like this:
let vMsg = '<h1>Posting message to Teams from Qlik Sense</h1> A basic message from <b>Qlik Sense</b> '; // Send the message Call PostToTeamsChannel_GenericMessage('$(vTeamsWebhook)', '$(vMsg)');
In addition to the message you need a subroutine PostToTeamsChannel_GenericMessage and a vTeamsWebhook variable, both are described further down in this article.
A more complex message contains a both a sub-heading, a button to open the app and a couple of metrics:
Some additional code is needed to create those new message fields:
// vSenseBaseURL is the URL where Sense apps are accessed, less the App ID let vSenseBaseURL = 'https://qliksense.mydomain.com/sense/app/'; let vTitle = 'Daily sales metrics in Qlik Sense have been updated'; let vSubtitle = 'Click the button to open the app'; let vFactTitle1 = 'Total sales ' & Date(Today()-1, 'YYYY-MM-DD') & ' (kEUR)'; let vFactValue1 = '125'; let vFactTitle2 = 'Change compared to 7d average'; let vFactValue2 = '2.5%'; // Send the message Call PostToTeamsChannel_AppNotification('$(vSenseBaseURL)', '$(vTeamsWebhook)', '$(vTitle)', '$(vSubTitle)', '$(vFactTitle1)', '$(vFactValue1)', '$(vFactTitle2)', '$(vFactValue2)');
Again a subroutine hides the complexities of sending the message – nice.
Do try this at home
You can easily try sending messages yourself:
- A demo load script is available as a GitHub gist. Paste it into your own Sense app.
- Create a Teams webhook. See below for an example of what this can look like.
- Add your incoming web hook URL to the vTeamsWebhook variable in the script.
- Create a Sense data connection “PostMessageToTeams”. It is used when posting messages to Teams and must exist for the script to work. You can use a dummy JSON service to create the data connection, see below for an example.
… and that’s about it. This concept can be of course be extended in all kinds of ways. Microsoft Team’s message cards are actually very flexible, with a pretty cool prototyping tool available here.