Skip to content

Commit

Permalink
fix: update README and dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
germanattanasio committed Apr 12, 2019
1 parent 96e33c4 commit 936bfbf
Show file tree
Hide file tree
Showing 11 changed files with 8,991 additions and 10,046 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Environment variables
ASSISTANT_URL=https://gateway.watsonplatform.net/assistant/api
ASSISTANT_IAM_APIKEY=
ASSISTANT_ID=
19 changes: 8 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
language: node_js
dist: trusty
sudo: required
node_js: "8"
script:
- npm run build
- npm test
dist: xenial
node_js: "10"
cache:
directories:
- node_modules
Expand All @@ -15,18 +11,19 @@ env:
- BX_ORGANIZATION=WatsonPlatformServices
- BX_SPACE=demos
- B_DOMAIN=ng.bluemix.net
script:
- npm run build
- npm test

before_deploy:
- npm install -g bx-blue-green
deploy:
- provider: script
script: bx-blue-green-travis
on:
branch: master
repo: Watson/watson-conversation-demo-redesign
repo: watson-developer-cloud/assistant-demo
skip_cleanup: true
- provider: script
script: BX_APP=watson-conversation-duo-test bx-blue-green-travis
on:
branch: dev
repo: Watson/watson-conversation-demo-redesign
skip_cleanup: true
script: npx semantic-release
17 changes: 0 additions & 17 deletions ISSUE_TEMPLATE.md

This file was deleted.

125 changes: 124 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,124 @@
<h1 align="center" style="border-bottom: none;">🚀 Watson Assistant Demo Sample Application</h1>
<h1 align="center" style="border-bottom: none;">🚀 Watson Assistant Duo Demo</h1>

[![Build Status](https://travis-ci.org/watson-developer-cloud/assistant-demo.svg?branch=master)](https://travis-ci.org/watson-developer-cloud/assistant-demo)

In this sample application, you're engaging with a banking virtual assistant. The assistant simulates a few scenarios, such as making a credit card payment, booking an appointment with a banker and choosing a credit card. Watson can understand your entries and respond accordingly.


[![Demo](./demo.gif)](https://watson-assistant-demo.ng.bluemix.net)



## Prerequisites

1. Sign up for an [IBM Cloud account](https://cloud.ibm.com/registration).
1. Download the [IBM Cloud CLI](https://cloud.ibm.com/docs/cli/index.html#overview).
1. Create an instance of the Watson Assistant service and get your credentials:
- Go to the [Watson Assistant][service_url] page in the IBM Cloud Catalog.
- Log in to your IBM Cloud account.
- Click **Create**.
- Click **Show** to view the service credentials.
- Copy the `apikey` value.
- Copy the `url` value.

## Configuring the application

1. In the application folder, copy the *.env.example* file and create a file called *.env*

```
cp .env.example .env
```
2. Open the *.env* file and add the service credentials that you obtained in the previous step.
Example *.env* file that configures the `apikey` and `url` for a Watson Assistant service instance hosted in the US East region:
```
ASSISTANT_IAM_APIKEY=X4rbi8vwZmKpXfowaS3GAsA7vdy17Qh7km5D6EzKLHL2
ASSISTANT_URL=https://gateway-wdc.watsonplatform.net/assistant/api
```
## Running locally
1. Install the dependencies
```
npm install
```
1. Run the application
```
npm start
```
1. View the application in a browser at `localhost:3000`
## Deploying to IBM Cloud as a Cloud Foundry Application
1. Login to IBM Cloud with the [IBM Cloud CLI](https://cloud.ibm.com/docs/cli/index.html#overview)
```
ibmcloud login
```
1. Target a Cloud Foundry organization and space.
```
ibmcloud target --cf
```
1. Edit the *manifest.yml* file. Change the **name** field to something unique.
For example, `- name: my-app-name`.
1. Deploy the application
```
ibmcloud app push
```
1. View the application online at the app URL.
For example: https://my-app-name.mybluemix.net
## Codebase Structure
```s
Root
/src
index.js (React frontend index)
/components
/ExampleComponentDirectory
ExampleComponent.js
ExampleComponent.test.js
/public
index.html (served at the root route)
/styles
duo-grid.min.css (Duo grid styles)
/js
bundle.js (imports the root react component)
/config
Configuration files for Express backend
/test
Backend unit and integration tests
index.js (express backend)
server.js (main backend entry point)
.config files
package.json
```

## License

This sample code is licensed under Apache 2.0.
Full license text is available in [LICENSE](LICENSE).

## Contributing

See [CONTRIBUTING](CONTRIBUTING.md).

## Open Source @ IBM

Find more open source projects on the
[IBM Github Page](http://ibm.github.io/).

[service_url]: https://www.ibm.com/cloud/watson-assistant/
[docs]: https://cloud.ibm.com/docs/services/assistant/index.html#about
6 changes: 0 additions & 6 deletions config/webpack.config.common.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const StyleLintPlugin = require('stylelint-webpack-plugin');

const distDir = path.resolve(__dirname, '..', 'dist');
Expand Down Expand Up @@ -60,11 +59,6 @@ module.exports = {
],
},
plugins: [
new CleanWebpackPlugin([distDir], {
root: path.resolve(__dirname, '..'),
verbose: true,
dry: false,
}),
new HtmlWebpackPlugin({
title: 'Production',
template: 'public/index.html',
Expand Down
Binary file added demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 7 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ const bank = require('./lib/bankFunctions');

// declare Watson Assistant service
const assistant = new AssistantV2({
version: '2018-11-08',
username: process.env.ASSISTANT_USERNAME || '<username>',
password: process.env.ASSISTANT_PASSWORD || '<password>',
version: '2019-01-01',
});

const date = new Date();
Expand Down Expand Up @@ -57,9 +55,9 @@ app.get('/', (req, res) => {
});

app.post('/api/message', (req, res) => {
// check for workspace id and handle null workspace env variable
const assistantId = process.env.ASSISTANT_ID || '<workspace-id>';
if (!assistantId || assistantId === '<workspace-id>') {
// check for assistant id and handle null assistant env variable
const assistantId = process.env.ASSISTANT_ID || '<assistant-id>';
if (!assistantId || assistantId === '<assistant-id>') {
return res.json({
output: {
text: 'The app has not been configured with a ASSISTANT_ID environment variable.',
Expand Down Expand Up @@ -96,9 +94,10 @@ app.post('/api/message', (req, res) => {
// send payload to Conversation and return result
assistant.message(payload, (err, data) => {
if (err) {
console.log(err);
// TODO: return error from service, currently service returns non-legal
// status code
return res.status(500).jsonp(err);
return res.status(err.code || 500).json(err);
}

return res.json(data);
Expand Down Expand Up @@ -135,7 +134,7 @@ app.get('/api/session', (req, res) => {
assistant_id: process.env.ASSISTANT_ID || '{assistant_id}',
}, (error, response) => {
if (error) {
return res.send(error);
return res.status(error.code || 500).send(error);
}
return res.send(response);
});
Expand Down
2 changes: 1 addition & 1 deletion manifest.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
applications:
- name: watson-assistant-duo
- path: .
command: npm start
buildpack: sdk-for-nodejs
env:
NODE_ENV: production
Loading

0 comments on commit 936bfbf

Please sign in to comment.