nchat I will not rescue people on the WhatsApp side out of WhatsApp. So I needed to look further.
↩ Reply
nchat had a way to export messages ( which I could use for the bridge ), but I couldn't write messages. I mean I could have hacked into it a little bit to make it work. It is a cli app anyway, so I can STDIN into it. But come on.
↩ Reply
bash able interface for WhatsApp. Which is amazing.
↩ Reply
bash syntax to send messages, it can also output the messages in JSON. Like can it be any better?
↩ Reply
bashinteract with wacli for the WhatsApp side of things.
↩ Reply
simplematrixbotlib!
↩ Reply
asyncio!
c:2 ↩ Reply
import simplematrixbotlib as botlib creds = botlib.Creds("https://home.server", "echo_bot", "pass") bot = botlib.Bot(creds) PREFIX = '!' @bot.listener.on_message_event async def echo(room, message): match = botlib.MessageMatch(room, message, bot, PREFIX) if match.is_not_from_this_bot() and match.prefix() and match.command("echo"): await bot.api.send_text_message( room.room_id, " ".join(arg for arg in match.args()) ) bot.run()
simplematrixbotlib on their PyPi page. Notice the @bot.listener.on_message_event part followed by async def function.
↩ Reply
asyncio was kind of like a new, fancy version of threading. I thought that there is a loop somewhere started by bot.run() which executes this async function in a separate thread when a certain condition is met. I was wrong.
↩ Reply
bot.api.send_text_message() function in a separate thread or something, because it is an awaitable function. You have to run it inside of an async function. Or more like you have to await it inside of the async function. And yeah, technically I could create an async function in a separate thread and do that this way. Perhaps. But it then looses all its context and cannot send messages. Because apparently it needs to run within one of the @bot.listener event calls to make it work. To have the context necessary to send the message properly, or something.
↩ Reply
@bot.listener.on_startup call to bind some async code to the startup of the bot. Which gives me an option to start running something. And I can run a while loop that listens to WhatsApp inputs and sends messages over to Matrix. And it would work.
↩ Reply
asyncio is not threading.
↩ Reply
asyncio even is. And thankfully I did something similar for Dani's Race the other day.
↩ Reply
depsgraph problem I have some stuff that happens in the game scheduled to be executed once there is enough depsgraph to execute the function. Instead of running the function, I pass it over to the scheduler that periodically checks if the conditions are favorable, and only if they are, it executes the function.
↩ Reply
asyncio does that for each line of async function code, or something. All awaiting async functions are scheduled to be executed at once. But they are not executing until one of the functions gives away the execution privileges to the other functions. If I run a while loop, it will never return nothing. All the other scheduled functions will just wait for their turn forever.
↩ Reply
@bot.listener.on_startup async def on_startup_setuper(stuff): if not config.get("swl"): config["swl"] = True print("\n\nStarting WhatsApp to Matrix thread!!!\n\n") # THIS IS THE MAGIC SAUSE!!! asyncio.ensure_future(whatsapp_loop())
whatsapp_loop() actually contains the while loop. And periodically it runs asyncio.sleep() ( a version of time.sleep() that returns privileges for some time ), and so now it sort of works.
↩ Reply
print("\n\nStarting WhatsApp to Matrix thread!!!\n\n")
@bot.listener.on_startup thing doesn't work always.
↩ Reply
@bot.listener.on_startup will not fire. And therefor I wont see the text. So the text is needed for me to know that everything started as needed.
↩ Reply
@bot.listener.on_startup doesn't fire in say a minute after starting the bot.
↩ Reply
Troler
c:0 October 08, 2026
Troler
c:1 October 08, 2026![[thumbnail]](/pictures/user_upload/Troler/KHYF0Z71AGCAID4L.png)
Troler