Database plugin
The Database plugin allows custom attributes to be captured and associated to the conversation.
Note: Please subscribe to ready event before calling any Database plugin commands.
When Database plugin is ready to accept commands, it will publish ready event. It's recommended to subscribe to this event before calling any commands in this plugin. If the ready event is already published before you subscribe to it, it will simply republish again ensuring your callback function gets executed.
Database plugin commands
Database.set
Set the database with the provided data. If the customAttributes property already exists in the database, it will simply update with the new data (shallow merge).
Options:
Option | Data type | Description |
Genesys("command", "Database.set", { messaging: { customAttributes: { key: 'value' }}},
function(data){ /* fulfilled, returns data */}, function(){ /* rejected */ });
{
messaging: {
customAttributes: {}
},
..
}
Published event: Database.updated
Database.update
Update the existing database with the new data (deep merge).
Options:
Option | Data type | Description |
Genesys("command", "Database.update", { messaging: { customAttributes: { key: 'value2' }}},
function(data){ /* fulfilled, returns data */}, function(){ /* rejected */ });
{
messaging: {
customAttributes: {}
},
..
}
Published event: Database.updated
Database.get
Retrieve the data value of an object property name passed in the command. If no object property name is provided, the entire database object is returned.
Options:
Option | Data type | Description |
Genesys("command", "Database.get", { name: "messaging.customAttributes" },
function(data){ /* fulfilled, returns data */}, function(){ /* rejected */ });
{ key: 'value2', ...}
{ messaging: { customAttributes: { } }, ... }
Database.remove
Delete an object property and its associated data from the Database plugin.
Note: The Database.remove
command only removes data from the Database plugin. Data already sent on an inbound message is not removed from the conversation.
Options:
Option | Data type | Description |
Published event: Database.removed
Genesys("command", "Database.remove", { name: "messaging.customAttributes" },
function(data){ /* fulfilled, returns data */}, function(){ /* rejected */ });
Database plugin events
Database.ready
Published when the Database plugin is initialized.
Data: Not applicable.
Genesys("subscribe", "Database.ready", function() {
console.log("Database plugin is ready.")
});
Database.updated
Published when customAttributes are updated in the database.
Data: Updated database object
Genesys("subscribe", "Database.updated", function(e){
console.log(e.data) // Updated database object
});
Database.removed
Published when customAttributes are removed from the database.
Data: Updated database object
Genesys("subscribe", "Database.removed", function(e){
console.log(e.data) // Updated database object
});