1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// src/adapter/handler/webhook_management.rs
use super::ConnectionHandler;
use super::types::*;
use crate::app::config::App;
use crate::error::Result;
use crate::websocket::SocketId;
use tracing::warn;
impl ConnectionHandler {
pub async fn send_client_event_webhook(
&self,
socket_id: &SocketId,
app_config: &App,
request: &ClientEventRequest,
) -> Result<()> {
if let Some(webhook_integration) = &self.webhook_integration {
// Get user_id for presence channels - clone the string to avoid lifetime issues
let user_id = if request.channel.starts_with("presence-") {
let connection_manager = &self.connection_manager;
if let Some(conn_arc) = connection_manager
.get_connection(socket_id, &app_config.id)
.await
{
let conn_locked = conn_arc.inner.lock().await;
conn_locked
.state
.presence
.as_ref()
.and_then(|p_map| p_map.get(&request.channel))
.map(|pi| pi.user_id.clone()) // Clone the String instead of borrowing
} else {
None
}
} else {
None
};
webhook_integration
.send_client_event(
app_config,
&request.channel,
&request.event,
request.data.clone(),
Some(&socket_id.to_string()),
user_id.as_deref(), // Convert Option<String> to Option<&str>
)
.await
.unwrap_or_else(|e| {
warn!(
"Failed to send client_event webhook for {}: {}",
request.channel, e
);
});
}
Ok(())
}
}