fix: split long text messages into multiple parts in wechatmp_service

This commit is contained in:
lanvent
2023-04-21 21:03:38 +08:00
parent 350633b69b
commit 7cefe2d825
2 changed files with 6 additions and 2 deletions

View File

@@ -130,7 +130,11 @@ class WechatMPChannel(ChatChannel):
else:
if reply.type == ReplyType.TEXT or reply.type == ReplyType.INFO or reply.type == ReplyType.ERROR:
reply_text = reply.content
self.client.message.send_text(receiver, reply_text)
texts = split_string_by_utf8_length(reply_text, MAX_UTF8_LEN)
if len(texts)>1:
logger.info("[wechatmp] text too long, split into {} parts".format(len(texts)))
for text in texts:
self.client.message.send_text(receiver, text)
logger.info("[wechatmp] Do send text to {}: {}".format(receiver, reply_text))
elif reply.type == ReplyType.VOICE:
try: