Events
Manage Message, Postback, Quick Reply, and more events with @pyyupsk/messenger-webhooks library.
The
@pyyupsk/messenger-webhooks
library provides a robust mechanism for handling different types of events that
occur on
Facebook Messenger.
When users interact with your Messenger bot, various events are triggered, and
your bot can respond to these events using the library’s event handling system.
Event Handling
Event Types
The library can handle several types of events, each representing different interactions or messages from users. The event types supported are:
- Message: Represents a message sent by the user.
- Quick Reply: Represents a quick reply button click.
- Echo: Represents a echoes event.
- Postback: Represents a postback button click.
- Template: Represents a template message.
- Referral: Represents a referral event.
Event Structure
Each event type extends the base WebhookEvent
interface, which includes common
properties:
Event Interfaces
Here are the specific interfaces for each event type:
Message Event
Represents a message sent by the user. May include a quick reply and echo payload.
Quick Reply Event
Represents a quick reply button click.
Echo Event
Represents a message sent by the user. May include a quick reply and echo payload.
Postback Event
Represents a postback button click.
Template Event
Represents a template message. Includes template type and associated buttons.
Referral Event
Represents a referral event, typically used for deep linking or tracking.
Handling Events in the Bot
The Bot
class emits events based on the event type determined by the
determineEventType
function. Here’s how you can handle events in your bot:
In this setup, the bot listens for different event types and executes the appropriate handler for each event type.
By understanding and utilizing these event types and handlers, you can create dynamic and interactive Messenger bots that respond to user actions effectively.
Last updated on