Mood based push sample is an intuitive example usage of Bluemix P ush Notifications Service with the help of Watson Tone Analyzer Service , OpenWhisk and Cloudant Service.
The Mood-based-push-sample implements the core features of the scenario described above. It showcases OpenWhisk, Watson APIs, Cloudant with Bluemix Push Notifications Service and demonstrates mobile integration capabilities. The Feedback app will register a feedback on recent purchased item to the cloudant complaints
database. The openWhisk will read the changes in the complaints
and will send the data to Watson Tone Analyzer. The Tone Analyzer will send back the results to OpenWhisk , by analyzing the result OpenWhisk will fetch appropriate message from Cloudant moods
database and constructs a valid message . This message get pushed to IBM Push Notifications Service
and deliver to the mobile device.
Follow the steps below ,
-
Create a Bluemix Application. Configure the Bluemix Push Notifications service.
-
Create and Bind a Watson Tone Analyzer Service to your application.
-
Create a database named Mood in your Cloudant. In the
mood
database create a view namednew_view
and design namedmoodPick
. -
Click on the new design document you have created in previous step and edit it with the below given lines. Do not have to change the
_id
and_rev
values.{ "_id": "_design/moodPick", "_rev": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "indexes": { "fields": { "analyzer": "keyword", "index": "function(doc) {index("default", doc._id, {"facet": true});if ((doc.mood) || (doc.mood===0)){index("doc.mood", doc.mood);}if ((doc.message) || (doc.message===0)){index("message", doc.message);}}" } }, "views": { "new_view": { "map": "function (doc) { emit(doc.mood,doc.message);}" } }, "language": "javascript" }
-
In the above created add messages for each emotions -
Fear, Sadness, andDisgust, Anger and Joy
(Watson Tone Analyzer outputs). For example,{ "mood": "Joy", "message": "thank you very much for your valuable feedback. We are extremely happy to here from you. Come back again have a wonderfull shopping experience with us." }
-
In your Cloudant, create one more database named
complaints
.
The sendFeedback.js
file will need the following parameters to complete the actions.
-
appId
- Bluemix app GUID. -
appSecret
- Bluemix Push Service appSecret. -
version
- This is the version of the Tone analyzer service . -
message
- The test value that is passing to the Tone Analyzer service as user Input. -
cloudantUserName
- Your cloudant username. This is for accessing yourmood
database in cloudant. -
cloudantPassword
- Your cloudant password. This is for accessing yourmood
database in cloudant. -
appRegion
- Region where your bluemix app is hosted. Eg for US Dallas -.ng.bluemix.net
. -
deviceIds
- The deviceId to which the message need to be send. This data will come from thecomplaints
database. -
name
- Name of the customer. This data will come from thecomplaints
database.
For OpenWhisk setup you have to get the auth from the Bluemix OpenWhisk. Install OpenWhisk CLI and Auth.
The example app have Feedback sending feature. The following steps should be completed before running the example app.
-
Create an OpenWhisk
action
using the following command.wsk action update yourActionName sendFeedback.js -p version 'toneAnalyserVersion' -p cloudantUserName '' -p cloudantPassword '' -p appSecret '' -p appId '' -p appRegion '.ng.bluemix.net'
-
Create a OpenWhisk
Trigger
.wsk trigger create yourTriggerName --feed /yourNameSpace/CloudantPackage/changes -p dbname complaints -p includeDoc true -p username 'cloudantUsername' -p password 'cloudantPassword' -p host 'cloudantUsername.cloudant.com'
-
Create OpenWhisk Rule to join
yourActionName
andyourTriggerName
.wsk rule create --enable yourRule yourTriggerName yourActionName
-
Enable the activation Poll.
wsk activation poll
-
Open the Example app in
XCode.app
. Go to theInfo.plist
file and add values forcloudantPermission
andcloudantUserName
. -
Do
carthage update
in the application to add the Bluemix Push service SDK. -
Run the application and register for push notifications and close the app.
-
Reopen the app again, it will ask for Feedback, go to the feedback page send a feed back.
-
You will get push notifications as feedback response.
Copyright 2015-2016 IBM Corporation
Licensed under the Apache License, Version 2.0 (the "License").
Unless required by applicable law or agreed to in writing, software distributed under the license is distributed on an "as is" basis, without warranties or conditions of any kind, either express or implied. See the license for the specific language governing permissions and limitations under the license.