story-kit: merge 320_story_whatsapp_business_api_integration_for_bot_commands

This commit is contained in:
Dave
2026-03-19 23:03:35 +00:00
parent cc0110e577
commit 351f770516
8 changed files with 721 additions and 90 deletions

View File

@@ -29,6 +29,8 @@ use settings::SettingsApi;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use crate::whatsapp::WhatsAppWebhookContext;
const DEFAULT_PORT: u16 = 3001;
pub fn parse_port(value: Option<String>) -> u16 {
@@ -51,12 +53,15 @@ pub fn remove_port_file(path: &Path) {
let _ = std::fs::remove_file(path);
}
pub fn build_routes(ctx: AppContext) -> impl poem::Endpoint {
pub fn build_routes(
ctx: AppContext,
whatsapp_ctx: Option<Arc<WhatsAppWebhookContext>>,
) -> impl poem::Endpoint {
let ctx_arc = std::sync::Arc::new(ctx);
let (api_service, docs_service) = build_openapi_service(ctx_arc.clone());
Route::new()
let mut route = Route::new()
.nest("/api", api_service)
.nest("/docs", docs_service.swagger_ui())
.at("/ws", get(ws::ws_handler))
@@ -71,8 +76,18 @@ pub fn build_routes(ctx: AppContext) -> impl poem::Endpoint {
.at("/health", get(health::health))
.at("/assets/*path", get(assets::embedded_asset))
.at("/", get(assets::embedded_index))
.at("/*path", get(assets::embedded_file))
.data(ctx_arc)
.at("/*path", get(assets::embedded_file));
if let Some(wa_ctx) = whatsapp_ctx {
route = route.at(
"/webhook/whatsapp",
get(crate::whatsapp::webhook_verify)
.post(crate::whatsapp::webhook_receive)
.data(wa_ctx),
);
}
route.data(ctx_arc)
}
type ApiTuple = (
@@ -181,6 +196,6 @@ mod tests {
fn build_routes_constructs_without_panic() {
let tmp = tempfile::tempdir().unwrap();
let ctx = context::AppContext::new_test(tmp.path().to_path_buf());
let _endpoint = build_routes(ctx);
let _endpoint = build_routes(ctx, None);
}
}