Start building your own chatbot now!

You may have seen Node.js mentioned in other SAP Conversational AI tutorials and, unless you’re a developer, Node.js may look scary. But once you understand why SAP Conversational AI chatbots sometimes use Node.js and how the platform works with it, Node.js might seem less daunting. And who knows? Some day you might even decide to make a chatbot that uses Node.js yourself. This blog won’t show you how to do that, but it will try to unravel some of the mystery surrounding Node.js.nodejs_for_dwight_large

What is Node.js?

Node.js is essentially an app that works like a server. It can open files, get data that’s stored locally or online, generate text, and much more. A developer can write some code, and Node.js will read it and do whatever the code says. The code the developer writes is considered a Node.js application.

Why use Node.js anyway?  

As a non-developer, you can build a pretty sophisticated chatbot in SAP Conversational AI without ever bothering with Node.js. On the other hand, a developer can build an equally sophisticated chatbot using mostly Node.js and less of the SAP Conversational AI functionality. So, where do SAP Conversational AI and Node.js usually meet?

Generally, a chatbot that uses SAP Conversational AI and Node.js will first take advantage of the natural language processing (NLP) that SAP Conversational AI offers, with its intents, entities, and expressions. The chatbot uses this functionality to determine from a conversation what information the user wants. If the information must be fetched and calculated or processed, the chatbot can use Node.js for these purposes and have it return the desired information to the chatbot, which displays it for the user.

How do SAP Conversational AI and Node.js work together?

In the chatbot shown below, for example, when a user types “I want to change my report”, the expression “change my report” will find two entities: “#VERB_EDITING” and “#NOUN_REPORT.” These entities help the chatbot determine what information the user wants and what the chatbot’s Node.js application will need to fetch.

chatbot-sap-conversational-ai

entities-sap-conversational-ai

Entities detected

While NLP does its work, each exchange between user and chatbot is sent to SAP Conversational AI to look for intents and entities in the conversation:

bot-connector-callback-url

When it’s time to use Node.js, the chatbot must connect to the Node.js application that the developer has written for it. This connection between the chatbot and the Node.js application is called a webhook.

bot-builder-webhook-url

When and how does SAP Conversational AI use the webhook?

The person building the chatbot must create a skill that calls the webhook when certain intents and entities are found in the conversation.

call-webhook-sap-conversational-ai

Let’s look at the example of our Movie Bot tutorial. If the user enters “I want to watch a movie western”, the chatbot’s NLP will understand the following:

  • Intent: “@discover”
  • Entity: #RECORDING (“movie”)
  • Entity: #GENRE (“western”)

movie-bot-nlp-intent-entity-detection

The presence of the above entities in the conversation triggers the skill, which then calls the webhook.

In this example, the webhook points to a directory named “discover-movies”, where the Node.js application is stored for this particular chatbot.

What does the developer’s Node.js application do after the webhook is called?

Once the webhook is called, a connection is made between the chatbot and the Node.js application. Now the application can ask SAP Conversational AI to send any intents and entities it has found. SAP Conversational AI sends them in a format that the application can read and crawl through.

What we see in the SAP Conversational AI Bot Builder

What the Node.js application gets

For example, the application can crawl through the information shown under “What the Node.js application gets” to find the intent “discover” and two entities: “recording” and “genre”. The application can crawl deeper to see the following:

  • The “recording” has “movie” (instead of “tv show” or some other media format).
  • The “genre” has “western” (instead of “comedy” or “drama”).

With that information, the application now knows to search for movies that are classified as Westerns. It can then search a movie database to find a list of Westerns and send that list back to the chatbot.

Every step the application takes is made possible by Node.js.

And that’s it. In a way, what Node.js is and does is both simple and complicated at the same time. Connecting a chatbot to a Node.js application is straightforward enough. The tricky part, for us non-developers, is writing the code for the Node.js application. However, no matter how complicated a Node.js application for an SAP Conversational AI chatbot is, it will usually use the same code for the following basic tasks:

  • Connect to SAP Conversational AI
  • Receive information from the chatbot
  • Send information to the chatbot to display to the user

In my next blog, I’ll go over those basics. Learning them will round out your understanding of how Node.js works with SAP Conversational AI chatbots. In the meantime, don’t hesitate to comment using the section below and follow us on LinkedIn, Twitter or SAP Blogs.

There are currently no comments.

This site uses Akismet to reduce spam. Learn how your comment data is processed.