Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a1c197cb06 |
+21
-17
@@ -19,23 +19,27 @@ jobs:
|
|||||||
go-version: '1.25.3' # You can specify a specific version or 'stable'
|
go-version: '1.25.3' # You can specify a specific version or 'stable'
|
||||||
|
|
||||||
- name: Build
|
- 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
|
- name: Test
|
||||||
run: go test -v ./...
|
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
@@ -6,7 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"git.kundeng.us/phoenix/sender/models"
|
"git.kundeng.us/phoenix/textsender-models/pkg/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -20,11 +20,11 @@ func IsVersionFlagPresent() bool {
|
|||||||
if *versionFlag {
|
if *versionFlag {
|
||||||
return true
|
return true
|
||||||
} else {
|
} 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)
|
content, err := os.ReadFile(filepath)
|
||||||
|
|
||||||
fmt.Println("Reading config file...")
|
fmt.Println("Reading config file...")
|
||||||
|
|||||||
@@ -2,10 +2,15 @@ module git.kundeng.us/phoenix/sender
|
|||||||
|
|
||||||
go 1.25.3
|
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 (
|
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/golang/mock v1.6.0 // indirect
|
||||||
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
|
github.com/twilio/twilio-go v1.28.6 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -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/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A=
|
||||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
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.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8=
|
|
||||||
github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
|
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 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||||
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
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.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
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/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/twilio/twilio-go v1.26.3 h1:K2mYBzbhPVyWF+Jq5Sw53edBFvkgWo4sKTvgaO7461I=
|
github.com/twilio/twilio-go v1.28.6 h1:L/pikXkARmPOzF/gUMeZPP/Lu5mY/wA4XC7sRzS86W4=
|
||||||
github.com/twilio/twilio-go v1.26.3/go.mod h1:FpgNWMoD8CFnmukpKq9RNpUSGXC0BwnbeKZj2YHlIkw=
|
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=
|
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
|
|||||||
@@ -4,9 +4,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/pkg/contact"
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/pkg/message"
|
||||||
|
|
||||||
"git.kundeng.us/phoenix/sender/config"
|
"git.kundeng.us/phoenix/sender/config"
|
||||||
"git.kundeng.us/phoenix/sender/messaging"
|
"git.kundeng.us/phoenix/sender/messaging"
|
||||||
"git.kundeng.us/phoenix/sender/models"
|
|
||||||
"git.kundeng.us/phoenix/sender/util"
|
"git.kundeng.us/phoenix/sender/util"
|
||||||
"git.kundeng.us/phoenix/sender/version"
|
"git.kundeng.us/phoenix/sender/version"
|
||||||
)
|
)
|
||||||
@@ -28,33 +30,47 @@ func main() {
|
|||||||
configPath, numberPath, messagePath := util.GetPaths(myArgs)
|
configPath, numberPath, messagePath := util.GetPaths(myArgs)
|
||||||
|
|
||||||
fmt.Printf("Config file path: %s\n", configPath)
|
fmt.Printf("Config file path: %s\n", configPath)
|
||||||
|
fmt.Println("Numbers file path:", numberPath)
|
||||||
|
fmt.Println("Message path:", messagePath)
|
||||||
|
|
||||||
cfg, _ := config.ParseConfig(configPath)
|
cfg, _ := config.ParseConfig(configPath)
|
||||||
|
|
||||||
cfg.PrintConfig()
|
cfg.PrintConfig()
|
||||||
|
|
||||||
fmt.Println("Numbers file path:", numberPath)
|
|
||||||
|
|
||||||
numbers := util.ParseNumbers(numberPath)
|
numbers := util.ParseNumbers(numberPath)
|
||||||
|
prepMessage := util.ParseMessage(messagePath)
|
||||||
|
|
||||||
|
if len(numbers) == 0 || prepMessage.IsEmpty() {
|
||||||
if len(numbers) == 0 {
|
if len(numbers) == 0 {
|
||||||
fmt.Println("No numbers to send")
|
fmt.Println("No numbers to send")
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
} else {
|
||||||
|
|
||||||
models.PrintNumbers(numbers)
|
|
||||||
fmt.Println("")
|
|
||||||
|
|
||||||
fmt.Println("Message path:", messagePath)
|
|
||||||
|
|
||||||
message := util.ParseMessage(messagePath)
|
|
||||||
|
|
||||||
if message.IsEmpty() {
|
|
||||||
fmt.Println("No message to send")
|
fmt.Println("No message to send")
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
message.Print()
|
|
||||||
|
fmt.Println("")
|
||||||
messaging.SendMessages(cfg, numbers, message, 5)
|
prepMessage.Print()
|
||||||
|
|
||||||
|
convertedContacts, err := util.Convert(numbers, 1)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error converting numbers: Error:", err)
|
||||||
|
os.Exit(-1)
|
||||||
|
}
|
||||||
|
|
||||||
|
convertedMessage, err := util.Convert(prepMessage, 0)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error converting message")
|
||||||
|
os.Exit(-1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if contacts, ok := convertedContacts.([]contact.Contact); ok {
|
||||||
|
if msg, ok := convertedMessage.(message.Message); ok {
|
||||||
|
messaging.SendMessages(cfg, contacts, msg, 5)
|
||||||
|
} else {
|
||||||
|
fmt.Println("Could not convert message")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Println("Could not convert numbers")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-32
@@ -5,58 +5,41 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/twilio/twilio-go"
|
"git.kundeng.us/phoenix/swoosh/swoop/send"
|
||||||
twilioApi "github.com/twilio/twilio-go/rest/api/v2010"
|
cnfg "git.kundeng.us/phoenix/textsender-models/pkg/config"
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/pkg/contact"
|
||||||
"git.kundeng.us/phoenix/sender/models"
|
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")
|
fmt.Println("Sending message")
|
||||||
|
|
||||||
longSleepLimit := 5
|
longSleepLimit := 5
|
||||||
count := 0
|
count := 0
|
||||||
|
|
||||||
client := initClient(config)
|
var snr send.MessageSender
|
||||||
|
snr.Config = config
|
||||||
|
|
||||||
for _, number := range numbers {
|
for _, number := range numbers {
|
||||||
numberToSend := number
|
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)
|
fmt.Println("Sending to: " + numberToSend.PhoneNumber)
|
||||||
|
|
||||||
resp, err := client.Api.CreateMessage(params)
|
if resp, err := snr.Send(message, number, nil); err != nil {
|
||||||
if err != nil {
|
fmt.Println("Error sending:", err)
|
||||||
fmt.Println("Error sending SMS message: " + err.Error())
|
|
||||||
} else {
|
} else {
|
||||||
response, _ := json.Marshal(*resp)
|
if response, err := json.Marshal(*resp); err != nil {
|
||||||
fmt.Println("Response: " + string(response))
|
fmt.Println("Error parsing:", err)
|
||||||
|
} else {
|
||||||
|
fmt.Println("Response:", string(response))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if count%longSleepLimit == 0 {
|
if count%longSleepLimit == 0 {
|
||||||
// sleep for X seconds
|
// sleep for X seconds
|
||||||
tme := 5 * time.Second
|
tme := 1 * time.Second
|
||||||
time.Sleep(tme)
|
time.Sleep(tme)
|
||||||
} else {
|
} else {
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func initClient(config models.TwiloDetails) *twilio.RestClient {
|
|
||||||
return twilio.NewRestClientWithParams(twilio.ClientParams{
|
|
||||||
Username: config.AccountSID,
|
|
||||||
Password: config.AuthToken,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package models
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
cnfg "git.kundeng.us/phoenix/textsender-models/pkg/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Number struct {
|
type Number struct {
|
||||||
@@ -38,28 +40,6 @@ func (msg Message) Print() {
|
|||||||
fmt.Println("Message:", msg.Text)
|
fmt.Println("Message:", msg.Text)
|
||||||
}
|
}
|
||||||
|
|
||||||
type TwiloDetails struct {
|
func Init() cnfg.TwiloConfig {
|
||||||
AccountSID string `json:"auth_sid"`
|
return cnfg.TwiloConfig{}
|
||||||
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"
|
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"
|
||||||
|
|||||||
+44
-5
@@ -1,11 +1,14 @@
|
|||||||
package util
|
package util
|
||||||
|
|
||||||
import "encoding/json"
|
|
||||||
import "fmt"
|
|
||||||
import "os"
|
|
||||||
import "strings"
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/pkg/contact"
|
||||||
|
"git.kundeng.us/phoenix/textsender-models/pkg/message"
|
||||||
|
|
||||||
"git.kundeng.us/phoenix/sender/models"
|
"git.kundeng.us/phoenix/sender/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -64,3 +67,39 @@ func ParseMessage(filepath string) (message models.Message) {
|
|||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Convert(data interface{}, msgOrNumber int) (interface{}, error) {
|
||||||
|
switch msgOrNumber {
|
||||||
|
case 0:
|
||||||
|
{
|
||||||
|
if msg, ok := data.(models.Message); ok {
|
||||||
|
return message.Message{Content: msg.Text}, nil
|
||||||
|
} else {
|
||||||
|
return nil, fmt.Errorf("Could not resolve value")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
var items []contact.Contact
|
||||||
|
|
||||||
|
switch nbrs := data.(type) {
|
||||||
|
case []models.Number:
|
||||||
|
for _, number := range nbrs {
|
||||||
|
if !number.IsEmpty() {
|
||||||
|
items = append(items, contact.Contact{PhoneNumber: number.PhoneNumber})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("Unrecognized type")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(items) == 0 {
|
||||||
|
return nil, fmt.Errorf("Failure converting")
|
||||||
|
} else {
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("Invalid msgOrNumber")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user