Skip to content

Commit

Permalink
update: ymlおよびpythonファイルの追加
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazyHuman00 committed Jul 30, 2024
1 parent 6a394c0 commit 31fee05
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/GourmetOjosama.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.analysis.typeCheckingMode": "off"
}
5 changes: 5 additions & 0 deletions json/config.json
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"
}
7 changes: 7 additions & 0 deletions linebot/chat.py
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)'

75 changes: 75 additions & 0 deletions linebot/main.py
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)
7 changes: 7 additions & 0 deletions linebot/search.py
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)'

0 comments on commit 31fee05

Please sign in to comment.