For this new project, I have implemented some of the chat capabilities Telegram offers, mainly oriented to the Qlik Sense master items, and more precise, to Qlik Sense master measures.
Using the new Chatbot interface, I have a development able to receive the messages sent to the Chatbot, process them, and send a response back to the user. At this moment, only a few predefined commands and if not a command, the bot will try to find a master measure to send its value. Natural Language Processing is enough complex for other set of articles, probably after a well deserved vacations (I need to make a pause about bots, to be able to return with new articles ).
Now, you can find a new Visual Studio solution in Github here: https://github.com/jgerardoc/QlikSenseSDKChatbotTelegram. This solution implements the Telegram integration, and extends the Qlik Sense Easy library with more functions to get information from a Qlik Sense server. The new modules are structured to separate the integration with Qlik Sense and the integration with Telegram:
To run the new project you need to fill the different parameters for Qlik Sense (see previous article: Step 1 - Prepare the Qlik Sense Server). But now you will also add the Telegram Chatbot token in the variable cntBotToken. To create a Telegram bot and get this token, you can follow the instructions in this post: Step 2a - Register a Chatbot in Telegram.
About the security, we are going to use the Telegram User ID as the Qlik Sense User ID. So every user that accesses the bot, will do it with a new user with his Telegram ID. In the Telegram module, there is a function called CheckTheUser() that manages all the logic to connect the users, make the Header Authentication and open the connection with Qlik Sense:
If the Telegram Bot is running sucessfully, you will see in the program console something similar to this example:
A few improvements have been done to this version:
- Telegram integration (TelegramBot.cs)
- Added all the Bot setup and initialization (the token from the BotFather is needed here)
- BotOnMessageReceived() is called every time a user send a text message to the Bot.
- CheckTheUser() is the function to check the user and open a different session in Qlik Sense for every user. At this moment, all users are allowed to use the bot, but here is the best place to limit the access if we want to, for example based on the Telegram UserId.
- Predefined commands are managed from this module:
- Sales: Show a predefined sales calculation.
- Margin: Show a predefined margin calculation.
- Inventory: Show a predefined inventory calculation.
- Cost: Show a predefined cost calculation.
- Kpi: Show a predefined list of the last 4 measures plus a button of Full Analysis, all with a button menu. The Full Analysis button will go directly to the first sheet of the app.
- Hello and Bye answers
- Help to show some guidance if user does not know how to use the bot
- By default, if no previous action is detected, the bot will try to use the sentence sent as a filter to find some measure from all the Master Measures defined in the app master items.
- Qlik Sense Easy
- Read master items, like measures and sheets.
- Get measures and expressions values, as plain numbers or formatted.
So, for this new project, make the same changes as before for the Qlik Sense connection, and then fill the Telegram bot token. Run the app and try some tests. For example:
- KPI --> And select some buttons
The bot will show something like this:
Now you have the basics to start with basic functionallity for Telegram Chatbots with Qlik Sense.
Please, let me know about your bots, your experience about this new user interface, etc. Are you able to run a real Chatbot project with my guidance? Do I missed anything?
Juan Gerardo Cabeza