Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6396bc861b | ||
|
|
2ba8d1fd86 | ||
|
|
c32090881d | ||
|
|
b45cd58f6b | ||
|
|
c7484ea885 | ||
|
|
85059d3c23 | ||
|
|
6e7b2cdee8 | ||
|
|
2a519e2883 | ||
|
|
2041e3e20b |
@@ -0,0 +1,4 @@
|
|||||||
|
AUTH_SID=n9c43yr3f2c4743f7y4329dnq238f7
|
||||||
|
AUTH_TOKEN=9nmc4820qf4cor838r4fy3o84rfy348fyr
|
||||||
|
PHONE_NUMBER="+1234567890"
|
||||||
|
SERVICE_SID=n9f4dw4y327453947dhny23q7hy4379y5
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
name: Go
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ main, master ]
|
|
||||||
pull_request:
|
|
||||||
branches: [ main, master ]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-24.04 # You can change this to macos-latest or windows-latest if needed
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v5
|
|
||||||
|
|
||||||
- name: Set up Go
|
|
||||||
uses: actions/setup-go@v4
|
|
||||||
with:
|
|
||||||
go-version: '1.25.3' # You can specify a specific version or 'stable'
|
|
||||||
|
|
||||||
- name: Build
|
|
||||||
run: |
|
|
||||||
echo "Initializing config"
|
|
||||||
mkdir -p ~/.ssh
|
|
||||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender_models_deploy_key
|
|
||||||
chmod 600 ~/.ssh/textsender_models_deploy_key
|
|
||||||
ssh-keyscan ${{ vars.MY_HOST }} >> ~/.ssh/known_hosts
|
|
||||||
|
|
||||||
eval $(ssh-agent -s)
|
|
||||||
ssh-add -v ~/.ssh/textsender_models_deploy_key
|
|
||||||
|
|
||||||
go env -w GOPRIVATE='${{ secrets.GIT_HOST_ROOT }}'
|
|
||||||
|
|
||||||
echo "Creating local .gitconfig"
|
|
||||||
touch ~/.gitconfig
|
|
||||||
cat > ~/.gitconfig << "EOF"
|
|
||||||
[url "ssh://git@${{ secrets.GIT_HOST_ROOT }}"]
|
|
||||||
insteadOf = https://${{ secrets.GIT_HOST_ROOT }}
|
|
||||||
EOF
|
|
||||||
|
|
||||||
echo "Building binary"
|
|
||||||
make build
|
|
||||||
|
|
||||||
- name: Test
|
|
||||||
run: go test -v ./...
|
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
name: sender Build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
check:
|
||||||
|
name: Check
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: 1.95
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/deploy_key
|
||||||
|
chmod 600 ~/.ssh/deploy_key
|
||||||
|
ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add -v ~/.ssh/deploy_key
|
||||||
|
cargo check
|
||||||
|
|
||||||
|
test:
|
||||||
|
name: Test Suite
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
needs: setup_ssh
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: 1.95
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
env:
|
||||||
|
AUTH_SID: 'n9c43yr3f2c4743f7y4329dnq238f7'
|
||||||
|
AUTH_TOKEN: '9nmc4820qf4cor838r4fy3o84rfy348fyr'
|
||||||
|
PHONE_NUMBER: '+1234567890'
|
||||||
|
SERVICE_SID: 'n9f4dw4y327453947dhny23q7hy4379y5'
|
||||||
|
- run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/deploy_key
|
||||||
|
chmod 600 ~/.ssh/deploy_key
|
||||||
|
ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add -v ~/.ssh/deploy_key
|
||||||
|
|
||||||
|
cp .env.sample .env
|
||||||
|
cargo test
|
||||||
|
|
||||||
|
fmt:
|
||||||
|
name: Rustfmt
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
needs: setup_ssh
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: 1.95
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- run: rustup component add rustfmt
|
||||||
|
- run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/deploy_key
|
||||||
|
chmod 600 ~/.ssh/deploy_key
|
||||||
|
ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add -v ~/.ssh/deploy_key
|
||||||
|
cargo fmt --all -- --check
|
||||||
|
|
||||||
|
clippy:
|
||||||
|
name: Clippy
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
needs: setup_ssh
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: 1.95
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- run: rustup component add clippy
|
||||||
|
- run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/deploy_key
|
||||||
|
chmod 600 ~/.ssh/deploy_key
|
||||||
|
ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add -v ~/.ssh/deploy_key
|
||||||
|
cargo clippy -- -D warnings
|
||||||
|
|
||||||
|
build:
|
||||||
|
name: build
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
needs: setup_ssh
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: 1.95
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/deploy_key
|
||||||
|
chmod 600 ~/.ssh/deploy_key
|
||||||
|
ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add -v ~/.ssh/deploy_key
|
||||||
|
cargo build --release
|
||||||
+2
-5
@@ -1,5 +1,2 @@
|
|||||||
/sender
|
.env
|
||||||
/messages
|
target/
|
||||||
/numbers
|
|
||||||
/config.json
|
|
||||||
/vendor
|
|
||||||
|
|||||||
@@ -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
|
|
||||||
Generated
+2795
File diff suppressed because it is too large
Load Diff
+15
@@ -0,0 +1,15 @@
|
|||||||
|
[package]
|
||||||
|
name = "sender"
|
||||||
|
version = "0.1.1"
|
||||||
|
edition = "2024"
|
||||||
|
rust-version = "1.95"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
serde_json = { version = "1.0.149" }
|
||||||
|
tokio = { version = "1.52.2", features = ["full"] }
|
||||||
|
futures = { version = "0.3.32" }
|
||||||
|
textsender_models = { git = "ssh://git@git.kundeng.us/phoenix/textsender-models.git", tag = "v0.3.0" }
|
||||||
|
swoosh = { git = "ssh://git@git.kundeng.us/phoenix/swoosh.git", tag = "v0.3.2" }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
async-std = { version = "1.13.2" }
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
VERSION ?= $(shell git describe --tags 2>/dev/null || echo "dev")
|
|
||||||
COMMIT ?= $(shell git rev-parse --short HEAD)
|
|
||||||
BUILD_TIME ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
|
|
||||||
GO_VERSION ?= $(shell go version | awk '{print $$3}')
|
|
||||||
|
|
||||||
.PHONY: build
|
|
||||||
build:
|
|
||||||
go build -ldflags="\
|
|
||||||
-X 'git.kundeng.us/phoenix/sender/version.Version=$(VERSION)' \
|
|
||||||
-X 'git.kundeng.us/phoenix/sender/version.BuildTime=$(BUILD_TIME)' \
|
|
||||||
-X 'git.kundeng.us/phoenix/sender/version.Commit=$(COMMIT)' \
|
|
||||||
-X 'git.kundeng.us/phoenix/sender/version.GoVersion=$(GO_VERSION)'" \
|
|
||||||
-o sender main.go
|
|
||||||
|
|
||||||
.PHONY: install
|
|
||||||
install:
|
|
||||||
go install -ldflags="\
|
|
||||||
-X 'git.kundeng.us/phoenix/sender/version.Version=$(VERSION)' \
|
|
||||||
-X 'git.kundeng.us/phoenix/sender/version.BuildTime=$(BUILD_TIME)' \
|
|
||||||
-X 'git.kundeng.us/phoenix/sender/version.Commit=$(COMMIT)' \
|
|
||||||
-X 'git.kundeng.us/phoenix/sender/version.GoVersion=$(GO_VERSION)'"
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
# sender
|
|
||||||
sender is a cli program to send text messages.
|
|
||||||
|
|
||||||
## Install twilio
|
|
||||||
```
|
|
||||||
make build
|
|
||||||
```
|
|
||||||
|
|
||||||
## Using
|
|
||||||
```
|
|
||||||
./sender config_path.json numbers_path.json message_path.json
|
|
||||||
```
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"auth_sid": "somethingspecial243324",
|
|
||||||
"service_sid": "FEWJ93982N3FD9JV3F8",
|
|
||||||
"auth_token": "sdfdsmfoi3299823je98d29jd",
|
|
||||||
"phone_number": "+10123456789"
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
package config
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"git.kundeng.us/phoenix/textsender-models/pkg/config"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
App_Name = "sender"
|
|
||||||
)
|
|
||||||
|
|
||||||
func IsVersionFlagPresent() bool {
|
|
||||||
versionFlag := flag.Bool("version", false, "Print version information")
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
if *versionFlag {
|
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func ParseConfig(filepath string) (config config.TwiloConfig, success bool) {
|
|
||||||
content, err := os.ReadFile(filepath)
|
|
||||||
|
|
||||||
fmt.Println("Reading config file...")
|
|
||||||
fmt.Printf("%s\n", filepath)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("An error reading the file")
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = json.Unmarshal(content, &config)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("An error occurred")
|
|
||||||
return config, false
|
|
||||||
}
|
|
||||||
|
|
||||||
return config, true
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
module git.kundeng.us/phoenix/sender
|
|
||||||
|
|
||||||
go 1.25.3
|
|
||||||
|
|
||||||
require (
|
|
||||||
git.kundeng.us/phoenix/swoosh v0.0.1-main-3a21426ae1-556
|
|
||||||
git.kundeng.us/phoenix/textsender-models v0.0.7-5-9bc1743bd9-556
|
|
||||||
)
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/golang-jwt/jwt/v5 v5.3.0 // indirect
|
|
||||||
github.com/golang/mock v1.6.0 // indirect
|
|
||||||
github.com/google/uuid v1.6.0 // indirect
|
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
|
||||||
github.com/twilio/twilio-go v1.28.6 // indirect
|
|
||||||
)
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
git.kundeng.us/phoenix/swoosh v0.0.1-main-3a21426ae1-556 h1:HkaufrT0yaZA0VYS/eItPb0MAErCfnzsIqFlZKaQPtw=
|
|
||||||
git.kundeng.us/phoenix/swoosh v0.0.1-main-3a21426ae1-556/go.mod h1:P47q3zXiy5FVKrm6liOk9/gdn/bsJoAu27gnKiAaZos=
|
|
||||||
git.kundeng.us/phoenix/textsender-models v0.0.7-5-9bc1743bd9-556 h1:/tIswN4wEFioG++uo25iBY1jPNdHjhH07l8Vh4qUDQo=
|
|
||||||
git.kundeng.us/phoenix/textsender-models v0.0.7-5-9bc1743bd9-556/go.mod h1:lx5MCnOgGgsdpwzrfi9uph5xmkeb6H8AuexUNGss2no=
|
|
||||||
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/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.0 h1:pv4AsKCKKZuqlgs5sUmn4x8UlGa0kEVt/puTpKx9vvo=
|
|
||||||
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/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/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/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/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
|
||||||
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/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/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.28.6/go.mod h1:FpgNWMoD8CFnmukpKq9RNpUSGXC0BwnbeKZj2YHlIkw=
|
|
||||||
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-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
|
||||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
|
||||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
|
||||||
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-20191011141410-1b5146add898/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/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
||||||
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=
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"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, err := util.ParseNumbers(numberPath)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Error:", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
prepMessage, err := util.ParseMessage(messagePath)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Error:", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(numbers) == 0 || prepMessage.Content == "" {
|
|
||||||
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("")
|
|
||||||
fmt.Println("Message:", prepMessage.Content)
|
|
||||||
|
|
||||||
messaging.SendMessages(cfg, numbers, *prepMessage, 5)
|
|
||||||
}
|
|
||||||
@@ -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,9 +0,0 @@
|
|||||||
package models
|
|
||||||
|
|
||||||
import (
|
|
||||||
cnfg "git.kundeng.us/phoenix/textsender-models/pkg/config"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Init() cnfg.TwiloConfig {
|
|
||||||
return cnfg.TwiloConfig{}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
pub const APP_NAME: &str = "sender";
|
||||||
|
|
||||||
|
/// Returns numbers and message paths
|
||||||
|
pub fn get_paths(args: Vec<String>) -> Result<(String, String), std::io::Error> {
|
||||||
|
if args.len() < 2 {
|
||||||
|
Err(std::io::Error::other("Not enough arguments"))
|
||||||
|
} else {
|
||||||
|
let numbers_path = args[1].clone();
|
||||||
|
let message_path = args[2].clone();
|
||||||
|
if !path_exists(&numbers_path) && !path_exists(&message_path) {
|
||||||
|
Err(std::io::Error::other("Paths do not exists"))
|
||||||
|
} else {
|
||||||
|
Ok((numbers_path, message_path))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn path_exists(path: &str) -> bool {
|
||||||
|
let file = std::path::Path::new(path);
|
||||||
|
file.exists()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn parse_config() -> (textsender_models::config::auxiliary::TwilioConfig, bool) {
|
||||||
|
let mut config = textsender_models::config::auxiliary::TwilioConfig {
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
let auth_sid_var = textsender_models::envy::environment::get_env("AUTH_SID").await;
|
||||||
|
let auth_token_var = textsender_models::envy::environment::get_env("AUTH_TOKEN").await;
|
||||||
|
let phone_number_var = textsender_models::envy::environment::get_env("PHONE_NUMBER").await;
|
||||||
|
let service_sid_var = textsender_models::envy::environment::get_env("SERVICE_SID").await;
|
||||||
|
config.account_sid = auth_sid_var.value;
|
||||||
|
config.auth_token = auth_token_var.value;
|
||||||
|
config.phone_number = phone_number_var.value;
|
||||||
|
config.service_sid = service_sid_var.value;
|
||||||
|
let success = {
|
||||||
|
!config.account_sid.is_empty()
|
||||||
|
&& !config.auth_token.is_empty()
|
||||||
|
&& !config.phone_number.is_empty()
|
||||||
|
&& !config.service_sid.is_empty()
|
||||||
|
};
|
||||||
|
|
||||||
|
(config, success)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
#[test]
|
||||||
|
fn test_parse_config() {
|
||||||
|
let (config, success) = async_std::task::block_on(super::parse_config());
|
||||||
|
assert!(success, "Config was not parsed");
|
||||||
|
assert_eq!(
|
||||||
|
false,
|
||||||
|
config.account_sid.is_empty(),
|
||||||
|
"Account SID is missing"
|
||||||
|
);
|
||||||
|
assert_eq!(false, config.auth_token.is_empty(), "AUTH TOKEN is missing");
|
||||||
|
assert_eq!(
|
||||||
|
false,
|
||||||
|
config.phone_number.is_empty(),
|
||||||
|
"Phone Number is missing"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
false,
|
||||||
|
config.service_sid.is_empty(),
|
||||||
|
"Service SID is missing"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+47
@@ -0,0 +1,47 @@
|
|||||||
|
pub mod config;
|
||||||
|
pub mod messaging;
|
||||||
|
pub mod version;
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
println!("sender");
|
||||||
|
let args: Vec<String> = std::env::args().collect();
|
||||||
|
|
||||||
|
if version::contains_version(&args) {
|
||||||
|
version::print_version();
|
||||||
|
std::process::exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
match config::get_paths(args) {
|
||||||
|
Ok((n_path, m_path)) => {
|
||||||
|
println!("Message path: {m_path:?}");
|
||||||
|
println!("Phone Number path: {n_path:?}");
|
||||||
|
|
||||||
|
let (config, success) = config::parse_config().await;
|
||||||
|
if !success {
|
||||||
|
eprintln!("Error parsing config");
|
||||||
|
} else {
|
||||||
|
let contacts = match messaging::parse_numbers(&n_path) {
|
||||||
|
Ok(contacts) => contacts,
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error: {err:?}");
|
||||||
|
std::process::exit(-1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let message = match messaging::parse_message(&m_path) {
|
||||||
|
Ok(message) => message,
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error: {err:?}");
|
||||||
|
std::process::exit(-1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
println!("Message: {:?}", message.content);
|
||||||
|
messaging::send_messages(&config, &contacts, &message, 5).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error: {err:?}");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
use textsender_models::config::auxiliary::TwilioConfig;
|
||||||
|
use textsender_models::contact::Contact;
|
||||||
|
use textsender_models::message::Message;
|
||||||
|
|
||||||
|
pub async fn send_messages(
|
||||||
|
config: &TwilioConfig,
|
||||||
|
contacts: &[Contact],
|
||||||
|
message: &Message,
|
||||||
|
second_interval: u64,
|
||||||
|
) {
|
||||||
|
let long_sleep_limit: i64 = 5;
|
||||||
|
|
||||||
|
for (text_count, contact) in (0_i64..).zip(contacts.iter()) {
|
||||||
|
println!("Sending to: {:?}", contact.phone_number);
|
||||||
|
let param = swoosh::twilio::types::Parameters {
|
||||||
|
schedule: false,
|
||||||
|
schedule_at: None,
|
||||||
|
};
|
||||||
|
match swoosh::twilio::api::send_mssage(message, contact, param, config).await {
|
||||||
|
Ok(response) => {
|
||||||
|
println!("Raw response: {response:?}");
|
||||||
|
let val = swoosh::twilio::api::response_to_json(response).await;
|
||||||
|
println!("Response: {val:?}");
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error: {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if text_count % long_sleep_limit == 0 {
|
||||||
|
// Sleep for X seconds
|
||||||
|
let wait_time = second_interval;
|
||||||
|
std::thread::sleep(std::time::Duration::from_secs(wait_time));
|
||||||
|
} else {
|
||||||
|
// Sleep for a second
|
||||||
|
std::thread::sleep(std::time::Duration::from_secs(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parse_numbers(filepath: &str) -> Result<Vec<Contact>, std::io::Error> {
|
||||||
|
match std::fs::File::open(filepath) {
|
||||||
|
Ok(file) => {
|
||||||
|
let reader = std::io::BufReader::new(file);
|
||||||
|
let contacts: Vec<Contact> = match serde_json::from_reader(reader) {
|
||||||
|
Ok(va) => va,
|
||||||
|
Err(err) => {
|
||||||
|
return Err(std::io::Error::other(err.to_string()));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(contacts)
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parse_message(filepath: &str) -> Result<Message, std::io::Error> {
|
||||||
|
match std::fs::File::open(filepath) {
|
||||||
|
Ok(file) => {
|
||||||
|
let reader = std::io::BufReader::new(file);
|
||||||
|
let message: Message = serde_json::from_reader(reader)?;
|
||||||
|
Ok(message)
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
#[test]
|
||||||
|
fn test_parse_message() {
|
||||||
|
let message_path = String::from("tests/message-0.json");
|
||||||
|
match super::parse_message(&message_path) {
|
||||||
|
Ok(message) => {
|
||||||
|
assert_eq!(false, message.content.is_empty(), "Content is empty");
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {err:?}");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_parse_numbers() {
|
||||||
|
let numbers_path = String::from("tests/numbers-0.json");
|
||||||
|
match super::parse_numbers(&numbers_path) {
|
||||||
|
Ok(contacts) => {
|
||||||
|
assert_eq!(false, contacts.is_empty(), "Should not be empty");
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {err:?}");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
pub fn print_version() {
|
||||||
|
let name = env!("CARGO_PKG_NAME");
|
||||||
|
let version = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
|
println!("{name:?} {version:?}");
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn contains_version(args: &Vec<String>) -> bool {
|
||||||
|
let valid_flags = vec!["-v", "--version"];
|
||||||
|
|
||||||
|
for arg in args {
|
||||||
|
for valid_flag in &valid_flags {
|
||||||
|
if valid_flag == arg {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
false
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"content": "What is life?"
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"phone_number": "+10123456789"
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
package util
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"git.kundeng.us/phoenix/textsender-models/pkg/contact"
|
|
||||||
"git.kundeng.us/phoenix/textsender-models/pkg/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 {
|
|
||||||
fmt.Println("An error occurred")
|
|
||||||
return numbers, err
|
|
||||||
} else {
|
|
||||||
if err = json.Unmarshal(content, &nmbrs); err != nil {
|
|
||||||
fmt.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 {
|
|
||||||
fmt.Println("An error occurred")
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = json.Unmarshal(content, &msg)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("An error occurred")
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &msg, nil
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package version
|
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
var (
|
|
||||||
Version = "dev"
|
|
||||||
BuildTime = "unknown"
|
|
||||||
Commit = "unknown"
|
|
||||||
GoVersion = "unknown"
|
|
||||||
)
|
|
||||||
|
|
||||||
func String() string {
|
|
||||||
return fmt.Sprintf(
|
|
||||||
"Version: %s\nBuild Date: %s\nCommit: %s\nGo Version: %s",
|
|
||||||
Version, BuildTime, Commit, GoVersion,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user