Skip to main content

Yap bots (Python)

A Yap bot is a real account: it has its own username, its own id, its own place in member lists, and it authenticates with its own token. It is not a person's session wearing a hat, and it has no password at all — the token is the whole credential.

Bots are created in the developer portal (yap.foreskin.dev/developer → New Application), which shows the token once. Only its SHA-256 is stored on the server, so a lost token is rotated there, not recovered.

What a bot can do

Inside a space it was invited to, a bot is an ordinary member: the same permission bits decide what it can read, send, rename or manage. It cannot do account-level things — create spaces, open DMs, manage friends, publish E2EE keys, or manage API keys and bots — because those belong to people (403 forbidden). The full contract is in docs/protocol.md.

Two consequences worth knowing before you build:

  • Encrypted spaces stay sealed. A bot has no key, so it receives yap1: envelopes and this library skips them.
  • Joins are events. MemberJoin{space_id, member} arrives when somebody accepts an invite or a bot is installed, so a welcome message is a handler on that event. DMs have no join step, and a re-join that changes nothing sends nothing.

Run the example bot

cd client/bots/python
python -m venv .venv && . .venv/bin/activate    # Windows: .venv\Scripts\activate
pip install -r requirements.txt

export YAP_SERVER=https://api.foreskin.dev
export YAP_BOT_TOKEN=yapbot_...                  # from the panel, shown once
python -m bots.polly

Then invite the bot into a space like a person and type !help. Commands: !ping, !roll 2d6, !8ball <question>, !help. Type / in the composer and its slash commands (/ping, /roll) are listed there.

bots/yapper.py is the bot for the account whose token sits in .env (gitignored). It loads that file itself, so python -m bots.yapper needs no exported variables: !ping, !id, !say <text>, !faq [topic], !help. Its welcome text and FAQ answers live in bots/yapper.json, so they can change without touching code.

The welcome fires on MemberJoin, in the first text channel of that space the bot can see. Installing the bot sends the event for the bot itself, which it ignores; so do joins in spaces it cannot see and spaces with no text channel.

The AIO bot

aio/ is the all-in-one bot: one account for moderation (bans, kicks, warnings, mutes), automod (filtered words, invite links, mention floods, spam), audit logging, tickets with a reaction panel, reaction roles, welcome and auto-role, tags and autoresponders, reaction polls, and the usual info commands.

python -m aio

It reads the same .env, so YAP_BOT_TOKEN is all it needs. Its own state (settings, warnings, tags, tickets, mute expiries) is aio/aio.db, gitignored; message content is never written there. See aio/README.md for the permissions it needs, every command and what it deliberately does not do.

Write your own

import asyncio
from yapbot import Bot, Context

bot = Bot("https://api.foreskin.dev", "yapbot_...", prefix="!")

@bot.command("hi", help="say hello")
async def hi(ctx: Context):
    await ctx.reply(f"hello {ctx.author}")

@bot.event("message")
async def every_message(message):
    ...  # plain text only; sealed bodies are filtered out before commands run

asyncio.run(bot.run())

pip install client/bots/python from this checkout installs it as yapbot (the gateway stubs ship inside the package); once a release is on PyPI, pip install yapbot is all a bot needs. Only yapbot is imported — no top-level yap package, so nothing collides with the unrelated yap project on PyPI.

Context carries channel_id, space_id, message_id, author, content, args, plus reply() and history(). Handlers may be sync or async, run concurrently, and a failing handler is logged and answered once with an apology rather than killing the connection.

The library reconnects with backoff on network errors. A rejected or revoked token raises BotStopped: rotating the token in the panel is the only fix, so it does not spin.

Slash commands

@bot.slash publishes a command for the client's / menu — name and description on the left, the bot's name on the right, the way Discord shows an app's commands. Picking one only fills the input with /name and invoking it is an ordinary message, so the same command works in the desktop app, the panel and the Roblox overlay, and any member can still type it by hand.

@bot.slash("kiss", description="kiss someone")
async def kiss(ctx: Context, who: str = ""):
    await ctx.reply(f"*kisses {who or ctx.author}*")

The bot publishes its list when it connects (PUT /bots/{id}/commands), replacing whatever it had before. Names are 1-32 of a-z, 0-9, - or _ (lower-cased for you), descriptions up to 100 characters, at most 25 commands. Decorators stack, so one function can answer both forms:

@bot.command("roll", help="roll dice")
@bot.slash("roll", description="roll dice")
async def roll(ctx: Context, spec: str = "1d6"):
    ...

Protocol stubs

yapbot/_proto/gateway_pb2.py is generated from server/proto/proto/yap/v1/gateway.proto and committed so the bot runs from a fresh clone. Regenerate it after a schema change:

pip install grpcio-tools
sh gen-proto.sh

gen-proto.sh writes the generated module into yapbot/_proto/, where the wheel ships it. There is no top-level yap/ directory anymore: the protobuf package name stays yap.v1, but the file lives under yapbot, so yapbot is the only import.

The wire format is what the desktop client speaks: one WebSocket binary message per protobuf Frame, Hello with the token inside the frame (never in the URL), Ping at least every heartbeat_ms, then MessageCreate / SendMessage with a nonce.

License

The wrapper is AGPL-3.0-only, like the server — see LICENSE. Building and publishing it under another license means changing pyproject.toml and this file together.

Releasing

Push a tag whose version matches both pyproject.toml and yapbot.__version__:

git tag python-v0.1.1
git push origin python-v0.1.1

.github/workflows/publish-python.yml checks the tag, builds the sdist and wheel, and uploads them with PyPI Trusted Publishing — no API token or twine upload. Before the first run, add a pending publisher for yapbot on PyPI with owner foreski, repository Yap, workflow publish-python.yml and environment pypi. The first successful upload creates the project, and later tags use the same publisher.

Metadata

Release files for yapbot 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yapbot 0.1.1
File Size Uploaded Provenance Actions
yapbot-0.1.1.tar.gz 30.5 kB With provenance Details for yapbot-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for yapbot 0.1.1
File Interpreter ABI Platform Actions
yapbot-0.1.1-py3-none-any.whl Python 3 none any Details for yapbot-0.1.1-py3-none-any.whl

Total release size: 59.5 kB

Release files / yapbot-0.1.1.tar.gz

Download URL yapbot-0.1.1.tar.gz
Size 30.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1b6b01f515909f12f3f9b09cd8a38b6ff40861a31570b44d03020fd3688e7ecc
BLAKE2b-256 checksum
How to use checksums
4ce8d97e28a4022987522c720bada388b78ed2f179191c3b0b1eeb08de4d407c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.

Transparency log

Release files / yapbot-0.1.1-py3-none-any.whl

Download URL yapbot-0.1.1-py3-none-any.whl
Size 29.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dc1f925c3540edf2c79f922dca377fa2f4ac24dbda3cf2fe146a20ae735dc1e2
BLAKE2b-256 checksum
How to use checksums
f5f4f57826c1fcee02b0ca813b82e9b356032eba9a5a98a5524e4d4acf54f1e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.

Transparency log

Security for yapbot 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for yapbot-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page