diff options
| author | Matthieu <matthieu@developershouse.xyz> | 2021-10-18 13:29:07 +0400 |
|---|---|---|
| committer | Matthieu <matthieu@developershouse.xyz> | 2021-10-18 13:29:07 +0400 |
| commit | 9023aa354902844b7d6100f55c3064afedd88966 (patch) | |
| tree | 195ddb0e3d3ffecf93f1a060325e429dd2356c3e /webhook/src/handler/handler.rs | |
| parent | b94b0552f81e667bec31352901bbc8c76f1b4216 (diff) | |
| parent | a80124cfe207cf99fb170d1050b4f609c6a169d3 (diff) | |
Merge branch 'nats-structs-discord-gateway'
Diffstat (limited to 'webhook/src/handler/handler.rs')
| -rw-r--r-- | webhook/src/handler/handler.rs | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/webhook/src/handler/handler.rs b/webhook/src/handler/handler.rs index 4af2ba6..74a1762 100644 --- a/webhook/src/handler/handler.rs +++ b/webhook/src/handler/handler.rs @@ -1,8 +1,10 @@ use super::error::WebhookError; -use super::{signature::validate_signature, types::Interaction}; +use super::signature::validate_signature; use crate::config::Config; -use common::log::{debug, error, info}; +use common::discord_models::slash_commands::{Interaction, InteractionRequestType}; +use common::log::{debug, error}; use common::nats_crate::Connection; +use common::payloads::CacheData; use hyper::{ body::{to_bytes, Bytes}, service::Service, @@ -79,15 +81,12 @@ impl HandlerService { let utf8 = from_utf8(&data); match utf8 { Ok(data) => match serde_json::from_str::<Interaction>(data) { - Ok(value) => { - if value.t == 1 { - info!("sending pong"); - // a ping must be responded with another ping - return Ok(Response::builder() - .header("Content-Type", "application/json") - .body(serde_json::to_string(&Ping { t: 1 }).unwrap().into()) - .unwrap()); - } else { + Ok(value) => match value.type_ { + InteractionRequestType::Ping => Ok(Response::builder() + .header("Content-Type", "application/json") + .body(serde_json::to_string(&Ping { t: 1 }).unwrap().into()) + .unwrap()), + _ => { debug!("calling nats"); // this should hopefully not fail ? let payload = @@ -96,8 +95,9 @@ impl HandlerService { node_id: "".to_string(), span: None, }, - operation: "".to_string(), - data: value, + data: CacheData::InteractionCreate { + interaction: Box::new(value), + }, }) .unwrap(); @@ -120,7 +120,7 @@ impl HandlerService { } } } - } + }, Err(_) => Err(WebhookError::new( StatusCode::BAD_REQUEST, |
