fca-neokex-fix 1.0.1
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/CHANGELOG.md +220 -0
- package/LICENSE +26 -0
- package/README.md +346 -0
- package/THEME_FEATURES.md +137 -0
- package/examples/README.md +131 -0
- package/examples/apply-ai-theme.js +127 -0
- package/examples/check-current-theme.js +74 -0
- package/examples/simple-bot.js +114 -0
- package/examples/test-bot.js +752 -0
- package/examples/test-logging.js +85 -0
- package/examples/theme-usage-example.js +53 -0
- package/index.js +2 -0
- package/package.json +105 -0
- package/src/apis/addExternalModule.js +24 -0
- package/src/apis/addUserToGroup.js +108 -0
- package/src/apis/changeAdminStatus.js +148 -0
- package/src/apis/changeArchivedStatus.js +61 -0
- package/src/apis/changeAvatar.js +103 -0
- package/src/apis/changeBio.js +69 -0
- package/src/apis/changeBlockedStatus.js +54 -0
- package/src/apis/changeGroupImage.js +136 -0
- package/src/apis/changeThreadColor.js +116 -0
- package/src/apis/comment.js +207 -0
- package/src/apis/createAITheme.js +129 -0
- package/src/apis/createNewGroup.js +79 -0
- package/src/apis/createPoll.js +73 -0
- package/src/apis/deleteMessage.js +44 -0
- package/src/apis/deleteThread.js +52 -0
- package/src/apis/editMessage.js +70 -0
- package/src/apis/emoji.js +124 -0
- package/src/apis/fetchThemeData.js +65 -0
- package/src/apis/follow.js +81 -0
- package/src/apis/forwardMessage.js +52 -0
- package/src/apis/friend.js +243 -0
- package/src/apis/gcmember.js +122 -0
- package/src/apis/gcname.js +123 -0
- package/src/apis/gcrule.js +119 -0
- package/src/apis/getAccess.js +111 -0
- package/src/apis/getBotInfo.js +88 -0
- package/src/apis/getBotInitialData.js +43 -0
- package/src/apis/getFriendsList.js +79 -0
- package/src/apis/getMessage.js +423 -0
- package/src/apis/getTheme.js +104 -0
- package/src/apis/getThemeInfo.js +96 -0
- package/src/apis/getThreadHistory.js +239 -0
- package/src/apis/getThreadInfo.js +257 -0
- package/src/apis/getThreadList.js +222 -0
- package/src/apis/getThreadPictures.js +58 -0
- package/src/apis/getUserID.js +83 -0
- package/src/apis/getUserInfo.js +495 -0
- package/src/apis/getUserInfoV2.js +146 -0
- package/src/apis/handleMessageRequest.js +50 -0
- package/src/apis/httpGet.js +63 -0
- package/src/apis/httpPost.js +89 -0
- package/src/apis/httpPostFormData.js +69 -0
- package/src/apis/listenMqtt.js +796 -0
- package/src/apis/listenSpeed.js +170 -0
- package/src/apis/logout.js +63 -0
- package/src/apis/markAsDelivered.js +47 -0
- package/src/apis/markAsRead.js +95 -0
- package/src/apis/markAsReadAll.js +41 -0
- package/src/apis/markAsSeen.js +70 -0
- package/src/apis/mqttDeltaValue.js +330 -0
- package/src/apis/muteThread.js +45 -0
- package/src/apis/nickname.js +132 -0
- package/src/apis/notes.js +163 -0
- package/src/apis/pinMessage.js +141 -0
- package/src/apis/produceMetaTheme.js +180 -0
- package/src/apis/realtime.js +161 -0
- package/src/apis/removeUserFromGroup.js +117 -0
- package/src/apis/resolvePhotoUrl.js +58 -0
- package/src/apis/searchForThread.js +154 -0
- package/src/apis/sendMessage.js +281 -0
- package/src/apis/sendMessageMqtt.js +188 -0
- package/src/apis/sendTypingIndicator.js +41 -0
- package/src/apis/setMessageReaction.js +27 -0
- package/src/apis/setMessageReactionMqtt.js +61 -0
- package/src/apis/setThreadTheme.js +260 -0
- package/src/apis/setThreadThemeMqtt.js +94 -0
- package/src/apis/share.js +107 -0
- package/src/apis/shareContact.js +66 -0
- package/src/apis/stickers.js +257 -0
- package/src/apis/story.js +181 -0
- package/src/apis/theme.js +233 -0
- package/src/apis/unfriend.js +47 -0
- package/src/apis/unsendMessage.js +17 -0
- package/src/database/appStateBackup.js +189 -0
- package/src/database/models/index.js +56 -0
- package/src/database/models/thread.js +31 -0
- package/src/database/models/user.js +32 -0
- package/src/database/threadData.js +101 -0
- package/src/database/userData.js +90 -0
- package/src/engine/client.js +91 -0
- package/src/engine/models/buildAPI.js +109 -0
- package/src/engine/models/loginHelper.js +326 -0
- package/src/engine/models/setOptions.js +53 -0
- package/src/utils/auth-helpers.js +149 -0
- package/src/utils/autoReLogin.js +169 -0
- package/src/utils/axios.js +290 -0
- package/src/utils/clients.js +270 -0
- package/src/utils/constants.js +396 -0
- package/src/utils/formatters/data/formatAttachment.js +370 -0
- package/src/utils/formatters/data/formatDelta.js +153 -0
- package/src/utils/formatters/index.js +159 -0
- package/src/utils/formatters/value/formatCookie.js +91 -0
- package/src/utils/formatters/value/formatDate.js +36 -0
- package/src/utils/formatters/value/formatID.js +16 -0
- package/src/utils/formatters.js +1067 -0
- package/src/utils/headers.js +199 -0
- package/src/utils/index.js +151 -0
- package/src/utils/monitoring.js +358 -0
- package/src/utils/rateLimiter.js +380 -0
- package/src/utils/tokenRefresh.js +311 -0
- package/src/utils/user-agents.js +238 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# Theme Management Features
|
|
2
|
+
|
|
3
|
+
This document explains the theme-related features in NeoKEX-FCA v4.2.5.
|
|
4
|
+
|
|
5
|
+
## š Documentation
|
|
6
|
+
|
|
7
|
+
- **[README](README.md)** - Getting started and overview
|
|
8
|
+
- **[API Reference](API_REFERENCE.md)** - Complete API documentation
|
|
9
|
+
- **[Bot Testing](BOT_TESTING.md)** - Test bot examples
|
|
10
|
+
- **[Contributing](CONTRIBUTING.md)** - Contribution guidelines
|
|
11
|
+
- **[Changelog](CHANGELOG.md)** - Version history
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Available Functions
|
|
16
|
+
|
|
17
|
+
### 1. `getTheme(threadID)`
|
|
18
|
+
Retrieves all available Facebook Messenger themes.
|
|
19
|
+
|
|
20
|
+
```javascript
|
|
21
|
+
const themes = await api.getTheme(threadID);
|
|
22
|
+
console.log(`Found ${themes.length} themes!`);
|
|
23
|
+
themes.forEach(theme => {
|
|
24
|
+
console.log(`- ${theme.name} (ID: ${theme.id})`);
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**Returns:** Array of theme objects with `id`, `name`, `theme_idx`, and `accessibility_label`.
|
|
29
|
+
|
|
30
|
+
### 2. `getThemeInfo(threadID)`
|
|
31
|
+
Gets the current theme information for a specific thread.
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
const info = await api.getThemeInfo(threadID);
|
|
35
|
+
console.log(`Thread: ${info.threadName}`);
|
|
36
|
+
console.log(`Color: ${info.color}`);
|
|
37
|
+
console.log(`Emoji: ${info.emoji}`);
|
|
38
|
+
console.log(`Theme ID: ${info.theme_id}`);
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**Returns:** Object containing thread name, color, emoji, theme_id, and more.
|
|
42
|
+
|
|
43
|
+
### 3. `createAITheme(prompt)`
|
|
44
|
+
Generates AI-powered custom themes based on a text prompt.
|
|
45
|
+
|
|
46
|
+
```javascript
|
|
47
|
+
try {
|
|
48
|
+
const aiThemes = await api.createAITheme("sunset ocean vibes");
|
|
49
|
+
console.log(`Generated ${aiThemes.length} AI themes!`);
|
|
50
|
+
} catch (e) {
|
|
51
|
+
if (e.code === 'FEATURE_UNAVAILABLE') {
|
|
52
|
+
console.log("AI themes not available for this account");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Important:** AI theme generation is restricted by Facebook to specific accounts/regions. If unavailable for your account, you'll receive a `FEATURE_UNAVAILABLE` error - this is normal and not a bug.
|
|
58
|
+
|
|
59
|
+
### 4. `setThreadThemeMqtt(threadID, themeID)`
|
|
60
|
+
Applies a theme to a conversation thread.
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
const themes = await api.getTheme(threadID);
|
|
64
|
+
const blueTheme = themes.find(t => t.name.includes("Blue"));
|
|
65
|
+
await api.setThreadThemeMqtt(threadID, blueTheme.id);
|
|
66
|
+
console.log("Theme applied!");
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Complete Example
|
|
70
|
+
|
|
71
|
+
See `examples/theme-usage-example.js` for a full working example.
|
|
72
|
+
|
|
73
|
+
## Error Handling
|
|
74
|
+
|
|
75
|
+
### Error 1545012 Fix with Automatic Retry
|
|
76
|
+
|
|
77
|
+
**New in v4.2.4:** Error 1545012 ("Not part of conversation") now includes intelligent retry logic to handle temporary Facebook API glitches.
|
|
78
|
+
|
|
79
|
+
**What changed:**
|
|
80
|
+
- The API now automatically retries up to 3 times with exponential backoff (1s, 2s, 3s)
|
|
81
|
+
- Between retries, it verifies your bot's membership using `getThreadInfo`
|
|
82
|
+
- If the bot is confirmed NOT in the group, it fails immediately
|
|
83
|
+
- If the bot IS in the group, it retries automatically
|
|
84
|
+
|
|
85
|
+
**Why this matters:**
|
|
86
|
+
Facebook often returns error 1545012 even when your bot IS in the group due to:
|
|
87
|
+
- Stale thread membership cache on Facebook's side
|
|
88
|
+
- Recent re-joins not yet propagated
|
|
89
|
+
- Temporary backend hiccups
|
|
90
|
+
|
|
91
|
+
This fix masks transient errors while still catching real "not in group" cases.
|
|
92
|
+
|
|
93
|
+
```javascript
|
|
94
|
+
try {
|
|
95
|
+
await api.sendMessage("Hello", threadID);
|
|
96
|
+
} catch (err) {
|
|
97
|
+
if (err.code === 1545012) {
|
|
98
|
+
if (err.verified) {
|
|
99
|
+
console.log(`Confirmed: Bot is NOT in conversation ${err.threadID}`);
|
|
100
|
+
} else {
|
|
101
|
+
console.log(`Error persisted after ${err.attempts} retries for ${err.threadID}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
The error now includes:
|
|
108
|
+
- `code`: 1545012
|
|
109
|
+
- `threadID`: The thread you tried to message
|
|
110
|
+
- `messageID`: The generated message ID
|
|
111
|
+
- `timestamp`: When the error occurred
|
|
112
|
+
- `attempts`: Number of retry attempts made
|
|
113
|
+
- `verified`: Whether membership was verified via getThreadInfo
|
|
114
|
+
|
|
115
|
+
## Testing
|
|
116
|
+
|
|
117
|
+
Run the comprehensive test suite:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
node test/theme-complete-test.js
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
This validates all theme functionality and clearly distinguishes between working features and Facebook-imposed restrictions.
|
|
124
|
+
|
|
125
|
+
## Notes
|
|
126
|
+
|
|
127
|
+
- **Standard themes**: Always work for all accounts (93+ themes available)
|
|
128
|
+
- **AI themes**: May not be available depending on your Facebook account's region/permissions
|
|
129
|
+
- **MQTT required**: Theme operations require an active MQTT connection via `api.listenMqtt()`
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## See Also
|
|
134
|
+
|
|
135
|
+
- **[API Reference](API_REFERENCE.md)** - Complete documentation of all API methods including theme functions
|
|
136
|
+
- **[Bot Testing](BOT_TESTING.md)** - Test the theme commands with the test bot
|
|
137
|
+
- **[README](README.md)** - Main project documentation
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# NeoKEX-FCA Example Bot
|
|
2
|
+
|
|
3
|
+
A comprehensive test bot demonstrating all API functions of NeoKEX-FCA.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Make sure you have appstate.json in test/ directory
|
|
9
|
+
node examples/test-bot.js
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Available Commands
|
|
13
|
+
|
|
14
|
+
### š Basic Commands
|
|
15
|
+
- `/help` - Show all available commands
|
|
16
|
+
- `/ping` - Test bot response time
|
|
17
|
+
- `/about` - Bot information and stats
|
|
18
|
+
|
|
19
|
+
### š¤ User Information
|
|
20
|
+
- `/me` - Get your user information
|
|
21
|
+
- `/user <name>` - Search for a user
|
|
22
|
+
- `/friends` - List your friends (first 10)
|
|
23
|
+
- `/userid <name>` - Get user ID by name
|
|
24
|
+
|
|
25
|
+
### š¬ Thread Commands
|
|
26
|
+
- `/info` - Get current thread information
|
|
27
|
+
- `/history [limit]` - Get message history (default: 5 messages)
|
|
28
|
+
- `/members` - List all thread members
|
|
29
|
+
- `/photo` - Get thread photo URL
|
|
30
|
+
|
|
31
|
+
### šØ Theme Commands
|
|
32
|
+
- `/themes` - List all available themes
|
|
33
|
+
- `/theme <name>` - Change thread theme by name or ID
|
|
34
|
+
- `/color <hex>` - Change thread color (e.g., `/color #0084ff`)
|
|
35
|
+
- `/aitheme <prompt>` - Generate AI theme (e.g., `/aitheme ocean sunset`)
|
|
36
|
+
|
|
37
|
+
### āļø Thread Settings
|
|
38
|
+
- `/name <new name>` - Change thread name
|
|
39
|
+
- `/emoji <emoji>` - Change thread emoji (e.g., `/emoji š„`)
|
|
40
|
+
- `/nickname @mention <nickname>` - Set someone's nickname
|
|
41
|
+
|
|
42
|
+
### š Messaging Features
|
|
43
|
+
- `/typing` - Send typing indicator
|
|
44
|
+
- `/react <emoji>` - React to your command message
|
|
45
|
+
- `/unsend` - Unsend your command message
|
|
46
|
+
- `/poll <question> | <option1> | <option2>` - Create a poll
|
|
47
|
+
|
|
48
|
+
### š Search Commands
|
|
49
|
+
- `/search <query>` - Search for users
|
|
50
|
+
- `/searchthread <query>` - Search for threads
|
|
51
|
+
|
|
52
|
+
### š Status & Testing
|
|
53
|
+
- `/status` - Bot status and uptime
|
|
54
|
+
- `/test` - Run quick API function tests
|
|
55
|
+
|
|
56
|
+
## Examples
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
/ping
|
|
60
|
+
ā š Pong! Response time: 123ms
|
|
61
|
+
|
|
62
|
+
/search John Doe
|
|
63
|
+
ā š Search results for "John Doe"...
|
|
64
|
+
|
|
65
|
+
/theme love
|
|
66
|
+
ā ā
Theme changed to: love
|
|
67
|
+
|
|
68
|
+
/poll Best pizza? | Pepperoni | Hawaiian | Veggie
|
|
69
|
+
ā Creates a poll with 3 options
|
|
70
|
+
|
|
71
|
+
/test
|
|
72
|
+
ā Runs 4 quick API tests
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Features Tested
|
|
76
|
+
|
|
77
|
+
This bot demonstrates:
|
|
78
|
+
- ā
Message listening (MQTT)
|
|
79
|
+
- ā
User information retrieval
|
|
80
|
+
- ā
Thread management
|
|
81
|
+
- ā
Theme operations (GraphQL + MQTT)
|
|
82
|
+
- ā
Search functionality
|
|
83
|
+
- ā
Messaging features
|
|
84
|
+
- ā
Thread customization
|
|
85
|
+
- ā
Status monitoring
|
|
86
|
+
|
|
87
|
+
## API Functions Coverage
|
|
88
|
+
|
|
89
|
+
**Total Functions Tested: 25+**
|
|
90
|
+
- Authentication & Session
|
|
91
|
+
- Messaging (send, react, unsend)
|
|
92
|
+
- Thread Management (info, history, members)
|
|
93
|
+
- User Search & Info
|
|
94
|
+
- Theme Operations (list, change, AI generation)
|
|
95
|
+
- Thread Settings (name, emoji, nickname)
|
|
96
|
+
- Typing indicators
|
|
97
|
+
- Polls
|
|
98
|
+
- Search operations
|
|
99
|
+
|
|
100
|
+
## Notes
|
|
101
|
+
|
|
102
|
+
- All commands use `/` prefix
|
|
103
|
+
- Some commands require MQTT connection
|
|
104
|
+
- Theme changes require MQTT to be active
|
|
105
|
+
- Error handling included for all commands
|
|
106
|
+
- Responds with helpful error messages
|
|
107
|
+
|
|
108
|
+
## Troubleshooting
|
|
109
|
+
|
|
110
|
+
**Bot not responding?**
|
|
111
|
+
- Check MQTT connection status
|
|
112
|
+
- Verify appstate.json is valid
|
|
113
|
+
- Ensure bot has permission in the thread
|
|
114
|
+
|
|
115
|
+
**Commands failing?**
|
|
116
|
+
- Use `/status` to check bot health
|
|
117
|
+
- Use `/test` to verify API functions
|
|
118
|
+
- Check console for error messages
|
|
119
|
+
|
|
120
|
+
## Architecture
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
test-bot.js
|
|
124
|
+
āāā Login with appstate
|
|
125
|
+
āāā Initialize MQTT listener
|
|
126
|
+
āāā Parse commands (prefix: /)
|
|
127
|
+
āāā Route to command handlers
|
|
128
|
+
āāā Error handling & logging
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Built with NeoKEX-FCA v4.4.4 - 98.2% API success rate
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Theme Generation and Application Example
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* node examples/apply-ai-theme.js "theme prompt" "thread_id"
|
|
6
|
+
*
|
|
7
|
+
* Example:
|
|
8
|
+
* node examples/apply-ai-theme.js "vibrant purple pink ocean sunset" "123456789"
|
|
9
|
+
*
|
|
10
|
+
* Note: AI theme generation requires Facebook account-level access.
|
|
11
|
+
* If unavailable, use standard themes via api.getTheme() instead.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const fs = require("fs");
|
|
15
|
+
const { login } = require("../index");
|
|
16
|
+
|
|
17
|
+
const APPSTATE_PATH = "appstate.json";
|
|
18
|
+
const AI_THEME_PROMPT = process.argv[2] || "vibrant purple pink ocean sunset";
|
|
19
|
+
// Replace with your actual thread ID (find it in messenger URL or use api.getThreadList())
|
|
20
|
+
const THREAD_ID = process.argv[3] || "YOUR_THREAD_ID_HERE";
|
|
21
|
+
|
|
22
|
+
if (THREAD_ID === "YOUR_THREAD_ID_HERE") {
|
|
23
|
+
console.error("ā Please provide a thread ID:");
|
|
24
|
+
console.error(' node examples/apply-ai-theme.js "theme prompt" "thread_id"');
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (!fs.existsSync(APPSTATE_PATH)) {
|
|
29
|
+
console.error("ā appstate.json is required.");
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const credentials = { appState: JSON.parse(fs.readFileSync(APPSTATE_PATH, "utf8")) };
|
|
34
|
+
|
|
35
|
+
console.log("š Logging in...");
|
|
36
|
+
|
|
37
|
+
login(credentials, {
|
|
38
|
+
online: true,
|
|
39
|
+
updatePresence: true,
|
|
40
|
+
selfListen: false
|
|
41
|
+
}, async (err, api) => {
|
|
42
|
+
if (err) {
|
|
43
|
+
console.error("ā LOGIN ERROR:", err);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
console.log(`ā
Logged in as: ${api.getCurrentUserID()}`);
|
|
48
|
+
|
|
49
|
+
console.log("š Starting MQTT listener...");
|
|
50
|
+
api.listenMqtt((err, event) => {
|
|
51
|
+
if (err) console.error("MQTT Error:", err);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
55
|
+
console.log("ā
MQTT connection established\n");
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
console.log("āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā");
|
|
59
|
+
console.log(`šØ AI THEME GENERATION AND APPLICATION`);
|
|
60
|
+
console.log("āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n");
|
|
61
|
+
|
|
62
|
+
console.log(`š Prompt: "${AI_THEME_PROMPT}"`);
|
|
63
|
+
|
|
64
|
+
console.log("\nšØ Step 1: Generating AI theme...");
|
|
65
|
+
const aiThemes = await api.createAITheme(AI_THEME_PROMPT);
|
|
66
|
+
|
|
67
|
+
if (!aiThemes || aiThemes.length === 0) {
|
|
68
|
+
console.error("ā No themes generated!");
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
console.log(`ā
AI theme generated!`);
|
|
73
|
+
console.log(` Theme ID: ${aiThemes[0].id}`);
|
|
74
|
+
console.log(` Name: ${aiThemes[0].accessibility_label || AI_THEME_PROMPT}`);
|
|
75
|
+
|
|
76
|
+
console.log("\nā³ Waiting 2 seconds before applying...");
|
|
77
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
78
|
+
|
|
79
|
+
console.log("\nš Step 2: Applying theme to thread...");
|
|
80
|
+
console.log(` Thread ID: ${THREAD_ID}`);
|
|
81
|
+
console.log(` Theme ID: ${aiThemes[0].id}`);
|
|
82
|
+
|
|
83
|
+
// Apply using callback to catch errors
|
|
84
|
+
await new Promise((resolve, reject) => {
|
|
85
|
+
api.setThreadThemeMqtt(THREAD_ID, aiThemes[0].id, (err) => {
|
|
86
|
+
if (err) {
|
|
87
|
+
console.error("ā Error in setThreadThemeMqtt:", err);
|
|
88
|
+
reject(err);
|
|
89
|
+
} else {
|
|
90
|
+
console.log("ā
MQTT publish completed");
|
|
91
|
+
resolve();
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
console.log("\nā³ Waiting 3 seconds for theme to sync...");
|
|
97
|
+
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
98
|
+
|
|
99
|
+
console.log("\nš Step 3: Verifying theme was applied...");
|
|
100
|
+
const themeInfo = await api.getThemeInfo(THREAD_ID);
|
|
101
|
+
|
|
102
|
+
console.log("\nāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā");
|
|
103
|
+
console.log("š VERIFICATION RESULTS");
|
|
104
|
+
console.log("āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā");
|
|
105
|
+
console.log(`Thread Name: ${themeInfo.threadName || 'Unnamed'}`);
|
|
106
|
+
console.log(`Current Color: ${themeInfo.color || 'Default'}`);
|
|
107
|
+
console.log(`Theme ID: ${themeInfo.theme_id || 'None'}`);
|
|
108
|
+
console.log(`Expected Theme ID: ${aiThemes[0].id}`);
|
|
109
|
+
console.log(`Match: ${themeInfo.theme_id === aiThemes[0].id ? 'ā
YES' : 'ā NO'}`);
|
|
110
|
+
|
|
111
|
+
if (themeInfo.theme_id === aiThemes[0].id) {
|
|
112
|
+
console.log("\nš SUCCESS! AI theme applied successfully!");
|
|
113
|
+
} else {
|
|
114
|
+
console.log("\nā ļø Theme generated but not applied. Theme ID mismatch.");
|
|
115
|
+
console.log("This might be a timing issue or MQTT delivery problem.");
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
console.log("āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n");
|
|
119
|
+
|
|
120
|
+
process.exit(0);
|
|
121
|
+
|
|
122
|
+
} catch (error) {
|
|
123
|
+
console.error("\nā Error occurred:", error.message || error);
|
|
124
|
+
console.error("Stack:", error.stack);
|
|
125
|
+
process.exit(1);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check Current Thread Theme Example
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* node examples/check-current-theme.js "thread_id"
|
|
6
|
+
*
|
|
7
|
+
* Example:
|
|
8
|
+
* node examples/check-current-theme.js "123456789"
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const fs = require("fs");
|
|
12
|
+
const { login } = require("../index");
|
|
13
|
+
|
|
14
|
+
const APPSTATE_PATH = "appstate.json";
|
|
15
|
+
// Replace with your actual thread ID (find it in messenger URL or use api.getThreadList())
|
|
16
|
+
const THREAD_ID = process.argv[2] || "YOUR_THREAD_ID_HERE";
|
|
17
|
+
|
|
18
|
+
if (THREAD_ID === "YOUR_THREAD_ID_HERE") {
|
|
19
|
+
console.error("ā Please provide a thread ID:");
|
|
20
|
+
console.error(' node examples/check-current-theme.js "thread_id"');
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!fs.existsSync(APPSTATE_PATH)) {
|
|
25
|
+
console.error("ā appstate.json is required.");
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const credentials = { appState: JSON.parse(fs.readFileSync(APPSTATE_PATH, "utf8")) };
|
|
30
|
+
|
|
31
|
+
console.log("š Logging in...");
|
|
32
|
+
|
|
33
|
+
login(credentials, {
|
|
34
|
+
online: true,
|
|
35
|
+
updatePresence: true,
|
|
36
|
+
selfListen: false
|
|
37
|
+
}, async (err, api) => {
|
|
38
|
+
if (err) {
|
|
39
|
+
console.error("ā LOGIN ERROR:", err);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
console.log(`ā
Logged in as: ${api.getCurrentUserID()}`);
|
|
44
|
+
|
|
45
|
+
console.log("š Starting MQTT listener...");
|
|
46
|
+
api.listenMqtt((err, event) => {
|
|
47
|
+
if (err) console.error("MQTT Error:", err);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
51
|
+
console.log("ā
MQTT connection established\n");
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
console.log("š Checking current theme for thread:", THREAD_ID);
|
|
55
|
+
const themeInfo = await api.getThemeInfo(THREAD_ID);
|
|
56
|
+
|
|
57
|
+
console.log("\nāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā");
|
|
58
|
+
console.log("šØ CURRENT THREAD THEME INFO");
|
|
59
|
+
console.log("āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā");
|
|
60
|
+
console.log(JSON.stringify(themeInfo, null, 2));
|
|
61
|
+
console.log("āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n");
|
|
62
|
+
|
|
63
|
+
console.log("Thread Name:", themeInfo.threadName || 'Unnamed');
|
|
64
|
+
console.log("Current Color:", themeInfo.color || 'Default');
|
|
65
|
+
console.log("Current Emoji:", themeInfo.emoji || 'None');
|
|
66
|
+
console.log("Theme ID:", themeInfo.theme_id || 'None/Default');
|
|
67
|
+
|
|
68
|
+
process.exit(0);
|
|
69
|
+
|
|
70
|
+
} catch (error) {
|
|
71
|
+
console.error("\nā Error:", error.message || error);
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple NeoKEX-FCA Bot Example
|
|
3
|
+
*
|
|
4
|
+
* A minimal bot demonstrating basic functionality:
|
|
5
|
+
* - Auto-reply to mentions
|
|
6
|
+
* - Command handling
|
|
7
|
+
* - Basic info commands
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const { login } = require('../index');
|
|
11
|
+
const fs = require('fs');
|
|
12
|
+
const path = require('path');
|
|
13
|
+
|
|
14
|
+
const APPSTATE_PATH = path.join(__dirname, '../test/appstate.json');
|
|
15
|
+
const appState = JSON.parse(fs.readFileSync(APPSTATE_PATH, 'utf8'));
|
|
16
|
+
|
|
17
|
+
console.log('š¤ Simple Bot Starting...\n');
|
|
18
|
+
|
|
19
|
+
login({ appState }, (err, api) => {
|
|
20
|
+
if (err) {
|
|
21
|
+
console.error('ā Login failed:', err);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
console.log('ā
Bot is online!');
|
|
26
|
+
const botID = api.getCurrentUserID();
|
|
27
|
+
|
|
28
|
+
api.listenMqtt((err, event) => {
|
|
29
|
+
if (err) return console.error('Error:', err);
|
|
30
|
+
|
|
31
|
+
if (event.type === 'message' && event.body) {
|
|
32
|
+
const { threadID, senderID, body } = event;
|
|
33
|
+
|
|
34
|
+
// Ignore own messages
|
|
35
|
+
if (senderID === botID) return;
|
|
36
|
+
|
|
37
|
+
// Auto-reply to mentions
|
|
38
|
+
if (event.mentions && event.mentions[botID]) {
|
|
39
|
+
api.sendMessage('š You mentioned me! Type "!help" for commands.', threadID);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Command handling
|
|
44
|
+
if (body.startsWith('!')) {
|
|
45
|
+
handleCommand(api, body.substring(1).trim(), threadID, senderID);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
console.log('ā
Listening for messages...\n');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
async function handleCommand(api, cmd, threadID, senderID) {
|
|
54
|
+
const [command, ...args] = cmd.split(' ');
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
switch (command.toLowerCase()) {
|
|
58
|
+
case 'help':
|
|
59
|
+
await api.sendMessage(`š¤ Simple Bot Commands
|
|
60
|
+
|
|
61
|
+
!help - Show this menu
|
|
62
|
+
!ping - Check if bot is alive
|
|
63
|
+
!time - Current time
|
|
64
|
+
!info - Thread information
|
|
65
|
+
!me - Your user info
|
|
66
|
+
!theme <name> - Change theme
|
|
67
|
+
|
|
68
|
+
Example: !theme love`, threadID);
|
|
69
|
+
break;
|
|
70
|
+
|
|
71
|
+
case 'ping':
|
|
72
|
+
await api.sendMessage('š Pong! Bot is alive!', threadID);
|
|
73
|
+
break;
|
|
74
|
+
|
|
75
|
+
case 'time':
|
|
76
|
+
await api.sendMessage(`ā° ${new Date().toLocaleString()}`, threadID);
|
|
77
|
+
break;
|
|
78
|
+
|
|
79
|
+
case 'info':
|
|
80
|
+
const info = await api.getThreadInfo(threadID);
|
|
81
|
+
await api.sendMessage(`š¬ Thread: ${info.threadName || 'Unnamed'}
|
|
82
|
+
š„ Members: ${info.participantIDs.length}
|
|
83
|
+
š¬ Messages: ${info.messageCount || 'Unknown'}`, threadID);
|
|
84
|
+
break;
|
|
85
|
+
|
|
86
|
+
case 'me':
|
|
87
|
+
const userInfo = await api.getUserInfo(senderID);
|
|
88
|
+
const user = userInfo[senderID];
|
|
89
|
+
await api.sendMessage(`š¤ ${user.name}
|
|
90
|
+
š ${senderID}`, threadID);
|
|
91
|
+
break;
|
|
92
|
+
|
|
93
|
+
case 'theme':
|
|
94
|
+
if (args.length === 0) {
|
|
95
|
+
await api.sendMessage('ā Usage: !theme <name>', threadID);
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
await api.theme(args.join(' '), threadID);
|
|
99
|
+
await api.sendMessage(`ā
Theme changed!`, threadID);
|
|
100
|
+
break;
|
|
101
|
+
|
|
102
|
+
default:
|
|
103
|
+
await api.sendMessage(`ā Unknown command. Type !help for help.`, threadID);
|
|
104
|
+
}
|
|
105
|
+
} catch (error) {
|
|
106
|
+
console.error('Command error:', error);
|
|
107
|
+
await api.sendMessage(`ā Error: ${error.message}`, threadID);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
process.on('SIGINT', () => {
|
|
112
|
+
console.log('\nš Shutting down...');
|
|
113
|
+
process.exit(0);
|
|
114
|
+
});
|