Trait WebhookEventHandler

Source
pub trait WebhookEventHandler {
    type Error;

    // Provided methods
    fn handle_topic_created(
        &mut self,
        event: &TopicWebhookEvent,
    ) -> Result<(), Self::Error> { ... }
    fn handle_topic_edited(
        &mut self,
        event: &TopicWebhookEvent,
    ) -> Result<(), Self::Error> { ... }
    fn handle_topic_destroyed(
        &mut self,
        event: &TopicWebhookEvent,
    ) -> Result<(), Self::Error> { ... }
    fn handle_topic_recovered(
        &mut self,
        event: &TopicWebhookEvent,
    ) -> Result<(), Self::Error> { ... }
    fn handle_post_created(
        &mut self,
        event: &PostWebhookEvent,
    ) -> Result<(), Self::Error> { ... }
    fn handle_post_edited(
        &mut self,
        event: &PostWebhookEvent,
    ) -> Result<(), Self::Error> { ... }
    fn handle_post_destroyed(
        &mut self,
        event: &PostWebhookEvent,
    ) -> Result<(), Self::Error> { ... }
    fn handle_post_recovered(
        &mut self,
        event: &PostWebhookEvent,
    ) -> Result<(), Self::Error> { ... }
    fn handle_ping(&mut self) -> Result<(), Self::Error> { ... }
}
Expand description

Trait for handling different types of webhook events

Implement this trait to define custom behavior for each event type. All methods have default implementations that do nothing, so you only need to implement the events you care about.

§Examples (Sync)

use discourse_webhooks::{WebhookEventHandler, TopicWebhookEvent};

struct MyHandler;

impl WebhookEventHandler for MyHandler {
    type Error = String;

    fn handle_topic_created(&mut self, event: &TopicWebhookEvent) -> Result<(), Self::Error> {
        println!("Topic created: {}", event.topic.title);
        Ok(())
    }
}

§Examples (Async - requires “async” feature)

use discourse_webhooks::{WebhookEventHandler, TopicWebhookEvent, async_trait};

struct MyHandler;

#[async_trait]
impl WebhookEventHandler for MyHandler {
    type Error = String;

    async fn handle_topic_created(&mut self, event: &TopicWebhookEvent) -> Result<(), Self::Error> {
        // Your async logic here
        println!("Topic created: {}", event.topic.title);
        Ok(())
    }
}

Required Associated Types§

Source

type Error

The error type returned by event handlers

Provided Methods§

Source

fn handle_topic_created( &mut self, event: &TopicWebhookEvent, ) -> Result<(), Self::Error>

Called when a new topic is created

Source

fn handle_topic_edited( &mut self, event: &TopicWebhookEvent, ) -> Result<(), Self::Error>

Called when a topic is edited

Source

fn handle_topic_destroyed( &mut self, event: &TopicWebhookEvent, ) -> Result<(), Self::Error>

Called when a topic is deleted/destroyed

Source

fn handle_topic_recovered( &mut self, event: &TopicWebhookEvent, ) -> Result<(), Self::Error>

Called when a deleted topic is recovered

Source

fn handle_post_created( &mut self, event: &PostWebhookEvent, ) -> Result<(), Self::Error>

Called when a new post is created

Source

fn handle_post_edited( &mut self, event: &PostWebhookEvent, ) -> Result<(), Self::Error>

Called when a post is edited

Source

fn handle_post_destroyed( &mut self, event: &PostWebhookEvent, ) -> Result<(), Self::Error>

Called when a post is deleted/destroyed

Source

fn handle_post_recovered( &mut self, event: &PostWebhookEvent, ) -> Result<(), Self::Error>

Called when a deleted post is recovered

Source

fn handle_ping(&mut self) -> Result<(), Self::Error>

Called when a ping event is received

Implementors§