Update main.py
Browse files
main.py
CHANGED
|
@@ -195,22 +195,23 @@ def handle_image_message(event):
|
|
| 195 |
|
| 196 |
client = ImgurClient(client_id, client_secret, access_token, refresh_token)
|
| 197 |
image_binary = generate_image_with_gemini(prompt)
|
|
|
|
| 198 |
|
| 199 |
if image_binary:
|
| 200 |
album = "nvsYwgq" # 你的相簿ID
|
| 201 |
image_url = upload_image_to_imgur_direct(client, image_binary, album)
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
ImageSendMessage(original_content_url=image_url,
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
|
| 215 |
if event.message.type == "image":
|
| 216 |
image_path = get_image_url(event.message.id)
|
|
|
|
| 195 |
|
| 196 |
client = ImgurClient(client_id, client_secret, access_token, refresh_token)
|
| 197 |
image_binary = generate_image_with_gemini(prompt)
|
| 198 |
+
line_bot_api.reply_message(event.reply_token, TextSendMessage(text="圖片生成中~ 請稍候約10-20秒✨"))
|
| 199 |
|
| 200 |
if image_binary:
|
| 201 |
album = "nvsYwgq" # 你的相簿ID
|
| 202 |
image_url = upload_image_to_imgur_direct(client, image_binary, album)
|
| 203 |
+
if image_url:
|
| 204 |
+
# 使用 push 訊息,避免回覆過期
|
| 205 |
+
line_bot_api.push_message(
|
| 206 |
+
event.source.user_id,
|
| 207 |
+
[TextSendMessage(text="✨ 這是我為你生成的圖片喔~"),ImageSendMessage(original_content_url=image_url,preview_image_url=image_url)]
|
| 208 |
+
)
|
| 209 |
+
else:
|
| 210 |
+
line_bot_api.push_message(
|
| 211 |
+
event.source.user_id,
|
| 212 |
+
TextSendMessage(text="⚠️ 圖片上傳失敗,請稍後再試~")
|
| 213 |
+
)
|
| 214 |
+
|
| 215 |
|
| 216 |
if event.message.type == "image":
|
| 217 |
image_path = get_image_url(event.message.id)
|