commit 327649889c9a0bef4ed082e637a030ab71fd713c
parent a4361a759062211a1fc5751659117a8ce9014181
Author: Henry Unite <unitehenry@gmail.com>
Date: Sat, 28 Feb 2026 06:45:42 +0000
refactor: build xml helpers
Diffstat:
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/voice.ts b/voice.ts
@@ -29,28 +29,36 @@ function respond(req: Request, res: Response, message: string): void {
res.send(responseXml);
}
-function hangup(res: Response, message: string = ""): void {
- const responseXml = `<?xml version="1.0" encoding="UTF-8"?>
+function buildHangupXml(message: string) {
+ return `<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>${message}</Say>
<Hangup />
</Response>
`;
+}
+
+function hangup(res: Response, message: string = ""): void {
+ const hangupXml = buildHangupXml(message);
res.set("Content-Type", "text/xml");
- res.send(responseXml);
+ res.send(hangupXml);
}
-function hold(res: Response): void {
- const responseXml = `<?xml version="1.0" encoding="UTF-8"?>
+function buildHoldXml(holdMusicUrl: string) {
+ return `<?xml version="1.0" encoding="UTF-8"?>
<Response>
- <Play loop="0">${HOLD_MUSIC_URL}</Play>
+ <Play loop="0">${holdMusicUrl}</Play>
</Response>`;
+}
+
+function hold(res: Response): void {
+ const holdXml = buildHoldXml(HOLD_MUSIC_URL);
res.set("Content-Type", "text/xml");
- res.send(responseXml);
+ res.send(holdXml);
}
interface UpdateCallParams {