@effect/chat-slack 0.0.0 → 4.1.6
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/AGENTS.md +434 -0
- package/CLAUDE.md +434 -0
- package/LICENSE +21 -0
- package/README.md +47 -0
- package/ai-docs/README.md +44 -0
- package/ai-docs/package.json +36 -0
- package/ai-docs/src/01_effect/01_basics/01_effect-gen.ts +30 -0
- package/ai-docs/src/01_effect/01_basics/02_effect-fn.ts +52 -0
- package/ai-docs/src/01_effect/01_basics/10_creating-effects.ts +74 -0
- package/ai-docs/src/01_effect/01_basics/index.md +7 -0
- package/ai-docs/src/01_effect/02_schema/10_schema-basics.ts +43 -0
- package/ai-docs/src/01_effect/02_schema/index.md +7 -0
- package/ai-docs/src/01_effect/03_services/01_service.ts +45 -0
- package/ai-docs/src/01_effect/03_services/10_reference.ts +10 -0
- package/ai-docs/src/01_effect/03_services/20_layer-composition.ts +70 -0
- package/ai-docs/src/01_effect/03_services/20_layer-unwrap.ts +66 -0
- package/ai-docs/src/01_effect/03_services/index.md +5 -0
- package/ai-docs/src/01_effect/04_errors/01_error-handling.ts +30 -0
- package/ai-docs/src/01_effect/04_errors/10_catch-tags.ts +24 -0
- package/ai-docs/src/01_effect/04_errors/20_reason-errors.ts +64 -0
- package/ai-docs/src/01_effect/04_errors/index.md +1 -0
- package/ai-docs/src/01_effect/05_resources/10_acquire-release.ts +105 -0
- package/ai-docs/src/01_effect/05_resources/20_layer-side-effects.ts +31 -0
- package/ai-docs/src/01_effect/05_resources/30_layer-map.ts +86 -0
- package/ai-docs/src/01_effect/05_resources/index.md +3 -0
- package/ai-docs/src/01_effect/06_running/10_run-main.ts +30 -0
- package/ai-docs/src/01_effect/06_running/20_layer-launch.ts +27 -0
- package/ai-docs/src/01_effect/06_running/index.md +1 -0
- package/ai-docs/src/01_effect/07_pubsub/10_pubsub.ts +56 -0
- package/ai-docs/src/01_effect/07_pubsub/index.md +3 -0
- package/ai-docs/src/03_stream/10_creating-streams.ts +103 -0
- package/ai-docs/src/03_stream/20_consuming-streams.ts +137 -0
- package/ai-docs/src/03_stream/30_encoding.ts +163 -0
- package/ai-docs/src/03_stream/index.md +4 -0
- package/ai-docs/src/04_integration/10_managed-runtime.ts +129 -0
- package/ai-docs/src/04_integration/index.md +5 -0
- package/ai-docs/src/05_batching/10_request-resolver.ts +89 -0
- package/ai-docs/src/05_batching/index.md +3 -0
- package/ai-docs/src/06_schedule/10_schedules.ts +111 -0
- package/ai-docs/src/06_schedule/index.md +3 -0
- package/ai-docs/src/07_datetime/10_creating-and-formatting.ts +30 -0
- package/ai-docs/src/07_datetime/20_time-zones.ts +44 -0
- package/ai-docs/src/07_datetime/index.md +5 -0
- package/ai-docs/src/08_observability/10_logging.ts +66 -0
- package/ai-docs/src/08_observability/20_otlp-tracing.ts +95 -0
- package/ai-docs/src/08_observability/index.md +7 -0
- package/ai-docs/src/09_testing/10_effect-tests.ts +55 -0
- package/ai-docs/src/09_testing/20_layer-tests.ts +138 -0
- package/ai-docs/src/09_testing/index.md +1 -0
- package/ai-docs/src/10_predicate/01_basics.ts +14 -0
- package/ai-docs/src/10_predicate/index.md +9 -0
- package/ai-docs/src/40_sql/10_basics.ts +175 -0
- package/ai-docs/src/40_sql/index.md +6 -0
- package/ai-docs/src/50_http-client/10_basics.ts +102 -0
- package/ai-docs/src/50_http-client/index.md +3 -0
- package/ai-docs/src/51_http-server/10_basics.ts +118 -0
- package/ai-docs/src/51_http-server/20_testing.ts +100 -0
- package/ai-docs/src/51_http-server/fixtures/api/Api.ts +14 -0
- package/ai-docs/src/51_http-server/fixtures/api/Authorization.ts +36 -0
- package/ai-docs/src/51_http-server/fixtures/api/System.ts +10 -0
- package/ai-docs/src/51_http-server/fixtures/api/Users.ts +107 -0
- package/ai-docs/src/51_http-server/fixtures/domain/User.ts +21 -0
- package/ai-docs/src/51_http-server/fixtures/domain/UserErrors.ts +22 -0
- package/ai-docs/src/51_http-server/fixtures/server/Authorization.ts +37 -0
- package/ai-docs/src/51_http-server/fixtures/server/Users/http.ts +80 -0
- package/ai-docs/src/51_http-server/fixtures/server/Users.ts +183 -0
- package/ai-docs/src/51_http-server/index.md +3 -0
- package/ai-docs/src/52_graphql/10_basics.ts +117 -0
- package/ai-docs/src/52_graphql/20_testing.ts +45 -0
- package/ai-docs/src/52_graphql/30_batching.ts +118 -0
- package/ai-docs/src/52_graphql/40_aliased-batching.ts +124 -0
- package/ai-docs/src/52_graphql/50_errors-and-retries.ts +74 -0
- package/ai-docs/src/52_graphql/index.md +6 -0
- package/ai-docs/src/60_child-process/10_working-with-child-processes.ts +117 -0
- package/ai-docs/src/60_child-process/index.md +3 -0
- package/ai-docs/src/70_cli/10_basics.ts +162 -0
- package/ai-docs/src/70_cli/index.md +5 -0
- package/ai-docs/src/71_ai/10_language-model.ts +156 -0
- package/ai-docs/src/71_ai/20_tools.ts +226 -0
- package/ai-docs/src/71_ai/30_chat.ts +158 -0
- package/ai-docs/src/71_ai/fixtures/domain/LaunchPlan.ts +9 -0
- package/ai-docs/src/71_ai/index.md +5 -0
- package/ai-docs/src/80_cluster/10_entities.ts +97 -0
- package/ai-docs/src/80_cluster/index.md +4 -0
- package/ai-docs/src/index.md +10 -0
- package/ai-docs/tsconfig.json +28 -0
- package/dist/SlackChat.d.ts +500 -0
- package/dist/SlackChat.d.ts.map +1 -0
- package/dist/SlackChat.js +512 -0
- package/dist/SlackChat.js.map +1 -0
- package/dist/SlackWebApi.d.ts +74 -0
- package/dist/SlackWebApi.d.ts.map +1 -0
- package/dist/SlackWebApi.js +96 -0
- package/dist/SlackWebApi.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/actions.d.ts +2 -0
- package/dist/internal/actions.d.ts.map +1 -0
- package/dist/internal/actions.js +169 -0
- package/dist/internal/actions.js.map +1 -0
- package/dist/internal/adapter.d.ts +2 -0
- package/dist/internal/adapter.d.ts.map +1 -0
- package/dist/internal/adapter.js +836 -0
- package/dist/internal/adapter.js.map +1 -0
- package/dist/internal/address.d.ts +2 -0
- package/dist/internal/address.d.ts.map +1 -0
- package/dist/internal/address.js +36 -0
- package/dist/internal/address.js.map +1 -0
- package/dist/internal/emoji.d.ts +2 -0
- package/dist/internal/emoji.d.ts.map +1 -0
- package/dist/internal/emoji.js +207 -0
- package/dist/internal/emoji.js.map +1 -0
- package/dist/internal/emojiData.d.ts +54 -0
- package/dist/internal/emojiData.d.ts.map +1 -0
- package/dist/internal/emojiData.js +1965 -0
- package/dist/internal/emojiData.js.map +1 -0
- package/dist/internal/errors.d.ts +2 -0
- package/dist/internal/errors.d.ts.map +1 -0
- package/dist/internal/errors.js +190 -0
- package/dist/internal/errors.js.map +1 -0
- package/dist/internal/escape.d.ts +14 -0
- package/dist/internal/escape.d.ts.map +1 -0
- package/dist/internal/escape.js +413 -0
- package/dist/internal/escape.js.map +1 -0
- package/dist/internal/interactions.d.ts +2 -0
- package/dist/internal/interactions.d.ts.map +1 -0
- package/dist/internal/interactions.js +389 -0
- package/dist/internal/interactions.js.map +1 -0
- package/dist/internal/json.d.ts +2 -0
- package/dist/internal/json.d.ts.map +1 -0
- package/dist/internal/json.js +30 -0
- package/dist/internal/json.js.map +1 -0
- package/dist/internal/length.d.ts +2 -0
- package/dist/internal/length.d.ts.map +1 -0
- package/dist/internal/length.js +33 -0
- package/dist/internal/length.js.map +1 -0
- package/dist/internal/mentions.d.ts +2 -0
- package/dist/internal/mentions.d.ts.map +1 -0
- package/dist/internal/mentions.js +229 -0
- package/dist/internal/mentions.js.map +1 -0
- package/dist/internal/normalize.d.ts +2 -0
- package/dist/internal/normalize.d.ts.map +1 -0
- package/dist/internal/normalize.js +211 -0
- package/dist/internal/normalize.js.map +1 -0
- package/dist/internal/options.d.ts +2 -0
- package/dist/internal/options.d.ts.map +1 -0
- package/dist/internal/options.js +6 -0
- package/dist/internal/options.js.map +1 -0
- package/dist/internal/richText.d.ts +2 -0
- package/dist/internal/richText.d.ts.map +1 -0
- package/dist/internal/richText.js +346 -0
- package/dist/internal/richText.js.map +1 -0
- package/dist/internal/text.d.ts +2 -0
- package/dist/internal/text.d.ts.map +1 -0
- package/dist/internal/text.js +239 -0
- package/dist/internal/text.js.map +1 -0
- package/dist/internal/webhook.d.ts +2 -0
- package/dist/internal/webhook.d.ts.map +1 -0
- package/dist/internal/webhook.js +142 -0
- package/dist/internal/webhook.js.map +1 -0
- package/package.json +62 -1
- package/src/SlackChat.ts +640 -0
- package/src/SlackWebApi.ts +135 -0
- package/src/index.ts +18 -0
- package/src/internal/actions.ts +203 -0
- package/src/internal/adapter.ts +961 -0
- package/src/internal/address.ts +50 -0
- package/src/internal/emoji.ts +223 -0
- package/src/internal/emojiData.ts +1965 -0
- package/src/internal/errors.ts +192 -0
- package/src/internal/escape.ts +428 -0
- package/src/internal/interactions.ts +391 -0
- package/src/internal/json.ts +35 -0
- package/src/internal/length.ts +41 -0
- package/src/internal/mentions.ts +224 -0
- package/src/internal/normalize.ts +221 -0
- package/src/internal/options.ts +22 -0
- package/src/internal/richText.ts +367 -0
- package/src/internal/text.ts +252 -0
- package/src/internal/webhook.ts +199 -0
|
@@ -0,0 +1,512 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Slack adapter for `effect/chat`: the `Registry` layer, the Events API
|
|
3
|
+
* webhook, the Interactivity route for buttons and modals, the pure
|
|
4
|
+
* normalisers, address helpers and the scoped post options.
|
|
5
|
+
*
|
|
6
|
+
* **Details**
|
|
7
|
+
*
|
|
8
|
+
* - Bot token scopes: `chat:write`, `channels:history`, `groups:history`,
|
|
9
|
+
* `im:history`, `mpim:history`, `channels:read`, `groups:read`,
|
|
10
|
+
* `im:read`, `mpim:read`, `users:read`, `reactions:read`, `files:read`
|
|
11
|
+
* and `files:write`.
|
|
12
|
+
* - Event subscriptions, sent to `layerWebhook`'s path: `message.channels`,
|
|
13
|
+
* `message.groups`, `message.im`, `message.mpim`, `app_mention`,
|
|
14
|
+
* `reaction_added`, `reaction_removed` and `agent_session_stopped`.
|
|
15
|
+
* - Buttons, selects and modals need Interactivity, which is its own
|
|
16
|
+
* switch in the app settings, off by default, with its own Request URL,
|
|
17
|
+
* separate from Event Subscriptions. Point it at `layerInteractivity`'s
|
|
18
|
+
* path. With Socket Mode on, Slack sends interactions over the socket and
|
|
19
|
+
* never to the URL: pass each payload to `SlackChat.interaction` and send
|
|
20
|
+
* its result as the envelope ack's `payload`.
|
|
21
|
+
* - Slash commands need the `commands` scope. Declare each in the app
|
|
22
|
+
* manifest under `features.slash_commands`, or in the app settings under
|
|
23
|
+
* Slash Commands, with its Request URL set to `layerInteractivity`'s path.
|
|
24
|
+
* The name, less its slash, is the id of the `ChatInteraction.command`,
|
|
25
|
+
* and the manifest's description and usage hint are what Slack shows.
|
|
26
|
+
* With Socket Mode on, commands come as `slash_commands` envelopes: pass
|
|
27
|
+
* the envelope's `payload` to `SlackChat.interaction` in the same way.
|
|
28
|
+
* That path is from Slack's docs and was not run, nor were commands in
|
|
29
|
+
* Slack Connect channels or directs.
|
|
30
|
+
* - A command can't be run inside a thread: Slack doesn't offer it there.
|
|
31
|
+
* A command that acts on a thread has to be told which one. Command names are shared by every app
|
|
32
|
+
* in a workspace. "Escape channels, users, and links" is off by default;
|
|
33
|
+
* with it on, `text` carries `<@U…|name>` and `<#C…|name>` tokens.
|
|
34
|
+
* - Slack's stop button also needs the app declared as an agent with
|
|
35
|
+
* `features.agent_view` in the manifest. Slack documents that declaration
|
|
36
|
+
* as irreversible. Without it the adapter's session status calls answer
|
|
37
|
+
* `not_authorized`; it then stops making them, and replies still work.
|
|
38
|
+
* - A click on the stop button stops nothing by itself: the consumer gets a
|
|
39
|
+
* `StopRequested` and ends the reply. Until it does, the user sees a
|
|
40
|
+
* disabled button. Every click is a separate `StopRequested`, and only
|
|
41
|
+
* the first in a thread lists the open stream in `messageIds`.
|
|
42
|
+
*
|
|
43
|
+
* @stability unstable
|
|
44
|
+
* @since 4.1.5
|
|
45
|
+
*/
|
|
46
|
+
import * as ByteSize from "effect/ByteSize";
|
|
47
|
+
import { Registry } from "effect/chat/ChatAdapter";
|
|
48
|
+
import { ChatErrorReason } from "effect/chat/ChatError";
|
|
49
|
+
import { ChatHandler } from "effect/chat/ChatHandler";
|
|
50
|
+
import * as ChatInteraction from "effect/chat/ChatInteraction";
|
|
51
|
+
import { ChatThread } from "effect/chat/ChatThread";
|
|
52
|
+
import * as Context from "effect/Context";
|
|
53
|
+
import * as Duration from "effect/Duration";
|
|
54
|
+
import * as Effect from "effect/Effect";
|
|
55
|
+
import { dual } from "effect/Function";
|
|
56
|
+
import * as HttpClient from "effect/http/HttpClient";
|
|
57
|
+
import * as HttpRouter from "effect/http/HttpRouter";
|
|
58
|
+
import * as Layer from "effect/Layer";
|
|
59
|
+
import * as Option from "effect/Option";
|
|
60
|
+
import * as Schema from "effect/Schema";
|
|
61
|
+
import * as Adapter from "./internal/adapter.js";
|
|
62
|
+
import * as Address from "./internal/address.js";
|
|
63
|
+
import * as Emoji from "./internal/emoji.js";
|
|
64
|
+
import * as Errors from "./internal/errors.js";
|
|
65
|
+
import * as Interactions from "./internal/interactions.js";
|
|
66
|
+
import * as Json from "./internal/json.js";
|
|
67
|
+
import * as Mentions from "./internal/mentions.js";
|
|
68
|
+
import * as Normalize from "./internal/normalize.js";
|
|
69
|
+
import { CurrentPostOptions } from "./internal/options.js";
|
|
70
|
+
import * as Webhook from "./internal/webhook.js";
|
|
71
|
+
import { SlackWebApi } from "./SlackWebApi.js";
|
|
72
|
+
import * as WebApi from "./SlackWebApi.js";
|
|
73
|
+
/**
|
|
74
|
+
* The Slack side of the adapter, for what the core has no op for.
|
|
75
|
+
*
|
|
76
|
+
* **Details**
|
|
77
|
+
*
|
|
78
|
+
* - `botUserId` comes from `auth.test`, read once. A failed read is tried
|
|
79
|
+
* again next time.
|
|
80
|
+
* - `user` calls `users.info` each time. Nothing is cached.
|
|
81
|
+
* - `interaction` is the entry for a decoded Interactivity `payload`
|
|
82
|
+
* (`block_actions` or `view_submission`), as `DiscordChat.interaction`
|
|
83
|
+
* is for Discord, and for a slash command: the form fields of its
|
|
84
|
+
* request, or the `payload` of a `slash_commands` envelope, as one
|
|
85
|
+
* object. It normalises with `normalizeInteraction`, calls the
|
|
86
|
+
* handler through `ChatInteraction.handle` inside `deadline` (2.5
|
|
87
|
+
* seconds by default, the handler's share of Slack's 3), opens a modal
|
|
88
|
+
* with `views.open` and calls `Handler.refused` when it can't.
|
|
89
|
+
* - A modal's title is held to 24 code points, each input label to 2,000 and
|
|
90
|
+
* the modal's id to 255. These are not on the descriptor. A modal past one
|
|
91
|
+
* of them is not opened: `Handler.refused` gets `TooLarge`, and the click
|
|
92
|
+
* is still acked. A portable modal keeps its title to 24.
|
|
93
|
+
* - Slack needs a submit button on a modal with inputs, so a modal with no
|
|
94
|
+
* `submitLabel` gets the English "Submit". Pass `submitLabel` to localise
|
|
95
|
+
* it.
|
|
96
|
+
* - It succeeds with the body to answer Slack with: the JSON of the 200 on
|
|
97
|
+
* the Request URL, or the `payload` of the envelope ack on Socket Mode.
|
|
98
|
+
* For a command answered with `respond` that body is the message, with
|
|
99
|
+
* `response_type` `ephemeral` or `in_channel`, after the checks of a
|
|
100
|
+
* `post`; one that fails them goes to `Handler.refused`. A command's
|
|
101
|
+
* answer, `respond` or `followUp`, mentions nobody: `withPostOptions`
|
|
102
|
+
* does not reach it, so `<@U…>` goes out escaped and shows as text, as a
|
|
103
|
+
* `post` without `withPostOptions` does. There is no way to allow a
|
|
104
|
+
* mention in it.
|
|
105
|
+
* `undefined` is an empty answer: an ack, a close, a late click, a
|
|
106
|
+
* deferred command, a command that opened a modal, a command nobody
|
|
107
|
+
* handles, or a payload that is not from an element this adapter built.
|
|
108
|
+
* - `Late` is a submit or a command whose handler ran past the deadline
|
|
109
|
+
* and was interrupted. It is not an answer, since an empty one would close
|
|
110
|
+
* the modal, or tell the user the command worked: `layerInteractivity`
|
|
111
|
+
* answers 503 for it, and a caller on Socket Mode sends no ack. For a
|
|
112
|
+
* command, Slack's desktop client then shows its own private failure
|
|
113
|
+
* notice and keeps the text; its iOS client shows nothing. `Late` is
|
|
114
|
+
* itself a JSON value, so test for it with `Schema.is(ChatInteraction.Late)`
|
|
115
|
+
* before treating the result as a body.
|
|
116
|
+
* - `Chat.followUp` on a deferred command posts once to the command's
|
|
117
|
+
* `response_url`, which must be on a Slack host, through the layer's
|
|
118
|
+
* `HttpClient`. It is a write and is not retried. Slack takes five posts
|
|
119
|
+
* to one `response_url` within 30 minutes, each a new message. A spent
|
|
120
|
+
* or expired one answers 404 `used_url` or `expired_url`, which is
|
|
121
|
+
* `NotFound` with detail `interaction_expired`. A 410 or a JSON `error`
|
|
122
|
+
* with either string is mapped the same, from the docs: neither was seen.
|
|
123
|
+
* - A click on a private answer has no `message`. Its `messageId` is the
|
|
124
|
+
* answer's `container.message_ts`, which tells which answer was clicked
|
|
125
|
+
* and which no Web API method reaches: `chat.update` on it answers
|
|
126
|
+
* `message_not_found`, so `edit` fails `NotFound`. `raw` has
|
|
127
|
+
* `container.is_ephemeral`. A public answer reads back as a
|
|
128
|
+
* `bot_message` whose `bot_id` is not the app's own, so it is not
|
|
129
|
+
* `isSelf`.
|
|
130
|
+
* - `interaction` checks no signature and no app id: that is the
|
|
131
|
+
* transport's job. It needs `ChatInteraction.Handler` where it is
|
|
132
|
+
* called, so the layer does not need it.
|
|
133
|
+
*
|
|
134
|
+
* @stability unstable
|
|
135
|
+
* @category services
|
|
136
|
+
* @since 4.1.5
|
|
137
|
+
*/
|
|
138
|
+
export class SlackChat extends /*#__PURE__*/Context.Service()("@effect/chat-slack/SlackChat") {}
|
|
139
|
+
/**
|
|
140
|
+
* Registers the Slack adapter in the `Registry`, for one workspace.
|
|
141
|
+
*
|
|
142
|
+
* **Details**
|
|
143
|
+
*
|
|
144
|
+
* - `post` and `edit` send the Markdown as one `markdown` block, in which
|
|
145
|
+
* a `<` outside inline and fenced code goes as `<`, plus a `text` the
|
|
146
|
+
* adapter builds, in which every `<`, `>` and `&` goes as an entity.
|
|
147
|
+
* Slack decides who a message mentions from `text`, so no token notifies
|
|
148
|
+
* unless `withPostOptions({ notify })` allows it. Allowed tokens stay
|
|
149
|
+
* intact in both.
|
|
150
|
+
* - That `text` is cut to 16,000 code points on a post and 3,800 UTF-8
|
|
151
|
+
* bytes on an edit, on a grapheme cluster boundary, ending in `…` with
|
|
152
|
+
* the allowed tokens the cut left out appended. The cut never fails.
|
|
153
|
+
* - Stream appends go as `markdown_text`, which has no `text` beside it.
|
|
154
|
+
* A stream decodes the character references for `<`, `@` and `!`, so
|
|
155
|
+
* the adapter finds token shapes (`<@`, and `<!` followed by a letter)
|
|
156
|
+
* with those references decoded, in prose and in code alike, and puts a
|
|
157
|
+
* zero-width space (U+200B) straight after whatever spells the `<`.
|
|
158
|
+
* Allowed tokens are sent as they are. An append holds back an unclosed
|
|
159
|
+
* `<`, a trailing character reference that is not finished and a
|
|
160
|
+
* trailing high surrogate, and reports them as `held`. The start and a
|
|
161
|
+
* `flush` hold nothing, so a shape that the next write completes gets
|
|
162
|
+
* its zero-width space at the start of that write.
|
|
163
|
+
* - Once a stream is stopped, by `stop` or by a user, a message whose appends differ from what
|
|
164
|
+
* `post` would send gets one `chat.update` as blocks plus `text`,
|
|
165
|
+
* which takes the zero-width spaces out. It is skipped, leaving them, when
|
|
166
|
+
* the block would pass 12,000 code points, when the edit fails, and when
|
|
167
|
+
* an append to the message was left unconfirmed, since `ChatMarkdown`
|
|
168
|
+
* then rewrites the message itself. A skip fails nothing and sets the
|
|
169
|
+
* span attribute `slack.stream.cleanup`. A cleanup that is interrupted
|
|
170
|
+
* runs again on the next `stop` for that message.
|
|
171
|
+
* - `post`, `edit` and stream writes fail with `TooLarge` before calling
|
|
172
|
+
* Slack when the text as sent passes 12,000 code points. Slack's second
|
|
173
|
+
* limit, 13,200 with every emoji counted as its shortcode, is left to
|
|
174
|
+
* Slack, whose refusal is also `TooLarge` and posts nothing.
|
|
175
|
+
* `descriptor.measure` keeps a part under both.
|
|
176
|
+
* - A post with files uploads them with no channel, posts the message, then
|
|
177
|
+
* attaches them with `chat.update` and `file_ids`. Both calls send the
|
|
178
|
+
* same blocks and `text`, so the `text` of a post with files is cut to the
|
|
179
|
+
* update budget of 3,800 bytes. A post with files and no Markdown carries
|
|
180
|
+
* the file names, joined by ", ", as its text, and keeps them.
|
|
181
|
+
* - A post with files is all-or-nothing. A file Slack refuses at upload,
|
|
182
|
+
* one past `limits`, or an attach Slack refuses fails the post `denied`
|
|
183
|
+
* with detail `file_refused`: a refused attach first deletes the message
|
|
184
|
+
* and then the files, best effort. A timed out attach is retried, for up
|
|
185
|
+
* to a minute in all, waits after a 429 included; past that it is rolled
|
|
186
|
+
* back the same way. When the message can't be deleted, the post fails
|
|
187
|
+
* `Unknown` with detail `attach_failed_message_left` and a
|
|
188
|
+
* `SlackAttachFailed` as its cause. From the post on, the route can't be
|
|
189
|
+
* interrupted, and each call has a timeout.
|
|
190
|
+
* - `edit` keeps a message's files, and `delete` removes the message and
|
|
191
|
+
* not its files: a user may have shared them on. Read the file ids with
|
|
192
|
+
* `fetchMessage` before deleting to remove them too.
|
|
193
|
+
* - A mention in a post with files can notify for a message that a refused
|
|
194
|
+
* attach then deletes.
|
|
195
|
+
* - A post with files in a Slack Connect channel is untested.
|
|
196
|
+
* - `replyTo` is not supported.
|
|
197
|
+
* - A message from another app or an incoming webhook (`bot_message`) has
|
|
198
|
+
* the `bot_id` as its author id. `getUser` on that id fails `NotFound`.
|
|
199
|
+
* - `getUser`'s `raw` is the user from `users.info`, with its `team_id`.
|
|
200
|
+
* `SlackChat.user` is the same call with the team, guest and Slack
|
|
201
|
+
* Connect status as typed fields.
|
|
202
|
+
* - The layer provides the `SlackChat` and `SlackWebApi` services as well
|
|
203
|
+
* as registering the adapter. A consumer that needs more of Slack than
|
|
204
|
+
* `Chat` has reads either from context beside `Chat`.
|
|
205
|
+
* - A thread root whose subtype is not a message, such as an agent-view
|
|
206
|
+
* chat's `assistant_app_thread` root, is treated as deleted: `opener`
|
|
207
|
+
* gives `None` and history starts at the first reply.
|
|
208
|
+
* - Edits to one message are at least 3 seconds apart.
|
|
209
|
+
* - After a 429 on a stream append or an edit, the next write to that
|
|
210
|
+
* message waits for the retry-after, and later writes to it wait twice
|
|
211
|
+
* the interval, for the rest of the reply. A stream started with
|
|
212
|
+
* `continues` keeps the pace of the part it continues.
|
|
213
|
+
* - The native stream needs a thread and a recipient, and rotates before
|
|
214
|
+
* Slack's ten minute cap. A reply that ends after a click on the stop
|
|
215
|
+
* button moves the agent session off `processing`.
|
|
216
|
+
* - A message's buttons, link buttons and selects go in one `actions` block
|
|
217
|
+
* after the `markdown` block, on `post` and on `edit`. A button's id is
|
|
218
|
+
* its `action_id` and its value its `value`. A message with elements and
|
|
219
|
+
* no Markdown has no `markdown` block, and its `text` is the button
|
|
220
|
+
* labels joined by a space. A streamed reply gets its buttons by `edit`
|
|
221
|
+
* after the stream stops.
|
|
222
|
+
* - Elements are refused before the call past 25 in a message, for an id
|
|
223
|
+
* longer than 255 or holding U+241F, and for an id plus a value longer
|
|
224
|
+
* than 2,000, all in code points.
|
|
225
|
+
* - Text and elements share Slack's 13,200 budget, so
|
|
226
|
+
* `descriptor.measure(markdown, actions)` counts the `actions` block as
|
|
227
|
+
* Slack stores it, with every non-ASCII unit at 6. A `value` near 2,000
|
|
228
|
+
* uses up the budget by itself. A `post` whose elements push it past the
|
|
229
|
+
* cap fails `TooLarge` with `msg_blocks_too_long`, and nothing is posted.
|
|
230
|
+
* The adapter never falls back to posting the text and adding the elements
|
|
231
|
+
* by `edit`. A caller can: `chat.update` had no 13,200 cap when tested,
|
|
232
|
+
* which Slack does not document.
|
|
233
|
+
*
|
|
234
|
+
* @stability unstable
|
|
235
|
+
* @category layers
|
|
236
|
+
* @since 4.1.5
|
|
237
|
+
*/
|
|
238
|
+
export const layer = options => Layer.effect(SlackChat, Effect.gen(function* () {
|
|
239
|
+
const api = yield* SlackWebApi;
|
|
240
|
+
const http = yield* HttpClient.HttpClient;
|
|
241
|
+
const registry = yield* Registry;
|
|
242
|
+
let cached;
|
|
243
|
+
const botUserId = Effect.suspend(() => {
|
|
244
|
+
if (cached !== undefined) return Effect.succeed(cached);
|
|
245
|
+
return api.call("auth.test", {}).pipe(Effect.mapError(Errors.withOp("botUserId")), Effect.flatMap(answer => {
|
|
246
|
+
const id = Json.string(answer, "user_id");
|
|
247
|
+
if (id === undefined) {
|
|
248
|
+
return Effect.fail(Errors.chatError("botUserId", Errors.invalidResponse(false, "missing_user_id")));
|
|
249
|
+
}
|
|
250
|
+
cached = id;
|
|
251
|
+
return Effect.succeed(id);
|
|
252
|
+
}));
|
|
253
|
+
});
|
|
254
|
+
const {
|
|
255
|
+
adapter,
|
|
256
|
+
answer,
|
|
257
|
+
user
|
|
258
|
+
} = Adapter.make({
|
|
259
|
+
api,
|
|
260
|
+
http,
|
|
261
|
+
botToken: options.botToken,
|
|
262
|
+
teamId: options.teamId,
|
|
263
|
+
botUserId,
|
|
264
|
+
attachFailed: fields => new SlackAttachFailed(fields)
|
|
265
|
+
});
|
|
266
|
+
yield* registry.register(adapter);
|
|
267
|
+
const interaction = Interactions.make({
|
|
268
|
+
api,
|
|
269
|
+
teamId: options.teamId,
|
|
270
|
+
answer
|
|
271
|
+
});
|
|
272
|
+
return SlackChat.of({
|
|
273
|
+
teamId: options.teamId,
|
|
274
|
+
botUserId,
|
|
275
|
+
user,
|
|
276
|
+
interaction
|
|
277
|
+
});
|
|
278
|
+
})).pipe(Layer.provideMerge(WebApi.layer({
|
|
279
|
+
botToken: options.botToken
|
|
280
|
+
})));
|
|
281
|
+
/**
|
|
282
|
+
* The `cause` of a `post` with files that failed `uncertain` with detail
|
|
283
|
+
* `attach_failed_message_left`.
|
|
284
|
+
*
|
|
285
|
+
* **Details**
|
|
286
|
+
*
|
|
287
|
+
* - The attach failed and the message could not be deleted. The message may
|
|
288
|
+
* still exist, with or without its files: an attach that timed out may
|
|
289
|
+
* have landed, and a delete that timed out may have too. `messageId` is
|
|
290
|
+
* that message and `fileIds` are its files, which are kept. `reason` is
|
|
291
|
+
* the attach's own.
|
|
292
|
+
* - Its `message` leaves the ids out.
|
|
293
|
+
*
|
|
294
|
+
* @stability unstable
|
|
295
|
+
* @category errors
|
|
296
|
+
* @since 4.1.5
|
|
297
|
+
*/
|
|
298
|
+
export class SlackAttachFailed extends /*#__PURE__*/Schema.TaggedError("@effect/chat-slack/SlackChat/SlackAttachFailed")("SlackAttachFailed", {
|
|
299
|
+
thread: ChatThread,
|
|
300
|
+
messageId: Schema.String,
|
|
301
|
+
fileIds: /*#__PURE__*/Schema.Array(Schema.String),
|
|
302
|
+
reason: ChatErrorReason
|
|
303
|
+
}) {
|
|
304
|
+
get message() {
|
|
305
|
+
return `Slack did not attach the files and the message may be left: ${this.reason.message}`;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* The address of a Slack channel, direct conversation or thread:
|
|
310
|
+
* `{team}/{channel}`, or `{team}/{channel}/{threadTs}` for a thread.
|
|
311
|
+
*
|
|
312
|
+
* @stability unstable
|
|
313
|
+
* @category constructors
|
|
314
|
+
* @since 4.1.5
|
|
315
|
+
*/
|
|
316
|
+
export const thread = Address.thread;
|
|
317
|
+
/**
|
|
318
|
+
* The parts of a Slack address, or `None` for another platform's or a
|
|
319
|
+
* malformed one.
|
|
320
|
+
*
|
|
321
|
+
* @stability unstable
|
|
322
|
+
* @category destructors
|
|
323
|
+
* @since 4.1.5
|
|
324
|
+
*/
|
|
325
|
+
export const parts = Address.parts;
|
|
326
|
+
/**
|
|
327
|
+
* `POST {path}`: the Events API webhook.
|
|
328
|
+
*
|
|
329
|
+
* **Details**
|
|
330
|
+
*
|
|
331
|
+
* - Checks the `v0` signature with the signing secret and a five minute
|
|
332
|
+
* window, then answers `url_verification`.
|
|
333
|
+
* - An envelope for another app, another workspace or of another type is
|
|
334
|
+
* answered 200 and dropped.
|
|
335
|
+
* - The events go through `normalize` to the `ChatHandler`, one at a time.
|
|
336
|
+
* - Answers 503, so Slack retries, when the handler fails `NotAccepted`,
|
|
337
|
+
* when the bot user can't be read, or when the request, from reading its
|
|
338
|
+
* body to the handler's return, takes longer than `deadline` (2.5 seconds
|
|
339
|
+
* by default). Each of the three is logged with its own message, the
|
|
340
|
+
* unreadable bot user as an error with its `ChatError` and the other two
|
|
341
|
+
* as warnings.
|
|
342
|
+
* - Answers 413 past `maxBodyBytes` (1 MiB by default), and for a body that
|
|
343
|
+
* can't be read, before the signature is checked. `maxBodyBytes` must be
|
|
344
|
+
* a non-negative safe integer; another value is a defect when the layer is
|
|
345
|
+
* built.
|
|
346
|
+
* - Slack redelivers on a timeout or an error, so an event can arrive twice.
|
|
347
|
+
* `ChatEvent.dedupeKey` gives the two deliveries equal keys.
|
|
348
|
+
*
|
|
349
|
+
* Signature checks use the required `Mac` service. Provide
|
|
350
|
+
* `NodeCrypto.layerMac`, `BunCrypto.layerMac`, `DenoCrypto.layerMac`,
|
|
351
|
+
* `BrowserCrypto.layerMac`, or `Mac.layerWebCrypto` with
|
|
352
|
+
* `SecureRandom.layerWebCrypto` for other runtimes such as Workers.
|
|
353
|
+
* Key construction failures are configuration defects; verification errors
|
|
354
|
+
* fail the signature check (401).
|
|
355
|
+
*
|
|
356
|
+
* @stability unstable
|
|
357
|
+
* @category layers
|
|
358
|
+
* @since 4.1.5
|
|
359
|
+
*/
|
|
360
|
+
export const layerWebhook = options => HttpRouter.use(Effect.fnUntraced(function* (router) {
|
|
361
|
+
const slack = yield* SlackChat;
|
|
362
|
+
const handler = yield* ChatHandler;
|
|
363
|
+
const verify = yield* Webhook.makeVerifier(options.signingSecret);
|
|
364
|
+
const webhookOptions = {
|
|
365
|
+
verify,
|
|
366
|
+
appId: options.appId,
|
|
367
|
+
teamId: slack.teamId,
|
|
368
|
+
botUserId: slack.botUserId,
|
|
369
|
+
handle: handler.handle,
|
|
370
|
+
deadline: options.deadline ?? Duration.millis(2500),
|
|
371
|
+
maxBodySize: ByteSize.bytes(options.maxBodyBytes ?? Webhook.defaultMaxBodyBytes)
|
|
372
|
+
};
|
|
373
|
+
yield* router.add("POST", options.path, request => Webhook.handleRequest(request, webhookOptions));
|
|
374
|
+
}));
|
|
375
|
+
/**
|
|
376
|
+
* `POST {path}`: the Interactivity Request URL, which Slack posts
|
|
377
|
+
* form-encoded and separately from the Events API.
|
|
378
|
+
*
|
|
379
|
+
* **Details**
|
|
380
|
+
*
|
|
381
|
+
* - Checks the `v0` signature as `layerWebhook` does, decodes the form's
|
|
382
|
+
* `payload` and drops one for another app with a 200.
|
|
383
|
+
* - It is also the Request URL of a slash command. A command's form has no
|
|
384
|
+
* `payload` field and has a `command` field, which is how the route tells
|
|
385
|
+
* the two apart. Its fields go to `SlackChat.interaction` as one object,
|
|
386
|
+
* after the same signature and app checks.
|
|
387
|
+
* - Hands the payload to `SlackChat.interaction` with `deadline` (2.5
|
|
388
|
+
* seconds by default). Its body is the response, and `Late` is answered
|
|
389
|
+
* with a 503, so the modal stays open with Slack's own error.
|
|
390
|
+
* - Answers 413 past `maxBodyBytes`, as `layerWebhook` does.
|
|
391
|
+
* - Slack never redelivers an interaction, so a click or submit that is not
|
|
392
|
+
* answered in time is lost. A user can submit again, as a new request.
|
|
393
|
+
*
|
|
394
|
+
* Signature checks use the required `Mac` service. Provide
|
|
395
|
+
* `NodeCrypto.layerMac`, `BunCrypto.layerMac`, `DenoCrypto.layerMac`,
|
|
396
|
+
* `BrowserCrypto.layerMac`, or `Mac.layerWebCrypto` with
|
|
397
|
+
* `SecureRandom.layerWebCrypto` for other runtimes such as Workers.
|
|
398
|
+
* Key construction failures are configuration defects; verification errors
|
|
399
|
+
* fail the signature check (401).
|
|
400
|
+
*
|
|
401
|
+
* @stability unstable
|
|
402
|
+
* @category layers
|
|
403
|
+
* @since 4.1.5
|
|
404
|
+
*/
|
|
405
|
+
export const layerInteractivity = options => HttpRouter.use(Effect.fnUntraced(function* (router) {
|
|
406
|
+
const slack = yield* SlackChat;
|
|
407
|
+
const handler = yield* ChatInteraction.Handler;
|
|
408
|
+
const verify = yield* Webhook.makeVerifier(options.signingSecret);
|
|
409
|
+
const interactivityOptions = {
|
|
410
|
+
verify,
|
|
411
|
+
appId: options.appId,
|
|
412
|
+
interaction: (payload, interactionOptions) => Effect.provideService(slack.interaction(payload, interactionOptions), ChatInteraction.Handler, handler),
|
|
413
|
+
deadline: options.deadline ?? Interactions.defaultDeadline,
|
|
414
|
+
maxBodySize: ByteSize.bytes(options.maxBodyBytes ?? Webhook.defaultMaxBodyBytes)
|
|
415
|
+
};
|
|
416
|
+
yield* router.add("POST", options.path, request => Webhook.handleInteractivity(request, interactivityOptions));
|
|
417
|
+
}));
|
|
418
|
+
/**
|
|
419
|
+
* The normaliser behind `SlackChat.interaction`.
|
|
420
|
+
*
|
|
421
|
+
* **Details**
|
|
422
|
+
*
|
|
423
|
+
* - Pure: takes the decoded `payload` of a `block_actions` or
|
|
424
|
+
* `view_submission` request, or the fields of a slash command.
|
|
425
|
+
* - None for any other payload, and for one that is not from an element
|
|
426
|
+
* this adapter built: a block of the consumer's own, a link button, or a
|
|
427
|
+
* view the adapter did not open.
|
|
428
|
+
* - Every command gives a `CommandInvoked`, known or not: the registry
|
|
429
|
+
* decides that later. `id` is `command` less its slash, `text` is `text`
|
|
430
|
+
* or the empty string, and the thread is the channel's.
|
|
431
|
+
* - A submit's thread and message are those of the click that opened the
|
|
432
|
+
* modal, which the adapter packed into `private_metadata` beside the
|
|
433
|
+
* consumer's metadata. A modal a command opened has no message, so its
|
|
434
|
+
* submit has no `messageId`.
|
|
435
|
+
* - The team in an address is `context.teamId`. `raw` is the payload
|
|
436
|
+
* without its verification `token`. A command's holds its `response_url`,
|
|
437
|
+
* so it is a credential for 30 minutes.
|
|
438
|
+
*
|
|
439
|
+
* @stability unstable
|
|
440
|
+
* @category normalization
|
|
441
|
+
* @since 4.1.5
|
|
442
|
+
*/
|
|
443
|
+
export const normalizeInteraction = Interactions.normalize;
|
|
444
|
+
/**
|
|
445
|
+
* The normaliser, for Socket Mode or a consumer's own transport.
|
|
446
|
+
*
|
|
447
|
+
* **Details**
|
|
448
|
+
*
|
|
449
|
+
* - Pure: takes an `event_callback` envelope, gives zero or more events.
|
|
450
|
+
* - An envelope for another workspace gives none. The team in an address is
|
|
451
|
+
* the workspace, from the envelope's `team_id` or `authorizations`.
|
|
452
|
+
* - `message` and `app_mention` for one message give equal events. An
|
|
453
|
+
* `app_mention` that carries `edited` gives none.
|
|
454
|
+
* - A message subtype other than `file_share`, `thread_broadcast`,
|
|
455
|
+
* `bot_message` and `me_message` gives none.
|
|
456
|
+
* - Mentions come from the message's `rich_text` block when it has one,
|
|
457
|
+
* and only for elements whose token is in `text`, since Slack decides a
|
|
458
|
+
* mention from `text`. Without a `rich_text` block they come from `text`
|
|
459
|
+
* outside code.
|
|
460
|
+
* - The bot's own messages with a `rich_text` block read back with `text`
|
|
461
|
+
* rendered from the blocks as Markdown, whole and with its newlines, as
|
|
462
|
+
* the stored `text` the adapter sent may be cut. Everyone else's `text`
|
|
463
|
+
* is Slack's field as stored.
|
|
464
|
+
* - `agent_session_stopped` gives a `StopRequested`.
|
|
465
|
+
* - `raw` is the envelope without its verification `token`.
|
|
466
|
+
*
|
|
467
|
+
* @stability unstable
|
|
468
|
+
* @category normalization
|
|
469
|
+
* @since 4.1.5
|
|
470
|
+
*/
|
|
471
|
+
export const normalize = Normalize.normalize;
|
|
472
|
+
/**
|
|
473
|
+
* Scoped Slack options for every write inside `effect`. Nested calls merge,
|
|
474
|
+
* the inner one winning field by field.
|
|
475
|
+
*
|
|
476
|
+
* @stability unstable
|
|
477
|
+
* @category combinators
|
|
478
|
+
* @since 4.1.5
|
|
479
|
+
*/
|
|
480
|
+
export const withPostOptions = /*#__PURE__*/dual(2, (effect, options) => Effect.updateService(effect, CurrentPostOptions, current => ({
|
|
481
|
+
...current,
|
|
482
|
+
...options
|
|
483
|
+
})));
|
|
484
|
+
/**
|
|
485
|
+
* A Slack emoji name, with or without colons and with at most one skin tone
|
|
486
|
+
* suffix (`+1::skin-tone-4`), as Unicode. `None` for a name the table
|
|
487
|
+
* doesn't know, such as a custom emoji, and for a name with two tones.
|
|
488
|
+
*
|
|
489
|
+
* @stability unstable
|
|
490
|
+
* @category emoji
|
|
491
|
+
* @since 4.1.5
|
|
492
|
+
*/
|
|
493
|
+
export const emojiFromName = name => Option.fromUndefinedOr(Emoji.fromName(name));
|
|
494
|
+
/**
|
|
495
|
+
* An emoji as its Slack name, without colons.
|
|
496
|
+
*
|
|
497
|
+
* @stability unstable
|
|
498
|
+
* @category emoji
|
|
499
|
+
* @since 4.1.5
|
|
500
|
+
*/
|
|
501
|
+
export const emojiToName = emoji => Option.fromUndefinedOr(Emoji.toName(emoji));
|
|
502
|
+
/**
|
|
503
|
+
* Reads one Slack mention token, such as `<@U123>`, `<!subteam^S123|@team>`,
|
|
504
|
+
* `<#C123|name>` or `<!here>`, for `ChatTest.checkMessage`,
|
|
505
|
+
* `ChatTest.checkEvent` and `ChatTest.conformance`.
|
|
506
|
+
*
|
|
507
|
+
* @stability unstable
|
|
508
|
+
* @category testing
|
|
509
|
+
* @since 4.1.5
|
|
510
|
+
*/
|
|
511
|
+
export const parseMention = slice => Option.fromUndefinedOr(Mentions.parseToken(slice));
|
|
512
|
+
//# sourceMappingURL=SlackChat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SlackChat.js","names":[],"sources":["../src/SlackChat.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,OAAO,KAAK,QAAQ,MAAM,iBAAiB;AAC3C,SAAS,QAAQ,QAAQ,yBAAyB;AAClD,SAAyB,eAAe,QAAQ,uBAAuB;AAEvE,SAAS,WAAW,QAAQ,yBAAyB;AACrD,OAAO,KAAK,eAAe,MAAM,6BAA6B;AAE9D,SAAS,UAAU,QAAQ,wBAAwB;AACnD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;;;;;;;;;;;;AAyBA,OAAO,MAAM,oBAAoB,GAGiB,YAAY,CAAC,SAAS;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,OAAO,MAAM,SAAS,GAGU,SAAS,CAAC,SAAS;AAqCnD;;;;;;;;AAQA,OAAO,MAAM,eAAe,gBAmBxB,IAAI,CACN,CAAC,EACD,CAAU,MAA8B,EAAE,OAAyB,KACjE,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,kBAAkB,EAAG,OAAO,KAAM;EAAE,GAAG,OAAO;EAAE,GAAG;AAAO,CAAE,CAAC,CAAC,CAC9F;AAED;;;;;;;;;AASA,OAAO,MAAM,aAAa,GAAI,IAAY,IAA4B,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAElH;;;;;;;AAOA,OAAO,MAAM,WAAW,GAAI,KAAa,IAA4B,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAEhH;;;;;;;;;AASA,OAAO,MAAM,YAAY,GAAkB,KAAK,IAAK,MAAM,CAAC,eAAe,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { ChatError } from "effect/chat/ChatError";
|
|
2
|
+
import * as Context from "effect/Context";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as HttpClient from "effect/http/HttpClient";
|
|
5
|
+
import * as Layer from "effect/Layer";
|
|
6
|
+
import * as Redacted from "effect/Redacted";
|
|
7
|
+
import type * as Schema from "effect/Schema";
|
|
8
|
+
/**
|
|
9
|
+
* Options for one Web API call.
|
|
10
|
+
*
|
|
11
|
+
* @stability unstable
|
|
12
|
+
* @category models
|
|
13
|
+
* @since 4.1.5
|
|
14
|
+
*/
|
|
15
|
+
export interface CallOptions {
|
|
16
|
+
/**
|
|
17
|
+
* The call changes something. It is never retried after the request left,
|
|
18
|
+
* and a failure that may have landed is `uncertain`.
|
|
19
|
+
*/
|
|
20
|
+
readonly write?: boolean | undefined;
|
|
21
|
+
/** Retry `retry` failures, as `ChatAdapter.retrySafe` does. Default true. */
|
|
22
|
+
readonly retry?: boolean | undefined;
|
|
23
|
+
}
|
|
24
|
+
declare const SlackWebApi_base: Context.ServiceClass<SlackWebApi, "@effect/chat-slack/SlackWebApi", {
|
|
25
|
+
readonly call: (method: string, body: Readonly<Record<string, unknown>>, options?: CallOptions | undefined) => Effect.Effect<Schema.Json, ChatError>;
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
* The minimal Web API client, with the bot token.
|
|
29
|
+
*
|
|
30
|
+
* **Details**
|
|
31
|
+
*
|
|
32
|
+
* - `call` posts form parameters to `https://slack.com/api/{method}`. A
|
|
33
|
+
* string goes as it is, any other value as JSON, and `undefined` is left
|
|
34
|
+
* out. It succeeds with the answer once Slack says `ok`.
|
|
35
|
+
* - An `ok: false` answer fails with the reason for Slack's error code, which
|
|
36
|
+
* becomes the reason's `detail`. `ratelimited` and an HTTP 429 give
|
|
37
|
+
* `RateLimited` with the `Retry-After` wait.
|
|
38
|
+
* - A write never repeats once the request left: a transport failure, a
|
|
39
|
+
* server error or an unreadable answer is `uncertain`. A read retries
|
|
40
|
+
* `retry` failures unless `retry: false`.
|
|
41
|
+
* - The error's `op` is the method name.
|
|
42
|
+
*
|
|
43
|
+
* @stability unstable
|
|
44
|
+
* @category services
|
|
45
|
+
* @since 4.1.5
|
|
46
|
+
*/
|
|
47
|
+
export declare class SlackWebApi extends SlackWebApi_base {
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Builds the client from an `HttpClient` and a bot token.
|
|
51
|
+
*
|
|
52
|
+
* @stability unstable
|
|
53
|
+
* @category constructors
|
|
54
|
+
* @since 4.1.5
|
|
55
|
+
*/
|
|
56
|
+
export declare const make: (options: {
|
|
57
|
+
readonly botToken: Redacted.Redacted;
|
|
58
|
+
readonly baseUrl?: string | undefined;
|
|
59
|
+
}) => Effect.Effect<{
|
|
60
|
+
readonly call: (method: string, body: Readonly<Record<string, unknown>>, options?: CallOptions | undefined) => Effect.Effect<Schema.Json, ChatError>;
|
|
61
|
+
}, never, HttpClient.HttpClient>;
|
|
62
|
+
/**
|
|
63
|
+
* The client as a layer.
|
|
64
|
+
*
|
|
65
|
+
* @stability unstable
|
|
66
|
+
* @category layers
|
|
67
|
+
* @since 4.1.5
|
|
68
|
+
*/
|
|
69
|
+
export declare const layer: (options: {
|
|
70
|
+
readonly botToken: Redacted.Redacted;
|
|
71
|
+
readonly baseUrl?: string | undefined;
|
|
72
|
+
}) => Layer.Layer<SlackWebApi, never, HttpClient.HttpClient>;
|
|
73
|
+
export {};
|
|
74
|
+
//# sourceMappingURL=SlackWebApi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SlackWebApi.d.ts","sourceRoot":"","sources":["../src/SlackWebApi.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAA;AAEpD,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAG5C;;;;;;GAMG;AACH,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IACpC,6EAA6E;IAC7E,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CACrC;;mBAuBgB,CACb,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,E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