aboutsummaryrefslogtreecommitdiff
path: root/pkg/twilio/sms.go
diff options
context:
space:
mode:
authorGrégoire Duchêne <gduchene@awhk.org>2021-03-14 15:41:22 +0000
committerGrégoire Duchêne <gduchene@awhk.org>2021-03-14 15:41:22 +0000
commitce3182d4c3f5fb723a16bece3157a5058b1236f9 (patch)
tree858301133dd6a547e935da356f049ac165261c06 /pkg/twilio/sms.go
parentd10731043bfd7429ebd22c717794c8363f462caf (diff)
Move Twilio authn code into its own package
Diffstat (limited to 'pkg/twilio/sms.go')
-rw-r--r--pkg/twilio/sms.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/pkg/twilio/sms.go b/pkg/twilio/sms.go
new file mode 100644
index 0000000..0a7dba8
--- /dev/null
+++ b/pkg/twilio/sms.go
@@ -0,0 +1,34 @@
+// SPDX-FileCopyrightText: © 2021 Grégoire Duchêne <gduchene@awhk.org>
+// SPDX-License-Identifier: ISC
+
+package twilio
+
+import (
+ "net/http"
+ "time"
+)
+
+type SMS struct {
+ DateReceived time.Time
+ From, To, Body string
+}
+
+type SMSTee struct {
+ Chan chan<- SMS
+ Handler http.Handler
+}
+
+var _ http.Handler = &SMSTee{}
+
+func (th *SMSTee) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+ select {
+ case th.Chan <- SMS{
+ DateReceived: time.Now(),
+ From: r.FormValue("From"),
+ To: r.FormValue("To"),
+ Body: r.FormValue("Body"),
+ }:
+ th.Handler.ServeHTTP(w, r)
+ case <-r.Context().Done():
+ }
+}