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: Regardless of which method you choose, you must have a Bluemix account and run some steps using the Bluemix web interface.

Make sure that you have a Bluemix account, and that your account has 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

![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 and fully functional. Click View App or go to the application route URL to try it out.

Deploying locally

The application uses Node.js and npm.

1 Copy the credentials from your conversation-service service in Bluemix to a .env file in the root.

2 Use the Conversation tooling app to import a workspace and add the workspace ID environment variable to the .env file. For details about obtaining the workspace ID, see Step 5 in the workspace section.

3 Install Node.js.

4 Open the terminal, go to the project folder, and run this command: npm install

5 Start the application by running this command: npm start

6 Open http://localhost:3000 in a browser.

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%