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
def test_add_action(): from enum import Enum class ActionMethod(Enum): TEST_METHOD = 'TEST_METHOD' parameters = OrderedDict() parameters['param1'] = 'value1' parameters['param2'] = 'value2' button = TextButton(text='OPEN ORDER').add_action( action_method=ActionMethod.TEST_METHOD, parameters=parameters) expected = { 'textButton': { 'text': 'OPEN ORDER', 'onClick': { 'action': { 'actionMethodName': 'TEST_METHOD', 'parameters': [{ 'key': 'param1', 'value': 'value1' }, { 'key': 'param2', 'value': 'value2' }] } } } } assert button.output() == expected
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
def test_add_link(): button = TextButton(text='OPEN ORDER').add_link(url='https://example.com/orders/...') expected = { 'textButton': { 'text': 'OPEN ORDER', 'onClick': { 'openLink': { 'url': 'https://example.com/orders/...' } } } } assert button.output() == expected
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
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
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