4

While Defining the Dialog in the Watson Conversation I'm not able to greet user with his/her name or I'm not able to detect contact number sent by the user and rephrase it to the user. Is it possible to do it in the Watson Conversation Api or not.

user2881430
  • 367
  • 1
  • 5
  • 17

3 Answers3

6

Although Mitch's response is correct, here is an example of doing a personalised response.

1. Set your conversation_start node text to "Hello <? context.username ?>".

enter image description here

2. In your code you would do something like this (Python).

import json
from watson_developer_cloud import ConversationV1

conversation = ConversationV1(
    username='SERVICE_USERNAME',
    password='SERVICE_PASSWORD',
    version='2016-07-11')

workspace_id = 'WORKSPACE_ID_CONVERSATION'

response = conversation.message(workspace_id=workspace_id, context= {'username':'Simon'})

print json.dumps(response)

3. When you run this, it should output the following, with the "text" part being what the user sees.

{
  "entities":[],
  "intents":[],
  "output":{
    "log_messages":[],
    "nodes_visited":["node_1_1472298724972],
    "text":["Hello Simon"]
  },
  "context":{
    "username":"Simon",
    "conversation_id":"9dc1501b-ac53-4b51-a299-37f5314ebf89",
    "system":{
      "dialog_turn_counter":1,
      "dialog_stack":["root"],
      "dialog_request_counter":1
    }
  },
  "input":{}
}

One thing to be aware is that, the context object is used to maintain the state of the conversation. So if you plan to use just REST API's then you need to merge your context variables into the preceding context object before sending it. You do only need to do this at points where you do know the conversation needs that context.

Simon O'Doherty
  • 9,259
  • 3
  • 26
  • 54
  • What do you mean when you say -"In your code you would do something like this (Python)." Where should I include this code snippet?Additionally,Is there any way of not hard coding the username?(I see you have hard coded Simon) but instead get the user to input his name and use it. P.S. I am novice in Bluemix – Athif Shaffy Dec 11 '16 at 13:59
  • It's hard coded for example, but you would load that through your application. – Simon O'Doherty Dec 11 '16 at 14:00
  • Where should I code the python code snippet? Should I run it locally in my pc or should I integrate it to the conversation service?If I am to integrate to the conversation service,how should I go about with it?If you could provide a link to any tutorial,it would be great – Athif Shaffy Dec 11 '16 at 15:37
  • 1
    @AthifShaffy I have some examples on my blog. https://sodoherty.com but you can also check out the conversation examples: https://www.ibm.com/watson/developercloud/doc/conversation/sample-applications.html – Simon O'Doherty Dec 12 '16 at 09:55
4

Do you already have access to this information? You can send these values through as context, and refer to them using $context_variable The same goes for collecting information from a user. You can capture things using regular expressions via your application, or using some Spring Expressions, you can see the text.matches here: https://www.ibm.com/watson/developercloud/doc/conversation/dialog_reference.shtml You would store this as context, and then refer to it using $context_variable again. Information like names and phone numbers is quite open ended, so can be difficult to capture without using an open entity extraction engine, which we are researching best ways to incorporate this.

Mitch
  • 849
  • 4
  • 4
-1

To get the user's input, use:

"context": {"yourVariable": "<?input.text?>"}

And to show:

"output": {"text": "You entered this $yourVariable"}
J. Watson
  • 11
  • 1