@im-more/dsh-slack 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/cordis.patch.yml +13 -0
- package/lib/index.js +2659 -0
- package/lib/index.js.map +1 -0
- package/lib/types/bot.d.ts +66 -0
- package/lib/types/bot.d.ts.map +1 -0
- package/lib/types/bot.js +165 -0
- package/lib/types/bot.js.map +1 -0
- package/lib/types/config.d.ts +49 -0
- package/lib/types/config.d.ts.map +1 -0
- package/lib/types/config.js +54 -0
- package/lib/types/config.js.map +1 -0
- package/lib/types/decode.d.ts +126 -0
- package/lib/types/decode.d.ts.map +1 -0
- package/lib/types/decode.js +396 -0
- package/lib/types/decode.js.map +1 -0
- package/lib/types/errors.d.ts +61 -0
- package/lib/types/errors.d.ts.map +1 -0
- package/lib/types/errors.js +196 -0
- package/lib/types/errors.js.map +1 -0
- package/lib/types/identity.d.ts +27 -0
- package/lib/types/identity.d.ts.map +1 -0
- package/lib/types/identity.js +35 -0
- package/lib/types/identity.js.map +1 -0
- package/lib/types/index.d.ts +14 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +14 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/modes/mrkdwn.d.ts +17 -0
- package/lib/types/modes/mrkdwn.d.ts.map +1 -0
- package/lib/types/modes/mrkdwn.js +123 -0
- package/lib/types/modes/mrkdwn.js.map +1 -0
- package/lib/types/modes/shared.d.ts +164 -0
- package/lib/types/modes/shared.d.ts.map +1 -0
- package/lib/types/modes/shared.js +411 -0
- package/lib/types/modes/shared.js.map +1 -0
- package/lib/types/mrkdwn.d.ts +41 -0
- package/lib/types/mrkdwn.d.ts.map +1 -0
- package/lib/types/mrkdwn.js +137 -0
- package/lib/types/mrkdwn.js.map +1 -0
- package/lib/types/request.d.ts +225 -0
- package/lib/types/request.d.ts.map +1 -0
- package/lib/types/request.js +330 -0
- package/lib/types/request.js.map +1 -0
- package/lib/types/send.d.ts +74 -0
- package/lib/types/send.d.ts.map +1 -0
- package/lib/types/send.js +200 -0
- package/lib/types/send.js.map +1 -0
- package/lib/types/transport/socket.d.ts +58 -0
- package/lib/types/transport/socket.d.ts.map +1 -0
- package/lib/types/transport/socket.js +297 -0
- package/lib/types/transport/socket.js.map +1 -0
- package/lib/types/transport/webhook.d.ts +48 -0
- package/lib/types/transport/webhook.d.ts.map +1 -0
- package/lib/types/transport/webhook.js +210 -0
- package/lib/types/transport/webhook.js.map +1 -0
- package/lib/types/types/admin.d.ts +682 -0
- package/lib/types/types/admin.d.ts.map +1 -0
- package/lib/types/types/admin.js +172 -0
- package/lib/types/types/admin.js.map +1 -0
- package/lib/types/types/api.d.ts +20 -0
- package/lib/types/types/api.d.ts.map +1 -0
- package/lib/types/types/api.js +7 -0
- package/lib/types/types/api.js.map +1 -0
- package/lib/types/types/apps.d.ts +138 -0
- package/lib/types/types/apps.d.ts.map +1 -0
- package/lib/types/types/apps.js +28 -0
- package/lib/types/types/apps.js.map +1 -0
- package/lib/types/types/auth.d.ts +36 -0
- package/lib/types/types/auth.d.ts.map +1 -0
- package/lib/types/types/auth.js +10 -0
- package/lib/types/types/auth.js.map +1 -0
- package/lib/types/types/bots.d.ts +32 -0
- package/lib/types/types/bots.d.ts.map +1 -0
- package/lib/types/types/bots.js +7 -0
- package/lib/types/types/bots.js.map +1 -0
- package/lib/types/types/calls.d.ts +82 -0
- package/lib/types/types/calls.d.ts.map +1 -0
- package/lib/types/types/calls.js +22 -0
- package/lib/types/types/calls.js.map +1 -0
- package/lib/types/types/chat.d.ts +208 -0
- package/lib/types/types/chat.d.ts.map +1 -0
- package/lib/types/types/chat.js +34 -0
- package/lib/types/types/chat.js.map +1 -0
- package/lib/types/types/conversations.d.ts +266 -0
- package/lib/types/types/conversations.d.ts.map +1 -0
- package/lib/types/types/conversations.js +58 -0
- package/lib/types/types/conversations.js.map +1 -0
- package/lib/types/types/definition.d.ts +505 -0
- package/lib/types/types/definition.d.ts.map +1 -0
- package/lib/types/types/definition.js +2 -0
- package/lib/types/types/definition.js.map +1 -0
- package/lib/types/types/dialog.d.ts +20 -0
- package/lib/types/types/dialog.d.ts.map +1 -0
- package/lib/types/types/dialog.js +7 -0
- package/lib/types/types/dialog.js.map +1 -0
- package/lib/types/types/dnd.d.ts +70 -0
- package/lib/types/types/dnd.d.ts.map +1 -0
- package/lib/types/types/dnd.js +19 -0
- package/lib/types/types/dnd.js.map +1 -0
- package/lib/types/types/emoji.d.ts +18 -0
- package/lib/types/types/emoji.d.ts.map +1 -0
- package/lib/types/types/emoji.js +7 -0
- package/lib/types/types/emoji.js.map +1 -0
- package/lib/types/types/events/base-events.d.ts +235 -0
- package/lib/types/types/events/base-events.d.ts.map +1 -0
- package/lib/types/types/events/base-events.js +3 -0
- package/lib/types/types/events/base-events.js.map +1 -0
- package/lib/types/types/events/index.d.ts +97 -0
- package/lib/types/types/events/index.d.ts.map +1 -0
- package/lib/types/types/events/index.js +3 -0
- package/lib/types/types/events/index.js.map +1 -0
- package/lib/types/types/events/message-events.d.ts +215 -0
- package/lib/types/types/events/message-events.d.ts.map +1 -0
- package/lib/types/types/events/message-events.js +3 -0
- package/lib/types/types/events/message-events.js.map +1 -0
- package/lib/types/types/files.d.ts +189 -0
- package/lib/types/types/files.d.ts.map +1 -0
- package/lib/types/types/files.js +43 -0
- package/lib/types/types/files.js.map +1 -0
- package/lib/types/types/index.d.ts +82 -0
- package/lib/types/types/index.d.ts.map +1 -0
- package/lib/types/types/index.js +29 -0
- package/lib/types/types/index.js.map +1 -0
- package/lib/types/types/internal.d.ts +17 -0
- package/lib/types/types/internal.d.ts.map +1 -0
- package/lib/types/types/internal.js +60 -0
- package/lib/types/types/internal.js.map +1 -0
- package/lib/types/types/migration.d.ts +25 -0
- package/lib/types/types/migration.d.ts.map +1 -0
- package/lib/types/types/migration.js +7 -0
- package/lib/types/types/migration.js.map +1 -0
- package/lib/types/types/oauth.d.ts +50 -0
- package/lib/types/types/oauth.d.ts.map +1 -0
- package/lib/types/types/oauth.js +13 -0
- package/lib/types/types/oauth.js.map +1 -0
- package/lib/types/types/pins.d.ts +39 -0
- package/lib/types/types/pins.d.ts.map +1 -0
- package/lib/types/types/pins.js +13 -0
- package/lib/types/types/pins.js.map +1 -0
- package/lib/types/types/reactions.d.ts +75 -0
- package/lib/types/types/reactions.d.ts.map +1 -0
- package/lib/types/types/reactions.js +16 -0
- package/lib/types/types/reactions.js.map +1 -0
- package/lib/types/types/reminders.d.ts +64 -0
- package/lib/types/types/reminders.d.ts.map +1 -0
- package/lib/types/types/reminders.js +19 -0
- package/lib/types/types/reminders.js.map +1 -0
- package/lib/types/types/rtm.d.ts +30 -0
- package/lib/types/types/rtm.d.ts.map +1 -0
- package/lib/types/types/rtm.js +7 -0
- package/lib/types/types/rtm.js.map +1 -0
- package/lib/types/types/search.d.ts +24 -0
- package/lib/types/types/search.d.ts.map +1 -0
- package/lib/types/types/search.js +7 -0
- package/lib/types/types/search.js.map +1 -0
- package/lib/types/types/stars.d.ts +56 -0
- package/lib/types/types/stars.d.ts.map +1 -0
- package/lib/types/types/stars.js +13 -0
- package/lib/types/types/stars.js.map +1 -0
- package/lib/types/types/team.d.ts +98 -0
- package/lib/types/types/team.d.ts.map +1 -0
- package/lib/types/types/team.js +19 -0
- package/lib/types/types/team.js.map +1 -0
- package/lib/types/types/usergroups.d.ts +103 -0
- package/lib/types/types/usergroups.d.ts.map +1 -0
- package/lib/types/types/usergroups.js +25 -0
- package/lib/types/types/usergroups.js.map +1 -0
- package/lib/types/types/users.d.ts +169 -0
- package/lib/types/types/users.d.ts.map +1 -0
- package/lib/types/types/users.js +40 -0
- package/lib/types/types/users.js.map +1 -0
- package/lib/types/types/views.d.ts +56 -0
- package/lib/types/types/views.d.ts.map +1 -0
- package/lib/types/types/views.js +16 -0
- package/lib/types/types/views.js.map +1 -0
- package/lib/types/types/workflows.d.ts +45 -0
- package/lib/types/types/workflows.d.ts.map +1 -0
- package/lib/types/types/workflows.js +13 -0
- package/lib/types/types/workflows.js.map +1 -0
- package/package.json +65 -3
- package/src/bot.ts +273 -0
- package/src/config.ts +92 -0
- package/src/decode.ts +489 -0
- package/src/errors.ts +230 -0
- package/src/identity.ts +59 -0
- package/src/index.ts +64 -0
- package/src/modes/mrkdwn.ts +159 -0
- package/src/modes/shared.ts +515 -0
- package/src/mrkdwn.ts +146 -0
- package/src/request.ts +449 -0
- package/src/send.ts +300 -0
- package/src/transport/socket.ts +393 -0
- package/src/transport/webhook.ts +269 -0
- package/src/types/admin.ts +910 -0
- package/src/types/api.ts +28 -0
- package/src/types/apps.ts +175 -0
- package/src/types/auth.ts +49 -0
- package/src/types/bots.ts +40 -0
- package/src/types/calls.ts +110 -0
- package/src/types/chat.ts +255 -0
- package/src/types/conversations.ts +342 -0
- package/src/types/definition.ts +530 -0
- package/src/types/dialog.ts +28 -0
- package/src/types/dnd.ts +94 -0
- package/src/types/emoji.ts +26 -0
- package/src/types/events/base-events.ts +281 -0
- package/src/types/events/index.ts +125 -0
- package/src/types/events/message-events.ts +253 -0
- package/src/types/files.ts +245 -0
- package/src/types/index.ts +84 -0
- package/src/types/internal.ts +60 -0
- package/src/types/migration.ts +34 -0
- package/src/types/oauth.ts +66 -0
- package/src/types/pins.ts +55 -0
- package/src/types/reactions.ts +95 -0
- package/src/types/reminders.ts +88 -0
- package/src/types/rtm.ts +38 -0
- package/src/types/search.ts +32 -0
- package/src/types/stars.ts +72 -0
- package/src/types/team.ts +122 -0
- package/src/types/usergroups.ts +135 -0
- package/src/types/users.ts +221 -0
- package/src/types/views.ts +76 -0
- package/src/types/workflows.ts +61 -0
- package/README.md +0 -3
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Events API transport (`protocol: 'http'`).
|
|
3
|
+
*
|
|
4
|
+
* The profile's `webServer` owns the listener, so this transport only registers one anonymous route at `path` and
|
|
5
|
+
* authenticates every request itself: `v0:` HMAC-SHA256 over `v0:<timestamp>:<raw body>`, inside a five-minute window
|
|
6
|
+
* and compared in constant time. Interactive payloads (a form body) are refused, because v1 publishes no controls.
|
|
7
|
+
*
|
|
8
|
+
* `event_callback` is answered `200` before its event reaches intake. Slack redelivers whatever it could not confirm
|
|
9
|
+
* within three seconds and gives up after three retries, so a slow intake must not delay the confirmation; the cost is
|
|
10
|
+
* that a crash between the confirmation and the store loses the event.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { createHmac, timingSafeEqual } from 'node:crypto'
|
|
14
|
+
import type { IncomingMessage, ServerResponse } from 'node:http'
|
|
15
|
+
import type { SlackBot } from '../bot.ts'
|
|
16
|
+
import { routePath } from '../config.ts'
|
|
17
|
+
import { decodeEvent } from '../decode.ts'
|
|
18
|
+
import type { SlackEnvelopeLike } from '../decode.ts'
|
|
19
|
+
|
|
20
|
+
/** The part of `ctx.webServer` this adapter uses. */
|
|
21
|
+
interface WebServerLike {
|
|
22
|
+
register(route: {
|
|
23
|
+
kind: 'exact'
|
|
24
|
+
path: string
|
|
25
|
+
auth: 'anonymous'
|
|
26
|
+
handler: (
|
|
27
|
+
request: IncomingMessage,
|
|
28
|
+
response: ServerResponse,
|
|
29
|
+
) => void | Promise<void>
|
|
30
|
+
}): () => void
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** How far a request's timestamp may be from now before it is refused as a replay. */
|
|
34
|
+
const TIMESTAMP_WINDOW_SECONDS = 5 * 60
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The `X-Slack-Signature` value of one request.
|
|
38
|
+
* @param signing - the app's signing secret.
|
|
39
|
+
* @param timestamp - `X-Slack-Request-Timestamp`.
|
|
40
|
+
* @param body - the raw request body, before parsing.
|
|
41
|
+
* @returns `v0=<hex digest>`.
|
|
42
|
+
*/
|
|
43
|
+
export function signatureOf(
|
|
44
|
+
signing: string,
|
|
45
|
+
timestamp: string,
|
|
46
|
+
body: string,
|
|
47
|
+
): string {
|
|
48
|
+
const digest = createHmac('sha256', signing)
|
|
49
|
+
.update(`v0:${timestamp}:${body}`)
|
|
50
|
+
.digest('hex')
|
|
51
|
+
return `v0=${digest}`
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Compare two signature strings without leaking where they differ.
|
|
56
|
+
* @param expected - the signature computed from the body.
|
|
57
|
+
* @param received - the signature the request carried.
|
|
58
|
+
* @returns whether they are equal.
|
|
59
|
+
*/
|
|
60
|
+
export function matchesSignature(expected: string, received: string): boolean {
|
|
61
|
+
const left = Buffer.from(expected, 'utf8')
|
|
62
|
+
const right = Buffer.from(received, 'utf8')
|
|
63
|
+
if (left.length !== right.length) return false
|
|
64
|
+
return timingSafeEqual(left, right)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** One header of an inbound request, when it arrived exactly once. */
|
|
68
|
+
function headerOf(request: IncomingMessage, name: string): string | undefined {
|
|
69
|
+
const value = request.headers[name]
|
|
70
|
+
return typeof value === 'string' ? value : undefined
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Read a request body to its end. The adapter imposes no size limit, as the upstream plugin does not. */
|
|
74
|
+
async function readBody(request: IncomingMessage): Promise<string> {
|
|
75
|
+
const chunks: Buffer[] = []
|
|
76
|
+
for await (const chunk of request) {
|
|
77
|
+
chunks.push(
|
|
78
|
+
Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk as Uint8Array),
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
return Buffer.concat(chunks).toString('utf8')
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Answer one request without a body. */
|
|
85
|
+
function writeStatus(
|
|
86
|
+
response: ServerResponse,
|
|
87
|
+
status: number,
|
|
88
|
+
headers: Record<string, string> = {},
|
|
89
|
+
): void {
|
|
90
|
+
response.writeHead(status, headers)
|
|
91
|
+
response.end()
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Confirm one request: `200` with the plain-text body Slack's own examples use. */
|
|
95
|
+
function writeOk(response: ServerResponse): void {
|
|
96
|
+
response.writeHead(200, { 'content-type': 'text/plain' })
|
|
97
|
+
response.end('ok')
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Whether a request body claims to be JSON. */
|
|
101
|
+
function isJson(contentType: string | undefined): boolean {
|
|
102
|
+
if (contentType === undefined) return false
|
|
103
|
+
return contentType.split(';')[0]!.trim().toLowerCase() === 'application/json'
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Message of any caught value, for a log line. */
|
|
107
|
+
function messageOf(error: unknown): string {
|
|
108
|
+
return error instanceof Error ? error.message : String(error)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** The Events API transport of one bot. */
|
|
112
|
+
export class SlackWebhook {
|
|
113
|
+
private dispose: (() => void) | undefined
|
|
114
|
+
|
|
115
|
+
constructor(private readonly bot: SlackBot) {}
|
|
116
|
+
|
|
117
|
+
/** Register the route; a profile without a web server fails with an actionable message. */
|
|
118
|
+
async start(): Promise<void> {
|
|
119
|
+
const webServer = this.bot.ctx.get('webServer') as WebServerLike | undefined
|
|
120
|
+
if (webServer === undefined) {
|
|
121
|
+
throw this.failStart(
|
|
122
|
+
'slack: protocol "http" needs a profile-provided webServer; use protocol "ws" instead',
|
|
123
|
+
)
|
|
124
|
+
}
|
|
125
|
+
this.dispose = webServer.register({
|
|
126
|
+
kind: 'exact',
|
|
127
|
+
path: routePath(this.bot.config.path),
|
|
128
|
+
auth: 'anonymous',
|
|
129
|
+
handler: (request, response) => this.handle(request, response),
|
|
130
|
+
})
|
|
131
|
+
this.bot.online()
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Release the route. The platform keeps posting to it until the app's Request URL changes. */
|
|
135
|
+
async stop(): Promise<void> {
|
|
136
|
+
this.dispose?.()
|
|
137
|
+
this.dispose = undefined
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Log a fatal start failure before the caller throws it, because `Bot.start` only stores a connect failure on
|
|
142
|
+
* `bot.error`.
|
|
143
|
+
* @param message - error text that also names the corrective action.
|
|
144
|
+
* @returns the error for the caller to throw.
|
|
145
|
+
*/
|
|
146
|
+
private failStart(message: string): Error {
|
|
147
|
+
this.bot.ctx.logger.error(message)
|
|
148
|
+
return new Error(message)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
private async handle(
|
|
152
|
+
request: IncomingMessage,
|
|
153
|
+
response: ServerResponse,
|
|
154
|
+
): Promise<void> {
|
|
155
|
+
try {
|
|
156
|
+
if (request.method !== 'POST') {
|
|
157
|
+
writeStatus(response, 405, { allow: 'POST' })
|
|
158
|
+
return
|
|
159
|
+
}
|
|
160
|
+
if (!isJson(headerOf(request, 'content-type'))) {
|
|
161
|
+
// The Events API posts JSON; an Interactivity payload (`payload=<json>`) is a form body and out of scope.
|
|
162
|
+
writeStatus(response, 400)
|
|
163
|
+
return
|
|
164
|
+
}
|
|
165
|
+
const timestamp = headerOf(request, 'x-slack-request-timestamp')
|
|
166
|
+
const signature = headerOf(request, 'x-slack-signature')
|
|
167
|
+
if (timestamp === undefined || signature === undefined) {
|
|
168
|
+
writeStatus(response, 401)
|
|
169
|
+
return
|
|
170
|
+
}
|
|
171
|
+
const seconds = Number(timestamp)
|
|
172
|
+
const now = Math.floor(Date.now() / 1000)
|
|
173
|
+
if (
|
|
174
|
+
!Number.isFinite(seconds) ||
|
|
175
|
+
Math.abs(now - seconds) > TIMESTAMP_WINDOW_SECONDS
|
|
176
|
+
) {
|
|
177
|
+
writeStatus(response, 403)
|
|
178
|
+
return
|
|
179
|
+
}
|
|
180
|
+
// The signature covers the raw bytes, so the body is read before JSON.parse and never re-serialized.
|
|
181
|
+
const body = await readBody(request)
|
|
182
|
+
const expected = signatureOf(this.bot.config.signing, timestamp, body)
|
|
183
|
+
if (!matchesSignature(expected, signature)) {
|
|
184
|
+
writeStatus(response, 403)
|
|
185
|
+
return
|
|
186
|
+
}
|
|
187
|
+
let parsed: unknown
|
|
188
|
+
try {
|
|
189
|
+
parsed = JSON.parse(body)
|
|
190
|
+
} catch (error) {
|
|
191
|
+
this.bot.ctx.logger.warn(
|
|
192
|
+
'slack: cannot parse an Events API request: %s',
|
|
193
|
+
messageOf(error),
|
|
194
|
+
)
|
|
195
|
+
writeStatus(response, 400)
|
|
196
|
+
return
|
|
197
|
+
}
|
|
198
|
+
if (typeof parsed !== 'object' || parsed === null) {
|
|
199
|
+
writeStatus(response, 400)
|
|
200
|
+
return
|
|
201
|
+
}
|
|
202
|
+
const retryNum = headerOf(request, 'x-slack-retry-num')
|
|
203
|
+
if (retryNum !== undefined) {
|
|
204
|
+
// Redelivery is not skipped: `event_id` dedupe keeps the copy out of the store, while a skipped retry would be
|
|
205
|
+
// a lost message whenever an earlier attempt failed after the platform had given up on it.
|
|
206
|
+
this.bot.ctx.logger.debug(
|
|
207
|
+
'slack: redelivery #%s (%s)',
|
|
208
|
+
retryNum,
|
|
209
|
+
headerOf(request, 'x-slack-retry-reason') ?? 'no reason given',
|
|
210
|
+
)
|
|
211
|
+
}
|
|
212
|
+
const type = (parsed as { type?: unknown }).type
|
|
213
|
+
if (type === 'url_verification') {
|
|
214
|
+
const challenge = (parsed as { challenge?: unknown }).challenge
|
|
215
|
+
response.writeHead(200, { 'content-type': 'application/json' })
|
|
216
|
+
response.end(
|
|
217
|
+
JSON.stringify({
|
|
218
|
+
challenge: typeof challenge === 'string' ? challenge : '',
|
|
219
|
+
}),
|
|
220
|
+
)
|
|
221
|
+
return
|
|
222
|
+
}
|
|
223
|
+
if (type === 'event_callback') {
|
|
224
|
+
// Confirm first: the delivery timeout is three seconds, and intake may take longer.
|
|
225
|
+
writeOk(response)
|
|
226
|
+
await this.deliver(parsed)
|
|
227
|
+
return
|
|
228
|
+
}
|
|
229
|
+
writeOk(response)
|
|
230
|
+
this.bot.ctx.logger.debug(
|
|
231
|
+
'slack: ignored an Events API request of type "%s"',
|
|
232
|
+
String(type ?? 'unknown'),
|
|
233
|
+
)
|
|
234
|
+
} catch (error) {
|
|
235
|
+
this.bot.ctx.logger.warn(
|
|
236
|
+
'slack: Events API delivery failed: %s',
|
|
237
|
+
messageOf(error),
|
|
238
|
+
)
|
|
239
|
+
if (!response.headersSent) writeStatus(response, 500)
|
|
240
|
+
else response.end()
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** Hand one confirmed event to intake; a failed intake is logged because the confirmation already went out. */
|
|
245
|
+
private async deliver(envelope: SlackEnvelopeLike): Promise<void> {
|
|
246
|
+
let session
|
|
247
|
+
try {
|
|
248
|
+
session = decodeEvent(this.bot, envelope)
|
|
249
|
+
} catch (error) {
|
|
250
|
+
this.bot.ctx.logger.error(
|
|
251
|
+
'slack: cannot decode an event: %s',
|
|
252
|
+
messageOf(error),
|
|
253
|
+
)
|
|
254
|
+
return
|
|
255
|
+
}
|
|
256
|
+
if (session === undefined) {
|
|
257
|
+
this.bot.ctx.logger.debug(
|
|
258
|
+
'slack: ignored an %s event',
|
|
259
|
+
envelope.event?.type ?? 'unknown',
|
|
260
|
+
)
|
|
261
|
+
return
|
|
262
|
+
}
|
|
263
|
+
try {
|
|
264
|
+
await this.bot.receive(session)
|
|
265
|
+
} catch (error) {
|
|
266
|
+
this.bot.ctx.logger.error('slack: intake failed: %s', messageOf(error))
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|