npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

facebook-message-api

v1.0.4

Published

Unofficial Facebook Chat API for user-account (not page).

Downloads

3

Readme

Facebook Message API

This API is the only way to automate chat functionalities on a user account. We do this by emulating the browser. This means doing the exact same GET/POST requests and tricking Facebook into thinking we're accessing the website normally. Because we're doing it this way, this API won't work with an auth token but requires the credentials of a Facebook account.

Install

Install using npm:

npm install facebook-message-api

Install using yarn:

yarn add facebook-message-api

Testing your bots

If you want to test your bots without creating another account on Facebook, you can use Facebook Whitehat Accounts.

Authenticate

To authenticate your account you should create .env or export it on Environment variable Note: Please make sure that your .env is ignore on git to avoid stealing your credential or you can make your repo private.

# It can be username or email
[email protected]
PASSWORD=markzuckerbot

Example Usage

const command = require('facebook-message-api')

// Initialize the chat command first
// you may passed additional options, it can be accessed into command options from the callback
command.init({ prefix: '/' })

// You can add event middleware
// Note that this will be served as global event middleware
const eventMiddleware1 = (next) => {
  return async (event, api, options) => {
    // Handle before the event is resolved
    await next(event, api, options)
    // Or handle after event has been resolved
  }
}

const eventMiddleware2 = (next) => {
  return async (event, api, options) => {
    // Handle before the event is resolved
    await next(event, api, options)
    // Or handle after event has been resolved
  }
}

command.addEventMiddleware(eventMiddleware1, eventMiddleware2)

// Also you may listen the event using on function
// Listen all incoming events using wildcards
command.on('*', (event, api, options) => {
  // handle all event here
})

// Also you can specify what event to listen, you may use | to listen multiple events
command.on('message|message_unsend', (matches, event, api, options) => {
  // handle message and message_unsend event
})

// You can also listen initialized events
command.on('init', (api, options) => {
  // handle init event here
})

// You can also listen before the scripts restarted
// Why scripts should restart ? because we need to make new facebook home request inorder to get new session token, this will prevent from login state expiration.
command.on('restarting', (api, options) => {
  // handle before the script will be restarted
})

// Adding commands makes easy using chaining method.
command
  .add(async function (match, event, api) {
    // Handle inspire command here
    console.log(match) // { category: 'value here' }
  })
  .addName('inspire')
  .addDescription('Generate motivational quotes.')
  .addAlias('ins')
  .addUsage('/inspire')
  .addPattern('^(.*)$', ['category'])

// Adding global command middleware
const commandMiddleware1 = (next) => {
  return async (match, event, api, options) => {
    // Handle before the command is resolved
    await next(match, event, api, options)
    // Or handle after command has been resolved
  }
}

const commandMiddleware2 = (next) => {
  return async (match, event, api, options) => {
    // Handle before the command is resolved
    await next(match, event, api, options)
    // Or handle after command has been resolved
  }
}
command.addCommandMiddleware(commandMiddleware1, commandMiddleware2)

Command Methods

Command API's


command.add([, callback])

Add command

Arguments

  • callback: A callback function, required.

command.add([, callback]).addName(string name)

Add command name

Arguments

  • name: A command name, required.

command.add([, callback]).addDescription(string description)

Add command Description

Arguments

  • description: A command description, optional.

command.add([, callback]).addAlias(string alias)

Add command alias

Arguments

  • alias: A command alias, optional.

command.add([, callback]).addUsage(string usage)

Add command help usage

Arguments

  • usage: A command usage, optional.

command.add([, callback]).addOption({...option})

Add command option

Arguments

  • option: A command option, you may pass object, optional.

command.add([, callback]).addMiddleware(...middleware)

Add command middleware

Arguments

  • middleware: A command middleware, you may pass args as many as you want, optional.

command.add([, callback]).addPattern(regexPattern, matches)

Add command pattern to match the arguments of the command

Arguments

  • pattern: You may pass regex pattern that matches the arguments of the command, required.
  • matches: You can also pass matches here, example if you passed the first matches with search name, then in the command callback you can get match.search, instead of match[1]

command.add([, callback]).withPrefix(string prefix)

Add command prefix

Arguments

  • prefix: A command prefix, It will be fallback to global prefix if this not defined, optional.

command.add([, callback]).pipe([, callback])

Pipe the command instance into callback function so you can extend functionalities and other stuff

Arguments

  • callback: A pipe callback which has arguments of instance of the Command class, required.

Facebook APIs


Documentation for Facebook API'S

See this from facebook-chat-api

Credits

facebook-chat-api contributors puppeteer

LICENSE

The MIT License (MIT)

Copyright (c) 2015 Avery, Benjamin, David, Maude
Copyright (c) 2022 Jerson Carin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.