@segmentstream/ontology 0.138.0 → 0.139.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 +21 -0
- package/README.md +3 -2
- package/dist/analyze.d.ts +2 -0
- package/dist/analyze.js +14 -5
- package/dist/chat.d.ts +6 -0
- package/dist/manifest.d.ts +32 -13
- package/dist/manifest.js +14 -5
- package/dist/migrate/model.d.ts +8 -0
- package/dist/service/chat/attribution.d.ts +1 -0
- package/dist/service/chat/delivery.js +16 -8
- package/dist/service/chat/providers/provider.d.ts +4 -1
- package/dist/service/chat/providers/slack.d.ts +4 -3
- package/dist/service/chat/providers/slack.js +8 -5
- package/dist/service/chat/providers/whatsapp-refusals.d.ts +10 -0
- package/dist/service/chat/providers/whatsapp-refusals.js +13 -0
- package/dist/service/chat/providers/whatsapp.js +1 -12
- package/dist/service/schemas.d.ts +2 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.139.1
|
|
4
|
+
|
|
5
|
+
A WhatsApp message Meta accepts and later reports it could not deliver, in a `failed` delivery
|
|
6
|
+
status, now reads `failed`: a replay of its idempotency key fails with `keyConsumed` and the
|
|
7
|
+
`refusal` Meta's code names, and the chat's history shows the message failed. The platform reads
|
|
8
|
+
these statuses; this release shares the ontology's WhatsApp refusal codes with it.
|
|
9
|
+
|
|
10
|
+
## 0.139.0
|
|
11
|
+
|
|
12
|
+
The inbox takes `attribution`: `inbox: { roles: [client], attribution: "none" }` sends a member's
|
|
13
|
+
own reply to a person in the inbox, from their session in the app, as written, without the
|
|
14
|
+
separator or their name, and archives that text alone. The reply stays the member's own message,
|
|
15
|
+
and its `requestedBy` still names them, with an empty `attribution`. The default, `"name"`, signs
|
|
16
|
+
the reply with `chat.attribution` as before, and writes nothing new into the manifest. Posts to
|
|
17
|
+
group chats, and posts by OAuth clients, services and the agent's sessions, stay signed whatever
|
|
18
|
+
the inbox says. `check` reports `invalid-inbox` for any other value.
|
|
19
|
+
|
|
20
|
+
An approved Slack reply goes in the thread it answers: `agent_review.approve` posts it with the
|
|
21
|
+
review's `threadId` as Slack's `thread_ts`, in a channel or in the person's direct message, and
|
|
22
|
+
records it `sent` only when Slack confirms that thread. Chat posts are unchanged.
|
|
23
|
+
|
|
3
24
|
## 0.138.0
|
|
4
25
|
|
|
5
26
|
`agent_chat.send` sends WhatsApp templates with a header and buttons: `header.parameters` for a text
|
package/README.md
CHANGED
|
@@ -1585,8 +1585,9 @@ renders it. The body is at most 4096 characters, and `reply_to` is refused. Meta
|
|
|
1585
1585
|
free-form text only inside the 24-hour customer-service window: a post outside it fails with
|
|
1586
1586
|
Meta's code 131047 and consumes the key. Any Meta refusal with an error code does the same; a
|
|
1587
1587
|
timeout, a 5xx or an answer naming no message is `uncertain`. The receipt's `message_id` is the
|
|
1588
|
-
`wamid…` Meta accepted; it has no URL
|
|
1589
|
-
|
|
1588
|
+
`wamid…` Meta accepted; it has no URL. A failure Meta reports later in delivery statuses makes the
|
|
1589
|
+
receipt read `failed`: a replay of the key then fails with `keyConsumed` and the `refusal` Meta's
|
|
1590
|
+
code names.
|
|
1590
1591
|
|
|
1591
1592
|
`chat` names the agent's channels as its `channels` does. A channel not named after its kind,
|
|
1592
1593
|
such as a second number, says its kind: `chat: { sales_whatsapp: { kind: "whatsapp", connection:
|
package/dist/analyze.d.ts
CHANGED
|
@@ -237,6 +237,8 @@ export interface Analysis {
|
|
|
237
237
|
readonly takeover: {
|
|
238
238
|
readonly channels: ReadonlyArray<string>;
|
|
239
239
|
};
|
|
240
|
+
/** Whether a member's own reply to the person carries their name. */
|
|
241
|
+
readonly attribution: "name" | "none";
|
|
240
242
|
};
|
|
241
243
|
readonly entities: ReadonlyArray<ResolvedEntity>;
|
|
242
244
|
/** The workspace-owned `member` role and declared roles, then the implicit reporter when enabled. */
|
package/dist/analyze.js
CHANGED
|
@@ -355,8 +355,9 @@ export function analyze(config, options = {}) {
|
|
|
355
355
|
}
|
|
356
356
|
/**
|
|
357
357
|
* `inbox`: the wire names of the roles whose private chats join the inbox, each a declared role or
|
|
358
|
-
* `member`,
|
|
359
|
-
* every channel `chat` declares
|
|
358
|
+
* `member`, the channels whose chats staff may take over: those `takeover.channels` lists, or
|
|
359
|
+
* every channel `chat` declares, and whether a member's own reply carries their name: `name`
|
|
360
|
+
* unless `attribution` is `none`; `undefined` when absent or malformed.
|
|
360
361
|
*/
|
|
361
362
|
function inboxOptions(value, declaredRoles,
|
|
362
363
|
/** Whether the ontology declares `guest`, whose visitors' chats the inbox may take. */
|
|
@@ -367,13 +368,19 @@ chatChannels, report) {
|
|
|
367
368
|
return undefined;
|
|
368
369
|
}
|
|
369
370
|
if (!isPlainObject(value) ||
|
|
370
|
-
Object.keys(value).some((key) => key !== "roles" && key !== "takeover") ||
|
|
371
|
+
Object.keys(value).some((key) => key !== "roles" && key !== "takeover" && key !== "attribution") ||
|
|
371
372
|
!Array.isArray(value.roles) ||
|
|
372
373
|
value.roles.length === 0) {
|
|
373
|
-
report("invalid-inbox", "inbox",
|
|
374
|
+
report("invalid-inbox", "inbox", 'inbox takes { roles: [...], takeover?: { channels?: [...] }, attribution?: "name" | ' +
|
|
375
|
+
'"none" }, at least one role.');
|
|
374
376
|
return undefined;
|
|
375
377
|
}
|
|
376
378
|
const takeover = takeoverOptions(value.takeover, chatChannels, report);
|
|
379
|
+
const attribution = value.attribution === undefined ? "name" : value.attribution;
|
|
380
|
+
if (attribution !== "name" && attribution !== "none") {
|
|
381
|
+
report("invalid-inbox", "inbox.attribution", 'inbox.attribution takes "name", the default, which signs a member\'s reply with their ' +
|
|
382
|
+
'name, or "none".');
|
|
383
|
+
}
|
|
377
384
|
const declared = new Set(declaredRoles.map((candidate) => candidate.name));
|
|
378
385
|
if (guests) {
|
|
379
386
|
declared.add(GUEST_ROLE);
|
|
@@ -394,7 +401,9 @@ chatChannels, report) {
|
|
|
394
401
|
roles.push(name);
|
|
395
402
|
}
|
|
396
403
|
});
|
|
397
|
-
return valid && takeover !== undefined
|
|
404
|
+
return valid && takeover !== undefined && (attribution === "name" || attribution === "none")
|
|
405
|
+
? { roles, takeover, attribution }
|
|
406
|
+
: undefined;
|
|
398
407
|
}
|
|
399
408
|
/**
|
|
400
409
|
* `inbox.takeover`: the channels whose private chats staff may take over from the agent, each a
|
package/dist/chat.d.ts
CHANGED
|
@@ -18,6 +18,12 @@ export interface InboxOptions<R = unknown> {
|
|
|
18
18
|
readonly takeover?: {
|
|
19
19
|
readonly channels?: ReadonlyArray<string>;
|
|
20
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* Whether a member's own reply to the person, from their session in the app, carries their name
|
|
23
|
+
* as `chat.attribution` lays it out: `"name"`, the default, or `"none"`, sent and archived as
|
|
24
|
+
* written and still the member's message. Every other post stays signed.
|
|
25
|
+
*/
|
|
26
|
+
readonly attribution?: "name" | "none";
|
|
21
27
|
}
|
|
22
28
|
import { Context, Effect, Schema } from "effect";
|
|
23
29
|
import type { ActionError } from "./errors.js";
|
package/dist/manifest.d.ts
CHANGED
|
@@ -92,7 +92,9 @@ import { type ResolvedGuest, type ResolvedSignInOptions, type SignInPolicy } fro
|
|
|
92
92
|
* Within version 15, the top-level `inbox`, written only when declared, holds the wire names of the
|
|
93
93
|
* `roles` whose people's private chats the agent registers as `agent_chat` records of kind
|
|
94
94
|
* `private`, and in `takeover.channels` the channels whose chats staff may take over from the
|
|
95
|
-
* agent. Older readers ignore it, register none and let none be taken over.
|
|
95
|
+
* agent. Older readers ignore it, register none and let none be taken over. `inbox` may carry
|
|
96
|
+
* `attribution: "none"`, written only when declared: a member's own reply in the inbox is sent and
|
|
97
|
+
* archived without their name. Older readers ignore it and sign the reply.
|
|
96
98
|
* Within version 15, a webhook trigger's `signature` may have scheme `hmac` and carry the provider's
|
|
97
99
|
* format, written only when declared. Older readers present the scheme and ignore the format; an
|
|
98
100
|
* older publication check refuses the scheme. A signature may carry `generated: true` instead of
|
|
@@ -1306,16 +1308,18 @@ export declare const OntologyManifestWire: Schema.encodeKeys<Schema.Struct<{
|
|
|
1306
1308
|
}>>;
|
|
1307
1309
|
}>>;
|
|
1308
1310
|
/**
|
|
1309
|
-
* Whose private chats join the inbox, within version 15: the wire names of their roles,
|
|
1310
|
-
* channels whose chats staff may take over from the agent
|
|
1311
|
-
*
|
|
1312
|
-
*
|
|
1311
|
+
* Whose private chats join the inbox, within version 15: the wire names of their roles, the
|
|
1312
|
+
* channels whose chats staff may take over from the agent, and `attribution: "none"` when a
|
|
1313
|
+
* member's own reply there goes without their name. Written only when declared; absent
|
|
1314
|
+
* registers no private chat, absent `takeover` lets no chat be taken over, absent `attribution`
|
|
1315
|
+
* signs replies, and older readers ignore all three.
|
|
1313
1316
|
*/
|
|
1314
1317
|
readonly inbox: Schema.optionalKey<Schema.Struct<{
|
|
1315
1318
|
readonly roles: Schema.$Array<Schema.String>;
|
|
1316
1319
|
readonly takeover: Schema.optionalKey<Schema.Struct<{
|
|
1317
1320
|
readonly channels: Schema.$Array<Schema.String>;
|
|
1318
1321
|
}>>;
|
|
1322
|
+
readonly attribution: Schema.optionalKey<Schema.Literals<readonly ["name", "none"]>>;
|
|
1319
1323
|
}>>;
|
|
1320
1324
|
/**
|
|
1321
1325
|
* The metrics of the model, since version 8. Written only when there are some; absent reads as
|
|
@@ -1796,6 +1800,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
1796
1800
|
} | undefined;
|
|
1797
1801
|
readonly inbox?: {
|
|
1798
1802
|
readonly roles: readonly string[];
|
|
1803
|
+
readonly attribution?: "name" | "none" | undefined;
|
|
1799
1804
|
readonly takeover?: {
|
|
1800
1805
|
readonly channels: readonly string[];
|
|
1801
1806
|
} | undefined;
|
|
@@ -2149,6 +2154,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
2149
2154
|
} | undefined;
|
|
2150
2155
|
readonly inbox?: {
|
|
2151
2156
|
readonly roles: readonly string[];
|
|
2157
|
+
readonly attribution?: "name" | "none" | undefined;
|
|
2152
2158
|
readonly takeover?: {
|
|
2153
2159
|
readonly channels: readonly string[];
|
|
2154
2160
|
} | undefined;
|
|
@@ -2465,6 +2471,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
2465
2471
|
} | undefined;
|
|
2466
2472
|
readonly inbox?: {
|
|
2467
2473
|
readonly roles: readonly string[];
|
|
2474
|
+
readonly attribution?: "name" | "none" | undefined;
|
|
2468
2475
|
readonly takeover?: {
|
|
2469
2476
|
readonly channels: readonly string[];
|
|
2470
2477
|
} | undefined;
|
|
@@ -2855,6 +2862,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
2855
2862
|
} | undefined;
|
|
2856
2863
|
readonly inbox?: {
|
|
2857
2864
|
readonly roles: readonly string[];
|
|
2865
|
+
readonly attribution?: "name" | "none" | undefined;
|
|
2858
2866
|
readonly takeover?: {
|
|
2859
2867
|
readonly channels: readonly string[];
|
|
2860
2868
|
} | undefined;
|
|
@@ -3207,16 +3215,18 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
3207
3215
|
}>>;
|
|
3208
3216
|
}>>;
|
|
3209
3217
|
/**
|
|
3210
|
-
* Whose private chats join the inbox, within version 15: the wire names of their roles,
|
|
3211
|
-
* channels whose chats staff may take over from the agent
|
|
3212
|
-
*
|
|
3213
|
-
*
|
|
3218
|
+
* Whose private chats join the inbox, within version 15: the wire names of their roles, the
|
|
3219
|
+
* channels whose chats staff may take over from the agent, and `attribution: "none"` when a
|
|
3220
|
+
* member's own reply there goes without their name. Written only when declared; absent
|
|
3221
|
+
* registers no private chat, absent `takeover` lets no chat be taken over, absent `attribution`
|
|
3222
|
+
* signs replies, and older readers ignore all three.
|
|
3214
3223
|
*/
|
|
3215
3224
|
readonly inbox: Schema.optionalKey<Schema.Struct<{
|
|
3216
3225
|
readonly roles: Schema.$Array<Schema.String>;
|
|
3217
3226
|
readonly takeover: Schema.optionalKey<Schema.Struct<{
|
|
3218
3227
|
readonly channels: Schema.$Array<Schema.String>;
|
|
3219
3228
|
}>>;
|
|
3229
|
+
readonly attribution: Schema.optionalKey<Schema.Literals<readonly ["name", "none"]>>;
|
|
3220
3230
|
}>>;
|
|
3221
3231
|
/**
|
|
3222
3232
|
* The metrics of the model, since version 8. Written only when there are some; absent reads as
|
|
@@ -3683,16 +3693,18 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
3683
3693
|
}>>;
|
|
3684
3694
|
}>>;
|
|
3685
3695
|
/**
|
|
3686
|
-
* Whose private chats join the inbox, within version 15: the wire names of their roles,
|
|
3687
|
-
* channels whose chats staff may take over from the agent
|
|
3688
|
-
*
|
|
3689
|
-
*
|
|
3696
|
+
* Whose private chats join the inbox, within version 15: the wire names of their roles, the
|
|
3697
|
+
* channels whose chats staff may take over from the agent, and `attribution: "none"` when a
|
|
3698
|
+
* member's own reply there goes without their name. Written only when declared; absent
|
|
3699
|
+
* registers no private chat, absent `takeover` lets no chat be taken over, absent `attribution`
|
|
3700
|
+
* signs replies, and older readers ignore all three.
|
|
3690
3701
|
*/
|
|
3691
3702
|
readonly inbox: Schema.optionalKey<Schema.Struct<{
|
|
3692
3703
|
readonly roles: Schema.$Array<Schema.String>;
|
|
3693
3704
|
readonly takeover: Schema.optionalKey<Schema.Struct<{
|
|
3694
3705
|
readonly channels: Schema.$Array<Schema.String>;
|
|
3695
3706
|
}>>;
|
|
3707
|
+
readonly attribution: Schema.optionalKey<Schema.Literals<readonly ["name", "none"]>>;
|
|
3696
3708
|
}>>;
|
|
3697
3709
|
/**
|
|
3698
3710
|
* The metrics of the model, since version 8. Written only when there are some; absent reads as
|
|
@@ -4165,6 +4177,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
4165
4177
|
} | undefined;
|
|
4166
4178
|
readonly inbox?: {
|
|
4167
4179
|
readonly roles: readonly string[];
|
|
4180
|
+
readonly attribution?: "name" | "none" | undefined;
|
|
4168
4181
|
readonly takeover?: {
|
|
4169
4182
|
readonly channels: readonly string[];
|
|
4170
4183
|
} | undefined;
|
|
@@ -4518,6 +4531,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
4518
4531
|
} | undefined;
|
|
4519
4532
|
readonly inbox?: {
|
|
4520
4533
|
readonly roles: readonly string[];
|
|
4534
|
+
readonly attribution?: "name" | "none" | undefined;
|
|
4521
4535
|
readonly takeover?: {
|
|
4522
4536
|
readonly channels: readonly string[];
|
|
4523
4537
|
} | undefined;
|
|
@@ -4877,6 +4891,7 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
|
|
|
4877
4891
|
} | undefined;
|
|
4878
4892
|
readonly inbox?: {
|
|
4879
4893
|
readonly roles: readonly string[];
|
|
4894
|
+
readonly attribution?: "name" | "none" | undefined;
|
|
4880
4895
|
readonly takeover?: {
|
|
4881
4896
|
readonly channels: readonly string[];
|
|
4882
4897
|
} | undefined;
|
|
@@ -5230,6 +5245,7 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
|
|
|
5230
5245
|
} | undefined;
|
|
5231
5246
|
readonly inbox?: {
|
|
5232
5247
|
readonly roles: readonly string[];
|
|
5248
|
+
readonly attribution?: "name" | "none" | undefined;
|
|
5233
5249
|
readonly takeover?: {
|
|
5234
5250
|
readonly channels: readonly string[];
|
|
5235
5251
|
} | undefined;
|
|
@@ -5286,6 +5302,8 @@ export declare function signUpRolesOf(manifest: Pick<OntologyManifest, "signIn">
|
|
|
5286
5302
|
export declare function inboxRolesOf(manifest: Pick<OntologyManifest, "inbox">): ReadonlySet<string>;
|
|
5287
5303
|
/** The channels whose private chats staff may take over from the agent; empty without any. */
|
|
5288
5304
|
export declare function takeoverChannelsOf(manifest: Pick<OntologyManifest, "inbox">): ReadonlySet<string>;
|
|
5305
|
+
/** Whether a member's own reply in the inbox carries their name: `name` unless declared `none`. */
|
|
5306
|
+
export declare function inboxAttributionOf(manifest: Pick<OntologyManifest, "inbox">): "name" | "none";
|
|
5289
5307
|
/**
|
|
5290
5308
|
* The account providers people write from on the channels staff take chats over on: a platform
|
|
5291
5309
|
* channel's kind, whose accounts every channel of the kind shares, and `channel:<name>` for a
|
|
@@ -5349,6 +5367,7 @@ export declare function buildManifest(input: {
|
|
|
5349
5367
|
readonly takeover: {
|
|
5350
5368
|
readonly channels: ReadonlyArray<string>;
|
|
5351
5369
|
};
|
|
5370
|
+
readonly attribution?: "name" | "none";
|
|
5352
5371
|
};
|
|
5353
5372
|
readonly entities: ReadonlyArray<ResolvedEntity>;
|
|
5354
5373
|
readonly roles: ReadonlyArray<Role>;
|
package/dist/manifest.js
CHANGED
|
@@ -93,7 +93,9 @@ import { CHANNEL_PROVIDERS, DEFAULT_SIGN_IN_POLICY, isGuestBotCheckScheme, isGue
|
|
|
93
93
|
* Within version 15, the top-level `inbox`, written only when declared, holds the wire names of the
|
|
94
94
|
* `roles` whose people's private chats the agent registers as `agent_chat` records of kind
|
|
95
95
|
* `private`, and in `takeover.channels` the channels whose chats staff may take over from the
|
|
96
|
-
* agent. Older readers ignore it, register none and let none be taken over.
|
|
96
|
+
* agent. Older readers ignore it, register none and let none be taken over. `inbox` may carry
|
|
97
|
+
* `attribution: "none"`, written only when declared: a member's own reply in the inbox is sent and
|
|
98
|
+
* archived without their name. Older readers ignore it and sign the reply.
|
|
97
99
|
* Within version 15, a webhook trigger's `signature` may have scheme `hmac` and carry the provider's
|
|
98
100
|
* format, written only when declared. Older readers present the scheme and ignore the format; an
|
|
99
101
|
* older publication check refuses the scheme. A signature may carry `generated: true` instead of
|
|
@@ -610,14 +612,16 @@ const OntologyManifestModel = Schema.Struct({
|
|
|
610
612
|
})),
|
|
611
613
|
})),
|
|
612
614
|
/**
|
|
613
|
-
* Whose private chats join the inbox, within version 15: the wire names of their roles,
|
|
614
|
-
* channels whose chats staff may take over from the agent
|
|
615
|
-
*
|
|
616
|
-
*
|
|
615
|
+
* Whose private chats join the inbox, within version 15: the wire names of their roles, the
|
|
616
|
+
* channels whose chats staff may take over from the agent, and `attribution: "none"` when a
|
|
617
|
+
* member's own reply there goes without their name. Written only when declared; absent
|
|
618
|
+
* registers no private chat, absent `takeover` lets no chat be taken over, absent `attribution`
|
|
619
|
+
* signs replies, and older readers ignore all three.
|
|
617
620
|
*/
|
|
618
621
|
inbox: Schema.optionalKey(Schema.Struct({
|
|
619
622
|
roles: Schema.Array(Schema.String),
|
|
620
623
|
takeover: Schema.optionalKey(Schema.Struct({ channels: Schema.Array(Schema.String) })),
|
|
624
|
+
attribution: Schema.optionalKey(Schema.Literals(["name", "none"])),
|
|
621
625
|
})),
|
|
622
626
|
/**
|
|
623
627
|
* The metrics of the model, since version 8. Written only when there are some; absent reads as
|
|
@@ -721,6 +725,10 @@ export function inboxRolesOf(manifest) {
|
|
|
721
725
|
export function takeoverChannelsOf(manifest) {
|
|
722
726
|
return new Set(manifest.inbox?.takeover?.channels ?? []);
|
|
723
727
|
}
|
|
728
|
+
/** Whether a member's own reply in the inbox carries their name: `name` unless declared `none`. */
|
|
729
|
+
export function inboxAttributionOf(manifest) {
|
|
730
|
+
return manifest.inbox?.attribution === "none" ? "none" : "name";
|
|
731
|
+
}
|
|
724
732
|
/**
|
|
725
733
|
* The account providers people write from on the channels staff take chats over on: a platform
|
|
726
734
|
* channel's kind, whose accounts every channel of the kind shares, and `channel:<name>` for a
|
|
@@ -1098,6 +1106,7 @@ export function buildManifest(input) {
|
|
|
1098
1106
|
inbox: {
|
|
1099
1107
|
roles: [...input.inbox.roles],
|
|
1100
1108
|
takeover: { channels: [...input.inbox.takeover.channels] },
|
|
1109
|
+
...(input.inbox.attribution === "none" ? { attribution: "none" } : {}),
|
|
1101
1110
|
},
|
|
1102
1111
|
}),
|
|
1103
1112
|
...(connections.length > 0
|
package/dist/migrate/model.d.ts
CHANGED
|
@@ -595,6 +595,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
595
595
|
} | undefined;
|
|
596
596
|
readonly inbox?: {
|
|
597
597
|
readonly roles: readonly string[];
|
|
598
|
+
readonly attribution?: "name" | "none" | undefined;
|
|
598
599
|
readonly takeover?: {
|
|
599
600
|
readonly channels: readonly string[];
|
|
600
601
|
} | undefined;
|
|
@@ -948,6 +949,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
948
949
|
} | undefined;
|
|
949
950
|
readonly inbox?: {
|
|
950
951
|
readonly roles: readonly string[];
|
|
952
|
+
readonly attribution?: "name" | "none" | undefined;
|
|
951
953
|
readonly takeover?: {
|
|
952
954
|
readonly channels: readonly string[];
|
|
953
955
|
} | undefined;
|
|
@@ -1264,6 +1266,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1264
1266
|
} | undefined;
|
|
1265
1267
|
readonly inbox?: {
|
|
1266
1268
|
readonly roles: readonly string[];
|
|
1269
|
+
readonly attribution?: "name" | "none" | undefined;
|
|
1267
1270
|
readonly takeover?: {
|
|
1268
1271
|
readonly channels: readonly string[];
|
|
1269
1272
|
} | undefined;
|
|
@@ -1654,6 +1657,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1654
1657
|
} | undefined;
|
|
1655
1658
|
readonly inbox?: {
|
|
1656
1659
|
readonly roles: readonly string[];
|
|
1660
|
+
readonly attribution?: "name" | "none" | undefined;
|
|
1657
1661
|
readonly takeover?: {
|
|
1658
1662
|
readonly channels: readonly string[];
|
|
1659
1663
|
} | undefined;
|
|
@@ -1944,6 +1948,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1944
1948
|
readonly takeover: Schema.optionalKey<Schema.Struct<{
|
|
1945
1949
|
readonly channels: Schema.$Array<Schema.String>;
|
|
1946
1950
|
}>>;
|
|
1951
|
+
readonly attribution: Schema.optionalKey<Schema.Literals<readonly ["name", "none"]>>;
|
|
1947
1952
|
}>>;
|
|
1948
1953
|
readonly metrics: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
1949
1954
|
readonly name: Schema.String;
|
|
@@ -2293,6 +2298,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2293
2298
|
readonly takeover: Schema.optionalKey<Schema.Struct<{
|
|
2294
2299
|
readonly channels: Schema.$Array<Schema.String>;
|
|
2295
2300
|
}>>;
|
|
2301
|
+
readonly attribution: Schema.optionalKey<Schema.Literals<readonly ["name", "none"]>>;
|
|
2296
2302
|
}>>;
|
|
2297
2303
|
readonly metrics: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
2298
2304
|
readonly name: Schema.String;
|
|
@@ -2718,6 +2724,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2718
2724
|
} | undefined;
|
|
2719
2725
|
readonly inbox?: {
|
|
2720
2726
|
readonly roles: readonly string[];
|
|
2727
|
+
readonly attribution?: "name" | "none" | undefined;
|
|
2721
2728
|
readonly takeover?: {
|
|
2722
2729
|
readonly channels: readonly string[];
|
|
2723
2730
|
} | undefined;
|
|
@@ -3071,6 +3078,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
3071
3078
|
} | undefined;
|
|
3072
3079
|
readonly inbox?: {
|
|
3073
3080
|
readonly roles: readonly string[];
|
|
3081
|
+
readonly attribution?: "name" | "none" | undefined;
|
|
3074
3082
|
readonly takeover?: {
|
|
3075
3083
|
readonly channels: readonly string[];
|
|
3076
3084
|
} | undefined;
|
|
@@ -22,5 +22,6 @@ export interface ChatRequester {
|
|
|
22
22
|
readonly via: "oauth" | "hq" | "service";
|
|
23
23
|
readonly clientId: string | null;
|
|
24
24
|
readonly clientName: string | null;
|
|
25
|
+
/** Empty only for a member's own reply in the inbox, unsigned where the inbox says `none`. */
|
|
25
26
|
readonly attribution: string;
|
|
26
27
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { validateTelegramPreviews } from "../../telegram.js";
|
|
2
|
-
import { takeoverChannelsOf } from "../../manifest.js";
|
|
2
|
+
import { inboxAttributionOf, takeoverChannelsOf } from "../../manifest.js";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
4
|
import { Cause, Effect } from "effect";
|
|
5
5
|
import { chatOperationId, chatPreviewDigest, } from "../../chat.js";
|
|
@@ -51,6 +51,7 @@ chats) {
|
|
|
51
51
|
const attribution = ontology.config.chat?.attribution;
|
|
52
52
|
const separator = attribution?.separator ?? "\n\n";
|
|
53
53
|
const takeoverChannels = takeoverChannelsOf(ontology.manifest);
|
|
54
|
+
const unsignedReplies = inboxAttributionOf(ontology.manifest) === "none";
|
|
54
55
|
const providers = listedChatProviders(ontology.manifest.chat);
|
|
55
56
|
const destination = ontology.manifest.chat?.telegram?.connection;
|
|
56
57
|
const destinationPreviews = previews.settings?.connection === destination ? previews : { ownOrigins: previews.ownOrigins };
|
|
@@ -87,7 +88,8 @@ chats) {
|
|
|
87
88
|
}
|
|
88
89
|
const inbox = yield* inboxChat(input.chat, permission);
|
|
89
90
|
// A member answers a person in the inbox from their own session in the app, signed with
|
|
90
|
-
// their name as the workspace's attribution lays it out
|
|
91
|
+
// their name as the workspace's attribution lays it out, or unsigned where the inbox's
|
|
92
|
+
// `attribution` is `none`: only this reply, never a post to a group or by another caller.
|
|
91
93
|
const requester = (inbox !== undefined || asAgent) &&
|
|
92
94
|
context.caller.kind === "member" &&
|
|
93
95
|
context.caller.subjectId === context.principal.id &&
|
|
@@ -99,7 +101,9 @@ chats) {
|
|
|
99
101
|
via: "hq",
|
|
100
102
|
clientId: null,
|
|
101
103
|
clientName: null,
|
|
102
|
-
attribution:
|
|
104
|
+
attribution: inbox !== undefined && !asAgent && unsignedReplies
|
|
105
|
+
? ""
|
|
106
|
+
: (attribution?.template ?? "{name}").replace(/\{(name|client)\}/g, (_, key) => (key === "name" ? String(user.name) : "")),
|
|
103
107
|
}
|
|
104
108
|
: yield* deliveryRequester(context.caller, context.principal, String(user.name), attribution);
|
|
105
109
|
if (context.caller.kind === "runtime" &&
|
|
@@ -152,7 +156,8 @@ chats) {
|
|
|
152
156
|
message: "Chat posting requires a configured connection for the chat's provider.",
|
|
153
157
|
});
|
|
154
158
|
}
|
|
155
|
-
// The agent's own message carries no attribution, as a reply a member approved does not
|
|
159
|
+
// The agent's own message carries no attribution, as a reply a member approved does not,
|
|
160
|
+
// and neither does a member's unsigned reply in the inbox; without one, no separator.
|
|
156
161
|
const signature = asAgent ? "" : requester.attribution;
|
|
157
162
|
const invalid = () => new ActionRejected({
|
|
158
163
|
message: "The exact attributed message or reply target is invalid or too long. Nothing was truncated.",
|
|
@@ -243,7 +248,7 @@ chats) {
|
|
|
243
248
|
}
|
|
244
249
|
const text = input.text ?? "";
|
|
245
250
|
const { finalText, plainText } = yield* Effect.try({
|
|
246
|
-
try: () => provider.render(text, signature,
|
|
251
|
+
try: () => provider.render(text, signature, signature === "" ? "" : separator),
|
|
247
252
|
catch: (cause) => new ActionRejected({ message: "The Markdown could not be rendered.", cause }),
|
|
248
253
|
});
|
|
249
254
|
if (!text.trim() ||
|
|
@@ -534,8 +539,11 @@ chats) {
|
|
|
534
539
|
sessionId: context.envelope?.session_id ?? null,
|
|
535
540
|
turnId: null,
|
|
536
541
|
// The claim binds text immutably. Keep the source here and the actual wire payload
|
|
537
|
-
// in argsSummary, which can record the plain retry without changing that binding.
|
|
538
|
-
|
|
542
|
+
// in argsSummary, which can record the plain retry without changing that binding. A
|
|
543
|
+
// message without attribution is kept as written.
|
|
544
|
+
text: preview.attribution === ""
|
|
545
|
+
? preview.text
|
|
546
|
+
: `${preview.text}${separator}${preview.attribution}`,
|
|
539
547
|
decision: null,
|
|
540
548
|
reason: null,
|
|
541
549
|
toolCallId: null,
|
|
@@ -571,7 +579,7 @@ chats) {
|
|
|
571
579
|
destination: target,
|
|
572
580
|
connection,
|
|
573
581
|
text: preview.text,
|
|
574
|
-
separator,
|
|
582
|
+
separator: preview.attribution === "" ? "" : separator,
|
|
575
583
|
attribution: preview.attribution,
|
|
576
584
|
finalText: preview.finalText,
|
|
577
585
|
previews: destinationPreviews,
|
|
@@ -39,7 +39,10 @@ export interface ChatSend {
|
|
|
39
39
|
readonly finalText: string;
|
|
40
40
|
readonly plainText: string;
|
|
41
41
|
readonly replyTo: string | null;
|
|
42
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* The chat's thread to send in: a Telegram group's forum topic, the Slack thread of a message
|
|
44
|
+
* that replies to none, the person's Gmail thread, or a workspace channel's; WhatsApp ignores it.
|
|
45
|
+
*/
|
|
43
46
|
readonly threadId?: string | null;
|
|
44
47
|
/** Telegram's link preview settings for its destination connection; others ignore them. */
|
|
45
48
|
readonly previews?: TelegramPreviewContext;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { type ChatProvider, type ChatSend, type ProviderOutcome } from "./provider.js";
|
|
3
3
|
/**
|
|
4
|
-
* One `chat.postMessage` through the connection's `web` API, never retried
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* One `chat.postMessage` through the connection's `web` API, never retried, in the thread of the
|
|
5
|
+
* message it replies to, else in the chat's thread, such as the one a reviewed reply answers.
|
|
6
|
+
* Slack's own refusal (`ok: false` with an error code) is definite; a timeout, a 5xx, an
|
|
7
|
+
* unparseable answer or a success that does not name the message, or its thread, is uncertain.
|
|
7
8
|
*/
|
|
8
9
|
export declare function sendSlack(input: ChatSend): Effect.Effect<ProviderOutcome>;
|
|
9
10
|
/** Slack: the member's Markdown as `markdown_text`, in a channel or a member's direct message. */
|
|
@@ -13,13 +13,16 @@ const POSSIBLY_POSTED = new Set([
|
|
|
13
13
|
"service_unavailable",
|
|
14
14
|
]);
|
|
15
15
|
/**
|
|
16
|
-
* One `chat.postMessage` through the connection's `web` API, never retried
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
* One `chat.postMessage` through the connection's `web` API, never retried, in the thread of the
|
|
17
|
+
* message it replies to, else in the chat's thread, such as the one a reviewed reply answers.
|
|
18
|
+
* Slack's own refusal (`ok: false` with an error code) is definite; a timeout, a 5xx, an
|
|
19
|
+
* unparseable answer or a success that does not name the message, or its thread, is uncertain.
|
|
19
20
|
*/
|
|
20
21
|
export function sendSlack(input) {
|
|
21
22
|
return Effect.gen(function* () {
|
|
22
23
|
const payload = { markdown_text: input.finalText };
|
|
24
|
+
const thread = input.replyTo ??
|
|
25
|
+
(typeof input.threadId === "string" && SLACK_TS.test(input.threadId) ? input.threadId : null);
|
|
23
26
|
const result = yield* input.transport
|
|
24
27
|
.request({
|
|
25
28
|
connection: input.connection,
|
|
@@ -30,7 +33,7 @@ export function sendSlack(input) {
|
|
|
30
33
|
body: new TextEncoder().encode(JSON.stringify({
|
|
31
34
|
channel: input.destination.external_id,
|
|
32
35
|
...payload,
|
|
33
|
-
...(
|
|
36
|
+
...(thread === null ? {} : { thread_ts: thread }),
|
|
34
37
|
})),
|
|
35
38
|
})
|
|
36
39
|
.pipe(Effect.exit);
|
|
@@ -70,7 +73,7 @@ export function sendSlack(input) {
|
|
|
70
73
|
body.channel === "" ||
|
|
71
74
|
// A member's direct message is posted to their user id and answers with its `D…` channel.
|
|
72
75
|
(input.destination.kind === "group" && body.channel !== input.destination.external_id) ||
|
|
73
|
-
(
|
|
76
|
+
(thread !== null && message.thread_ts !== thread)) {
|
|
74
77
|
return uncertain(new Error("Slack success could not be verified."));
|
|
75
78
|
}
|
|
76
79
|
return { payload, status: "sent", messageId: body.ts, url: null };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ChatRefusal } from "./provider.js";
|
|
2
|
+
/**
|
|
3
|
+
* Meta's refusals that code acts on: 131047, the person last wrote more than 24 hours ago, so only a
|
|
4
|
+
* template reaches them; 131026, the message cannot be delivered to the number; 131050, the person
|
|
5
|
+
* stopped marketing messages. Meta answers them when it refuses a message, or reports them later in
|
|
6
|
+
* a `failed` delivery status of a message it accepted.
|
|
7
|
+
*/
|
|
8
|
+
export declare const REFUSALS: Readonly<Record<number, ChatRefusal>>;
|
|
9
|
+
/** The id Meta gives an accepted message, which its delivery statuses name. */
|
|
10
|
+
export declare const WAMID: RegExp;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Meta's refusals that code acts on: 131047, the person last wrote more than 24 hours ago, so only a
|
|
3
|
+
* template reaches them; 131026, the message cannot be delivered to the number; 131050, the person
|
|
4
|
+
* stopped marketing messages. Meta answers them when it refuses a message, or reports them later in
|
|
5
|
+
* a `failed` delivery status of a message it accepted.
|
|
6
|
+
*/
|
|
7
|
+
export const REFUSALS = {
|
|
8
|
+
131047: "outside_reply_window",
|
|
9
|
+
131026: "recipient_unreachable",
|
|
10
|
+
131050: "recipient_opted_out",
|
|
11
|
+
};
|
|
12
|
+
/** The id Meta gives an accepted message, which its delivery statuses name. */
|
|
13
|
+
export const WAMID = /^wamid\.[A-Za-z0-9+/=_-]{1,512}$/;
|
|
@@ -1,21 +1,10 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { renderWhatsApp, WHATSAPP_MESSAGE_LIMIT } from "../../../whatsapp.js";
|
|
3
3
|
import { whatsappTemplate } from "./whatsapp-template.js";
|
|
4
|
+
import { REFUSALS, WAMID } from "./whatsapp-refusals.js";
|
|
4
5
|
import { record, transportFailure, } from "./provider.js";
|
|
5
6
|
/** A WhatsApp id: the member's number, digits only. */
|
|
6
7
|
const WA_ID = /^[1-9][0-9]{5,19}$/;
|
|
7
|
-
/**
|
|
8
|
-
* Meta's refusals that code acts on: 131047, the person last wrote more than 24 hours ago, so only a
|
|
9
|
-
* template reaches them; 131026, the message cannot be delivered to the number; 131050, the person
|
|
10
|
-
* stopped marketing messages.
|
|
11
|
-
*/
|
|
12
|
-
const REFUSALS = {
|
|
13
|
-
131047: "outside_reply_window",
|
|
14
|
-
131026: "recipient_unreachable",
|
|
15
|
-
131050: "recipient_opted_out",
|
|
16
|
-
};
|
|
17
|
-
/** The id Meta gives an accepted message. */
|
|
18
|
-
const WAMID = /^wamid\.[A-Za-z0-9+/=_-]{1,512}$/;
|
|
19
8
|
/**
|
|
20
9
|
* One text message from the workspace's number, `POST /phone/messages` on the connection's
|
|
21
10
|
* `graph` API, never retried. A Graph refusal with an error code, such as 131047 outside the
|
|
@@ -552,6 +552,7 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
|
|
|
552
552
|
readonly takeover: Schema.optionalKey<Schema.Struct<{
|
|
553
553
|
readonly channels: Schema.$Array<Schema.String>;
|
|
554
554
|
}>>;
|
|
555
|
+
readonly attribution: Schema.optionalKey<Schema.Literals<readonly ["name", "none"]>>;
|
|
555
556
|
}>>;
|
|
556
557
|
readonly metrics: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
557
558
|
readonly name: Schema.String;
|
|
@@ -914,6 +915,7 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
|
|
|
914
915
|
readonly takeover: Schema.optionalKey<Schema.Struct<{
|
|
915
916
|
readonly channels: Schema.$Array<Schema.String>;
|
|
916
917
|
}>>;
|
|
918
|
+
readonly attribution: Schema.optionalKey<Schema.Literals<readonly ["name", "none"]>>;
|
|
917
919
|
}>>>;
|
|
918
920
|
readonly metrics: Schema.toEncoded<Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
919
921
|
readonly name: Schema.String;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/ontology",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.139.1",
|
|
4
4
|
"description": "Define a SegmentStream workspace app's ontology: entities, relationships, roles and actions, written with Effect.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "SegmentStream",
|