generated from marcieltorres/python-boilerplate-project
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creating a simple Bot using slack bolt package
- Loading branch information
1 parent
23dc966
commit f4d0853
Showing
10 changed files
with
70 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.github | ||
.docs | ||
.vscode | ||
.pytest_cache | ||
.ruff_cache | ||
*.md | ||
*.md |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
ENV=dev | ||
PYTHONPATH=. | ||
PYTHONPATH=. | ||
SLACK_BOT_TOKEN= | ||
SLACK_APP_TOKEN= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from asyncio import run as async_run | ||
from logging import getLogger | ||
from logging.config import fileConfig as logConfig | ||
from os import getenv | ||
|
||
from slack_bolt.adapter.socket_mode.async_handler import AsyncSocketModeHandler | ||
from slack_bolt.async_app import AsyncApp | ||
|
||
from src.messages.constants import DEFAULT_WARNING_MESSAGE | ||
from src.rules.pattern import pattern | ||
|
||
logConfig("./logging.conf", disable_existing_loggers=False) | ||
logger = getLogger(__name__) | ||
|
||
SLACK_BOT_TOKEN = getenv("SLACK_BOT_TOKEN", "").strip() | ||
SLACK_APP_TOKEN = getenv("SLACK_APP_TOKEN", "").strip() | ||
|
||
app = AsyncApp(token=SLACK_BOT_TOKEN) | ||
|
||
@app.message(pattern.compiled_pattern) | ||
async def say_hello_regex(say, message, client): | ||
user = message['user'] | ||
await say(text=DEFAULT_WARNING_MESSAGE.format(name=f'<@{user}>'), thread_ts=message.get('ts')) | ||
|
||
async def main(): | ||
try: | ||
handler = AsyncSocketModeHandler(app, SLACK_APP_TOKEN) | ||
await handler.start_async() | ||
except Exception as ex: | ||
logger.error("Error when starting the bot", ex) | ||
|
||
if __name__ == "__main__": # pragma: no cover | ||
async_run(main()) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# todo: we will use locale (gnu gettext) to improve the messages | ||
# ruff: noqa: E501 | ||
DEFAULT_WARNING_MESSAGE='Olá {name}, por favor não envie CPF, email, telefone (ou qualquer outro dado sensível) em canais públicos aqui pelo slack' |
This file was deleted.
Oops, something went wrong.