IBM Watson Chatbot

  • Cubettech
  • Artificial Intelligence
  • 7 years ago
IBM Watson Chatbot

IBM Watson is a cognitive technology that combines artificial intelligence and innovatory analytical software for optimal performance. It is a collection of about 30 products, aimed at dozens of small to large industries and requires anything from little technical knowledge to advanced data science skills. Watson can understand, perform reasoning, learn and interact like a human being.

IBM Watson: –

  • Can analyze and interpret huge volumes of unstructured data, including images, audio and video.
  • Can support search engines or an expert system with capabilities far superior to any previously existing system.
  • Can provide personalized recommendations by understanding the user’s personality, tone and emotion.
  • Can utilize in machine learning to grow the subject matter expertise in apps and systems.
  • Can create chatbots.

Watson is available as a set of open APIs and SaaS products. IBM API connect is an API management solution from IBM Bluemix that addresses critical aspects of the API lifecycle for both on-premises and cloud environments providing the capability to create, run, manage and secure APIs and microservices. Watson is used in educational, healthcare, commercial, and a variety of other fields.

Chatbot

Chatbot is a prominent way for users to interact with an organisation. It can be one of the keys to success of a business since it provides immediate communication with the customers. A chatbot can speak in our own language and can offer support to the customers and answer their questions. By adding a chatbot interface to our app, website or even to social channels, an efficient and fast customer communication can be ensured.

IBM Watson conversation services helps to build chatbots that can understand our natural language, and we can quickly build, test and deploy them on the messaging platform. The conversation service gives a visual dialog builder to train the chatbot without any coding experience.

Authentication: In order to work with the Conversation service, a username and password is essential. For that, we need to register with IBM Bluemix. It is a paid service, but is available for a 30 days free trial. After the registration and email verification, On this page, click on the ‘Catalog’ tab and click on services > Watson from the category section, select Conversation service and create the username and password. This username and password will act as the authentication for accessing the Conversation service.

Methods: Below is a simple example of javascript ajax code for sending the chat messages and deploy the reply to the chat interface.

$(document).ready(function() { var context ={}; //method to trigger when user hits enter key $("#shout_message").keypress(function(evt) { if(evt.which == 13) { var message = ($('#shout_message').val()).trim(); //reset value of message box $('#shout_message').val(''); if(message){ $('.message_box').append('<div class="rgt">'+message+'</div>'); $("#loader").show(); $.ajax({ type : "POST", url : "http://localhost:3030/message", dataType: 'json', beforeSend: function (request) { return request.setRequestHeader('X-CSRF-Token', $("meta[name='csrf-token']").attr('content')); }, data : {"message":message, "context": context}, success:function(data){ //keeping the context value context = data.context; $("#loader").hide(); $('.message_box').append('<div class="lft">'+data.msg[0]+'</div>'); //keep scrolled to bottom of chat! var scrolltoh = $('.message_box')[0].scrollHeight; $('.message_box').scrollTop(scrolltoh); } }); } } }); });

The IBM Watson has well explained tutorials for each services. So you don’t need a developer to understand about the services and use it. They also provide demo videos. Also, a lot of youtube videos are available which explain each and every step.

 The first step of conversation tool is to create the workspace. A workspace is a container for the artifacts that define the conversation flow for an application. After you log in, type conversation-tutorial in the Service name field, click Create, and then click Launch tool. Go to for details. From the credentials tab we will get the username, password and workspace-id. These credentials will be used in the following code.

var express = require('express'); var app = express(); var bodyParser = require('body-parser'); var path = require('path'); var ejs = require('ejs'); var http = require("http"); var request = require('request'); var cors = require('cors'); //credentials var user_name = 'xxxxxxxxxxxxx'; var pass_word = 'xxxxxxxxxxxxx'; var work_id = 'xxxxxxxxxxxxxxx'; // view engine setup var whitelist = ['http://localhost'] var corsOptions = { origin: function (origin, callback) { if (whitelist.indexOf(origin) !== -1) { callback(null, true) } else { callback(new Error('Not allowed by CORS')) } } } app.use(cors()); app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); //route setup app.post('/message', cors(corsOptions), function(req, res) { var watson = require('watson-developer-cloud'); var conversation = watson.conversation({ username: user_name, password: pass_word, version: 'v1', version_date: '2017-02-03' }); conversation.message({ input: { text: req.body.message }, context: req.body.context, alternate_intents: true, workspace_id: work_id }, function(err, response) { if (err) { console.error(err); } else { console.log(JSON.stringify(response, null, 2)); res.send({ msg: response.output.text, context: response.context }); } }); }); var httpServer = http.createServer(app); httpServer.listen(3030,'localhost');

Conclusion

IBM Watson is one of the greatest technology which utilizes artificial intelligence. Watson has a variety of smart services and by using these services, we can build our own innovative applications. I hope this blog will help you to have a fundamental understanding about IBM Watson and the chatbot using its conversation service.

Do you have any questions/comments related to building a chatbot? Contact us at info@cubettech.com

Thanks!

Know More About This Topic from our Techies

Other Blogs:

Table of Contents

    Contact Us

    Contact

    What's on your mind? Tell us what you're looking for and we'll connect you to the right people.

    Let's discuss your project.

    Phone