예제 #1
0
 def action_card():
     message = Message()
     message.add_card(
         Card(
             CardHeader(
                 title="Timmy's Action Menu",
                 subtitle="Top tips for Timmy Timesheets",
                 image_url='https://timesheets.servian.fun/static/img/timmy.2fafd88.png',
                 image_style=ImageStyle.AVATAR),
             Section(
                 ButtonList(
                     TextButton(text="VIEW LAST WEEK'S TIMESHEET").add_action(
                         action_method=ActionMethod.SHOW_LAST_WEEKS_TIMESHEET)),
                 TextParagraph("Show last week's timesheet")),
             Section(
                 ButtonList(
                     TextButton(text="VIEW THIS WEEK'S TIMESHEET").add_action(
                         action_method=ActionMethod.SHOW_THIS_WEEKS_TIMESHEET)),
                 TextParagraph("Show this week's timesheet")),
             Section(
                 ButtonList(
                     TextButton(text="PROPOSE THIS WEEK'S TIMESHEET").add_action(
                         action_method=ActionMethod.PROPOSE_TIMESHEET)),
                 TextParagraph(
                     "Show Timmy's Best Guessâ„¢ at this week's timesheet. "
                     "You also have the option to make it real by updating your timesheet "
                     "right from this here chat. Rock on 🤘")),
             Section(
                 TextParagraph('Bring up this menu anytime by typing <b>help</b>')
             )
     ))
     return message
예제 #2
0
 def simple_text_card(text, show_menu_button=False, button_label="BACK"):
     message = Message()
     card = Card(Section(TextParagraph(text)))
     if show_menu_button:
         card.add_section(
             Section(ButtonList(TextButton(button_label).add_action(ActionMethod.HELP))))
     message.add_card(card)
     return message
예제 #3
0
def test_section_without_header():
    section = Section(Image('https://placeimg.com/640/480/animals'))
    expected = {
        'widgets': [{
            'image': {
                'imageUrl': 'https://placeimg.com/640/480/animals'
            }
        }]
    }
    assert section.output() == expected
예제 #4
0
 def timesheet_updated_successfully():
     message = Message(action_response=Message.ResponseType.UPDATE_MESSAGE)
     message.add_card(
         Card(
             Section(
                 TextParagraph('Timesheet updated sucessfully 🎉'),
                 ButtonList(
                     TextButton('VIEW ON TIMESHEETS.COM.AU').add_link('https://timesheets.com.au/login.asp'))),
             Section(
                 ButtonList(
                     TextButton('BACK').add_action(ActionMethod.HELP)))))
     return message
예제 #5
0
    def timesheet_card(date_entries, user, title='Timesheet Summary', show_buttons=False):
        start_date = min(date_entries.keys())
        end_date = max(date_entries.keys())
        start_date_label = start_date.strftime('%d-%b-%Y')
        end_date_label = end_date.strftime('%d-%b-%Y')

        message = Message()
        card = Card(CardHeader(
            title=title,
            subtitle=f'{start_date_label} - {end_date_label}',
            image_url=user.picture,
            image_style=ImageStyle.AVATAR))

        # Loop through timesheet and construct widget_list
        widget_list = list()
        for date, entries in date_entries.items():
            date_label = date.strftime('%A, %d %B')
            widget_list.append(TextParagraph(f'<b>{date_label}</b>'))
            if not entries:
                widget_list.append(KeyValue(top_label='Incomplete', content='0.0', icon=Icon.CLOCK))
            for entry in entries:
                widget_list.append(KeyValue(
                    top_label=entry.get('customer_description'),
                    content=str(entry.get('hours')),
                    bottom_label=entry.get('project_description'),
                    icon=Icon.CLOCK))
        timesheet_section = Section(*widget_list)
        card.add_section(timesheet_section)

        if show_buttons:
            action_parameters = {
                'start_date': str(start_date),
                'end_date': str(end_date)}
            button_section = Section(
                ButtonList(
                    TextButton('SAVE TIMESHEET').add_action(
                        action_method=ActionMethod.COPY_TIMESHEET,
                        parameters=action_parameters)))
            card.add_section(button_section)
        back_button = Section(
            ButtonList(
                TextButton('BACK').add_action(ActionMethod.HELP)))
        card.add_section(back_button)
        message.add_card(card)
        return message
예제 #6
0
def test_pizza_bot_full_example(pizza_bot_message):
    message = Message()
    message.add_card(
        Card(
            CardHeader(
                title='Pizza Bot Customer Support',
                subtitle='*****@*****.**',
                image_url='https://goo.gl/aeDtrS'),
            Section(
                KeyValue(top_label='Order No.', content='12345'),
                KeyValue(top_label='Status', content='In Delivery')),
            Section(
                'Location',
                Image(image_url='https://maps.googleapis.com/...')),
            Section(
                ButtonList(
                    TextButton(text='OPEN ORDER').add_link(url='https://example.com/orders/...')))))

    assert message.output() == pizza_bot_message
예제 #7
0
 def reminder_meme():
     random_integer = randint(0, 4) + 1
     meme_url = f'https://timesheets.servian.fun/images/{random_integer}.jpg'
     message = Message()
     message.add_card(Card(Section(Image(image_url=meme_url))))
     return message