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:
git clone https://github.com/pyyupsk/messenger-webhooks.git -
Navigate to the Examples Directory:
cd messenger-webhooks/apps/examples -
Install Dependencies:
npm install -
Set Up Your Environment Variables:
Copy the example environment file and configure it with your credentials:
cp .env.example .envThen edit
.envand fill in your values:-
ACCESS_TOKEN: Your Facebook Page Access Token- Get it from the Facebook Developer Console
- Navigate to: Your App > Messenger > Settings > Access Tokens
-
VERIFY_TOKEN: Your Webhook Verify Token-
Any string you choose (must match the one in Facebook webhook setup)
-
Generate a secure token using one of these methods:
# Using openssl (recommended) openssl rand -base64 32Or visit our password generator to create a secure random token online.
-
-
-
Build the Project:
npm run build -
Start the Bot:
npm run start
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:
npm run devThis 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