Search code examples
ibm-watsonwatson-dialogwatson-conversation

Create dialog using json file


I have been working on watson dialog for few days now, and I am able to create a dialog using .xml file after following few tutorials.

<?xml version="1.0" encoding="UTF-8"?>
<dialog xsi:noNamespaceSchemaLocation="WatsonDialogDocument_1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <flow>
        <folder label="Main">
            <output>
                <prompt selectionType="RANDOM">
                    <item>Hi, I'll show you the latest buzz around a topic of your choice. What topic are you interested in?</item>
                </prompt>
                <goto ref="getUserInput_2442994"/>
            </output>
            <output>
                <prompt selectionType="RANDOM">
                    <item>Bye</item>
                </prompt>
                <getUserInput id="getUserInput_2442994">
                    <search ref="folder_2442998"/>
                </getUserInput>
            </output>
        </folder>
        <folder label="Library">
            <folder label="Live Content" id="folder_2447777">
                <output>
                    <prompt selectionType="RANDOM">
                        <item>Alright. Open this URL to see the tweets: http://insights-search.mybluemix.net/api/1/messages/search?q={Topic}%20AND%20posted%3A2015-07-01%20AND%20sentiment%3A{Sentiment}</item>
                    </prompt>
                </output>
            </folder>
            <folder label="Live Content" id="folder_2442998">
                <input>
                    <grammar>
                        <item>*</item>
                    </grammar>
                    <action varName="Topic" operator="SET_TO_USER_INPUT"/>
                    <output>
                        <prompt selectionType="SEQUENTIAL">
                            <item>Are you interested in positive or negative tweets?</item>
                        </prompt>
                            <getUserInput>
                                <input>
                                    <grammar>
                                        <item>positive</item>
                                    </grammar>
                                    <action varName="Sentiment" operator="SET_TO">positive</action>
                                    <goto ref="folder_2447777"/>
                                </input>
                                <input>
                                    <grammar>
                                        <item>negative</item>
                                    </grammar>
                                    <action varName="Sentiment" operator="SET_TO">negative</action>
                                    <goto ref="folder_2447777"/>
                                </input>
                                <input>
                                    <grammar>
                                        <item>*</item>
                                    </grammar>
                                    <action varName="Sentiment" operator="SET_TO">nothing</action>
                                    <goto ref="folder_2442998"/>
                                </input>
                            </getUserInput>
                    </output>
                </input>
            </folder>
            <folder label="Storage"/>
        </folder>
        <folder label="Global"/>
        <folder label="Concepts">
            <concept>
                <grammar>
                    <item>positive</item>
                    <item>good</item>
                </grammar>
            </concept>
        </folder>
    </flow>
    <entities>
    </entities>
    <constants>
    </constants>
    <variables>
        <var_folder name="Home">
            <var name="Topic" type="TEXT"/>
            <var name="Sentiment" type="TEXT"/>
        </var_folder>
    </variables>
    <settings>
    </settings>
    <specialSettings>
    </specialSettings>
</dialog>

I am using nodeJs for my server and wish to switch to JSON instead of XML. As the API reference says,

The dialog template file. Valid extensions are .mct for encrypted dialog files, .json, and .xml.

I dont find any JSON structure anywhere in the documentation for the dialog file.

Has anyone tried this before and succeeded in using JSON instead of XML? How?


Solution

  • The Dialog service only accepts XML and MCT files. I think you found an error in the documentation.

    On the other hand, the service was deprecated on August 15, 2016. Existing instances of the service will continue to function until August 9, 2017. We are encouraging users to migrate to use the Conversation service.

    The conversation service has a web tool that lets you create dialogs, you won't have to write XML. It also allows you to export the project as JSON.