Proactive Messaging¶
These examples demonstrate sending messages proactively -- without waiting for a user to message first (once a context_token has been established).
Proactive Text Sending¶
Waits for one incoming message to cache a context_token, then sends 3 consecutive text messages to that user.
See examples/test_proactive_send.py in the repository.
Usage¶
How It Works¶
- Logs in and waits for one incoming message via
wl.recv(). - The SDK automatically caches the
context_tokenfrom that message. - Sends 3 text messages in a row to the same user using
wl.send()-- no furtherrecv()needed.
Proactive Media Sending¶
Sends text, image, file (PDF), and video to a specific user using a persisted context_token -- no recv() call is needed at all.
See examples/test_proactive_media.py in the repository.
Usage¶
Note
This example hardcodes a target user ID and local file paths. Edit the USER variable and file paths in the script before running.
How It Works¶
- Logs in. Because the SDK persists
context_tokenvalues across sessions, norecv()is needed if the user has previously messaged the bot. - Sends four media types in sequence: text, image, file, and video.
- Each
wl.send()call reads the local file intobytesand passes it via the appropriate keyword argument (image=,file=,video=).
Key Features Demonstrated¶
- context_token caching -- the SDK automatically stores tokens so you can message users without waiting for them to message first.
- context_token persistence -- tokens survive across bot restarts, enabling fully proactive messaging.
- Consecutive sends -- multiple
wl.send()calls work without interleavingwl.recv(). - Multimodal proactive sending -- text, image, file, and video can all be sent proactively.