Skip to content

Commit

Permalink
feat(core): add slack integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Moreno authored and photonbit committed Oct 21, 2021
1 parent 16ca022 commit 86c4206
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 19 deletions.
6 changes: 5 additions & 1 deletion giges/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,23 @@ class BaseSettings:
SENTRY_URI = ""
ASANA_TOKEN = os.environ.get("ASANA_TOKEN", "")
ASANA_WORKSPACE = "1199978051314275"
SLACK_TOKEN = os.environ.get("SLACK_TOKEN", "")
SLACK_BLOCKS_CHANNEL = ""


class ProductionSettings(BaseSettings):
ENVIRONMENT = "production"

SERVER_BASE_URI = "https://integrations.tesselo.com"
SENTRY_URI = "https://[email protected]/5911249" # noqa: E501
SLACK_BLOCKS_CHANNEL = "C02GXT5UY22"


class StagingSettings(BaseSettings):
ENVIRONMENT = "staging"

ASANA_WORKSPACE = "1199978051314275"
SERVER_BASE_URI = "https://integrations-staging.tesselo.com"
SLACK_BLOCKS_CHANNEL = "C021VUWGA3E" # dev-null


class DevelopmentSettings(BaseSettings):
Expand All @@ -41,6 +44,7 @@ class DevelopmentSettings(BaseSettings):
SQLALCHEMY_DATABASE_URI = os.getenv("GIGES_DATABASE_URI") or (
"postgresql://postgres@localhost:5432/giges_dev"
)
SLACK_BLOCKS_CHANNEL = "C021VUWGA3E" # dev-null


class TestingSettings(BaseSettings):
Expand Down
25 changes: 25 additions & 0 deletions giges/slack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from typing import Any

import structlog
from flask import current_app
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError
from slack_sdk.web import SlackResponse

logger = structlog.get_logger(__file__)


class SlackClient(WebClient):
def __init__(self, **kwargs: Any):
super().__init__(token=current_app.config["SLACK_TOKEN"], **kwargs)

def send_message(self, channel: str, message: str) -> SlackResponse:
try:
return self.chat_postMessage(channel=channel, text=message)
except SlackApiError as e:
logger.error("Failed to send a message to slack", error=e)

def send_to_road_blocks(self, message: str) -> SlackResponse:
return self.send_message(
current_app.config["SLACK_BLOCKS_CHANNEL"], message
)
1 change: 1 addition & 0 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ flask-sqlalchemy
psycopg2-binary
zappa
sentry-sdk[flask]
slack-sdk
structlog

# All the package restrictions are due to zappa :(
Expand Down
41 changes: 23 additions & 18 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# pip-compile --output-file=./requirements.txt requirements.in
#
alembic==1.7.1
alembic==1.7.4
# via flask-migrate
argcomplete==1.12.3
# via zappa
Expand All @@ -14,21 +14,21 @@ attrs==21.2.0
# via jsonschema
blinker==1.4
# via sentry-sdk
boto3==1.18.32
boto3==1.18.59
# via
# kappa
# zappa
botocore==1.21.32
botocore==1.21.59
# via
# boto3
# s3transfer
certifi==2021.5.30
certifi==2021.10.8
# via
# requests
# sentry-sdk
cfn-flip==1.2.3
cfn-flip==1.3.0
# via troposphere
charset-normalizer==2.0.4
charset-normalizer==2.0.7
# via requests
click==7.1.2
# via
Expand Down Expand Up @@ -60,12 +60,14 @@ flask-sqlalchemy==2.5.1
# flask-migrate
future==0.18.2
# via zappa
greenlet==1.1.1
greenlet==1.1.2
# via sqlalchemy
hjson==3.0.2
# via zappa
idna==3.2
# via requests
importlib-metadata==4.8.1
# via alembic
importlib-resources==5.2.2
# via alembic
inflection==0.5.1
Expand All @@ -83,7 +85,7 @@ jmespath==0.10.0
# boto3
# botocore
# zappa
jsonschema==3.2.0
jsonschema==4.1.0
# via
# connexion
# openapi-schema-validator
Expand All @@ -104,9 +106,9 @@ openapi-spec-validator==0.3.1
# via connexion
pep517==0.11.0
# via pip-tools
pip-tools==6.2.0
pip-tools==6.3.1
# via zappa
placebo==0.9.0
placebo==0.10.0
# via kappa
psycopg2-binary==2.9.1
# via -r requirements.in
Expand Down Expand Up @@ -136,39 +138,40 @@ requests-oauthlib==1.3.0
# via asana
s3transfer==0.5.0
# via boto3
sentry-sdk[flask]==1.3.1
sentry-sdk[flask]==1.4.3
# via -r requirements.in
six==1.16.0
# via
# asana
# cfn-flip
# jsonschema
# openapi-schema-validator
# openapi-spec-validator
# python-dateutil
# zappa
sqlalchemy==1.4.23
slack-sdk==3.11.2
# via -r requirements.in
sqlalchemy==1.4.25
# via
# alembic
# dictalchemy
# flask-sqlalchemy
structlog==21.1.0
# via -r requirements.in
swagger-ui-bundle==0.0.8
swagger-ui-bundle==0.0.9
# via connexion
text-unidecode==1.3
# via python-slugify
toml==0.10.2
# via zappa
tomli==1.2.1
# via pep517
tqdm==4.62.2
tqdm==4.62.3
# via zappa
troposphere==2.7.1
# via
# -r requirements.in
# zappa
urllib3==1.26.6
urllib3==1.26.7
# via
# botocore
# requests
Expand All @@ -185,8 +188,10 @@ wsgi-request-logger==0.4.6
# via zappa
zappa==0.53.0
# via -r requirements.in
zipp==3.5.0
# via importlib-resources
zipp==3.6.0
# via
# importlib-metadata
# importlib-resources

# The following packages are considered to be unsafe in a requirements file:
# pip
Expand Down

0 comments on commit 86c4206

Please sign in to comment.