@slack/bolt
Advanced tools
Comparing version 3.17.0 to 3.17.1-customFunctionBeta.0
@@ -14,2 +14,3 @@ /// <reference types="node" /> | ||
import { StringIndexed } from './types/helpers'; | ||
import { CustomFunctionMiddleware } from './CustomFunction'; | ||
/** App initialization options */ | ||
@@ -48,2 +49,3 @@ export interface AppOptions { | ||
extendedErrorHandler?: boolean; | ||
attachFunctionToken?: boolean; | ||
} | ||
@@ -148,3 +150,4 @@ export { LogLevel, Logger } from '@slack/logger'; | ||
private initialized; | ||
constructor({ signingSecret, endpoints, port, customRoutes, agent, clientTls, receiver, convoStore, token, appToken, botId, botUserId, authorize, logger, logLevel, ignoreSelf, clientOptions, processBeforeResponse, signatureVerification, clientId, clientSecret, stateSecret, redirectUri, installationStore, scopes, installerOptions, socketMode, developerMode, tokenVerificationEnabled, extendedErrorHandler, deferInitialization, }?: AppOptions); | ||
private attachFunctionToken; | ||
constructor({ signingSecret, endpoints, port, customRoutes, agent, clientTls, receiver, convoStore, token, appToken, botId, botUserId, authorize, logger, logLevel, ignoreSelf, clientOptions, processBeforeResponse, signatureVerification, clientId, clientSecret, stateSecret, redirectUri, installationStore, scopes, installerOptions, socketMode, developerMode, tokenVerificationEnabled, extendedErrorHandler, deferInitialization, attachFunctionToken, }?: AppOptions); | ||
init(): Promise<void>; | ||
@@ -164,2 +167,6 @@ /** | ||
/** | ||
* Register CustomFunction middleware | ||
*/ | ||
function(callbackId: string, ...listeners: CustomFunctionMiddleware): this; | ||
/** | ||
* Convenience method to call start on the receiver | ||
@@ -166,0 +173,0 @@ * |
@@ -21,2 +21,3 @@ "use strict"; | ||
const allSettled = require("promise.allsettled"); // eslint-disable-line @typescript-eslint/no-require-imports | ||
const CustomFunction_1 = require("./CustomFunction"); | ||
// eslint-disable-next-line @typescript-eslint/no-require-imports, import/no-commonjs | ||
@@ -51,3 +52,3 @@ const packageJson = require('../package.json'); // eslint-disable-line @typescript-eslint/no-var-requires | ||
class App { | ||
constructor({ signingSecret = undefined, endpoints = undefined, port = undefined, customRoutes = undefined, agent = undefined, clientTls = undefined, receiver = undefined, convoStore = undefined, token = undefined, appToken = undefined, botId = undefined, botUserId = undefined, authorize = undefined, logger = undefined, logLevel = undefined, ignoreSelf = true, clientOptions = undefined, processBeforeResponse = false, signatureVerification = true, clientId = undefined, clientSecret = undefined, stateSecret = undefined, redirectUri = undefined, installationStore = undefined, scopes = undefined, installerOptions = undefined, socketMode = undefined, developerMode = false, tokenVerificationEnabled = true, extendedErrorHandler = false, deferInitialization = false, } = {}) { | ||
constructor({ signingSecret = undefined, endpoints = undefined, port = undefined, customRoutes = undefined, agent = undefined, clientTls = undefined, receiver = undefined, convoStore = undefined, token = undefined, appToken = undefined, botId = undefined, botUserId = undefined, authorize = undefined, logger = undefined, logLevel = undefined, ignoreSelf = true, clientOptions = undefined, processBeforeResponse = false, signatureVerification = true, clientId = undefined, clientSecret = undefined, stateSecret = undefined, redirectUri = undefined, installationStore = undefined, scopes = undefined, installerOptions = undefined, socketMode = undefined, developerMode = false, tokenVerificationEnabled = true, extendedErrorHandler = false, deferInitialization = false, attachFunctionToken = true, } = {}) { | ||
// Some payloads don't have teamId anymore. So we use EnterpriseId in those scenarios | ||
@@ -86,2 +87,4 @@ this.clients = {}; | ||
this.extendedErrorHandler = extendedErrorHandler; | ||
// Override token with functionBotAccessToken in function-related handlers | ||
this.attachFunctionToken = attachFunctionToken; | ||
/* ------------------------ Set client options ------------------------*/ | ||
@@ -233,2 +236,11 @@ this.clientOptions = clientOptions !== undefined ? clientOptions : {}; | ||
/** | ||
* Register CustomFunction middleware | ||
*/ | ||
function(callbackId, ...listeners) { | ||
const fn = new CustomFunction_1.CustomFunction(callbackId, listeners); | ||
const m = fn.getMiddleware(); | ||
this.middleware.push(m); | ||
return this; | ||
} | ||
/** | ||
* Convenience method to call start on the receiver | ||
@@ -445,2 +457,12 @@ * | ||
}; | ||
// Extract function-related information and augment to context | ||
const { functionExecutionId, functionBotAccessToken } = extractFunctionContext(body); | ||
if (functionExecutionId) { | ||
context.functionExecutionId = functionExecutionId; | ||
} | ||
if (this.attachFunctionToken) { | ||
if (functionBotAccessToken) { | ||
context.functionBotAccessToken = functionBotAccessToken; | ||
} | ||
} | ||
// Factory for say() utility | ||
@@ -540,2 +562,7 @@ const createSay = (channelId) => { | ||
const token = selectToken(context); | ||
// Add complete() and fail() utilities for function-related interactivity | ||
if (type === helpers_1.IncomingEventType.Action && context.functionExecutionId !== undefined) { | ||
listenerArgs.complete = CustomFunction_1.CustomFunction.createFunctionComplete(context, client); | ||
listenerArgs.fail = CustomFunction_1.CustomFunction.createFunctionFail(context, client); | ||
} | ||
if (token !== undefined) { | ||
@@ -896,2 +923,17 @@ let pool; | ||
} | ||
function extractFunctionContext(body) { | ||
let functionExecutionId; | ||
let functionBotAccessToken; | ||
// function_executed event | ||
if (body.event && body.event.type === 'function_executed' && body.event.function_execution_id) { | ||
functionExecutionId = body.event.function_execution_id; | ||
functionBotAccessToken = body.event.bot_access_token; | ||
} | ||
// interactivity (block_actions) | ||
if (body.function_data) { | ||
functionExecutionId = body.function_data.execution_id; | ||
functionBotAccessToken = body.bot_access_token; | ||
} | ||
return { functionExecutionId, functionBotAccessToken }; | ||
} | ||
// ---------------------------- | ||
@@ -898,0 +940,0 @@ // Instrumentation |
@@ -28,3 +28,4 @@ /// <reference types="node" /> | ||
UnknownError = "slack_bolt_unknown_error", | ||
WorkflowStepInitializationError = "slack_bolt_workflow_step_initialization_error" | ||
WorkflowStepInitializationError = "slack_bolt_workflow_step_initialization_error", | ||
CustomFunctionInitializationError = "slack_bolt_custom_function_initialization_error" | ||
} | ||
@@ -80,2 +81,5 @@ export declare class UnknownError extends Error implements CodedError { | ||
} | ||
export declare class CustomFunctionInitializationError extends Error implements CodedError { | ||
code: ErrorCode; | ||
} | ||
//# sourceMappingURL=errors.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.WorkflowStepInitializationError = exports.MultipleListenerError = exports.HTTPReceiverDeferredRequestError = exports.ReceiverInconsistentStateError = exports.ReceiverAuthenticityError = exports.ReceiverMultipleAckError = exports.CustomRouteInitializationError = exports.InvalidCustomPropertyError = exports.ContextMissingPropertyError = exports.AuthorizationError = exports.AppInitializationError = exports.asCodedError = exports.UnknownError = exports.ErrorCode = void 0; | ||
exports.CustomFunctionInitializationError = exports.WorkflowStepInitializationError = exports.MultipleListenerError = exports.HTTPReceiverDeferredRequestError = exports.ReceiverInconsistentStateError = exports.ReceiverAuthenticityError = exports.ReceiverMultipleAckError = exports.CustomRouteInitializationError = exports.InvalidCustomPropertyError = exports.ContextMissingPropertyError = exports.AuthorizationError = exports.AppInitializationError = exports.asCodedError = exports.UnknownError = exports.ErrorCode = void 0; | ||
var ErrorCode; | ||
@@ -22,2 +22,3 @@ (function (ErrorCode) { | ||
ErrorCode["WorkflowStepInitializationError"] = "slack_bolt_workflow_step_initialization_error"; | ||
ErrorCode["CustomFunctionInitializationError"] = "slack_bolt_custom_function_initialization_error"; | ||
})(ErrorCode = exports.ErrorCode || (exports.ErrorCode = {})); | ||
@@ -121,2 +122,9 @@ class UnknownError extends Error { | ||
exports.WorkflowStepInitializationError = WorkflowStepInitializationError; | ||
class CustomFunctionInitializationError extends Error { | ||
constructor() { | ||
super(...arguments); | ||
this.code = ErrorCode.CustomFunctionInitializationError; | ||
} | ||
} | ||
exports.CustomFunctionInitializationError = CustomFunctionInitializationError; | ||
//# sourceMappingURL=errors.js.map |
@@ -9,3 +9,3 @@ import { View, MessageAttachment, KnownBlock, Block } from '@slack/types'; | ||
*/ | ||
export declare type SlackEvent = AppRequestedEvent | AppHomeOpenedEvent | AppMentionEvent | AppRateLimitedEvent | AppUninstalledEvent | CallRejectedEvent | ChannelArchiveEvent | ChannelCreatedEvent | ChannelDeletedEvent | ChannelHistoryChangedEvent | ChannelIDChangedEvent | ChannelLeftEvent | ChannelRenameEvent | ChannelSharedEvent | ChannelUnarchiveEvent | ChannelUnsharedEvent | DNDUpdatedEvent | DNDUpdatedUserEvent | EmailDomainChangedEvent | EmojiChangedEvent | FileChangeEvent | FileCommentDeletedEvent | FileCreatedEvent | FileDeletedEvent | FilePublicEvent | FileSharedEvent | FileUnsharedEvent | GridMigrationFinishedEvent | GridMigrationStartedEvent | GroupArchiveEvent | GroupCloseEvent | GroupDeletedEvent | GroupHistoryChangedEvent | GroupLeftEvent | GroupOpenEvent | GroupRenameEvent | GroupUnarchiveEvent | IMCloseEvent | IMCreatedEvent | IMHistoryChangedEvent | IMOpenEvent | InviteRequestedEvent | LinkSharedEvent | MemberJoinedChannelEvent | MemberLeftChannelEvent | MessageEvent | MessageMetadataEvent | PinAddedEvent | PinRemovedEvent | ReactionAddedEvent | ReactionRemovedEvent | SharedChannelInviteReceived | SharedChannelInviteAccepted | SharedChannelInviteApproved | SharedChannelInviteDeclined | StarAddedEvent | StarRemovedEvent | SubteamCreated | SubteamMembersChanged | SubteamSelfAddedEvent | SubteamSelfRemovedEvent | SubteamUpdatedEvent | TeamAccessGrantedEvent | TeamAccessRevokedEvent | TeamDomainChangedEvent | TeamJoinEvent | TeamRenameEvent | TokensRevokedEvent | UserChangeEvent | UserHuddleChangedEvent | UserProfileChangedEvent | UserStatusChangedEvent | WorkflowDeletedEvent | WorkflowPublishedEvent | WorkflowUnpublishedEvent | WorkflowStepDeletedEvent | WorkflowStepExecuteEvent; | ||
export declare type SlackEvent = AppRequestedEvent | AppHomeOpenedEvent | AppMentionEvent | AppRateLimitedEvent | AppUninstalledEvent | CallRejectedEvent | ChannelArchiveEvent | ChannelCreatedEvent | ChannelDeletedEvent | ChannelHistoryChangedEvent | ChannelIDChangedEvent | ChannelLeftEvent | ChannelRenameEvent | ChannelSharedEvent | ChannelUnarchiveEvent | ChannelUnsharedEvent | DNDUpdatedEvent | DNDUpdatedUserEvent | EmailDomainChangedEvent | EmojiChangedEvent | FileChangeEvent | FileCommentDeletedEvent | FileCreatedEvent | FileDeletedEvent | FilePublicEvent | FileSharedEvent | FileUnsharedEvent | FunctionExecutedEvent | GridMigrationFinishedEvent | GridMigrationStartedEvent | GroupArchiveEvent | GroupCloseEvent | GroupDeletedEvent | GroupHistoryChangedEvent | GroupLeftEvent | GroupOpenEvent | GroupRenameEvent | GroupUnarchiveEvent | IMCloseEvent | IMCreatedEvent | IMHistoryChangedEvent | IMOpenEvent | InviteRequestedEvent | LinkSharedEvent | MemberJoinedChannelEvent | MemberLeftChannelEvent | MessageEvent | MessageMetadataEvent | PinAddedEvent | PinRemovedEvent | ReactionAddedEvent | ReactionRemovedEvent | SharedChannelInviteReceived | SharedChannelInviteAccepted | SharedChannelInviteApproved | SharedChannelInviteDeclined | StarAddedEvent | StarRemovedEvent | SubteamCreated | SubteamMembersChanged | SubteamSelfAddedEvent | SubteamSelfRemovedEvent | SubteamUpdatedEvent | TeamAccessGrantedEvent | TeamAccessRevokedEvent | TeamDomainChangedEvent | TeamJoinEvent | TeamRenameEvent | TokensRevokedEvent | UserChangeEvent | UserHuddleChangedEvent | UserProfileChangedEvent | UserStatusChangedEvent | WorkflowDeletedEvent | WorkflowPublishedEvent | WorkflowUnpublishedEvent | WorkflowStepDeletedEvent | WorkflowStepExecuteEvent; | ||
export declare type EventTypePattern = string | RegExp; | ||
@@ -307,2 +307,34 @@ /** | ||
} | ||
export interface FunctionParams { | ||
type?: string; | ||
name?: string; | ||
description?: string; | ||
title?: string; | ||
is_required?: boolean; | ||
} | ||
export interface FunctionInputs { | ||
[key: string]: unknown; | ||
} | ||
export declare type FunctionOutputValues = FunctionInputs; | ||
export interface FunctionExecutedEvent { | ||
type: 'function_executed'; | ||
function: { | ||
id: string; | ||
callback_id: string; | ||
title: string; | ||
description: string; | ||
type: string; | ||
input_parameters: FunctionParams[]; | ||
output_parameters: FunctionParams[]; | ||
app_id: string; | ||
date_created: number; | ||
date_updated: number; | ||
date_deleted: number; | ||
}; | ||
inputs: FunctionInputs; | ||
function_execution_id: string; | ||
workflow_execution_id: string; | ||
event_ts: string; | ||
bot_access_token: string; | ||
} | ||
export interface GridMigrationFinishedEvent { | ||
@@ -309,0 +341,0 @@ type: 'grid_migration_finished'; |
{ | ||
"name": "@slack/bolt", | ||
"version": "3.17.0", | ||
"version": "3.17.1-customFunctionBeta.0", | ||
"description": "A framework for building Slack apps, fast.", | ||
@@ -44,6 +44,6 @@ "author": "Slack Technologies, LLC", | ||
"@slack/logger": "^4.0.0", | ||
"@slack/oauth": "^2.6.1", | ||
"@slack/socket-mode": "^1.3.2", | ||
"@slack/oauth": "^2.6.2", | ||
"@slack/socket-mode": "^1.3.3", | ||
"@slack/types": "^2.11.0", | ||
"@slack/web-api": "^6.11.0", | ||
"@slack/web-api": "^6.12.0", | ||
"@types/express": "^4.16.1", | ||
@@ -63,7 +63,7 @@ "@types/promise.allsettled": "^1.0.3", | ||
"@types/mocha": "^10.0.1", | ||
"@types/node": "20.10.5", | ||
"@types/node": "20.11.5", | ||
"@types/sinon": "^7.0.11", | ||
"@typescript-eslint/eslint-plugin": "^4.4.1", | ||
"@typescript-eslint/parser": "^4.4.0", | ||
"chai": "^4.2.0", | ||
"chai": "~4.3.0", | ||
"eslint": "^7.26.0", | ||
@@ -70,0 +70,0 @@ "eslint-config-airbnb-base": "^14.2.1", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
557417
175
7943
1
Updated@slack/oauth@^2.6.2
Updated@slack/socket-mode@^1.3.3
Updated@slack/web-api@^6.12.0