@manybot/manybot 4.2.0 → 4.3.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/README.md +1 -1
- package/package.json +1 -1
- package/src/kernel/pluginApi.js +71 -2
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|

|
|
4
4
|
|
|
5
|
-

|
|
6
6
|

|
|
7
7
|

|
|
8
8
|

|
package/package.json
CHANGED
package/src/kernel/pluginApi.js
CHANGED
|
@@ -136,6 +136,70 @@ const log = {
|
|
|
136
136
|
success: (...a) => logger.success(...a),
|
|
137
137
|
};
|
|
138
138
|
|
|
139
|
+
// -- Contact API --------------------------------------------------------------
|
|
140
|
+
|
|
141
|
+
function buildContactsApi(client) {
|
|
142
|
+
return {
|
|
143
|
+
/**
|
|
144
|
+
* Get a normalized Contact object by ID.
|
|
145
|
+
* @param {string} contactId — serialized ID (e.g. "5511999999999@c.us")
|
|
146
|
+
* @returns {Promise<object|null>}
|
|
147
|
+
*/
|
|
148
|
+
async get(contactId) {
|
|
149
|
+
try {
|
|
150
|
+
const c = await client.getContactById(contactId);
|
|
151
|
+
return {
|
|
152
|
+
id: c.id._serialized,
|
|
153
|
+
number: c.number,
|
|
154
|
+
pushname: c.pushname ?? null,
|
|
155
|
+
name: c.name ?? null,
|
|
156
|
+
shortName: c.shortName ?? null,
|
|
157
|
+
isBusiness: c.isBusiness,
|
|
158
|
+
isEnterprise: c.isEnterprise,
|
|
159
|
+
isBlocked: c.isBlocked,
|
|
160
|
+
isMe: c.isMe,
|
|
161
|
+
isMyContact: c.isMyContact,
|
|
162
|
+
isWAContact: c.isWAContact,
|
|
163
|
+
isUser: c.isUser,
|
|
164
|
+
isGroup: c.isGroup,
|
|
165
|
+
};
|
|
166
|
+
} catch {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Get the profile picture URL of a contact.
|
|
173
|
+
* Uses Contact#getProfilePicUrl() — respects privacy settings.
|
|
174
|
+
* @param {string} contactId
|
|
175
|
+
* @returns {Promise<string|null>}
|
|
176
|
+
*/
|
|
177
|
+
async getProfilePicUrl(contactId) {
|
|
178
|
+
try {
|
|
179
|
+
const c = await client.getContactById(contactId);
|
|
180
|
+
return await c.getProfilePicUrl();
|
|
181
|
+
} catch {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Get the "about" text of a contact.
|
|
188
|
+
* Returns null if privacy settings block access.
|
|
189
|
+
* @param {string} contactId
|
|
190
|
+
* @returns {Promise<string|null>}
|
|
191
|
+
*/
|
|
192
|
+
async getAbout(contactId) {
|
|
193
|
+
try {
|
|
194
|
+
const c = await client.getContactById(contactId);
|
|
195
|
+
return await c.getAbout();
|
|
196
|
+
} catch {
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
139
203
|
// ── Internal media helpers ───────────────────────────────────────────────────
|
|
140
204
|
|
|
141
205
|
function mediaFromSource(source, mimetype = "image/webp") {
|
|
@@ -162,9 +226,9 @@ function makeSender(target) {
|
|
|
162
226
|
const media = MessageMedia.fromFilePath(filePath);
|
|
163
227
|
return target.sendMessage(media, { caption });
|
|
164
228
|
},
|
|
165
|
-
async audio(filePath) {
|
|
229
|
+
async audio(filePath, { asVoice = true } = {}) {
|
|
166
230
|
const media = MessageMedia.fromFilePath(filePath);
|
|
167
|
-
return target.sendMessage(media, { sendAudioAsVoice:
|
|
231
|
+
return target.sendMessage(media, { sendAudioAsVoice: asVoice });
|
|
168
232
|
},
|
|
169
233
|
async sticker(source) {
|
|
170
234
|
const media = mediaFromSource(source);
|
|
@@ -217,6 +281,7 @@ function buildBaseApi(client, pluginRegistry) {
|
|
|
217
281
|
download: buildDownloadApi(),
|
|
218
282
|
plugins: buildPluginsApi(pluginRegistry),
|
|
219
283
|
botId: client.info?.wid?._serialized ?? null,
|
|
284
|
+
contacts: buildContactsApi(),
|
|
220
285
|
...buildSendToApi(client),
|
|
221
286
|
};
|
|
222
287
|
}
|
|
@@ -294,6 +359,10 @@ export function buildApi({ msg, chat, client, pluginRegistry }) {
|
|
|
294
359
|
async react(emoji) {
|
|
295
360
|
return msg.react(emoji);
|
|
296
361
|
},
|
|
362
|
+
|
|
363
|
+
async getContact() {
|
|
364
|
+
return msg.getContact();
|
|
365
|
+
},
|
|
297
366
|
},
|
|
298
367
|
|
|
299
368
|
// ── chat ─────────────────────────────────────────────────
|