Skip to main content
Yianni_Ververis
Employee
Employee

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...

41 Comments
prajuds99
Contributor II
Contributor II

HI Yianni,

I am facing same error as Andy.

Error: TypeError: Cannot read property '0' of undefined

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

info: helpdeskHighPriorityCases route=api/sense-bot/telegram

info: error: Error: connect ECONNREFUSED 127.0.0.1:4747 model=models/utilities/Enigma::connect()

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

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

I have downloaded the latest code from GitHub.

Could you please help.

0 Likes
1,177 Views
lwileczek
Contributor III
Contributor III

Yianni,

Please review my pull request on GitHub for SenseUI-ComboChart.

0 Likes
1,177 Views
Yianni_Ververis
Employee
Employee

lwileczek‌ done! Sorry for the late reply

1,177 Views
lwileczek
Contributor III
Contributor III

Thank you! I may be adding more updates in the future as well. I am using this extension thoroughly, and want other to be able to use these as well. Cheers.

0 Likes
1,177 Views
shabaan33
Contributor III
Contributor III

Hello Yianni,

Thanks a lot for such great blog on integrating telegram with Qliksense. As per your guidance i have installed all modules from npm install. Also i have configured telegram and created environment variables.

But now when i run gulp in GitBash, i am facing an issue/error as attached.gulpError1.jpg

jvs please provide your help on this.Appreciated.

P.S.:- I have not yet done any configuration Qliksense server side.

Thanks,

Shabaan shaikh.

0 Likes
1,177 Views
Sky8lade
Contributor
Contributor

I am getting this error after running gulp

error: uncaughtException: 401: Bot Token is required

Is this something to do with how I set my telegram bot token in the system variables? I am using mac and set it in my bash_profile.

Is this app still working?

 

0 Likes
1,147 Views
agni_gold
Specialist III
Specialist III

How this config.json got created ?

0 Likes
1,109 Views
Sky8lade
Contributor
Contributor

The "error: uncaughtException: 401: Bot Token is required" seems to be a problem on MAC OS, I tried on Windows and Linux and it works fine, however I get the "Error: TypeError: Cannot read property '0' of undefined" as so many people have already mentioned. Is there no other support person who was successful with with this apart from Yianni? I would imagine that this is beneficial for Qlik so any assistance from them would be welcome. 

0 Likes
1,105 Views
jaimecrespin190
Partner - Contributor
Partner - Contributor

I think this is not working anymore?

0 Likes
1,079 Views
Sky8lade
Contributor
Contributor

I got a bit further but using a windows/linux. MacOS gives the 401 bot token error. On windows I can run the bot but if I try to click on a button in the chatbot on Telegram I get an error Error: ER_Access denied for user 'sensebot'@'localhost' (using password: yes) model=models/sense-bot/DB: get. This is my certificates folder structure server>certs>demosapi.qlik.com then I added all the certificates here: client_key.pem, client.pem, root.pem, server_key.pem, server.pem.  

0 Likes
1,068 Views