Skip to content

Commit d43cc5c

Browse files
author
xuyanling
committed
fix(message): telegram未填入threadid,消息失败
1 parent cdf7156 commit d43cc5c

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

app/message/client/telegram.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import log
77
from app.helper import ThreadHelper
88
from app.message.client._base import _IMessageClient
9-
from app.utils import RequestUtils, ExceptionUtils
9+
from app.utils import RequestUtils, ExceptionUtils, StringUtils
1010
from config import Config
1111

1212
lock = Lock()
@@ -200,7 +200,10 @@ def _res_parse(result):
200200
if image:
201201
# 发送图文消息
202202
values = {"chat_id": chat_id, "photo": image, "caption": caption,
203-
"parse_mode": "Markdown", "message_thread_id": thread_id}
203+
"parse_mode": "Markdown"}
204+
if StringUtils.is_string_and_not_empty(thread_id):
205+
values.update({"message_thread_id": thread_id})
206+
204207
sc_url = "%s/bot%s/sendPhoto?" % (self._telegram_domain,
205208
self._telegram_token)
206209
res = RequestUtils(proxies=proxies).get_res(
@@ -214,8 +217,9 @@ def _res_parse(result):
214217
sc_url = "%s/bot%s/sendPhoto" % (
215218
self._telegram_domain, self._telegram_token)
216219
data = {"chat_id": chat_id, "caption": caption,
217-
"parse_mode": "Markdown",
218-
"message_thread_id": thread_id}
220+
"parse_mode": "Markdown"}
221+
if StringUtils.is_string_and_not_empty(thread_id):
222+
data.update({"message_thread_id": thread_id})
219223
files = {"photo": photo_req.content}
220224
res = requests.post(
221225
sc_url, proxies=proxies, data=data, files=files)
@@ -224,7 +228,9 @@ def _res_parse(result):
224228
return flag, msg
225229
# 发送文本消息
226230
values = {"chat_id": chat_id, "text": caption,
227-
"parse_mode": "Markdown", "message_thread_id": thread_id}
231+
"parse_mode": "Markdown"}
232+
if StringUtils.is_string_and_not_empty(thread_id):
233+
values.update({"message_thread_id": thread_id})
228234
sc_url = "%s/bot%s/sendMessage?" % (
229235
self._telegram_domain, self._telegram_token)
230236
res = RequestUtils(proxies=proxies).get_res(

0 commit comments

Comments
 (0)