Bot callback: please add argument indicating number of path bytes #26

Closed
opened 2026-10-05 01:53:46 +02:00 by adam · 6 comments
Owner

Hi! I have a simple little ping bot and which tries to pretty-print the path by seperating its components with commas:

if path is None or len(path)==0:
  path = "direct"
elif len(path)%2 == 0:
  path = ",".join([path[2*i:2*i+2] for i in range(len(path)//2)])
return f"Pong @[{sender_name}] path {path}"

But of course, this only works for 1-byte-paths.

But I'm already receiving messages with multi-byte-paths - at least according to the frontend.

Image

=> need a way to detect this within the bot callback.

A simple int argument indicating the number of bytes (1, 2, or 4) would suffice...

Hi! I have a simple little ping bot and which tries to pretty-print the path by seperating its components with commas: ```{python} if path is None or len(path)==0: path = "direct" elif len(path)%2 == 0: path = ",".join([path[2*i:2*i+2] for i in range(len(path)//2)]) return f"Pong @[{sender_name}] path {path}" ``` But of course, this only works for 1-byte-paths. But I'm already receiving messages with multi-byte-paths - at least according to the frontend. <img width="439" height="189" alt="Image" src="https://github.com/user-attachments/assets/f1bc7491-d77c-48f8-8701-970f248bf523" /> => need a way to detect this within the bot callback. A simple int argument indicating the number of bytes (1, 2, or 4) would suffice... <!-- github-sync-id:4065070040 -->
adam closed this issue 2026-10-05 01:53:46 +02:00
Author
Owner

Okay I've added that in 30f6f95, which adds path_bytes_per_hop and also nudges people towards using kwargs for less thrashing in the future on new fields (which will hopefully be minimal).

Let me know if that works for your purposes.

Okay I've added that in 30f6f95, which adds `path_bytes_per_hop` and also nudges people towards using kwargs for less thrashing in the future on new fields (which will hopefully be minimal). Let me know if that works for your purposes. <!-- github-comment-id:4048654098 -->
Author
Owner

just a minor but breaking issue so far: I cannot save with function header from example:

def bot(**kwargs) -> str | list[str] | None:

frontend will complain about missing positional arguments.

just a minor but breaking issue so far: I cannot save with function header from example: ``` def bot(**kwargs) -> str | list[str] | None: ``` frontend will complain about missing positional arguments. <!-- github-comment-id:4048760580 -->
Author
Owner

Dangit, yes, I have a stash sitting right here I failed to readd 🙃 Sorry about that!!

Dangit, yes, I have a stash sitting right here I failed to readd 🙃 Sorry about that!! <!-- github-comment-id:4048819108 -->
Author
Owner

got it partially fixed with this header:

def bot(
    sender_name: str | None,
    sender_key: str | None,
    message_text: str,
    is_dm: bool,
    channel_key: str | None,
    channel_name: str | None,
    sender_timestamp: int | None,
    path: str | None,
    is_outgoing: bool = False,
    **kwargs) -> str | list[str] | None:

...and it kinda works (ping reply being performed properly), but raises runtime errors:

2026-03-12 18:00:59 - app.fanout.bot_exec - ERROR - Bot function execution failed
Traceback (most recent call last):
  File "/home/ak/Remote-Terminal-for-MeshCore/app/fanout/bot_exec.py", line 228, in execute_bot_code
    result = bot_func(
        sender_name,
    ...<7 lines>...
        **keyword_args,
    )
  File "<string>", line 33, in bot
TypeError: unsupported operand type(s) for *: 'int' and 'NoneType'
got it partially fixed with this header: ``` def bot( sender_name: str | None, sender_key: str | None, message_text: str, is_dm: bool, channel_key: str | None, channel_name: str | None, sender_timestamp: int | None, path: str | None, is_outgoing: bool = False, **kwargs) -> str | list[str] | None: ``` ...and it kinda works (ping reply being performed properly), but raises runtime errors: ``` 2026-03-12 18:00:59 - app.fanout.bot_exec - ERROR - Bot function execution failed Traceback (most recent call last): File "/home/ak/Remote-Terminal-for-MeshCore/app/fanout/bot_exec.py", line 228, in execute_bot_code result = bot_func( sender_name, ...<7 lines>... **keyword_args, ) File "<string>", line 33, in bot TypeError: unsupported operand type(s) for *: 'int' and 'NoneType' ``` <!-- github-comment-id:4048846025 -->
Author
Owner

Hm, guessing there is some multiplication happening on a None-able value in your bot function. If you paste the full function here I can probably help you spot the bug.

Hm, guessing there is some multiplication happening on a None-able value in your bot function. If you paste the full function here I can probably help you spot the bug. <!-- github-comment-id:4049105849 -->
Author
Owner

yeah, that was 100% correct and also explains why the ping works. it only raises the error on outgoing messages 🙈

thanks for remote-guess-debugging, I got it fixed 👍

yeah, that was 100% correct and also explains why the ping works. it only raises the error on outgoing messages 🙈 thanks for remote-guess-debugging, I got it fixed 👍 <!-- github-comment-id:4049469747 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/Remote-Terminal-for-MeshCore#26