Wikipedia Factoid Bot (6 of 6) : Build a factoid conversation flow in Watson Conversation

Anthony Stevens
IBM watsonx Assistant
3 min readJan 10, 2017

This is the last of a six part series on training a bot to answer factoids

Post 1: Intro factoid bot demo plus download and configure code
Post 2: Identify famous people as entities using Alchemy Language
Post 3: Initialize the factoid bot’s connection to Watson Conversation
Post 4: Train a factoid bot to classify the intent of a user’s query
Post 5: Extract answers from DBpedia (Wikipedia)
Post 6: You are here

Working Demo: Factoid bot running on Bluemix
Source Code: NodeJS factoid bot on Github

We’re now ready to finalize the design of our conversation within Watson Conversation. This will complete the bot workflow by implementing steps 8 and 9.

High Level Workflow for Factoid Conversation Bot

To this point, our bot has captured the data below from our user’s query about a famous person during steps 1–7:

Step  1:        user query    How old is Brad Pitt?
Steps 2-3: entity @Brad_Pitt
Steps 4-5: intent #person-birthDate
Steps 6-7: birth_date December 18, 1963
years_old 53

These are packaged as JSON and passed to Watson Conversation by ConversationUtils.processUserQuery()

See full code at javascript/conversation_utils.jsConversationUtils.prototype.processUserQuery(...) 
{
var payload = internalThis.getDefaultConversationPayload()
payload.input = req.body.input
payload.context = req.body.context
...
person = payload.context.person
...
payload.context[entity.type] = entity
internalThis.conversation.message(payload,...) {
...
}
...
}
JSON PAYLOAD
{
input : "When was Brad Pitt born?",
context : {
person : {
name : "Brad Pitt",
details : {
"birth_date : "December 18, 1963",
"years_old" : 53
}
},
"conversation_id":"YOUR_UNIQUE_ID",
"system":{
"dialog_turn_counter": 3,
"dialog_stack":
[{"dialog_node":"root"}],
"dialog_request_counter":1
}
}
}
}
NOTE: The JSON payload must include the conversation_id and system values as discussed in the earlier post on classifying user intent.

This JSON context will now become accessible in the tooling as $person.
So we’ll need to add a node in Watson Conversation with this output:

$person.name is $person.details.years_old years old and was born on $person.details.birth_date.

Which becomes:

Brad Pitt is 53 years old and was born on December 18, 1963. 

Let’s implement this in Watson Conversation. Open your factoid bot’s workspace in the tooling and go to the Dialog screen to view the bot’s root-level conversation flow. You’ll recall that we stopped at the $person node of our conversation flow (right-bottom node in image below) at the end of the prior post on training Watson to recognize factoid intents.

Conversation flow up to $person node.

The $person context data has now been passed to Watson Conversation so it will now continue processing the $person node‘s children.

$person node plus children

For our example our case, the #person_birthdate node will be processed and the answer will be returned as below.

And that’s finally the end. Go ahead and explore the other intents and context variables. You might also want to explore some of the advanced methods for interacting with the context as well.

Thanks for reading through this long post, and I hope it was useful. Please post comments below about anything missing from this tutorial. I monitor comments daily and appreciate advice on improvements.

--

--