All Projects → gobridge → gopherbot

gobridge / gopherbot

Licence: MIT license
Source code for the gopher Slack Bot rewrite

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to gopherbot

gopher
A gopher browser for plan9
Stars: ✭ 33 (+13.79%)
Mutual labels:  gopher
htmlhost
hostHTML.live is downright the fastest way of hosting your single page HTML!
Stars: ✭ 21 (-27.59%)
Mutual labels:  gopher
Gophers
Free gophers
Stars: ✭ 2,542 (+8665.52%)
Mutual labels:  gopher
Free Gophers Pack
✨ This pack of 100+ gopher pictures and elements will help you to build own design of almost anything related to Go Programming Language: presentations, posts in blogs or social media, courses, videos and many, many more.
Stars: ✭ 2,343 (+7979.31%)
Mutual labels:  gopher
Algernon
🎩 Small self-contained pure-Go web server with Lua, Markdown, HTTP/2, QUIC, Redis and PostgreSQL support
Stars: ✭ 1,880 (+6382.76%)
Mutual labels:  gopher
Night
Weekly Go Online Meetup via Bilibili|Go 夜读|通过 bilibili 在线直播的方式分享 Go 相关的技术话题,每天大家在微信/telegram/Slack 上及时沟通交流编程技术话题。
Stars: ✭ 10,058 (+34582.76%)
Mutual labels:  gopher
Curl
A command line tool and library for transferring data with URL syntax, supporting DICT, FILE, FTP, FTPS, GOPHER, GOPHERS, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, MQTT, POP3, POP3S, RTMP, RTMPS, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP. libcurl offers a myriad of powerful features
Stars: ✭ 22,875 (+78779.31%)
Mutual labels:  gopher
Go42
《Go语言四十二章经》详细讲述Go语言规范与语法细节及开发中常见的误区,通过研读标准库等经典代码设计模式,启发读者深刻理解Go语言的核心思维,进入Go语言开发的更高阶段。
Stars: ✭ 4,129 (+14137.93%)
Mutual labels:  gopher
gopher
A simple server for the Gopher protocol written in Go.
Stars: ✭ 17 (-41.38%)
Mutual labels:  gopher
go-sensor
🚀 Go Distributed Tracing & Metrics Sensor for Instana
Stars: ✭ 90 (+210.34%)
Mutual labels:  gopher
burrow
burrow is a helper for building and managing a gopher hole
Stars: ✭ 43 (+48.28%)
Mutual labels:  gopher
overbitenx
Because Firefox isn't complete without Gopherspace.
Stars: ✭ 50 (+72.41%)
Mutual labels:  gopher
gophersnake
Stand-alone Gopher client for modern desktops
Stars: ✭ 14 (-51.72%)
Mutual labels:  gopher
flask-gopher
A Flask extension to support the Gopher protocol
Stars: ✭ 68 (+134.48%)
Mutual labels:  gopher
fortran-curl
Fortran 2008 interface bindings to libcurl
Stars: ✭ 25 (-13.79%)
Mutual labels:  gopher

gopherbot

This is a rewrite of the original Go Slack Workspace chat bot. This big difference between that version and this, is that gopherbot uses the Slack Events API instead of the antiquated RTM (WebSocket) API.

This unfortunately results in a more complicated queue-based architecture, that results in a more resilient chat bot. As a result of it now being a queue-based system, the bot will not respond to any messages more than 30 seconds ago. So if Slack experiences an issue preventing us from replying, the message will be dropped.

Contributing

Adding Responses / Reactions

Pretty much all responses and reactions should be configured in the cmd/consumer/ directory, with each thing being split out by file. How to configure each should be fairly straightforward based on existing examples, and the usage of the handler package is documented via GoDoc if you have any questions.

Adding Definitions to Glossary

There is also the define command that is powered by the glossary package. If you'd like to add definitions to the glossary, you can do it here and raise a PR against this repo.

The glossary is meant to contain common words and terms relevant to the Go community. It's not Urban Dictionary.

Architecture

Slack API

As mentioned above, the old version used the RTM API for interacting with Slack. This is no longer the recommended API to use for building integrations, with them now suggesting The Slack Events API.

It's a HTTP+JSON based subscription model, with strict requirements on message acknowledgment times on delivery. Based on that, the best way to accept events is to write them to a queue to be processed by workers later so that some slow task doesn't violate the contract or introduce the risk of lossy message processing.

The Events API offers signing of requests, so that you can be confident the request originated from Slack.

Components

Gateway

The job for the gateway is to cryptographically validate the incoming event from Slack, confirm that it contains the metadata we expect, and then forward the message on to the work queue.

This is a pretty simple gateway, although it does use fastjson to avoid reflection to make queue routing logic decisions (based on JSON event type). There is effectively one queue for event type:

  • messages (private vs public)
  • new users joining workspace
  • new users joining a channel

The gateway is stateless and can be scaled horizontally.

Consumer

The consumer registers a handler for each of the queues, and those handlers process each message internally. They themselves may have sub-handlers that get executed, like reacting to messages with emoji versus responding to them.

If you're looking to add commands, reactions, a channel join message, or an update to the workspace join message this is the component that handles those.

The consumer is stateless and can be scaled horizontally.

BGTasks

The bgtasks component is meant to be a place where regular background jobs are ran, such as filling data caches, polling for Gerrit (Go CL) merges, or GoTime shows starting.

This currently has a channel cache poller, so that consumer handlers can look up channels by name without making many Slack API calls.

Things here cannot be safely scaled horizontally, as it could cause double messages or excessive API calls / cache fills. These jobs are kept here so that we can avoid dealing with cluster locking, in addition to our work queue. :)

Redis

More specifically, Heroku Redis. We use Redis Streams to implement the bot's workqueue. It's also where we cache some data for use in the handlers, such as mapping channel names to IDs.

Local Development

Let us get back to you on this one. :)

The most straightforward way is to run it in Heroku yourself, or simulate the environment with these environment variables:

Environment Var Description
PORT The port to bind to, used for the gateway component.
REDIS_URL Expects this in the format the Heroku provides it: redis://u:pass@host:port.
GOPHER_REDIS_INSECURE Set to 1 if Redis is over an insecure connection.
GOPHER_REDIS_SKIPVERIFY Set to 1 if you want Redis client to not verify TLS connection. Heroku Redis's certificate cannot be validated, so tis is required for production. :(
GOPHER_LOG_LEVEL Any level as recognized by github.com/rs/zerolog.
GOPHER_SLACK_APP_ID The App's unique ID. Starts with A.
GOPHER_SLACK_TEAM_ID The installed workspace's unique ID. Starts with T.
GOPHER_SLACK_CLIENT_ID The OAuth Client ID. Currently unused.
GOPHER_SLACK_CLIENT_SECRET The OAuth Client secret. Currently unused.
GOPHER_SLACK_REQUEST_TOKEN This is the static Verification Token in the App's configuration pane, sent with every request.
GOPHER_SLACK_REQUEST_SECRET This is the called the Signing Secret in the App's configuration pane, used to cryptographically validate the request.
GOPHER_SLACK_BOT_ACCESS_TOKEN The Slack API token for the Bot App. Starts with xoxb-.
HEROKU_APP_ID The UUID Heroku has given to the application. This should be set.
HEROKU_APP_NAME The human-readable name of the application. This is used for Redis key generation, and must be set.
HEROKU_DYNO_ID The UUID Heroku gives each Dyno (worker process). This is used for Redis key generation, and must be set.
HEROKU_SLUG_COMMIT The commit of the code running. This is used in logging, and should be set.

Deployment

The bot is currently running under the GoBridge Heroku organization, and merges to master are automatically deployed to the staging version (@glenda**. If a merge to master seems to have deployed okay automatically, you need to go into the Heroku UI and and promote each running app to production.

Please Note: Because Bill had requested our repo be a monorepo, our Heroku deployment configuration is an operational landmine. When clicking the "Promote to Production" button, you need to deselect the unrelated apps so that you don't accidentally promote the wrong build to production. For example, if you're promoting the gateway component you need to make sure not to promote it to the bgtasks or consumer apps. This will break the bot, and require some manual action to fix the production deployment.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].