Below is an demonstration of using the customData from webSDK at fields of Simple Task.
We are setting up a webService alert which would send notifications to the user based on Category (available at the customData present in web SDK).
Follow the below syntax to add customData to web SDK at index.html.
botOptions.botInfo={ name: "Ambiguous choice", "_id": "st-108853be-d963-5d46-ac33-08a19f2fbfd2", customData: { "category": "rssfeedstopstories" }
};
Now create a webservice alert on the bot builder with the parameter category which is not mandatory to prompt the user.
Add a preprocessor to push the data from the customData object to the parameter “category” created on the builder.
Note: The customData will be available under BotUserSession.lastMessage.messagePayload.botInfo
Code snippet to push the data from customData object to the parameter using pre-processor.
var fields= {};
var pathFields = {};
var obj = BotUserSession.get(“lastMessage”);
pathFields.category = obj.messagePayload.botInfo.customData.category;
fields.pathFields = pathFields;
var finalObject = {};
finalObject.fields = fields;
print(JSON.stringify(finalObject));
We are using this category at the endpoint as a query parameter to fetch the data from endpoint as shown below.
Configuring the bot response to print the titles available in the response from API.
Configure the settings to set up the frequency options and the de-duplication strategy as needed for your alert and finish setup.
Now execute the alert from the web SDK channel. Below are the snips showing the setup for alert and the alerts received based on the category which is present in customData of web SDK.