kopia lustrzana https://github.com/mate-dev/meshtastic-matrix-relay
Truncate message size to 320 bytes
rodzic
d21fd57063
commit
1cefe8654f
6
main.py
6
main.py
|
@ -126,6 +126,10 @@ def on_meshtastic_message(packet, loop=None):
|
|||
)
|
||||
|
||||
|
||||
def truncate_message(text, max_bytes=320): #GPT says it thinks Meshtastic's Max Payload is 340 bytes, it wanted to set it to 250. I'm trying 320.
|
||||
truncated_text = text.encode('utf-8')[:max_bytes].decode('utf-8', 'ignore')
|
||||
return truncated_text
|
||||
|
||||
|
||||
# Callback for new messages in Matrix room
|
||||
async def on_room_message(room: MatrixRoom, event: RoomMessageText) -> None:
|
||||
|
@ -150,6 +154,8 @@ async def on_room_message(room: MatrixRoom, event: RoomMessageText) -> None:
|
|||
|
||||
text = f"{short_display_name}[M]: {text}"
|
||||
|
||||
text = truncate_message(text)
|
||||
|
||||
if relay_config["meshtastic"]["broadcast_enabled"]:
|
||||
logger.info(f"Sending radio message from {full_display_name} to radio broadcast")
|
||||
meshtastic_interface.sendText(
|
||||
|
|
Ładowanie…
Reference in New Issue