Hi guys i have a problem merging two objects any idea how can i do this ?
controller.hears('offres','message_received, facebook_postback',function(bot,message){
connection.connect("mongodb://localhost/bot",function(err,db){
var z ="";
var data = db.collection('offres').find().toArray().then(function(data){
for (var i =0 ; i<10; i++){
var _under = require("underscore");
var titre = data[i]['titre'];
var ref = data[i]['ref'].toString();
var description = data[i]['description'];
b = setpayload(titre,description, ref,'https://cdn.pixabay.com/photo/2017/01/13/17/29/hiring-1977803_960_720.jpg');
z= _under.extend(z, b);
}
bot.reply(message,{
attachment:{
'type': 'template',
'payload': {
'template_type': 'generic',
'elements':[z ]
}}
})
})
});
function setpayload(titre,sub, ref, image)
{
var m = {
'title': titre,
'image_url': image,
'subtitle': sub,
'buttons': [
{
'type': 'postback',
'title': 'postuler',
'payload': ref
},
{
'type': 'postback',
'title': 'plus de détail',
'payload': ref
}
]
}
return m ;
}
notant que pour un slide ça marche tré bien controller.hears('offres','message_received, facebook_postback',function(bot,message){
connection.connect("mongodb://localhost/bot",function(err,db){
var data = db.collection('offres').find().toArray().then(function(data){
var _under = require("underscore");
var titre = data[0]['titre'];
var ref = data[0]['ref'].toString();
var description = data[0]['description'];
b = setpayload(titre,description, ref,'https://cdn.pixabay.com/photo/2017/01/13/17/29/hiring-1977803_960_720.jpg');
bot.reply(message,{
attachment:{
'type': 'template',
'payload': {
'template_type': 'generic',
'elements':[b]
}}
})
})
});
function setpayload(titre,sub, ref, image)
{
var m = {
'title': titre,
'image_url': image,
'subtitle': sub,
'buttons': [
{
'type': 'postback',
'title': 'postuler',
'payload': ref
},
{
'type': 'postback',
'title': 'plus de détail',
'payload': ref
}
]
}
return m ;
}
via shaghabo
No comments:
Post a Comment