diff options
Diffstat (limited to 'pkg/twilio/sms.go')
| -rw-r--r-- | pkg/twilio/sms.go | 34 |
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(): + } +} |
