Skip to content

Send and receive SMS messages using your Android phone programmatically via a simple HTTP API

Add API to fetch all messages

Acho Arnoldf7e0e95f36d7
diff --git a/api/Dockerfile b/api/Dockerfile
index efedb289..ca1127f9 100644
--- a/api/Dockerfile
+++ b/api/Dockerfile
@@ -35,4 +35,4 @@ ENV ZONEINFO=/zoneinfo.zip
EXPOSE 8000
-ENTRYPOINT ["./http-sms"]
+ENTRYPOINT ["./http-sms", "--dotenv=false"]
diff --git a/api/go.mod b/api/go.mod
index 9b7ef598..20b2597d 100644
--- a/api/go.mod
+++ b/api/go.mod
@@ -9,7 +9,6 @@ require (
github.com/davecgh/go-spew v1.1.1
github.com/go-redis/redis/v8 v8.11.5
github.com/gofiber/fiber/v2 v2.34.0
- github.com/gofiber/swagger v0.0.1
github.com/google/uuid v1.3.0
github.com/joho/godotenv v1.4.0
github.com/palantir/stacktrace v0.0.0-20161112013806-78658fd2d177
@@ -49,7 +48,6 @@ require (
github.com/mailru/easyjson v0.7.7 // indirect
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 // indirect
- github.com/swaggo/files v0.0.0-20210815190702-a29dd2bc99b2 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.37.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
diff --git a/api/go.sum b/api/go.sum
index 4a46d50b..b4c374a4 100644
--- a/api/go.sum
+++ b/api/go.sum
@@ -7,9 +7,6 @@ github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc=
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
-github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
-github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
-github.com/agiledragon/gomonkey/v2 v2.3.1/go.mod h1:ap1AmDzcVOAz1YpeJ3TCzIgstoaWLA6jbbgxfB4w2iY=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY=
@@ -25,7 +22,6 @@ github.com/cockroachdb/cockroach-go/v2 v2.2.11/go.mod h1:xZ2VHjUEb/cySv0scXBx7Ys
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
-github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -37,7 +33,6 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/r
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
-github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
@@ -46,10 +41,8 @@ github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY=
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
-github.com/go-openapi/jsonreference v0.19.6/go.mod h1:diGHMEHg2IqXZGKxqyvWdfWU/aim5Dprw5bqpKkTvns=
github.com/go-openapi/jsonreference v0.20.0 h1:MYlu0sBgChmCfJxxUKZ8g1cPWFOB37YSZqewK7OKeyA=
github.com/go-openapi/jsonreference v0.20.0/go.mod h1:Ag74Ico3lPc+zR+qjn4XBUmXymS4zJbYVCZmcgkasdo=
-github.com/go-openapi/spec v0.20.4/go.mod h1:faYFR1CvsJZ0mNsmsphTMSoRrNV3TEDoAM7FOEWeq8I=
github.com/go-openapi/spec v0.20.6 h1:ich1RQ3WDbfoeTqTAb+5EIxNmpKVJZWBNah9RAT0jIQ=
github.com/go-openapi/spec v0.20.6/go.mod h1:2OpW+JddWPrpXSCIX8eOx7lZ5iyuWj3RYR6VaaBKcWA=
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
@@ -62,11 +55,8 @@ github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfC
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
-github.com/gofiber/fiber/v2 v2.32.0/go.mod h1:CMy5ZLiXkn6qwthrl03YMyW1NLfj0rhxz2LKl4t7ZTY=
github.com/gofiber/fiber/v2 v2.34.0 h1:96BJMw6uaxQhJsHY54SFGOtGgp9pgombK5Hbi4JSEQA=
github.com/gofiber/fiber/v2 v2.34.0/go.mod h1:ozRQfS+D7EL1+hMH+gutku0kfx1wLX4hAxDCtDzpj4U=
-github.com/gofiber/swagger v0.0.1 h1:Qwt6uehJffeMG7zla3ampguOPtAW5K4xDAmpaL1qwXk=
-github.com/gofiber/swagger v0.0.1/go.mod h1:gal49FHSULvKAl9Ta+W7fRHdlTWhHPvArmsxKaIdLw4=
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw=
@@ -84,7 +74,6 @@ github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm4
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
-github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo=
github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8=
@@ -153,7 +142,6 @@ github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8Hm
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
-github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.15.0/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/klauspost/compress v1.15.5 h1:qyCLMz2JCrKADihKOh9FxnW3houKeNsp2h5OEz0QSEA=
@@ -196,11 +184,6 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLA
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
-github.com/otiai10/copy v1.7.0/go.mod h1:rmRl6QPdJj6EiUqXQ/4Nn2lLXoNQjFCQbbNrxgc/t3U=
-github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
-github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs=
-github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo=
-github.com/otiai10/mint v1.3.3/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc=
github.com/palantir/stacktrace v0.0.0-20161112013806-78658fd2d177 h1:nRlQD0u1871kaznCnn1EvYiMbum36v7hw1DLPEjds4o=
github.com/palantir/stacktrace v0.0.0-20161112013806-78658fd2d177/go.mod h1:ao5zGxj8Z4x60IOVYZUbDSmt3R8Ddo080vEgPosHpak=
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
@@ -216,17 +199,13 @@ github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OK
github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc=
github.com/rs/zerolog v1.26.1 h1:/ihwxqH+4z8UxyI70wM1z9yCvkWcfz/a3mj48k/Zngc=
github.com/rs/zerolog v1.26.1/go.mod h1:/wSSJWX7lVrsOwlbyTRSOJvqRlc+WjWlfes+CiJ+tmc=
-github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
-github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
-github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
-github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
@@ -238,17 +217,12 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
-github.com/swaggo/files v0.0.0-20210815190702-a29dd2bc99b2 h1:+iNTcqQJy0OZ5jk6a5NLib47eqXK8uYcPX+O4+cBpEM=
-github.com/swaggo/files v0.0.0-20210815190702-a29dd2bc99b2/go.mod h1:lKJPbtWzJ9JhsTN1k1gZgleJWY/cqq0psdoMmaThG3w=
-github.com/swaggo/swag v1.8.1/go.mod h1:ugemnJsPZm/kRwFUnzBlbHRd0JY9zE1M4F+uy2pAaPQ=
github.com/swaggo/swag v1.8.2 h1:D4aBiVS2a65zhyk3WFqOUz7Rz0sOaUcgeErcid5uGL4=
github.com/swaggo/swag v1.8.2/go.mod h1:jMLeXOOmYyjk8PvHTsXBdrubsNd9gUJTTCzL5iBnseg=
github.com/thedevsaddam/govalidator v1.9.10 h1:m3dLRbSZ5Hts3VUWYe+vxLMG+FdyQuWOjzTeQRiMCvU=
github.com/thedevsaddam/govalidator v1.9.10/go.mod h1:Ilx8u7cg5g3LXbSS943cx5kczyNuUn7LH/cK5MYuE90=
-github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
-github.com/valyala/fasthttp v1.35.0/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I=
github.com/valyala/fasthttp v1.37.0 h1:7WHCyI7EAkQMVmrfBhWTCOaeROb1aCBiTopx63LkMbE=
github.com/valyala/fasthttp v1.37.0/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I=
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
@@ -300,7 +274,6 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
-golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM=
golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
@@ -321,7 +294,6 @@ golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@@ -344,7 +316,6 @@ golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac h1:7zkz7BUtwNFFqcowJ+RIgu2M
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
-golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20190823170909-c4a336ef6a2f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
@@ -370,7 +341,6 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
-gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
diff --git a/api/main.go b/api/main.go
index 71a5b8ea..36a6fc3c 100644
--- a/api/main.go
+++ b/api/main.go
@@ -1,11 +1,10 @@
package main
import (
+ "os"
+
_ "github.com/NdoleStudio/http-sms-manager/docs"
"github.com/NdoleStudio/http-sms-manager/pkg/di"
- "github.com/gofiber/fiber/v2"
- "github.com/gofiber/fiber/v2/middleware/logger"
- "github.com/gofiber/swagger"
)
// @title HTTP SMS API
@@ -21,19 +20,10 @@ import (
// @host api.httpsms.com
// @BasePath /v1
func main() {
- di.LoadEnv()
-
- app := fiber.New()
-
- app.Use(logger.New())
+ if len(os.Args) == 1 {
+ di.LoadEnv()
+ }
container := di.NewContainer("http-sms")
-
- apiV1 := app.Group("v1")
- apiV1.Post("/messages/send", container.MessageHandler().PostSend)
- apiV1.Get("/messages/outstanding", container.MessageHandler().GetOutstanding)
-
- app.Get("/*", swagger.HandlerDefault)
-
- container.Logger().Info(app.Listen(":8000").Error())
+ container.Logger().Info(container.App().Listen(":8000").Error())
}
diff --git a/api/pkg/di/container.go b/api/pkg/di/container.go
index a2669596..1a671799 100644
--- a/api/pkg/di/container.go
+++ b/api/pkg/di/container.go
@@ -9,6 +9,7 @@ import (
"github.com/NdoleStudio/http-sms-manager/pkg/entities"
"github.com/NdoleStudio/http-sms-manager/pkg/listeners"
"github.com/NdoleStudio/http-sms-manager/pkg/repositories"
+ fiberLogger "github.com/gofiber/fiber/v2/middleware/logger"
"github.com/palantir/stacktrace"
"gorm.io/driver/postgres"
@@ -27,6 +28,7 @@ import (
type Container struct {
projectID string
db *gorm.DB
+ app *fiber.App
eventDispatcher *services.EventDispatcher
logger telemetry.Logger
}
@@ -37,10 +39,31 @@ func NewContainer(projectID string) (container *Container) {
projectID: projectID,
logger: logger().WithService(fmt.Sprintf("%T", container)),
}
- container.RegisterMessageListener()
+
+ container.RegisterMessageListeners()
+ container.RegisterMessageRoutes()
+
return container
}
+// App creates a new instance of fiber.App
+func (container *Container) App() (app *fiber.App) {
+ if container.app != nil {
+ return container.app
+ }
+
+ container.logger.Debug(fmt.Sprintf("creating %T", app))
+
+ app = fiber.New()
+
+ if os.Getenv("APP_HTTP_LOGGER") == "true" {
+ app.Use(fiberLogger.New())
+ }
+
+ container.app = app
+ return app
+}
+
// Logger creates a new instance of telemetry.Logger
func (container *Container) Logger() telemetry.Logger {
container.logger.Debug("creating telemetry.Logger")
@@ -171,8 +194,8 @@ func (container *Container) MessageHandler() (handler *handlers.MessageHandler)
)
}
-// RegisterMessageListener creates a new instance of listeners.MessageListener
-func (container *Container) RegisterMessageListener() (listener *listeners.MessageListener) {
+// RegisterMessageListeners creates a new instance of listeners.MessageListener
+func (container *Container) RegisterMessageListeners() (listener *listeners.MessageListener) {
container.logger.Debug(fmt.Sprintf("registering %T", listener))
listener, routes := listeners.NewMessageListener(
container.Logger(),
@@ -188,6 +211,12 @@ func (container *Container) RegisterMessageListener() (listener *listeners.Messa
return listener
}
+// RegisterMessageRoutes creates a new instance of handler.MessageHandler
+func (container *Container) RegisterMessageRoutes() {
+ container.logger.Debug(fmt.Sprintf("registering %T routes", &handlers.MessageHandler{}))
+ container.MessageHandler().RegisterRoutes(container.App().Group("v1"))
+}
+
func logger() telemetry.Logger {
hostname, _ := os.Hostname()
fields := fiber.Map{
diff --git a/api/pkg/entities/message.go b/api/pkg/entities/message.go
index 0e540ab1..85d7412a 100644
--- a/api/pkg/entities/message.go
+++ b/api/pkg/entities/message.go
@@ -40,24 +40,23 @@ const (
// Message represents a message sent between 2 phone numbers
type Message struct {
ID uuid.UUID `json:"id" gorm:"primaryKey;type:uuid;"`
- From string `json:"from"`
- To string `json:"to"`
- Content string `json:"content"`
- Type MessageType `json:"type"`
- Status MessageStatus `json:"status"`
+ From string `json:"from" gorm:"index:idx__messages__from__to" example:"+18005550199"`
+ To string `json:"to" gorm:"index:idx__messages__from__to" example:"+18005550100"`
+ Content string `json:"content" example:"This is a sample text message"`
+ Type MessageType `json:"type" example:"mobile-terminated"`
+ Status MessageStatus `json:"status" gorm:"index:idx__messages__status" example:"pending"`
// SendDuration is the number of nanoseconds from when the request was received until when the mobile phone send the message
- SendDuration *int64 `json:"send_time"`
-
- RequestReceivedAt time.Time `json:"request_received_at"`
- CreatedAt time.Time `json:"created_at"`
- UpdatedAt time.Time `json:"updated_at"`
- OrderTimestamp time.Time `json:"order_timestamp"`
- LastAttemptedAt *time.Time `json:"last_attempted_at"`
- SentAt *time.Time `json:"sent_at"`
- ReceivedAt *time.Time `json:"received_at"`
-
- FailureReason *string `json:"failure_reason"`
+ SendDuration *int64 `json:"send_time" example:"2022-06-05T14:26:01.520828+03:00"`
+
+ RequestReceivedAt time.Time `json:"request_received_at" example:"2022-06-05T14:26:01.520828+03:00"`
+ CreatedAt time.Time `json:"created_at" example:"2022-06-05T14:26:02.302718+03:00"`
+ UpdatedAt time.Time `json:"updated_at" example:"2022-06-05T14:26:10.303278+03:00"`
+ OrderTimestamp time.Time `json:"order_timestamp" gorm:"index:idx__messages__order_timestamp" example:"2022-06-05T14:26:09.527976+03:00"`
+ LastAttemptedAt *time.Time `json:"last_attempted_at" example:"2022-06-05T14:26:09.527976+03:00"`
+ SentAt *time.Time `json:"sent_at" example:"2022-06-05T14:26:09.527976+03:00"`
+ ReceivedAt *time.Time `json:"received_at" example:"2022-06-05T14:26:09.527976+03:00"`
+ FailureReason *string `json:"failure_reason"`
}
// IsSending determines if a message is being sent
diff --git a/api/pkg/handlers/message_handler.go b/api/pkg/handlers/message_handler.go
index 415cd5d2..acf5086f 100644
--- a/api/pkg/handlers/message_handler.go
+++ b/api/pkg/handlers/message_handler.go
@@ -36,6 +36,13 @@ func NewMessageHandler(
}
}
+// RegisterRoutes registers the routes for the MessageHandler
+func (h *MessageHandler) RegisterRoutes(router fiber.Router) {
+ router.Post("/messages/send", h.PostSend)
+ router.Get("/messages/outstanding", h.GetOutstanding)
+ router.Get("/messages", h.Index)
+}
+
// PostSend a new entities.Message
// @Summary Send a new SMS message
// @Description Add a new SMS message to be sent by the android phone
@@ -83,7 +90,7 @@ func (h *MessageHandler) PostSend(c *fiber.Ctx) error {
// @Tags Messages
// @Accept json
// @Produce json
-// @Param take query int false "number of outstanding messages to return" minimum(1) maximum(10)
+// @Param limit query int false "number of outstanding messages to return" minimum(1) maximum(10)
// @Success 200 {object} responses.MessagesResponse
// @Success 400 {object} responses.BadRequest
// @Success 422 {object} responses.UnprocessableEntity
@@ -115,5 +122,50 @@ func (h *MessageHandler) GetOutstanding(c *fiber.Ctx) error {
return h.responseInternalServerError(c)
}
- return h.responseOK(c, fmt.Sprintf("fetch %d %s", len(*messages), h.pluralize("message", len(*messages))), messages)
+ return h.responseOK(c, fmt.Sprintf("fetched %d %s", len(*messages), h.pluralize("message", len(*messages))), messages)
+}
+
+// Index returns messages sent between 2 phone numbers
+// @Summary Get messages which are sent between 2 phone numbers
+// @Description Get list of messages which are sent between 2 phone numbers. It will be sorted by timestamp in descending order.
+// @Tags Messages
+// @Accept json
+// @Produce json
+// @Param from query string true "from phone number" example(+18005550199)
+// @Param to query string true "to phone number" example(+18005550100)
+// @Param skip query int false "number of messages to skip" minimum(0)
+// @Param query query string true "filter messages containing query"
+// @Param limit query int false "number of messages to return" minimum(1) maximum(20)
+// @Success 200 {object} responses.MessagesResponse
+// @Success 400 {object} responses.BadRequest
+// @Success 422 {object} responses.UnprocessableEntity
+// @Success 500 {object} responses.InternalServerError
+// @Router /messages [get]
+func (h *MessageHandler) Index(c *fiber.Ctx) error {
+ ctx, span := h.tracer.StartFromFiberCtx(c)
+ defer span.End()
+
+ ctxLogger := h.tracer.CtxLogger(h.logger, span)
+
+ var request requests.MessageIndex
+ if err := c.QueryParser(&request); err != nil {
+ msg := fmt.Sprintf("cannot marshall params [%s] into %T", c.OriginalURL(), request)
+ ctxLogger.Warn(stacktrace.Propagate(err, msg))
+ return h.responseBadRequest(c, err)
+ }
+
+ if errors := h.validator.ValidateMessageIndex(ctx, request.Sanitize()); len(errors) != 0 {
+ msg := fmt.Sprintf("validation errors [%s], while fetching messages [%+#v]", spew.Sdump(errors), request)
+ ctxLogger.Warn(stacktrace.NewError(msg))
+ return h.responseUnprocessableEntity(c, errors, "validation errors while fetching messages")
+ }
+
+ messages, err := h.service.GetMessages(ctx, request.ToGetParams())
+ if err != nil {
+ msg := fmt.Sprintf("cannot get messgaes with params [%+#v]", request)
+ ctxLogger.Error(stacktrace.Propagate(err, msg))
+ return h.responseInternalServerError(c)
+ }
+
+ return h.responseOK(c, fmt.Sprintf("fetched %d %s", len(*messages), h.pluralize("message", len(*messages))), messages)
}
diff --git a/api/pkg/repositories/gorm_message_repository.go b/api/pkg/repositories/gorm_message_repository.go
index 24a0987f..0a4a5958 100644
--- a/api/pkg/repositories/gorm_message_repository.go
+++ b/api/pkg/repositories/gorm_message_repository.go
@@ -34,6 +34,25 @@ func NewGormMessageRepository(
}
}
+// Index entities.Message between 2 parties
+func (repository *gormMessageRepository) Index(ctx context.Context, from string, to string, params IndexParams) (*[]entities.Message, error) {
+ ctx, span := repository.tracer.Start(ctx)
+ defer span.End()
+
+ query := repository.db.Where("\"from\" = ?", from).Where("\"to\" = ?", to)
+ if len(params.Query) > 0 {
+ query = query.Where("content ILIKE ?", params.Query)
+ }
+
+ messages := new([]entities.Message)
+ if err := query.Order("order_timestamp DESC").Limit(params.Limit).Offset(params.Skip).Find(&messages).Error; err != nil {
+ msg := fmt.Sprintf("cannot fetch messges from [%s] to [%s] and params [%+#v]", from, to, params)
+ return nil, repository.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
+ }
+
+ return messages, nil
+}
+
// Store a new entities.Message
func (repository *gormMessageRepository) Store(ctx context.Context, message *entities.Message) error {
ctx, span := repository.tracer.Start(ctx)
diff --git a/api/pkg/repositories/message_repository.go b/api/pkg/repositories/message_repository.go
index e73da5b6..cc196616 100644
--- a/api/pkg/repositories/message_repository.go
+++ b/api/pkg/repositories/message_repository.go
@@ -18,6 +18,9 @@ type MessageRepository interface {
// Load an entities.Message by ID
Load(ctx context.Context, messageID uuid.UUID) (*entities.Message, error)
+ // Index entities.Message between 2 phone numbers
+ Index(ctx context.Context, from string, to string, params IndexParams) (*[]entities.Message, error)
+
// GetOutstanding fetches list of outstanding []entities.Message
- GetOutstanding(ctx context.Context, take int) (*[]entities.Message, error)
+ GetOutstanding(ctx context.Context, limit int) (*[]entities.Message, error)
}
diff --git a/api/pkg/repositories/repository.go b/api/pkg/repositories/repository.go
new file mode 100644
index 00000000..41b7753e
--- /dev/null
+++ b/api/pkg/repositories/repository.go
@@ -0,0 +1,8 @@
+package repositories
+
+// IndexParams parameters for indexing a database table
+type IndexParams struct {
+ Skip int `json:"skip"`
+ Query string `json:"query"`
+ Limit int `json:"take"`
+}
diff --git a/api/pkg/requests/message_index_request.go b/api/pkg/requests/message_index_request.go
new file mode 100644
index 00000000..724b4737
--- /dev/null
+++ b/api/pkg/requests/message_index_request.go
@@ -0,0 +1,66 @@
+package requests
+
+import (
+ "strconv"
+ "strings"
+
+ "github.com/NdoleStudio/http-sms-manager/pkg/repositories"
+
+ "github.com/NdoleStudio/http-sms-manager/pkg/services"
+)
+
+// MessageIndex is the payload fetching entities.Message sent between 2 numbers
+type MessageIndex struct {
+ Skip string `json:"skip" query:"skip"`
+ To string `json:"to" query:"to"`
+ From string `json:"from" query:"from"`
+ Query string `json:"query" query:"query"`
+ Limit string `json:"limit" query:"limit"`
+}
+
+// Sanitize sets defaults to MessageOutstanding
+func (input *MessageIndex) Sanitize() MessageIndex {
+ if strings.TrimSpace(input.Limit) == "" {
+ input.Limit = "20"
+ }
+
+ input.Query = strings.TrimSpace(input.Query)
+
+ input.From = input.sanitizeAddress(input.From)
+ input.To = input.sanitizeAddress(input.To)
+
+ input.Skip = strings.TrimSpace(input.Skip)
+ if input.Skip == "" {
+ input.Skip = "0"
+ }
+
+ return *input
+}
+
+// ToGetParams converts request to services.MessageGetParams
+func (input *MessageIndex) ToGetParams() services.MessageGetParams {
+ return services.MessageGetParams{
+ IndexParams: repositories.IndexParams{
+ Skip: input.getInt(input.Skip),
+ Query: input.Query,
+ Limit: input.getInt(input.Limit),
+ },
+ From: input.From,
+ To: input.To,
+ }
+}
+
+// getLimit gets the take as a string
+func (input *MessageIndex) sanitizeAddress(value string) string {
+ value = strings.TrimRight(value, " ")
+ if len(value) > 0 && value[0] == ' ' {
+ value = strings.Replace(value, " ", "+", 1)
+ }
+ return value
+}
+
+// getLimit gets the take as a string
+func (input *MessageIndex) getInt(value string) int {
+ val, _ := strconv.Atoi(value)
+ return val
+}
diff --git a/api/pkg/requests/message_outstanding_request.go b/api/pkg/requests/message_outstanding_request.go
index 98e49063..73bc177f 100644
--- a/api/pkg/requests/message_outstanding_request.go
+++ b/api/pkg/requests/message_outstanding_request.go
@@ -9,13 +9,13 @@ import (
// MessageOutstanding is the payload fetching outstanding entities.Message
type MessageOutstanding struct {
- Take string `json:"take" query:"take"`
+ Limit string `json:"limit" query:"limit"`
}
// Sanitize sets defaults to MessageOutstanding
func (input *MessageOutstanding) Sanitize() MessageOutstanding {
- if strings.TrimSpace(input.Take) == "" {
- input.Take = "1"
+ if strings.TrimSpace(input.Limit) == "" {
+ input.Limit = "1"
}
return *input
}
@@ -24,12 +24,12 @@ func (input *MessageOutstanding) Sanitize() MessageOutstanding {
func (input *MessageOutstanding) ToGetOutstandingParams(source string) services.MessageGetOutstandingParams {
return services.MessageGetOutstandingParams{
Source: source,
- Take: input.getTake(),
+ Limit: input.getLimit(),
}
}
-// getTake gets the take as a string
-func (input *MessageOutstanding) getTake() int {
- val, _ := strconv.Atoi(input.Take)
+// getLimit gets the take as a string
+func (input *MessageOutstanding) getLimit() int {
+ val, _ := strconv.Atoi(input.Limit)
return val
}
diff --git a/api/pkg/services/message_service.go b/api/pkg/services/message_service.go
index bf4e473f..3e267336 100644
--- a/api/pkg/services/message_service.go
+++ b/api/pkg/services/message_service.go
@@ -42,7 +42,7 @@ func NewMessageService(
// MessageGetOutstandingParams parameters for sending a new message
type MessageGetOutstandingParams struct {
Source string
- Take int
+ Limit int
}
// GetOutstanding fetches messages that still to be sent to the phone
@@ -52,9 +52,9 @@ func (service *MessageService) GetOutstanding(ctx context.Context, params Messag
ctxLogger := service.tracer.CtxLogger(service.logger, span)
- messages, err := service.repository.GetOutstanding(ctx, params.Take)
+ messages, err := service.repository.GetOutstanding(ctx, params.Limit)
if err != nil {
- msg := fmt.Sprintf("could not fetch [%d] outstanding messages", params.Take)
+ msg := fmt.Sprintf("could not fetch [%d] outstanding messages", params.Limit)
return nil, service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
}
@@ -62,6 +62,30 @@ func (service *MessageService) GetOutstanding(ctx context.Context, params Messag
return service.handleOutstandingMessages(ctx, params.Source, messages), nil
}
+// MessageGetParams parameters for sending a new message
+type MessageGetParams struct {
+ repositories.IndexParams
+ From string
+ To string
+}
+
+// GetMessages fetches sent between 2 phone numbers
+func (service *MessageService) GetMessages(ctx context.Context, params MessageGetParams) (*[]entities.Message, error) {
+ ctx, span := service.tracer.Start(ctx)
+ defer span.End()
+
+ ctxLogger := service.tracer.CtxLogger(service.logger, span)
+
+ messages, err := service.repository.Index(ctx, params.From, params.To, params.IndexParams)
+ if err != nil {
+ msg := fmt.Sprintf("could not fetch messages with parms [%+#v]", params)
+ return nil, service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
+ }
+
+ ctxLogger.Info(fmt.Sprintf("fetched [%d] messages with prams [%+#v]", len(*messages), params))
+ return messages, nil
+}
+
func (service *MessageService) handleOutstandingMessages(ctx context.Context, source string, messages *[]entities.Message) *[]entities.Message {
ctx, span := service.tracer.Start(ctx)
defer span.End()
diff --git a/api/pkg/validators/message_handler_validator.go b/api/pkg/validators/message_handler_validator.go
index 7846d280..fce9e1c1 100644
--- a/api/pkg/validators/message_handler_validator.go
+++ b/api/pkg/validators/message_handler_validator.go
@@ -10,6 +10,10 @@ import (
"github.com/thedevsaddam/govalidator"
)
+const (
+ phoneNumberRule = "regex:^\\+[1-9]\\d{1,14}$"
+)
+
// MessageHandlerValidator validates models used in handlers.MessageHandler
type MessageHandlerValidator struct {
logger telemetry.Logger
@@ -34,11 +38,11 @@ func (validator MessageHandlerValidator) ValidateMessageSend(_ context.Context,
Rules: govalidator.MapData{
"to": []string{
"required",
- "regex:^\\+[1-9]\\d{10,14}$",
+ phoneNumberRule,
},
"from": []string{
"required",
- "regex:^\\+[1-9]\\d{1,14}$",
+ phoneNumberRule,
},
"content": []string{
"required",
@@ -64,12 +68,46 @@ func (validator MessageHandlerValidator) ValidateMessageOutstanding(_ context.Co
v := govalidator.New(govalidator.Options{
Data: &request,
Rules: govalidator.MapData{
- "take": []string{
+ "limit": []string{
+ "required",
+ "numeric",
+ "min:1",
+ "max:20",
+ },
+ },
+ })
+ return v.ValidateStruct()
+}
+
+// ValidateMessageIndex validates the requests.MessageIndex request
+func (validator MessageHandlerValidator) ValidateMessageIndex(_ context.Context, request requests.MessageIndex) url.Values {
+ v := govalidator.New(govalidator.Options{
+ Data: &request,
+ Rules: govalidator.MapData{
+ "limit": []string{
"required",
"numeric",
"min:1",
"max:20",
},
+ "skip": []string{
+ "required",
+ "numeric",
+ "min:0",
+ },
+ "from": []string{
+ "required",
+ "min:1",
+ },
+ "to": []string{
+ "required",
+ phoneNumberRule,
+ },
+ },
+ Messages: map[string][]string{
+ "to": {
+ "regex:The 'to' field must be a valid E.164 phone number: https://en.wikipedia.org/wiki/E.164",
+ },
},
})
return v.ValidateStruct()