def create_message_body(message_template: dict, message_type: MessageType, **kwargs): """Creates the correct message body based on message type.""" template, description = get_template(message_type) rendered = render_message_template(message_template, **kwargs) kwargs.update({"items": rendered, "description": description}) return template.render(**kwargs)
def create_message_blocks(message_template: List[dict], message_type: MessageType, items: Optional[List] = None, **kwargs): """Creates all required blocks for a given message type and template.""" if not items: items = [] if kwargs: items.append(kwargs) # combine items and kwargs template_func, description = get_template(message_type) blocks = [] if description: # include optional description text (based on message type) blocks.append({ "type": "section", "text": { "type": "mrkdwn", "text": description } }) for item in items: rendered_items = render_message_template(message_template, **item) blocks += template_func(rendered_items) return blocks
def create_message_body(message_template: dict, message_type: MessageType, **kwargs): """Creates the correct message body based on message type.""" template, description = get_template(message_type) kwargs.update({ "dispatch_help_email": DISPATCH_HELP_EMAIL, "dispatch_help_slack_channel": DISPATCH_HELP_SLACK_CHANNEL, }) rendered = render_message_template(message_template, **kwargs) kwargs.update({"items": rendered, "description": description}) return template.render(**kwargs)
def create_multi_message_body(message_template: dict, message_type: MessageType, items: list, **kwargs): """Creates a multi message message body based on message type.""" template, description = get_template(message_type) master_map = [] for item in items: master_map.append(render_message_template(message_template, **item)) kwargs.update({"items": master_map, "description": description}) return template.render(**kwargs)
def create_multi_message_body(message_template: dict, message_type: MessageType, items: list, **kwargs): """Creates a multi message message body based on message type.""" template, description = get_template(message_type) master_map = [] for item in items: data = item.__dict__ data.update({"name": item.incident.name, "title": item.incident.title}) master_map.append(render_message_template(message_template, **data)) kwargs.update({"items": master_map, "description": description}) return template.render(**kwargs)
def create_multi_message_body(message_template: dict, message_type: MessageType, items: list, **kwargs): """Creates a multi message message body based on message type.""" template, description = get_template(message_type) master_map = [] for item in items: data = item.__dict__ data.update({"name": item.incident.name, "title": item.incident.title}) master_map.append(render_message_template(message_template, **data)) kwargs.update({ "items": master_map, "description": description, "dispatch_help_email": DISPATCH_HELP_EMAIL, "dispatch_help_slack_channel": DISPATCH_HELP_SLACK_CHANNEL, }) return template.render(**kwargs)
def set_description(cls, v, values): """Sets the description""" description = render_message_template( [INCIDENT_CONFERENCE], conference_challenge=values["conference_challenge"] )[0]["text"] return description