-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbasic_usage.rs
41 lines (33 loc) · 1.17 KB
/
basic_usage.rs
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
use actix_web::{web, App, HttpServer};
use ussdframework::prelude::*;
mod config;
mod controller;
mod functions;
mod session;
use controller::{handle_ussd, health_check};
use session::InMemorySessionStore;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
// Start the MenuBuilder server
// menubuilder::MenuBuilder::server(8080).await?;
// menubuilder::MenuBuilder::to_json(Some("menu.json"));
HttpServer::new(move || {
let session_store = InMemorySessionStore::new();
// Create a new instance of UssdApp
let app = UssdApp::new(false, Some(Box::new(session_store)));
// Register functions
app.register_functions(functions::get_functions());
// Load menus
let content = include_str!("../examples/data/menu.json");
let menus: USSDMenu = serde_json::from_str(&content).unwrap();
// Create a new instance of the Actix web application
App::new()
.app_data(web::Data::new(app))
.app_data(web::Data::new(menus))
.service(health_check)
.route("/ussd", web::post().to(handle_ussd))
})
.bind("127.0.0.1:3000")?
.run()
.await
}