Coder Social home page Coder Social logo

jmscraig / personal-wealth-portfolio-mgt-bot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ibm/personal-wealth-portfolio-mgt-bot

0.0 2.0 0.0 3.23 MB

Code for a Cognitive IBM Pattern that uses the Financial APIs (Investment Portfolio & Simulated Instrumented Analytics) on IBM Cloud. This application demonstrates using multiple interfaces (Twilio & WebUI) with Watson Assistant interacting with a Cloudant NoSQL database.

Home Page: https://developer.ibm.com/code/patterns/create-an-investment-management-chatbot

License: Apache License 2.0

JavaScript 41.07% CSS 50.60% HTML 8.32%

personal-wealth-portfolio-mgt-bot's Introduction

Architecture

Personal Wealth Portfolio Management Bot

Read this in other languages: 한국어, **, Português .

In this developer pattern we will create a financial-based Watson Conversation based chatbot that allows a user to: 1) use an Investment Portfolio service to query his or her investment portfolios and associated holdings 2) use the Simulated Instrument Analytics service to compute analytics on securities under a given scenario. 3) understand how to swap between alternative interfaces: a) web interface b) TwilioSMS

When the reader has completed this pattern, he or she will understand how to:

  • Create a chatbot dialog with Watson Conversation
  • Set up multiple interfaces with the Watson Conversation bot: Web & Twilio
  • Access, seed and send data to the Investment Portfolio Service
  • Send data along with a scenario to the Simulated Instrument Analytics service to retrieve analytics

Click here to view the IBM Pattern for this project.

Prerequisites

You will need the following accounts and tools:

Included Components

  • IBM Cloud Watson Conversation
  • IBM Cloud Cloudant NoSQL DB
  • IBM Cloud Investment Portfolio
  • IBM Cloud Simulated Instrument Analytics
  • TwilioSMS

Steps

Use the Deploy to IBM Cloud button OR create the services and run Run Locally.

Use the IBM Cloud for Financial Services to build the future of financial services with to help from Watson and developer starter kits. Visit https://developer.ibm.com/finance/

Deploy to IBM Cloud

Deploy to IBM Cloud

  1. Log in to your IBM Cloud account before deploying. If already logged in, then ignore this step. Deploy - step 1

  2. We can see that the app is ready to be deployed, and we need to ensure that the App name, region, Organization, Space is valid before pressing 'Deploy'. Deploy - step 2

  3. In Toolchain, the app is deployed. There are also option to edit code via eclipseIDE, git changes if required. Deploy - step 3

  4. You should see two stages pass successfully once your Deploy Stage completes Deploy - step 4

  5. To see the app and services created and configured for this pattern, use the IBM Cloud dashboard. The app is named personal-wealth-portfolio-mgt-bot with a unique suffix:

Note There are a few more steps you need to complete before you can run the application.

Before you start the configuration process, clone the personal-wealth-portfoli-mgt-bot code locally. In a terminal window, run:

$ git clone https://github.com/IBM/personal-wealth-portfolio-mgt-bot.git

A. Configure Watson Conversation

The Conversation service must be trained before you can successfully use this application. The training data is provided in the file: resources/workspace.json

  1. Make sure you are logged into IBM Cloud

  2. Navigate to upper left hand side and click on the 3 parallel lines and select Dashboard from the left hand navigation panel.

  3. Scroll down and under "All Services" - select the instance of the Conversation service that you are using

  4. Once on the Service details page, scroll down (if necessary) and click green Launch tool button on the right hand side of the page. This will launch the tooling for the Conversation service, which allows you to build dialog flows and train your chatbot. This should take you to your workspace in the Conversation service which represents a unique set of chat flows and training examples. This allows you to have multiple chatbots within a single instance of the Conversation service.

  5. Once on the page, you will see the option to either “Create” a new workspace, or “import” an existing one. We are going to “import” a premade chatbot for this example, so select “Import" (click on the arrow next to the create button).

  1. Click Choose a file, navigate to the resources directory of your clone of the repository for this project, and select the file workspace.json. Once the file is selected, ensure that the “Everything (Intents, Entities, and Dialog” option is selected.

  2. Click Import to upload the .json file to create a workspace and train the model used by the Conversation service.

Note: Record your Workspace ID to use in Step C.

To find your workspace ID once training has completed, click the three vertical dots in the upper right-hand corner of the Workspace pane, and select View details. Once the upload is complete, you will see a new workspace. In order to connect this workspace to our application, we will need to include the Workspace ID in our environment variables on your application dashboard (if you used the Deploy to IBM Cloud button or save in the file “.env” if you are deploying locally. Save this id.

Optionally, you may want to explore the conversation dialog. select the workspace and choose the Dialog tab, here's a snippet of the dialog:

B. Seed the Investment Portfolio Service

You now need to manually seed your Investment Portfolio. For all these steps - replace userid, password with the credentials from your IBM Cloud Service.

i. Example of manually creating a portfolio entry in your Portfolio Investment Service:

NOTE

  • {service-user-id} is the user id associated with your Portfolio Investment Service
  • {service-user_password} is the password associated with your Portfolio Investment Service

curl -X POST -u "{service-user-id}":"{service-user_password}" --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ "name":"P1", "timestamp": "2017-02-24T19:53:56.830Z", "closed": false, "data": { "manager": "Edward Lam" }}' 'https://investment-portfolio.mybluemix.net/api/v1/portfolios'

ii. Example of manually creating holdings in your entry:

curl -X POST -u "{service-user-id}":"{service-user_password}" --header 'Content-Type: application/json' --header 'Accept:application/json' -d '{ "timestamp": "2017-05-05T19:53:56.830Z", "holdings": [ { "asset": "IBM", "quantity": 1500, "instrumentId": "CX_US4592001014_NYQ"}, { "asset": "GE", "quantity": 5000, "instrumentId": "CX_US3696041033_NYQ" }, { "asset": "F", "quantity": 5000, "instrumentId": "CX_US3453708600_NYQ" }, { "asset": "BAC", "quantity": 1800, "instrumentId": "CX_US0605051046_NYS" } ] }' 'https://investment-portfolio.mybluemix.net/api/v1/portfolios/P1/holdings'

C. Configuring your Environment Variables in IBM Cloud

Before you can actually run the application, you need to manually update three environment variables in IBM Cloud:

Go to the runttime tab of your application. Scroll to the bottom of the screen and Add the following environment variables:

Note: Replace the Value for Workspace ID with the one you noted in Step A.

Name Value
WORKSPACE_ID 5b4d1d87-a712-4b24-be39-e7090421b014
USE_WEBUI true
CRED_SIMULATED_INSTRUMENT_ANALYTICS_SCENARIO_FILENAME ./resources/spdown5_scenario.csv

Click Save to redeploy your application.

D. Running application from IBM Cloud

Now you are ready to run your application from IBM Cloud. Select the URL

NOTE: If you get a not Authorized message - you need to confirm that the credentials you used match the credentials in IBM Cloud.

Running Application Locally

NOTE: These steps are only needed when running locally instead of using the Deploy to IBM Cloud button

  1. Clone the repo
  2. Create IBM Cloud services
  3. Configure Watson Conversation
  4. Seed Investment Portfolio
  5. Configure Manifest file
  6. Configure .env file
  7. Update controller.js file
  8. Run the application

1. Clone the repo

Clone the personal-wealth-portfoli-mgt-bot code locally. In a terminal, run:

$ git clone https://github.com/IBM/personal-wealth-portfolio-mgt-bot.git

2. Create IBM Cloud services

Create the following services:

Note

  • Because this pattern uses 4 IBM Cloud services, you may hit your limit for the number of services you have instantiated. You can get around this by removing services you don't need anymore. Additionally - if you hit the limit on the number of Apps you have created, you may need to also remove any that you don't need anymore.
  • Record the userid, password from the credentials tab on the Conversation Service.

3. Configure Watson Conversation

NOTE: Execute section A of the Deploy to IBM Cloud section

4. Seed Investment Portfolio

NOTE: Execute section B of the Deploy to IBM Cloud section

5. Configure Manifest

Edit the manifest.yml file in the folder that contains your code and replace portoflio-chat-newbot with a unique name for your application. The name that you specify determines the application's URL, such as your-application-name.mybluemix.net. Additional - update the service lables and service names so they match what you have in IBM Cloud. The relevant portion of the manifest.yml file looks like the following:

```yml
declared-services:
conversation:
   label: Conversation
   plan: free
Cloudant-service:
   label: cloudantNoSQLDB
   plan: Lite
investment-portfolio-service:
   label: fss-portfolio-service
instrument-analytics:
   label: fss-scenario-analytics-service
applications:
    - services:
    - Conversation
    - Cloudant-service
    - investment-portfolio-service
    - instrument-analytics-service
name: portfolio-chat-newbot
command: npm start
path: .
memory: 512M
instances: 1
domain: mybluemix.net
disk_quota: 1024M
```

6. Configure .env file

  1. Create a .env file in the root directory of your clone of the project repository by copying the sample .env.example file using the following command:

NOTE Most files systems regard files with a "." at the front as hidden files. If you are on a Windows system, you should be able to use either GitBash or Xcopy

cp .env.example .env

You will need to update the credentials with the IBM Cloud credentials for each of the services you created in Step 2.

The `.env` file will look something like the following:

```none

USE_WEBUI=true

#CONVERSATION
CONVERSATION_URL=https://gateway.watsonplatform.net/conversation/api
CONVERSATION_USERNAME=
CONVERSATION_PASSWORD=
WORKSPACE_ID=

#CLOUDANT
CLOUDANT_URL=

#INVESTMENT PORTFOLIO
CRED_PORTFOLIO_USERID=
CRED_PORTFOLIO_PWD=
URL_GET_PORTFOLIO_HOLDINGS=https://investment-portfolio.mybluemix.net/api/v1/portfolios

CRED_SIMULATED_INSTRUMENT_ANALYTICS_URL=https://fss-analytics.mybluemix.net/api/v1/scenario/instrument
CRED_SIMULATED_INSTRUMENT_ANALYTICS_ACCESSTOKEN=
CRED_SIMULATED_INSTRUMENT_ANALYTICS_SCENARIO_FILENAME=

#TWILIO
USE_TWILIO=false
USE_TWILIO_SMS=false
TWILIO_ACCOUNT_SID=
TWILIO_AUTH_TOKEN=
TWILIO_API_KEY=
TWILIO_API_SECRET=
TWILIO_IPM_SERVICE_SID=
TWILIO_NUMBER=
```

7. Update file

One additional step is that you need to comment out two lines in the Controller file to set the userid & password of the investment portfolio service (lines 66-70)

8. Run Application

a. Install the dependencies you application need:

npm install

b. Start the application locally:

npm start

c. Test your application by going to: http://localhost:3000/

Start a conversation with your bot:

Configure Twilio (Optional if you want your app to interface with Twilio)

You still have one more step if you are planning to use Twilio as the interface. We have to update a couple more environment variables. Again - this is an optional step. By default the app interfaces with a WebUI; but this enables an interface with Twilio.

NOTE: Using Twilio is an option, the application works with the Web UI by default. So only do the Twilio configuration if you are using Twilio.

  1. If you have not done so yet, get a phone number from the Twilio service. https://www.twilio.com/
  2. Edit your .env file to add credentials for Twilio. You can get this information from the dashboard when you get a phone number for Twilio

  • Set the USE_TWILIO_SMS variable to true.
  • Set the TWILIO_ACCOUNT_SID variable
  • Set the TWILIO_AUTH_TOKEN variable
  • Set the TWILIO_NUMBER variable

If you clicked the "Deploy to IBM Cloud" button, save the new values and restart the application in IBM Cloud, watch the logs for errors.

In order to have Twilio listen to the local port (:3000), you need to set up a tunnel a webhook. You can use the tool ngrok https://ngrok.com/. Go ahead and download ngrok. Open a terminal window and start ngrok by using the command:

ngrok http 3000

Note: use port 80 if you are running the application from IBM Cloud.

You will get a response like the following:

Copy the https uri and paste it into the entry field for your SMS Webhook (inside the Twilio dashboard):

Adapting/Extending the pattern

One can enhance the current application by adding in additional financial services. Xignite, Inc. (http://xignite.com) provides cloud-based financial market data APIs that work side by side with the IBM Cloud Fintech services. Specifically, the GetGlobalDelayedQuotes() Rest API is available to provide delayed quotes for a specific global security.

Troubleshooting

* To troubleshoot your IBM Cloud application, use the logs. To see the logs, run:

```bash
cf logs <application-name> --recent
```

* If you are running locally - inspect your environment varibles closely to confirm they match.

The credentials for IBM Cloud services (Conversation, Cloudant, and Discovery), can
be found in the ``Services`` menu in IBM Cloud, and selecting the ``Service Credentials``
option.


* Alternatively, you can debug the application by going to `https://<name of your application>.mybluemix.net/debug.html` to see a panel that shows metadata which contains details on the interaction with the services being used.

License

Apache 2.0

personal-wealth-portfolio-mgt-bot's People

Contributors

ljbennett62 avatar wwalisa avatar stevemart avatar hovig avatar dolph avatar tomcli avatar hisunah avatar lnrego avatar animeshsingh avatar kant avatar

Watchers

James Cloos avatar James Craig avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.