@c4t4/heyamigo 0.8.2 → 0.8.3

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.
@@ -24,13 +24,41 @@ export function detectMediaType(msg) {
24
24
  return null;
25
25
  return MEDIA_TYPES[type] ?? null;
26
26
  }
27
+ // Baileys' extensionForMediaMessage throws when the media's mimetype is
28
+ // undefined — happens on some forwarded documents (notably PDFs shared in
29
+ // contexts that strip metadata). Fall back to the filename's extension,
30
+ // then to .bin. Never throws.
31
+ function resolveMediaExtension(msg) {
32
+ try {
33
+ const ext = extensionForMediaMessage(msg.message);
34
+ if (ext)
35
+ return ext;
36
+ }
37
+ catch {
38
+ // baileys tripped on missing mimetype — try fileName instead
39
+ }
40
+ const content = msg.message;
41
+ if (content) {
42
+ const type = getContentType(content);
43
+ if (type) {
44
+ const mediaMsg = content[type];
45
+ const fileName = mediaMsg?.fileName;
46
+ if (fileName) {
47
+ const m = fileName.match(/\.([a-zA-Z0-9]+)$/);
48
+ if (m && m[1])
49
+ return m[1].toLowerCase();
50
+ }
51
+ }
52
+ }
53
+ return 'bin';
54
+ }
27
55
  export async function downloadAndSave(msg, jid) {
28
56
  const mediaType = detectMediaType(msg);
29
57
  if (!mediaType)
30
58
  return null;
31
59
  try {
32
60
  const buffer = await downloadMediaMessage(msg, 'buffer', {});
33
- const ext = extensionForMediaMessage(msg.message) || 'bin';
61
+ const ext = resolveMediaExtension(msg);
34
62
  const id = msg.key.id || `${Date.now()}`;
35
63
  const dir = mediaDir(jid);
36
64
  await mkdir(dir, { recursive: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@c4t4/heyamigo",
3
- "version": "0.8.2",
3
+ "version": "0.8.3",
4
4
  "description": "WhatsApp AI bot powered by Claude with long-term memory, browser control, and role-based access",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",