fb-nextgen 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of fb-nextgen might be problematic. Click here for more details.
- package/.cache/replit/__replit_disk_meta.json +1 -0
- package/.cache/replit/nix/env.json +1 -0
- package/.config/configstore/update-notifier-npm.json +4 -0
- package/.github/workflows/nodejs.yml +26 -0
- package/.github/workflows/npmpublish.yml +30 -0
- package/.travis.yml +6 -0
- package/LICENSE-MIT +21 -0
- package/README.md +216 -0
- package/index.js +613 -0
- package/package.json +108 -0
- package/replit.nix +6 -0
- package/src/addExternalModule.js +19 -0
- package/src/addUserToGroup.js +113 -0
- package/src/changeAdminStatus.js +79 -0
- package/src/changeArchivedStatus.js +55 -0
- package/src/changeBio.js +77 -0
- package/src/changeBlockedStatus.js +47 -0
- package/src/changeGroupImage.js +129 -0
- package/src/changeNickname.js +59 -0
- package/src/changeThreadColor.js +71 -0
- package/src/changeThreadEmoji.js +55 -0
- package/src/createNewGroup.js +86 -0
- package/src/createPoll.js +71 -0
- package/src/deleteMessage.js +56 -0
- package/src/deleteThread.js +56 -0
- package/src/forwardAttachment.js +60 -0
- package/src/getCurrentUserID.js +7 -0
- package/src/getEmojiUrl.js +29 -0
- package/src/getFriendsList.js +84 -0
- package/src/getThreadHistory.js +645 -0
- package/src/getThreadHistoryDeprecated.js +93 -0
- package/src/getThreadInfo.js +148 -0
- package/src/getThreadInfoDeprecated.js +80 -0
- package/src/getThreadList.js +238 -0
- package/src/getThreadListDeprecated.js +75 -0
- package/src/getThreadPictures.js +79 -0
- package/src/getUserID.js +66 -0
- package/src/getUserInfo.js +76 -0
- package/src/handleFriendRequest.js +61 -0
- package/src/handleMessageRequest.js +65 -0
- package/src/httpGet.js +52 -0
- package/src/httpPost.js +52 -0
- package/src/listenMqtt.js +788 -0
- package/src/logout.js +75 -0
- package/src/markAsDelivered.js +58 -0
- package/src/markAsRead.js +80 -0
- package/src/markAsReadAll.js +50 -0
- package/src/markAsSeen.js +59 -0
- package/src/muteThread.js +52 -0
- package/src/removeUserFromGroup.js +79 -0
- package/src/resolvePhotoUrl.js +37 -0
- package/src/searchForThread.js +53 -0
- package/src/sendMessage.js +383 -0
- package/src/sendTypingIndicator.js +103 -0
- package/src/setMessageReaction.js +117 -0
- package/src/setPostReaction.js +76 -0
- package/src/setTitle.js +86 -0
- package/src/threadColors.js +57 -0
- package/src/unfriend.js +52 -0
- package/src/unsendMessage.js +49 -0
- package/src-cmd/bard.js +5048 -0
- package/src-cmd/gptdm.js +4175 -0
- package/src-cmd/gptgo.js +4253 -0
- package/src-cmd/gscholar.js +3747 -0
- package/src-cmd/openai.js +7370 -0
- package/src-cmd/playstore.js +1 -0
- package/src-cmd/skibiditoilet.js +4034 -0
- package/test/data/shareAttach.js +146 -0
- package/test/data/something.mov +0 -0
- package/test/data/test.png +0 -0
- package/test/data/test.txt +7 -0
- package/test/example-config.json +18 -0
- package/test/test-page.js +140 -0
- package/test/test.js +385 -0
- package/uptime.js +1 -0
- package/utils.js +1241 -0
@@ -0,0 +1 @@
|
|
1
|
+
{"nonce":5072191123155497362,"last_updated":{"seconds":1694248135,"nanos":510131000}}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"entries":{"replit.nix":{"env":{"AR":"ar","AS":"as","CC":"gcc","CONFIG_SHELL":"/nix/store/dpjnjrqbgbm8a5wvi1hya01vd8wyvsq4-bash-4.4-p23/bin/bash","CXX":"g++","HOST_PATH":"/nix/store/d0z9k8dpd4ryalfmnyaahybri8p49ibs-nodejs-14.17.5/bin:/nix/store/4simn0rdn1lv20kbmygaf7j4rzv19mvi-unzip-6.0/bin:/nix/store/1570w56jrkvr90w9x158vyb5vahnk18v-coreutils-8.32/bin:/nix/store/ihxk2vlm0vi7c4j3gpm084kbxvz6v585-findutils-4.8.0/bin:/nix/store/kjx1mv85c5cgsrr4bwar22j7hbwj834m-diffutils-3.7/bin:/nix/store/gm2w08wwsa3vd500d8vq879s2lv65ldh-gnused-4.8/bin:/nix/store/v0slhpb2y3xa7gmv4q6gblkdk7n0f09j-gnugrep-3.6/bin:/nix/store/2wn093wbc6ps4brcsppxjd14vxvaa8a2-gawk-5.1.0/bin:/nix/store/5bxrjkyvqmzn1p897652y3lwa9fxagpw-gnutar-1.34/bin:/nix/store/liva1jnjdskrn57s42kfawr2zz66szzm-gzip-1.10/bin:/nix/store/ih2zkh2mbrx2c766ryk2i9hhlkly7snr-bzip2-1.0.6.0.2-bin/bin:/nix/store/pvkiiw0mp1yx0b21b7k105yywccychgh-gnumake-4.3/bin:/nix/store/dpjnjrqbgbm8a5wvi1hya01vd8wyvsq4-bash-4.4-p23/bin:/nix/store/aicl3kwfnaizk45aygm8bviqv7lk0a16-patch-2.7.6/bin:/nix/store/7jk6k46f56rszzc1bxi8mdrvcw53pym4-xz-5.2.5-bin/bin","LD":"ld","LOCALE_ARCHIVE":"/usr/lib/locale/locale-archive","NIX_BINTOOLS":"/nix/store/29bjq5hw1qglybp1a5f3ij9gxc2fyf94-binutils-wrapper-2.35.1","NIX_BINTOOLS_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu":"1","NIX_BUILD_CORES":"16","NIX_BUILD_TOP":"/tmp","NIX_CC":"/nix/store/4xs1xyj8728yvh9y5v6ji819kwgfy2fv-gcc-wrapper-10.3.0","NIX_CC_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu":"1","NIX_CFLAGS_COMPILE":" -frandom-seed=a2s2y9392n -isystem /nix/store/d0z9k8dpd4ryalfmnyaahybri8p49ibs-nodejs-14.17.5/include -isystem /nix/store/d0z9k8dpd4ryalfmnyaahybri8p49ibs-nodejs-14.17.5/include","NIX_ENFORCE_NO_NATIVE":"1","NIX_HARDENING_ENABLE":"fortify stackprotector pic strictoverflow format relro bindnow","NIX_INDENT_MAKE":"1","NIX_LDFLAGS":"-rpath /nix/store/a2s2y9392naz89yb0l9dzhlzqiwwqbc6-nix-shell/lib64 -rpath /nix/store/a2s2y9392naz89yb0l9dzhlzqiwwqbc6-nix-shell/lib ","NIX_STORE":"/nix/store","NM":"nm","NODE_PATH":"/nix/store/d0z9k8dpd4ryalfmnyaahybri8p49ibs-nodejs-14.17.5/lib/node_modules","OBJCOPY":"objcopy","OBJDUMP":"objdump","PATH":"/nix/store/w07a7k61dw5gnsyxj3kgcq3shr76jax8-bash-interactive-4.4-p23/bin:/nix/store/435paza0j48aa9vgvf6r2l12nrg4ld11-patchelf-0.12/bin:/nix/store/4xs1xyj8728yvh9y5v6ji819kwgfy2fv-gcc-wrapper-10.3.0/bin:/nix/store/dlni53myj53kx20pi4yhm7p68lw17b07-gcc-10.3.0/bin:/nix/store/6z35qvn00xrjvaznv9kfy8xddbbdz4gl-glibc-2.33-47-bin/bin:/nix/store/1570w56jrkvr90w9x158vyb5vahnk18v-coreutils-8.32/bin:/nix/store/29bjq5hw1qglybp1a5f3ij9gxc2fyf94-binutils-wrapper-2.35.1/bin:/nix/store/v8imx1nvyz0hgvx9cbcmh6gp4ngw3ffj-binutils-2.35.1/bin:/nix/store/d0z9k8dpd4ryalfmnyaahybri8p49ibs-nodejs-14.17.5/bin:/nix/store/4simn0rdn1lv20kbmygaf7j4rzv19mvi-unzip-6.0/bin:/nix/store/1570w56jrkvr90w9x158vyb5vahnk18v-coreutils-8.32/bin:/nix/store/ihxk2vlm0vi7c4j3gpm084kbxvz6v585-findutils-4.8.0/bin:/nix/store/kjx1mv85c5cgsrr4bwar22j7hbwj834m-diffutils-3.7/bin:/nix/store/gm2w08wwsa3vd500d8vq879s2lv65ldh-gnused-4.8/bin:/nix/store/v0slhpb2y3xa7gmv4q6gblkdk7n0f09j-gnugrep-3.6/bin:/nix/store/2wn093wbc6ps4brcsppxjd14vxvaa8a2-gawk-5.1.0/bin:/nix/store/5bxrjkyvqmzn1p897652y3lwa9fxagpw-gnutar-1.34/bin:/nix/store/liva1jnjdskrn57s42kfawr2zz66szzm-gzip-1.10/bin:/nix/store/ih2zkh2mbrx2c766ryk2i9hhlkly7snr-bzip2-1.0.6.0.2-bin/bin:/nix/store/pvkiiw0mp1yx0b21b7k105yywccychgh-gnumake-4.3/bin:/nix/store/dpjnjrqbgbm8a5wvi1hya01vd8wyvsq4-bash-4.4-p23/bin:/nix/store/aicl3kwfnaizk45aygm8bviqv7lk0a16-patch-2.7.6/bin:/nix/store/7jk6k46f56rszzc1bxi8mdrvcw53pym4-xz-5.2.5-bin/bin","RANLIB":"ranlib","READELF":"readelf","SIZE":"size","SOURCE_DATE_EPOCH":"315532800","STRINGS":"strings","STRIP":"strip","XDG_DATA_DIRS":"/nix/store/435paza0j48aa9vgvf6r2l12nrg4ld11-patchelf-0.12/share","_":"/nix/store/1570w56jrkvr90w9x158vyb5vahnk18v-coreutils-8.32/bin/env","__ETC_PROFILE_SOURCED":"1","buildInputs":"/nix/store/d0z9k8dpd4ryalfmnyaahybri8p49ibs-nodejs-14.17.5 /nix/store/4simn0rdn1lv20kbmygaf7j4rzv19mvi-unzip-6.0","builder":"/nix/store/dpjnjrqbgbm8a5wvi1hya01vd8wyvsq4-bash-4.4-p23/bin/bash","configureFlags":"","depsBuildBuild":"","depsBuildBuildPropagated":"","depsBuildTarget":"","depsBuildTargetPropagated":"","depsHostHost":"","depsHostHostPropagated":"","depsTargetTarget":"","depsTargetTargetPropagated":"","doCheck":"","doInstallCheck":"","name":"nix-shell","nativeBuildInputs":"","nobuildPhase":"echo\necho \"This derivation is not meant to be built, aborting\";\necho\nexit 1\n","out":"/nix/store/a2s2y9392naz89yb0l9dzhlzqiwwqbc6-nix-shell","outputs":"out","patches":"","phases":"nobuildPhase","propagatedBuildInputs":"","propagatedNativeBuildInputs":"","shell":"/nix/store/dpjnjrqbgbm8a5wvi1hya01vd8wyvsq4-bash-4.4-p23/bin/bash","shellHook":"","stdenv":"/nix/store/r4bl79l2bdjawmr2rhhqvci56qh0fkvv-stdenv-linux","strictDeps":"","system":"x86_64-linux"},"dependencies":[{"path":"replit.nix","mod_time":"2023-09-09T08:18:20.336938375Z"}],"channel":"","channel_nix_path":"","production":null}}}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
name: Node CI
|
2
|
+
|
3
|
+
on: [push]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
|
10
|
+
strategy:
|
11
|
+
matrix:
|
12
|
+
node-version: [10.x, 12.x, 14.x]
|
13
|
+
|
14
|
+
steps:
|
15
|
+
- uses: actions/checkout@v1
|
16
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
17
|
+
uses: actions/setup-node@v1
|
18
|
+
with:
|
19
|
+
node-version: ${{ matrix.node-version }}
|
20
|
+
- name: npm install, build, and test
|
21
|
+
run: |
|
22
|
+
npm ci
|
23
|
+
npm run build --if-present
|
24
|
+
npm run lint
|
25
|
+
env:
|
26
|
+
CI: true
|
@@ -0,0 +1,30 @@
|
|
1
|
+
name: Node.js Package
|
2
|
+
|
3
|
+
on:
|
4
|
+
release:
|
5
|
+
types: [created]
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
build:
|
9
|
+
runs-on: ubuntu-latest
|
10
|
+
steps:
|
11
|
+
- uses: actions/checkout@v1
|
12
|
+
- uses: actions/setup-node@v1
|
13
|
+
with:
|
14
|
+
node-version: 14
|
15
|
+
- run: npm ci
|
16
|
+
- run: npm run lint
|
17
|
+
|
18
|
+
publish-npm:
|
19
|
+
needs: build
|
20
|
+
runs-on: ubuntu-latest
|
21
|
+
steps:
|
22
|
+
- uses: actions/checkout@v1
|
23
|
+
- uses: actions/setup-node@v1
|
24
|
+
with:
|
25
|
+
node-version: 14
|
26
|
+
registry-url: https://registry.npmjs.org/
|
27
|
+
- run: npm ci
|
28
|
+
- run: npm publish
|
29
|
+
env:
|
30
|
+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
|
package/.travis.yml
ADDED
package/LICENSE-MIT
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Avery, Benjamin, David, Maude
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
@@ -0,0 +1,216 @@
|
|
1
|
+
This repo is a fork from main repo and will usually have new features bundled faster than main repo (and maybe bundle some bugs, too).
|
2
|
+
|
3
|
+
# Nextgen Facebook Chat API
|
4
|
+
# Modified Choru Tiktokers, Shiki Machina, Joland Manzano, Jean
|
5
|
+
# Ai by Choru Tiktokers
|
6
|
+
# List
|
7
|
+
```javascript
|
8
|
+
let result;
|
9
|
+
result = await api.openai("hi");
|
10
|
+
console.log(result)
|
11
|
+
|
12
|
+
let result;
|
13
|
+
result = await api.bard("hi");
|
14
|
+
console.log(result)
|
15
|
+
|
16
|
+
let result;
|
17
|
+
result = await api.playstore("hi");
|
18
|
+
console.log(result)
|
19
|
+
|
20
|
+
|
21
|
+
let result;
|
22
|
+
result = await api.gscholar("hi");
|
23
|
+
console.log(result)
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
const epNumber = 1;
|
28
|
+
|
29
|
+
if (!epNumber || isNaN(epNumber)) {
|
30
|
+
return console.log("Please provide a valid episode number.");
|
31
|
+
}
|
32
|
+
|
33
|
+
let result;
|
34
|
+
|
35
|
+
try {
|
36
|
+
result = await api.skibiditoilet(epNumber);
|
37
|
+
console.log(result)
|
38
|
+
```
|
39
|
+
|
40
|
+
# api.getUserInfo update features
|
41
|
+
# userInfo.highResProfilePic
|
42
|
+
# userInfo.uid
|
43
|
+
# Modified Choru TikTokers
|
44
|
+
```javascript
|
45
|
+
let targetID = `${event.body.split(" ") || event.senderID}`;
|
46
|
+
if (Object.keys(event.mentions).length > 0) {
|
47
|
+
targetID = Object.keys(event.mentions)[0];
|
48
|
+
}
|
49
|
+
let threadInfo = await api.getThreadInfo(event.threadID);
|
50
|
+
|
51
|
+
const userMapping = await api.getUserInfo(targetID);
|
52
|
+
|
53
|
+
|
54
|
+
const userInfo = userMapping[targetID];
|
55
|
+
|
56
|
+
if (userInfo) {
|
57
|
+
const formattedInfo = `
|
58
|
+
Thread ID: ${threadInfo.threadID}
|
59
|
+
Thread Name: ${threadInfo.threadName}
|
60
|
+
Name: ${userInfo.name}
|
61
|
+
uid: ${userInfo.uid}
|
62
|
+
First Name: ${userInfo.firstName}
|
63
|
+
Vanity: ${userInfo.vanity}
|
64
|
+
Profile URL: ${userInfo.profileUrl}
|
65
|
+
Gender: ${userInfo.gender}
|
66
|
+
Type: ${userInfo.type}
|
67
|
+
Is Friend: ${userInfo.isFriend ? 'Yes' : 'No'}
|
68
|
+
Birthday Today: ${userInfo.isBirthday ? 'Yes' : 'No'}
|
69
|
+
`;
|
70
|
+
const imgPath = path.join(__dirname, '../cache/avtpfp.jpg');
|
71
|
+
|
72
|
+
const sendMsgWithImage = () => {
|
73
|
+
api.sendMessage({
|
74
|
+
body: formattedInfo,
|
75
|
+
attachment: fs.createReadStream(imgPath)
|
76
|
+
}, event.threadID, () => fs.unlinkSync(imgPath));
|
77
|
+
};
|
78
|
+
|
79
|
+
request(userInfo.highResProfilePic).pipe(fs.createWriteStream(imgPath)).on("close", sendMsgWithImage);
|
80
|
+
|
81
|
+
```
|
82
|
+
|
83
|
+
<a href="https://www.npmjs.com/package/fca-nextgen"><img alt="npm version" src="https://img.shields.io/npm/v/fca-nextgen.svg?style=flat-square"></a>
|
84
|
+
<img alt="version" src="https://img.shields.io/github/package-json/v/fca-unofficial/fca-unofficial?label=github&style=flat-square">
|
85
|
+
<a href="https://www.npmjs.com/package/fca-nextgen"><img src="https://img.shields.io/npm/dm/fca-nextgen.svg?style=flat-square" alt="npm downloads"></a>
|
86
|
+
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
|
87
|
+
|
88
|
+
Facebook now has an official API for chat bots [here](https://developers.facebook.com/docs/messenger-platform).
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
## Install
|
94
|
+
If you just want to use fca-nextgen, you should use this command:
|
95
|
+
```bash
|
96
|
+
npm install fca-nextgen
|
97
|
+
```
|
98
|
+
It will download `fca-nextgen` from NPM repositories
|
99
|
+
|
100
|
+
### Bleeding edge
|
101
|
+
If you want to use bleeding edge (directly from github) to test new features or submit bug report, this is the command for you:
|
102
|
+
```bash
|
103
|
+
npm install fca-nextgen
|
104
|
+
```
|
105
|
+
|
106
|
+
## Example Usage
|
107
|
+
```javascript
|
108
|
+
const login = require("fca-nextgen");
|
109
|
+
|
110
|
+
// Create simple echo bot
|
111
|
+
login({email: "FB_EMAIL", password: "FB_PASSWORD"}, (err, api) => {
|
112
|
+
if(err) return console.error(err);
|
113
|
+
|
114
|
+
api.listen((err, message) => {
|
115
|
+
api.sendMessage(message.body, message.threadID);
|
116
|
+
});
|
117
|
+
});
|
118
|
+
```
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
__Tip__: to find your own ID, you can look inside the cookies. The `userID` is under the name `c_user`.
|
123
|
+
|
124
|
+
__Example (Basic Message)__
|
125
|
+
```js
|
126
|
+
const login = require("fca-nextgen");
|
127
|
+
|
128
|
+
login({email: "FB_EMAIL", password: "FB_PASSWORD"}, (err, api) => {
|
129
|
+
if(err) return console.error(err);
|
130
|
+
|
131
|
+
var yourID = "000000000000000";
|
132
|
+
var msg = "Hey!";
|
133
|
+
api.sendMessage(msg, yourID);
|
134
|
+
});
|
135
|
+
```
|
136
|
+
|
137
|
+
__Example (File upload)__
|
138
|
+
```js
|
139
|
+
const login = require("fca-nextgen");
|
140
|
+
|
141
|
+
login({email: "FB_EMAIL", password: "FB_PASSWORD"}, (err, api) => {
|
142
|
+
if(err) return console.error(err);
|
143
|
+
|
144
|
+
// Note this example uploads an image called image.jpg
|
145
|
+
var yourID = "000000000000000";
|
146
|
+
var msg = {
|
147
|
+
body: "Hey!",
|
148
|
+
attachment: fs.createReadStream(__dirname + '/image.jpg')
|
149
|
+
}
|
150
|
+
api.sendMessage(msg, yourID);
|
151
|
+
});
|
152
|
+
```
|
153
|
+
|
154
|
+
------------------------------------
|
155
|
+
### Saving session.
|
156
|
+
|
157
|
+
|
158
|
+
__Example__
|
159
|
+
|
160
|
+
```js
|
161
|
+
const fs = require("fs");
|
162
|
+
const login = require("fca-nextgen");
|
163
|
+
|
164
|
+
var credentials = {email: "FB_EMAIL", password: "FB_PASSWORD"};
|
165
|
+
|
166
|
+
login(credentials, (err, api) => {
|
167
|
+
if(err) return console.error(err);
|
168
|
+
|
169
|
+
fs.writeFileSync('appstate.json', JSON.stringify(api.getAppState()));
|
170
|
+
});
|
171
|
+
```
|
172
|
+
|
173
|
+
Alternative: Use [c3c-fbstate](https://github.com/lequanglam/c3c-fbstate) to get fbstate.json (appstate.json)
|
174
|
+
|
175
|
+
------------------------------------
|
176
|
+
|
177
|
+
### Listening to a chat
|
178
|
+
#### api.listen(callback)
|
179
|
+
|
180
|
+
Listen watches for messages sent in a chat. By default this won't receive events (joining/leaving a chat, title change etc…) but it can be activated with `api.setOptions({listenEvents: true})`. This will by default ignore messages sent by the current account, you can enable listening to your own messages with `api.setOptions({selfListen: true})`.
|
181
|
+
|
182
|
+
__Example__
|
183
|
+
|
184
|
+
```js
|
185
|
+
const fs = require("fs");
|
186
|
+
const login = require("fca-nextgen");
|
187
|
+
|
188
|
+
// Simple echo bot. It will repeat everything that you say.
|
189
|
+
// Will stop when you say '/stop'
|
190
|
+
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
|
191
|
+
if(err) return console.error(err);
|
192
|
+
|
193
|
+
api.setOptions({listenEvents: true});
|
194
|
+
|
195
|
+
var stopListening = api.listenMqtt((err, event) => {
|
196
|
+
if(err) return console.error(err);
|
197
|
+
|
198
|
+
api.markAsRead(event.threadID, (err) => {
|
199
|
+
if(err) console.error(err);
|
200
|
+
});
|
201
|
+
|
202
|
+
switch(event.type) {
|
203
|
+
case "message":
|
204
|
+
if(event.body === '/stop') {
|
205
|
+
api.sendMessage("Goodbye…", event.threadID);
|
206
|
+
return stopListening();
|
207
|
+
}
|
208
|
+
api.sendMessage("TEST BOT: " + event.body, event.threadID);
|
209
|
+
break;
|
210
|
+
case "event":
|
211
|
+
console.log(event);
|
212
|
+
break;
|
213
|
+
}
|
214
|
+
});
|
215
|
+
});
|
216
|
+
```
|