Skip to content

Lyrokz/conversation-simple

Repository files navigation

Conversation Sample Application

Build Status codecov.io

This Node.js application demonstrates how the Conversation service uses intent capabilities in a simple chat interface.

See the application demo.

For more information about Conversation, see the detailed documentation.

How the application works

The application interface is designed and trained for chatting with a cognitive car. The chat interface is on the left, and the JSON that the JavaScript code receives from the server is on the right. Your questions and commands are interpreted using a small set of sample data trained with intents like these:

turn_on
weather
capabilities

These intents help the system to understand variations of questions and commands that you might submit.

Example commands that can be executed by the Conversation service are:

turn on windshield wipers
play music

If you type Wipers on or I want to turn on the windshield wipers, the system understands that in both cases your intent is the same and responds accordingly.

Deploying the application

There are two ways you can deploy the application:

  • Deploying on Bluemix. You can use the IBM Bluemix web interface to set up the Conversation service and deploy the application in the IBM cloud. No software prerequisites are required; both the Conversation service and the demo application run in the Bluemix environment. Use this method if you want to get your instance of the application up and running quickly. You can subsequently make changes to the application using the Bluemix web interface.

  • Deploying locally. You can use command-line tools to set up the Conversation service in the IBM cloud and then deploy the application in a local runtime environment. To use this method, you must have Node.js and Cloud Foundry installed locally. Use this method if you want to host the application on your system, or if you want to modify the application locally before deploying it to the Bluemix cloud.

Note: Even if you are deploying locally, some steps currently require using the Bluemix web interface.

Regardless of which method you choose, you must have a Bluemix account, and your account must have available space for at least 1 application and 1 service. To register for a Bluemix account, go to https://console.ng.bluemix.net/registration/. Your Bluemix console shows your available space:

Screen capture of console showing Services

## Deploying on Bluemix

This procedure deploys the application code in the IBM cloud using the Bluemix web interface.

![Overview diagram of deploying on Bluemix](readme_images/Deploy on Bluemix - simple app.png)

Deploy the application and create the service

  1. Click here to deploy the application directly from GitHub to Bluemix:

    Deploy to Bluemix

  2. When prompted, log in with an existing Bluemix account or sign up for a new account.

  3. Verify the values in the APP NAME, REGION, ORGANIZATION, and SPACE fields. You can accept the default values or modify them.

    Screen capture of app deployment page

  4. Click DEPLOY. This performs two actions:

  • Deploying the JavaScript application code from GitHub to Bluemix
  • Creating an instance of the Conversation service to be used by the application

The Bluemix interface shows you the progress of the deployment process, which can take several minutes.

Screen capture of deployment progress

Import the workspace

  1. Download the workspace JSON file to your computer. This file defines all of the artifacts used by the service, including intents, entities, and dialog flow.

  2. In your browser, navigate to your Bluemix console.

  3. From the All Items tab, click the newly created Conversation service in the Services list.

    Screen capture of Services list

    The Service Details page opens.

  4. Click Launch tool.

    Launch tool button

    The Conversation service tool opens.

  5. Click Import. When prompted, specify the location of the workspace JSON file you downloaded.

  6. Select Everything (Intents, Entities, and Dialog) and then click Import. The car dashboard workspace is created.

Configure the workspace ID

  1. Click the menu icon in the upper right corner of the workspace tile, and then select View details.

    Screen capture of workspace tile menu

    The tile shows the workspace details.

  2. Click the Copy icon to copy the workspace ID to the clipboard.

  3. Close the Conversation tool and return to your Bluemix console.

  4. From the All Items tab, click the demo application in the Cloud Foundry Applications list.

    Screen capture of Applications list

    The Application Details page opens.

  5. On the Runtime tab, click Environment Variables.

  6. In the User Defined section, click Add.

  7. In the Name field, type WORKSPACE_ID.

  8. In the Value field, paste the workspace ID from the clipboard.

  9. Click Save.

  10. Click the Restart icon at the top of the page to restart the application.

The application is now deployed in Bluemix and ready to use. Click View App or go to the application route URL to try it out.

Deploying locally

This procedure deploys the application code on your system and configures it to access Watson services in the IBM cloud.

Note: To deploy the application locally, you must have the following prerequisites installed:

Getting the files

  1. Download the application code to your computer. You can do this in either of the following ways:

    • Download the .zip file of the GitHub repository and extract the files to a local directory

    • Use GitHub to clone the repository locally

  2. At the command line, go to the local project directory (conversation-simple).

Setting up the service

  1. Use the cf login command to log in to your Bluemix account.

  2. Create an instance of the Conversation service in the IBM cloud:

    cf create-service Conversation <service_plan> <service_instance>

    For example:

    cf create-service Conversation free conversation-simple-demo-test1

  3. Create a service key:

    cf create-service-key <service_instance> <service_key>

    For example:

    cf create-service-key conversation-simple-demo-test1 conversation-simple-demo-test1-key1

Setting up the application

  1. Copy the .env.example file to a new .env file. Open this file in a text editor.

  2. Retrieve the credentials from the service key:

    cf service-key <service_instance> <service_key>

    For example:

    cf service-key conversation-simple-demo-test1 conversation-simple-demo-test1-key1

    The output from this command is a JSON object, as in this example:

    {
      "password": "87iT7aqpvU7l",
      "url": "https://gateway.watsonplatform.net/conversation/api",
      "username": "ca2905e6-7b5d-4408-9192-e4d54d83e604"
    }
  3. In the JSON output, find the values for the password and username keys. Paste these values (not including the quotation marks) into the CONVERSATION_PASSWORD and CONVERSATION_USERNAME variables in the .env file:

    CONVERSATION_USERNAME=ca2905e6-7b5d-4408-9192-e4d54d83e604
    CONVERSATION_PASSWORD=87iT7aqpvU7l
    

    Leave the .env file open in your text editor.

Import the workspace

  1. In your browser, navigate to your Bluemix console.

  2. From the All Items tab, click the newly created Conversation service in the Services list.

    Screen capture of Services list

    The Service Details page opens.

  3. Click Launch tool.

    Launch tool button

    The Conversation service tool opens.

  4. Click Import. When prompted, specify the location of the workspace JSON file in your local copy of the application project:

    <project_root>/training/car_workspace.json

  5. Select Everything (Intents, Entities, and Dialog) and then click Import. The car dashboard workspace is created.

Configure the workspace ID

  1. Click the menu icon in the upper right corner of the workspace tile, and then select View details.

    Screen capture of workspace tile menu

    The tile shows the workspace details.

  2. Click the Copy icon to copy the workspace ID to the clipboard.

  3. On the local system, paste the workspace ID into the WORKSPACE_ID variable in the .env file. Save and close the file.

  4. Install the demo application package into the local Node.js runtime environment:

    npm install

  5. Start the application:

    npm start

The application is now deployed on the local system and ready to use. Go to http://localhost:3000 in your browser to try it out.

Optional: deploying from the local system to Bluemix

Note: If you are interested in deploying you local application or the changes you have made locally to Bluemix, go to this section

### Service Credentials

1 Go to the Bluemix Dashboard and select the Conversation service instance. Once there, select the Service Credentials menu item.

            

2 Select ADD CREDENTIALS. Name your credentials then select ADD.

3 Copy the credentials (or remember this location) for later use.

### Import a workspace

To use the app you're creating, you need to add a worksapce to your Conversation service. A workspace is a container for all the artifacts that define the behavior of your service (ie: intents, entities and chat flows). For this sample app, a workspace is provided.

For more information on workspaces, see the full Conversation service documentation.

1 Navigate to the Bluemix dashboard, select the Conversation service that you created.

2 Go to the Manage menu item and select Launch Tool. This opens a new tab in your browser, where you are prompted to login if you have not done so before. Use your Bluemix credentials.

3 If you are deploying through Bluemix, download the exported JSON file that contains the Workspace contents. If deploying locally, this was cloned and is in the training folder (training/car_workspace.json).

4 Select the import icon: . Browse to (or drag and drop) the JSON file. Choose to import Everything(Intents, Entities, and Dialog). Then select Import to finish importing the workspace.

5 Refresh your browser. A new workspace tile is created within the tooling. Select the menu button within the workspace tile, then select View details:

            Workpsace Details

In the Details UI, copy the 36 character UNID **ID** field. This is the **Workspace ID**.

            

6 Return to the deploy steps that you were following:

### Adding environment variables in Bluemix

1 In Bluemix, open the application from the Dashboard. Select Environment Variables.

2 Select USER-DEFINED.

3 Select ADD.

4 Add a variable with the name WORKSPACE_ID. For the value, paste in the Workspace ID you copied earlier. Select SAVE.

            

5 Restart your application.

### Using Cloudfoundry CLI tool to deploy your application

To build the application:

1 Download and install the Cloudfoundry CLI tool.

2 Git clone the project https://github.com/watson-developer-cloud/conversation-simple

3 Navigate to the conversation-simple folder

4 Connect to Bluemix in the command-line tool:

For US Region

$ cf api https://api.ng.bluemix.net
$ cf login -u <your user ID>

5 Create the Conversation service in Bluemix:

$ cf create-service conversation free conversation-service

6 Push it live:

$ cf push <application-name>

The name you use determinates your application URL initially, such as <application-name>.mybluemix.net.

## Deploying locally 2 In Bluemix, [create a Conversation Service](http://www.ibm.com/watson/developercloud/doc/conversation/convo_getstart.shtml). - [Import a workspace](#workspace) - Copy the [Service Credentials](#credentials) for later use. - Return to these steps

Troubleshooting in Bluemix

In the Classic Experience:

  • Log in to Bluemix, you'll be taken to the dashboard.
  • Navigate to the the application you previously created.
  • Select Logs.

            

  • If you want, filter the LOG TYPE by "APP".

            

In the new Bluemix:

  • Log in to Bluemix, you'll be taken to the dashboard.
  • Select Compute

            

  • Select the application you previously created.
  • Select Logs.

            

  • If you want, filter the Log Type by selecting the drop-down and selecting Application(APP).

            

Troubleshooting with CLI

To see the logs, run the command

$ cf logs < application-name > --recent

License

This sample code is licensed under Apache 2.0. Full license text is available in LICENSE.

Contributing

See CONTRIBUTING.

Open Source @ IBM

Find more open source projects on the IBM Github Page.

About

A simple sample application demonstrating the conversation api.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 72.2%
  • CSS 23.3%
  • HTML 4.5%