import re
from datetime import datetime


def slack_webhook_message(serial_number, webhook_event, event_time):
    """Create a formatted Slack message."""
    event_time = re.sub(r'([\+|\-]{1}[0-9]{2})\:([0-9]{2})', r'\g<1>\g<2>', event_time)
    event_time = datetime.strptime(event_time, '%Y-%m-%dT%H:%M:%S.%f%z')
    event_time = event_time.strftime('%A, %B %d, %Y at %H:%M %Z')
    slack_message = {
        'text': (
            "SimpleMDM: Device `" +
            serial_number +
            "` " +
            webhook_event +
            " on " +
            event_time +
            "."
        )
    }
    return slack_message