This question already has an answer here:
I'm beginning with Javascript, trying to build a Messenger bot. I would like to send a message to all my users, using a loop to send a message for each user ID I have in database. I have no idea how I could do that and found nothing on the internet. The logic would be the following but I know this is not the way to do it:
// DB
var mongoose = require("mongoose");
var db = mongoose.connect(process.env.MONGODB_URI);
var User = require("./models/user");
for (i = 0; i < User.length; i++) {
curl -X POST -H "Content-Type: application/json" -d '{
"recipient":{
"id": User[i][_id]
},
"message":{
"attachment":{
"type": "template",
"payload":{
"template_type": "generic",
"elements":[
{
"title": "Nouvel ou nouveau ?",
"image_url": "https://www.lalanguefrancaise.com/wp-content/uploads/2017/04/nouvel-ou-nouveau.png",
"subtitle": "Faut-il écrire nouvel ou nouveau ? Je vous détaille dans cet article la règle pour ne plus les confondre simplement.",
"buttons": [
{
"type": "web_url",
"url": "https://www.lalanguefrancaise.com",
"title": "Lire article"
},
{
"type": "element_share"
}
]
}
]
}
}
}
}' "https://graph.facebook.com/v2.6/me/messages?access_token=EAAJxZBmxpT0oBAHHYAVqh8ieVFSlFpO0ZC5hqOwLePh4nysZAKnZAZBFNeR9NPYBpccLaHzII492aBE5cNWoh6bEqDZAkHYsgSKTY1IhSULVfioYTKPZC7gGHFhVWVamKPWzoO8vN8smsJloyXyOoZCsTr5yEjoXGAE4OZBbB1XtKbQZDZD"
}
via AlphaNico
No comments:
Post a Comment