1
votes

I'm Wondering how to extract the username using IBM Watson Conversation within the standard chat:

For example:

bot: What is your name?
User respond: my name is Mike
bot: ok good morning Mike. -> i want this

How to store the name that user type in the chat? so the bot can answer the given name?

1
@RiyaMRoy this question is more general than the one mentioned by you allowing me to give a more generic answer how to process input.text in general, which seems useful to me. - Michal Bida
Sure @MichalBida - RiyaMRoy

1 Answers

12
votes

EDIT: There is a new feature in WCS that enabled to extract pattern-based entities - in other words, user is able to define entities based on regular expressions. More information in the DOC here:

https://console.bluemix.net/docs/services/conversation/entities.html#creating-entities [30.11.2017]


You can access the user input text by writing <? input.text ?> then two methods supported by WCS might be useful:

<?input.text.matches('regexp')?> return true if the input matches input regexp expression.

and

<?input.text.extract('regexp', 0)?> (second parameter is regexp group number). That extracts part of the input String as specified by regexp and group.

For example this expression on a dialog node context:

"lastword" : "<?input.text.extract('\\w+$', 0)?>" will extract the last word from the input text provided by user.

Note that this is not a perfect solution for your use case, so it might be a good idea to add a dialog flow that confirms whether the parsed string is really a user name...