11 Commits
Author SHA1 Message Date
phoenix 6396bc861b Update dependencies (#5)
sender Build / Check (push) Successful in 1m27s
sender Build / Rustfmt (push) Successful in 36s
sender Build / Test Suite (push) Successful in 1m15s
sender Build / Clippy (push) Successful in 42s
sender Build / build (push) Successful in 1m40s
sender Build / Check (pull_request) Successful in 1m3s
sender Build / Rustfmt (pull_request) Successful in 54s
sender Build / Test Suite (pull_request) Successful in 1m43s
sender Build / Clippy (pull_request) Successful in 1m37s
sender Build / build (pull_request) Successful in 3m11s
Reviewed-on: #5
2026-06-07 16:02:46 -04:00
phoenix 2ba8d1fd86 Merge pull request 'v0.1.0' (#1) from v0.1.x into main
Reviewed-on: #1
2026-06-06 17:52:42 -04:00
phoenix c32090881d Migrate (#4)
sender Build / Check (push) Successful in 27s
sender Build / Test Suite (push) Successful in 32s
sender Build / Rustfmt (push) Successful in 36s
sender Build / Clippy (push) Failing after 37s
sender Build / build (push) Successful in 35s
Reviewed-on: #4
2026-06-06 17:47:45 -04:00
phoenix b45cd58f6b Init (#3)
sender Build / Check (push) Successful in 40s
sender Build / Rustfmt (push) Successful in 27s
sender Build / Clippy (push) Successful in 32s
sender Build / build (push) Successful in 29s
sender Build / Test Suite (push) Successful in 1m55s
Reviewed-on: #3
2026-06-06 14:43:55 -04:00
phoenix c7484ea885 Clear out (#2)
Reviewed-on: #2
2026-06-06 14:26:17 -04:00
phoenixandphoenix 85059d3c23 update go (#18)
Go / build (pull_request) Failing after 6s
Reviewed-on: #18
Co-authored-by: phoenix <mail@kundeng.us>
Co-committed-by: phoenix <mail@kundeng.us>
2026-05-03 16:58:06 -04:00
phoenixandphoenix 6e7b2cdee8 Update go (#17)
Reviewed-on: #17
Co-authored-by: phoenix <mail@kundeng.us>
Co-committed-by: phoenix <mail@kundeng.us>
2026-04-04 21:54:30 -04:00
phoenixandphoenix 2a519e2883 Update packages (#16)
Reviewed-on: #16
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-12-26 22:08:10 +00:00
phoenixandphoenix 2041e3e20b tsk-14: Update go (#15)
Closes #14

Reviewed-on: #15
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-11-24 20:21:39 +00:00
phoenixandphoenix 83fb0aa49e Changed format (#13)
Reviewed-on: #13
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-11-16 01:22:14 +00:00
phoenixandphoenix a1c197cb06 experiment (#12)
Reviewed-on: #12
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-11-14 22:09:08 +00:00
25 changed files with 3169 additions and 501 deletions
+4
View File
@@ -0,0 +1,4 @@
AUTH_SID=n9c43yr3f2c4743f7y4329dnq238f7
AUTH_TOKEN=9nmc4820qf4cor838r4fy3o84rfy348fyr
PHONE_NUMBER="+1234567890"
SERVICE_SID=n9f4dw4y327453947dhny23q7hy4379y5
-41
View File
@@ -1,41 +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: make build
- name: Test
run: go test -v ./...
- name: Run gofmt (optional)
# Uncomment to check code formatting with gofmt
run: |
if [ -n "$(gofmt -l.)" ]; then
echo "Go code is not formatted. Please run 'gofmt -w.' to fix it."
exit 1
fi
- name: Run golint (optional)
# Uncomment to check code style with golint
run: |
if [ -n "$(golint./...)" ]; then
echo "Go code has style issues. Please run 'golint./...' to see them."
exit 1
fi
+113
View File
@@ -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
View File
@@ -1,5 +1,2 @@
/sender .env
/messages target/
/numbers
/config.json
/vendor
-36
View File
@@ -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
View File
File diff suppressed because it is too large Load Diff
+15
View File
@@ -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" }
-21
View File
@@ -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)'"
-12
View File
@@ -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
```
-6
View File
@@ -1,6 +0,0 @@
{
"auth_sid": "somethingspecial243324",
"service_sid": "FEWJ93982N3FD9JV3F8",
"auth_token": "sdfdsmfoi3299823je98d29jd",
"phone_number": "+10123456789"
}
-47
View File
@@ -1,47 +0,0 @@
package config
import (
"encoding/json"
"flag"
"fmt"
"os"
"git.kundeng.us/phoenix/sender/models"
)
const (
App_Name = "sender"
)
func IsVersionFlagPresent() bool {
versionFlag := flag.Bool("version", false, "Print version information")
flag.Parse()
if *versionFlag {
return true
} else {
return true
}
}
func ParseConfig(filepath string) (config models.TwiloDetails, 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
}
-11
View File
@@ -1,11 +0,0 @@
module git.kundeng.us/phoenix/sender
go 1.25.3
require github.com/twilio/twilio-go v1.26.3
require (
github.com/golang-jwt/jwt/v5 v5.2.2 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
)
-51
View File
@@ -1,51 +0,0 @@
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 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8=
github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
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/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.26.3 h1:K2mYBzbhPVyWF+Jq5Sw53edBFvkgWo4sKTvgaO7461I=
github.com/twilio/twilio-go v1.26.3/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=
-60
View File
@@ -1,60 +0,0 @@
package main
import (
"fmt"
"os"
"git.kundeng.us/phoenix/sender/config"
"git.kundeng.us/phoenix/sender/messaging"
"git.kundeng.us/phoenix/sender/models"
"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)
cfg, _ := config.ParseConfig(configPath)
cfg.PrintConfig()
fmt.Println("Numbers file path:", numberPath)
numbers := util.ParseNumbers(numberPath)
if len(numbers) == 0 {
fmt.Println("No numbers to send")
os.Exit(-1)
}
models.PrintNumbers(numbers)
fmt.Println("")
fmt.Println("Message path:", messagePath)
message := util.ParseMessage(messagePath)
if message.IsEmpty() {
fmt.Println("No message to send")
os.Exit(-1)
}
message.Print()
messaging.SendMessages(cfg, numbers, message, 5)
}
-62
View File
@@ -1,62 +0,0 @@
package messaging
import (
"encoding/json"
"fmt"
"time"
"github.com/twilio/twilio-go"
twilioApi "github.com/twilio/twilio-go/rest/api/v2010"
"git.kundeng.us/phoenix/sender/models"
)
func SendMessages(config models.TwiloDetails, numbers [](models.Number), message models.Message, secondInterval int) {
fmt.Println("Sending message")
longSleepLimit := 5
count := 0
client := initClient(config)
for _, number := range numbers {
numberToSend := number
if numberToSend.IsEmpty() {
fmt.Println("Empty number")
continue
}
fmt.Println(numberToSend)
params := &twilioApi.CreateMessageParams{}
params.SetTo(numberToSend.PhoneNumber)
params.SetFrom(config.Number)
params.SetBody(message.Text)
fmt.Println("Sending to: " + numberToSend.PhoneNumber)
resp, err := client.Api.CreateMessage(params)
if err != nil {
fmt.Println("Error sending SMS message: " + err.Error())
} else {
response, _ := json.Marshal(*resp)
fmt.Println("Response: " + string(response))
}
if count%longSleepLimit == 0 {
// sleep for X seconds
tme := 5 * time.Second
time.Sleep(tme)
} else {
time.Sleep(time.Second)
}
}
}
func initClient(config models.TwiloDetails) *twilio.RestClient {
return twilio.NewRestClientWithParams(twilio.ClientParams{
Username: config.AccountSID,
Password: config.AuthToken,
})
}
-65
View File
@@ -1,65 +0,0 @@
package models
import (
"fmt"
)
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)
}
type TwiloDetails struct {
AccountSID string `json:"auth_sid"`
ServiceSID string `json:"service_sid"`
URI string `json:"uri"`
AuthToken string `json:"auth_token"`
Number string `json:"phone_number"`
}
func (config TwiloDetails) PrintConfig() {
fmt.Printf("Account SID: %s\n", config.AccountSID)
fmt.Printf("Service SID: %s\n", config.ServiceSID)
fmt.Println("URI:", config.URI)
fmt.Printf("Auth Token: %s\n", config.AuthToken)
fmt.Printf("Number: %s\n", config.Number)
}
func Init() TwiloDetails {
return TwiloDetails{
"",
"",
"",
"",
"",
}
}
+1 -1
View File
@@ -19,6 +19,6 @@ send_message="True"
echo "Changing directory to $root_dir" echo "Changing directory to $root_dir"
cd $root_dir cd $root_dir
./twilio_sender "$config_path" "$numbers_path" "$messages_path" ./sender "$config_path" "$numbers_path" "$messages_path"
echo "Done" echo "Done"
+68
View File
@@ -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
View File
@@ -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:?}");
}
};
}
+96
View File
@@ -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:?}");
}
};
}
}
+20
View File
@@ -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
}
+3
View File
@@ -0,0 +1,3 @@
{
"content": "What is life?"
}
+5
View File
@@ -0,0 +1,5 @@
[
{
"phone_number": "+10123456789"
}
]
-66
View File
@@ -1,66 +0,0 @@
package util
import "encoding/json"
import "fmt"
import "os"
import "strings"
import (
"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
}
-17
View File
@@ -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,
)
}