Building intelligent Telegram BOTs with IBM Watson
In this post I’m going to talk about how building intelligent Telegram BOTs with IBM Watson using Bluemix and nodeRED.
Telegram is a messaging app with a focus on speed and security, it’s super-fast, simple and free. With Telegram, you can send messages, photos, videos and files and you can create groups. Telegram is like SMS and email combined. Moreover Telegram launched a BOT API and platform for third-party developers to create BOTs. BOTs are simply Telegram accounts operated by software, not people, and they’ll often have Artificial Intelligence (AI) features. They can do anything: teach, play, search, broadcast, remind, connect, integrate with other services and you can interact with Internet of Things (IoT) world.
So a Telegram BOT involve two concepts very very important for me: AI and IoT. From my point of view the AI means IBM Watson and IoT means IBM IoT platform.
The idea is to build an intelligent Telegram BOT using the Watson services to introduce some AI features. For example by Alchemy Language APIs the chat text can be analyze to add high-level semantic information like a Sentiment Analysis, the Emotion Analysis, the Concept Tagging and the Taxonomy Classification. In this way a BOT can understand the sentiments and the concepts express in a chat.
Another example is to build a BOT using the Watson Dialog APIs, the Dialog service can help the user to order a pizza or to suggest a good movie to watch.
Moreover a Telegram BOT can act as a smart agent for customer support service: by the Watson Retrieve and Rank service the BOT can resolve directly a service request without the human interaction and without a Trouble Ticketing product.
The Watson Retrieve and Rank service together with Sentiment analysis could be a game changer in the customer support service: my idea is that the algorithm can be interact with the user to resolve a service request but when the user’s sentiment is negative a human operator will swap with the algorithm to manage the problem. The user may not understand when he interacts with an algorithm or when he interacts with a human.
The BOT-customer support scenario is so interesting that I will dedicate a separate post in the near feature.
According to me the best way to building intelligent Telegram BOT with IBM Watson is to use node-RED, there are already Telegram BOT nodes for node-RED, in details there are receiver and a sender node which act as a telegram BOT. The only thing required is the token that can be retrieved by the BOTfather telegram BOT during the BOT creation. Here how to create a BOT via another BOT: the BOTFather
You also can implement your BOT using directly the rest-API. After creating my BOT I created my channel for my tests: https://telegram.me/watsonpoc. Attention to subscribe to my channel you might receive many notifications senseless 🙂
In general a BOT interacts with a Telegram channel or with a single user.
In my Proof Of Concept there are two manly scenarios:
- BOT-channel interaction: the channel is used to send news, alerts based on weather forecast, messaging from software products, real-time data from IoT devices and so on. The interaction BOT-channel is mono-directional, currently a BOT cannot read messages send by the other users on the channel.
- BOT-user interaction: the BOT executes commands send from users and it interacts with the user using the Watson services.
An example of first scenario (BOT-channel interaction) is shown by the follow flow, where my BOT send weather forecast on the channel :
Of course I used the IBM insights for weather API, you can read more details here.
Another example of first scenario is shown by the follow flow, where my BOT sends the sensor data to the channel:
To send Internet of Things sensor data can be useful on a private channel, for example associated to own smart-home, real-time data can be send on the “family telegram channel”.
With this approach the Telegram is used to broadcast messages to anyone who joins and currently this is the most common use of a Telegram channel.
The second scenario (BOT-user interaction) represents my personal thoughts about how IBM Watson services can support the classic AI algorithms as text recognition, semantic analysis, and machine learning.
An example of second scenario is shown by the follow flow, where my BOT waits for an user request :
The telegram node waits for user chat, it can manage a conversation by the Dialog services. This service allows to automate branching conversations between an user and your application. The Dialog service enables your applications to use natural language to automatically respond to user questions.
When the user chats a /SR command the Watson Retrieve and Rank is invoked. You can read details here.IBM Watson Retrieve and Rank service helps users find the most relevant information for their query by using a combination of search and machine learning algorithms to detect “signals” in the data. You can load data into the service, train a machine learning model based on known relevant results, then leverage this model to provide improved results to their end users based on their question or query. By this approach a service request can be managed directly by a BOT without a human operator and without a specific trouble ticketing application.
Here a Telegram chat example about an e-mail configuration problem, I trained a machine learning model on this topic for my previous demo :
In this example the solution is the answer with rank position one and it is just sent to the user.
An extension of second scenario is based on the sentiment analysis, see this flow :
a human operator is alerted if the user opens a service request with a negative sentiment. In this case a human friendly, sensitive, empathetic approach can help to manage a hungry user. You can read details about the sentiment analysis here.
I still remember the first IRC BOT, a set of scripts that connects to Internet Relay Chat as a client, and so appears to other IRC users as another user. Today an user cannot recognize if you are talking with a BOT or with a human being 🙂
Building intelligent Telegram bots with IBM Watson is really fun, and it does not end there.
Your Feedback is Welcome.
Hi, sorry but I cannot post my code 🙂 unfortunately it’s not open source
Hi, can you tell me how to make my bot to send another message without user input? For example, user ask a question, then bot replies and after that sends another message, e.g. “do you need more help?”
I have complex conversation script in Watson Conversation (it’s connected to node-RED on Bluemix) and everything works there, but when it comes to bot on Telegram, I got only one reply.
Thank you in advance
I managed to implement the telegram-nodes and it is working quiet well. Did you also manage to read out sensor values with the “command node” ? For example I`d like to read out the temperature of the temp. sensor that is attached to my arduino by using a telegram command e.g like “/get_temp”. But I got problems with the msg.payload, it somehow does not work to forward the content correctly to telegram. (Gives me an property read error in node-red). However, if i just send some text string it works fine…
Hi, just in this nodeRED I used IBM code that I can’t share as public license. did you test the bot telegram rest-api as http node ?
Hi!
I am currently also trying to set up a telegram bot with node-red. Unfortunately I have problems to get it working…
Could you provide your node-red code? Btw. where did u get this telegram node from? (I see you have a sender node with 2 outputs ? I importet the telegram nodes but mine are a little different, e.g only one output)
Thanks!