Exemplo n.º 1
0
import datetime
import json
import logging

from slackeventsapi import SlackEventAdapter

from app import app
from app.helpers.slack import get_slack_client
from app.helpers.redis import request_previously_responded, request_processed

slack_events_adapter = SlackEventAdapter(app.config["SLACK_SIGNING_SECRET"],
                                         "/events", app)

client = get_slack_client()


@slack_events_adapter.on("channel_created")
def event_channel_created(event_data):
    log_entry = {}

    event_id = event_data["event_id"]

    # Get the name of the new channel, and the ID of the creator
    channel_id = event_data["event"]["channel"]["id"]
    channel_name = event_data["event"]["channel"]["name"]

    log_entry["timestamp"] = (datetime.datetime.utcnow().replace(
        tzinfo=datetime.timezone.utc).isoformat())
    log_entry["event"] = "channel_created"
    log_entry["eventId"] = event_id
    log_entry["channelId"] = channel_id
Exemplo n.º 2
0
import logging

from app import app
from app.helpers import slack as sl
from app.features import trello, jira, release_notes as rn

client = sl.get_slack_client()


def create_change(message_payload):

    user_id = message_payload["user"]["id"]
    user_name = message_payload["user"]["name"]

    state_values = message_payload["view"]["state"]["values"]
    change_number = state_values["change_no"]["txt_change_no"]["value"]

    new_channel_name = f"{app.config['SLACK_CHANGE_CHANNEL_PREFIX']}{change_number}"
    change_summary = state_values["change_summary"]["txt_change_summary"][
        "value"]

    try:
        release_notes = state_values["release_notes"]["txt_release_notes"][
            "value"]

    except KeyError:
        logging.debug("No release notes found in modal payload")
        release_notes = None

    # Create the new channel and set purpose / topic
    new_channel = client.conversations_create(name=new_channel_name)