Skip to content

Commit

Permalink
fix(message): telegram未填入threadid,消息失败
Browse files Browse the repository at this point in the history
  • Loading branch information
xuyanling committed Feb 6, 2024
1 parent cdf7156 commit d43cc5c
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions app/message/client/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import log
from app.helper import ThreadHelper
from app.message.client._base import _IMessageClient
from app.utils import RequestUtils, ExceptionUtils
from app.utils import RequestUtils, ExceptionUtils, StringUtils
from config import Config

lock = Lock()
Expand Down Expand Up @@ -200,7 +200,10 @@ def _res_parse(result):
if image:
# 发送图文消息
values = {"chat_id": chat_id, "photo": image, "caption": caption,
"parse_mode": "Markdown", "message_thread_id": thread_id}
"parse_mode": "Markdown"}
if StringUtils.is_string_and_not_empty(thread_id):
values.update({"message_thread_id": thread_id})

sc_url = "%s/bot%s/sendPhoto?" % (self._telegram_domain,
self._telegram_token)
res = RequestUtils(proxies=proxies).get_res(
Expand All @@ -214,8 +217,9 @@ def _res_parse(result):
sc_url = "%s/bot%s/sendPhoto" % (
self._telegram_domain, self._telegram_token)
data = {"chat_id": chat_id, "caption": caption,
"parse_mode": "Markdown",
"message_thread_id": thread_id}
"parse_mode": "Markdown"}
if StringUtils.is_string_and_not_empty(thread_id):
data.update({"message_thread_id": thread_id})
files = {"photo": photo_req.content}
res = requests.post(
sc_url, proxies=proxies, data=data, files=files)
Expand All @@ -224,7 +228,9 @@ def _res_parse(result):
return flag, msg
# 发送文本消息
values = {"chat_id": chat_id, "text": caption,
"parse_mode": "Markdown", "message_thread_id": thread_id}
"parse_mode": "Markdown"}
if StringUtils.is_string_and_not_empty(thread_id):
values.update({"message_thread_id": thread_id})
sc_url = "%s/bot%s/sendMessage?" % (
self._telegram_domain, self._telegram_token)
res = RequestUtils(proxies=proxies).get_res(
Expand Down

0 comments on commit d43cc5c

Please sign in to comment.