Beispiel #1
0
def create_quick_replay():
    """
    Building a quick reply floating window for messages.

        reference
        - `Common Message Property <https://developers.worksmobile.com/jp/document/100500807?lang=en>`_

    Check also: faq_bot/model/data.py
    :return: quick replay item
    """
    fmt0 = _("HR/Leave")
    action0 = make_i18n_postback_action("enquire_leave", "message", "HR/Leave",
                                        fmt0, "HR/Leave", fmt0)
    item0 = make_quick_reply_item(action0)

    fmt1 = _("Welfare/Work support")
    action1 = make_i18n_postback_action("enquire_welfare", "message",
                                        "Welfare/Work support", fmt1,
                                        "Welfare/Work support", fmt1)
    item1 = make_quick_reply_item(action1)

    fmt2 = _("Security")
    action2 = make_i18n_postback_action("enquire_security", "message",
                                        "Security", fmt2, "Security", fmt2)
    item2 = make_quick_reply_item(action2)

    return make_quick_reply([item0, item1, item2])
Beispiel #2
0
def create_quick_replay_item(callback,
                             locale,
                             label,
                             fmt_label=None,
                             text=None,
                             fmt_text=None):
    """
    Building a quick reply floating window for messages.
    Check also: faq_bot/model/data.py

        reference
        - `Common Message Property <https://developers.worksmobile.com/jp/document/100500807?lang=en>`_

    :param callback: callback string for the button.
    :return: quick replay item
    """

    if text is None:
        text = label
        if fmt_text is None and fmt_label is not None:
            fmt_text = fmt_label

    action = make_i18n_postback_action(callback, locale, label, fmt_label,
                                       text, fmt_text)

    item = make_quick_reply_item(action)
    return make_quick_reply([item])
Beispiel #3
0
def echo_display(message):
    """
    Generate messages that require user confirmation.

        reference
        - `Common Message Property <https://developers.worksmobile.com/jp/document/100500807?lang=en>`_

    Check also: faq_bot/model/data.py
    :param message: User input message.
    :return: Message to prompt users.
    """
    text = "Do you want to send the following as your question? \n\n" \
           "===\n{message}\n===".format(message=message)
    fmt = _(
        "Do you want to send the following as your question? \n\n===\n{message}\n==="
    )
    content = make_i18n_text(text, "message", fmt, message=message)

    fmt0 = _("Send")
    action0 = make_i18n_postback_action("send", "message", "Send", fmt0,
                                        "Send", fmt0)
    item0 = make_quick_reply_item(action0)

    fmt1 = _("Modify")
    action1 = make_i18n_postback_action("modify", "message", "Modify", fmt1,
                                        "Modify", fmt1)
    item1 = make_quick_reply_item(action1)

    fmt2 = _("Cancel")
    action2 = make_i18n_postback_action("cancel", "message", "Cancel", fmt2,
                                        "Cancel", fmt2)
    item2 = make_quick_reply_item(action2)

    quick_reply = make_quick_reply([item0, item1, item2])

    content["quickReply"] = quick_reply

    return content
Beispiel #4
0
def make_add_rich_menu_body(rich_menu_name):
    """
    add rich menu body

        reference
        - `Common Message Property <https://developers.worksmobile.com/jp/document/100504001?lang=en>`_

    :param rich_menu_name: rich menu name
    :return: rich menu id
    """
    size = make_size(2500, 1686)

    fmt_label1 = _("\"Find FAQ\" by task")
    fmt_text1 = _("Do you have any work-related questions? "
                  "\n\"Find FAQ\" by task")

    bound1 = make_bound(0, 0, 2500, 1160)
    action1 = make_i18n_postback_action(
        "query", "richmenu", "\"Find FAQ\" by task", fmt_label1,
        "Do you have any work-related "
        "questions? \n\"Find FAQ\" by task", fmt_text1)

    fmt2 = _("Send a question")
    bound2 = make_bound(0, 1160, 1250, 526)
    action2 = make_i18n_postback_action("enquire", "richmenu",
                                        "Send a question", fmt2,
                                        "Send a question", fmt2)

    fmt3 = _("Go to Initial Menu")
    bound3 = make_bound(1250, 1160, 1250, 526)
    action3 = make_i18n_postback_action("to_first", "richmenu",
                                        "Go to Initial Menu", fmt3,
                                        "Go to Initial Menu", fmt3)

    rich_menu = make_add_rich_menu(rich_menu_name, size, [
        make_area(bound1, action1),
        make_area(bound2, action2),
        make_area(bound3, action3)
    ])

    headers = API_BO["headers"]
    headers["consumerKey"] = OPEN_API["consumerKey"]

    url = API_BO["rich_menu_url"]
    url = utils.replace_url_bot_no(url)

    logging.info("register richmenu. url:%s", url)

    response = auth_post(url, data=json.dumps(rich_menu), headers=headers)
    if response.status_code != 200:
        logging.info("register richmenu failed. url:%s text:%s body:%s", url,
                     response.text, response.content)
        raise Exception("register richmenu. http return error.")

    tmp = json.loads(response.content)
    rich_menu_id = tmp.get("richMenuId", None)
    if rich_menu_id is None:
        logging.error("register richmenu failed. url:%s txt:%s body:%s", url,
                      response.text, response.content)
        raise Exception("register richmenu failed. rich menu id is None.")

    logging.info("register richmenu success. url:%s txt:%s body:%s", url,
                 response.text, response.content)

    return rich_menu_id