Skip to content

Commit

Permalink
Handle errors in message sending and filename decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuiman committed Mar 2, 2024
1 parent bcb83b2 commit c95c1dd
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/scripts/handle_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def handle_assistant(event, process_ts, files, assistant, model):
except Exception as e:
logging.exception(e)
# 連続で質問されている場合は失敗するので処理を終了させる
message = "現在回答を生成中です。しばらく待ってからメッセージを送信してください。"
message = f"回答の生成でエラーが発生しました。{e}"
update_message(channel_id, process_ts, text=message)
return
else:
Expand Down
3 changes: 2 additions & 1 deletion src/scripts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from datetime import datetime
from tempfile import mkdtemp
from sentry_sdk import set_user, set_tag
from urllib.parse import unquote
from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration

logging.basicConfig(format="[%(levelname)s] %(message)s", level=logging.INFO)
Expand Down Expand Up @@ -80,7 +81,7 @@ def handle_file_share(event):
# アップロードされたファイルを取得
for file in event.get("files", []):
url_private = file["url_private_download"]
filename = datetime.now().strftime("%Y%m%d_") + file["name"]
filename = datetime.now().strftime("%Y%m%d_") + unquote(file["name"])
file_path = os.path.join(mkdtemp(), filename)
file_data = get_slack_file_bytes(url_private)
with open(file_path, "wb") as f:
Expand Down
18 changes: 0 additions & 18 deletions src/scripts/slacklib.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,6 @@ def add_reaction(name, channel_id, message_ts):
logging.info(f"Failed to add {name} reaction: {str(e)}")


def extract_msg_file(msg):
messages = ""
files = []
# ファイルタイプがテキストならダウンロードする
for file in msg.get("files", []):
url_private = file["url_private_download"]
filetype = file["filetype"]
filename = file["name"]
file_data = get_slack_file_bytes(url_private)
if file["mimetype"] == "text/plain":
messages += f"{file_data.decode()}\n"
download_file = os.path.join(mkdtemp(), filename)
files.append(download_file)
with open(download_file, "wb") as f:
f.write(file_data)
return messages, files


def get_thread_messages(channel_id, thread_ts):
# すべてのメッセージを保持するリスト
all_messages = []
Expand Down

0 comments on commit c95c1dd

Please sign in to comment.