sfr_server/response/
slash_command.rs1use sfr_types as st;
4
5use crate::response::{CT_APPLICATION_JSON, CT_TEXT_PLAIN};
6use axum::body::Body;
7use axum::http::status::StatusCode;
8use axum::http::Response;
9use axum::response::IntoResponse;
10
11#[derive(Debug)]
13pub struct SlashCommandResponse(st::SlashCommandResponse);
14
15impl From<st::SlashCommandResponse> for SlashCommandResponse {
16 fn from(r: st::SlashCommandResponse) -> Self {
17 Self(r)
18 }
19}
20
21impl IntoResponse for SlashCommandResponse {
22 fn into_response(self) -> Response<Body> {
23 match self.0 {
24 st::SlashCommandResponse::Empty => return ([CT_TEXT_PLAIN], "").into_response(),
25 st::SlashCommandResponse::String(s) => return ([CT_TEXT_PLAIN], s).into_response(),
26 st::SlashCommandResponse::Layouts(_)
27 | st::SlashCommandResponse::LayoutsInChannel(_) => {}
28 }
29
30 let body = match serde_json::to_string(&self.0) {
31 Ok(body) => body,
32 Err(e) => {
33 tracing::warn!("failed to serialise to build layouts: {e:?}");
34 return (StatusCode::INTERNAL_SERVER_ERROR, "").into_response();
35 }
36 };
37
38 tracing::trace!("SlashCommandResponse::into_response: body = {body}");
39 ([CT_APPLICATION_JSON], body).into_response()
40 }
41}