Compare commits

...
Author SHA1 Message Date
phoenixandphoenix 92a492cb06 textsender-models version bump (#6)
Reviewed-on: #6
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-12-01 19:04:35 +00:00
phoenixandphoenix 4bba8d6b3c Added scheduling check (#5)
Reviewed-on: #5
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-11-29 19:22:29 +00:00
phoenixandphoenix 6b2907cd69 fixes (#4)
Reviewed-on: #4
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-11-29 18:38:47 +00:00
phoenixandphoenix 9516f1a052 Refactoring (#3)
Reviewed-on: #3
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-11-27 01:59:25 +00:00
phoenixandphoenix e28e5c6755 tsk-1: Update go version (#2)
Closes #1

Reviewed-on: #2
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-11-24 20:10:10 +00:00
phoenix 3a21426ae1 Minor improvements 2025-11-14 16:47:48 -05:00
6 changed files with 47 additions and 27 deletions
+2 -2
View File
@@ -18,14 +18,14 @@ jobs:
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v6 uses: actions/setup-go@v6
with: with:
go-version: '1.25.3' go-version: '1.25.4'
- name: Create version - name: Create version
id: version id: version
run: | run: |
echo "Creating version" echo "Creating version"
VERSION="0.0.1" VERSION="0.0.6"
PROJECT_COMMIT_HASH=$(git rev-parse HEAD | cut -c 1-10) PROJECT_COMMIT_HASH=$(git rev-parse HEAD | cut -c 1-10)
BRANCH_REF="${{ gitea.ref }}" BRANCH_REF="${{ gitea.ref }}"
BRANCH_NAME=$(echo "$BRANCH_REF" | cut -d '/' -f 3) BRANCH_NAME=$(echo "$BRANCH_REF" | cut -d '/' -f 3)
+5 -5
View File
@@ -11,13 +11,13 @@ jobs:
uses: actions/checkout@v5 uses: actions/checkout@v5
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v4 uses: actions/setup-go@v6
with: with:
go-version: '1.25.3' go-version: '1.25.4'
- name: Configure Git for SSH - name: Configure Git for SSH
run: | run: |
git config --global url."git@git.kundeng.us:".insteadOf "https://git.kundeng.us/" git config --global url."git@${{ secrets.GIT_HOST_ROOT }}:".insteadOf "https://${{ secrets.GIT_HOST_ROOT }}/"
go env -w GOPRIVATE=git.kundeng.us/phoenix/* go env -w GOPRIVATE=${{ secrets.GIT_HOST_ROOT }}/phoenix/*
- name: Download dependencies - name: Download dependencies
run: | run: |
@@ -25,7 +25,7 @@ jobs:
mkdir -p ~/.ssh mkdir -p ~/.ssh
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/swoosh_deploy_key echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/swoosh_deploy_key
chmod 600 ~/.ssh/swoosh_deploy_key chmod 600 ~/.ssh/swoosh_deploy_key
ssh-keyscan ${{ vars.MY_HOST }} >> ~/.ssh/known_hosts ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts
eval $(ssh-agent -s) eval $(ssh-agent -s)
ssh-add -v ~/.ssh/swoosh_deploy_key ssh-add -v ~/.ssh/swoosh_deploy_key
+3 -3
View File
@@ -1,10 +1,10 @@
module git.kundeng.us/phoenix/swoosh module git.kundeng.us/phoenix/swoosh
go 1.25.3 go 1.25.4
require ( require (
git.kundeng.us/phoenix/textsender-models v0.0.7-5-9bc1743bd9-556 git.kundeng.us/phoenix/textsender-models v0.0.11
github.com/twilio/twilio-go v1.28.6 github.com/twilio/twilio-go v1.28.7
) )
require ( require (
+4 -4
View File
@@ -1,5 +1,5 @@
git.kundeng.us/phoenix/textsender-models v0.0.7-5-9bc1743bd9-556 h1:/tIswN4wEFioG++uo25iBY1jPNdHjhH07l8Vh4qUDQo= git.kundeng.us/phoenix/textsender-models v0.0.11 h1:kd2FdeZJhJJAXBm8MoyadtgNGyzC+puU1oR8B8N+MfE=
git.kundeng.us/phoenix/textsender-models v0.0.7-5-9bc1743bd9-556/go.mod h1:lx5MCnOgGgsdpwzrfi9uph5xmkeb6H8AuexUNGss2no= git.kundeng.us/phoenix/textsender-models v0.0.11/go.mod h1:9iPDQJg1Tc6WMNoW5+f8YKmnosMwlWHJ++hmxNLDEe0=
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=
@@ -25,8 +25,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.28.6 h1:L/pikXkARmPOzF/gUMeZPP/Lu5mY/wA4XC7sRzS86W4= github.com/twilio/twilio-go v1.28.7 h1:WzzQDR/rqmNkVs1TwtcHFPYGTdSdPnx/eAZf5UIXzr4=
github.com/twilio/twilio-go v1.28.6/go.mod h1:FpgNWMoD8CFnmukpKq9RNpUSGXC0BwnbeKZj2YHlIkw= github.com/twilio/twilio-go v1.28.7/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=
+26 -13
View File
@@ -5,21 +5,25 @@ import (
"fmt" "fmt"
"time" "time"
"git.kundeng.us/phoenix/textsender-models/pkg/config" "git.kundeng.us/phoenix/textsender-models/tx0/config"
"git.kundeng.us/phoenix/textsender-models/pkg/contact" "git.kundeng.us/phoenix/textsender-models/tx0/contact"
"git.kundeng.us/phoenix/textsender-models/pkg/message" "git.kundeng.us/phoenix/textsender-models/tx0/message"
"github.com/twilio/twilio-go" "github.com/twilio/twilio-go"
twilioApi "github.com/twilio/twilio-go/rest/api/v2010" twilioApi "github.com/twilio/twilio-go/rest/api/v2010"
"git.kundeng.us/phoenix/swoosh/swoop/types"
) )
type TwilioResult = twilioApi.ApiV2010Message const Schedule_Type = "fixed"
type MessageSender struct { type MessageSender struct {
Numbers []contact.Contact Config *config.TwiloConfig
Config config.TwiloConfig
} }
func (m *MessageSender) Send(msg message.Message, number contact.Contact, sendTime *time.Time) (*TwilioResult, error) { func (m *MessageSender) Send(msg message.Message, number contact.Contact, sendTime *time.Time) (*types.TwilioResult, error) {
if m.Config == nil {
return nil, fmt.Errorf("Config has not been initialized")
}
now := time.Now() now := time.Now()
client := twilio.NewRestClientWithParams(twilio.ClientParams{ client := twilio.NewRestClientWithParams(twilio.ClientParams{
Username: m.Config.AccountSID, Username: m.Config.AccountSID,
@@ -29,15 +33,14 @@ func (m *MessageSender) Send(msg message.Message, number contact.Contact, sendTi
params := &twilioApi.CreateMessageParams{} params := &twilioApi.CreateMessageParams{}
params.SetTo(number.PhoneNumber) params.SetTo(number.PhoneNumber)
params.SetFrom(m.Config.Number) params.SetFrom(m.Config.Number)
params.SetMessagingServiceSid(m.Config.ServiceSID)
params.SetBody(msg.Content) params.SetBody(msg.Content)
if sendTime != nil { if sendTime != nil && isSchedulable(&now, sendTime) {
if sendTime.After(now) { params.SetSendAt(*sendTime)
params.SetSendAt(*sendTime) params.SetScheduleType(Schedule_Type)
}
} }
resp, err := client.Api.CreateMessage(params) if resp, err := client.Api.CreateMessage(params); err != nil {
if err != nil {
return nil, fmt.Errorf("Error sending message: %v", err) return nil, fmt.Errorf("Error sending message: %v", err)
} else { } else {
if _, err := json.Marshal(*resp); err != nil { if _, err := json.Marshal(*resp); err != nil {
@@ -47,3 +50,13 @@ func (m *MessageSender) Send(msg message.Message, number contact.Contact, sendTi
} }
} }
} }
func isSchedulable(now *time.Time, scheduled *time.Time) bool {
early := now.Add(300 * time.Second)
if scheduled.After(early) {
return true
} else {
return false
}
}
+7
View File
@@ -0,0 +1,7 @@
package types
import (
twilioApi "github.com/twilio/twilio-go/rest/api/v2010"
)
type TwilioResult = twilioApi.ApiV2010Message