UNPKG

@slack/bolt

Version:

A framework for building Slack apps, fast.

96 lines 3.76 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.HTTPResponseAck = void 0; const errors_1 = require("../errors"); const httpFunc = __importStar(require("./HTTPModuleFunctions")); class HTTPResponseAck { logger; isAcknowledged; processBeforeResponse; unhandledRequestHandler; unhandledRequestTimeoutMillis; httpRequest; httpResponse; noAckTimeoutId; // biome-ignore lint/suspicious/noExplicitAny: response bodies can be anything storedResponse; constructor(args) { this.logger = args.logger; this.isAcknowledged = false; this.processBeforeResponse = args.processBeforeResponse; this.unhandledRequestHandler = args.unhandledRequestHandler ?? httpFunc.defaultUnhandledRequestHandler; this.unhandledRequestTimeoutMillis = args.unhandledRequestTimeoutMillis ?? 3001; this.httpRequest = args.httpRequest; this.httpResponse = args.httpResponse; this.storedResponse = undefined; this.noAckTimeoutId = undefined; this.init(); } init() { this.noAckTimeoutId = setTimeout(() => { if (!this.isAcknowledged) { this.unhandledRequestHandler({ logger: this.logger, request: this.httpRequest, response: this.httpResponse, }); } }, this.unhandledRequestTimeoutMillis); return this; } bind() { return async (responseBody) => { this.logger.debug(`ack() call begins (body: ${responseBody})`); if (this.isAcknowledged) { throw new errors_1.ReceiverMultipleAckError(); } this.ack(); if (this.processBeforeResponse) { // In the case where processBeforeResponse: true is enabled, // we don't send the HTTP response immediately. We hold off until the listener execution is completed. if (!responseBody) { this.storedResponse = ''; } else { this.storedResponse = responseBody; } this.logger.debug(`ack() response stored (body: ${responseBody})`); } else { httpFunc.buildContentResponse(this.httpResponse, responseBody); this.logger.debug(`ack() response sent (body: ${responseBody})`); } }; } ack() { this.isAcknowledged = true; if (this.noAckTimeoutId) { clearTimeout(this.noAckTimeoutId); } } } exports.HTTPResponseAck = HTTPResponseAck; //# sourceMappingURL=HTTPResponseAck.js.map