App built with node.js to query weather information (and perhaps in the future proactive provide weather alerts).
This app will listen for @weather <zipcode>
and give you some cool data (US zipcodes for now)
Assuming you just want to take this code and get it running before hacking it, the first step is to get it deployed to a live on a server so that IBM Watson Workspace validates it's up and working before pushing messages to the app. To facilitate things, you can click the button below and it'll get it going to Bluemix very easily.
Note: you can run this code locally, but then you would need to change the webhook code to get the URL of the callback. See Appendix for instructions.
Once the code is live, make note of the URL (e.g. http://mysuperawesomeurl.mybluemix.net) as you'll need this later.
Now let's register the app to get some API keys to get things going. We need an API key from weatherunderground.com to be able to call their services. To do that, head out to this URL and follow the steps to get the key. Once you get that key, store it in the environment variable WEATHER_KEY
.
Now, let's register the app with IBM Watson Workspace and get some keys!
- Go to the developer apps page
- On the left, enter the
App Name
and theDescription of App
- Click on
Add an outbound webhook
- Give the webhook a name (e.g. "listen for messages") and check the
message-created
webhook. This is how we'll listen to messages in a space - In the callback URL, specify the URL for your app. This code assumes that the webhook listener is at
https://yoururl/webhook
so don't forget to add/webhook
to the end of the URL (if you don't know where the app will be deployed, use a sample URL for now, likehttps://weather.acme.com/webhook
and you can modify that later) - Click on
Register app
- This will give you the App ID, App secret and webhook secret. You need to save these to environment variables called
WEATHER_CLIENT_ID
,WEATHER_SECRET
,WEATHER_WEBHOOK_SECRET
respectively
At this point the webhook is not enabled since the system has not been able to verify it's up and running. While the webhook is probably running on Bluemix, it doesn't have the variables set
Now that we have the API keys, let's configure it
- Go to
https://console.ng.bluemix.net/dashboard/applications/
and click on your app - Go to Runtime -> Environment Variables
- Define the 4 variables from above:
WEATHER_CLIENT_ID
,WEATHER_SECRET
,WEATHER_WEBHOOK_SECRET
andWEATHER_KEY
, provide the right values and save them. - Click the circular arrow to restart the app so the values take effect.
You are almost there!!!
- Assuming all environment variables are set (see above), go back to the apps page and click on the pencil icon to edit your app
- Check the box to enable your webhook
- Save your changes by clicking on "Edit app"
This now does an HTTP POST verification call to ensure your webhook is setup properly. This will also ensure that all your variables and code are good to go. If so, the webhook is now enabled and it's ready to be used! How easy was that!?!
We are almost there! Now we need to add the app to spaces that we want to listen for messages, and where the app will post messages to.
- Head out to
https://workspace.ibm.com
and go to your favorite space - Go into the space settings
- Click on
Apps
to go the apps menu - Click on your app to add it to the space
- Type in
@weather 90210
and the app should respond with the current weather conditions in Beverly Hills, CA
Have fun!!
- Run
npm install
to install dependencies - Run
npm run build
to compile the code - Set the environment variables as per above.
- Run
npm start
- The server will now run on localhost:3000.
You can use curl to submit a query and test it (or just deploy to Bluemix and test it there!) to simulate a call from Workspace to your webhook.
Licensed under Apache 2.0 (see LICENSE)
Depends on:
- body-parser
- express
- request
- node-weatherunderground
- request
- zipcode