UNPKG

slack-edge

Version:

Slack app development framework for edge functions with streamlined TypeScript support

42 lines 1.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.urlVerification = void 0; exports.ignoringSelfEvents = ignoringSelfEvents; /** * Built-in middleware to handle url_verification requests. * @param req request * @returns response if needed */ // deno-lint-ignore require-await const urlVerification = async (req) => { if (req.body.type === "url_verification") { return { status: 200, body: req.body.challenge }; } }; exports.urlVerification = urlVerification; const eventTypesToKeep = ["member_joined_channel", "member_left_channel"]; /** * Built-in middleware bypass self-generated events for preventing an infinite loop of self-responses. * @param req request * @returns response if needed */ function ignoringSelfEvents(ignoreSelfAssistantMessageEvents) { // deno-lint-ignore require-await return async (req) => { if (req.body.event) { if (eventTypesToKeep.includes(req.body.event.type)) { return; } const auth = req.context.authorizeResult; const isSelfEvent = auth.botId === req.body.event.bot_id || auth.botUserId === req.context.userId; if (isSelfEvent) { if (!ignoreSelfAssistantMessageEvents && req.body.event.type === "message" && req.body.event.channel_type === "im") { // Assistant#botMessage handles this pattern return; } return { status: 200, body: "" }; } } }; } //# sourceMappingURL=built-in-middleware.js.map