Search code examples
javascriptnode.jshttprequestfacebook-messenger

Node js: Automated Broadcast, facebook messenger


I am writing a messenger bot with node js express. I want to broadcast daily messages to my users. To do that, I need to use the following post requests:

curl -X POST -H "Content-Type: application/json" -d '{    
  "messages":[
    <MESSAGE_OBJECT>
  ]
}' "https://graph.facebook.com/v2.11/me/message_creatives?access_token=<PAGE_ACCESS_TOKEN>>"

This one outputs a message_creative_id and is followed by the following:

 curl -X POST -H "Content-Type: application/json" -d '{    
  "message_creative_id": <MESSAGE_CREATIVE_ID>,
  "notification_type": "<REGULAR | SILENT_PUSH | NO_PUSH>",
  "messaging_type": "MESSAGE_TAG",
  "tag": "NON_PROMOTIONAL_SUBSCRIPTION"
}' "https://graph.facebook.com/v2.11/me/broadcast_messages?access_token=<PAGE_ACCESS_TOKEN>"

Is there any way to automatically send the requests at a preset time?

Edit: The post needs to be repeated daily and the a different message will sent. The messages will be predetermined and the admin should not have to change it through the code.

Edit2: I also plan on automating it to a degree so that non-technical admins can add the messages. i.e. they will just enter the time and message and some script will take care of the rest.


Solution

  • Yes, you need to add "schedule_time": "<ISO-8601_OR_UNIX_TIMESTAMP>" parameter to your existing request body of /broadcast_messages endpoint, for more info please refer to Docs.