Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a34ff04776
|
||
|
|
c6ca9063a3
|
@@ -25,7 +25,7 @@ jobs:
|
||||
run: |
|
||||
echo "Creating version"
|
||||
|
||||
VERSION="0.1.0"
|
||||
VERSION="0.0.2"
|
||||
PROJECT_COMMIT_HASH=$(git rev-parse HEAD | cut -c 1-10)
|
||||
BRANCH_REF="${{ gitea.ref }}"
|
||||
BRANCH_NAME=$(echo "$BRANCH_REF" | cut -d '/' -f 3)
|
||||
@@ -44,3 +44,13 @@ jobs:
|
||||
run: |
|
||||
echo "Printing version"
|
||||
echo "Version: ${{ steps.version.outputs.project_tag_release }}"
|
||||
|
||||
- name: Create GitHub Release
|
||||
uses: actions/create-release@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
tag_name: ${{ steps.version.outputs.project_tag_release }}
|
||||
release_name: Release ${{ steps.version.outputs.project_tag_release }}
|
||||
body: |
|
||||
Release of version ${{ steps.version.outputs.project_tag_release }}
|
||||
|
||||
@@ -16,8 +16,8 @@ jobs:
|
||||
go-version: '1.25.4'
|
||||
- name: Configure Git for SSH
|
||||
run: |
|
||||
git config --global url."git@${{ secrets.GIT_HOST_ROOT }}:".insteadOf "https://${{ secrets.GIT_HOST_ROOT }}/"
|
||||
go env -w GOPRIVATE=${{ secrets.GIT_HOST_ROOT }}/phoenix/*
|
||||
git config --global url."git@git.kundeng.us:".insteadOf "https://git.kundeng.us/"
|
||||
go env -w GOPRIVATE=git.kundeng.us/phoenix/*
|
||||
|
||||
- name: Download dependencies
|
||||
run: |
|
||||
@@ -25,7 +25,7 @@ jobs:
|
||||
mkdir -p ~/.ssh
|
||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/swoosh_deploy_key
|
||||
chmod 600 ~/.ssh/swoosh_deploy_key
|
||||
ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts
|
||||
ssh-keyscan ${{ vars.MY_HOST }} >> ~/.ssh/known_hosts
|
||||
|
||||
eval $(ssh-agent -s)
|
||||
ssh-add -v ~/.ssh/swoosh_deploy_key
|
||||
|
||||
@@ -3,8 +3,8 @@ module git.kundeng.us/phoenix/swoosh
|
||||
go 1.25.4
|
||||
|
||||
require (
|
||||
git.kundeng.us/phoenix/textsender-models v0.1.6
|
||||
github.com/twilio/twilio-go v1.28.8
|
||||
git.kundeng.us/phoenix/textsender-models v0.0.10
|
||||
github.com/twilio/twilio-go v1.28.6
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
git.kundeng.us/phoenix/textsender-models v0.1.6 h1:d/rhvqjFSt1Ty/3UfwS21be+lYb9EtWEaDtkzfbzEp0=
|
||||
git.kundeng.us/phoenix/textsender-models v0.1.6/go.mod h1:9iPDQJg1Tc6WMNoW5+f8YKmnosMwlWHJ++hmxNLDEe0=
|
||||
git.kundeng.us/phoenix/textsender-models v0.0.10 h1:0AMe/zm4Xte2BcuqqhRP7+42m+4To+rUnHkR2a9eXlI=
|
||||
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/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=
|
||||
@@ -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/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.28.8 h1:wbFz7Wt4S5mCEaes6FcM/ddcJGIhdjwp/9CHb9e+4fk=
|
||||
github.com/twilio/twilio-go v1.28.8/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=
|
||||
|
||||
+12
-32
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
auxcfg "git.kundeng.us/phoenix/textsender-models/tx0/config/auxiliary"
|
||||
"git.kundeng.us/phoenix/textsender-models/tx0/config"
|
||||
"git.kundeng.us/phoenix/textsender-models/tx0/contact"
|
||||
"git.kundeng.us/phoenix/textsender-models/tx0/message"
|
||||
"github.com/twilio/twilio-go"
|
||||
@@ -14,18 +14,13 @@ import (
|
||||
"git.kundeng.us/phoenix/swoosh/swoop/types"
|
||||
)
|
||||
|
||||
const Schedule_Type = "fixed"
|
||||
const Schedulable_Limit_In_Seconds = 300
|
||||
|
||||
type MessageSender struct {
|
||||
Config *auxcfg.TwilioConfig
|
||||
Config *config.TwiloConfig
|
||||
}
|
||||
|
||||
// Sends a message to a contact via Twilio
|
||||
// Has support for scheduling a time based on if it is in the future
|
||||
func (m *MessageSender) Send(msg message.Message, number contact.Contact, sendTime *time.Time) (*types.TwilioResult, map[string]any, error) {
|
||||
func (m *MessageSender) Send(msg message.Message, number contact.Contact, sendTime *time.Time) (*types.TwilioResult, error) {
|
||||
if m.Config == nil {
|
||||
return nil, nil, fmt.Errorf("Config has not been initialized")
|
||||
return fmt.Errorf("Config has not been initialized")
|
||||
}
|
||||
now := time.Now()
|
||||
client := twilio.NewRestClientWithParams(twilio.ClientParams{
|
||||
@@ -36,35 +31,20 @@ func (m *MessageSender) Send(msg message.Message, number contact.Contact, sendTi
|
||||
params := &twilioApi.CreateMessageParams{}
|
||||
params.SetTo(number.PhoneNumber)
|
||||
params.SetFrom(m.Config.Number)
|
||||
params.SetMessagingServiceSid(m.Config.ServiceSID)
|
||||
params.SetBody(msg.Content)
|
||||
if sendTime != nil && isSchedulable(&now, sendTime) {
|
||||
params.SetSendAt(*sendTime)
|
||||
params.SetScheduleType(Schedule_Type)
|
||||
if sendTime != nil {
|
||||
if sendTime.After(now) {
|
||||
params.SetSendAt(*sendTime)
|
||||
}
|
||||
}
|
||||
|
||||
if resp, err := client.Api.CreateMessage(params); err != nil {
|
||||
return nil, nil, fmt.Errorf("Error sending message: %v", err)
|
||||
return nil, fmt.Errorf("Error sending message: %v", err)
|
||||
} else {
|
||||
if twilioRespMarshaled, err := json.Marshal(*resp); err != nil {
|
||||
return nil, nil, fmt.Errorf("Error parsing result: %v", err)
|
||||
if _, err := json.Marshal(*resp); err != nil {
|
||||
return nil, fmt.Errorf("Error parsing result: %v", err)
|
||||
} else {
|
||||
var rawObject map[string]any
|
||||
if err := json.Unmarshal(twilioRespMarshaled, &rawObject); err != nil {
|
||||
return resp, nil, err
|
||||
} else {
|
||||
return resp, rawObject, nil
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func isSchedulable(now *time.Time, scheduled *time.Time) bool {
|
||||
early := now.Add(Schedulable_Limit_In_Seconds * time.Second)
|
||||
|
||||
if scheduled.After(early) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user