Code on GitHub Slack Platform Home

@slack/events-api

Classes

SlackEventAdapter

An adapter for Slack’s Events API.

new SlackEventAdapter(signingSecret, opts)

Constructs a new instance of the SlackEventAdapter class

Parameters:

Name Type Required Description
signingSecret string

The token used to authenticate signed requests from Slack's Events API.

opts EventAdapterOptions See options.

Options:

Name Type
includeBody boolean
includeHeaders boolean
waitForResponse boolean

Fields

Name Type Description
includeBody boolean

Whether to include the API event bodies in adapter event listeners.

includeHeaders boolean

Whether to include request headers in adapter event listeners.

signingSecret string

The token used to authenticate signed requests from Slack's Events API.

waitForResponse boolean

When true prevents the adapter from responding by itself and leaves that up to listeners.

Methods

createServer()

Creates an HTTP server to listen for event payloads.

Returns Promise<http.Server>

expressMiddleware()

Returns a middleware-compatible adapter.

Returns RequestHandler

requestListener()

Creates a request listener.

Returns RequestListener

start(port)

Starts a server on the specified port.

Parameters:

Name Type Required Description
port number

The port number to listen on.

Returns Promise<http.Server>

stop()

Stops the server started by SlackEventAdapter.

Returns Promise<void>

Functions

createEventAdapter(signingSecret, options)

Creates a new SlackEventAdapter.

Parameters:

Name Type Required
signingSecret string
options EventAdapterOptions

Returns SlackEventAdapter

verifyRequestSignature(opts)

Verifies the signature of a request. Throws a CodedError if the signature is invalid.

Remarks

See Verifying requests from Slack for more information.

Parameters:

Name Type Required
opts VerifyRequestSignatureParams

Options:

Name Type Description
body string

Full, raw body string.

requestSignature string

Signature from the X-Slack-Signature header.

requestTimestamp number

Timestamp from the X-Slack-Request-Timestamp header.

signingSecret string

The signing secret used to verify request signature.

Returns true:

true when the signature is valid.

Enums

ErrorCode

A dictionary of codes for errors produced by this package.

Members

  • BodyParserNotPermitted
  • RequestTimeFailure
  • SignatureVerificationFailure

Interfaces

CodedError

All errors produced by this package are regular Error objects with an extra CodedError field.

Fields

Name Type Description
code ErrorCode

What kind of error occurred.

EventAdapterOptions

Options when constructing SlackEventAdapter. See SlackEventAdapter’s fields for more information on what each option does.

Fields

Name Type
includeBody boolean
includeHeaders boolean
waitForResponse boolean

VerifyRequestSignatureParams

Parameters for calling verifyRequestSignature.

Fields

Name Type Description
body string

Full, raw body string.

requestSignature string

Signature from the X-Slack-Signature header.

requestTimestamp number

Timestamp from the X-Slack-Request-Timestamp header.

signingSecret string

The signing secret used to verify request signature.