Я пытаюсь подключить свой чат-бот facebook messenger к mongodb база данных. Это простой чат-бот с вопросами, который будет принимать текст и отображать некоторые кнопки с параметрами, и если пользователь нажимает одну кнопку, он должен отображать больше кнопок с параметрами и т. д. Здесь я настроил чат-бот в nodejs и вместо жесткого кодирования я хочу для извлечения данных из базы данных mongodb и отправки запросов в ту же базу данных. Может ли кто-нибудь помочь мне, как подключить чат-бота мессенджера к базе данных mongodb, а также как мне написать схемы для публикации и получения ответов. Заранее спасибо. Вот мой код чат-бота в мессенджере.



![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


if (received_message.text) {
// Get the URL of the message attachments
response = {
attachment: {
type: "template",
payload: {
template_type: "generic",
elements: [
{
title: "Welcome to Flying Sphaghetti Monster Restaurant!",
subtitle: "Choose any of the options below.",
image_url:
"https://content3.jdmagicbox.com/comp/hyderabad/h5/040pxx40.xx40.140516124003.h3h5/catalogue/flying-spaghetti-monster-restaurant-jubilee-hills-hyderabad-home-delivery-restaurants-p6kmmr.jpg",
default_action: {
type: "web_url",
url:
"https://content3.jdmagicbox.com/comp/hyderabad/h5/040pxx40.xx40.140516124003.h3h5/catalogue/flying-spaghetti-monster-restaurant-jubilee-hills-hyderabad-home-delivery-restaurants-p6kmmr.jpg",
webview_height_ratio: "tall"
},
buttons: [
{
type: "postback",
title: "Walkin!",
payload: "A"
},
{
type: "postback",
title: "Reserve table!",
payload: "B"
},
{
type: "postback",
title: "Feed back!",
payload: "C"
}
]
}
]
}
}
};
else if (received_message.attachments){ let attachment_url = received_message.attachments[0].payload.url;
response = {
attachment: {
type: "template",
payload: {
template_type: "generic",
elements: [
{
title: "What this picture is for?",
subtitle: "Tap a button to answer.",
image_url: attachment_url,
buttons: [
{
type: "postback",
title: "Review!",
payload: "yes"
},
{
type: "postback",
title: "Suggestion!",
payload: "yeah"
}
]
}
]
}
} callSendAPI(sender_psid, response);
};}
Вот как я обрабатываю постбэки...
function handlePostback(sender_psid, received_postback) {
let response;
let payload = received_postback.payload;
if (payload === "A")
{
response = {
attachment: {
type: "template",
payload: {
template_type: "generic",
elements: [
{
title: "you have choosen for walkin!",
subtitle: "please choose these available walkins!.",
image_url:
"https://content3.jdmagicbox.com/comp/hyderabad/h5/040pxx40.xx40.140516124003.h3h5/catalogue/flying-spaghetti-monster-restaurant-jubilee-hills-hyderabad-home-delivery-restaurants-p6kmmr.jpg",
default_action: {
type: "web_url",
url:
"https://content3.jdmagicbox.com/comp/hyderabad/h5/040pxx40.xx40.140516124003.h3h5/catalogue/flying-spaghetti-monster-restaurant-jubilee-hills-hyderabad-home-delivery-restaurants-p6kmmr.jpg",
webview_height_ratio: "tall"
},
buttons: [
{
type: "postback",
title: "4 PM",
payload: "a"
},
{
type: "postback",
title: "5 PM",
payload: "b"
},
{
type: "postback",
title: "6 PM",
payload: "c"
}
]
}
]`