Spaces:
Running
Running
from fastapi import FastAPI, Request, BackgroundTasks, Header | |
from linebot import LineBotApi, WebhookHandler | |
from linebot.exceptions import InvalidSignatureError | |
from linebot.models import MessageEvent, TextMessage | |
from starlette.exceptions import HTTPException | |
import os | |
app = FastAPI() | |
# line_bot_api = LineBotApi(os.environ["LINE_CHANNEL_ACCESS_TOKEN"]) | |
# handler = WebhookHandler(os.environ["LINE_CHANNEL_SECRET"]) | |
line_bot_api = LineBotApi("ZwnEWwK46AUmRDOFXJOwUh1TqAELahP+kxHY0iBevF8JiEUe0CBQpkW2Gpo3C38LOaIX7hpW4IuTOSOjVof+DX9XgZg8MTeh5Iz+NDLlw6KKMtqNsyR6zt9CMnsso21ieifC/S8dcgXx3iKlhdS7UAdB04t89/1O/w1cDnyilFU=") | |
handler = WebhookHandler("7b9984bbc5c62445a79b95b15e34b727") | |
def root(): | |
return {"title": "Echo Bot"} | |
async def callback( | |
request: Request, | |
): | |
# get X-Line-Signature header value | |
signature = request.headers['X-Line-Signature'] | |
# get request body as text | |
body = request.get_data(as_text=True) | |
app.logger.info("Request body: " + body) | |
# handle webhook body | |
try: | |
line_handler.handle(body, signature) | |
except InvalidSignatureError: | |
abort(400) | |
return 'OK' | |
def handle_message(event): | |
global working_status | |
if event.message.text == "εθ¦": | |
working_status = True | |
line_bot_api.reply_message( | |
event.reply_token, | |
TextSendMessage(text="Bye!")) | |
return | |
if working_status: | |
out = event.message.text | |
if not out: | |
out = "δΈζζ¨ηζζ!" | |
line_bot_api.reply_message( | |
event.reply_token, | |
TextSendMessage(text=out)) |