All Projects → OperationCode → operationcode-pybot

OperationCode / operationcode-pybot

Licence: other
Operation Code's Official Slackbot

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to operationcode-pybot

resources api
Flask API for programming and cyber security learning resources
Stars: ✭ 63 (+117.24%)
Mutual labels:  hacktoberfest2017, hacktoberfest2018, hacktoberfest2019, hacktoberfest2020
Slack Machine
A sexy, simple, yet powerful and extendable Slack bot
Stars: ✭ 91 (+213.79%)
Mutual labels:  slackbot, slack-api
Slack Poster
Simple gem to post messages on Slack using web hooks.
Stars: ✭ 49 (+68.97%)
Mutual labels:  slackbot, slack-api
slacking
Modern Slack C++ 11 library for communicating with the Web Slack API
Stars: ✭ 58 (+100%)
Mutual labels:  slackbot, slack-api
dienstplan
Slack bot app for duty rotations
Stars: ✭ 14 (-51.72%)
Mutual labels:  slackbot, slack-api
Slacker
Slack Bot Framework
Stars: ✭ 495 (+1606.9%)
Mutual labels:  slackbot, slack-api
Slack Block Builder
Lightweight, no-dependency JavaScript library for creating Slack Block Kit UIs, with a builder syntax, inspired by SwiftUI.
Stars: ✭ 129 (+344.83%)
Mutual labels:  slackbot, slack-api
fridaybot
Slack bot for https://spb-frontend.slack.com
Stars: ✭ 29 (+0%)
Mutual labels:  slackbot, slack-api
IOSD-UIETKUK-HacktoberFest-Meetup-2019
This repository for IOSD HacktoberFest 2020
Stars: ✭ 17 (-41.38%)
Mutual labels:  hacktoberfest2019, hacktoberfest2020
cpalgorithms
Algorithms and Techniques for competitive programming
Stars: ✭ 16 (-44.83%)
Mutual labels:  hacktoberfest2019, hacktoberfest2020
Bolt Python
A framework to build Slack apps using Python
Stars: ✭ 190 (+555.17%)
Mutual labels:  aiohttp, slack-api
slackr
Simple shell command to send or pipe content to slack via webhooks. (To upload snippets or files use: www.github.com/a-sync/slackfu)
Stars: ✭ 41 (+41.38%)
Mutual labels:  slackbot, slack-api
Idea-ReVue
Social Ideation application to manage Ideas. Developed with Vue, Firebase & Vuetify
Stars: ✭ 15 (-48.28%)
Mutual labels:  hacktoberfest2019, hacktoberfest2020
Slack Ruby Client
A Ruby and command-line client for the Slack Web, Real Time Messaging and Event APIs.
Stars: ✭ 957 (+3200%)
Mutual labels:  slackbot, slack-api
Hactoberfest-2021
Make your first PR! ~ A beginner friendly repository made specifically for open source beginners. Add your profile, a blog or any program under any language (it can be anything from a hello-world program to a complex data structure algorithm) or update the existing one. Just make sure to add the file under the correct directory. Happy hacking!
Stars: ✭ 134 (+362.07%)
Mutual labels:  hacktoberfest2018, hacktoberfest2020
noobtoberfest
Game-coding challenge for everyone who wants to contribute to an open-source project for Hacktoberfest 2020 🎮
Stars: ✭ 32 (+10.34%)
Mutual labels:  hacktoberfest2019, hacktoberfest2020
inspireNuggetsSlackBot
A simple Slackbot that displays random inspiring techie quotes and jokes for developers/designers.
Stars: ✭ 15 (-48.28%)
Mutual labels:  slackbot, slack-api
hacktoberfest2020
This is a hacktoberfest repo with learning propose to make pull request(PR) and get contribute on opensource project
Stars: ✭ 13 (-55.17%)
Mutual labels:  hacktoberfest2020
slack-cat
meow
Stars: ✭ 16 (-44.83%)
Mutual labels:  slackbot
Hackerrank-Codes
Here are some of the solutions to HackerRank questions.
Stars: ✭ 63 (+117.24%)
Mutual labels:  hacktoberfest2020

License: MIT Twitter Follow Code-style: black

CircleCI PRs Welcome

OperationCode-Pybot

OperationCode PyBot is a Python Slack Bot utilizing Slack Bolt.

Resources

Contributing

Bug reports and pull requests are welcome on our Github repo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct. The best place to get assistance with OperationCode-Pybot is on Slack in the #oc-python-project channel.

Quick Start

Recommended versions of tools used within the repo:

  • [email protected] or greater
  • [email protected] or greater - pipenv is a package manager similar to poetry that utilizes pip to manage project dependencies, along with creating new virtual environments and deterministic builds
# Ensure you have pipenv already installed
pipenv install --dev

# Start up your virtual environment
pipenv shell

# Run the test suite
pytest

# Run the code formatter
black .

How to Test Integration with SlackAPI

In order to test the new methods and interactions you may have created already, you'll need an "app configuration token". In order to get one of those, you'll need to create a new issue. Please use the type: config token request label and make the title " Requests an App Config Token". For example: Judson Stevens Requests an App Config Token.

Once you have created your issue, one of the maintainers of this repository will get in touch and give you your token.

How to Test Integration With Slack

After having developed some new feature, or having in hand what you believe is a fix for an existing bug, how do you test it out in a real system in order to make sure that your changes do all that you hope they do? The answer; bring up the application in your own environment and hook it up to Slack!

In order to do this, you'll want to tackle the following items in order:

  1. Setup your own Slack workspace.
  2. Grab a signing secret from Slack that pybot can utilize.
  3. Launch pybot locally, passing it your Slack signing secret.
  4. Attach your pybot instance to the public internet so that Slack can speak with it.
  5. Point Slack at your running pybot instance, and properly configure it.

The following sections will guide you through each of these stages.

1 - Setup Your Own Slack Workspace

To start, you'll want to visit Slack's Getting Started page. From this page, follow the steps required to create a new workspace. The names/options you configure during creation don't matter so much, but make sure you associate it with an email address you have access to. Once complete it should present you with an option to login to the new workspace, make sure you go ahead and do that.

If you're having a hard time figuring this out, try checking out the following Slack article Create a Slack Workspace.

Create expected channels

Several of Pybot's features involve sending messages to specific channels - in order for this to work in your personal Slack workspace you'll need to create the following channels:

  • mentors-internal
  • greetings
  • moderators
  • oc-tech

2 - Create a pybot App in Your Slack Workspace

The next step is to create a new bot application in your workspace. While still logged in, visit the App Management page and choose to create a new app. During this process, make sure to copy down the signing secret key that gets generated for your app, as you'll need it later, following this, follow the guidelines for creating a bot app as laid out in the Enabling interactions with bots article. When you get to the stage of creating the bot user, make sure to write down the bot user OAuth access token that is presented, as you'll need to use it later.

On the OAuth & Permissions page configure the Pybot app with the following scopes

  • channels:manage
  • chat:write
  • chat:write.public
  • commands
  • users:read

3 - Launch pybot Locally, Passing in Your Signing Secret

With your Slack workspace, app and bot user created, and your app signing secret and bot user OAuth access token in hand, you should now be ready to configure pybot to integrate with your new Slack workspace. To do this, you'll first want to setup the proper configuration in pybot.

pybot configuration is specified completely through environment variables. When running locally, you can configure the ./docker/pybot.env file with the environment variable name/value pairings, which will get evaluated on application start. Otherwise, make sure to export or pass in the correct environment variables through your shell when launching pybot.

Here's an example of configuring these through the pybot.env file:

SLACK_BOT_SIGNING_SECRET=APP-SIGNING-SECRET
BOT_USER_OAUTH_ACCESS_TOKEN=BOT-USER-OAUTH-TOKEN

NOTE: More configuration settings than these may be specified. Please see the Known Configuration Settings section near the bottom of this document for details on other settings that can be set.

4 - Attach Your pybot Instance to the Public Internet

With an instance of pybot running, you now need to expose this instance to the public internet so Slack can send in API requests. You can easily utilize ngrok for this purpose if you wish. To do so; download ngrok from https://ngrok.com/download and set up a tunnel like so:

ngrok http 5000

Pay attention to copy out the response you get and keep this command running. Here's an example output from the command:

ngrok by @inconshreveable                                                                        (Ctrl+C to quit)
Session Status                online                                                                             
Session Expires               7 hours, 56 minutes                                                                
Version                       2.3.35                                                                             
Region                        United States (us)                                                                 
Web Interface                 http://127.0.0.1:4040                                                              
Forwarding                    http://9d73595a7aac.ngrok.io -> http://localhost:5000                              
Forwarding                    https://9d73595a7aac.ngrok.io -> http://localhost:5000                             
Connections                   ttl     opn     rt1     rt5     p50     p90                                        
                              0       1       0.00    0.00    0.00    0.00                                       
HTTP Requests 

With this done, ngrok will now expose the instance of pybot running locally on port 5000 via the "Forwarding" address it returns. Be sure to use the URL beginning with https.

5 - Point Slack at Your Running pybot Instance

With the initial Slack configuration complete and your instance of pybot running on the public internet, it is now the perfect time to fully configure Slack to interact with your bot. Depending on the interactions you're wanting to play with, there are various configurations you can specify, which can be broken down into the following parts:

  • Event Subscriptions - this allows pybot to respond to various events that may occur in your Slack workspace.
  • Slash Commands - this allows a user to invoke various commands from any channel in your workspace to interact with pybot.
  • Interactive Components - this allows various options to be exposed when right clicking on a message, or, when the bot presents various user elements that can be interacted with, instructs Slack on where to send the results for such interactions.

High level steps for configuring each of these can be found in the following sub-sections; note that you don't need to necessarily configure all of these, it all depends on what areas of pybot you're wanting to play with.

Event Subscriptions

You can follow the instructions (and read helpful related information) on the Events API page on Slack to setup event subscriptions. When configuring your events URI; make sure you pass in the Base-URI that pybot is listening on followed by the text /slack/events. For example:

https://123_random_code_321.ngrok.io/slack/events

Additional setup may be needed depending on the type of events pybot is subscribing to. For example, in order to work on the app's functionality on a team_join event, you need to:

  • Add team_join to workspace event
  • Make sure greetings channel exists and ensure the app is invited to the channel
  • Add necessary OAuth scopes to the app e.g. users:read, chat:write, etc.

In the section which says "Subscribe to events on behalf of users", you must add the following events:

Event Name Required OAuth Scope
member_joined_channel channels:read or groups:read
message.channels channels:history
message.groups groups:history
message.im im:history
team_join users:read

Slash Commands

You can follow the instructions (and read helpful related information) on the Enabling interactivity with Slash Commands page on Slack to setup pybot slash commands. When configuring a Slash command, make sure you configure the request URL to match the Base-URI that pybot is listening on followed by the text /slack/commands. For example:

https://123_random_code_321.ngrok.io/slack/commands

You'll use the same URI for each command. Here's a table listing of currently supported commands along with some suggested configuration text:

Command Description Usage Hint
/lunch find lunch suggestions nearby <zip code> <distance in miles>
/mentor request mentoring
/mentor-volunteer offer to mentor others
/repeat parrot canned messages <10000
/report report something to the admins
/roll roll x dice with y sides
/ticket submit ticket to admins (text of ticket)

👋 IMPORTANT!

The /lunch command requires a valid Yelp API token stored in the YELP_TOKEN environment variable. See https://www.yelp.com/developers/faq

Similarly, the /mentor and /mentor-volunteer commands require access to an Airtable environment with a specific configuration. If you're planning on working with the mentor functionality please reach out to the #oc-python-projects channel for help getting set up.

Interactive Components

You can follow the instructions (and read helpful related information) on the Handling user interaction in your Slack apps page on Slack to setup Slack interactive component configuration. When configuring the request URL, you'll want to set it to the Base-URI that pybot is listening on followed by the text /slack/actions. For example:

https://123_random_code_321.ngrok.io/slack/actions

You'll also want to make sure to configure the report message action with the following parameters:

Name Description Callback ID
Report Message Report this message to admins report_message

Known Configuration Settings

This application has a number of environment variables that can be set when launching to alter the behaviour of the application. The list below is an incomplete description of a number of them. Please feel free to update this list with more details via a PR:

Name Description Example
SLACK_BOT_SIGNING_SECRET The unique signing secret used by Slack for a specific app that will be validated by pybot when inspecting an inbound API request f3b4d774b79e0fb55af624c3f376d5b4
BOT_USER_OAUTH_ACCESS_TOKEN The bot user specific OAuth token used to authenticate the bot when making API requests to Slack xoxb-800506043194-810119867738-vRvgSc3rslDUgQakFbMy3wAt

License

This package is available as open source under the terms of the MIT License.

Notes

Option 1 - Create your own Slack workspace to use for testing. Follow this guide

Start the application with WebSockets instead of HTTP for better development experience? Requires the use of the SLACK_APP_TOKEN. Would need to set an environment variable to determine if we were in development or staging/production.

Database to store history of events or just use logging? Probably best to use a database to store history of requests and responses? Easier to track interactions that way.

Utilizing FastAPI allows us to take advantage of things like Pydantic, inherent typing, models, and a better handler for the HTTP requests themselves.

Utilizing FastAPI and Slack-Bolt.

All the interactive elements of this bot were built using the Slack Block Kit Builder. The example JSON for each interactive element can be found in the modules/slack/blocks/block_kit_examples folder.

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].