ibm-watsonwatson-conversationwatson-discovery

How do I format Watson Discovery results to look like a Watson Assistant response?


We are developing a chat bot using Watson Assistant and when it produces a response from Discovery, it displays it in a box that isn't a chat bubble, as seen in the attached image. It seems like there is a formatDiscovery function in App.js that might have to do with it, I'm just not sure what has to be edited and what to do in order to achieve this. Is there a way to format it so that the first result is displayed in a chat bubble and not the separated window? Thanks!!

formatDiscovery(resultArr) {
    resultArr.map(function(result, index) {
        const formattedResult = <DiscoveryResult key={'d' + this.state.discoveryNumber + index} title={result.title} preview={result.bodySnippet} link={result.sourceUrl} linkText={'See full manual entry'} />;
        this.addMessage({ message: formattedResult });
}.bind(this));

Chat bot output


Solution

  • Change the last line in the function from:

    this.addMessage(result.bodySnippet);
    

    to this

    this.addMessage({ label: 'Discovery Result:', message: String(result.bodySnippet), date: (new Date()).toLocaleTimeString()});
    

    This works for me when I test on a Discovery tutorial, let me know if it works for you!