HTTP Server Setup
The HTTP server starts automatically when you initialize the bot:Creating Endpoints
UsehandleCtx() to create endpoints that have access to your bot instance:
Basic POST Endpoint
Basic GET Endpoint
Sending Messages
Create an endpoint to send text messages:Triggering Flows
Trigger conversation flows programmatically:Dispatch Custom Events
Test Flow Trigger
Blacklist Management
Create endpoints to manage the blacklist:Add/Remove from Blacklist
Get Blacklist
Test Blacklist API
State Management via API
Access and modify state through HTTP endpoints:Get User State
Update User State
Clear User State
Request Parameters
Access different types of request data:URL Parameters
URL Parameters
Query Parameters
Query Parameters
Request Body
Request Body
Response Formats
JSON Response
Text Response
Error Response
Complete API Example
Bot Instance Methods
These methods are available on thebot object in handleCtx:
| Method | Description |
|---|---|
bot.sendMessage(number, message, options) | Send a message to a number |
bot.dispatch(event, context) | Trigger a custom event flow |
bot.blacklist.add(number) | Add number to blacklist |
bot.blacklist.remove(number) | Remove number from blacklist |
bot.blacklist.getList() | Get all blacklisted numbers |
bot.state(number) | Access user state |
bot.globalState() | Access global state |
bot.provider | Access provider instance |
Best Practices
Validate input
Validate input
Always validate request data:
Handle errors gracefully
Handle errors gracefully
Wrap logic in try-catch blocks:
Use appropriate HTTP methods
Use appropriate HTTP methods
- GET: Retrieve data
- POST: Create/trigger actions
- PUT/PATCH: Update data
- DELETE: Remove data
Secure your endpoints
Secure your endpoints
Add authentication:
Next Steps
- Learn about State Management to use state in endpoints
- Explore Queue System to understand message processing
- Check out Testing to test your endpoints