Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/devict/bot


https://github.com/devict/bot

bot deno slack slack-bot typescript

Last synced: 11 days ago
JSON representation

Awesome Lists containing this project

README

        

# 🤖 devICT bot 🤖

A slack bot powered by Slack webhook events.

## Overview

This is _not_ using any of the Slack platform stuff. Trying to keep it simple by
simply receiving webhook events from Slack and responding to those events
however we want.

- Runs as an API service listening on a `/slack/event` endpoint for webhook
events from Slack.
- Deployed to Deno Deploy
- Commands are implemented as handlers that are executed if the message from the
event matches some defined criteria.
- Check the
[commands/ping.ts](https://github.com/devict/bot/tree/main/commands/ping.ts)
for a basic example.
- Responses to the events are sent as separate HTTP requests, not as responses
to the incoming webhooks.
- We're using the
[@slack/web-api](https://www.npmjs.com/package/@slack/web-api) package,
which is a thin wrapper over Slack's HTTP API.

## Contributing

This is a great project to contribute to as a member of the devICT community!

## Local dev

This project runs on TypeScript with Deno.

### Setup

- [Install deno](https://docs.deno.com/runtime/manual/getting_started/installation/)
with `brew install deno`, or several other methods
- Copy `.env.example` to `.env`
- Plug your `SLACK_TOKEN` in to `.env` (reach out to
[@seth](https://devict.slack.com/archives/D19FFBMPB) for this)
- Run `deno task cache` to download dependencies

### Running the service

- `deno task start`

### Testing commands locally

There is a separate Slack app for development (`@bot (test)`) that can be used.
Reach out to [@seth](https://devict.slack.com/archives/D19FFBMPB) in Slack for
the `SLACK_TOKEN`.

Simulate events from Slack hitting your local server with the
`bin/simulate-message` util.

```
$ bin/simulate-message.ts "@bot ping"
```

or for windows

```
deno run --env --allow-env --allow-net .\bin\simulate-message.ts "@bot ping"
```

You won't see the simulated message in Slack, but the response will show up
there from `@bot (test)`.

#### Testing reply in thread responses

To test reply in thread responses, you can pass a `thread_ts` to the `simulate-message.ts command`.

```
$ bin/simulate-message.ts "@bot events" "1724586898.242849"
```

To get the `thread_ts` for your message:

- Post a message of your own in the `#bot-testing` channel
- Post _another_ message as a threaded reply to the first one
- Copy the link to the threaded reply message
- Grab the `thread_ts` query param from the URL

## Slack App

This bot is installed in the devICT work space as a Slack app called **bot**.

- The [OAuth & Permissions](https://api.slack.com/apps/A07B9TL6EMT/oauth) page
contains the `SLACK_TOKEN` needed to power the bot.
- The following scopes must be added: `app_mentions:read`, `chat:write`
- The event receiving endpoint must be added on the
[Event Subscriptions](https://api.slack.com/apps/A07B9TL6EMT/event-subscriptions)
page.
- Events to subscribe to: `app_mention`

## Slack Events

[A list of all the events can be seen here](https://api.slack.com/events).

The events the bot responds to are defined in the `events.ts` module. Typebox
schemas are defined for the events we respond to.

_Note: If we want to respond to new event types, we will need to add them in the
Slack app console before Slack will start sending them._

## Deployment

Bot is deployed on Deno Deploy. The Slack App points to the `/slack/event`
endpoint of the deployed bot API (this repo).