Skip to content

Commit 00adf30

Browse files
committed
Added phone number to admin page
1 parent 7323af3 commit 00adf30

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

src/routes/admin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ adminRoutes.get("/status", async (c) => {
1818
}
1919
const result = await checkAllServices(
2020
c.env.TWILIO_ACCOUNT_SID,
21-
c.env.TWILIO_AUTH_TOKEN
21+
c.env.TWILIO_AUTH_TOKEN,
22+
c.env.TWILIO_PHONE_NUMBER
2223
);
2324
return c.json(result);
2425
});

src/services/status.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export type ServiceStatus = {
88
export type StatusResult = {
99
overall: "ok" | "degraded" | "down";
1010
checked_at: string;
11+
phone_number: string | null;
1112
services: ServiceStatus[];
1213
};
1314

@@ -64,7 +65,7 @@ async function checkTwilio(accountSid: string, authToken: string): Promise<Servi
6465
}
6566
}
6667

67-
export async function checkAllServices(accountSid: string, authToken: string): Promise<StatusResult> {
68+
export async function checkAllServices(accountSid: string, authToken: string, phoneNumber?: string): Promise<StatusResult> {
6869
const services = await Promise.all([
6970
checkAvalancheApi(),
7071
checkTwilio(accountSid, authToken),
@@ -77,6 +78,7 @@ export async function checkAllServices(accountSid: string, authToken: string): P
7778
return {
7879
overall,
7980
checked_at: new Date().toISOString(),
81+
phone_number: phoneNumber || null,
8082
services,
8183
};
8284
}

src/templates/admin.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: #f5f5f5; color: #333; padding: 20px; max-width: 640px; margin: 0 auto; }
1010
h1 { margin-bottom: 6px; font-size: 1.4em; }
1111
.subtitle { font-size: 0.85em; color: #666; margin-bottom: 20px; }
12+
.phone { background: #fff; border-radius: 8px; padding: 16px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); margin-bottom: 20px; display: flex; align-items: center; gap: 12px; }
13+
.phone-label { font-size: 0.8em; color: #666; text-transform: uppercase; letter-spacing: 0.5px; }
14+
.phone-number { font-size: 1.3em; font-weight: 600; letter-spacing: 0.5px; }
1215
.overall { padding: 16px; border-radius: 8px; margin-bottom: 20px; font-weight: 600; font-size: 1.1em; text-align: center; }
1316
.overall.ok { background: #dcfce7; color: #166534; }
1417
.overall.degraded { background: #fef9c3; color: #854d0e; }
@@ -32,12 +35,21 @@
3235
<body>
3336
<h1>Avalanche SMS</h1>
3437
<div class="subtitle">System Status</div>
38+
<div class="phone" id="phone" style="display:none">
39+
<div><div class="phone-label">Text lat,long or send location to</div><div class="phone-number" id="phone-number"></div></div>
40+
</div>
3541
<div class="overall loading" id="overall">Checking...</div>
3642
<div id="services"></div>
3743
<button class="refresh-btn" id="refresh-btn" onclick="refresh()">Refresh</button>
3844
<div class="updated" id="updated"></div>
3945
<script>
4046
var labels = { ok: 'All Systems Operational', degraded: 'Partial Outage', down: 'Major Outage' };
47+
function formatPhone(num) {
48+
// Format +15551234567 as +1 (555) 123-4567
49+
var m = num.match(/^\+1(\d{3})(\d{3})(\d{4})$/);
50+
if (m) return '+1 (' + m[1] + ') ' + m[2] + '-' + m[3];
51+
return num;
52+
}
4153
function refresh() {
4254
var btn = document.getElementById('refresh-btn');
4355
btn.disabled = true;
@@ -48,6 +60,13 @@ <h1>Avalanche SMS</h1>
4860
fetch('/status').then(function(r) { return r.json(); }).then(function(data) {
4961
ov.className = 'overall ' + data.overall;
5062
ov.textContent = labels[data.overall] || data.overall;
63+
var phoneEl = document.getElementById('phone');
64+
if (data.phone_number) {
65+
document.getElementById('phone-number').textContent = formatPhone(data.phone_number);
66+
phoneEl.style.display = '';
67+
} else {
68+
phoneEl.style.display = 'none';
69+
}
5170
var container = document.getElementById('services');
5271
container.innerHTML = '';
5372
data.services.forEach(function(s) {

0 commit comments

Comments
 (0)