aboutsummaryrefslogtreecommitdiffstats
path: root/main.go
diff options
context:
space:
mode:
authorterminaldweller <devi@terminaldweller.com>2023-10-14 13:31:32 +0000
committerterminaldweller <devi@terminaldweller.com>2023-10-14 13:31:32 +0000
commit93b89566ba9010fe5998513c5e00a61d476e4c55 (patch)
treed04bbafb38d58e08d8f91a2ef3783f132bc355fa /main.go
parentone (diff)
downloadsms-webhook-93b89566ba9010fe5998513c5e00a61d476e4c55.tar.gz
sms-webhook-93b89566ba9010fe5998513c5e00a61d476e4c55.zip
wip
Diffstat (limited to 'main.go')
-rw-r--r--main.go61
1 files changed, 58 insertions, 3 deletions
diff --git a/main.go b/main.go
index d32641e..41e6bfe 100644
--- a/main.go
+++ b/main.go
@@ -1,18 +1,73 @@
package main
import (
+ "flag"
+ "fmt"
"log"
- "os"
+ "net/http"
+ "github.com/go-redis/redis/v8"
+ "github.com/labstack/echo/v5"
"github.com/pocketbase/pocketbase"
- "github.com/pocketbase/pocketbase/apis"
"github.com/pocketbase/pocketbase/core"
)
+var rdb *redis.Client
+
+const (
+ redisDialTimeout = 5
+ redisReadTimeout = 10
+ redisWriteTimetout = 10
+)
+
+type SMSInfo struct {
+ From string `json:"from"`
+ Text string `json:"text"`
+ SentStamp int64 `json:"sentStamp"`
+ ReceivedStamp int64 `json:"receivedStamp"`
+ Sim string `json:"sim"`
+}
+
+func postHandler(context echo.Context) error {
+ smsInfo := new(SMSInfo)
+ if err := context.Bind(smsInfo); err != nil {
+ return context.String(http.StatusBadRequest, "bad request")
+ }
+
+ smsInfoReal := SMSInfo{
+ From: smsInfo.From,
+ Text: smsInfo.Text,
+ SentStamp: smsInfo.SentStamp,
+ ReceivedStamp: smsInfo.ReceivedStamp,
+ Sim: smsInfo.Sim,
+ }
+
+ fmt.Println(smsInfoReal)
+
+ return context.JSON(http.StatusOK, smsInfo)
+}
+
func main() {
+ redisAddress := flag.String("redisaddress", "redis:6379", "determines the address of the redis instance")
+ redisPassword := flag.String("redispassword", "", "determines the password of the redis db")
+ redisDB := flag.Int64("redisdb", 0, "determines the db number")
+ flag.Parse()
+
+ rdb = redis.NewClient(&redis.Options{
+ Addr: *redisAddress,
+ Password: *redisPassword,
+ DB: int(*redisDB),
+ DialTimeout: redisDialTimeout,
+ ReadTimeout: redisReadTimeout,
+ WriteTimeout: redisWriteTimetout,
+ })
+ defer rdb.Close()
+
app := pocketbase.New()
+
app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
- e.Router.GET("/*", apis.StaticDirectoryHandler(os.DirFS("./pb_public"), false))
+ e.Router.POST("/sms/*", postHandler)
+
return nil
})