Need of Context in a chatbot conversation

This blog post introduces the Importance of Context to maintain the state of a Conversation while building a bot more specifically a chatbot.

A conversation (or chat) is a chain of statements exchanged between two or more individuals. Mostly, conversations happen on a particular topic or in a situation. Whatever the topic or situation is, Context is very important to maintain the state of a conversation.

Conversation Chatbot

In the world of cognitive computing, computers are conversing with humans as ChatBots or in short Bots. As Alan Turing famously quoted
“A computer would deserve to be called intelligent if it could deceive a human into believing that it was human.”
So, even computers need the so called Context to keep the conversation flowing and to deceive us as humans.

Why am I so contextual today? Looks like chatting with a WatBot for a week took a toll on me or reading the below line from the Watson Conversation documentation had its impact,

State information for your conversation is maintained using the context. The context is a JSON object that is passed back and forth between your application and the Conversation service. It is the responsibility of your application to maintain the context from one turn of the conversation to the next.


A context includes a unique identifier for each conversation with a user, as well as a counter that is incremented with each turn of the conversation. If we don’t preserve the context,  each round of input appeared to be the start of a new conversation. We can fix that by saving the context and sending it back to the Conversation service each time.

Code to achieve Context persistence

In Javascript,

In Android, using Watson Developer Cloud Java SDK

Check the complete Android code –  WatBot Repo on Github

In Swift 3.0,  using swift watson sdk

In addition to maintaining our place in the conversation, the context can also be used to store any other data you want to pass back and forth between your application and the Conversation service. This can include persistent data you want to maintain throughout the conversation (such as a customer’s name or account number), or any other data you want to track (such as the current status of option settings).


Polyglot & Pragmatic Programmer • Developer Advocate, IBM Cloud • Intel software Innovator • DZone MVB
(Visited 228 times, 1 visits today)

You may also like...

Show Buttons
Hide Buttons