Installation Guide For Telegram Bot.V2.1 - Header
Installation Guide For Telegram Bot.V2.1 - Header
Version 2.1
Installation Guide
Abstract
Follow this guide to prepare, install and configure your own Telegram Bot. This Bot will
connect from Telegram to your Qlik Sense applications giving the users a new experience
using analytics in a conversational interface.
1
Telegram Bot for Qlik Sense 2.1 Installation guide
Contents
Preparation............................................................................................................................... 3
Qlik Sense Server .................................................................................................................. 3
Demo Kit ............................................................................................................................... 3
Troubleshooting .................................................................................................................... 3
Installation................................................................................................................................ 4
Natural Language Processing................................................................................................. 4
Microsoft LUIS ................................................................................................................... 4
Preparation ................................................................................................................... 4
Spell Check .................................................................................................................... 5
LUIS Application ............................................................................................................ 5
Google Api.Ai .................................................................................................................... 7
Natural Language Generation................................................................................................ 7
Yseop Savvy ...................................................................................................................... 7
Narrative Science .............................................................................................................. 8
News Search ......................................................................................................................... 8
Telegram Bot creation ........................................................................................................... 8
Qlik Sense server................................................................................................................... 9
What you will need ........................................................................................................... 9
Qlik Sense customization for Bots ...................................................................................... 9
Assumptions................................................................................................................ 10
Create a tag to identify all the modifications ............................................................... 10
Create Virtual Proxies .................................................................................................. 10
Streams ....................................................................................................................... 11
Apps ............................................................................................................................ 12
Bot User ...................................................................................................................... 12
Data Connection .......................................................................................................... 12
Security Rules .............................................................................................................. 13
Capture HTML ............................................................................................................. 16
Telegram Bot Software installation ..................................................................................... 17
Inline mode images ......................................................................................................... 17
Context and Authorization .............................................................................................. 17
Reports ........................................................................................................................... 18
Telegram Bot Software .................................................................................................... 18
Appendix – Troubleshooting ................................................................................................... 22
Qlik
2
Telegram Bot for Qlik Sense 2.1 Installation guide
No connection could be made because the target machine actively refused it .................... 22
SDK target system version mismatch. SDK target system version (v10.0.3) should match
server version(v3.2.0).......................................................................................................... 22
Error opening the Qlik Sense app ........................................................................................ 22
Error in QSUsers with file "...": System.IO.FileNotFoundException: Could not find file '...' .... 22
System.Xml.XmlException ................................................................................................... 23
Chart link does not appear as a link, just as plain text .......................................................... 23
Chart link appear empty or like “-----“ ................................................................................. 23
Error about licensing ........................................................................................................... 23
Error “Version string portion was too short or too long” ..................................................... 23
The chart snapshots appear empty or a white square ......................................................... 23
Appendix – How to create a new Natural Language model in other language for Google Api.Ai
............................................................................................................................................... 24
Qlik
3
Telegram Bot for Qlik Sense 2.1 Installation guide
Preparation
Qlik Sense Server
This software will be installed in a Qlik Sense server. Because the Bot will send single object
links to users to explore the Qlik Sense charts, it is recommended to use a server accessible
from the internet (public IP or DNS) to allow other users to access this charts.
Demo Kit
Unzip all the folders and files in the Telegram Bot Demo Kit.zip file to a folder in the Windows
server where Qlik Sense is running:
Troubleshooting
There is a section for solving the most common problems here: Appendix – Troubleshooting.
Please refer to this section in case of errors.
Qlik
4
Telegram Bot for Qlik Sense 2.1 Installation guide
Installation
Download the Telegram Bot Demo Kit, and unzip the files to your server hard disk. This will be
the same server where Qlik Sense Enterprise is installed.
At this moment, there are two NLP engines supported, but only one is needed. Depending on
your preferences (usually based on the language you want to use for the bot), you will choose
between two options for the Natural Language Processing engine to use.
As Microsoft model has some limits in the free Azure account, I prefer to use the Google
engine, and this NLP model is more mature and is best trained because I have used it more. If
both engines are configured, only the Google model will be used.
• Microsoft LUIS:
• Google Api.Ai:
Language Language Tag
Brazilian Portuguese pt-BR
Chinese (Cantonese) zh-HK
Chinese (Simplified) zh-CN
Chinese (Traditional) zh-TW
English en
Dutch nl
French fr
German de
Italian it
Japanese ja
Korean ko
Portuguese pt
Russian ru
Spanish es
Ukrainian uk
Depending on your selection, follow the corresponding section of the next ones.
Microsoft LUIS
Preparation
• You need a Microsoft account (Hotmail or Outlook.com, for example)
Qlik
5
Telegram Bot for Qlik Sense 2.1 Installation guide
• Go to https://www.microsoft.com/cognitive-services/en-us/language-understanding-
intelligent-service-luis
• Optionally, you can get a Bing Spell Check key from here
(https://www.microsoft.com/cognitive-services/en-us/bing-spell-check-api) to be used
when creating your LUIS model, to spell check the sentences before trying to
understand them. This could help fixing typos and mistakes in voice recognition.
Spell Check
This is an optional step you could follow if you want to help the Natural Language engine to
spell check the sentences before trying to understand them. This could help fixing typos and
mistakes in voice recognition.
1. Go to https://www.microsoft.com/cognitive-services/en-us/bing-spell-check-api
2. Select “Get started for free”
3. Subscribe to the Bing Spell Check. At this moment, there is a free option for 5,000
transactions per month, 7 per minute. It should be enough for demo purposes.
4. Save the Key 1 for later (it could be used in the LUIS Application configuration).
LUIS Application
1. Go to https://www.microsoft.com/cognitive-services/en-us/language-understanding-
intelligent-service-luis
2. Login to LUIS, and go to My Applications.
3. Go to New App, and use the import option:
Qlik
6
Telegram Bot for Qlik Sense 2.1 Installation guide
4. In case you want to use the Bing Spell Check, here is where you can enter that key (Key
1):
5. Use the “Analytics General.json” file you can find in the NLP folder, and give the
application the name you like, in my case “Analytics General”:
6. Train the model. You will see this option on the bottom left corner ( ).
7. When the train is finished, publish the application ( ) to be able to call it
from the LUIS API:
8. Here, in the URL link you can obtain the LUIS App ID and the LUIS Key, that you must
save for later:
Qlik
7
Telegram Bot for Qlik Sense 2.1 Installation guide
Google dialogflow
You will need an account to login (Gmail, Facebook, Slack or Github).
1. Go to https://dialogflow.com/
2. Create an account, there is a “Sign up for Free” option, enough for demo purposes.
3. Go to the console (https://console.dialogflow.com) and create a new Agent. An agent
is a NL model.
4. Choose Private if you want to keep it for yourself, or Public to be available to other
people.
5. Choose English for language. If you want to create a new model for another language,
check if this already available. If not, go to Appendix – How to create a new Natural
Language model in other language for Google Api.Ai to create it.
6. Fill the required information (name, description, etc.) and save it:
7. Go to the agent configuration , in the General tab you have both keys, Client
Access Token (needed for Language Understanding, the one we need to save), and
Developer Access Token (only needed if you want to make changes from the API, not
needed for the bot).
8. Go to the Export and Import tab, select Import from Zip. When asked, use the file
AnalyticsGeneral Google.zip included in the folder NLP Models from the Demo Kit.
Yseop Savvy
• Go to https://savvy.yseop.com/download/, and request an evaluation key (Select Api
Access in the Tool section).
• Save the key for later.
Qlik
8
Telegram Bot for Qlik Sense 2.1 Installation guide
Narrative Science
• You can ask for a license key to our Technology Alliances team.
• Save the key for later.
News Search
This service is used to show how Qlik Sense can integrate with another source of information
to complement the analysis.
• Go to https://www.microsoft.com/cognitive-services/en-us/bing-news-search-api, and
register a free account for the Bing News Search API (this account will expire in 90
days).
• Save the ID for later.
• Define the bot name and the userid. The userid could be anything, but it must end
with “bot” and have no spaces. For example, Qlik Sense Bot for the name and
QlikSenseBot for the userid.
• The bot profile photo, a squared photo (similar width and height), something around
250 x 250 pixel works well. Consider the copyrights for images from the internet.
You must use Telegram (from desktop, mobile and/or web), so create a Telegram account. Not
needed in the Qlik Sense server, it is just to have access from some place to configure, test and
demo.
1. Go to Telegram
2. In the contacts search box, look for BotFather. This is a bot to create bots.
3. Start a conversation with this bot.
4. Write /newbot, then you will be requested to write the name, for example Qlik Cool
Bot. After this, you will be requested to write the bot userid (no spaces and ending
with bot), for example QlikCoolBot.
5. If the name is not used by another bot and everything is correct, you will get a token to
access the Telegram API. Save it for later, you will have to use it in Telegram Bot
Software.
6. Write /setdescription, then you will have to select the bot first (with a button bellow
the text), and write a description text that will appear when any user starts a
conversation with the bot. For example, “This bot connects to Qlik Sense and allows
you to have an analytical conversation based on Consumer Goods Sales information”.
7. Write /setinline, then you will have to select the bot first and write the text that will
appear when the bot is called from another chat with @. For example, “Search data”.
8. Write /setinlinegeo, then you will have to select the bot first and choose Enable. This
option will allow the bot to request the user geo location from the Telegram device,
and use it to filter data in a Qlik Sense application.
9. Write /setinlinefeedback, then you will have to select the bot first and choose Disable.
Qlik
9
Telegram Bot for Qlik Sense 2.1 Installation guide
10. Write /setuserpic, then you will have to select the bot first and upload the bot profile
photo. Using the clip icon, upload the image that will appear in the bot profile.
Now, to check the bot has been successfully created, go to Telegram and using the search box
in the contacts, write the name of the bot and start a conversation with him. From now on, the
bot will appear on your recent list of contacts.
An option is to use our Demo Server for these public single object links, but
you should use the same app (Consumer Goods Sales, for example) in our
Qlik Sense server (to have the same object IDs). My recommendation is to
download the app from the demo site.
To configure this option, go to the config file and review the parameters
DemoqsSingleServer (for example, to https://sense-demo.qlik.com/site)
and DemoqsSingleApp (something like 372cbc85-f7…).
Attention! If the user changes the app analyzed, the Single Object links
won’t be valid. And no self-service will be allowed.
4. A Stream for the apps available to the bot. It could be used Everyone or one specific
like Bots, or both.
5. Some demo apps published on that stream. The apps must have Master Items for
Dimensions and Measures, because the Bot will use those elements for searching what
to show the users. It is recommended to have enough charts in the app (not needed to
be master items) with titles, as those texts will be used for names when the link is sent
to users.
6. The Windows user that will run the Bot software must have read access to this stream.
a. I recommend to create a new Windows user for the Bot, for example
TelegramBot.
b. This user must have access to Qlik Sense, for example creating a User Directory
Connection for local users (Local Network).
c. This user must have a User Access allocated (do not use login access), as the
session could be running 24h a day.
Qlik
10
Telegram Bot for Qlik Sense 2.1 Installation guide
Assumptions
• A Qlik Sense server already installed and licensed.
• I will use http, but https can also be used.
• I will use an anonymous virtual proxy to allow Telegram users to access the apps
objects with header authentication, as this is very easy to setup, and thus making the
process simpler. This is because the primary function for this bot is demo and no
production.
• Every Bot user will need a token, unless core based licensing is used.
Do not forget to add the IP and DNS addresses to the white list of every virtual proxy.
Anonymous access
• Description: Telegram
• Prefix: telegram
• Timeout: 30
Qlik
11
Telegram Bot for Qlik Sense 2.1 Installation guide
Streams
Bots
1
Save the "Header authentication header name" for later, as this parameter has to be used in the bot
program config file (DemoqsServerHeaderAuth). I have put it in red, but you can use whatever name
you want, for example X-Qlik-TelHeadAuth.
Qlik
12
Telegram Bot for Qlik Sense 2.1 Installation guide
Bot Publications
Apps
Now, publish all the apps that will be used in the Bot to the Bots Stream. For example,
Consumer Goods Sales Bot, Retail Margin Erosion, Executive Dashboard.
There is no need to publish anything in Bot Publications. In that Stream, only the Bot will
publish apps.
Bot User
For running the Bot software, we need to use a Windows user that will run the Bot program
and connect to Qlik Sense using Windows authentication to check the API and create the
Telegram Users. I recommend to create a new Windows local user, assign a token to it in Qlik
Sense, and grant the Content Admin role to that user.
Data Connection
If we want to demonstrate full self-service from the Bot, i.e. upload a CSV file and create a new
app from that data, we need to define a Folder Data Connection in Qlik Sense.
The Data Connections in Qlik Sense must be defined from the apps, so you should create a new
app, then create a new Folder Connection to the folder where the Bot accesses the Reports,
Qlik
13
Telegram Bot for Qlik Sense 2.1 Installation guide
and then rename it from the QMC if you like (as by default the user name is added to the data
connection name). Do not forget to add the Bots tag to this element in the QMC.
Security Rules
These security rules will allow all the Telegram users to access the Qlik Sense server through
the Anonymous virtual proxy, but only the apps in the Bots stream (and Everyone stream, that
is set by default).
Qlik
14
Telegram Bot for Qlik Sense 2.1 Installation guide
PD.- This security rule could be easier to create from the Stream menu than from the Security
Rules menu.
Qlik
15
Telegram Bot for Qlik Sense 2.1 Installation guide
PD.- This security rule could be easier to create from the Stream menu than from the Security
Rules menu. But for the Create action, you should modify the rule after creation.
Qlik
16
Telegram Bot for Qlik Sense 2.1 Installation guide
Capture HTML
To allow the Capture HTML app being able to connect to the Qlik Sense server to render single
object images for the snapshots sent by the Bot to the users, if you use a Windows Server
version you will need to add the address used by the capture app to the intranet or trusted
sites in the Internet configuration. These addresses will be the ones set in the config file
parameters DemoqsServer, DemoqsSingleServer and cntCaptureWeb.
Qlik
17
Telegram Bot for Qlik Sense 2.1 Installation guide
And also some chart captured images to show during the alert. They will be picked randomly
from the nine available here, so you can use your own images if you like.
Copy the folder qsimg to C:\Program Files\Qlik\Sense\Client (You will need to provide
Administrator rights to write in this folder):
This file has one record for every user that has accessed the bot, and has the following fields:
• USERID Telegram User ID, this is unique for every Telegram user
• USERNAME Telegram User Name
Qlik
18
Telegram Bot for Qlik Sense 2.1 Installation guide
• QSUSERID Qlik Sense User ID, in case we want to map a Telegram user with an
existing Qlik Sense user.
• QSUSERDIR Qlik Sense User Directory, in case we want to map a Telegram user with
an existing Qlik Sense user.
• QSUSERNAME Not used
• LASTACCESS Last time the user talked to the bot
• ALLOWED Y or N. If N, the bot will not answer this user, except with a message
saying the user is not allowed. The default value for new users can be set in the config
file.
• LANGUAGE Not used
• EMAIL For future use.
• ACCESSCODE For future use.
Reports
In C:\JG Bot\Reports you can copy all the NPrinting reports you want to be available to the
users when they ask reports to the bot. Every PDF file in this folder will be shown to the user
for he to choose the one to be downloaded.
I have included some sample NPrinting reports, but you can replace or add your own reports.
The default report sent when an alert is launched can be defined in the config file.
As a first step, you will have to modify the QlikSenseBot.exe.config file with all the folders in
your server, and the APIs keys needed to run everything. This is a XML file, you can edit with a
text editor like Notepad, for example:
Follow the instructions to change every key in this file with the correct value you have from
your installation. For example, if you go to the line:
You must replace the value (Your Bot Token Here) with the key value Telegram sent to your
when the Bot was created (maintaining the quotation marks). The following keys must be
configured in this config file before running the bot program:
Qlik
19
Telegram Bot for Qlik Sense 2.1 Installation guide
Qlik
20
Telegram Bot for Qlik Sense 2.1 Installation guide
If you want to use a template for this file, here you have one based on the default settings
described in this document, where you can fill the gaps (specially the Bot token and the
qsserver name):
QlikSenseBot.exe.c
onfig
Now that everything is configured, go to the C:\JG Bot\Bot Software folder, and run the
program QlikSenseBot.exe.
Qlik
21
Telegram Bot for Qlik Sense 2.1 Installation guide
A Windows Console application will run, and every start step will be shown in the console
window. Check there are no error messages, like in the following image:
Qlik
22
Telegram Bot for Qlik Sense 2.1 Installation guide
Appendix – Troubleshooting
No connection could be made because the target machine
actively refused it
¿Have you assigned a token to the user running the bot software? ¿Does he have access to the
stream and app configured for the Bot?
We can tell Qlik Sense to avoid this version checking by setting the parameter
cntCheckSDKVersion to N, in the config file.
Error opening the Qlik Sense app : System.NullReferenceException: Object reference not set to
an instance of an object. at Qlik.Engine.Session.WithApp(IAppIdentifier appIdentifier, String
sessionToken) at Qlik.Engine.LocationExtensions.App(ILocation location, IAppIdentifier
appIdentifier, ISession session, Nullable`1 noVersionCheck, Boolean noData)
This could be happening because the virtual proxy the Bot is connecting to the local Qlik Sense
server is configured to allow Anonymous user. Change this setting to No anonymous user:
Qlik
23
Telegram Bot for Qlik Sense 2.1 Installation guide
System.Xml.XmlException
And probably the program will stop working and Windows will propose to close it.
This could be due to format error in the config file. For example, you have changed something
but have delete an end symbol “>”, or not closing a string value with quotes, check the config
file has a valid XML format.
The Bot uses the Chart title, thus the recommendation is to fill titles in the app charts.
Try waiting for a couple of minutes and start the bot again, and review the licenses for the Bot
user.
Also, be sure Enable Integrated Windows Authentication is enabled in the Internet Options, so
the user running the bot program will be able to access the single object link.
Qlik
24
Telegram Bot for Qlik Sense 2.1 Installation guide
• It is advisable to use a Qlik Sense app with the master items in this language, to avoid
mixing languages in the same sentence and confusing the NL engine.
• If you also want to have the bot messages translated, contact me
([email protected]) to include a resources translation for your language in the bot
software.
Qlik
25
Telegram Bot for Qlik Sense 2.1 Installation guide
qs- ShowElementsBelow R Param Entity Value show me the customers with sales bello
ShowElementsBelowValu Value No Dimension @Dimension $Dimension w 5%
e No Measure @Measure $Measure
Tell me which deals have margins less t
No Percentage @sys.percentage $Percentage
No Number @sys.number $Number
han 20%
qs-ShowKPIs ShowKPIs None Show me KPI
what are my kpis?
qs-ShowListOfElements ShowListOfElements R Param Entity Value list all state names
No Dimension @Dimension $Dimension Show me the list of customers with milk
No Element @Element $Element
qs-ShowMeasure ShowMeasure R Param Entity Value may I know the sales?
Yes Measure @Measure $Measure show me the expenses
let me know the margin
Qlik
26
Telegram Bot for Qlik Sense 2.1 Installation guide
3. To train the Natural Language model (or agent), it is recommended to use quite
sentences in every intent, and review and correct the parameters identification. Try
with some sentences in the new language.
4. In the Training section, there are more possibilities to train the model. Mainly,
reviewing the history of requested sentences, and uploading a set of sentences to
review and train the model. Do this periodically, especially at the beginning.
Qlik