def create_two_col_card(device, greetingtext, fields, time): greeting = TextBlock(greetingtext, size=FontSize.LARGE, horizontalAlignment=HorizontalAlignment.CENTER, color=Colors.ACCENT) col1 = [] col2 = [] for field in fields: name = field[0] value = field[1] col1.append(TextBlock(text=str(name), size=FontSize.SMALL)) col2.append(TextBlock(text=str(device[value]), size=FontSize.SMALL)) col1.append(TextBlock(text=str('As Of'), size=FontSize.SMALL)) col2.append(TextBlock(text=str(time), size=FontSize.SMALL)) column1 = Column(items=col1) column2 = Column(items=col2) table = ColumnSet(columns=[column1, column2]) card = AdaptiveCard(body=[greeting, table]) attachment = { "contentType": CONTENT_TYPE, "content": card.to_dict(), } print(card.to_json(pretty=True)) return attachment
def generate_model_response(switch_data, original_model=None): items = [] if original_model: items.append( TextBlock(text=f"The {original_model} is equivalent to the", size="Small", weight="Lighter")) items.append( TextBlock(text=f"{switch_data.model}", size="ExtraLarge", color="Accent", spacing=None)) title = Container(items=items) facts = [] for attr, description in models.Switch._name_mapping.items(): value = vars(switch_data).get(attr, None) if value: facts.append(Fact(description, value)) factset = FactSet(facts) card = AdaptiveCard(body=[title, factset], fallbackText=str(switch_data)) attachment = { "contentType": "application/vnd.microsoft.card.adaptive", "content": card.to_dict(), } return attachment
def static_new_instance(tags, instanceid): greeting = TextBlock( f"New EC2 Instance ID: {str(instanceid)} " f"Has Been Created Please Validate Your Tags", horizontalAlignment=HorizontalAlignment.CENTER, size=FontSize.LARGE) _data_classification = Fact(title="Data Classification", value=str(tags.dataclassification)) _environment = Fact(title='Environment', value=str(tags.environment)) _resourc_oewner = Fact(title='ResourceOwner', value=str(tags.resourceowner)) _cisco_mail_alias = Fact(title="Cisco Mail Alias", value=str(tags.ciscomailalias)) _data_taxonomy = Fact(title="Data Taxonomy", value=str(tags.datataxonomy)) _app_name = Fact(title="Application Name", value=str(tags.appname)) info = FactSet(facts=[ _data_classification, _environment, _resourc_oewner, _cisco_mail_alias, _data_taxonomy, _app_name ]) approve = Submit(title="Approve", data={"instid": instanceid}) card = AdaptiveCard(body=[greeting, info], actions=[approve]) attachment = { "contentType": CONTENT_TYPE, "content": card.to_dict(), } return attachment
def send_card(self, userObjId, issueType, dbObj, webexObj): print("-->> AdaptiveCard.send_card():") IssueActionMapping = { 'pri': '\n\n These details might help:\n 1. show isdn status \n 2. show controller', 'gateway': '\n\n These details might help: \n 1. show ccm-manager\n 2. show isdn status \n 3. Check for crash files\n 4. Check for uptime' } AlertTextMapping = { 'pri': 'PRI is Down', 'gateway': 'Gateway is unreachable' } # greeting = TextBlock("Critical Case Alert Notification",weight="bolder",horizontalAlignment="center") alertType = TextBlock(f'Alert Type:{AlertTextMapping[issueType]}', color="attention") reqAction = TextBlock(f'{IssueActionMapping[issueType]}') CCANSLogo = Image(url=self.Main_Banner_with_text) submit = Submit(title="ACK", ) card = AdaptiveCard(body=[CCANSLogo, alertType, reqAction], actions=[submit]) attachment = { "contentType": "application/vnd.microsoft.card.adaptive", "content": card.to_dict(), } # roomId = inMsg['data']['roomId'] webexObj.ccans_api.messages.create(toPersonId=userObjId, text="Card: Crtitical Case Alert", attachments=[attachment])
def generate_edit_response(switch): title = Container(items=[ TextBlock(text=f"Currently editing switch", size="Small", weight="Lighter"), TextBlock(text=f"{switch.model}", size="ExtraLarge", color="Accent", spacing=None) ]) items = [] vars(models.Switch).keys() for attr, description in models.Switch._name_mapping.items(): try: value = vars(switch).get(attr, None) # Don't append null values or internal attributes if attr[0] != '_': if type(value) == bool: items.append(Toggle(description, attr, value=value)) else: items.append(TextBlock(text=f"{description}")) items.append( Text(attr, placeholder=f"{description}", value=value)) except AttributeError: continue submit = Submit(title="Update") body = Container(items=items) card = AdaptiveCard( body=[title, body], actions=[submit], fallbackText=str( "Adaptive cards need to be enabled to use this feature.")) attachment = { "contentType": "application/vnd.microsoft.card.adaptive", "content": card.to_dict(), } return attachment
def make_card(name): card_body = [] logo = Image( "https://gist.githubusercontent.com/sQu4rks/82ce8e2f0aa9f37413b7913fc1c0487b/raw/3152f2158c8b99e114ae0803a921b1ff26c15709/welcome-banner.jpg" ) card_body.append(logo) greeting = TextBlock(MESSAGE.format(name=name)) card_body.append(greeting) card = AdaptiveCard(body=card_body) attachment = { "contentType": "application/vnd.microsoft.card.adaptive", "content": card.to_dict(), } return attachment
def get_card_from_question_set(qs): body = [] intro = TextBlock(f"## {qs.name}") body.append(intro) # Create a input for each of the questions for q in qs.questions.all(): input_id = f"{qs.id}#{q.id}" label = TextBlock(f"**{q.text}**") body.append(label) if q.question_type == Question.TYPE_TEXT: field = Text(input_id) body.append(field) elif q.question_type == Question.TYPE_MC: string_choices = re.search(r'\((.*?)\)', q.text).group(1).split(",") choices = [] for str_choice in string_choices: c = Choice(str_choice, str_choice) choices.append(c) field = Choices(choices, input_id) body.append(field) submit_action = { 'type': "Action.Submit", 'title': "Send Survey", 'data': { 'question_set': str(qs.id) } } card = AdaptiveCard(body=body, actions=[]) ret = card.to_dict() ret['actions'].append(submit_action) return ret
def generate_teams_payload(adaptive_card: AdaptiveCard) -> dict: """Generate payload for MS Teams. Args: adaptive_card (AdaptiveCard): AdaptiveCard to generate payload with. Returns: dict: Payload dict for MS Teams. """ # Add adaptive card to payload payload = { "type": "message", "attachments": [{ "contentType": "application/vnd.microsoft.card.adaptive", "contentUrl": "null", "content": adaptive_card.to_dict(), }], } return payload
def generate_list_items_card(self) -> Attachment: from pyadaptivecards.card import AdaptiveCard from pyadaptivecards.components import TextBlock from pyadaptivecards.actions import Submit, OpenUrl, ShowCard order_number = '001' body = [] greeting = TextBlock(f'Order #{order_number}', weight='bolder', size='medium') submit = Submit(title='Confirm Order') date = TextBlock(str(datetime.now().strftime('%a. %d of %b, %Y at %H:%M')), size='small') body.append(greeting) body.append(date) quantity_column_items = [TextBlock('Quantity', weight='bolder')] item_column_items = [TextBlock('Item', weight='bolder')] for item in self.item_list: if item.unit == '' or item.quantity != 0: item_column_items.append(TextBlock(f'{item.description.capitalize()}')) quantity_column_items.append(TextBlock(f'{item.quantity}')) else: item_column_items.append(TextBlock(f'{item.description.capitalize()}')) quantity_column_items.append(TextBlock(f'{item.weight} {item.unit.capitalize()}')) card = AdaptiveCard(body=body, actions=[submit]) quantity_column = Column(items=quantity_column_items) item_column = Column(items=item_column_items) table = ColumnSet(columns=[quantity_column, item_column]) body.append(table) # Create attachment attachment = { 'contentType': 'application/vnd.microsoft.card.adaptive', 'content': card.to_dict() } data_value = attachment['content']['actions'][0]['data'] = 'Confirm' return attachment
def generate_add_response(): title = Container(items=[ TextBlock(text=f"Currently adding a new switch", size="Small", weight="Lighter"), ]) items = [] for attr in vars(models.Switch).keys(): # Don't append null values or internal attributes if attr[0] != '_': # This is so stupid, probably not the best way to do it target_type = str( getattr(models.Switch, attr).property.columns[0].type) if target_type == "BOOLEAN": items.append(Toggle(attr, attr)) else: items.append(TextBlock(text=f"{attr}")) items.append(Text(attr, placeholder=f"{attr}")) submit = Submit(title="Add") body = Container(items=items) card = AdaptiveCard( body=[title, body], actions=[submit], fallbackText=str( "Adaptive cards need to be enabled to use this feature.")) attachment = { "contentType": "application/vnd.microsoft.card.adaptive", "content": card.to_dict(), } return attachment
def create_update_instance_tag_card(tags, instanceid): _greeting = TextBlock( f"New EC2 Instance ID: {str(instanceid)} " f"Has Been Created Please Validate Your Tags", horizontalAlignment=HorizontalAlignment.CENTER, size=FontSize.SMALL) _choices = [ Choice("Cisco Restricted", "Cisco Restricted"), Choice("Cisco Highly Confidentia", "Cisco Highly Confidentia") ] _data_classification = Choices(id="Data Classification", choices=_choices, value=str(tags.dataclassification), style=2) _choices = [ Choice("dev", "dev"), Choice("test", "test"), Choice("stage", "stage"), Choice("prod", "prod") ] _environment = Choices(id="Environment", choices=_choices, value=str(tags.environment), style=2) _resourc_oewner = Text('Resource Owner', value=str(tags.resourceowner)) _cisco_mail_alias = Text("Cisco Mail Alias", value=str(tags.ciscomailalias)) _choices = [Choice("Cisco Operations Data", "Cisco Operations Data")] _data_taxonomy = Choices(id="Data Taxonomy", choices=_choices, value=str(tags.datataxonomy), style=2) _app_name = Text("Application Name", value=str(tags.appname)) _footer = TextBlock( "Security Tags must be validated with in 24 hours " "or your EC2 instace will be terminated", horizontalAlignment=HorizontalAlignment.CENTER, size=FontSize.SMALL, color=Colors.ATTENTION) submit = Submit(title="Update", data={"instid": instanceid}) card = AdaptiveCard(body=[ _greeting, _app_name, _resourc_oewner, _cisco_mail_alias, _environment, _data_classification, _data_taxonomy, _footer ], actions=[submit]) attachment = { "contentType": CONTENT_TYPE, "content": card.to_dict(), } print(card.to_json(pretty=True)) return attachment