Compare commits

..

2 Commits

Author SHA1 Message Date
c36774db3b Finish NoService and NightMode 2026-03-26 21:02:52 -04:00
b078dceb66 Forward the call to FreePBX successfully 2026-03-26 00:30:51 -04:00
5 changed files with 44 additions and 10 deletions

View File

@@ -49,12 +49,12 @@
<permission name="extended-data" value="false"/> <permission name="extended-data" value="false"/>
<permission name="execute-apps" value="true"> <permission name="execute-apps" value="true">
<!-- default to "deny" or "allow" --> <!-- default to "deny" or "allow" -->
<application-list default="allow"> <application-list default="deny">
<!-- type attr can be "deny" or "allow" nothing defaults to opposite of the list default so allow in this case --> <!-- type attr can be "deny" or "allow" nothing defaults to opposite of the list default so allow in this case -->
<!--
<application name="info"/> <application name="info"/>
<application name="answer"/>
<application name="hangup"/> <application name="hangup"/>
--> <application name="bridge"/>
</application-list> </application-list>
</permission> </permission>
<permission name="expand-vars-in-tag-body" value="false"> <permission name="expand-vars-in-tag-body" value="false">

View File

@@ -1,2 +1,3 @@
DATABASE_URL=postgres://freeswitch:T5NyU2NwQb5DD9oV@localhost/did_router DATABASE_URL=postgres://freeswitch:T5NyU2NwQb5DD9oV@localhost/did_router
SOUND_PATH=/usr/src/freeswitch_chris/sounds

View File

@@ -1,9 +1,19 @@
use dotenvy::dotenv;
use std::env;
use xml_builder::{XMLBuilder, XMLElement, XMLVersion}; use xml_builder::{XMLBuilder, XMLElement, XMLVersion};
use super::database as db; use super::database as db;
use super::database::{DidTargetType, Did}; use super::database::{DidTargetType, Did};
pub fn url(_did: Did) -> XMLElement { pub fn url(did: Did) -> XMLElement {
let work = XMLElement::new("work"); let mut work = XMLElement::new("work");
let mut bridge = XMLElement::new("execute");
let target = did.target.unwrap();
bridge.add_attribute("application", "bridge");
bridge.add_attribute("data", format!("sofia/internal/{}", target).as_str());
work.add_child(bridge).unwrap();
work work
} }
@@ -18,17 +28,25 @@ pub fn external_number(_did: Did) -> XMLElement {
} }
pub fn no_service(_did: Did) -> XMLElement { pub fn no_service(_did: Did) -> XMLElement {
dotenv().ok();
let sound_path = env::var("SOUND_PATH").expect("SOUND_PATH must be set");
let no_service_path = format!("{}/no_service.wav", sound_path);
let mut work = XMLElement::new("work"); let mut work = XMLElement::new("work");
let mut playback = XMLElement::new("playback");
playback.add_attribute("name", "exten");
playback.add_attribute("file", "ivr/ivr-welcome_to_freeswitch.wav");
work.add_child(playback).unwrap(); add_playback(&mut work, &no_service_path);
work work
} }
pub fn night_mode(_did: Did) -> XMLElement { pub fn night_mode(_did: Did) -> XMLElement {
let work = XMLElement::new("work"); dotenv().ok();
let sound_path = env::var("SOUND_PATH").expect("SOUND_PATH must be set");
let night_mode_path = format!("{}/night_mode.wav", sound_path);
let mut work = XMLElement::new("work");
add_playback(&mut work, &night_mode_path);
work work
} }
@@ -37,6 +55,21 @@ pub fn custom_message(_did: Did) -> XMLElement {
work work
} }
pub fn add_playback(work: &mut XMLElement ,file_path: &str) {
let mut answer = XMLElement::new("execute");
answer.add_attribute("application", "answer");
work.add_child(answer).unwrap();
let mut playback = XMLElement::new("playback");
playback.add_attribute("name", "exten");
playback.add_attribute("file", &file_path);
work.add_child(playback).unwrap();
let mut hangup = XMLElement::new("execute");
hangup.add_attribute("application", "hangup");
work.add_child(hangup).unwrap();
}
pub fn route_call(did: String) -> Vec<u8> { pub fn route_call(did: String) -> Vec<u8> {
let d = db::get_did_by(&did).unwrap(); let d = db::get_did_by(&did).unwrap();
let mut xml = XMLBuilder::new() let mut xml = XMLBuilder::new()

BIN
sounds/night_mode.wav Normal file

Binary file not shown.

BIN
sounds/no_service.wav Normal file

Binary file not shown.