Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff79d38305 | ||
|
|
a42b5aa460 | ||
|
|
ea31581464 | ||
|
|
c62fddf44e | ||
|
|
b5a01cbdc2 | ||
|
|
416ff1ef89 | ||
|
|
6396bc861b | ||
|
|
2ba8d1fd86 | ||
|
|
c32090881d | ||
|
|
b45cd58f6b | ||
|
|
c7484ea885 | ||
|
|
85059d3c23 | ||
|
|
6e7b2cdee8 | ||
|
|
2a519e2883 | ||
|
|
2041e3e20b | ||
|
|
83fb0aa49e | ||
|
|
a1c197cb06 |
@@ -0,0 +1,4 @@
|
||||
AUTH_SID=n9c43yr3f2c4743f7y4329dnq238f7
|
||||
AUTH_TOKEN=9nmc4820qf4cor838r4fy3o84rfy348fyr
|
||||
PHONE_NUMBER="+1234567890"
|
||||
SERVICE_SID=n9f4dw4y327453947dhny23q7hy4379y5
|
||||
@@ -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
|
||||
@@ -0,0 +1,65 @@
|
||||
name: sender pr
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
check:
|
||||
name: Check
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: 1.97
|
||||
- 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
|
||||
|
||||
fmt:
|
||||
name: Rustfmt
|
||||
runs-on: ubuntu-24.04
|
||||
needs: setup_ssh
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: 1.97
|
||||
- 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@v6
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: 1.97
|
||||
- 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
|
||||
@@ -0,0 +1,110 @@
|
||||
name: sender Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
check:
|
||||
name: Check
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: 1.97
|
||||
- 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@v6
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: 1.97
|
||||
- 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@v6
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: 1.97
|
||||
- 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@v6
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: 1.97
|
||||
- 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@v6
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
toolchain: 1.97
|
||||
- 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
|
||||
/messages
|
||||
/numbers
|
||||
/config.json
|
||||
/vendor
|
||||
.env
|
||||
target/
|
||||
|
||||
@@ -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
+2836
File diff suppressed because it is too large
Load Diff
+15
@@ -0,0 +1,15 @@
|
||||
[package]
|
||||
name = "sender"
|
||||
version = "0.1.6"
|
||||
edition = "2024"
|
||||
license = "MIT"
|
||||
description = "CLI tool to send text messages"
|
||||
rust-version = "1.97"
|
||||
|
||||
[dependencies]
|
||||
serde_json = { version = "1.0.150" }
|
||||
tokio = { version = "1.52.3", features = ["full"] }
|
||||
schedtxt_models = { git = "ssh://git@git.kundeng.us/phoenix/schedtxt_models.git", tag = "v0.5.3", features = ["config", "contact", "envy", "message"] }
|
||||
swoosh = { git = "ssh://git@git.kundeng.us/phoenix/swoosh.git", tag = "v0.5.3" }
|
||||
|
||||
[dev-dependencies]
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
Copyright (c) 2026 Kun Deng.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -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 +1,2 @@
|
||||
# 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
|
||||
```
|
||||
A CLI tool that can send text messages.
|
||||
|
||||
@@ -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/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
|
||||
}
|
||||
@@ -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
|
||||
)
|
||||
@@ -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=
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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,
|
||||
})
|
||||
}
|
||||
@@ -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
@@ -19,6 +19,6 @@ send_message="True"
|
||||
echo "Changing directory to $root_dir"
|
||||
cd $root_dir
|
||||
|
||||
./twilio_sender "$config_path" "$numbers_path" "$messages_path"
|
||||
./sender "$config_path" "$numbers_path" "$messages_path"
|
||||
|
||||
echo "Done"
|
||||
|
||||
@@ -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 fn parse_config() -> (schedtxt_models::config::auxiliary::TwilioConfig, bool) {
|
||||
let mut config = schedtxt_models::config::auxiliary::TwilioConfig {
|
||||
..Default::default()
|
||||
};
|
||||
let auth_sid_var = schedtxt_models::envy::environment::get_env("AUTH_SID");
|
||||
let auth_token_var = schedtxt_models::envy::environment::get_env("AUTH_TOKEN");
|
||||
let phone_number_var = schedtxt_models::envy::environment::get_env("PHONE_NUMBER");
|
||||
let service_sid_var = schedtxt_models::envy::environment::get_env("SERVICE_SID");
|
||||
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) = 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();
|
||||
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,105 @@
|
||||
use schedtxt_models::config::auxiliary::TwilioConfig;
|
||||
use schedtxt_models::contact::Contact;
|
||||
use schedtxt_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,
|
||||
};
|
||||
let mut sendmsg = swoosh::SendMsg::default();
|
||||
sendmsg.load_config(
|
||||
&config.auth_token,
|
||||
&config.phone_number,
|
||||
&config.service_sid,
|
||||
&config.account_sid,
|
||||
);
|
||||
sendmsg.load_recipient(&contact.phone_number);
|
||||
sendmsg.load_message(&message.content);
|
||||
match sendmsg.send_message(¶m).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,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
|
||||
}
|
||||
@@ -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