42 lines
1.8 KiB
JavaScript
42 lines
1.8 KiB
JavaScript
|
|
// Code node (Run once for each item)
|
|||
|
|
// Добавляет text, buttons и готовое тело для MAX (message_body с inline_keyboard, callback).
|
|||
|
|
|
|||
|
|
return items.map(item => {
|
|||
|
|
const text = "Вас давно не было. Выберите, чем хотите заняться:";
|
|||
|
|
const buttons = [
|
|||
|
|
{ title: "ℹ️ О сервисе", payload: "about" },
|
|||
|
|
{ title: "📝 Подать жалобу", payload: "complaint" },
|
|||
|
|
{ title: "📋 Мои обращения", payload: "my_tickets" },
|
|||
|
|
{ title: "💬 Поддержка", payload: "support" }
|
|||
|
|
];
|
|||
|
|
|
|||
|
|
// MAX: каждый ряд — одна кнопка (во всю ширину). Внизу кнопка "Главное меню" (type: message) —
|
|||
|
|
// при нажатии бот получит сообщение "/menu" и можно снова показать это меню.
|
|||
|
|
const callbackRows = buttons.map(b => [ { type: "callback", text: b.title, payload: b.payload } ]);
|
|||
|
|
// Кнопка "Главное меню": type message — при нажатии бот получит этот text.
|
|||
|
|
const menuButtonRow = [ { type: "message", text: "📋 Главное меню" } ];
|
|||
|
|
// Кнопка "Поделиться контактом": request_contact — MAX запросит телефон, в webhook придёт message_created с контактом (структуру смотри в payload).
|
|||
|
|
const contactButtonRow = [ { type: "request_contact", text: "📱 Отправить номер телефона" } ];
|
|||
|
|
const message_body = {
|
|||
|
|
text,
|
|||
|
|
format: "markdown",
|
|||
|
|
attachments: [
|
|||
|
|
{
|
|||
|
|
type: "inline_keyboard",
|
|||
|
|
payload: {
|
|||
|
|
buttons: [ ...callbackRows, contactButtonRow, menuButtonRow ]
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
]
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
return {
|
|||
|
|
json: {
|
|||
|
|
...item.json,
|
|||
|
|
text,
|
|||
|
|
buttons,
|
|||
|
|
message_body
|
|||
|
|
}
|
|||
|
|
};
|
|||
|
|
});
|