The SmartFollowup is an intuitive example usage of Bluemix Push Notifications Service with the help of Watson Tone Analyzer Service , OpenWhisk and Cloudant Service.
The SmartFollowup app will register a feedback on the recently purchased items to the cloudant complaints
database. The OpenWhisk will read changes in the complaints
and will send data to Watson Tone Analyzer. The Tone Analyzer will send back the results to OpenWhisk. By analyzing the results, OpenWhisk will fetch appropriate message from Cloudant moods
database and construct a valid message. This message gets pushed to IBM Push Notifications service
, and is delivered to the mobile device.
##Requirements
- iOS 10
- Xcode 8.+
- Swift 3.+
- Cocoapods
Complete the steps:
Go to https://console.ng.bluemix.net and Log in. Click on Catalog on the top bar.
-
On the left pane click on
Boiler Plates
below Apps. Create [MobileFirst service starter] app. This will havePush notification service
. -
Create an
Mobile Foundation
service. -
Click on Catalog on the top bar. On the left pane click on
Watson
belowServices
.Create aWatson Tone Analyzer
Service. -
Create a database named
mood
in your Cloudant. In themood
database, create a view namednew_view
and design namedmoodPick
. -
Click the new design document you have created in step 3 and update it with the following 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"
}
- To the updated new design document, add messages for each emotions -
Fear, Sadness, Disgust, 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
. This will be used in iOS application
Go to your push service and add iOS
configuration. Please follow the doc here to create iOS certificates
The BlueShoping.swift
file need the following parameters to complete the actions.
-
appId
- Bluemix app GUID. -
appSecret
- Bluemix Push Notification service appSecret. -
version
- This is the version of the Tone Analyzer service . -
cloudantUserName
- Your Cloudant username. This is for accessing yourmood
database in Cloudant. -
cloudantPermissionKey
- Your Cloudant cloudantPermission Key. This is for accessing yourmood
database in Cloudant. -
cloudantPermissionPassword
- Your Cloudant cloudantPermission Password. This is for accessing yourmood
database in Cloudant.
- Open the OpenWhisk Web Editor, and create
swift
action. Replace the content of the action withBlueShoping.swift
- Create a Cloudant package binding using the Bluemix OpenWhisk CLI.
wsk -v package bind /whisk.system/cloudant CloudantPackage -p username 'cloudantUsername' -p password 'cloudantPassword'
-p host 'yourUserName.cloudant.com' -p dbname 'complaints'
- Create a OpenWhisk
Trigger
.
wsk trigger create yourTriggerName --feed /yourNameSpace/CloudantPackage/changes
- Create a rule to connect your action (step 1) and trigger (step 3)
wsk rule create myRule yourTriggerName yourActionName
- Open the SmartFollowup app in
XCode.app
. Go to theAppDelegate.swift
file and add values for ,
//cloudant
var cloudantName:String = "Cloudant DB name"
var cloudantUserName:String = "Cloudant Username"
var cloudantPassword:String = "Cloudant password"
var cloudantHostName:String = "Your cloudant host name"
//Whisk
var whiskKey:String = "OpenWhisk Key"
var whiskPass:String = "OpenWhisk password"
//Push Service
var pushAppGUID:String = "push Service app GUID"
var pushAppClientSecret:String = "push Service client secret"
var pushAppRegion:String = "Push/AppID service region"
//APPID
let appIdTenantId = "your APPID tenant Id"
-
Do
pod install
in the application. And openSmartFollowup.xcworkspace
-
Run the application and Login using AppID.
-
Go to the feedback page and send feedback.
-
You will get push notifications as feedback response.
Copyright 2017-2018 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. `