Compare commits

...
Author SHA1 Message Date
phoenix e4b6b191f0 Added scheduling check 2025-11-29 13:46:14 -05: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
5 changed files with 28 additions and 15 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ jobs:
run: | run: |
echo "Creating version" echo "Creating version"
VERSION="0.0.2" VERSION="0.0.4"
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)
+3 -3
View File
@@ -16,8 +16,8 @@ jobs:
go-version: '1.25.4' 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
+1 -1
View File
@@ -3,7 +3,7 @@ module git.kundeng.us/phoenix/swoosh
go 1.25.4 go 1.25.4
require ( require (
git.kundeng.us/phoenix/textsender-models v0.0.9 git.kundeng.us/phoenix/textsender-models v0.0.10
github.com/twilio/twilio-go v1.28.6 github.com/twilio/twilio-go v1.28.6
) )
+2 -2
View File
@@ -1,5 +1,5 @@
git.kundeng.us/phoenix/textsender-models v0.0.9 h1:wHEbDLYzMpXQ8OaIf05xFY1V19iTpQogTJEuKInkjEQ= git.kundeng.us/phoenix/textsender-models v0.0.10 h1:0AMe/zm4Xte2BcuqqhRP7+42m+4To+rUnHkR2a9eXlI=
git.kundeng.us/phoenix/textsender-models v0.0.9/go.mod h1:9iPDQJg1Tc6WMNoW5+f8YKmnosMwlWHJ++hmxNLDEe0= git.kundeng.us/phoenix/textsender-models v0.0.10/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=
+20 -7
View File
@@ -5,20 +5,24 @@ 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" "git.kundeng.us/phoenix/swoosh/swoop/types"
) )
type MessageSender struct { type MessageSender struct {
Config config.TwiloConfig Config *config.TwiloConfig
} }
func (m *MessageSender) Send(msg message.Message, number contact.Contact, sendTime *time.Time) (*types.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,
@@ -28,12 +32,11 @@ 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)
} }
}
if resp, err := client.Api.CreateMessage(params); err != nil { if resp, err := client.Api.CreateMessage(params); err != nil {
return nil, fmt.Errorf("Error sending message: %v", err) return nil, fmt.Errorf("Error sending message: %v", err)
@@ -45,3 +48,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.Before(early) && scheduled.After(now) {
return true
} else {
return false
}
}