How to give personalised greeting in Watson Conversation?

一笑奈何 提交于 2019-12-01 18:58:09

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.

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.

To get the user's input, use:

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

And to show:

"output": {"text": "You entered this $yourVariable"}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!