async function handleAction(actionType, actionData) {
//lets write a switch statement to handle the different action types
switch (actionType) {
case "UNSUBSCRIBE":
const { uid, reason } = actionData;
//write code to unsubscribe the user from database
//send back a response
return {
actionResponseType: "AppendDialogue",
actionResponseData: {
"content": "The user has been successfully unsubscribed!",
"role":"system"
}
};
case "QUERY":
const { query } = actionData;
//write code to query the database
//send back a response where the content is the result of the query
return {
actionResponseType: "AppendDialogue",
actionResponseData: {
"content": "The result of the query is: We have medium woolen jumpers in blue, red, and green. The item code is 123456.",
"role":"system"
}
};
case "SUBSCRIBE":
const { uid, subscription } = actionData;
return {
actionResponseType: "AppendDialogue",
actionResponseData: {
"content": "The user has been successfully subscribed!",
"role":"system"
}
};
case "PURCHASE":
const { uid, itemId, color } = actionData;
//write code to purchase the item
//send back a response
return {
actionResponseType: "AppendDialogue",
actionResponseData: {
"content": "The user's card was declined. Tell them to update their payment information.",
"role":"system"
}
};
default:
return {
actionResponseType: "AppendDialogue",
actionResponseData: {
"content": "That was an invalid or badly formatted action. Please format your action correctly: <ACTIONNAME>{actionType: string, actionData: object}</ACTIONNAME>. And only use provided actions.",
"role":"system"
}
};
}
}