Skip to content

docs(examples): add runnable examples directory with 8 end-to-end bots#195

Open
victalejo wants to merge 3 commits into
david-lev:devfrom
victalejo:master
Open

docs(examples): add runnable examples directory with 8 end-to-end bots#195
victalejo wants to merge 3 commits into
david-lev:devfrom
victalejo:master

Conversation

@victalejo

Copy link
Copy Markdown

Summary

Adds a new examples/ directory with 8 self-contained, runnable PyWa bots covering the main features of the library. Each example is a single-file main.py plus a focused README — readable in one sitting, copy-pasteable into a new project.

Today the README has good snippets, but new users still have to assemble a working webhook + tunnel + .env setup before anything runs. These examples close that gap.

What's included

# Example Demonstrates
01 Echo bot Minimal FastAPI webhook + first reply
02 Menu with buttons & sections Button, SectionList, typed CallbackData
03 Conversation with listeners wait_for_reply / wait_for_click, timeouts, cancelers
04 Flow: newsletter signup FlowJSON, FlowButton, on_flow_completion, RSA encryption setup
05 Templates Create + send a marketing template with named params
06 Media handling Receive/download images, audio, docs; send media from URL
07 Full async bot pywa_async with async def handlers + concurrent httpx
08 Flask alternative Same as 01, on Flask instead of FastAPI

Plus:

Conventions

  • One main.py per example, env vars via python-dotenv (no hardcoded secrets).
  • Comments explain why, not what — the code is the documentation.
  • Per-example README covers WhatsApp limits, gotchas, and common Meta error codes.

victalejo and others added 2 commits May 15, 2026 19:17
- Created .env.example for configuration in examples.
- Implemented Echo bot example with FastAPI.
- Added Menu with buttons and section lists example.
- Developed Conversation with listeners example for multi-turn interactions.
- Introduced Flow: newsletter signup example with encryption setup.
- Created Templates: create + send example for marketing templates.
- Implemented Media handling example for receiving and sending media.
- Added Full async bot example using pywa_async for asynchronous operations.
- Developed Flask alternative for the echo bot example.
- Updated main README.md to include all examples and setup instructions.
- Added shared requirements.txt for all examples.
@yehuda-lev yehuda-lev added the documentation Improvements or additions to documentation label May 17, 2026
@david-lev

Copy link
Copy Markdown
Owner

Hi @victalejo!

First of all, thank you so much for putting this together. I really love the clear examples you've built, and this is a massively important contribution. I am actually planning to add a pywa new <example-name> command to the new CLI that will fetch these exact examples directly from GitHub, so getting this merged is a huge priority for the project!
Since you started working on this PR, the core library has evolved a bit. Would you mind updating the examples to reflect some of our new syntax and features?

Here is what we need to tweak:

  1. Drop the FastAPI Boilerplate
    We now have the pywa CLI to run and develop projects, so we no longer need the explicit FastAPI setup in the examples (users will just install "pywa[server]"). Let's remove the FastAPI code so the examples remain purely focused on Pywa logic.

  2. Use the Built-in Ngrok Helper
    We recently added a handy utility to handle Ngrok tunnels automatically. Please replace the manual setup with utils.start_ngrok_tunnel:

from pywa.utils import start_ngrok_tunnel
from pywa import WhatsApp

callback_url = start_ngrok_tunnel(
    auth_token="your_ngrok_auth_token",
    domain="subdomain.ngrok-free.app",
)
wa = WhatsApp(callback_url=callback_url, ...)
  1. Replace print() with Logger
    To enforce best practices, please swap out any standard print() statements in the examples for the _logger.

  2. Inline Flow Components (Walrus Operator)
    To keep the code as clean as possible, we now prefer defining and placing Flow components inline using the walrus operator (:=) (see example https://pywa.readthedocs.io/en/dev/content/flows/overview.html#id2).

(e.g., Defining the button/component inline right where it is passed to the action/layout).
5. Inline Template Components
Similar to flows, please use the walrus operator (:=) for template components and use .params() directly on their component reference (see example https://pywa.readthedocs.io/en/dev/content/templates/overview.html#id8).

Thank you again for your time and effort on this! These examples are going to make the onboarding experience so much better for new developers using the CLI. Let me know if you run into any issues with the new syntax or need a hand with anything.

@david-lev david-lev changed the base branch from master to dev June 5, 2026 13:08
@david-lev

Copy link
Copy Markdown
Owner

I went ahead and updated the base branch for this PR to target dev instead of main (which is our standard workflow for new features).

To make things easier and keep everything perfectly synced, I also merged the latest dev branch directly into your fork. This means your branch now has all the latest changes and utilities we discussed above

Thanks again for this awesome contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants