Messenger WebhooksMessenger Webhooks

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

index.ts
weatherService.ts
package.json
tsconfig.json
README.md

Setup

Follow these steps to set up and run the Weather Bot example:

  1. Clone the Repository:

    git clone https://github.com/pyyupsk/messenger-webhooks.git
  2. Navigate to the Examples Directory:

    cd messenger-webhooks/apps/examples
  3. Install Dependencies:

    npm install
  4. Set Up Your Environment Variables:

    Copy the example environment file and configure it with your credentials:

    cp .env.example .env

    Then edit .env and fill in your values:

    • ACCESS_TOKEN: Your Facebook Page Access Token

    • 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 32

        Or visit our password generator to create a secure random token online.

  5. Build the Project:

    npm run build
  6. Start the Bot:

    npm run start

Usage

Once the bot is running and properly configured with Facebook Messenger:

  1. Send a message to your Facebook Page with a city name or place.
  2. 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 dev

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!

Edit on GitHub

Last updated on