Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/khrj/slack-bolt

TypeScript framework to build Slack apps in a flash with the latest platform features. Deno port of @slack/bolt
https://github.com/khrj/slack-bolt

bolt deno module slack slack-api typescript

Last synced: about 4 hours ago
JSON representation

TypeScript framework to build Slack apps in a flash with the latest platform features. Deno port of @slack/bolt

Awesome Lists containing this project

README

        


blueprint illustration

Slack Bolt



TypeScript framework to build Slack apps in a flash with the latest platform features. Deno port of @slack/bolt



build status
language
code size
issues
license
version



View on deno.land



Slack Bolt for Deno - TypeScript framework to build Slack apps with Deno rapidly | Product Hunt








## Table of Contents

- [Usage](#usage)
- [API](#api)
- [Quirks](#quirks)
- [Supporters](#supporters)
- [Related](#related)

## Usage

```ts
import "https://deno.land/x/[email protected]/load.ts"
import { App } from "https://deno.land/x/[email protected]/mod.ts"

const app = new App({
signingSecret: Deno.env.get("SLACK_SIGNING_SECRET"),
token: Deno.env.get("SLACK_BOT_TOKEN"),
ignoreSelf: true,
})

app.event("message", async ({ event, say }) => {
console.log(event)
await say("pong")
})

await app.start({ port: 3000 })
console.log("🦕 ⚡️")
```

## API

- Methods are similar to the [node @slack/bolt](https://www.npmjs.com/package/@slack/bolt)
- Full generated documentation is available [here](https://doc.deno.land/https/deno.land/x/[email protected]/mod.ts)

## Quirks

`OpineReciever` and `HTTPReceiver`/`SocketModeReciever` req/res types are not compatible. This causes trouble when providing a custom callback for built-in oauth failure / success (if you're not using built-in oauth / not implementing custom callbacks for failure / success, you don't have to worry about this). This requires a [type guard](https://www.typescriptlang.org/docs/handbook/advanced-types.html) (See simpler alternative below).

```ts
import { ServerRequest } from "https://deno.land/[email protected]/http/server.ts"
import {
ParamsDictionary,
Request as OpineRequest,
Response as OpineResponse,
} from "https://deno.land/x/[email protected]/mod.ts"

const customCallbackOptions = {
failure: async (
req: ServerRequest | OpineRequest,
res?: OpineResponse,
) => {
if (isOpineRequest(req)) {
// Your custom code here, req is Request and res is Response from deno.land/x/opine
// Example:
res?.setStatus(500).send(
"

OAuth failed!

See stderr for errors.
",
)
} else {
// Your custom code here, req is a std/http ServerRequest, res is undefined
// Example:
await req.respond({
status: 500,
headers: new Headers({
"Content-Type": "text/html",
}),
body:
`

OAuth failed!

`,
})
}

function isOpineRequest(
_req: ServerRequest | OpineRequest,
res?: OpineResponse,
): _req is OpineRequest {
return !!res // If res exists, OpineReciever is being used since only 'req' exists for HTTPReciever and SocketModeReceiver
}
},
}
```

Alternatively, just specify the correct type according to your Receiver (if you don't specify this, its `HTTPReceiver` by default)

- For HTTPReceiver (default) / SocketModeReceiver

```ts
import { ServerRequest } from "https://deno.land/[email protected]/http/server.ts"
const customCallbackOptions = {
failure: async (req: ServerRequest) => {
// Your custom code here
// Example:
await req.respond({
status: 500,
headers: new Headers({
"Content-Type": "text/html",
}),
body: `

OAuth failed!

`,
})
},
}
```

- For OpineReceiver

```ts
import {
ParamsDictionary,
Request as OpineRequest,
Response as OpineResponse,
} from "https://deno.land/x/[email protected]/mod.ts"

const customCallbackOptions = {
failure: async (
req: OpineRequest,
res: OpineResponse,
) => {
// Your custom code here, req is Request and res is Response from deno.land/x/opine
// Example:
res?.setStatus(500).send(
"

OAuth failed!

See stderr for errors.
",
)
},
}
```

## Supporters

[![Stargazers repo roster for @khrj/slack-bolt](https://reporoster.com/stars/khrj/slack-bolt)](https://github.com/khrj/slack-bolt/stargazers)

[![Forkers repo roster for @khrj/slack-bolt](https://reporoster.com/forks/khrj/slack-bolt)](https://github.com/khrj/slack-bolt/network/members)

## Related

- [Deno Slack SDK](https://github.com/slack-deno/deno-slack-sdk)
- [Deno modules](https://github.com/khrj/deno-modules)