Files
MAX/n8n-code-add-menu-buttons.js
root 7cd3ccf21c MAX bot + n8n: webhook, нормализация, меню, доки, схемы БД
- register_max_webhook.py, fetch_schema.py
- n8n-code-node-max-normalize.js (max_id, callback из callback.user, contact из vcf_info)
- n8n-code-add-menu-buttons.js (меню с callback, request_contact, Главное меню)
- docs: max-webhook, max-curl-http-request, max-api (форматы, кнопки, контакт), clpr vs sprf
- README, SITUATION, схемы sprf_ и clpr_, .gitignore

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-16 09:23:51 +03:00

42 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 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
}
};
});