Skip to content

lucacrippa88/watson-telegram-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Telegram Bot meets IBM Watson!

This tutorial will show how to integrate a Chatbot made with Watson into a Telegram bot built with Node-RED. No coding skills are needed! This tutorial collects all experience gained on Watson Assistant and Node-RED during ASL 2017-2018-2019 sessions.

Features

The final bot will implement natural language chat, vocal message interactions, visual recognition on photos and sentences translation.

  • Implement a Virtual Assistant with Telegram interface creating a Telegram bot
  • Receive vocal messages - easy to use, easy to listen!
  • Ask to translate sentences in many languages
  • Ask for support on the selected topic (in this demo: online retail store assistance)
  • Receive description of photos - you can use your own trained Watson Visual Recognition classifiers!
  • Save orders on DB and manage them (retrieve, edit and delete)

Prerequisites

Prerequisites to get this tutorial done are:

  1. An IBM Cloud account
  2. Choose the option that fits:
  • Do you want to have a custom Virtual Assistant? -> Go to step 3
  • Do you just want to know how it works the Node-RED Watson Assistant integration, of do you already have a trained Virtual Assistant? -> Skip step 3 and go to step 4
  1. Make sure you completed this tutorial to have a custom Virtual Assistant with Watson Assistant: https://github.com/lucacrippa88/watson-assistant-training
  2. You are done with prerequisites!

What to expect from this tutorial

This tutorial will show you how to create a telegram-based interface for your Virtual Assistant with a Telegram bot. All other technical activities are based on the native Node-RED flow interface.

Tutorial

Basic Telegram Watson Assistant integration

Follow these steps to complete the tutorial.

Step 1 - Create a bot on Telegram

  • Search @BotFather on Telegram search bar, type /start and follow the instruction provided. Type /newbot and enter the name of the bot (it must end with "bot")
  • Then, save the token string to use it later in Node-RED

Step 2 - Create a Node-RED application

  • Select Node-RED Starter boilerplate on IBM Cloud catalog
  • Enter needed data and click create
  • You should protect your app with a username and password: you can do so by filling the form once the app is started

Step 3 - Install Telegram nodes on Node-RED

  • Once you are in the main RED dashboard of your app, click in install tab and search for telegram
  • Then install "node-red-contrib-telegrambot"

Note: if the Telegram nodes installation fails, please retry a couple of times.

Step 4 - Use Telegram nodes

  • Add the "Telegram receiver" node
  • Then, add the bot created by inserting the name and the token received from @BotFather by clicking on the pencil icon
  • Setup the switch node: first output should be set == "photo", second == "voice" (to be check), third to otherwise.

Step 5 - Watson Assistant integration

In order to integrate Watson Assistant in a Telegram bot, some nodes are required: "Telegram receiver", "function", "assistant", "function", "Telegram sender".

Advanced Telegram Watson Assistant integration

Step 6 - Adding Watson Visual Recognition

The Virtual Assistant linked below has been created to support users of a retail shop, both online and physical store. You can find here the trained assistant: https://github.com/lucacrippa88/watson-assistant-training/tree/master/online-shop-virtual-assistant

A customer could need to gather information on the product he's looking at. By introducing a Watson Visual Recognition integration, your Virtual Assistant can be able to send information about a product in a picture taken on the shop.

Now you can send a photo to your telegram bot and it will classify the image using Watson Visual Recognition using general classifiers.

Note that with IBM Watson you can easily train your own classifiers to ensure that the AI Visual Recognition feature will have the right knowledge on your custom problem. In example, do you have an enterprise that creates very particular design furniture? You can train your Visual Recognition classifiers on your design products in order to classify them, understand problems/issues during creation process, auto tag and so on!

Step 7 - Adding Watson Translator

Another useful feature to be integrated inside the Telegram bot is the language translation. An user can ask the bot to translate a sentence in real time leveraging on Watson Translator API.

Note: this step needs to train a Watson Assistant to understand translation scope. Please refer to this link to have it done (link to come!).

Step 8 - Adding Watson Text to Speech

An interesting feature that can be easily implemented is the Text to Speech service: this will send you output messages as audio messages, so you will be able to listen to your Assistant answers.

Pro Telegram Watson Assistant integration

The Node-RED Cloud Foundry application created on IBM Cloud for this tutorial comes with a Cloudant DB. Cloudant is an IBM software delivered as a cloud-based service on IBM Cloud, and it is a non-relational (NoSQL) distributed database. By using Node-RED Cloudant nodes, you can easily integrate a DB on your application, making your Telegram bot more useful in day-by-day situations: as a customer orders something by iteracting with the bot, the confirmation of the order should be stored into a DB, to be available for check, controls, operations and cancellations.

Step 9 - Save orders on DB

The first integration between Node-RED Telegram bot is the ability to save customer's orders on the DB.

Step 10 - Retrieve orders from DB

The second step is to add the possibility to retrieve customer's orders from the DB.

Step 11 - Retrieve catalog from DB

Another important feature is the possibility to retrieve the store catalog (available products) from the DB.

Step 11 - Delete orders on DB

Finally, a customer should be able to delete orders in case of mistakes, from which the feature of the deletion from the DB.

To be updated!

Full flow

In the picture below there is the full flow with all modules.

Please note: the Speech to Text flow (with F2 and F10 functions) is still in development, so it is not described in this guide.

Videos

Almost 5 videos are coming (Italian).

Notes

Watson Assistant is being continuously updated. All info and code in these repos should be compatible with new versions of the APIs, even if some notation could change (e.g. "Workspaces" renamed "Skills").

Outcomes

Outcome of conversation with audio message out.

Outcome of Visual Recognition feature. By now it only answers with the most probably recognition, but it's possible also to have the other options displayed.

Disclaimer

This is not an official asset. It has been created by me and it's not intended for professional use. However, it follows all guidelines you can find in https://console.bluemix.net/docs/services/conversation/ and in https://www.ibm.com/watson/developercloud/assistant/api/v1/. For Watson Services SLAs, please have a look here: https://www-03.ibm.com/software/sla/sladb.nsf/sla/bm-0038-09. Video tutorial linked are not official assets.

License

his project uses the Apache License Version 2.0 software license. https://github.com/lucacrippa88/watson-assistant-nodered/blob/master/LICENSE

About

Create a Telegram bot based on Watson services with no coding skills

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published