Skip to main content

tuwunel_admin/appservice/
register.rs

1use ruma::api::appservice::Registration;
2use tuwunel_core::{Err, Result, checked, err};
3
4use crate::admin_command;
5
6#[admin_command]
7pub(super) async fn appservice_register(&self) -> Result {
8	let body = &self.body;
9	let body_len = self.body.len();
10	if body_len < 2
11		|| !body[0].trim().starts_with("```")
12		|| body.last().unwrap_or(&"").trim() != "```"
13	{
14		return Err!("Expected code block in command body. Add --help for details.");
15	}
16
17	let range = 1..checked!(body_len - 1)?;
18	let appservice_config_body = body[range].join("\n");
19
20	let registration: Registration = serde_yaml::from_str(&appservice_config_body)
21		.map_err(|e| err!("Could not parse appservice config as YAML: {e}"))?;
22
23	let id = registration.id.clone();
24
25	self.services
26		.appservice
27		.register_appservice(registration)
28		.await
29		.map_err(|e| err!("Failed to register appservice: {e}"))?;
30
31	write!(self, "Appservice registered with ID: {id}").await
32}