meta-messenger.js 0.0.1 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +660 -660
- package/README.md +174 -166
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +6 -3
- package/scripts/build-go.mjs +36 -30
- package/scripts/detect-platform.mjs +41 -32
- package/scripts/download-prebuilt.mjs +126 -88
- package/scripts/package.mjs +11 -6
- package/scripts/postinstall.mjs +109 -73
package/README.md
CHANGED
|
@@ -1,166 +1,174 @@
|
|
|
1
|
-
# Unofficial Facebook Messenger API
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
//
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
//
|
|
33
|
-
client
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
//
|
|
59
|
-
await client.sendMessage(threadId,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
await client.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
>
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
>
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
>
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
-
|
|
165
|
-
- [
|
|
166
|
-
- [
|
|
1
|
+
# Unofficial Facebook Messenger API
|
|
2
|
+
|
|
3
|
+
<a href="https://www.npmjs.com/package/meta-messenger.js"><img alt="npm version" src="https://img.shields.io/npm/v/meta-messenger.js.svg?style=flat-square"></a>
|
|
4
|
+
<a href="https://www.npmjs.com/package/meta-messenger.js"><img src="https://img.shields.io/npm/dm/meta-messenger.js.svg?style=flat-square" alt="npm downloads"></a>
|
|
5
|
+
|
|
6
|
+
Facebook now has an official API for chat bots [here](https://developers.facebook.com/docs/messenger-platform).
|
|
7
|
+
|
|
8
|
+
This API is one of the ways to automate chat functions on user accounts.
|
|
9
|
+
Using the [mautrix-meta](https://github.com/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.
|
|
10
|
+
|
|
11
|
+
> [!CAUTION]
|
|
12
|
+
> **Using this feature on user accounts is prohibited under Meta's Terms of Service and may result in account suspension.**
|
|
13
|
+
> **I am not responsible for any Meta accounts that are suspended due to using this library.**
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
```bash
|
|
17
|
+
npm install meta-messenger.js
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Requirements
|
|
21
|
+
- Node.js >= 22
|
|
22
|
+
- Cookies from a logged-in Facebook/Messenger account
|
|
23
|
+
|
|
24
|
+
## Usage Example
|
|
25
|
+
```typescript
|
|
26
|
+
import { Client, Utils } from 'meta-messenger.js'
|
|
27
|
+
import { readFileSync } from 'fs'
|
|
28
|
+
|
|
29
|
+
// Read cookies from file (supports multiple formats)
|
|
30
|
+
const cookies = Utils.parseCookies(readFileSync('cookies.json', 'utf-8'))
|
|
31
|
+
|
|
32
|
+
// Create a new client
|
|
33
|
+
const client = new Client(cookies)
|
|
34
|
+
|
|
35
|
+
// Listen to events
|
|
36
|
+
client.on('message', async (message) => {
|
|
37
|
+
console.log(`Message from ${message.senderId}: ${message.text}`)
|
|
38
|
+
|
|
39
|
+
// Simple echo bot
|
|
40
|
+
if (message.text === 'ping') {
|
|
41
|
+
await client.sendMessage(message.threadId, 'pong')
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
// Connect
|
|
46
|
+
await client.connect()
|
|
47
|
+
console.log(`Logged in as: ${client.user?.name}`)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+

|
|
51
|
+
|
|
52
|
+
## [Documentation](DOCS.md)
|
|
53
|
+
|
|
54
|
+
## Main Features
|
|
55
|
+
|
|
56
|
+
### Send Messages
|
|
57
|
+
```typescript
|
|
58
|
+
// Simple message
|
|
59
|
+
await client.sendMessage(threadId, 'Hello!')
|
|
60
|
+
|
|
61
|
+
// Message with reply
|
|
62
|
+
await client.sendMessage(threadId, {
|
|
63
|
+
text: 'This is a reply',
|
|
64
|
+
replyToId: 'mid.xxx'
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
// Message with mention
|
|
68
|
+
await client.sendMessage(threadId, {
|
|
69
|
+
text: 'Hello @friend!',
|
|
70
|
+
mentions: [{ userId: 123456, offset: 6, length: 7 }]
|
|
71
|
+
})
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Send Media
|
|
75
|
+
```typescript
|
|
76
|
+
import { readFileSync } from 'fs'
|
|
77
|
+
|
|
78
|
+
// Send image
|
|
79
|
+
const image = readFileSync('photo.jpg')
|
|
80
|
+
await client.sendImage(threadId, image, 'photo.jpg', 'Caption here')
|
|
81
|
+
|
|
82
|
+
// Send video
|
|
83
|
+
const video = readFileSync('video.mp4')
|
|
84
|
+
await client.sendVideo(threadId, video, 'video.mp4')
|
|
85
|
+
|
|
86
|
+
// Send sticker
|
|
87
|
+
await client.sendSticker(threadId, 369239263222822) // thumbs up
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Save Session
|
|
91
|
+
|
|
92
|
+
To avoid having to get new cookies each time, you should save the device data (for E2EE) to a file:
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
import { writeFileSync, readFileSync } from 'fs'
|
|
96
|
+
|
|
97
|
+
// Save device data when it changes
|
|
98
|
+
client.on('deviceDataChanged', ({ deviceData }) => {
|
|
99
|
+
writeFileSync('device.json', deviceData)
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
// Load device data on startup
|
|
103
|
+
const deviceData = readFileSync('device.json', 'utf-8')
|
|
104
|
+
const client = new Client(cookies, { deviceData })
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Listen to Messages
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
client.on('message', (message) => {
|
|
111
|
+
console.log(`[${message.threadId}] ${message.senderId}: ${message.text}`)
|
|
112
|
+
|
|
113
|
+
// Handle attachments
|
|
114
|
+
for (const att of message.attachments || []) {
|
|
115
|
+
if (att.type === 'image') {
|
|
116
|
+
console.log(` Image: ${att.url}`)
|
|
117
|
+
} else if (att.type === 'sticker') {
|
|
118
|
+
console.log(` Sticker: ${att.stickerId}`)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
// E2EE messages
|
|
124
|
+
client.on('e2eeMessage', (message) => {
|
|
125
|
+
console.log(`[E2EE] ${message.senderJid}: ${message.text}`)
|
|
126
|
+
})
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Supported Cookie Formats
|
|
130
|
+
|
|
131
|
+
The API supports multiple cookie formats through `Utils.parseCookies()`:
|
|
132
|
+
|
|
133
|
+
1. **C3C UFC Utility / EditThisCookie**
|
|
134
|
+
2. **Simple object**
|
|
135
|
+
3. **Cookie header string**
|
|
136
|
+
4. **Netscape cookie file format**
|
|
137
|
+
5. **Base64 encoded** (any of the above formats)
|
|
138
|
+
|
|
139
|
+
Required cookies: `c_user`, `xs`, `datr`, `fr`
|
|
140
|
+
|
|
141
|
+
## FAQs
|
|
142
|
+
|
|
143
|
+
1. **How do I get cookies?**
|
|
144
|
+
> Log in to Facebook in your browser, open DevTools (F12), go to Application > Cookies tab, and copy the values for `c_user`, `xs`, `datr`, `fr`.
|
|
145
|
+
|
|
146
|
+
2. **Why am I not receiving E2EE messages?**
|
|
147
|
+
> Make sure you have enabled E2EE with `enableE2EE: true` and wait for the `fullyReady` event before processing messages.
|
|
148
|
+
|
|
149
|
+
3. **What's the difference between message and e2eeMessage events?**
|
|
150
|
+
> - `message`: Regular messages, metadata visible to Facebook
|
|
151
|
+
> - `e2eeMessage`: End-to-end encrypted messages, only sender and receiver can read
|
|
152
|
+
|
|
153
|
+
4. **Why do I need to wait for fullyReady?**
|
|
154
|
+
> 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.
|
|
155
|
+
|
|
156
|
+
## License
|
|
157
|
+
|
|
158
|
+
GNU Affero General Public License v3.0
|
|
159
|
+
|
|
160
|
+
According to mautrix-meta License
|
|
161
|
+
|
|
162
|
+
## Credits
|
|
163
|
+
|
|
164
|
+
- Claude Opus 4.5 - Supports understanding and developing this library
|
|
165
|
+
- [mautrix-meta](https://github.com/mautrix/meta) - A Matrix-Facebook Messenger and Instagram DM puppeting bridge.
|
|
166
|
+
- [whatsmeow](https://github.com/tulir/whatsmeow) - Go library for the WhatsApp web multidevice API
|
|
167
|
+
- [facebook-chat-api](https://github.com/Schmavery/facebook-chat-api) - Inspired the API Style
|
|
168
|
+
- [whatsmeow-node](https://github.com/vinikjkkj/whatsmeow-node) - Reference for writing NodeJS library with FFI.
|
|
169
|
+
- [koffi](https://codeberg.org/Koromix/rygel/src/branch/master/src/koffi) - Fast and easy-to-use C FFI module for Node.js
|
|
170
|
+
|
|
171
|
+
## Disclaimer
|
|
172
|
+
|
|
173
|
+
> 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.
|
|
174
|
+
> "Facebook", "Messenger", "Meta", "Instagram" is a registered trademark of Meta, Inc., used under license agreement.
|
package/dist/index.js
CHANGED
|
@@ -995,7 +995,7 @@ var Utils = class _Utils extends null {
|
|
|
995
995
|
* ```
|
|
996
996
|
*/
|
|
997
997
|
static toCookieArray(cookies, domain = ".facebook.com") {
|
|
998
|
-
return Object.entries(cookies).filter(([
|
|
998
|
+
return Object.entries(cookies).filter(([, value]) => value !== void 0).map(([name, value]) => ({
|
|
999
999
|
name,
|
|
1000
1000
|
value,
|
|
1001
1001
|
domain,
|