This is an app for Java which demonstrates the basic integration flows with Watson Work Services. You can see this app:
- Post a message to a space using its own credentials
- Use oauth to gain authorization to perform actions on behalf of another user
- React to Webhooks, in this case by posting a message saying what type of webhook it has seen
-
Visit the app creation page and login.
-
Put whatever name you like in the App name field. Add an oauth redirect url with the value
https://localhost:8443/oauthCallback
and register the app. -
In this popup, grab the values for Id and App Secret since you'll need them later.
-
Now it's time to clone the repo, so open a terminal and run
git clone https://github.com/watsonwork/watsonwork-java-starter.git && cd watsonwork-java-starter
-
Open the config.yml file, change appId to the Id from above, and change appSecret to your secret from above.
-
In config.yml, uncomment the following lines:
# - type: https # port: 8443 # keyStorePath: skeleton.keystore # keyStorePassword: skeleton # validateCerts: false
Additionally, if you are on macos, uncomment these lines and replace JAVA_HOME with your java home
## trustStorePath is only necessary on macos, replace JAVA_HOME with your own java home ## trustStorePath: JAVA_HOME/jre/lib/security/cacerts
-
On linux/macos, run the command
./gradlew run
. On windows rungradlew run
-
Visit https://localhost:8443
-
Click on the button to observe the oauth flow and authorize the app.
-
Follow steps 1-5 in Run Locally
-
Sign up for a free trial on Bluemix and create an app.
-
Install the Cloud Foundry cli and then Install the Bluemix cli. On Windows, be sure to add the bluemix cli to your PATH.
-
Run
bluemix login -a https://api.ng.bluemix.net
, and enter your email and password when prompted -
Run
./gradlew clean build
on linux/mac orgradlew clean build
on windows. This will generate a file calledmanifest.yml
in the root folder of your app, containing some default settings to be used when uploading to bluemix. -
Run
cf push my-app-name --hostname my-host-name
, wheremy-app-name
is what you'd like to call your app on bluemix, andmy-host-name
is the host you want to use on bluemix (i.e. if you usemy-host-name
, your app will be hosted athttps://my-host-name.mybluemix.net
).Tip: Make sure the name you want to use is not taken on Bluemix already, since it must be unique.
Tip: Because of the
manifest.yml
file, if you just typecf push
, the name of your project folder will be used as the app name on bluemix. To make use of this you need to change the name of the project folder fromwatsonwork-java-starter
tomy-app-name
and run the command in step 5 again. -
When it's finished pushing to bluemix, visit your app's url.
This can only be done if you have the app set up on a public address, you can use bluemix for this, see Run on Bluemix, or port forwarding if you control the wifi router.
- Go back to the app creation page and edit your app.
- Click on Add an outbound webhook and give it a name. The callback url should be your app's public base url followed by
/webhook
, for examplehttps://watsonwork-java-starter.mybluemix.net/webhook
. Tick themessage-created
event. Do not tick the "enable" checkbox yet, because your app needs to know the webhook secret in order to respond to a verification request from the Watson Work Services. - Click the save button and take note of the webhook secret.
- Go back to your config.yml in the local project, and fill in the value for webhookSecret.
- Push to bluemix by following steps 4-6 in Run on Bluemix
- When the app is finished pushing to bluemix, go back to the app creation page one last time, edit your app and enable the webhook. Click save. Your app will now receive webhook events of the types you asked for.
- Go to Workspaces and select the space you want to add the app to. Click the dropdown at the top of the page where its name is, and then click the Apps section. You will see your app here.
- Hover over your app and click Add to space.
- Post a message in your space and watch your app respond.