Action Sequences
ActionSequence
s allow you to execute a series of Action
s which can modify a slot's value, trigger analytics events or clear out a slot altogether.
Action Sequence
ActionSequence
is a top level class that allows to sequentially execute a collection of actions. This allows you to do things like clearing/setting slot values or triggering analytics events from your Cloud Function.
The actions
property of ActionSequence
class should contain all the actions that you would like to execute. You can add as many or as few actions you like.
import { ActionSequence } from "@stackchat/dynamic-content-toolkit";
function sayHello() {
const actionSequence = new ActionSequence();
actionSequence.actions = [ ... ]
return [ actionSequence ];
}
Note: An
ActionSequence
must contain at least one action.
There are three types of Action
s you can use:
Set Slots
The SetSlotsAction
allows you to modify the value of one or more slots in your bot.
import {
SetSlotsAction,
ActionSequence
} from "@stackchat/dynamic-content-toolkit";
function updateSlotValues() {
const setSlotsAction = new SetSlotsAction();
setSlotsAction.slots = {
Slot1: "Value 1",
Slot2: "Value 2",
Slot3: "Value 3"
};
const actionSequence = new ActionSequence();
actionSequence.actions = [ setSlotsAction ];
return [ actionSequence ]
}
Clear Slots
The ClearSlotsAction
allows to reset the value of one or more slots in your bot.
import {
ClearSlotsAction,
ActionSequence
} from "@stackchat/dynamic-content-toolkit";
function resetSlots() {
const clearSlotsAction = new ClearSlotsAction();
clearSlotsAction.slotNames = [
"Slot1", "Slot2", "Slot3"
];
const actionSequence = new ActionSequence();
actionSequence.actions = [ clearSlotsAction ];
return [ actionSequence ]
}
Trigger Analytics
The AnalyticsEventAction
allows you trigger an analytics event complete with custom properties.
The
eventData
is an optional object that is sent as a straight pass-through to your configured analytics provider. It is an object with arbitary key-value mappings that should map to the values expected by your analytics provider.
import {
AnalyticsEventAction,
ActionSequence
} from "@stackchat/dynamic-content-toolkit";
function saveAnalyticsSnapshot() {
const analyticsEventAction = new AnalyticsEventAction();
/**
* The `eventName` property is required, but this value
* is ignored by Adobe Analytics.
*/
analyticsEventAction.eventName = "Event 1";
/**
* For example, if you're using Adobe Analytics,
* `eventData` might look something like this:
*/
analyticsEventAction.eventData = {
prop1: "value 1",
prop38: "value 2",
events: "event3,event4"
}
const actionSequence = new ActionSequence();
actionSequence.actions = [ analyticsEventAction ];
return [ actionSequence ]
}