DEPRECATED: this repo is no longer actively maintained. It can still be used as reference, but may contain outdated or unpatched code.
This project gives you the current weather forecast for your city (U.S. only as of now). The Weather Bot uses Watson Assistant (formerly Conversation), Natural Language Understanding, and The Weather Company Data API. It is run with OpenWhisk.
To see a list of IBM Services, visit here: https://console.bluemix.net/catalog/
To deploy this application to IBM Cloud, click the Deploy to IBM Cloud button below.
Note: Please ensure that your IBM Cloud organization has enough space for one web application using 256MB of memory and for 4 services (CloudantDB, Watson Assistant (Conversation), NLU, and Weather Insights) and that you have enough space for another Watson Assistant workspace (up to 6 total).
- The Architecture
- Getting Started
- OpenWhisk Setup
- Run the React App
- Cloud Foundry Deployment
- Future Updates
- If you do not already have an existing IBM Cloud account, sign up here.
- Clone this repository and go to the cloned directory.
git clone https://github.com/watson-developer-cloud/text-bot-openwhisk.git cd text-bot-openwhisk
- Download and install the Cloud-Foundry CLI.
- Alternatively, you can create the necessary services by going to your IBM Cloud dashboard.
- Once the CLI has been set up and the repo has been cloned, open a terminal window and connect to IBM Cloud by doing the following:
cf api https://api.ng.bluemix.net cf login
- Open the manifest.yml file located in the root directory of your cloned repository. Replace the content in the
name:
field with a unique name for your application. The name you specify in this field will become your application's URL, .mybluemix.net.--- declared-services: watson-assistant-service: label: conversation plan: free cloudantNoSQLDB-service: label: cloudantNoSQLDB plan: Lite applications: - path: . memory: 256M instances: 1 name: text-bot-openwhisk # REPLACE ME buildpack: https://github.com/cloudfoundry/staticfile-buildpack.git disk_quota: 1024M services: - cloudant-text-bot - weather-text-bot - nlu-text-bot - watson-assistant-text-bot
-
Create an instance of the Watson Assistant (formerly Conversation) service and set your credentials by issuing the following commands (our CLI is being updated, for now, use the
create-service conversation
command):cf create-service conversation free watson-assistant-text-bot cf create-service-key watson-assistant-text-bot theKey cf service-key watson-assistant-text-bot theKey
-
Create an instance of the Natural Langauge Understanding service and set your credentials by running the following:
cf create-service Natural-Language-Understanding free nlu-text-bot cf create-service-key nlu-text-bot theKey cf service-key nlu-text-bot theKey
-
Create an instance of the Weather Insights service and set your credentials by running the following:
cf create-service weatherinsights Free-v2 weather-text-bot cf create-service-key weather-text-bot theKey cf service-key weather-text-bot theKey
-
Create an instance of the Cloudant NoSQL Database and set your credentials by running the following commands:
cf create-service cloudantNoSQLDB Lite cloudant-text-bot cf create-service-key cloudant-text-bot theKey cf service-key cloudant-text-bot theKey
-
Before moving on, you must train your Watson Assistant service in order to use this application. The training data is provided in the
.bluemix/workspace.json
file. To train the Watson Assistant model, follow the steps below:- Go to your IBM Cloud services dashboard.
- Select the Watson Assistant service you created for this application.
- Click on the button. This will take you to the Watson Assistant training tool, which you will create a workspace for in the next step.
- Once the page has loaded, you are going to Import a workspace by clicking the button, which is next to the Create button.
- Click on Choose a file and navigate to the
.bluemix
folder in your cloned repository. Select theworkspace.json
file and make sure the box that says Everything (Intents, Entities, and Dialog) is selected. - Next, click Import to upload the training data and create your Watson Assistant workspace.
- After this has completed, you will be able to access your Watson Assistant Workspace ID by clicking the button with the three vertical dots (located in the upper right corner of the Workspace pane), and then selecting View Details. You will need the Workspace ID when you create the OpenWhisk actions for Watson Assistant (formerly Conversation).
-
Download and install the OpenWhisk CLI, then follow the steps on that page to set up your OpenWhisk Namespace and Authorization Key.
-
You will be creating 5 actions (not including actions for the Cloudant DB) for the weather chat bot as follows:
wsk action create conversation1 actions/watson-assistant.js --web true wsk action create conversation2 actions/watson-assistant-weather.js --web true wsk action create nlu actions/nlu.js --web true wsk action create getGeoLoc actions/getGeoLoc.js --web true wsk action create getWeather actions/getWeather.js --web true
-
Change to the config directory and replace the default parameters with your Watson service credentials. Your credentials can be found by heading to your IBM Cloud dashboard, clicking on the service name, and then the Service Credentials tab on the left-hand side of the page.
cd config
Watson Assistant Credentials
{ "WATSON_ASSISTANT_USERNAME": "<YOUR WATSON ASSISTANT SERVICE USERNAME>", "WATSON_ASSISTANT_PASSWORD": "<YOUR WATSON ASSISTANT SERVICE PASSWORD>", "WATSON_ASSISTANT_URL": "https://gateway.watsonplatform.net/conversation/api", "WORKSPACE_ID": "<YOUR WATSON ASSISTANT SERVICE WORKSPACE_ID>" }
Your workspace ID can be found by going to your IBM Cloud dashboard, clicking on your Watson Assistant service, then clicking on the Launch Tool button.
NLU Credentials
{ "NLU_USERNAME": "<YOUR NLU SERVICE USERNAME>", "NLU_PASSWORD": "<YOUR NLU SERVICE PASSWORD>", "NLU_URL": "https://gateway.watsonplatform.net/natural-language-understanding/api", }
Weather Company Data Credentials
{ "WEATHER_URL": "<YOUR WEATHER SERVICE URL>", "WEATHER_USERNAME": "<YOUR WEATHER SERVICE USERNAME>", "WEATHER_PASSWORD": "<YOUR WEATHER NSERVICE PASSWORD>" }
-
Export your service credentials by performing the following:
wsk action update conversation1 --param-file config/watson-assistant-config.json wsk action update conversation2 --param-file config/watson-assistant-config.json wsk action update nlu --param-file config/nlu-config.json wsk action update getGeoLoc --param-file config/weather-config.json wsk action update getWeather --param-file config/weather-config.json
-
Finally, create an OpenWhisk sequence to connect the actions:
wsk action create <sequence name> --sequence nlu,getGeoLoc,conversation1,getWeather,conversation2
-
Copy and paste the following command in a terminal window and replace with the name of your OpenWhisk sequence. If you get a JSON response with no status error messages, then your sequence has been successfully created.
wsk action invoke --blocking <sequence name> --param conversation '{ "input": { "text": "Hello", "language": "en" }, "context": {} }'
If you do not intend to have database support for your application, then you can skip to the Create an API section.
OpenWhisk actions to use the Cloudant Database have been included, and allow your application to insert, read, and write Watson Assistant contexts to the database. Once set up, the actions will be ready to use but require some additions to the UI to handle database IDs and Revision numbers (for updating documents). Follow the instructions below to create the Cloudant OpenWhisk actions.
-
Open a terminal window and create the 3 Cloudant actions below:
wsk action create cloudant-add actions/cloudant-add.js --web true wsk action create cloudant-read actions/cloudant-read.js --web true wsk action create cloudant-write actions/cloudant-write.js --web true
-
Navigate to the config folder and replace the placeholder text with your Cloudant credentials.
cd config
{ "CLOUDANT_USERNAME": "<YOUR CLOUDANT USERNAME>", "CLOUDANT_PASSWORD": "<YOUR CLOUDANT PASSWORD>", "CLOUDANT_URL": "<YOUR CLOUDANT URL>" }
Your credentials can be found by heading to your IBM Cloud dashboard, clicking on the Cloudant service name you created, and then the Service Credentials tab. Then, click on the "View credentials" dropdown associated with the API key you will use. You will need the username, password, and URL of your Cloudant DB.
-
Next, export your service credentials by doing the following commands:
wsk action update cloudant-add --param-file config/cloudant-config.json wsk action update cloudant-read --param-file config/cloudant-config.json wsk action update cloudant-write --param-file config/cloudant-config.json
-
Finally, create an OpenWhisk sequence to connect all the actions:
wsk action create <sequence name> --sequence cloudant-add,cloudant-read,nlu,getGeoLoc,conversation1,getWeather,conversation2,cloudant-write
-
You can test your sequence by copying and pasting the following command in a new terminal window.
wsk action invoke --blocking <sequence name> --param conversation '{ "input": { "text": "Hello", "language": "en" }, "context": {} }' --param _id test --param _rev null
If you get a JSON response with no status error messages, then your sequence has been successfully created.
-
To ensure that your document is saved in your Cloudant DB instance, go to your IBM Cloud dashboard, click on your Cloudant DB service instance, then click on the Launch button. Once you are viewing your list of Databases, click on the name of your weather bot database. If you see an entry with the same ID number used in the
wsk
command, then your sequence has sucessfully written to the database. If you would like to view the context that has been saved, then check the Include Docs box at the top of the page.
- Cloudant integration requires the DB document's
_id
and_rev
to be passed in the UI. - The document ID numbers should be UUIDs. Install the Node UUID Package and follow the instructions on how to generate the IDs.
-
Go to the OpenWhisk API Management Console and then click on .
-
Create a POST operation for your API and specify the OpenWhisk sequence created earlier as the Action that will be used:
-
In the Security and Rate Limiting section, enable the following:
-
Then, click Save and expose.
-
Now, create API keys for sharing within IBM Cloud and outside of IBM Cloud by clicking .
-
To test your API, navigate to the API Explorer tab. Copy and paste the following command in a terminal window. Replace the
--url
flag with the route and path for your POST request, and replace thedefault
API key with yours. To generate anid
, click on Try it, which is to the right of Examples, and then click Generate under the Parameters section to generate an ID.curl --request POST --url <YOUR POST PATH> --header 'accept: application/json' --header 'content-type: application/json' --header 'x-ibm-client-key: <YOUR API KEY>' --data '{"id":<GENERATED ID>, "conversation": { "input": { "text": "Hello", "language": "en"}, "context": {}}}'
- Ensure that you have Node.js installed on your machine. You can also use Homebrew to install Node.
- Make sure you are in the root directory in your cloned repository.
- Install the node-modules needed to run the app by typing the following in a terminal window. NPM stands for Node Package Manager and is installed when you install Node.
npm install
- Next, install the Create React App package.
npm install create-react-app
- You should now be able to run the app locally on localhost:3000 by typing the following:
npm start
- Follow the instructions for Run the React App before moving on to this section.
- Make sure you are in the root directory in your cloned repository.
- Then build the app for production.
npm run build
- You can change the following fields in the
manifest.yml
if you like.name: <Your App Name>
- Push the app to Cloud Foundry by doing the following command:
cf push
Cloudant DB integration and the creation of actions to get and store information within the databaseAbility to query a certain day within the 7-day forecast for your cityBuild a UI- Output a list of states for the user to choose from should a city name occur in more than one state
- Improve city detection accuracy