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

messenger-events

v2.3.2

Published

Messenger Events is an abstraction layer over the more popular [`facebook-chat-api`](https://github.com/Schmavery/facebook-chat-api/) and has as an objective to simplify the library and make it overall more consistent through embracing immutable Object-Or

Downloads

9

Readme

Messenger Events

Messenger Events is a thin abstraction layer over the more popular facebook-chat-api and has as an objective to simplify the library and make it overall more consistent through embracing immutable Object-Oriented design while at the same time enabling backward compatibility with the underlying library.

Performance is at best a consideration in this project and is sacrificed on every turn in favor of making the library easier to use. This library is not recommended for projects relying on quick response times and instead favors more complex use cases such as building a messenger clone.

This library abstracts nearly everything you will need so you don't have to!

Feature Support

Incomplete Features

The following are features which either feature no, or insufficient support but will have first-class support.

  • Abstraction for sending stickers
  • Abstraction for sending files
  • Abstraction for sending pictures
  • Abstraction for handling received files
  • Abstraction for handling received pictures
  • Thread lists
  • Thread history
  • onReaction events (Facebook does not report the actual message to which someone reacted, but just the ID. It is possible to find out the message but will require the parsing of the thread until the messsage id is found)

Unsupported Features

The following are features which will, at best, feature second-class support and worst, not be implemented. If facebook-chat-api supports a feature in this list, you can still use it by using it directly. Conversely, some in this list are not supported because they lack support and will be implemented if it changes.

  • Animated stickers (Reason: Messenger uses sprites and math to animate stickers. This is a massive pain.)
  • Calling (Reason: Not supported by dependency in issue #472 )
  • GetFriendsList() method (Reason: Read the response to my PR, if you are curious, Messenger Events is using my fork instead of the official repo until it is fixed)Cleaner Syntax

Features

Cleaner Code

The following is a short program to receive a message, react to it, log the user's nickname (if any) as well as his real name and send him a private message.

require("messenger-events")
    ({email: "FB_EMAIL", password: "FB_PASSWORD"},
    (success, $) => {
        if (!success) return console.log($);

        $.onMessage((context, message) => {
            message.react(":haha:");
            console.log(context.user.nickname, context.user.name);
            context.user.sendMessage("Hey!")
        })
    })

Supports multipler listeners

require("messenger-events")
    ({email: "FB_EMAIL", password: "FB_PASSWORD"},
    (success, $) => {
        if (!success) return console.log($);

        $.onMessage((context, message) => {
            console.log("This will be called first")
        })
        
        $.onMessage((context, message) => {
            console.log("This will be called second")
        })
        
        $.onMessage((context, message) => {
            console.log("This will be called third")
        })
    })

Directly interface with facebook-chat-api

To permit users more familiar with facebook-chat-api to gradually transition to Messenger Events as well as to allow the usage of left-out features, it exposes direct access to the API in the $.api object.

require("messenger-events")
    ({email: "FB_EMAIL", password: "FB_PASSWORD"},
    (success, $) => {
        if (!success) return console.log($);

        var yourID = "000000000000000";
        var msg = "Hey!";
        $.api.sendMessage(msg, yourID);
  
  		// Or alternatively,
  		let api = $.api;
  		api.sendMessage(msg, yourID);
    })

When using the legacy api object directly, note that using api.listen()is not the real api.listen() but instead mapped to api.legacyListen() while the real one is at api.realListen(). While they are functionally the same, you must never use api.realListen() as it will break all the abstractions. A bonus of using api.legacyListen(), is that it allows you to reuse it multiple times as opposed to the real listener provided by facebook-chat-api (Issue #525).

Notice

This project is in active development making it both not feature-complete (yet) and unstable enough to make it unsuitable for production environments. You are encouraged to remedy both of those issues.

This project depends fully on facebook-chat-api, if there is a bug in their code, it will propagate to this package as well.