예제 #1
0
def handle_menu(event):
    bot_api.reply_message(event.reply_token, [
        TextSendMessage(text="""
Welcome to MarketChat!

You can choose what you want to do on the menu below.
Happy shopping! :D

If you are lost, you can type "menu" to view the menu again.
""".strip()),
        TemplateSendMessage(
            alt_text='Main menu',
            template=ButtonsTemplate(
                title='What do you want to do?',
                text='Choose action:',
                actions=[
                    PostbackTemplateAction(
                        label='Search Items',
                        data=make_beacon('view_categories')),
                    PostbackTemplateAction(label='Search Store',
                                           data=make_beacon('view_stores')),
                    PostbackTemplateAction(label='View Transactions',
                                           data=make_beacon('status')),
                    PostbackTemplateAction(label='Special Deals',
                                           data=make_beacon('special_deals'))
                ]))
    ])

    return True
예제 #2
0
def view_catalog(event, i_items, compare_id=None):
    bot_api.reply_message(
        event.reply_token,
        list(
            filter(None, [
                TextSendMessage(text="""
Select item to compare with:
""".strip()) if compare_id is not None else None,
                TemplateSendMessage(
                    alt_text='Product list',
                    template=CarouselTemplate(columns=[
                        CarouselColumn(
                            thumbnail_image_url=item.image,
                            text=f"""
Rp {'{:,}'.format(item.price)},-{f" ({round(item.promo * 100)}% off)" if item.promo is not None else ""}
""".strip(),
                            title=item.name,
                            actions=[
                                PostbackTemplateAction(
                                    label='Select',
                                    data=make_beacon('compare',
                                                     id=[compare_id, i])),
                            ] if compare_id is not None else [
                                PostbackTemplateAction(
                                    label='Buy', data=make_beacon('buy', id=i
                                                                  )),
                                PostbackTemplateAction(label='Details',
                                                       data=make_beacon(
                                                           'details', id=i)),
                                PostbackTemplateAction(label='Compare',
                                                       data=make_beacon(
                                                           'view', compare=i))
                            ]) for i, item in i_items
                    ]))
            ])))
예제 #3
0
def handle_default(event):
    if not route(event):
        bot_api.reply_message(
            event.reply_token,
            TextSendMessage(text=dedent("""
            Need help?

            You can scroll up and select an option from the menus/cards shown previously.
            You can also view the main menu by typing "menu".
        """).strip()))
예제 #4
0
def handle_video_overlay_message(event):
    bot_api.reply_message(
        event.reply_token,
        TextSendMessage(text="""
The system already validate your evidence of transfer.

Your transfer are not accepted by our system.
Please upload your evidence of transfer again.
""".strip()))

    return True
예제 #5
0
def handle_image_overlay_message(event):
    bot_api.reply_message(
        event.reply_token,
        TextSendMessage(text="""
The system already validate your evidence of transfer.

Your transfer are accepted by our system.
Our system already contacted the seller. You can check the status of your order.
""".strip()))

    return True
예제 #6
0
def handle_choose_cod(event, data):
    bot_api.reply_message(
        event.reply_token,
        TextSendMessage(text="""
Your seller has been contacted by our system.
Please meet your seller at the meeting point on time.

Seller name: Toko Yoyo.
Seller contact: +6281-222-333-444.
""".strip()))

    return True
예제 #7
0
def handle_detail(event, data):
    item = catalog.items[int(data.params['id'])]
    bot_api.reply_message(
        event.reply_token,
        TextSendMessage(text=(f"""
{item.name}

Price: Rp {'{:,}'.format(item.price)},-{f" ({round(item.promo * 100)}% off)" if item.promo is not None else ""}
Store: {item.store}
Stock: {item.stock}
Delivery Cost: {item.deliv}
""").strip()))

    return True
예제 #8
0
def handle_text_overlay_route_message(event):
    i_items = enumerate(catalog.items)

    text = event.message.text.strip().lower()
    i_items = [(i, item) for i, item in i_items if text in item.name.lower()]

    if len(i_items) > 0:
        view_catalog(event, i_items)
    else:
        bot_api.reply_message(
            event.reply_token,
            TextSendMessage(text="""
No item matches with specified keyword.
""".strip()))

    return True
예제 #9
0
def handle_status_detail(event, data):
    status_id = int(data.params['id'])
    status = catalog.statuses[status_id]

    bot_api.reply_message(
        event.reply_token,
        TextSendMessage(text=f"""
Transaction #{status_id}

Item: {status.item.name}
Price: {status.item.price}
Store: {status.item.store}

Status: {status.status}
""".strip()))

    return True
예제 #10
0
def handle_buy_product(event, data):
    bot_api.reply_message(
        event.reply_token,
        TemplateSendMessage(
            alt_text='Payment Method',
            template=ButtonsTemplate(
                title='Payment Method?',
                text='Choose method:',
                actions=[
                    PostbackTemplateAction(label='Payment by Transfer',
                                           data=make_beacon('transfer',
                                                            itemId=1)),
                    PostbackTemplateAction(label='Payment by COD',
                                           data=make_beacon('cod', itemId=1))
                ])))

    return True
예제 #11
0
def handle_special_deals(event, data):
    bot_api.reply_message(
        event.reply_token,
        TemplateSendMessage(
            alt_text='Special deals menu',
            template=ButtonsTemplate(
                title='What do you want to do?',
                text='Choose action:',
                actions=[
                    PostbackTemplateAction(label='Promo Items',
                                           data=make_beacon('view', promo=1)),
                    PostbackTemplateAction(label='Recommended Items',
                                           data=make_beacon('unimplemented')),
                    PostbackTemplateAction(label='Popular Items',
                                           data=make_beacon('view', popular=1))
                ])))

    return True
예제 #12
0
def handle_status(event, data):
    i_statuses = enumerate(catalog.statuses)

    bot_api.reply_message(
        event.reply_token,
        TemplateSendMessage(
            alt_text="Active transactions list",
            template=ButtonsTemplate(title="Active transactions",
                                     text="Choose transaction:",
                                     actions=[
                                         PostbackTemplateAction(
                                             label=f"ID#{i} Jeans AX",
                                             data=make_beacon('status_detail',
                                                              id=i))
                                         for i, status in i_statuses
                                     ])))

    return True
예제 #13
0
def handle_cod(event, data):
    bot_api.reply_message(
        event.reply_token,
        TemplateSendMessage(
            alt_text='Payment COD',
            template=ButtonsTemplate(
                title='When?',
                text='Choose schedule:',
                actions=[
                    PostbackTemplateAction(label='30 Nov 08.00-Marina',
                                           data=make_beacon('choosecod',
                                                            itemId=1)),
                    PostbackTemplateAction(label='20 Dec 19.00-Sydney',
                                           data=make_beacon('choosecod',
                                                            itemId=2))
                ])))

    return True
예제 #14
0
def handle_compare(event, data):
    a, b = [catalog.items[int(i)] for i in data.params['id']]

    bot_api.reply_message(
        event.reply_token,
        TextSendMessage(text=f"""
{a.name} (1) vs {b.name} (2)

Price:
(1) Rp {'{:,}'.format(a.price)},-{f" ({round(a.promo * 100)}% off)" if a.promo is not None else ""}
(2) Rp {'{:,}'.format(b.price)},-{f" ({round(b.promo * 100)}% off)" if b.promo is not None else ""}
Difference: Rp {'{:,}'.format(abs(a.price - b.price))},-

Store:
(1) {a.store}
(2) {b.store}
""".strip()))

    return True
예제 #15
0
def handle_transfer(event, data):
    bot_api.reply_message(
        event.reply_token,
        TextSendMessage(text="""
Seller status verdict are safe.

Seller name: Toko Yoyo
Account no.: 900-00-123-123

Bank name: Mandiri

Transfer payment is guaranteed to be safe.

If you have any dificulty in the payment,
please contact our administrator: +62818885.

Type "validate" to validate your transfer.
""".strip()))

    return True
예제 #16
0
def handle_validate_message(event):
    text = event.message.text.strip().lower()

    if text == 'validate':
        overlay_router(event, validate_overlay)
        bot_api.reply_message(
            event.reply_token,
            TextSendMessage(text="""
Please upload your evidence of transfer.
""".strip()))
    else:
        bot_api.reply_message(
            event.reply_token,
            TextSendMessage(text="""
Need help?

You can scroll up and select an option from the menus/cards shown previously.
You can also view the main menu by typing "menu".
""".strip()))

    return True
예제 #17
0
def handle_view_categories(event, data):
    i_categories = enumerate(catalog.categories)

    overlay_router(event, text_overlay_route)

    bot_api.reply_message(event.reply_token, [
        TemplateSendMessage(alt_text="Available category list",
                            template=ButtonsTemplate(
                                title="Available category",
                                text="Choose category:",
                                actions=[
                                    PostbackTemplateAction(
                                        label=category,
                                        data=make_beacon('view', category=i))
                                    for i, category in i_categories
                                ])),
        TextSendMessage(text="""
You can also type the item name.
""".strip())
    ])

    return True