I can tell you for one button on rasa webchat , you can extend the same to fb. Here the data is your json/dict which has the information related to your carousels(fetched from database). you can optimize the below code.
carousel_list = []
for i in range(len(data)):
empty_dict = {}
buttons = [{"title": "Title","url": "", "type": "web_url"}]
empty_dict['title'] = data[i]['Title']
empty_dict['subtitle'] = data[i]['Subtitle']
empty_dict['image_url'] = data[i]['image_url']
empty_dict['buttons'] = buttons
empty_dict['buttons'][0]['url'] = data[i]['image_url']
carousel_list.append(empty_dict)
test_carousel = { "type": "template",
"payload": {
"template_type": "generic",
"elements": carousel_list
}
}