Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
85059d3c23 | ||
|
|
6e7b2cdee8 | ||
|
|
2a519e2883 | ||
|
|
2041e3e20b | ||
|
|
83fb0aa49e |
@@ -14,9 +14,9 @@ jobs:
|
|||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v5
|
||||||
|
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v4
|
uses: actions/setup-go@v6
|
||||||
with:
|
with:
|
||||||
go-version: '1.25.3' # You can specify a specific version or 'stable'
|
go-version: '1.26.2' # You can specify a specific version or 'stable'
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: |
|
run: |
|
||||||
@@ -24,7 +24,7 @@ jobs:
|
|||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender_models_deploy_key
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender_models_deploy_key
|
||||||
chmod 600 ~/.ssh/textsender_models_deploy_key
|
chmod 600 ~/.ssh/textsender_models_deploy_key
|
||||||
ssh-keyscan ${{ vars.MY_HOST }} >> ~/.ssh/known_hosts
|
ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
eval $(ssh-agent -s)
|
eval $(ssh-agent -s)
|
||||||
ssh-add -v ~/.ssh/textsender_models_deploy_key
|
ssh-add -v ~/.ssh/textsender_models_deploy_key
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
# This file is a template, and might need editing before it works on your project.
|
|
||||||
# You can copy and paste this template into a new `.gitlab-ci.yml` file.
|
|
||||||
# You should not add this template to an existing `.gitlab-ci.yml` file by using the `include:` keyword.
|
|
||||||
#
|
|
||||||
# To contribute improvements to CI/CD templates, please follow the Development guide at:
|
|
||||||
# https://docs.gitlab.com/ee/development/cicd/templates.html
|
|
||||||
# This specific template is located at:
|
|
||||||
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Go.gitlab-ci.yml
|
|
||||||
|
|
||||||
image: golang:1.25.3
|
|
||||||
|
|
||||||
stages:
|
|
||||||
- test
|
|
||||||
- build
|
|
||||||
# - deploy
|
|
||||||
|
|
||||||
format:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- go fmt $(go list ./... | grep -v /vendor/)
|
|
||||||
- go vet $(go list ./... | grep -v /vendor/)
|
|
||||||
- go test -race $(go list ./... | grep -v /vendor/)
|
|
||||||
|
|
||||||
compile:
|
|
||||||
stage: build
|
|
||||||
script:
|
|
||||||
- make build
|
|
||||||
|
|
||||||
artifacts:
|
|
||||||
paths:
|
|
||||||
- mybinaries
|
|
||||||
|
|
||||||
# deploy:
|
|
||||||
# stage: deploy
|
|
||||||
# script: echo "Define your deployment script!"
|
|
||||||
# environment: production
|
|
||||||
@@ -6,16 +6,16 @@ GO_VERSION ?= $(shell go version | awk '{print $$3}')
|
|||||||
.PHONY: build
|
.PHONY: build
|
||||||
build:
|
build:
|
||||||
go build -ldflags="\
|
go build -ldflags="\
|
||||||
-X 'git.kundeng.us/phoenix/sender/version.Version=$(VERSION)' \
|
-X 'git.kundeng.us/phoenix/sender/internal/version.Version=$(VERSION)' \
|
||||||
-X 'git.kundeng.us/phoenix/sender/version.BuildTime=$(BUILD_TIME)' \
|
-X 'git.kundeng.us/phoenix/sender/internal/version.BuildTime=$(BUILD_TIME)' \
|
||||||
-X 'git.kundeng.us/phoenix/sender/version.Commit=$(COMMIT)' \
|
-X 'git.kundeng.us/phoenix/sender/internal/version.Commit=$(COMMIT)' \
|
||||||
-X 'git.kundeng.us/phoenix/sender/version.GoVersion=$(GO_VERSION)'" \
|
-X 'git.kundeng.us/phoenix/sender/internal/version.GoVersion=$(GO_VERSION)'" \
|
||||||
-o sender main.go
|
-o sender cmd/sender/main.go
|
||||||
|
|
||||||
.PHONY: install
|
.PHONY: install
|
||||||
install:
|
install:
|
||||||
go install -ldflags="\
|
go install -ldflags="\
|
||||||
-X 'git.kundeng.us/phoenix/sender/version.Version=$(VERSION)' \
|
-X 'git.kundeng.us/phoenix/sender/internal/version.Version=$(VERSION)' \
|
||||||
-X 'git.kundeng.us/phoenix/sender/version.BuildTime=$(BUILD_TIME)' \
|
-X 'git.kundeng.us/phoenix/sender/internal/version.BuildTime=$(BUILD_TIME)' \
|
||||||
-X 'git.kundeng.us/phoenix/sender/version.Commit=$(COMMIT)' \
|
-X 'git.kundeng.us/phoenix/sender/internal/version.Commit=$(COMMIT)' \
|
||||||
-X 'git.kundeng.us/phoenix/sender/version.GoVersion=$(GO_VERSION)'"
|
-X 'git.kundeng.us/phoenix/sender/internal/version.GoVersion=$(GO_VERSION)'"
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/sender/internal/config"
|
||||||
|
"git.kundeng.us/phoenix/sender/internal/messaging"
|
||||||
|
"git.kundeng.us/phoenix/sender/internal/util"
|
||||||
|
"git.kundeng.us/phoenix/sender/internal/version"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
myArgs := os.Args
|
||||||
|
argCount := len(myArgs)
|
||||||
|
|
||||||
|
if config.IsVersionFlagPresent() {
|
||||||
|
fmt.Println(config.App_Name)
|
||||||
|
fmt.Println(version.String())
|
||||||
|
return
|
||||||
|
} else if argCount < 4 {
|
||||||
|
log.Printf("Argument count: %v\n", argCount)
|
||||||
|
log.Fatal("Provide argument to config file and number file")
|
||||||
|
}
|
||||||
|
|
||||||
|
configPath, numberPath, messagePath := util.GetPaths(myArgs)
|
||||||
|
|
||||||
|
log.Printf("Config file path: %s\n", configPath)
|
||||||
|
log.Println("Numbers file path:", numberPath)
|
||||||
|
log.Println("Message path:", messagePath)
|
||||||
|
|
||||||
|
cfg, _ := config.ParseConfig(configPath)
|
||||||
|
cfg.PrintConfig()
|
||||||
|
|
||||||
|
numbers, err := util.ParseNumbers(numberPath)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Error:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
prepMessage, err := util.ParseMessage(messagePath)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Error:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(numbers) == 0 || prepMessage.Content == "" {
|
||||||
|
if len(numbers) == 0 {
|
||||||
|
log.Println("No numbers to send")
|
||||||
|
os.Exit(-1)
|
||||||
|
} else {
|
||||||
|
log.Println("No message to send")
|
||||||
|
os.Exit(-1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("")
|
||||||
|
log.Println("Message:", prepMessage.Content)
|
||||||
|
|
||||||
|
messaging.SendMessages(cfg, numbers, *prepMessage, 5)
|
||||||
|
}
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
module git.kundeng.us/phoenix/sender
|
module git.kundeng.us/phoenix/sender
|
||||||
|
|
||||||
go 1.25.3
|
go 1.26.2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.kundeng.us/phoenix/swoosh v0.0.1-main-3a21426ae1-556
|
git.kundeng.us/phoenix/swoosh v0.2.1
|
||||||
git.kundeng.us/phoenix/textsender-models v0.0.7-5-9bc1743bd9-556
|
git.kundeng.us/phoenix/textsender-models v0.2.1
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/golang-jwt/jwt/v5 v5.3.0 // indirect
|
github.com/golang-jwt/jwt/v5 v5.3.1 // indirect
|
||||||
github.com/golang/mock v1.6.0 // indirect
|
github.com/golang/mock v1.6.0 // indirect
|
||||||
github.com/google/uuid v1.6.0 // indirect
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
github.com/twilio/twilio-go v1.28.6 // indirect
|
github.com/twilio/twilio-go v1.30.5 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,34 +1,25 @@
|
|||||||
git.kundeng.us/phoenix/swoosh v0.0.1-main-3a21426ae1-556 h1:HkaufrT0yaZA0VYS/eItPb0MAErCfnzsIqFlZKaQPtw=
|
git.kundeng.us/phoenix/swoosh v0.2.1 h1:mJ/zXBOqzi0YTrSm5kxvahzp2WH7lx4R3iIO0s9VFFI=
|
||||||
git.kundeng.us/phoenix/swoosh v0.0.1-main-3a21426ae1-556/go.mod h1:P47q3zXiy5FVKrm6liOk9/gdn/bsJoAu27gnKiAaZos=
|
git.kundeng.us/phoenix/swoosh v0.2.1/go.mod h1:81XNzmTmDPuDPmXMUmKTLErNSKKBM+hsW5U60Lm78ww=
|
||||||
git.kundeng.us/phoenix/textsender-models v0.0.7-5-9bc1743bd9-556 h1:/tIswN4wEFioG++uo25iBY1jPNdHjhH07l8Vh4qUDQo=
|
git.kundeng.us/phoenix/textsender-models v0.2.1 h1:21br4NF58aUFuCx8laKxC5RvZMl4GsSIaMX4bvf5plw=
|
||||||
git.kundeng.us/phoenix/textsender-models v0.0.7-5-9bc1743bd9-556/go.mod h1:lx5MCnOgGgsdpwzrfi9uph5xmkeb6H8AuexUNGss2no=
|
git.kundeng.us/phoenix/textsender-models v0.2.1/go.mod h1:nu5QWy9o+spx/t9NFipaGmF5qiBJS/0QhxyCjoi3Z3E=
|
||||||
github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A=
|
|
||||||
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=
|
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
|
github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY=
|
||||||
github.com/golang-jwt/jwt/v5 v5.3.0 h1:pv4AsKCKKZuqlgs5sUmn4x8UlGa0kEVt/puTpKx9vvo=
|
github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
|
||||||
github.com/golang-jwt/jwt/v5 v5.3.0/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
|
|
||||||
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
|
||||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
|
||||||
github.com/localtunnel/go-localtunnel v0.0.0-20170326223115-8a804488f275 h1:IZycmTpoUtQK3PD60UYBwjaCUHUP7cML494ao9/O8+Q=
|
github.com/localtunnel/go-localtunnel v0.0.0-20170326223115-8a804488f275 h1:IZycmTpoUtQK3PD60UYBwjaCUHUP7cML494ao9/O8+Q=
|
||||||
github.com/localtunnel/go-localtunnel v0.0.0-20170326223115-8a804488f275/go.mod h1:zt6UU74K6Z6oMOYJbJzYpYucqdcQwSMPBEdSvGiaUMw=
|
github.com/localtunnel/go-localtunnel v0.0.0-20170326223115-8a804488f275/go.mod h1:zt6UU74K6Z6oMOYJbJzYpYucqdcQwSMPBEdSvGiaUMw=
|
||||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
|
||||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
|
||||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/twilio/twilio-go v1.28.6 h1:L/pikXkARmPOzF/gUMeZPP/Lu5mY/wA4XC7sRzS86W4=
|
github.com/twilio/twilio-go v1.30.5 h1:hi6+2kMte29zrFBsw7VSSNtbF30GPMGz/4LRIUgXng8=
|
||||||
github.com/twilio/twilio-go v1.28.6/go.mod h1:FpgNWMoD8CFnmukpKq9RNpUSGXC0BwnbeKZj2YHlIkw=
|
github.com/twilio/twilio-go v1.30.5/go.mod h1:QbitvbvtkV77Jn4BABAKVmxabYSjMyQG4tHey9gfPqg=
|
||||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
@@ -52,7 +43,5 @@ golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
|||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ package config
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"git.kundeng.us/phoenix/textsender-models/pkg/config"
|
axlry "git.kundeng.us/phoenix/textsender-models/tx0/config/auxiliary"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -24,22 +24,21 @@ func IsVersionFlagPresent() bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseConfig(filepath string) (config config.TwiloConfig, success bool) {
|
func ParseConfig(filepath string) (config axlry.TwilioConfig, success bool) {
|
||||||
content, err := os.ReadFile(filepath)
|
content, err := os.ReadFile(filepath)
|
||||||
|
|
||||||
fmt.Println("Reading config file...")
|
log.Println("Reading config file...")
|
||||||
fmt.Printf("%s\n", filepath)
|
log.Println(filepath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("An error reading the file")
|
log.Println("An error reading the file")
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(content, &config)
|
err = json.Unmarshal(content, &config)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("An error occurred")
|
log.Println("An error occurred")
|
||||||
return config, false
|
return config, false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package messaging
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"log"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/swoosh/swoop/send"
|
||||||
|
cnfg "git.kundeng.us/phoenix/textsender-models/tx0/config/auxiliary"
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/tx0/contact"
|
||||||
|
msg "git.kundeng.us/phoenix/textsender-models/tx0/message"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SendMessages(config cnfg.TwilioConfig, numbers [](contact.Contact), message msg.Message, secondInterval int) {
|
||||||
|
log.Println("Sending message")
|
||||||
|
|
||||||
|
longSleepLimit := 5
|
||||||
|
count := 0
|
||||||
|
|
||||||
|
var snr send.MessageSender
|
||||||
|
snr.Config = &config
|
||||||
|
|
||||||
|
for _, number := range numbers {
|
||||||
|
numberToSend := number
|
||||||
|
log.Println("Sending to: " + numberToSend.PhoneNumber)
|
||||||
|
|
||||||
|
if resp, _, err := snr.Send(message, number, nil); err != nil {
|
||||||
|
log.Println("Error sending:", err)
|
||||||
|
} else {
|
||||||
|
if response, err := json.Marshal(*resp); err != nil {
|
||||||
|
log.Println("Error parsing:", err)
|
||||||
|
} else {
|
||||||
|
log.Println("Response:", string(response))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("Sleeping")
|
||||||
|
if count%longSleepLimit == 0 {
|
||||||
|
// sleep for X seconds
|
||||||
|
tme := 1 * time.Second
|
||||||
|
time.Sleep(tme)
|
||||||
|
} else {
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/tx0/contact"
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/tx0/message"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetPaths(args []string) (configPath string, numberPath string, messagePath string) {
|
||||||
|
configPath = args[1]
|
||||||
|
numberPath = args[2]
|
||||||
|
messagePath = args[3]
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParseNumbers(filepath string) (numbers [](contact.Contact), err error) {
|
||||||
|
var nmbrs []contact.Contact
|
||||||
|
|
||||||
|
content, err := os.ReadFile(filepath)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Println("An error occurred")
|
||||||
|
return numbers, err
|
||||||
|
} else {
|
||||||
|
if err = json.Unmarshal(content, &nmbrs); err != nil {
|
||||||
|
log.Println("An error occurred:", err)
|
||||||
|
return numbers, err
|
||||||
|
} else {
|
||||||
|
return nmbrs, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParseMessage(filepath string) (*message.Message, error) {
|
||||||
|
var msg message.Message
|
||||||
|
|
||||||
|
content, err := os.ReadFile(filepath)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Println("An error occurred")
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(content, &msg)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Println("An error occurred")
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &msg, nil
|
||||||
|
}
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"git.kundeng.us/phoenix/textsender-models/pkg/contact"
|
|
||||||
"git.kundeng.us/phoenix/textsender-models/pkg/message"
|
|
||||||
|
|
||||||
"git.kundeng.us/phoenix/sender/config"
|
|
||||||
"git.kundeng.us/phoenix/sender/messaging"
|
|
||||||
"git.kundeng.us/phoenix/sender/util"
|
|
||||||
"git.kundeng.us/phoenix/sender/version"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
myArgs := os.Args
|
|
||||||
argCount := len(myArgs)
|
|
||||||
|
|
||||||
if config.IsVersionFlagPresent() {
|
|
||||||
fmt.Println(config.App_Name)
|
|
||||||
fmt.Println(version.String())
|
|
||||||
return
|
|
||||||
} else if argCount < 4 {
|
|
||||||
fmt.Printf("Argument count: %v\n", argCount)
|
|
||||||
fmt.Println("Provide argument to config file and number file")
|
|
||||||
os.Exit(-1)
|
|
||||||
}
|
|
||||||
|
|
||||||
configPath, numberPath, messagePath := util.GetPaths(myArgs)
|
|
||||||
|
|
||||||
fmt.Printf("Config file path: %s\n", configPath)
|
|
||||||
fmt.Println("Numbers file path:", numberPath)
|
|
||||||
fmt.Println("Message path:", messagePath)
|
|
||||||
|
|
||||||
cfg, _ := config.ParseConfig(configPath)
|
|
||||||
cfg.PrintConfig()
|
|
||||||
|
|
||||||
numbers := util.ParseNumbers(numberPath)
|
|
||||||
prepMessage := util.ParseMessage(messagePath)
|
|
||||||
|
|
||||||
if len(numbers) == 0 || prepMessage.IsEmpty() {
|
|
||||||
if len(numbers) == 0 {
|
|
||||||
fmt.Println("No numbers to send")
|
|
||||||
os.Exit(-1)
|
|
||||||
} else {
|
|
||||||
fmt.Println("No message to send")
|
|
||||||
os.Exit(-1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("")
|
|
||||||
prepMessage.Print()
|
|
||||||
|
|
||||||
convertedContacts, err := util.Convert(numbers, 1)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Error converting numbers: Error:", err)
|
|
||||||
os.Exit(-1)
|
|
||||||
}
|
|
||||||
|
|
||||||
convertedMessage, err := util.Convert(prepMessage, 0)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Error converting message")
|
|
||||||
os.Exit(-1)
|
|
||||||
}
|
|
||||||
|
|
||||||
if contacts, ok := convertedContacts.([]contact.Contact); ok {
|
|
||||||
if msg, ok := convertedMessage.(message.Message); ok {
|
|
||||||
messaging.SendMessages(cfg, contacts, msg, 5)
|
|
||||||
} else {
|
|
||||||
fmt.Println("Could not convert message")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fmt.Println("Could not convert numbers")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
package messaging
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"git.kundeng.us/phoenix/swoosh/swoop/send"
|
|
||||||
cnfg "git.kundeng.us/phoenix/textsender-models/pkg/config"
|
|
||||||
"git.kundeng.us/phoenix/textsender-models/pkg/contact"
|
|
||||||
msg "git.kundeng.us/phoenix/textsender-models/pkg/message"
|
|
||||||
)
|
|
||||||
|
|
||||||
func SendMessages(config cnfg.TwiloConfig, numbers [](contact.Contact), message msg.Message, secondInterval int) {
|
|
||||||
fmt.Println("Sending message")
|
|
||||||
|
|
||||||
longSleepLimit := 5
|
|
||||||
count := 0
|
|
||||||
|
|
||||||
var snr send.MessageSender
|
|
||||||
snr.Config = config
|
|
||||||
|
|
||||||
for _, number := range numbers {
|
|
||||||
numberToSend := number
|
|
||||||
fmt.Println("Sending to: " + numberToSend.PhoneNumber)
|
|
||||||
|
|
||||||
if resp, err := snr.Send(message, number, nil); err != nil {
|
|
||||||
fmt.Println("Error sending:", err)
|
|
||||||
} else {
|
|
||||||
if response, err := json.Marshal(*resp); err != nil {
|
|
||||||
fmt.Println("Error parsing:", err)
|
|
||||||
} else {
|
|
||||||
fmt.Println("Response:", string(response))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if count%longSleepLimit == 0 {
|
|
||||||
// sleep for X seconds
|
|
||||||
tme := 1 * time.Second
|
|
||||||
time.Sleep(tme)
|
|
||||||
} else {
|
|
||||||
time.Sleep(time.Second)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
package models
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
cnfg "git.kundeng.us/phoenix/textsender-models/pkg/config"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Number struct {
|
|
||||||
PhoneNumber string `json:"number"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (nbr Number) IsEmpty() bool {
|
|
||||||
if nbr.PhoneNumber == "" {
|
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func PrintNumbers(numbers [](Number)) {
|
|
||||||
for _, element := range numbers {
|
|
||||||
fmt.Println("Phone number:", element.PhoneNumber)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type Message struct {
|
|
||||||
Text string `json:"text"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (msg Message) IsEmpty() bool {
|
|
||||||
if msg.Text == "" {
|
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (msg Message) Print() {
|
|
||||||
fmt.Println("Message:", msg.Text)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Init() cnfg.TwiloConfig {
|
|
||||||
return cnfg.TwiloConfig{}
|
|
||||||
}
|
|
||||||
-105
@@ -1,105 +0,0 @@
|
|||||||
package util
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"git.kundeng.us/phoenix/textsender-models/pkg/contact"
|
|
||||||
"git.kundeng.us/phoenix/textsender-models/pkg/message"
|
|
||||||
|
|
||||||
"git.kundeng.us/phoenix/sender/models"
|
|
||||||
)
|
|
||||||
|
|
||||||
func GetPaths(args []string) (configPath string, numberPath string, messagePath string) {
|
|
||||||
configPath = args[1]
|
|
||||||
numberPath = args[2]
|
|
||||||
messagePath = args[3]
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func ParseNumbers(filepath string) (numbers [](models.Number)) {
|
|
||||||
nmbrs := [](string){}
|
|
||||||
|
|
||||||
content, err := os.ReadFile(filepath)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("An error occurred")
|
|
||||||
return numbers
|
|
||||||
}
|
|
||||||
|
|
||||||
err = json.Unmarshal(content, &nmbrs)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("An error occurred")
|
|
||||||
return numbers
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, nbr := range nmbrs {
|
|
||||||
var number models.Number
|
|
||||||
number.PhoneNumber = nbr
|
|
||||||
numbers = append(numbers, number)
|
|
||||||
}
|
|
||||||
|
|
||||||
return numbers
|
|
||||||
}
|
|
||||||
|
|
||||||
func ParseMessage(filepath string) (message models.Message) {
|
|
||||||
msg := [](string){""}
|
|
||||||
|
|
||||||
content, err := os.ReadFile(filepath)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("An error occurred")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = json.Unmarshal(content, &msg)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("An error occurred")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
message.Text = strings.Join(msg, "")
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func Convert(data interface{}, msgOrNumber int) (interface{}, error) {
|
|
||||||
switch msgOrNumber {
|
|
||||||
case 0:
|
|
||||||
{
|
|
||||||
if msg, ok := data.(models.Message); ok {
|
|
||||||
return message.Message{Content: msg.Text}, nil
|
|
||||||
} else {
|
|
||||||
return nil, fmt.Errorf("Could not resolve value")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
var items []contact.Contact
|
|
||||||
|
|
||||||
switch nbrs := data.(type) {
|
|
||||||
case []models.Number:
|
|
||||||
for _, number := range nbrs {
|
|
||||||
if !number.IsEmpty() {
|
|
||||||
items = append(items, contact.Contact{PhoneNumber: number.PhoneNumber})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return nil, fmt.Errorf("Unrecognized type")
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(items) == 0 {
|
|
||||||
return nil, fmt.Errorf("Failure converting")
|
|
||||||
} else {
|
|
||||||
return items, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return nil, fmt.Errorf("Invalid msgOrNumber")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user