-->

How to give personalised greeting in Watson Conver

2019-02-23 14:57发布

问题:

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.

回答1:

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.



回答2:

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 ?>".

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.



回答3:

To get the user's input, use:

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

And to show:

"output": {"text": "You entered this $yourVariable"}