Giter Club home page Giter Club logo

messenger-api.js's Introduction

Warning: I don't take any responsibility for blocked Facebook accounts that used this module.

1. About

  • messenger-api.js is a powerful Node.js module that allow you to interact with the Facebook API.

  • This module was fixed from: facebook-chat-api

2. Installation

npm install messenger-api.js@latest

3. Example usage

// index.js
const { Client, Events } = require("messenger-api.js")
const credentials = require("./path/to/your/fbstate.json")
const client = new Client({ online: true })

client.on(Events.Ready, bot => {
    console.log(`Logged as ${bot.user.username}`)
})

client.on(Events.MessageCreate, message => {
    if (message.isClientUser) return

    if (message.content === "/ping") {
        message.thread.send("Pong!")
    }

    if (message.content === "/mention") {
        message.thread.send(`<@${message.author.id}> :3`)
    }
})

client.login(credentials)
// fbstate.json
[
    {
        "key": "dbln",
        "value": "%7B%22000000000000000%22%3A%22HHEKSDDOR78%22%7D",
        "domain": "facebook.com",
        "path": "/login/device-based/",
        "hostOnly": false,
        "creation": "2023-02-25T15:46:50.557Z",
        "lastAccessed": "2023-02-25T15:46:50.558Z"
    },
    {
        "key": "sb",
        "value": "AeR-RES-qr98de480ogajq79g",
        "domain": "facebook.com",
        "path": "/",
        "hostOnly": false,
        "creation": "2023-02-25T15:46:50.558Z",
        "lastAccessed": "2023-02-25T15:46:50.558Z"
    },
    {
        "key": "datr",
        "value": "AeR-GfqGyAF-otw480ogajq79g",
        "domain": "facebook.com",
        "path": "/",
        "hostOnly": false,
        "creation": "2023-02-25T15:46:50.558Z",
        "lastAccessed": "2023-02-25T15:46:50.558Z"
    },
    {
        "key": "locale",
        "value": "en_GB",
        "domain": "facebook.com",
        "path": "/",
        "hostOnly": false,
        "creation": "2023-02-25T15:46:50.558Z",
        "lastAccessed": "2023-02-25T15:46:50.558Z"
    },
    {
        "key": "wd",
        "value": "1322x623",
        "domain": "facebook.com",
        "path": "/",
        "hostOnly": false,
        "creation": "2023-02-25T15:46:50.558Z",
        "lastAccessed": "2023-02-25T15:46:50.558Z"
    },
    {
        "key": "c_user",
        "value": "000000000000000",
        "domain": "facebook.com",
        "path": "/",
        "hostOnly": false,
        "creation": "2023-02-25T15:46:50.558Z",
        "lastAccessed": "2023-02-25T15:46:50.558Z"
    },
    {
        "key": "presence",
        "value": "C%7B%22lm3%22%3A%22g.2807234593920434%22%2C%22t3%22%3A%5B%5D%2C%22utc3%22%3A7855167733735%2C%22v%22%3A1%7D",
        "domain": "facebook.com",
        "path": "/",
        "hostOnly": false,
        "creation": "2023-02-25T15:46:50.558Z",
        "lastAccessed": "2023-02-25T15:46:50.558Z"
    },
    {
        "key": "xs",
        "value": "secret",
        "domain": "facebook.com",
        "path": "/",
        "hostOnly": false,
        "creation": "2023-02-25T15:46:50.558Z",
        "lastAccessed": "2023-02-25T15:46:50.558Z"
    },
    {
        "key": "fr",
        "value": "secret",
        "domain": "facebook.com",
        "path": "/",
        "hostOnly": false,
        "creation": "2023-02-25T15:46:50.558Z",
        "lastAccessed": "2023-02-25T15:46:50.558Z"
    }
]
  • Note: Use c3c-fbstate to get your account credentials.

4. Extensions

5. Contributing

6. Help

messenger-api.js's People

Contributors

misonomikadev avatar nekocyan avatar aiko-chan-ai avatar tachittanachote-ascend avatar gillhoang avatar

Stargazers

090099999999000 avatar Eien えいえん avatar Jose Fabio avatar Hiraku Katsumi avatar mingshu avatar Krzysztof Matuszak avatar Đinh Nhật Minh avatar Võ Thành Khánh Duy avatar  avatar John Marlo Lapiz avatar Patohru avatar Hoàng Giang avatar ภัยพิบัติทางไซเบอร์ avatar  avatar  avatar Kry avatar  avatar Nhân Nguyễn avatar chiruno avatar LovMoon3k avatar BeztDonkey avatar Thảo Nhiên Nguyễn (Erika - Erik|Rika) avatar  avatar  avatar  avatar Chu Nguyen Hoang Son avatar Nguyen Huu Hieu avatar Do Van Xuan avatar Cừu Đen avatar Ruri avatar  avatar Elian avatar Hayakawa Ayano avatar Toby Cm avatar  avatar Peter Tuan Anh avatar  avatar

Watchers

Kostas Georgiou avatar Allou Mohamed avatar

messenger-api.js's Issues

Cannot read properties of undefined

I got these error when starting the project, please check

messenger-api.js/src/client/Utils.js:120
        return () => (defaultValue ??= cb());
                                   ^^^

SyntaxError: Unexpected token '??='
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'user' of undefined
    at new Thread (/messenger-api.js/src/structures/Thread.js:27:46)
 UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'displayName' of undefined
    at new Thread (/messenger-api.js/src/structures/Thread.js:34:46)

This lib will break in one month due to E2EE.

Messenger will soon make E2EE chats the default. These chats do not show with the library - which will break the current state of the library.

There are a few similar repositories that are all based around the original facebook-chat-api. I think it makes sense to have one central place to discuss this: https://discord.gg/8FWVYhQ7P5.

Steps to reproduce:

  • open Messenger on your phone
  • select any one to one chat
  • enable "Secret Conversation"
  • see the new E2EE thread on your phone and in the browser
  • send a message to that thread on any device
  • confirm that the thread shows up on all devices and browsers
  • with the api, do api.getThreadList(5, null, ["INBOX"], function(err, res) { ...
  • confirm that the api response does not have the E2EE chat
  • I would not mind not seeing E2EE chats because I didn't enable them anyway but they will soon force this for everyone by the end of the year, meaning we only have 4 weeks left to add this

https://www.reddit.com/r/facebook/comments/17s8n46/messenger_forced_me_to_create_a_pin_and_now_my/

https://messengernews.fb.com/2023/08/22/expanding-testing-for-end-to-end-encryption-on-messenger/

parseAndCheckLogin got status code: 404. Bailing out of trying to parse response.

Some facebook account cannot log in correctly.

node:internal/process/promises:288
            triggerUncaughtException(err, true /* fromPromise */);
            ^

Error: parseAndCheckLogin got status code: 404. Bailing out of trying to parse response.
    at C:\Users\Tachittanachote\Desktop\Facebook\node_modules\messenger-api.js\src\lib\utils.js:994:48
    at tryCatcher (C:\Users\Tachittanachote\Desktop\Facebook\node_modules\bluebird\js\main\util.js:26:23)
    at Promise.attempt.Promise.try (C:\Users\Tachittanachote\Desktop\Facebook\node_modules\bluebird\js\main\method.js:31:24)
    at C:\Users\Tachittanachote\Desktop\Facebook\node_modules\messenger-api.js\src\lib\utils.js:972:28
    at tryCatcher (C:\Users\Tachittanachote\Desktop\Facebook\node_modules\bluebird\js\main\util.js:26:23)
    at Promise._settlePromiseFromHandler (C:\Users\Tachittanachote\Desktop\Facebook\node_modules\bluebird\js\main\promise.js:510:31)
    at Promise._settlePromiseAt (C:\Users\Tachittanachote\Desktop\Facebook\node_modules\bluebird\js\main\promise.js:584:18)
    at Async._drainQueue (C:\Users\Tachittanachote\Desktop\Facebook\node_modules\bluebird\js\main\async.js:128:12)
    at Async._drainQueues (C:\Users\Tachittanachote\Desktop\Facebook\node_modules\bluebird\js\main\async.js:133:10)
    at Async.drainQueues [as _onImmediate] (C:\Users\Tachittanachote\Desktop\Facebook\node_modules\bluebird\js\main\async.js:15:14)
    at process.processImmediate (node:internal/timers:471:21)

Node.js v18.12.1

Debugging result at parseAndCheckLogin function

data.statusCode: 200
data.request.uri: Url {
  protocol: 'https:',
  slashes: true,
  auth: null,
  host: 'www.facebook.com',
  port: 443,
  hostname: 'www.facebook.com',
  hash: null,
  search: null,
  query: null,
  pathname: '/chat/user_info/',
  path: '/chat/user_info/',
  href: 'https://www.facebook.com/chat/user_info/'
}

data.statusCode: 500
data.request.uri: Url {
  protocol: 'https:',
  slashes: true,
  auth: null,
  host: 'www.facebook.com',
  port: 443,
  hostname: 'www.facebook.com',
  hash: null,
  search: null,
  query: null,
  pathname: '/api/graphqlbatch/',
  path: '/api/graphqlbatch/',
  href: 'https://www.facebook.com/api/graphqlbatch/'
}

data.statusCode: 404
data.request.uri: Url {
  protocol: 'https:',
  slashes: true,
  auth: null,
  host: 'www.facebook.com',
  port: 443,
  hostname: 'www.facebook.com',
  hash: null,
  search: null,
  query: null,
  pathname: '/api/graphqlbatch/',
  path: '/api/graphqlbatch/',
  href: 'https://www.facebook.com/api/graphqlbatch/'
}

Logging out unexpectedly.

Copied the cookies and stored it on fbstate.json but the problem is that after logging in, it will automatically logged out.
Do you know the issue behind this? I tried other packages as well but still getting the same results. Thanks.

image

How to get all chat list

I am using this library on electron , facebook login success but the request of api is not pass

I want to get a list of all sessions of the logged-in user

I don't think it will work. Can you give me an example

thanks, I really need help

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.