Examples
Explore examples and usage scenarios for @pyyupsk/messenger-webhooks.
Explore practical examples of how to use the
@pyyupsk/messenger-webhooks
library. These examples illustrate common use cases and provide a starting point
for building your own Messenger bots. For more information on Messenger bot
capabilities, refer to the
official Facebook Messenger Platform documentation.
Weather Bot Example
The Weather Bot example demonstrates how to create a simple bot that responds
with weather information for a specified city. This example uses the
@pyyupsk/messenger-webhooks
library to interact with the Messenger Platform.
Project Structure
Setup
Follow these steps to set up and run the Weather Bot example:
-
Clone the Repository:
-
Navigate to the Examples Directory:
-
Install Dependencies:
-
Set Up Your Environment Variables:
Create a
.env
file in the root of the project with the following variables:Replace
your_facebook_page_access_token
andyour_webhook_verify_token
with your actual Facebook Page Access Token and Webhook Verify Token. -
Build the Project:
-
Start the Bot:
Usage
Once the bot is running and properly configured with Facebook Messenger:
- Send a message to your Facebook Page with a city name or place.
- The bot will respond with the current weather information for that location.
Development
To run the bot in development mode with hot reloading:
This command starts the bot with hot reloading enabled, allowing you to make changes to the code and see the updates in real-time without restarting the bot.
Additional Information
index.ts
: The entry point for the bot application, which sets up the bot and handles incoming messages.weatherService.ts
: Contains the logic for fetching weather information and formatting it for the user.
For more details or to contribute to the example projects, check out the repository or create an issue if you encounter any problems.
Feel free to explore and adapt the example code to fit your needs. Happy coding!
Last updated on