Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/khrj/slack-bolt
- Owner: khrj
- License: mit
- Created: 2021-02-10T15:17:48.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-12-14T10:44:26.000Z (almost 3 years ago)
- Last Synced: 2024-10-28T12:15:56.778Z (9 days ago)
- Topics: bolt, deno, module, slack, slack-api, typescript
- Language: TypeScript
- Homepage: https://deno.land/x/slack_bolt
- Size: 206 KB
- Stars: 46
- Watchers: 2
- Forks: 8
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Slack Bolt
TypeScript framework to build Slack apps in a flash with the latest platform features. Deno port of @slack/bolt
## 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)