Example #1
0
def update_impact(incident: Incident, user_id: str, message: str):
    # Easy case. No impact currently and one has been provided
    if message and not incident.impact:
        incident.impact = message
        incident.save()
        return True, f"{IMPACT_UPDATED_TITLE}{message}"

    # Either no new impact has been provided, or one already exists
    msg = block_kit.Message()
    msg.add_block(
        block_kit.Section(
            block_id="update",
            text=block_kit.Text(
                f"{CURRENT_TITLE}{incident.impact or NO_IMPACT_TEXT}"),
            accessory=block_kit.Button(CHANGE_BUTTON_TEXT,
                                       UPDATE_CURRENT_IMPACT_ACTION,
                                       value=incident.pk),
        ))

    # if the user has supplied a message, provide the option for them to set it without
    # retyping in the dialog
    if message:
        msg.add_block(
            block_kit.Section(
                block_id=PROPOSED_MESSAGE_BLOCK_ID,
                text=block_kit.Text(f"{PROPOSED_TITLE}{message}"),
                accessory=block_kit.Button(ACCEPT_PROPOSED_TEXT,
                                           SET_NEW_IMPACT_ACTION,
                                           value=incident.pk),
            ))

    comms_channel = CommsChannel.objects.get(incident=incident)
    msg.send(comms_channel.channel_id)
    return True, None
def handle_escalation(incident: Incident, user_id: str, message: str):

    msg = block_kit.Message()
    specialists = PagerDutySpecialist.objects.all().order_by("name")

    if not specialists:
        msg.add_block(
            block_kit.Section(
                text=block_kit.Text("No teams have been configured 😢")
            )
        )
    else:
        msg.add_block(
            block_kit.Section(
                text=block_kit.Text("Let's find the right team to help out 🔍")
            )
        )
        msg.add_block(block_kit.Divider())
        msg.add_block(
            block_kit.Section(
                text=block_kit.Text(
                    "These are the teams available as escalations:"
                )
            )
        )

        for team in specialists:
            team_section = block_kit.Section(
                text=block_kit.Text(f"*{team.name}*\n{team.summary}"),
                accessory=block_kit.Button(
                    f"📟 Page {team.name}", ESCALATE_BUTTON, value=f"{team.name}"
                ),
            )
            msg.add_block(team_section)

        msg.add_block(block_kit.Divider())
        msg.add_block(
            block_kit.Section(
                text=block_kit.Text(
                    "Not sure who to pick? Ask the Incident Lead for help!"
                )
            )
        )

    comms_channel = CommsChannel.objects.get(incident=incident)
    msg.send(comms_channel.channel_id)
    return True, None
Example #3
0
def handle_statuspage(incident: Incident, user_id: str, message: str):

    logger.info("Handling statuspage command")
    comms_channel = CommsChannel.objects.get(incident=incident)

    try:
        status_page = StatusPage.objects.get(incident=incident)
        values = status_page.get_from_statuspage()

        if values.get("status") == "resolved":
            comms_channel.post_in_channel(
                "The status page can't be updated after it has been resolved.")
            return True, None
    except models.ObjectDoesNotExist:
        logger.info(
            "Existing status page not found. Posting button to create a new one"
        )

    msg = block_kit.Message()
    msg.add_block(
        block_kit.Section(
            block_id="title",
            text=block_kit.Text(f"To update the Statuspage, click below!"),
        ))
    msg.add_block(
        block_kit.Actions(
            block_id="actions",
            elements=[
                block_kit.Button("Update Statuspage",
                                 OPEN_STATUS_PAGE_DIALOG,
                                 value=incident.pk)
            ],
        ))

    msg.send(comms_channel.channel_id)
    return True, None