-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"python.analysis.typeCheckingMode": "off" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"LINE_CHANNEL_SECRET": "74e05a3f47a12c8a1a201531d11009be", | ||
"LINE_CHANNEL_ACCESS_TOKEN": "h/yvbGvBJVEJLJWOccCJ1G9FdP12wEWlRYGflE+Un7lW5tInt8I+9ccE6EB2NdulqxGAAWkPwo97GMsZWugTbgKRDe47doriFyOp+bYQehFeh9nJaMqIHlcBWk1Z2kI7t293sdMgSmLGZ6hIPQtdvQdB04t89/1O/w1cDnyilFU=", | ||
"API_KEY": "a902d5426ee72db7" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# !/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
__author__ = 'Asakura Hiroto' | ||
__version__ = '2.0.0' | ||
__date__ = '2024/07/16 (Created: 2024/07/21)' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# !/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
__author__ = 'Asakura Hiroto' | ||
__version__ = '2.0.0' | ||
__date__ = '2024/07/16 (Created: 2024/02/02)' | ||
|
||
# ライブラリのインポート | ||
import os | ||
from flask import Flask, request, abort | ||
|
||
from linebot.v3 import ( | ||
WebhookHandler | ||
) | ||
from linebot.v3.exceptions import ( | ||
InvalidSignatureError | ||
) | ||
from linebot.v3.messaging import ( | ||
Configuration, | ||
ApiClient, | ||
MessagingApi, | ||
ReplyMessageRequest, | ||
TextMessage | ||
) | ||
from linebot.v3.webhooks import ( | ||
MessageEvent, | ||
TextMessageContent | ||
) | ||
|
||
import json | ||
|
||
app = Flask(__name__) | ||
|
||
# config.jsonから情報を取得 | ||
with open("config.json", "r", encoding="utf8") as file: | ||
info_config = json.load(file) | ||
|
||
configuration = Configuration(access_token=info_config["LINE_CHANNEL_ACCESS_TOKEN"]) | ||
handler = WebhookHandler(info_config["LINE_CHANNEL_SECRET"]) | ||
|
||
SEARCH_WORD = ["お腹すいた"] | ||
|
||
@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) | ||
app.logger.info("Request body: " + body) | ||
|
||
# handle webhook body | ||
try: | ||
handler.handle(body, signature) | ||
except InvalidSignatureError: | ||
app.logger.info("Invalid signature. Please check your channel access token/channel secret.") | ||
abort(400) | ||
|
||
return 'OK' | ||
|
||
|
||
@handler.add(MessageEvent, message=TextMessageContent) | ||
def handle_message(event): | ||
with ApiClient(configuration) as api_client: | ||
line_bot_api = MessagingApi(api_client) | ||
line_bot_api.reply_message_with_http_info( | ||
ReplyMessageRequest( | ||
reply_token=event.reply_token, | ||
messages=[TextMessage(text=event.message.text)] | ||
) | ||
) | ||
|
||
if __name__ == "__main__": | ||
port = int(os.getenv("PORT", 80)) | ||
app.run(host="0.0.0.0", port=port, debug=False) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# !/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
__author__ = 'Asakura Hiroto' | ||
__version__ = '2.0.0' | ||
__date__ = '2024/07/16 (Created: 2024/07/21)' | ||
|