@effect/chat-whatsapp 0.0.0-stage → 4.1.5

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.
Files changed (147) hide show
  1. package/AGENTS.md +434 -0
  2. package/CLAUDE.md +434 -0
  3. package/LICENSE +21 -0
  4. package/README.md +60 -2
  5. package/ai-docs/README.md +44 -0
  6. package/ai-docs/package.json +36 -0
  7. package/ai-docs/src/01_effect/01_basics/01_effect-gen.ts +30 -0
  8. package/ai-docs/src/01_effect/01_basics/02_effect-fn.ts +52 -0
  9. package/ai-docs/src/01_effect/01_basics/10_creating-effects.ts +74 -0
  10. package/ai-docs/src/01_effect/01_basics/index.md +7 -0
  11. package/ai-docs/src/01_effect/02_schema/10_schema-basics.ts +43 -0
  12. package/ai-docs/src/01_effect/02_schema/index.md +7 -0
  13. package/ai-docs/src/01_effect/03_services/01_service.ts +45 -0
  14. package/ai-docs/src/01_effect/03_services/10_reference.ts +10 -0
  15. package/ai-docs/src/01_effect/03_services/20_layer-composition.ts +70 -0
  16. package/ai-docs/src/01_effect/03_services/20_layer-unwrap.ts +66 -0
  17. package/ai-docs/src/01_effect/03_services/index.md +5 -0
  18. package/ai-docs/src/01_effect/04_errors/01_error-handling.ts +30 -0
  19. package/ai-docs/src/01_effect/04_errors/10_catch-tags.ts +24 -0
  20. package/ai-docs/src/01_effect/04_errors/20_reason-errors.ts +64 -0
  21. package/ai-docs/src/01_effect/04_errors/index.md +1 -0
  22. package/ai-docs/src/01_effect/05_resources/10_acquire-release.ts +105 -0
  23. package/ai-docs/src/01_effect/05_resources/20_layer-side-effects.ts +31 -0
  24. package/ai-docs/src/01_effect/05_resources/30_layer-map.ts +86 -0
  25. package/ai-docs/src/01_effect/05_resources/index.md +3 -0
  26. package/ai-docs/src/01_effect/06_running/10_run-main.ts +30 -0
  27. package/ai-docs/src/01_effect/06_running/20_layer-launch.ts +27 -0
  28. package/ai-docs/src/01_effect/06_running/index.md +1 -0
  29. package/ai-docs/src/01_effect/07_pubsub/10_pubsub.ts +56 -0
  30. package/ai-docs/src/01_effect/07_pubsub/index.md +3 -0
  31. package/ai-docs/src/03_stream/10_creating-streams.ts +103 -0
  32. package/ai-docs/src/03_stream/20_consuming-streams.ts +137 -0
  33. package/ai-docs/src/03_stream/30_encoding.ts +163 -0
  34. package/ai-docs/src/03_stream/index.md +4 -0
  35. package/ai-docs/src/04_integration/10_managed-runtime.ts +129 -0
  36. package/ai-docs/src/04_integration/index.md +5 -0
  37. package/ai-docs/src/05_batching/10_request-resolver.ts +89 -0
  38. package/ai-docs/src/05_batching/index.md +3 -0
  39. package/ai-docs/src/06_schedule/10_schedules.ts +111 -0
  40. package/ai-docs/src/06_schedule/index.md +3 -0
  41. package/ai-docs/src/07_datetime/10_creating-and-formatting.ts +30 -0
  42. package/ai-docs/src/07_datetime/20_time-zones.ts +44 -0
  43. package/ai-docs/src/07_datetime/index.md +5 -0
  44. package/ai-docs/src/08_observability/10_logging.ts +66 -0
  45. package/ai-docs/src/08_observability/20_otlp-tracing.ts +95 -0
  46. package/ai-docs/src/08_observability/index.md +7 -0
  47. package/ai-docs/src/09_testing/10_effect-tests.ts +55 -0
  48. package/ai-docs/src/09_testing/20_layer-tests.ts +138 -0
  49. package/ai-docs/src/09_testing/index.md +1 -0
  50. package/ai-docs/src/10_predicate/01_basics.ts +14 -0
  51. package/ai-docs/src/10_predicate/index.md +9 -0
  52. package/ai-docs/src/40_sql/10_basics.ts +175 -0
  53. package/ai-docs/src/40_sql/index.md +6 -0
  54. package/ai-docs/src/50_http-client/10_basics.ts +102 -0
  55. package/ai-docs/src/50_http-client/index.md +3 -0
  56. package/ai-docs/src/51_http-server/10_basics.ts +118 -0
  57. package/ai-docs/src/51_http-server/20_testing.ts +100 -0
  58. package/ai-docs/src/51_http-server/fixtures/api/Api.ts +14 -0
  59. package/ai-docs/src/51_http-server/fixtures/api/Authorization.ts +36 -0
  60. package/ai-docs/src/51_http-server/fixtures/api/System.ts +10 -0
  61. package/ai-docs/src/51_http-server/fixtures/api/Users.ts +107 -0
  62. package/ai-docs/src/51_http-server/fixtures/domain/User.ts +21 -0
  63. package/ai-docs/src/51_http-server/fixtures/domain/UserErrors.ts +22 -0
  64. package/ai-docs/src/51_http-server/fixtures/server/Authorization.ts +37 -0
  65. package/ai-docs/src/51_http-server/fixtures/server/Users/http.ts +80 -0
  66. package/ai-docs/src/51_http-server/fixtures/server/Users.ts +183 -0
  67. package/ai-docs/src/51_http-server/index.md +3 -0
  68. package/ai-docs/src/52_graphql/10_basics.ts +117 -0
  69. package/ai-docs/src/52_graphql/20_testing.ts +45 -0
  70. package/ai-docs/src/52_graphql/30_batching.ts +118 -0
  71. package/ai-docs/src/52_graphql/40_aliased-batching.ts +124 -0
  72. package/ai-docs/src/52_graphql/50_errors-and-retries.ts +74 -0
  73. package/ai-docs/src/52_graphql/index.md +6 -0
  74. package/ai-docs/src/60_child-process/10_working-with-child-processes.ts +117 -0
  75. package/ai-docs/src/60_child-process/index.md +3 -0
  76. package/ai-docs/src/70_cli/10_basics.ts +162 -0
  77. package/ai-docs/src/70_cli/index.md +5 -0
  78. package/ai-docs/src/71_ai/10_language-model.ts +156 -0
  79. package/ai-docs/src/71_ai/20_tools.ts +226 -0
  80. package/ai-docs/src/71_ai/30_chat.ts +158 -0
  81. package/ai-docs/src/71_ai/fixtures/domain/LaunchPlan.ts +9 -0
  82. package/ai-docs/src/71_ai/index.md +5 -0
  83. package/ai-docs/src/80_cluster/10_entities.ts +97 -0
  84. package/ai-docs/src/80_cluster/index.md +4 -0
  85. package/ai-docs/src/index.md +10 -0
  86. package/ai-docs/tsconfig.json +28 -0
  87. package/dist/WhatsAppChat.d.ts +373 -0
  88. package/dist/WhatsAppChat.d.ts.map +1 -0
  89. package/dist/WhatsAppChat.js +388 -0
  90. package/dist/WhatsAppChat.js.map +1 -0
  91. package/dist/WhatsAppGraphApi.d.ts +90 -0
  92. package/dist/WhatsAppGraphApi.d.ts.map +1 -0
  93. package/dist/WhatsAppGraphApi.js +97 -0
  94. package/dist/WhatsAppGraphApi.js.map +1 -0
  95. package/dist/WhatsAppUpdate.d.ts +168 -0
  96. package/dist/WhatsAppUpdate.d.ts.map +1 -0
  97. package/dist/WhatsAppUpdate.js +103 -0
  98. package/dist/WhatsAppUpdate.js.map +1 -0
  99. package/dist/index.d.ts +20 -0
  100. package/dist/index.d.ts.map +1 -0
  101. package/dist/index.js +21 -0
  102. package/dist/index.js.map +1 -0
  103. package/dist/internal/actions.d.ts +2 -0
  104. package/dist/internal/actions.d.ts.map +1 -0
  105. package/dist/internal/actions.js +224 -0
  106. package/dist/internal/actions.js.map +1 -0
  107. package/dist/internal/adapter.d.ts +2 -0
  108. package/dist/internal/adapter.d.ts.map +1 -0
  109. package/dist/internal/adapter.js +330 -0
  110. package/dist/internal/adapter.js.map +1 -0
  111. package/dist/internal/address.d.ts +2 -0
  112. package/dist/internal/address.d.ts.map +1 -0
  113. package/dist/internal/address.js +36 -0
  114. package/dist/internal/address.js.map +1 -0
  115. package/dist/internal/errors.d.ts +2 -0
  116. package/dist/internal/errors.d.ts.map +1 -0
  117. package/dist/internal/errors.js +93 -0
  118. package/dist/internal/errors.js.map +1 -0
  119. package/dist/internal/normalize.d.ts +2 -0
  120. package/dist/internal/normalize.d.ts.map +1 -0
  121. package/dist/internal/normalize.js +292 -0
  122. package/dist/internal/normalize.js.map +1 -0
  123. package/dist/internal/options.d.ts +2 -0
  124. package/dist/internal/options.d.ts.map +1 -0
  125. package/dist/internal/options.js +10 -0
  126. package/dist/internal/options.js.map +1 -0
  127. package/dist/internal/text.d.ts +11 -0
  128. package/dist/internal/text.d.ts.map +1 -0
  129. package/dist/internal/text.js +485 -0
  130. package/dist/internal/text.js.map +1 -0
  131. package/dist/internal/webhook.d.ts +2 -0
  132. package/dist/internal/webhook.d.ts.map +1 -0
  133. package/dist/internal/webhook.js +150 -0
  134. package/dist/internal/webhook.js.map +1 -0
  135. package/package.json +58 -3
  136. package/src/WhatsAppChat.ts +505 -0
  137. package/src/WhatsAppGraphApi.ts +147 -0
  138. package/src/WhatsAppUpdate.ts +142 -0
  139. package/src/index.ts +24 -0
  140. package/src/internal/actions.ts +220 -0
  141. package/src/internal/adapter.ts +284 -0
  142. package/src/internal/address.ts +41 -0
  143. package/src/internal/errors.ts +102 -0
  144. package/src/internal/normalize.ts +250 -0
  145. package/src/internal/options.ts +13 -0
  146. package/src/internal/text.ts +495 -0
  147. package/src/internal/webhook.ts +216 -0
@@ -0,0 +1,28 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "../tsconfig.base.json",
4
+ "include": ["src/**/*.ts", "src/**/*.tsx"],
5
+ "compilerOptions": {
6
+ "rootDir": ".",
7
+ "noEmit": true,
8
+ "declaration": false,
9
+ "declarationMap": false,
10
+ "composite": false,
11
+ "incremental": false,
12
+ "types": ["node"],
13
+ "plugins": [
14
+ {
15
+ "name": "@effect/language-service",
16
+ "effectFn": ["untraced"],
17
+ "namespaceImportPackages": [],
18
+ "diagnosticSeverity": {
19
+ "floatingEffect": "off",
20
+ "globalJson": "off",
21
+ "globalJsonInEffect": "off",
22
+ "unstableApiUsage": "off",
23
+ "effectFnOpportunity": "error"
24
+ }
25
+ }
26
+ ]
27
+ }
28
+ }
@@ -0,0 +1,373 @@
1
+ import { type Posted, Registry } from "effect/chat/ChatAdapter";
2
+ import type { ChatError } from "effect/chat/ChatError";
3
+ import type * as ChatEvent from "effect/chat/ChatEvent";
4
+ import { ChatHandler, type NotAccepted } from "effect/chat/ChatHandler";
5
+ import * as ChatInteraction from "effect/chat/ChatInteraction";
6
+ import type { ParseMention } from "effect/chat/ChatTest";
7
+ import type { ChatThread } from "effect/chat/ChatThread";
8
+ import * as Context from "effect/Context";
9
+ import type * as Mac from "effect/crypto/Mac";
10
+ import * as Duration from "effect/Duration";
11
+ import * as Effect from "effect/Effect";
12
+ import * as HttpClient from "effect/http/HttpClient";
13
+ import * as HttpRouter from "effect/http/HttpRouter";
14
+ import * as Layer from "effect/Layer";
15
+ import * as Option from "effect/Option";
16
+ import type * as Redacted from "effect/Redacted";
17
+ import type * as Schema from "effect/Schema";
18
+ import { WhatsAppGraphApi } from "./WhatsAppGraphApi.ts";
19
+ import type { WhatsAppUpdate } from "./WhatsAppUpdate.ts";
20
+ /**
21
+ * The detail of a `post` refused outside the 24 hour customer service
22
+ * window, Graph error 131047. The reason is `Forbidden`. Write with
23
+ * `sendTemplate` instead.
24
+ *
25
+ * @stability unstable
26
+ * @category constants
27
+ * @since 4.1.5
28
+ */
29
+ export declare const outsideWindow: string;
30
+ /**
31
+ * A template message: its approved name, its language code, such as
32
+ * `en_US`, and Meta's `components` for its parameters, sent as they are.
33
+ *
34
+ * @stability unstable
35
+ * @category models
36
+ * @since 4.1.5
37
+ */
38
+ export interface Template {
39
+ readonly name: string;
40
+ readonly language: string;
41
+ readonly components?: ReadonlyArray<Schema.Json> | undefined;
42
+ }
43
+ /**
44
+ * What one webhook delivery holds, in order: messages and reactions, clicks,
45
+ * and updates.
46
+ *
47
+ * @stability unstable
48
+ * @category models
49
+ * @since 4.1.5
50
+ */
51
+ export type Inbound = ChatEvent.MessageCreated | ChatEvent.ReactionAdded | ChatInteraction.ButtonClicked | ChatInteraction.SelectChanged | WhatsAppUpdate;
52
+ declare const WhatsAppChat_base: Context.ServiceClass<WhatsAppChat, "@effect/chat-whatsapp/WhatsAppChat", {
53
+ readonly phoneNumberId: string;
54
+ readonly sendTemplate: (thread: ChatThread, template: Template) => Effect.Effect<Posted, ChatError>;
55
+ readonly markRead: (thread: ChatThread, messageId: string, options?: {
56
+ readonly typing?: boolean | undefined;
57
+ }) => Effect.Effect<void, ChatError>;
58
+ readonly receive: (envelope: unknown, options?: {
59
+ readonly onUpdate?: ((update: WhatsAppUpdate) => Effect.Effect<void, NotAccepted>) | undefined;
60
+ readonly deadline?: Duration.Duration | undefined;
61
+ }) => Effect.Effect<void, NotAccepted, ChatHandler>;
62
+ }>;
63
+ /**
64
+ * The WhatsApp side of the adapter, for what the core has no op for.
65
+ *
66
+ * **Details**
67
+ *
68
+ * - `sendTemplate` sends an approved template, which is how v1 writes
69
+ * outside the 24 hour window. A template needs Meta's approval first; a
70
+ * Direct Send template, where Meta offers it, does not need a separate
71
+ * review. An authentication template with one-tap, zero-tap or copy-code
72
+ * buttons can't be sent to a BSUID: Meta refuses it with error 131062,
73
+ * which is `InvalidRequest`. Send those to a phone number address.
74
+ * - `markRead` marks a received message read, which shows blue ticks, and
75
+ * with `typing` shows the typing indicator until the next message or for
76
+ * up to 25 seconds.
77
+ * - `receive` runs one webhook delivery, already verified and parsed, as
78
+ * `layerWebhook` does, for a consumer's own transport. It needs a
79
+ * `ChatHandler`, and a `ChatInteraction.Handler` when there are
80
+ * clicks: without one a click is logged and dropped. `deadline` is a
81
+ * click handler's share, 3 seconds by default.
82
+ *
83
+ * @stability unstable
84
+ * @category services
85
+ * @since 4.1.5
86
+ */
87
+ export declare class WhatsAppChat extends WhatsAppChat_base {
88
+ }
89
+ /**
90
+ * Registers the WhatsApp adapter in the `Registry`, for one business phone
91
+ * number.
92
+ *
93
+ * **Details**
94
+ *
95
+ * - Capabilities: `replyTo`, `files`, `download`, `getThread`,
96
+ * `opener`, `buttons` and `selects`. Every other op fails
97
+ * `Unsupported`. WhatsApp has no edit, so `ChatMarkdown` posts each
98
+ * part of a streamed reply once.
99
+ * - Every `post` is one send, and every check runs before any upload or
100
+ * send. `Posted` means Meta accepted the message, not that it was
101
+ * delivered: a later `failed` status goes to `onUpdate`. A send that
102
+ * failed after the request left is `uncertain`.
103
+ * - Markdown is rendered to WhatsApp's formatting: bold as `*b*`, italics
104
+ * as `_i_`, strikethrough as `~s~`, a link as `label (url)`, a heading
105
+ * as bold, a table without its delimiter row and a fence without its info
106
+ * string. Each replacement is used only when it is no longer than the
107
+ * Markdown it replaces, so the text never grows; anything else is sent as
108
+ * typed, including reference links and their definitions, and code fenced
109
+ * inside a quote or a list item.
110
+ * - `descriptor.measure` and the label limits count UTF-16 units. In live
111
+ * checks on Graph `v23.0`, Meta counted text bodies, interactive bodies,
112
+ * reply button titles, list row titles and row ids in code points, which a
113
+ * UTF-16 count never undercounts: it is stricter only for characters
114
+ * outside the Basic Multilingual Plane, such as emoji. Captions, the list
115
+ * button and section titles were not measured, and are counted the same
116
+ * way.
117
+ * - Link previews are off unless `withPostOptions({ linkPreview: true })`.
118
+ * - One file per post. It is uploaded, then sent as one media message with
119
+ * the text as its caption, or as the header of a message with reply
120
+ * buttons or a link button. Refused with `TooLarge`, subject `files` and
121
+ * detail `file_refused`, before anything is sent: more than one file, a
122
+ * MIME type outside Meta's table, `image/webp`, a file past its type's
123
+ * size limit, audio with text or actions, text over 1,024 beside a file,
124
+ * and a file beside a list. An upload Meta refuses as invalid or too large
125
+ * fails the same way, so `ChatMarkdown`'s `unattachedNote` applies. `text/markdown` is uploaded as
126
+ * `text/plain`, with its bytes and name unchanged.
127
+ * - Actions: one to three buttons with labels up to 20 go as reply buttons;
128
+ * a lone link button with a label up to 20 as a link button; otherwise
129
+ * buttons and select options become the rows of one list, at most ten,
130
+ * with labels up to 24. Link buttons beside anything else, or with a
131
+ * longer label, are appended to the text as `Label: url` lines. A body
132
+ * beside reply buttons or a link button is held to 1,024, which
133
+ * `descriptor.measure` counts. A post with actions and no text gets the
134
+ * labels, joined by ", ", as its text.
135
+ * - The list's button is the first select's placeholder, or
136
+ * `withPostOptions({ listButton })`, "Options" by default, up to 20.
137
+ * With buttons and a select, or two selects, each section has a title up
138
+ * to 24: the select's placeholder, or `buttonsSection`, "Actions" by
139
+ * default, for the buttons.
140
+ * - Refused before the call: more than ten rows (`TooLarge`,
141
+ * `list_rows`), a label past its limit (`TooLarge`,
142
+ * `label_too_long`), an id holding U+241F, two reply buttons with one
143
+ * label, and two elements with one id and value (`InvalidRequest`). A
144
+ * select's `selected` and a button's `style` are ignored.
145
+ * - A reply button's id on the wire is `b`, the id, U+241F and the value,
146
+ * and Meta counts it in UTF-8 bytes, up to 256. Over that, the post is
147
+ * refused before the call with `TooLarge`, `action_data_too_long`,
148
+ * even when the id and value are within `limits.actionDataLength`.
149
+ * - `getThread` is built from the address alone, as `direct`. `opener`
150
+ * is always `None`.
151
+ * - The pair rate limit is one message every 6 seconds to one user, which is
152
+ * `limits.minWriteInterval`. Meta accepts short bursts above that rate
153
+ * but refuses a sustained faster pace with error 131056, `RateLimited`.
154
+ * - `messagingAccountId` is sent as `messaging_account_id` on every
155
+ * message. Include it to say which Messaging account sends when the
156
+ * access token can send from more than one on the phone number. Meta
157
+ * documents it as optional for now, required for such a token on the
158
+ * newest Graph version from H1 2027, and on every version from H1 2028.
159
+ * Without it, Meta picks the account from the token. Not yet checked
160
+ * against a production number.
161
+ * - Built against Graph API `v24.0`, the default `baseUrl`. The
162
+ * adapter's live checks ran on `v23.0`.
163
+ *
164
+ * @stability unstable
165
+ * @category layers
166
+ * @since 4.1.5
167
+ */
168
+ export declare const layer: (options: {
169
+ readonly accessToken: Redacted.Redacted;
170
+ readonly phoneNumberId: string;
171
+ readonly messagingAccountId?: string | undefined;
172
+ readonly baseUrl?: string | undefined;
173
+ }) => Layer.Layer<WhatsAppChat | WhatsAppGraphApi, never, HttpClient.HttpClient | Registry>;
174
+ /**
175
+ * The address of a WhatsApp user: `{phoneNumberId}/u/{user}`, where
176
+ * `user` is a phone number in digits or a BSUID.
177
+ *
178
+ * @stability unstable
179
+ * @category constructors
180
+ * @since 4.1.5
181
+ */
182
+ export declare const thread: (parts: {
183
+ readonly phoneNumberId: string;
184
+ readonly user: string;
185
+ }) => ChatThread;
186
+ /**
187
+ * The parts of a WhatsApp address, or `None` for another platform's or a
188
+ * malformed one. A group address, which is reserved, has `kind` `group`.
189
+ *
190
+ * @stability unstable
191
+ * @category destructors
192
+ * @since 4.1.5
193
+ */
194
+ export declare const parts: (thread: ChatThread) => Option.Option<{
195
+ readonly phoneNumberId: string;
196
+ readonly kind: "user" | "group";
197
+ readonly id: string;
198
+ }>;
199
+ /**
200
+ * `GET {path}` and `POST {path}`: the webhook's subscription check and its
201
+ * deliveries.
202
+ *
203
+ * **Details**
204
+ *
205
+ * - `GET` answers Meta's check with `hub.challenge` when `hub.verify_token`
206
+ * is `verifyToken`, and 403 otherwise.
207
+ * - `POST` reads at most `maxBodyBytes` (3 MiB by default, 413; a body
208
+ * that can't be read is 400), checks `X-Hub-Signature-256` with the app
209
+ * secret (401), and drops a delivery for another object or another phone
210
+ * number with a 200. `maxBodyBytes` must be a non-negative safe integer;
211
+ * another value is a defect when the layer is built.
212
+ * - The updates run in order. Messages and reactions go to the
213
+ * `ChatHandler`, clicks to `ChatInteraction.handle`, and statuses and
214
+ * changed ids to `onUpdate`. A removed reaction is dropped.
215
+ * - A `NotAccepted` stops the delivery and answers 503, as does a request
216
+ * that takes longer than `deadline`, 10 seconds by default. Meta then
217
+ * delivers the whole batch again, for up to 7 days, so a batch that
218
+ * always runs past the deadline repeats until then. At the deadline the
219
+ * work is interrupted without waiting for its finalizers. In a live check
220
+ * Meta gave up on a response after about 22 seconds and redelivered.
221
+ * - A click never causes a 503. It gets what is left of the deadline, less
222
+ * a margin. `Ack` and `Late` count as handled, and a late handler keeps
223
+ * running. `OpenModal` goes to `Handler.refused` as
224
+ * `Unsupported("modals")`, which is awaited only within the click's share. Without a `ChatInteraction.Handler` in the
225
+ * layer's context, a click is logged and dropped.
226
+ * - Delivery is at least once. A message, a reaction or a click can arrive
227
+ * twice, a click even at the same time as its first delivery. Drop
228
+ * repeated events with `ChatEvent.dedupeKey`; a click handler for which
229
+ * a second run is unsafe must claim `deliveryKey` atomically, before any
230
+ * side effect. The adapter keeps no seen-store. Deliveries are not in
231
+ * order either: order by the updates' timestamps.
232
+ * - A user can tap more than one reply button of a message, or pick one
233
+ * list row twice. Each tap is a click of its own, with its own
234
+ * `deliveryKey`, so a choice that must be made once needs its own
235
+ * claim.
236
+ *
237
+ * Signature checks use the required `Mac` service. Provide
238
+ * `NodeCrypto.layerMac`, `BunCrypto.layerMac`, `DenoCrypto.layerMac`,
239
+ * `BrowserCrypto.layerMac`, or `Mac.layerWebCrypto` with
240
+ * `SecureRandom.layerWebCrypto` for other runtimes such as Workers.
241
+ * Key construction failures are configuration defects; verification errors
242
+ * fail the signature check (401).
243
+ *
244
+ * @stability unstable
245
+ * @category layers
246
+ * @since 4.1.5
247
+ */
248
+ export declare const layerWebhook: (options: {
249
+ readonly path: `/${string}`;
250
+ readonly appSecret: Redacted.Redacted;
251
+ readonly verifyToken: Redacted.Redacted;
252
+ readonly onUpdate?: ((update: WhatsAppUpdate) => Effect.Effect<void, NotAccepted>) | undefined;
253
+ readonly deadline?: Duration.Duration | undefined;
254
+ readonly maxBodyBytes?: number | undefined;
255
+ }) => Layer.Layer<never, never, HttpRouter.HttpRouter | WhatsAppChat | ChatHandler | Mac.Mac>;
256
+ /**
257
+ * The normaliser, for a consumer's own transport.
258
+ *
259
+ * **Details**
260
+ *
261
+ * - Pure: takes a parsed webhook body, gives what it holds, in order. A
262
+ * change for another phone number, and a group message, give nothing.
263
+ * - A message's `thread` is the sender's BSUID address when the webhook
264
+ * has one, and its phone number address otherwise. `kind` is
265
+ * `direct`. Text is as the user typed it, a caption for media, and empty
266
+ * for a message with neither, such as a location. Media are attachments,
267
+ * with the media id as their `id`.
268
+ * - `raw` of an event or a click is the change's `metadata`, the
269
+ * sender's entry of `contacts`, with `wa_id` when Meta shares the
270
+ * number, and the one message. `message.raw` is the message.
271
+ * - A reaction with an emoji is `ReactionAdded`; a removed reaction gives
272
+ * nothing.
273
+ * - A reply button or a list row the adapter built is `ButtonClicked` or
274
+ * `SelectChanged`, whose `messageId` is the message that carried it.
275
+ * Any other interactive reply gives nothing.
276
+ * - Statuses give `Status`, and `Alias` too when they carry both ids. A
277
+ * `system` message about a changed number or id gives `UserIdChanged`.
278
+ *
279
+ * @stability unstable
280
+ * @category normalization
281
+ * @since 4.1.5
282
+ */
283
+ export declare const normalize: (envelope: unknown, context: {
284
+ readonly phoneNumberId: string;
285
+ }) => ReadonlyArray<Inbound>;
286
+ /**
287
+ * The key of one delivery of a click or a reaction:
288
+ * `{phoneNumberId}/{messageId}`, the id of the webhook message that carried
289
+ * it, each part percent-encoded.
290
+ *
291
+ * **When to use**
292
+ *
293
+ * Use to make a click handler safe to run twice. Meta redelivers a batch
294
+ * that was not answered in time, so a click can run again, even at the same
295
+ * time as the first run. Claim the key atomically, such as with an insert
296
+ * that fails on a duplicate, before any side effect, and skip the click when
297
+ * the claim fails.
298
+ *
299
+ * @stability unstable
300
+ * @category getters
301
+ * @since 4.1.5
302
+ */
303
+ export declare const deliveryKey: (event: ChatInteraction.ButtonClicked | ChatInteraction.SelectChanged | ChatEvent.ReactionAdded) => string;
304
+ /**
305
+ * The key of an update, for dropping a redelivered one, its parts
306
+ * percent-encoded and joined by `/`.
307
+ *
308
+ * **Details**
309
+ *
310
+ * - `Status`: `{phoneNumberId}/status/{messageId}/{status}`.
311
+ * - `UserIdChanged`: `{phoneNumberId}/user_changed/{id}`.
312
+ * - `Alias`: `{phoneNumberId}/alias/{messageId}/{status}/{phone}/{userId}`.
313
+ *
314
+ * @stability unstable
315
+ * @category getters
316
+ * @since 4.1.5
317
+ */
318
+ export declare const updateKey: (update: WhatsAppUpdate) => string;
319
+ /**
320
+ * WhatsApp options for every write inside an effect.
321
+ *
322
+ * @stability unstable
323
+ * @category models
324
+ * @since 4.1.5
325
+ */
326
+ export interface WhatsAppPostOptions {
327
+ /** A preview of the first link in a text message. Default false. */
328
+ readonly linkPreview?: boolean | undefined;
329
+ /** The button that opens a list, when no select has a placeholder. Default "Options", up to 20. */
330
+ readonly listButton?: string | undefined;
331
+ /** The title of a list's buttons section beside a select. Default "Actions", up to 24. */
332
+ readonly buttonsSection?: string | undefined;
333
+ }
334
+ /**
335
+ * Scoped WhatsApp options for every write inside `effect`. Nested calls
336
+ * merge, the inner one winning field by field.
337
+ *
338
+ * @stability unstable
339
+ * @category combinators
340
+ * @since 4.1.5
341
+ */
342
+ export declare const withPostOptions: {
343
+ /**
344
+ * Scoped WhatsApp options for every write inside `effect`. Nested calls
345
+ * merge, the inner one winning field by field.
346
+ *
347
+ * @stability unstable
348
+ * @category combinators
349
+ * @since 4.1.5
350
+ */
351
+ (options: WhatsAppPostOptions): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
352
+ /**
353
+ * Scoped WhatsApp options for every write inside `effect`. Nested calls
354
+ * merge, the inner one winning field by field.
355
+ *
356
+ * @stability unstable
357
+ * @category combinators
358
+ * @since 4.1.5
359
+ */
360
+ <A, E, R>(effect: Effect.Effect<A, E, R>, options: WhatsAppPostOptions): Effect.Effect<A, E, R>;
361
+ };
362
+ /**
363
+ * WhatsApp has no mention tokens outside groups, so nothing is a mention:
364
+ * for `ChatTest.checkMessage`, `ChatTest.checkEvent` and
365
+ * `ChatTest.conformance`.
366
+ *
367
+ * @stability unstable
368
+ * @category testing
369
+ * @since 4.1.5
370
+ */
371
+ export declare const parseMention: ParseMention;
372
+ export {};
373
+ //# sourceMappingURL=WhatsAppChat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WhatsAppChat.d.ts","sourceRoot":"","sources":["../src/WhatsAppChat.ts"],"names":[],"mappings":"AA6BA,OAAO,EAAE,KAAK,MAAM,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,KAAK,KAAK,SAAS,MAAM,uBAAuB,CAAA;AACvD,OAAO,EAAE,WAAW,EAAE,KAAK,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACvE,OAAO,KAAK,eAAe,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,KAAK,GAAG,MAAM,mBAAmB,CAAA;AAC7C,OAAO,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