2 Commits
Author SHA1 Message Date
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
9 changed files with 106 additions and 170 deletions
+21 -17
View File
@@ -19,23 +19,27 @@ jobs:
go-version: '1.25.3' # You can specify a specific version or 'stable'
- name: Build
run: make 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 ./...
- 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
+3 -3
View File
@@ -6,7 +6,7 @@ import (
"fmt"
"os"
"git.kundeng.us/phoenix/sender/models"
"git.kundeng.us/phoenix/textsender-models/pkg/config"
)
const (
@@ -20,11 +20,11 @@ func IsVersionFlagPresent() bool {
if *versionFlag {
return true
} else {
return true
return false
}
}
func ParseConfig(filepath string) (config models.TwiloDetails, success bool) {
func ParseConfig(filepath string) (config config.TwiloConfig, success bool) {
content, err := os.ReadFile(filepath)
fmt.Println("Reading config file...")
+7 -2
View File
@@ -2,10 +2,15 @@ module git.kundeng.us/phoenix/sender
go 1.25.3
require github.com/twilio/twilio-go v1.26.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.2.2 // indirect
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
)
+10 -3
View File
@@ -1,12 +1,19 @@
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 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8=
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=
@@ -20,8 +27,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
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/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=
+25 -23
View File
@@ -6,7 +6,6 @@ import (
"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"
)
@@ -28,33 +27,36 @@ func main() {
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)
cfg, _ := config.ParseConfig(configPath)
cfg.PrintConfig()
if message.IsEmpty() {
fmt.Println("No message to send")
os.Exit(-1)
numbers, err := util.ParseNumbers(numberPath)
if err != nil {
fmt.Println("Error:", err)
return
}
message.Print()
prepMessage, err := util.ParseMessage(messagePath)
if err != nil {
fmt.Println("Error:", err)
return
}
messaging.SendMessages(cfg, numbers, message, 5)
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)
}
+15 -32
View File
@@ -5,58 +5,41 @@ import (
"fmt"
"time"
"github.com/twilio/twilio-go"
twilioApi "github.com/twilio/twilio-go/rest/api/v2010"
"git.kundeng.us/phoenix/sender/models"
"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 models.TwiloDetails, numbers [](models.Number), message models.Message, secondInterval int) {
func SendMessages(config cnfg.TwiloConfig, numbers [](contact.Contact), message msg.Message, secondInterval int) {
fmt.Println("Sending message")
longSleepLimit := 5
count := 0
client := initClient(config)
var snr send.MessageSender
snr.Config = 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())
if resp, err := snr.Send(message, number, nil); err != nil {
fmt.Println("Error sending:", err)
} else {
response, _ := json.Marshal(*resp)
fmt.Println("Response: " + string(response))
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 := 5 * time.Second
tme := 1 * 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,
})
}
+3 -59
View File
@@ -1,65 +1,9 @@
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)
}
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{
"",
"",
"",
"",
"",
}
func Init() cnfg.TwiloConfig {
return cnfg.TwiloConfig{}
}
+1 -1
View File
@@ -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"
+21 -30
View File
@@ -1,12 +1,12 @@
package util
import "encoding/json"
import "fmt"
import "os"
import "strings"
import (
"git.kundeng.us/phoenix/sender/models"
"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) {
@@ -17,50 +17,41 @@ func GetPaths(args []string) (configPath string, numberPath string, messagePath
return
}
func ParseNumbers(filepath string) (numbers [](models.Number)) {
nmbrs := [](string){}
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
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
}
}
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){""}
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
return nil, err
}
err = json.Unmarshal(content, &msg)
if err != nil {
fmt.Println("An error occurred")
return
return nil, err
}
message.Text = strings.Join(msg, "")
return
return &msg, nil
}