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 🙏

© 2026 – Pkg Stats / Ryan Hefner

meta-messenger.js

v1.1.0

Published

Unofficial Meta Messenger Chat API for NodeJS

Readme

Unofficial Facebook Messenger API

Discord

[!TIP] The project has been moved here. The original repository will be archived.

Facebook now has an official API for chat bots here.

This API is one of the ways to automate chat functions on user accounts. Using the mautrix-meta library (Go) through FFI binding, this library supports (almost) all features that the original library has implemented through a high-level JavaScript API.

[!CAUTION] Using this feature on user accounts is prohibited under Meta's Terms of Service and may result in account suspension. I am not responsible for any Meta accounts that are suspended due to using this library.

Installation

npm install meta-messenger.js

Requirements

  • Node.js >= 22
  • Cookies from a logged-in Facebook/Messenger account

Usage Example

import { Client, Utils } from 'meta-messenger.js'
import { readFileSync } from 'fs'

// Read cookies from file (supports multiple formats)
const cookies = Utils.parseCookies(readFileSync('cookies.json', 'utf-8'))

// Create a new client
const client = new Client(cookies)

// Listen to events
client.on('message', async (message) => {
    console.log(`Message from ${message.senderId}: ${message.text}`)
    
    // Simple echo bot
    if (message.text === 'ping') {
        await client.sendMessage(message.threadId, 'pong')
    }
})

// Connect
await client.connect()
console.log(`Logged in as: ${client.user?.name}`)

img

Documentation

Main Features

Send Messages

// Simple message
await client.sendMessage(threadId, 'Hello!')

// Message with reply
await client.sendMessage(threadId, {
    text: 'This is a reply',
    replyToId: 'mid.xxx'
})

// Message with mention
await client.sendMessage(threadId, {
    text: 'Hello @friend!',
    mentions: [{ userId: 123456, offset: 6, length: 7 }]
})

Send Media

import { readFileSync } from 'fs'

// Send image
const image = readFileSync('photo.jpg')
await client.sendImage(threadId, image, 'photo.jpg', 'Caption here')

// Send video
const video = readFileSync('video.mp4')
await client.sendVideo(threadId, video, 'video.mp4')

// Send sticker
await client.sendSticker(threadId, 369239263222822) // thumbs up

Save E2EE State

To persist the E2EE state for later use, you should save the device data to a file:

import { writeFileSync, readFileSync } from 'fs'

// Save device data when it changes
client.on('deviceDataChanged', ({ deviceData }) => {
    writeFileSync('device.json', deviceData)
})

// Load device data on startup
const deviceData = readFileSync('device.json', 'utf-8')
const client = new Client(cookies, { deviceData })

Listen to Messages

client.on('message', (message) => {
    console.log(`[${message.threadId}] ${message.senderId}: ${message.text}`)
    
    // Handle attachments
    for (const att of message.attachments || []) {
        if (att.type === 'image') {
            console.log(`  Image: ${att.url}`)
        } else if (att.type === 'sticker') {
            console.log(`  Sticker: ${att.stickerId}`)
        }
    }
})

// E2EE messages
client.on('e2eeMessage', (message) => {
    console.log(`[E2EE] ${message.senderJid}: ${message.text}`)
})

Supported Cookie Formats

The API supports multiple cookie formats through Utils.parseCookies():

  1. C3C UFC Utility / EditThisCookie
  2. Simple object
  3. Cookie header string
  4. Netscape cookie file format
  5. Base64 encoded (any of the above formats)

Required cookies: c_user, xs (others like datr, fr are optional)

FAQs

  1. How do I get cookies?

Log in to Facebook in your browser, open DevTools (F12), go to Application > Cookies tab, and copy the values for c_user, xs (and optionally datr, fr).

  1. Why am I not receiving E2EE messages?

Make sure you have enabled E2EE with enableE2EE: true and wait for the fullyReady event before processing messages.

  1. What's the difference between message and e2eeMessage events?
  • message: Regular messages, metadata visible to Facebook
  • e2eeMessage: End-to-end encrypted messages, only sender and receiver can read
  1. Why do I need to wait for fullyReady?

The fullyReady event is emitted when both socket and E2EE (if enabled) are ready. If you process messages before this, you may miss some E2EE messages.

License

GNU Affero General Public License v3.0

According to mautrix-meta License

Credits

Disclaimer

All product and company names are trademarks™ or registered® trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.
"Facebook", "Messenger", "Meta", "Instagram" is a registered trademark of Meta, Inc., used under license agreement.