def handle_message(event): #入力された内容(event.message.text)に応じて返信する line_bot_api.reply_message( event.reply_token, TextSendMessage(text = os.environ[Response.getResponse(event.message.text)]) )
from flask import Flask, request, abort from linebot import (LineBotApi, WebhookHandler) from linebot.exceptions import (InvalidSignatureError) from linebot.models import ( MessageEvent, TextMessage, TextSendMessage, ) import os import random from account_response import Response app = Flask(__name__) res = Response() YOUR_CHANNEL_ACCESS_TOKEN = os.environ["YOUR_CHANNEL_ACCESS_TOKEN"] YOUR_CHANNEL_SECRET = os.environ["YOUR_CHANNEL_SECRET"] line_bot_api = LineBotApi(YOUR_CHANNEL_ACCESS_TOKEN) handler = WebhookHandler(YOUR_CHANNEL_SECRET) @app.route("/callback", methods=['POST']) def callback(): # get X-Line-Signature header value signature = request.headers['X-Line-Signature'] #get request body as text body = request.get_data(as_text=True)