Messenger.TS - v1.2.1

Messenger.TS

Unofficial Api for Facebook and Messenger

Messenger.TS is an Api that can interact with both Facebook and Messenger.

Installation

Messenger.TS requires Node.js v18+ to run.

npm i https://github.com/YMGPwcca/messenger.ts

Usage

Login and save cookies

import fs from 'fs'
import { Client } from 'messenger.ts'

(async () => {
// Using email and password
const client = new Client({
email: 'Your Email/User ID',
password: 'Your Password',
totp: 'Your TOTP Key' // Or with TOTP Key if you've enabled Two-Factor Authentication before
})

// Or with `sessionData` if you have saved it before
// In this case, `sessionData.cookies` will be used to log in.
// If the Api fails to log in with cookies, it will fallback to use your email and password.
const client = new Client({
...
sessionData: JSON.parse(fs.readFileSync('/path/to/your/sessionData.json', 'utf-8'))
})

// Set custom options (See more in the DOCS below)
await client.setOptions({ receiveAdminText: true })

// When you are ready to login
const { Facebook, Messenger } = await client.login()

// Save your login data to a file
fs.writeFileSync('/path/you/want/to/store/sessionData.json', JSON.stringify(client.getSessionData(), null, 2))
})()

Interact with Messenger

// Establish a WebSocket connection to use most of Messenger's methods.
const listener = await Messenger.listen()

// Listen to a message
listener.on('message', async event => {

// Send message
if (event.body === 'ping') await Messenger.sendMessage('pong', event.threadID, event.messageID)

// Send file (Image for example)
if (event.body === 'image') await Messenger.sendMessage([fs.readFileSync('/path/to/your/image.png')], event.threadID, event.messageID)
})

Interact with Facebook

// Get user information
await Facebook.getUserInfo(ID_HERE)

// Get friend list
await Facebook.getFriendsList()

// Upload a text to story
await Facebook.uploadTextStory('This is a bot') // -> Return the story ID
await Facebook.uploadTextStory('This is a bot', this.storyPresets.fonts.Clean) // With font
await Facebook.uploadTextStory('This is a bot', this.storyPresets.fonts.Clean, this.storyPresets.backgrounds.Image.Cactus) // And background

// Upload a media (image/video) to story
await Facebook.uploadMediaStory(fs.readFileSync('/path/to/your/media')) // -> Return the story ID

Documentation

See DOCS

License

See LICENSE