planvortex 0.19.0 → 0.20.0

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.
@@ -991,7 +991,7 @@ interface paths {
991
991
  * Re-enable a disconnected account
992
992
  * @description Brings back an account that was removed, without going through the authorization again — as long as its stored token still works.
993
993
  *
994
- * It takes a **slot of the plan**, so it fails with error 706 when the organization is already at its account limit. It also turns the network's webhooks back on, on any plan but the free one.
994
+ * It takes a **slot of the plan**, so it fails with error 706 when the organization is already at its account limit. It also turns the network's webhooks back on, on any plan but the free one. On the free plan a `whatsapp` account that is not active cannot be enabled (error 516), because its chat and its templates need a paid plan. One that is already active can still be reconnected.
995
995
  *
996
996
  * **On `telegram` you normally never call this.** That network's accounts are born active — there is no authorization return in which to choose them, so PlanVortex takes the slot when the bot is added to the channel. The one case left is a channel that arrived while the plan was full: it stays off until a slot frees up, and this is what turns it on.
997
997
  *
@@ -1017,6 +1017,10 @@ interface paths {
1017
1017
  *
1018
1018
  * The shape of a template is the network's own: PlanVortex does not normalise it.
1019
1019
  *
1020
+ * **A rejected template says why.** WhatsApp templates carry `rejected_reason` (`INVALID_FORMAT`, `PROMOTIONAL`, `TAG_CONTENT_MISMATCH`...) next to their `status`, as WhatsApp sends it.
1021
+ *
1022
+ * **`health` says whether the account can start conversations at all.** A template is only needed outside the 24-hour window, which is exactly what a failed payment method or an unverified business blocks, and neither of them fails when you create or approve a template: the message is simply never delivered. `health` is WhatsApp's own status for the phone number, reduced to `can_send_message` (`AVAILABLE`, `LIMITED`, `BLOCKED`), the `issues` behind it with WhatsApp's code (141006 = payment method, 141010 = business not verified) and `notes`. When it can't be read the field is absent, which means unknown, not healthy.
1023
+ *
1020
1024
  * **WhatsApp only.** No other network implements message templates: asking any of them returns HTTP 500 with `code: 500` (an unhandled server error), not the 1502 you would expect. Check `messages` in `GET /social_capabilities` and that the account is WhatsApp before calling.
1021
1025
  */
1022
1026
  get: operations["getMessageTemplates"];
@@ -1027,6 +1031,10 @@ interface paths {
1027
1031
  *
1028
1032
  * **Approval is not immediate.** The template comes back in a pending state and only becomes usable when the network approves it, which takes minutes or hours and can be refused.
1029
1033
  *
1034
+ * **WhatsApp templates are checked before they leave.** WhatsApp rejects a badly formatted template in the same second with `INVALID_FORMAT` and no explanation, so PlanVortex checks the rules it documents first and answers **1513** with `data.field` and `data.reason`: `invalid_name` (lowercase letters, numbers and underscores only), `missing_language`, `missing_body`, `body_too_long` (1,024 characters), `malformed_variable`, `variables_not_sequential`, `variable_at_edge` (the text can't start or end with a variable), `adjacent_variables` and `missing_examples`. **A body with variables needs one example per variable** in `example.body_text`, as in the example below.
1035
+ *
1036
+ * If WhatsApp refuses the template when it is created (a language it doesn't have, a name already in use), the answer is **1514** with WhatsApp's own `code`, `subcode` and `message` in `data`.
1037
+ *
1030
1038
  * **WhatsApp only.** No other network implements message templates: asking any of them returns HTTP 500 with `code: 500` (an unhandled server error), not the 1502 you would expect. Check `messages` in `GET /social_capabilities` and that the account is WhatsApp before calling.
1031
1039
  */
1032
1040
  post: operations["createMessageTemplate"];
@@ -1097,6 +1105,35 @@ interface paths {
1097
1105
  patch?: never;
1098
1106
  trace?: never;
1099
1107
  };
1108
+ "/organizations/{id_organization}/accounts/{id_account}/messages/{id_message}/files/{index}": {
1109
+ parameters: {
1110
+ query?: never;
1111
+ header?: never;
1112
+ path?: never;
1113
+ cookie?: never;
1114
+ };
1115
+ /**
1116
+ * One file of a message, fetched from the network
1117
+ * @description Files that arrive in a message (a photo, a video, a voice note, a document, a sticker) **are not stored by PlanVortex**: they stay on the network, and `message_options.files_urls` says where each one is.
1118
+ *
1119
+ * • **With `url`** (Instagram and Messenger): Meta's own CDN link. It works until Meta expires it.
1120
+ * • **Without `url`** (every WhatsApp file): WhatsApp only hands a file over with the account's token, through a link that lasts five minutes, so there is no link to give you.
1121
+ *
1122
+ * Either way, this endpoint asks the network for the file now and streams it back without keeping a copy. `index` is the file's position in `files_urls`. `message_options.files` holds only the files **you** sent from PlanVortex, which are uploads.
1123
+ *
1124
+ * **The network decides how long a file lives.** WhatsApp lets go of a file 7 days after it arrived, and Meta drops one when the message or the story is deleted. After that the answer is **1515**, with `data.social_network`; on a number that also runs the WhatsApp Business app, the file is still there. **1516** means the message is not from this account, or has no file at that position.
1125
+ *
1126
+ * Images, videos and audio come back `inline`. Anything else (a PDF, a spreadsheet, an HTML file, an SVG) comes back as an `attachment`: someone outside the business sent it, so don't render it inside your own pages.
1127
+ */
1128
+ get: operations["getMessageFile"];
1129
+ put?: never;
1130
+ post?: never;
1131
+ delete?: never;
1132
+ options?: never;
1133
+ head?: never;
1134
+ patch?: never;
1135
+ trace?: never;
1136
+ };
1100
1137
  "/organizations/{id_organization}/accounts/{id_account}/metric_list": {
1101
1138
  parameters: {
1102
1139
  query?: never;
@@ -1419,6 +1456,40 @@ interface paths {
1419
1456
  patch?: never;
1420
1457
  trace?: never;
1421
1458
  };
1459
+ "/organizations/{id_organization}/comments/{id_comment}/files/{index}": {
1460
+ parameters: {
1461
+ query?: never;
1462
+ header?: never;
1463
+ path?: never;
1464
+ cookie?: never;
1465
+ };
1466
+ /**
1467
+ * One file of a comment, fetched from the network
1468
+ * @description Files in a comment (a photo, a GIF, a sticker, a video) **are not stored by PlanVortex**: they stay on the network, and the comment's `files_urls` says where each one is. This endpoint asks the network for the file now and streams it back without keeping a copy. `index` is the file's position in `files_urls`.
1469
+ *
1470
+ * You need it when a file has no `url`, or when its `url` stopped loading:
1471
+ *
1472
+ * • **LinkedIn** gives only the image's id, never a link.
1473
+ * • **Telegram**'s download link carries the bot's token, so it never leaves PlanVortex. A bot can only download up to 20 MB: past that the answer is **1515** with `data.reason: "too_big"`, and the file is only visible in Telegram.
1474
+ * • **Bluesky** videos are an HLS playlist that browsers other than Safari do not play; this returns the video file itself.
1475
+ * • **Facebook, Threads and Discord** links expire; this reads the comment again and returns the file behind a fresh link.
1476
+ * • **X** links do not expire, and reading a post again costs money, so X is not re-read: if its `url` no longer loads, the post was deleted and the answer is **1515**.
1477
+ *
1478
+ * **1515** means the network no longer has the file (`data.social_network`), and **2602** that the comment has no file at that position. A comment of another organization is **1102**.
1479
+ *
1480
+ * Images, videos and audio come back `inline`. Anything else comes back as an `attachment`: someone outside the business posted it, so don't render it inside your own pages.
1481
+ *
1482
+ * Requires the `comments:read` permission (`client_organization_comments:read` for apps) and a paid plan.
1483
+ */
1484
+ get: operations["getCommentFile"];
1485
+ put?: never;
1486
+ post?: never;
1487
+ delete?: never;
1488
+ options?: never;
1489
+ head?: never;
1490
+ patch?: never;
1491
+ trace?: never;
1492
+ };
1422
1493
  "/organizations/{id_organization}/comments/{id_comment}/replies": {
1423
1494
  parameters: {
1424
1495
  query?: never;
@@ -1490,6 +1561,8 @@ interface paths {
1490
1561
  *
1491
1562
  * **A network that cannot produce a link simply does not appear.** That is a legitimate answer, not a failure: it is what happens with `discord` in an organization that has not saved its own bot credentials yet (see `PUT /organizations/{id_organization}/social_credentials/{social_network}`).
1492
1563
  *
1564
+ * **On the free plan `whatsapp` does not appear either**, unless the organization already has an active WhatsApp account, which has to stay reconnectable. Its chat and its templates need a paid plan, so enabling a new account answers error 516. Asking for it by name gets you an empty list, not an error.
1565
+ *
1493
1566
  * **An app cannot call this.** Connecting a social account is an OAuth flow with a person in front of it, so this endpoint only accepts a user token or a temporal connect token; with app credentials it answers error 519. The way an integration does it is to issue a temporal connect token with `GET /organizations/{id_organization}/temporal_connect_token` and hand it to its end user.
1494
1567
  *
1495
1568
  * **Read `authorization`, not `link`.** Almost every network is `redirect` and you send the person to `link`. Two are not, and neither of them fails visibly if you treat it as one:
@@ -2335,7 +2408,7 @@ interface paths {
2335
2408
  *
2336
2409
  * **It connects once.** As soon as an `account-connect` succeeds, the token stops being able to connect anything else and answers error 543; the `enable` calls that finish that same connection keep working until it expires. Issue a new one per connection — they are free and immediate.
2337
2410
  *
2338
- * **If you pass `social_network`, the token is bound to that network** and will not connect any other (error 544). Leave it out to let the person pick.
2411
+ * **If you pass `social_network`, the token is bound to that network** and will not connect any other (error 544). Leave it out to let the person pick. On the free plan, asking for `whatsapp` answers error 516 unless the organization already has an active WhatsApp account to reconnect: its chat and its templates need a paid plan.
2339
2412
  *
2340
2413
  * **Or show the account picker yourself** with `account_selection=integrator`. By default PlanVortex shows the screen where the person picks which accounts to enable, and only then sends them to your `redirect_uri`. In this mode that screen is yours:
2341
2414
  *
@@ -3771,6 +3844,12 @@ interface components {
3771
3844
  * • A Telegram comment lives in a **different chat** from the post it answers (the channel's linked discussion group), so it needs two ids at once and travels as `{thread}/{message}`: replying wants the first, deleting wants the second.
3772
3845
  */
3773
3846
  external_id: string;
3847
+ /**
3848
+ * @description The comment's files: a photo, a GIF, a sticker, a video. **PlanVortex does not store them** (see `SocialFileUrl`): open `url` when there is one, and when there is not, or it stops loading, fetch the file with `GET /organizations/{id_organization}/comments/{id_comment}/files/{index}`.
3849
+ *
3850
+ * Facebook, Threads, LinkedIn, X, Bluesky, Discord and Telegram give a comment's files, and on Google Business they are the photos and videos of a review. Instagram and YouTube do not expose them in their APIs, so there the list is always empty. A comment that is only a photo has an empty `text` and one file here.
3851
+ */
3852
+ files_urls?: components["schemas"]["SocialFileUrl"][];
3774
3853
  /** @description Hidden on the network. A hidden comment is never swept as deleted: on YouTube, hiding one makes the API stop returning it forever, and without that exception hiding would be indistinguishable from deleting. */
3775
3854
  hidden: boolean;
3776
3855
  /**
@@ -3807,7 +3886,7 @@ interface components {
3807
3886
  /** @description Absent when the network does not publish it — not zero */
3808
3887
  reply_count?: number;
3809
3888
  social_network: components["schemas"]["CommentsCommentNetworkName"];
3810
- /** @description **May legitimately be empty.** A stars-only review carries no text at all, so render `rating` alongside it and never assume a blank comment is a loading failure. */
3889
+ /** @description **May legitimately be empty.** A stars-only review carries no text at all, and a comment can be only a photo or a sticker (see `files_urls`), so render `rating` and the files alongside it and never assume a blank comment is a loading failure. */
3811
3890
  text: string;
3812
3891
  };
3813
3892
  /** @description What one network lets you do to a comment. Four booleans and never fewer: an absent key would be indistinguishable from an oversight. */
@@ -4243,7 +4322,7 @@ interface components {
4243
4322
  * The catalogue grows with the product, so treat an unknown `code` as a generic failure instead of rejecting it.
4244
4323
  */
4245
4324
  Error: {
4246
- /** @description PlanVortex error code. Ranges: 500-554 auth, tokens, client apps and connect sessions · 601-612 user · 700-716 social accounts · 800-810 files · 900-996 publications · 1000-1003 general · 1100-1111 organizations · 1200-1207 roles · 1300-1308 client plan · 1400-1408 organization plan · 1500-1512 messaging · 1600-1601 contacts · 1900-1906 payments · 2000-2099 products · 2100-2199 AI plans · 2200-2299 integrations · 2500-2599 publication fields, the ones that no longer fit in 900-996 (visibility, made for kids, TikTok's interactions and commercial content) · 2600-2699 comments, the ones that no longer fit in 945-948. */
4325
+ /** @description PlanVortex error code. Ranges: 500-554 auth, tokens, client apps and connect sessions · 601-612 user · 700-716 social accounts · 800-810 files · 900-996 publications · 1000-1003 general · 1100-1111 organizations · 1200-1207 roles · 1300-1309 client plan · 1400-1408 organization plan · 1500-1516 messaging · 1600-1601 contacts · 1900-1906 payments · 2000-2099 products · 2100-2199 AI plans · 2200-2299 integrations · 2500-2599 publication fields, the ones that no longer fit in 900-996 (visibility, made for kids, TikTok's interactions and commercial content) · 2600-2699 comments, the ones that no longer fit in 945-948. */
4247
4326
  code: number;
4248
4327
  /** @description Extra context attached to the error, when there is any. */
4249
4328
  data?: {
@@ -4508,11 +4587,8 @@ interface components {
4508
4587
  MessageOptions: {
4509
4588
  /** @description The uploads attached to the message. **Populated** wherever the message itself is: the messages list and webhook deliveries carry whole uploads, everything else carries their identifiers. Handle both. */
4510
4589
  files: (string | components["schemas"]["Upload"])[];
4511
- /** @description Files already hosted somewhere else. Filled in by PlanVortex when a message arrives from the network. */
4512
- files_urls: {
4513
- mime_type?: string;
4514
- url?: string;
4515
- }[];
4590
+ /** @description Files that arrived with the message from the network. PlanVortex does not store them: they live on the network (see `SocialFileUrl`). On WhatsApp every file is here, photos and videos included, and none has a `url`. */
4591
+ files_urls: components["schemas"]["SocialFileUrl"][];
4516
4592
  /** @description Meta cards, for `elements_message` and `button_message`. */
4517
4593
  metaElements?: {
4518
4594
  [key: string]: unknown;
@@ -5372,6 +5448,24 @@ interface components {
5372
5448
  */
5373
5449
  verified_date?: string;
5374
5450
  };
5451
+ /**
5452
+ * @description A file that arrived from the network: a photo, a video, a voice note, a document or a sticker in a private message or a comment. **PlanVortex does not store it**: it stays on the network, and this says where to find it.
5453
+ *
5454
+ * • **With `url`**: the network's own link, which your page can load directly. On Instagram, Messenger, Facebook, Threads and Discord it **expires**; on X and Bluesky it does not.
5455
+ * • **Without `url`**: the network only hands the file over with a token that never leaves PlanVortex (WhatsApp, and Telegram, whose download link carries the bot's token), or gives only an identifier (LinkedIn, a Bluesky video). Fetch it through the API.
5456
+ *
5457
+ * Either way, when `url` is missing or stops loading, fetch the file with `GET .../messages/{id_message}/files/{index}` or `GET .../comments/{id_comment}/files/{index}`, where `index` is its position in the list. PlanVortex asks the network for it at that moment and streams it back without keeping a copy.
5458
+ */
5459
+ SocialFileUrl: {
5460
+ /** @description The file's id on the network (WhatsApp's media id, Telegram's `file_id`, a Bluesky CID, a LinkedIn image URN). Treat it as opaque. */
5461
+ external_id?: string;
5462
+ /** @description Always present, so you can decide how to show it. When the network does not say, it is the most likely type: the file fetched through the API comes with its real `Content-Type`. */
5463
+ mime_type: string;
5464
+ /** @description The document's file name, when the network gives one. */
5465
+ name?: string;
5466
+ /** @description The network's direct link, when there is one a browser can open. It may expire. Never present on WhatsApp, Telegram, LinkedIn or a Bluesky video. */
5467
+ url?: string;
5468
+ };
5375
5469
  /** @description The same person, on one channel. */
5376
5470
  SocialIdentifier: {
5377
5471
  _id: string;
@@ -8358,6 +8452,7 @@ interface operations {
8358
8452
  * | --- | --- |
8359
8453
  * | `700` | The account has no usable token: it has to be connected again |
8360
8454
  * | `706` | The organization has no account slots left in its plan |
8455
+ * | `516` | The plan is free and this network needs a paid plan (today, `whatsapp`) |
8361
8456
  * | `519` | This endpoint does not accept app credentials |
8362
8457
  * | `544` | This temporal connect token was issued for a different social network |
8363
8458
  */
@@ -8404,7 +8499,23 @@ interface operations {
8404
8499
  };
8405
8500
  content: {
8406
8501
  "application/json": {
8407
- /** @description Templates as the network returns them. */
8502
+ /** @description Whether the account can start conversations. WhatsApp only, and absent when it couldn't be read. */
8503
+ health?: {
8504
+ /** @enum {string} */
8505
+ can_send_message: "AVAILABLE" | "LIMITED" | "BLOCKED";
8506
+ /** @description What blocks or limits it. Calling (SIP) errors are left out: they don't affect messaging. */
8507
+ issues: {
8508
+ /** @description WhatsApp's code: 141006 = payment method, 141010 = business not verified. */
8509
+ code: number;
8510
+ description?: string;
8511
+ /** @description Where the problem is: `PHONE_NUMBER`, `WABA`, `BUSINESS` or `APP`. */
8512
+ entity_type: string;
8513
+ solution?: string;
8514
+ }[];
8515
+ /** @description Warnings that are not errors, such as a display name still pending approval. */
8516
+ notes: string[];
8517
+ };
8518
+ /** @description Templates as the network returns them. For WhatsApp: `id`, `name`, `status`, `category`, `language`, `components` and, when rejected, `rejected_reason`. */
8408
8519
  templates: {
8409
8520
  [key: string]: unknown;
8410
8521
  }[];
@@ -8578,6 +8689,36 @@ interface operations {
8578
8689
  400: components["responses"]["MessagesError"];
8579
8690
  };
8580
8691
  };
8692
+ getMessageFile: {
8693
+ parameters: {
8694
+ query?: never;
8695
+ header?: never;
8696
+ path: {
8697
+ /** @description Connected account identifier */
8698
+ id_account: components["parameters"]["MessagesidAccount"];
8699
+ /** @description The message's `_id`. */
8700
+ id_message: string;
8701
+ /** @description Organization identifier */
8702
+ id_organization: components["parameters"]["MessagesidOrganization"];
8703
+ /** @description Position of the file in `message_options.files_urls`, from 0. */
8704
+ index: number;
8705
+ };
8706
+ cookie?: never;
8707
+ };
8708
+ requestBody?: never;
8709
+ responses: {
8710
+ /** @description The file, with the network's `Content-Type`. */
8711
+ 200: {
8712
+ headers: {
8713
+ [name: string]: unknown;
8714
+ };
8715
+ content: {
8716
+ "*/*": string;
8717
+ };
8718
+ };
8719
+ 400: components["responses"]["MessagesError"];
8720
+ };
8721
+ };
8581
8722
  getMetricList: {
8582
8723
  parameters: {
8583
8724
  query?: never;
@@ -9422,6 +9563,34 @@ interface operations {
9422
9563
  400: components["responses"]["CommentsCommentError"];
9423
9564
  };
9424
9565
  };
9566
+ getCommentFile: {
9567
+ parameters: {
9568
+ query?: never;
9569
+ header?: never;
9570
+ path: {
9571
+ /** @description Comment identifier (PlanVortex's `_id`, not the network's `external_id`) */
9572
+ id_comment: components["parameters"]["CommentsidComment"];
9573
+ /** @description Organization identifier */
9574
+ id_organization: components["parameters"]["CommentsidOrganization"];
9575
+ /** @description Position of the file in the comment's `files_urls`, from 0. */
9576
+ index: number;
9577
+ };
9578
+ cookie?: never;
9579
+ };
9580
+ requestBody?: never;
9581
+ responses: {
9582
+ /** @description The file, with the network's `Content-Type`. */
9583
+ 200: {
9584
+ headers: {
9585
+ [name: string]: unknown;
9586
+ };
9587
+ content: {
9588
+ "*/*": string;
9589
+ };
9590
+ };
9591
+ 400: components["responses"]["CommentsCommentError"];
9592
+ };
9593
+ };
9425
9594
  getCommentReplies: {
9426
9595
  parameters: {
9427
9596
  query?: {
@@ -9639,6 +9808,7 @@ interface operations {
9639
9808
  * | `553` | Some account is not part of this session. `data.accounts` lists them |
9640
9809
  * | `706` | The new accounts do not fit in the plan. `data` carries `limit`, `used` and `requested`, and none was enabled |
9641
9810
  * | `1101` | Invalid organization |
9811
+ * | `516` | The plan is free and one of the accounts belongs to a network that needs a paid plan (today, `whatsapp`) |
9642
9812
  */
9643
9813
  400: {
9644
9814
  headers: {
@@ -11762,6 +11932,7 @@ interface operations {
11762
11932
  * | Code | Meaning |
11763
11933
  * | --- | --- |
11764
11934
  * | `514` | This endpoint needs app credentials: neither a user token nor a temporal connect token can issue one |
11935
+ * | `516` | The plan is free, `social_network` needs a paid plan (today, `whatsapp`) and the organization has no active account of it to reconnect |
11765
11936
  * | `532` | `redirect_uri` is not one of the app's registered `redirect_urls` |
11766
11937
  * | `549` | `account_selection` is not `planvortex` or `integrator`, or it is `integrator` without `redirect_uri` or `social_network`. `data` says which |
11767
11938
  * | `550` | `account_selection=integrator` on a network with no return to the browser (`telegram`) |
@@ -13747,7 +13918,7 @@ declare class OrganizationError extends PlanVortexError {
13747
13918
  */
13748
13919
  declare class PlanLimitError extends PlanVortexError {
13749
13920
  }
13750
- /** 1500-1512 — conversaciones, mensajes y plantillas. Exige plan de pago. */
13921
+ /** 1500-1516 — conversaciones, mensajes, plantillas y sus archivos. Exige plan de pago. */
13751
13922
  declare class MessagingError extends PlanVortexError {
13752
13923
  }
13753
13924
  /** 1600-1601 — contactos. */
package/dist/index.cjs CHANGED
@@ -4,7 +4,7 @@ var path = require('path');
4
4
 
5
5
  // src/version.ts
6
6
  var PLANVORTEX_API_URL = "https://api.planvortex.com/v1.0.0";
7
- var VERSION = "0.19.0";
7
+ var VERSION = "0.20.0";
8
8
 
9
9
  // src/core/errors.ts
10
10
  var PLANVORTEX_ERROR_RANGES = [
@@ -31,7 +31,11 @@ var PLANVORTEX_ERROR_RANGES = [
31
31
  //1308 es el tope de APPS del plan, que nacio al quitar el candado de precio de la API.
32
32
  { from: 1300, to: 1308, family: "plan_limit" },
33
33
  { from: 1400, to: 1408, family: "plan_limit" },
34
- { from: 1500, to: 1512, family: "messaging" },
34
+ //1513 y 1514 son las plantillas de WhatsApp: el formato que Meta rechazaria sin decir por que,
35
+ //y Meta rechazandola al crearla. Nacieron por encima del techo, la cuarta vez que pasa. 1515 y
36
+ //1516 son los archivos que llegan de la red: 1515 = la red ya no lo tiene (tambien en un
37
+ //comentario), 1516 = ese mensaje o esa posicion no existen.
38
+ { from: 1500, to: 1516, family: "messaging" },
35
39
  { from: 1600, to: 1601, family: "contact" },
36
40
  { from: 1900, to: 1906, family: "payment" },
37
41
  { from: 2e3, to: 2099, family: "product" },
@@ -471,6 +475,9 @@ var HttpClient = class {
471
475
  if (request.parse === "none" || response.status === 204) {
472
476
  return void 0;
473
477
  }
478
+ if (request.parse === "binary") {
479
+ return new Uint8Array(await response.arrayBuffer());
480
+ }
474
481
  return this.readBody(response);
475
482
  }
476
483
  /** JSON si se puede; si no, el texto crudo. Un cuerpo vacío es `undefined`, nunca un throw. */
@@ -552,6 +559,19 @@ async function* iteratePages(fetchPage, options = {}) {
552
559
  }
553
560
 
554
561
  // src/resources/base.ts
562
+ function dispositionFileName(header) {
563
+ if (!header) {
564
+ return void 0;
565
+ }
566
+ const encoded = /filename\*=UTF-8''([^;]+)/i.exec(header);
567
+ if (encoded?.[1]) {
568
+ try {
569
+ return decodeURIComponent(encoded[1]);
570
+ } catch {
571
+ }
572
+ }
573
+ return /filename="([^"]*)"/i.exec(header)?.[1];
574
+ }
555
575
  var Resource = class {
556
576
  constructor(client) {
557
577
  this.client = client;
@@ -575,6 +595,27 @@ var Resource = class {
575
595
  * nombre obvio de mandar un mensaje, y con el genérico ocupando `send` la subclase no
576
596
  * compilaba.
577
597
  */
598
+ /**
599
+ * Un archivo, en bytes y con lo que dicen sus cabeceras. Lo usan las dos rutas de archivos de la
600
+ * API, la de mensajes y la de comentarios. Lleva `_` al final por lo mismo que los verbos llevan
601
+ * `http` delante: el método público de los recursos se llama `downloadFile`.
602
+ */
603
+ async downloadFile_(path, options = {}) {
604
+ const response = await this.client.request({
605
+ method: "GET",
606
+ path,
607
+ parse: "binary",
608
+ ...options.signal === void 0 ? {} : { signal: options.signal },
609
+ ...options.timeoutMs === void 0 ? {} : { timeoutMs: options.timeoutMs }
610
+ });
611
+ const disposition = response.headers?.get("content-disposition") ?? null;
612
+ return {
613
+ data: response.data ?? new Uint8Array(),
614
+ contentType: (response.headers?.get("content-type") ?? "application/octet-stream").split(";")[0].trim(),
615
+ fileName: dispositionFileName(disposition),
616
+ disposition: disposition?.toLowerCase().startsWith("inline") ? "inline" : "attachment"
617
+ };
618
+ }
578
619
  httpGet(path, query, options) {
579
620
  return this.dispatch({ method: "GET", path, ...query ? { query } : {} }, options);
580
621
  }
@@ -613,6 +654,12 @@ function requireId(value, name) {
613
654
  }
614
655
  return value;
615
656
  }
657
+ function fileIndex(index) {
658
+ if (!Number.isInteger(index) || index < 0) {
659
+ throw new TypeError(`index tiene que ser un entero desde 0, y es ${String(index)}.`);
660
+ }
661
+ return index;
662
+ }
616
663
 
617
664
  // src/resources/accounts.ts
618
665
  var AccountsResource = class extends Resource {
@@ -1522,6 +1569,22 @@ var CommentsResource = class extends Resource {
1522
1569
  options
1523
1570
  );
1524
1571
  }
1572
+ /**
1573
+ * Un archivo del comentario (la foto, el GIF, el sticker o el vídeo de `files_urls[index]`),
1574
+ * pedido a la red en ese momento: PlanVortex no lo guarda y lo reenvía sin quedarse una copia.
1575
+ *
1576
+ * Hace falta cuando el archivo no trae `url` (LinkedIn solo da el id de la imagen; el enlace de
1577
+ * Telegram lleva el token del bot; el vídeo de Bluesky es una lista HLS) o cuando el `url` ya no
1578
+ * carga (Facebook, Threads y Discord lo caducan). Si la red ya no lo tiene, error 1515; si el
1579
+ * comentario no tiene archivo en esa posición, 2602. Un bot de Telegram no baja más de 20 MB:
1580
+ * pasado eso es un 1515 con `data.reason: "too_big"`.
1581
+ *
1582
+ * Un `disposition: "attachment"` es un documento que alguien de fuera colgó: no lo pintes dentro
1583
+ * de tus propias páginas.
1584
+ */
1585
+ async downloadFile(idOrganization, idComment, index, options = {}) {
1586
+ return this.downloadFile_(`${this.path(idOrganization, idComment)}/files/${fileIndex(index)}`, options);
1587
+ }
1525
1588
  /**
1526
1589
  * Responde EN PÚBLICO, colgando de ese comentario.
1527
1590
  *
@@ -2213,6 +2276,25 @@ var MessagesResource = class extends Resource {
2213
2276
  options
2214
2277
  );
2215
2278
  }
2279
+ /**
2280
+ * Un archivo de un mensaje que llegó de la red (`message_options.files_urls[index]`): una foto,
2281
+ * un vídeo, una nota de voz, un documento o un sticker. PlanVortex no lo guarda: lo pide a la red
2282
+ * en ese momento y lo reenvía sin quedarse una copia.
2283
+ *
2284
+ * En WhatsApp es la ÚNICA forma de abrir un archivo: ninguno trae `url`, porque WhatsApp solo los
2285
+ * entrega con el token de la cuenta. En Instagram y Messenger hace falta cuando el `url` del CDN
2286
+ * de Meta caducó. WhatsApp suelta un archivo 7 días después de que llegara: a partir de ahí es un
2287
+ * error 1515. Un 1516 es que el mensaje no es de esa cuenta o no tiene archivo en esa posición.
2288
+ *
2289
+ * Un `disposition: "attachment"` es un documento que mandó alguien de fuera: no lo pintes dentro
2290
+ * de tus propias páginas.
2291
+ */
2292
+ async downloadFile(idOrganization, idAccount, idMessage, index, options = {}) {
2293
+ return this.downloadFile_(
2294
+ `${this.accountPath(idOrganization, idAccount)}/messages/${requireId(idMessage, "idMessage")}/files/${fileIndex(index)}`,
2295
+ options
2296
+ );
2297
+ }
2216
2298
  accountPath(idOrganization, idAccount) {
2217
2299
  return `/organizations/${requireId(idOrganization, "idOrganization")}/accounts/${requireId(idAccount, "idAccount")}`;
2218
2300
  }