"""hello.py: the smallest Pikoman bot, in Python. It joins a chat room with its own API key and answers "!ping" with "pong". Python 3.10+. pip install -r requirements.txt, then python hello.py (reads .env). Its key (dashboard, New API key): rights subscribe and client_events, kind presence, channels: prefix presence-chat-. """ from pikoman_bot import Bot, env ROOM = env("ROOM", "presence-chat-lobby") # REPLY_ALONE=1 answers the one who asked, and nobody else; without it the bot answers in the room. REPLY_ALONE = env("REPLY_ALONE") == "1" # The bot signs its own join tokens with its API key. Access 3: it may speak in the room. bot = Bot("Hello", access=3) room = bot.join(ROOM) @room.on("message") # every chat message: room.send("message", { text }) on a member's page async def message(sender, data, info): if str((data or {}).get("text", "")).strip().lower() != "!ping": return if REPLY_ALONE: await room.send_to(sender, "message", {"text": "pong"}) else: await room.send("message", {"text": "pong"}) @bot.on_ready def ready(): print(f"Hello is joining {ROOM}") bot.start()