An IBM Watson chatbot skill to answer specific questions

The French National Assembly has legislators organized in groups. We want a chatbot to be able to answer questions like:

  1. To which group belongs X (some legislator)?
  2. Which legislators are part of group Y?
  3. Is X a member of group Y?
  4. What are the groups?
  5. Who are the legislators?
  6. How many groups are there?
  7. How many legislator are there?

A type of question is known as an intent, it includes variations of a question, for instance “To which group belongs X” may also be “In which group can we find X”, or “Is X a member of group Y?” may also be “Is Y the group of X?”. Intents are part of dialog skills that can be created for assistants (chatbots). You’re presumed to be already familiar with the chatbot framework of IBM, if you’re not you may consider this course. This 10-minute-video is great to see used the elements discussed below.

I identify entities as part of the question to reference the intent. I use the prefix Maybe for these entities because maybe they’re not what one may expect in this context, for instance, Zinedine Zidane is not a legislator. I use various means to refer to one person: title + full name, full name or just surname. Likewise, groups can be shortened, here “En Marche” stands for “La République en Marche” and “communists” stands for “Député-e-s Communistes et Républicains”.

I don’t give any possible value for these maybe entities. Back in the intent, entities can be annotated. Hold shift to annotate a group of words.

This intent can be used to create a node that will identify the entities.

Turn on the slots in the settings (customize) for this node to retrieve these entities.

So you can store the values for these entities in variables. Mind how we also store the intent in a variable named $intent.

In addition to slots, you may use (other) parameters but we won’t use them in this instance.

These variables will be processed by an action.

You need to enable it as a web action. Copy the public url to which you will add .json at the end.

Back to the node in the dialog, you need to turn on the webhook the same way you turned on the slots. Use it to return a webhook variable (without $).

Click on Options to configure your webhook with the url you copied.

Back in the node finally say you want to jump to another node after you waited for an answer from the webhook.

The new node simply recognizes true and respond with some message from the webhook. If you try the chatbot now and that the intent is properly recognized, this message will be “Hello World”.

It’s because we haven’t yet coded the action we created. So back to it we can finally see some code.

For instance if you replace this code with:

function main(params) {
return { message: ['a', 'b', 'c', 'd'] };
}

You can then in the node of the chatbot iterate through this list and print its elements one by one (line by line) in JavaScript with:

<? $webhook.message.join('<br/>') ?>

All you need now is to make good use of the parameters you transmitted to the action:

function main(params) {
switch (params.intent) {
case "#is_MaybeLegislator_in_MaybeLegislatorGroup":
return { message: "I should now tell you whether " + params.MaybeLegislator + " is part of " + params.MaybeLegislatorGroup + "!" };
default:
return { message: "Unkown intent " + params.intent + "!" };
}
}

You should be good to go with your own project now. A final product will obviously require more nodes and more code, but all the necessary mechanisms have been covered.

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Pierre-Yves Dumas

Pierre-Yves Dumas

More from Medium

BabySPELL — Everything you need to know

In this part, we are going to delve into how project selection workflow works so our community as…

Ecuador volcanoes part 3:

Supporting Teachers to Follow the Fun — Building New Avenues for Teaching During COVID and Beyond