bot-util
bot-util is a package that makes it easier to post and automate posting to Facebook pages.
- Add Facebook pages by ID or link
- Add an app token with manage_pages and publish_pages permissions.
- Automate your posting!
Installation
$ npm install --save bot-util
Quick Start
let bot_util = ; // using Promisesbot_utilfacebook // using await{ let id = await bot_utilfacebook; let post = await bot_utilfacebookpagesid; console;} ;
If you have multiple pages that you want to add all at once, you can use AddPages(pages: array)
, the array containing objects that look like { id: PAGEID, token: TOKEN }
bot_utilfacebook
Posting
A post has a type of either text, image, or video.
Make sure you already added the page before using its ID
Posting text
bot_utilfacebookpagesid;
Posting an image
When posting an image or a video, the 'source' property of the object can either be a path or a ReadStream.
The properties message, caption and description can be used interchangeably for posts.
bot_utilfacebookpagesid;
Posting video
bot_utilfacebookpagesid;
Commenting
A comment can also contain a source property that is used to comment pictures. The 'source' property can be either a path or a ReadStream.
The object_id is the ID of the object upon which the comment will be made.
bot_utilfacebookpagesid;
Getters
bot-util can also be used to get posts, comments, and reactions.
All getters accept an options
object.
Currently the only parameter the options
object supports is fields
which specifies which fields should be retrieved from the Facebook API.
The fields
parameter can either be a string (with the fields separated by ","), or an array of strings
example:
bot_utilfacebookpagesidgetpostsallfields: 'id' 'message' 'type';
or
bot_utilfacebookpagesidgetpostsallfields: 'id, message, created_time';
Posts
all
all(options: object)
bot_utilfacebookpagesidgetpostsall;
latest
latest()
(without any parameter) returns the latest post made on the specified page.
bot_utilfacebookpagesidgetposts;
latest(n: number, options: object)
returns the latest n posts made on the specified page.
bot_utilfacebookpagesidgetposts;
range
range(start_date: Date, end_date: Date, options: object)
returns all posts published between the two dates
let now = ;let aWeekAgo = Date - 7 * 24 * 60 * 60 * 1000;bot_utilfacebookpagesidgetposts;
Comments
comments(object_id: string, options: object)
The object_id is the ID of the object that we are retrieving the comments of.
bot_utilfacebookpagesidget;
Reactions
reactions(object_id: string, options: object)
The object_id is the ID of the object that we are retrieving the reactions of.
bot_utilfacebookpagesidget;
Scheduling Posts
bot_util.facebook.pages[page_id].SchedulePost(recurrenceRule, func)
'func' gets called everytime node-schedule fires.
onPosted(res)
is a callback function that gets called everytime that post is made and is passed an object containing the post id
and, if it's the case, comment id
.
For more info on the 0 */30 * * * *
pattern you can check out the node-schedule package because they have a much better explanation than I could give! For now, 0 */30 * * * *
means every 30 minutes, 0 0 * * * *
means every hour, 0 0 */2 * * *
means every 2 hours.
Sync
bot_utilfacebookpagesid
Async
In the following snippet of code, doAsyncStuff()
is a hypothetical asynchronous function that is resolved at some unknown time in the future.
bot_utilfacebookpagesid;
If these wrappers don't satisfy your needs, you still have access to the whole FB api by using bot_util.facebook.api
TODO
- Discord support