Recipes
Confirm cash-on-delivery orders
Call customers before shipping COD orders, confirm or cancel, and offer changes in a submenu.
Cash-on-delivery orders get returned when the customer changes their mind. Confirm them before shipping, and keep extra choices in a submenu.
{
"to": "+34600555666",
"language": "es",
"message": "Hola. Su pedido 1042 de 45 euros, contra reembolso, sale mañana.",
"options": [
{ "label": "Confirmar", "reply": "Perfecto, sale mañana." },
{ "label": "Cancelar", "reply": "Su pedido queda cancelado." },
{
"label": "Cambiar algo",
"options": [
{ "label": "Cambiar la dirección", "reply": "Le enviaremos un enlace por SMS para cambiarla." },
{ "label": "Entregar otro día", "reply": "Le llamaremos para elegir el día." }
]
}
],
"webhook_url": "https://shop.example/hooks/callhuman",
"metadata": { "order_id": "1042" }
}Handle every branch
switch (call.option_path.join(".")) {
case "1": await shipOrder(call.metadata.order_id); break;
case "2": await cancelOrder(call.metadata.order_id); break;
case "3.1": await sendAddressChangeLink(call.metadata.order_id); break;
case "3.2": await scheduleCallback(call.metadata.order_id); break;
default: await holdOrder(call.metadata.order_id); // not answered or nothing chosen
}Using option_path instead of option_label keeps your code working if you reword the labels or translate them.
See Options, replies & submenus for the submenu rules.