Example #1
0
def get_richmenu2():

    rmm = RichMenuManager(CHANNEL_ACCESS_TOKEN)

    rm_name_and_id = get_rm_name_and_id(rmm)
    menu_name_to_get = "Menu2"

    if menu_name_to_get in rm_name_and_id.keys():
        richmenu_id = rm_name_and_id[menu_name_to_get]
        print("found {}".format(menu_name_to_get))

    else:
        rm = RichMenu(name=menu_name_to_get, chat_bar_text="住所変更", size_full=False)
        rm.add_area(0, 0, 625, 421, "message", "転出")
        rm.add_area(625, 0, 625, 421, "message", "転入(国内)")
        rm.add_area(1875, 422, 625, 421, "message", "戻る")
        rm.add_area(1250, 422, 625, 421, "message", "delete richmenu")

        # Register
        res = rmm.register(rm, "./menu_images/4x2.png")
        richmenu_id = res["richMenuId"]
        print("Registered as " + richmenu_id)

    # Apply to user
    user_id = "U0a028f903127e2178bd789b4b4046ba7"
    rmm.apply(user_id, richmenu_id)
Example #2
0
def get_richmenu():

    rmm = RichMenuManager(CHANNEL_ACCESS_TOKEN)

    rm_name_and_id = get_rm_name_and_id(rmm)
    menu_name_to_get = "Menu1"

    if menu_name_to_get in rm_name_and_id.keys():
        richmenu_id = rm_name_and_id[menu_name_to_get]
        print("found {}".format(menu_name_to_get))

    else:
        rm = RichMenu(name="Menu1", chat_bar_text="問い合わせカテゴリー", selected=True)
        rm.add_area(0, 0, 1250, 843, "message", "住所変更")
        rm.add_area(1250, 0, 1250, 843, "uri", "http://www.city.tsukuba.lg.jp/index.html")
        rm.add_area(0, 843, 1250, 843, "postback", "data1=from_richmenu&data2=as_postback")
        rm.add_area(1250, 843, 1250, 843, "postback", ["data3=from_richmenu_with&data4=message_text", "ポストバックのメッセージ"])

        # Register
        res = rmm.register(rm, "./menu_images/4x2.png")
        richmenu_id = res["richMenuId"]
        print("Registered as " + richmenu_id)

    # Apply to user
    user_id = "U0a028f903127e2178bd789b4b4046ba7"
    rmm.apply(user_id, richmenu_id)

    # Check
    res = rmm.get_applied_menu(user_id)
    print(user_id  + ":" + res["richMenuId"])
Example #3
0
def handle_follow(event):
    """
    followイベントを受け取るmethod
    Args:
        event (linebot.models.events.FollowEvent): LINE Webhookイベントオブジェクト
    """
    # 送信元
    send_id = func.get_send_id(event)

    rich_menu_id = 'richmenu-0a44bd1d889f7b4fe01e8558002429a8'
    rmm = RichMenuManager(config.ACCESS_TOKEN)

    # rich_menu_object = line_bot_api.get_rich_menu(rich_menu_id)
    # print(rich_menu_obj.rich_menu_id)
    rmm.apply(send_id, rich_menu_id)

    # フォローメッセージ送信
    func.reply_message(
        event.reply_token,
        TextSendMessage(
            text=
            "フォローありがとうだぽん!(ʃƪ ˘ ³˘) (˘ε ˘ ʃƪ)♡ \n私は「リマインダヌキ」だぽん!\n必要な時はいつでも呼んでぽんね!"
        ))
Example #4
0
from richmenu import RichMenu, RichMenuManager

# Setup RichMenuManager
channel_access_token = 'MRxgDT2kynXriL1fXUHC7yY6FRx0A8sYBhTqsAl6wL0UYoMLt2d+T9QEwPq0ySiwBMnwMFb8Hkf23Z8lmsaqzEfkKH188hrlhIDCp6+hIFDQBTutt5sNhheL2+VVALeTHHHVnabxRQPdo3WPAJyZLwdB04t89/1O/w1cDnyilFU='
rmm = RichMenuManager(channel_access_token)

# Setup RichMenu to register
rm = RichMenu(name="Test menu", chat_bar_text="押してぽん!")
rm.add_area(0, 0, 1250, 843, "message", "新しいリマインダ")
rm.add_area(1250, 0, 1250, 843, "message", "一覧を見る")
rm.add_area(0, 843, 1250, 843, "message", "おはよう")
rm.add_area(1250, 843, 1250, 843, "message", "リマインダヌキ")

# Register
res = rmm.register(rm, "./image/menu2.png")
richmenu_id = res["richMenuId"]
print("Registered as " + richmenu_id)

# Apply to user
user_id = "LINE_MID_TO_APPLY"
rmm.apply(user_id, richmenu_id)

#check
res = rmm.get_applied_menu(user_id)
print(user_id + ":" + richmenu_id)
Example #5
0
def callback():
    signature = request.headers['X-Line-Signature']

    # get request body as text
    body = request.get_data(as_text=True)
    app.logger.info("Request body: " + body)

    # parse webhook body
    events = []
    try:
        events = parser.parse(body, signature)
    except InvalidSignatureError:
        abort(400)

    for event in events:

        print("showing event")
        pprint.pprint(event)
        print("")

        if isinstance(event, MessageEvent):

            if isinstance(event.message, TextMessage):

                text = event.message.text

                if text in AREA_COUNT.keys():
                    line_bot_api.reply_message(
                        event.reply_token,
                        get_area_buttons_template_message(text)
                    )

                if text == "staff":
                    get_richmenu()

                if text == "住所変更":
                    line_bot_api.reply_message(
                        event.reply_token,
                        [
                            TextSendMessage(text="住所変更のFAQを表示します。"),
                            ImageSendMessage(original_content_url="https://i.imgur.com/8uLNKdb.png", preview_image_url="https://i.imgur.com/8uLNKdbb.png")
                        ]
                    )
                    get_richmenu2()

                if text == "戻る":
                    get_richmenu()

                if text == "delete richmenu":
                    rmm = RichMenuManager(CHANNEL_ACCESS_TOKEN)
                    rmm.remove_all()


                post_text_to_db(event)

            # if isinstance(event.message, LocationMessage):

            # latitude = event.message.latitude
            # longtitude = event.message.longitude

            # line_bot_api.reply_message(
            #     event.reply_token,
            #     get_budget_buttons_template_message()
            # )

        if isinstance(event, PostbackEvent):

            data_str = event.postback.data
            data_dict = dict(urlparse.parse_qsl(data_str))
            try:
                next = data_dict['next']
            except:
                next = ''

            if next == 'budget':

                line_bot_api.reply_message(
                    event.reply_token,
                    get_budget_buttons_template_message(data_dict)
                )

            elif next == 'transportation':

                line_bot_api.reply_message(
                    event.reply_token,
                    get_transportation_buttons_template_message(data_dict)
                )

            elif next == "show-result":

                print("showing result")
                places = get_places_by_nearby_search(
                    data_dict['budget'],
                    data_dict['transportation'],
                    get_geocode(data_dict['area'])
                )["results"]

                result_count = len(places)

                nth_result = data_dict['nth-result']

                start_index = int(nth_result) * 5
                end_index = 5 + int(nth_result) * 5

                second_message = get_additional_search_confirm_template(data_dict)

                if end_index >= result_count:
                    end_index = result_count
                    second_message = TextSendMessage(
                        text='指定された条件でこれ以上の候補は見つかりませんでした。\n条件を変えて検索する場合は、下のボタンから現在地を入力してください。'
                    )
                    if end_index % 5 is not 0:
                        start_index = end_index - (end_index % 5)

                line_bot_api.reply_message(
                    event.reply_token,
                    [get_spot_carousels(places[start_index:end_index]),
                     second_message]
                )

            if "detail" in data_str:
                place_id = dict(urlparse.parse_qsl(data_str))['id']
                place_detail = get_place_detail(place_id)['result']

                messages = []
                if 'phone' in data_str:
                    messages = [TextSendMessage(text=place_detail['formatted_phone_number'])]

                line_bot_api.reply_message(
                    event.reply_token,
                    messages
                )
            post_postback_to_db(event)

    return 'OK'
Example #6
0
small_image_res = (2500, 843)
canvas = Image.new('RGB', small_image_res, (255, 255, 255))

border_image_res = (2500, 1)
border = Image.new('RGB', border_image_res, (2, 24, 255))

trigger_words = [
    'マイナンバー関連', '印鑑登録関連', '各種証明書', '4', '5', '6', '計測スタート', '計測終了'
]
column_count = 4
row_count = 2
grid_width = int(small_image_res[0] / column_count)
grid_height = math.ceil(small_image_res[1] / row_count)

# Setup RichMenuManager
rmm = RichMenuManager(CHANNEL_ACCESS_TOKEN)
print(rmm.get_list())
rmm.remove_all()

# Setup RichMenu to register
rm = RichMenu(name="menu_init", chat_bar_text="問い合わせ分類", size_full=False)

for i, word in enumerate(trigger_words):

    img = Image.new('RGB', (grid_width, grid_height), (128, 128, 128))
    text = f"{word}"
    draw_text_at_center(img, text)
    row, column = calculate_grid_position(i, column_count)
    x, y = get_position(row, column)
    canvas.paste(img, (x, y))
    rm.add_area(x, y, grid_width, grid_height, "message", word)
line_bot_api = LineBotApi(CHANNEL_ACCESS_TOKEN)
handler = WebhookHandler(CHANNEL_SECRET)

# change below if using line-simulator or it would not work
# debugging_tool = 'line-sim'
debugging_tool = 'phone'

if debugging_tool == 'phone':
    line_bot_api = LineBotApi(CHANNEL_ACCESS_TOKEN)
elif debugging_tool == 'line-sim':
    line_bot_api = LineBotApi(CHANNEL_ACCESS_TOKEN, "http://localhost:8080/bot")


static_tmp_path = os.path.join(os.path.dirname(__file__), 'static', 'tmp')

rmm = RichMenuManager(CHANNEL_ACCESS_TOKEN)

# function for create tmp dir for download content
def make_static_tmp_dir():
    try:
        os.makedirs(static_tmp_path)
    except OSError as exc:
        if exc.errno == errno.EEXIST and os.path.isdir(static_tmp_path):
            pass
        else:
            raise


def get_text_template_for_id():
    text = '''本人確認書類とは:
    
STORAGE_BUCKET = os.environ["STORAGE_BUCKET"]
LIFF_URL = os.environ["LIFF_URL"]

app = Flask(__name__)
CORS(app)
bootstrap = Bootstrap(app)
db = firestore.Client()

app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWhoge'

# LINE APIおよびWebhookの接続
line_bot_api = LineBotApi(YOUR_CHANNEL_ACCESS_TOKEN)
handler = WebhookHandler(YOUR_CHANNEL_SECRET)

# rich menu setting
rmm = RichMenuManager(YOUR_CHANNEL_ACCESS_TOKEN)

image0 = "static/images/menu0.png"
image1 = "static/images/menu1.png"
image2 = "static/images/menu2.png"
image3 = "static/images/menu3.png"

# all rich menu deleate
rmm.remove_all()

# menu0
rm = RichMenu(name="Test menu", chat_bar_text="menu 0")
rm.add_area(0, 0, 2500, 843, "message", "マグロ")
rm.add_area(0, 843, 830, 840, "message", "捕獲")
rm.add_area(833, 843, 830, 840, "uri", LIFF_URL)
rm.add_area(1666, 843, 830, 840, "message", "マグロ一丁")
Example #9
0
""" Usage of RichMenu Manager """
from richmenu import RichMenu, RichMenuManager

# Setup RichMenuManager
channel_access_token = "YOUR_CHANNEL_ACCESS_TOKEN"
rmm = RichMenuManager(CHANNEL_ACCESS_TOKEN)

# Setup RichMenu to register
rm = RichMenu(name="Test menu", chat_bar_text="Open this menu")
rm.add_area(0, 0, 1250, 843, "message", "テキストメッセージ")
rm.add_area(1250, 0, 1250, 843, "uri", "http://imoutobot.com")
rm.add_area(0, 843, 1250, 843, "postback",
            "data1=from_richmenu&data2=as_postback")
rm.add_area(1250, 843, 1250, 843, "postback",
            ["data3=from_richmenu_with&data4=message_text", "ポストバックのメッセージ"])

# Register
res = rmm.register(rm, "/path/to/menu.png")
richmenu_id = res["richMenuId"]
print("Registered as " + richmenu_id)

# Apply to user
user_id = "LINE_MID_TO_APPLY"
rmm.apply(user_id, richmenu_id)

# Check
res = rmm.get_applied_menu(user_id)
print(user_id + ":" + res["richMenuId"])

# # Others
# res = rmm.get_list()