Esempio n. 1
0
def get_support_input_card():
    greeting1 = TextBlock("PR number (optional)")
    number = Number('support.pr_number', placeholder='12345')
    greeting2 = TextBlock("Issue details")
    query = Text('support.details', placeholder="...")
    submit = Submit(title="Submit")

    return AdaptiveCard(body=[greeting1, number, greeting2, query],
                        actions=[submit])
Esempio n. 2
0
    def __init__(self, q_id, query, answer_provided, answer_options):
        self.q_id = q_id

        body = []
        actions = []

        intro = TextBlock(
            "We received the following question that the requester deemed to be wrongly answered. If we have misclassified this please use the drop-down to choose the matching question. If the answer is not yet in our database use the response field to type the correct answer."
        )
        body.append(intro)

        question_label = TextBlock("**Query**")
        body.append(question_label)

        question = TextBlock(query)
        body.append(question)

        answer_label = TextBlock("**Our Answer**")
        body.append(answer_label)

        answer = TextBlock(answer_provided)
        body.append(answer)

        answer_options_label = TextBlock(
            "If this was misclassified provide the matching question here and click 'Wrongly classified'"
        )
        body.append(answer_options_label)

        answer_choices = []
        for q_id, text in answer_options.items():
            c = Choice(f"{q_id}:{text}", q_id)
            answer_choices.append(c)

        answer_option_choices = Choices(answer_choices, 'correct_question')
        body.append(answer_option_choices)

        answer_new_response_label = TextBlock(
            "If this is a new question please provide a answer in the text field below and click 'New answer'"
        )
        body.append(answer_new_response_label)

        new_answer = Text('new_answer')
        body.append(new_answer)

        super().__init__(body=body, actions=actions)
Esempio n. 3
0
    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
Esempio n. 4
0
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
Esempio n. 5
0
    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
Esempio n. 6
0
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
Esempio n. 7
0
from pyadaptivecards.actions import Submit
from pyadaptivecards.card import AdaptiveCard
from pyadaptivecards.components import TextBlock
from pyadaptivecards.inputs import Number, Text
from webexteamssdk import WebexTeamsAPI
import json

greeting = TextBlock("Hey hello there! I am a adaptive card")
first_name = Text('first_name', placeholder="First Name")
age = Number('age', placeholder="Age")

submit = Submit(title="Send me!")

card = AdaptiveCard(body=[greeting, first_name, age], actions=[submit])

with open("subscription.json") as file:
    active = json.load(file)
    
# Create a webex teams api connection
api = WebexTeamsAPI(access_token='MmM1ZTZlYmItZWI4Zi00NzgyLTgxYzctN2E5MDYyMTNhNzJmYTNkMjQ3OGYtM2Ex_PF84_1eb65fdf-9643-417f-9974-ad72cae0e10f')
room_id = "Y2lzY29zcGFyazovL3VzL1JPT00vMWNiYWMyN2ItNjEwYi0zNjBkLThhMTMtNjYzYTIxYjFlOTA2"
# Create a dict that will contain the card as well as some meta information
attachment = {
    "contentType": "application/vnd.microsoft.card.adaptive",
    "content": active,
}
api.messages.create(roomId=room_id, text="Fallback", attachments=[attachment])
Esempio n. 8
0
def get_search_input_card():
    greeting = TextBlock("Enter you search string w.r.to git/github")
    query = Text('query_string', placeholder="...")
    submit = Submit(title="Search")

    return AdaptiveCard(body=[greeting, query], actions=[submit])
Esempio n. 9
0
def get_cr_list_input_card():
    greeting = TextBlock("Enter <user-id> for PR reviewer lookup")
    user_id = Text('cr_list.user_id', placeholder="...")
    submit = Submit(title="Search")

    return AdaptiveCard(body=[greeting, user_id], actions=[submit])