IBM/tjbot-sports-buddy

Name: tjbot-sports-buddy

Owner: International Business Machines

Description: A Node application that can be run locally or on a Raspberry Pi powered TJBot. Use the SportsBuddy to chat about your favorite MLB team and receive news and standings using Twilio.

Created: 2017-05-12 17:38:20.0

Updated: 2018-05-14 19:27:12.0

Pushed: 2018-05-14 19:27:11.0

Homepage: https://developer.ibm.com/code/patterns/sports-buddy-tjbot-watson-discovery/

Size: 2410

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Build Status

Build a TJBot using Watson Services to talk about sports

Read this in other languages: ???.

Watson Conversation is now Watson Assistant. Although some images in this code pattern may show the service as Watson Conversation, the steps and processes will still work.

In this developer journey we will build a TJBot that knows baseball. Using Watson Discovery, TJBot will give you insight about your favorite teams, such as their current league standing, their upcoming shedule, and links to a few relevant articles from Watson News.

When the reader has completed this journey, they will understand how to:

With Watson

Want to take your Watson app to the next level? Looking to leverage Watson Brand assets? Join the With Watson program which provides exclusive brand, marketing, and tech resources to amplify and accelerate your Watson embedded commercial solution.

Included components
Featured technologies

Watch the Video

Steps

This app is designed to be run on a TJBot, but it can work on any standard workstation or laptop that supports audio controls - specifically a microphone input device and an output speaker. It may be simplier to first get this working on your laptop. If you would like to go directly to building this on a TJBot, jump to the section entitled Build a TJBot before completing the following steps.

  1. Clone the repo
  2. Create IBM Cloud services
  3. Configure Watson Assistant
  4. Enable Watson Discovery
  5. Enable Watson Speech to Text
  6. Enable Watson Text to Speech
  7. Enable Watson Tone Analyzer
  8. Register for Twilio Service
  9. Register for MLB Fantasy Data Service
  10. Run the application
1. Clone the repo

Clone the tjbot-sports-buddy locally. In a terminal, run:

$ git clone https://github.com/ibm/tjbot-sports-buddy

We?ll be using the file data/workspace.json

2. Create IBM Cloud services

Create the following services:

3. Configure Watson Assistant

Launch the Watson Assistant tool. Use the import icon button on the right

Find the local version of data/workspace.json and select Import. Find the Workspace ID by clicking on the context menu of the new workspace and select View details. Save this ID for later.

Optionally, to view the conversation dialog select the workspace and choose the Dialog tab, here's a snippet of the dialog:

4. Enable Watson Discovery

Launch the Watson Discovery tool. Select the Watson Discovery News Collection.

From the details panel, save the environment_id and collection_id values.

5. Enable Watson Speech to Text

Select the Watson Speech to Text service. Select the Service credentials menu item.

Click View Credentials and save the username and password values.

6. Enable Watson Text to Speech

Select the Watson Text to Speech service. Select the Service credentials menu item.

Click View Credentials and save the username and password values.

7. Enable Watson Tone Analyzer

Select the Watson Tone Analyzer service. Select the Service credentials menu item.

Click View Credentials and save the username and password values.

8. Register for Twilio Service

One of the main functions of the tjbot-sports-buddy is to text upcoming games and news headlines about the users favorite baseball teams. To send SMS text messages, we use the Twilio service. Register for a free trial account at https://www.twilio.com/try-twilio.

As part of the service, you will be assigned the following values, which you will need to save, they are accessible through your user account settings:

Lastly, you will need a Twilio supplied phone number, where all texts will originate from. To create one, navigate to the Programmable SMS option in the context menu.

By default, you will only be able to send SMS text messages to the phone number you provided to create your account. To send messages to other numbers, you need to add them at https://www.twilio.com/console. For each number you enter, the user of the number will be asked to verify and then be sent a verification code. You will then need to enter this verification code to complete the registration process.

9. Register for MLB Fantasy Data Service

Another feature of the tjbot-sports-buddy is being able to provide up to the minute Major League Baseball (MLB) stats. Specifically, schedules and standings. To retrieve this data, we use APIs supplied by FantasyData.

Register for a free trial accoount at https://developer.fantasydata.com.

Once registered, save the supplied subscription key, available through your profile.

10. Run the application

First, update the values in config.new.js and rename it to config.js:

 config.new.js config.js
edit config.js

Second, install dependencies, run the following from the cloned repo location:

m install --save

NOTE: you may need to install other dependencies, refer to the Troubleshooting section below.

Lastly, run the application:

de run.js

Sample output

Textual version of a sample conversation with TJBot:

You: “Hello Watson”

TJBot: “Hello. I'm Watson and I love baseball. Who's your favorite team?”

You: “The Yankees”

TJBot: “The New York Yankees are currently in first place. How do you think they will do this year?”

You: “Great!”

TJBot: “I agree, if they can stay healthy”

TJBot: “Would you like me to text you the New York Yankees upcoming schedule and some headling links from Watson News?”

You: “Sure”

TJBot: “What number should I use?”

You: “One two three four five six seven eight nine ten zero”

TJBot: “Your text has been sent. Are you interested in any other teams?”

You: “No thank you”

TJBot: “OK. Have a nice day”

Here is a recap of the services used to perform this conversation:

Build a TJBot

To build your TJBot, follow the tutorial entitled: Build a Chatbot That Cares - Part2.

It provides a comprehensive guide for:

Once your TJBot is running and functional, perform steps 1-10 above to setup and run the TJBot Sports Buddy app.

Troubleshooting

Help! My app is crashing

You may need to install a few audio related dependencies if you're seeing the following error:

ts.js:163
row er; // Unhandled 'error' event
On OSX

Use brew to install:

ew install sox mplayer ffmpeg

And use NPM to install:

m install node-ffprobe
On Ubuntu

Use apt-get to install:

do apt-get install ffmpeg

And use NPM to install:

m install node-ffprobe
TJBot says “Hi there, I am awake” and then exits.

We have seen this error on Ubuntu, and it is due to microphone issues.

The first step is to diagnose the problem. In run.js, go to the following object and modify debug to true:

t MIC_PARAMS = {
te: 44100,
annels: 2,
bug: true,
itOnSilence: 6

If you get the error:

ived Info: arecord: main:722: audio open error: No such file or directory

Try this:

ecord -l  // locate your microphone card and device number
 List of CAPTURE Hardware Devices ****
 0: Intel [HDA Intel], device 0: ALC262 Analog [ALC262 Analog]
bdevices: 1/1
bdevice #0: subdevice #0
 0: Intel [HDA Intel], device 2: ALC262 Alt Analog [ALC262 Alt Analog]
bdevices: 2/2
bdevice #0: subdevice #0
bdevice #1: subdevice #1
 2: C320M [Plantronics C320-M], device 0: USB Audio [USB Audio]
bdevices: 1/1
bdevice #0: subdevice #0

Then add the card and device (hw:card,device) number to your microphone params. For example to use the Plantronics card above:

t MIC_PARAMS = {
te: 44100,
annels: 2,
vice: 'hw:2,0',
bug: true,
itOnSilence: 6

If you get the error:

ived Info: arecord: main:722: audio open error: Device or resource busy

It means your device is being used by another process. Try the following:

  1. Exit any volume control applications that may be running, such as PulseAudio.
  2. Exit any open browsers.

If you still get the error, reboot.

NOTE: make sure you set debug:false after everything is working, otherwise too many log messages will be output to the console.

TJBot never speaks and you ONLY see “Retrieved schedule for date: NO GAMES FOUND” messages.

This is most likely due to the baseball season being over, or your config file specifies the wrong baseball season.

If the baseball season is over (runs from early April to late September), set the following flag in config.js:

rts.offSeason = true;

NOTE: the data returned by TJBot will come from an archived version of previous season data and and will not be accurate, but at least you will be able to interact with it.

If the baseball season isn't over, make sure the following variable is set correctly in config.js:

rts.MLBSeason = '2017';

License

Apache 2.0


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.