Qlik Community

Qlik Design Blog

All about product and Qlik solutions: scripting, data modeling, visual design, extensions, best practices, etc.

Employee
Employee

Qlik Sense Bot with Node.js and Enigma.js

Qlik_BOT_Headers_Telegram.jpg

Hello everyone. After I saw the popularity of Juan's Qlik Bot for Telegram written all in C#, I decided to create another one in JavaScript with Node.js‌ and Enigma.js. Today I am going to share with you the code and how to get started creating your own bot for Telegram on any Operating System that has Node.js installed.

The server will be running under https so if you do not have valid certificates for your domain, or localhost if you are testing it on your local computer, you can have Qlik Sense Enterprise take care of that for you. From QMC, go to start->Certificates and then export for localhost using the "Platform Independent PEM-format"

export-certificates.png

Copy these certificates and paste them into {QlikBotNode folder}/app/server/certs/localhost

I have used 3 apps in this, helpdesk, Salesforce and CIO dashboard. The qvf for helpdesk is bundled in your Qlik Sense Desktop while the Salesforce one you can get from Salesforce/Files at master · yianni-ververis/Salesforce · GitHub and the CIO Dashboard one from CIO/Files at master · yianni-ververis/CIO · GitHub.

Now lets get the code from GitHub - qlik-bots/QlikBotNode: QlikBotNode is a server build in nodejs, expressjs and MySql that co...

From the command line using your favorite tool, I am using Git Bash for this one, type Npm install to get all of the required modules.

Install MySql or Xampp / Wamp and connect to it. Xampp is bundled with phpmyadmin so you can use that. Then create the database and the tables by running sql query (QlikBotNode/sensebot.sql at master · qlik-bots/QlikBotNode · GitHub)

Every platform, upon creation of the bot, it gives you some tokens so your code can authenticate with the platform's servers. Once we have these tokens, for security reasons, we need to set them as environment variables. So, lets create our bot and get our token.

Once you install Telegram Desktop, go to your "BotFather" contact and type "/newbot". Everything in Telegram that starts with "/" is a command. So we typed the command to create a new bot. This will give you an options menu to configure your bot.

settings.png

Go ahead and give your Bot a name, an icon and a description. If you click on "Back to Bot", you will get a button with the "API Token". Take that token and store it as Environment Variable.

In windows you have to go to "Control Panel" -> "System" -> "Advanced System Settings" -> "Environment Variables" and set a new one as "TELEGRAM_BOT_TOKEN", while in Linux, from your directory (~), type "nano .bash_profile" or "vim .bash_profile" and enter a new line with the token "export TELEGRAM_BOT_TOKEN=######".

Now you should be ready to run your code. From the command line (Git Bash), type "gulp". If everything goes well and you do not have any errors, you should see a message "[nodemon] starting `node app/server/server.js`". Your server is up and running and communication via the Token auth has been established.

Now lets explore the Bot.

  • Type help to view all of the available commands main.png

  • Click on the Salesforce button or type /salesforce salesforce.png
  • Here, there are some buttons to get KPIs and one that takes you to the mashup for validation. Try them all!!!!!
  • Click on the CIO button or type /cio and then click on "Management" to get the set of KPIscio-dashboard-management.png
  • Click on the Helpdesk button or type /helpdesk helpdesk.png

That's it! Now you can a have a Node.js server running with your QlikBotNode and you can start experimenting with KPI commands in the Telegram app.


The code is open sourced at GitHub - qlik-bots/QlikBotNode: QlikBotNode is a server build in nodejs, expressjs and MySql that co...

35 Comments
eliran_s
Contributor II

Well done! I can't wait to check it out.

11 Views
paulyeo11
Valued Contributor II

BOT is a very interesting topic in QS , many people are looking forward to having such feature. Hope that some one can make it more simple.

0 Likes
11 Views
valerio_fatatis
New Contributor III

Very interesting topic...

Great Functionally!!

Well done


0 Likes
11 Views
rahulvagadiya
New Contributor

Real nice demo, jvs

I am working on Telegram Bot integration with Qlik Sense.

Do you have any examples or direction for how to authenticate a Qlik Sense user to get the reporting directly from Qlik Sense via the bot?

Something similar to what the Youtube Telegram Bot is doing to authenticate the user (check the flow here Telegram: Contact @youtube), but for Qlik Sense authentication.

Expected flow:

- User clicks on command "Login to Qlik"

- web view opens up in Telegram for the user to login to qlik (this would be the SAML / AD login page into qlik window server)

- after login the web view closes and the bot has the user's Qlik User ID and User Directory

Appreciate any help.

Thanks,

Rahul

0 Likes
11 Views
Employee
Employee

That is my next move.

Soon....

0 Likes
11 Views
rahulvagadiya
New Contributor

Great, would you be able to share some advise on how to go about it?

Thanks!

0 Likes
11 Views
Employee
Employee

Very nice Yianni - I was able to get this running rather quickly - next I will attempt to incorporate my own app.

Great Work!

0 Likes
11 Views
nikhilgarg
Contributor III

Hey Rahul,

I have just started to integrate QlikBot with QlikApp. But dont know from where to start. Can you help me in this?

0 Likes
11 Views
nikhilgarg
Contributor III

Hey Mike,

I have just started to integrate QlikBot with QlikApp. But dont know from where to start. Can you help me in this? There are no videos as well for the same.

0 Likes
11 Views
Employee
Employee

Hello Nikhil,

Have you installed the Bot? Did you run it? Is it working? Do you see a welcome screen?

I need to know at what stage are you so I can help you.

Best,

Yianni

0 Likes
11 Views
nikhilgarg
Contributor III

Hey Yianni,

I have unzipped the QlikBotNet zip file. After that I am not sure what to

do. Do I need to make a azure account or something? Can you guide me?

0 Likes
11 Views
Employee
Employee

I can only help you with the Node version which I have created.

For .Net you can find details here:

https://github.com/qlik-bots/QlikBotNet

and contact Wu for more details:

https://github.com/wuzhong-zhu

baz

Also our Bot Group page is here:

Qlik Bots

0 Likes
11 Views
Employee
Employee

I forgot to mention Slack

#qlik-bots

0 Likes
11 Views
nikhilgarg
Contributor III

Well if you have successfully integrated bot with qlikapp then I can use

QlikBotNet as well. Pls guide me for qlikbotnode.

0 Likes
11 Views
Employee
Employee

You can start by going through the steps on this blog post.

Then you can

and the latest blog about authenticating users and keeping selection states

qlikBotNode - authenticate users with certificates

Also more reading

basic installation here:

https://github.com/qlik-bots/QlikBotNode

For Telegram here:

https://github.com/qlik-bots/QlikBotNode/blob/master/docs/Telegram.md

and/or Skype here:

https://github.com/qlik-bots/QlikBotNode/blob/master/docs/Skype.md

If you have issues on any of those steps, let me know.

0 Likes
11 Views
nikhilgarg
Contributor III

Sure, I will go thru the links shared and in case if I have any issues,

will get back to you.

0 Likes
11 Views
nikhilgarg
Contributor III

Hey Yianni,

I have gone thru the Link shared by you for 'Skype'. I am not able to create a bot service. When i click on  AI + Cognitive Services > Bot Channels Registration, i am not getting any option to create Bot service. Pls help

0 Likes
11 Views
ankit_singh
New Contributor II

Hi Yianni,

    After completing the configurations it is working as expected. However, I am facing few issues.

Below undefined javascript error and:

error: error: {} model=Enigma::getHyperCube()

error: error: {} model=Enigma::kpiMulti()

info: error: Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client model=models/sense-bot/Db::get

info: error: Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client model=models/sense-bot/Db:Smiley Tongueut

info: helpdesk-main route=api/sense-bot/telegram

info: cio-main route=api/sense-bot/telegram

info: cio-management route=api/sense-bot/telegram


simultaneous stack trace for those errors.

Capture.PNG

Capture.PNG

jvs‌ can you please help.

0 Likes
11 Views
Employee
Employee

It seems you cannot connect to MySql.

Do you have this in your DB?

this.config = {

host: 'localhost',

user: 'sensebot',

password: '1234',

database: 'sensebot'

};

https://github.com/qlik-bots/QlikBotNode/blob/master/app/server/models/sense-bot/Db.js

0 Likes
11 Views
ankit_singh
New Contributor II

Thank you Yianni for your response. I edited Db.js with below data on my local machine and restarted gulp.

this.config = {

host: 'localhost',

user: 'local',

password: 'local',

database: 'sensebot'

};

also have this database in my sql:Capture.PNG

I also updated:

mysql> select plugin from user where user='local';
+-----------------------+
| plugin                |
+-----------------------+
| caching_sha2_password |
+-----------------------+
1 row in set (0.00 sec)

mysql> update user set plugin='mysql_native_password' where user='root';
Query OK, 1 row affected (0.25 sec)
Rows matched: 1  Changed: 1  Warnings: 0

However I am still facing same error. Is there any problem in communication between Node server and MySQL server.

Again thank you for your help.

0 Likes
11 Views
Employee
Employee

I think you need to set privileges

GRANT ALL ON sensebot.* TO 'local'@'%';

GRANT SELECT, EXECUTE, SHOW VIEW, ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE VIEW, DELETE, DROP, EVENT, INDEX, INSERT, REFERENCES, TRIGGER, UPDATE, LOCK TABLES ON `sensebot`.* TO 'local'@'%' WITH GRANT OPTION;


FLUSH PRIVILEGES;

0 Likes
11 Views
andyjalexlive
New Contributor

Hi Yianni,

Great post. Can i set this up without Qlik Sense Enterprise? i.e using Qlik Sense Desktop

Also, can this node bot be extended to understand natural language?

Thanks

Andy

0 Likes
11 Views
andyjalexlive
New Contributor

Hi Yianni,

The demo bot Qlik Bot Node doens't seem to work anymore in Skype or Telegram. When i click on Dashboard or Opportunities it returns the error message below. Any ideas?


Thanks


Andytelegram snip.PNG

0 Likes
11 Views
Employee
Employee

Thank you Alexander. Everything is fixed now. Please try again

0 Likes
11 Views
vikraant
Contributor

Hi Yianni,

I have tried this. Not supported Auth error is still popping up. Could you please help.

0 Likes
11 Views
Employee
Employee

Hello Vikraant,

Tried what? What Auth error? Are you in the live published one, because I have just checked it and works fine, or on your own servers?

0 Likes
11 Views
vikraant
Contributor

Hi Yianni,

Sorry for not mentioning the problem clearly.

I have set the plugin to 'mysql_native_password'  as per the following

https://github.com/mysqljs/mysql/issues/1507

I have also set privileges as per your earlier message.

GRANT ALL ON sensebot.* TO 'sensebot'@'%';

GRANT SELECT, EXECUTE, SHOW VIEW, ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE VIEW, DELETE, DROP, EVENT, INDEX, INSERT, REFERENCES, TRIGGER, UPDATE, LOCK TABLES ON `sensebot`.* TO 'sense'@'%' WITH GRANT OPTION;

FLUSH PRIVILEGES;

However, I am still getting the following error when i try to send message to the bot via Telegram.

[nodemon] starting `node app/server/server.js`

info: error: Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client model=models/sense-bot/Db::get

info: error: Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client model=models/sense-bot/Db:Smiley Tongueut

Please help!

0 Likes
11 Views
vikraant
Contributor

I guess the problem is with mysql 8. i have installed mysql 5.7.22. It is working fine now Thanks

0 Likes
11 Views
gaurav_janoti
New Contributor

Hi jvs

I have done full configuration setup as described by you but i am not getting any response in telegram.

Also after successfully running server i am getting message in console as  ""Failed to get update" (as in below screenshot).

botIssue.PNG

Please help me out of this error i am not getting any clue to solve it.

0 Likes
11 Views
Employee
Employee

Hello Gaurav,

This is telegram's ip. Check your firewall or ask your IT if its blocked. It seems that it is...

After you do that, make sure that you have the correct token.

0 Likes
11 Views