How to give personalised greeting in Watson Conversation?

不想你离开。 提交于 2019-12-31 00:44:12

问题


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"}


来源:https://stackoverflow.com/questions/39232950/how-to-give-personalised-greeting-in-watson-conversation

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