Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a9d9200794 | ||
|
|
3c1f8a1a27 |
@@ -25,7 +25,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
echo "Creating version"
|
echo "Creating version"
|
||||||
|
|
||||||
VERSION="0.0.8"
|
VERSION="0.1.0"
|
||||||
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)
|
||||||
@@ -44,13 +44,3 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
echo "Printing version"
|
echo "Printing version"
|
||||||
echo "Version: ${{ steps.version.outputs.project_tag_release }}"
|
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 }}
|
|
||||||
|
|||||||
@@ -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.12
|
git.kundeng.us/phoenix/textsender-models v0.1.6
|
||||||
github.com/twilio/twilio-go v1.28.8
|
github.com/twilio/twilio-go v1.28.8
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
git.kundeng.us/phoenix/textsender-models v0.0.12 h1:ps9H3FS5LyCwQhAiIvg4vYyfLZZ64dex1y9ytb0o9C4=
|
git.kundeng.us/phoenix/textsender-models v0.1.6 h1:d/rhvqjFSt1Ty/3UfwS21be+lYb9EtWEaDtkzfbzEp0=
|
||||||
git.kundeng.us/phoenix/textsender-models v0.0.12/go.mod h1:9iPDQJg1Tc6WMNoW5+f8YKmnosMwlWHJ++hmxNLDEe0=
|
git.kundeng.us/phoenix/textsender-models v0.1.6/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=
|
||||||
|
|||||||
+17
-9
@@ -5,7 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.kundeng.us/phoenix/textsender-models/tx0/config"
|
auxcfg "git.kundeng.us/phoenix/textsender-models/tx0/config/auxiliary"
|
||||||
"git.kundeng.us/phoenix/textsender-models/tx0/contact"
|
"git.kundeng.us/phoenix/textsender-models/tx0/contact"
|
||||||
"git.kundeng.us/phoenix/textsender-models/tx0/message"
|
"git.kundeng.us/phoenix/textsender-models/tx0/message"
|
||||||
"github.com/twilio/twilio-go"
|
"github.com/twilio/twilio-go"
|
||||||
@@ -15,14 +15,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const Schedule_Type = "fixed"
|
const Schedule_Type = "fixed"
|
||||||
|
const Schedulable_Limit_In_Seconds = 300
|
||||||
|
|
||||||
type MessageSender struct {
|
type MessageSender struct {
|
||||||
Config *config.TwilioConfig
|
Config *auxcfg.TwilioConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MessageSender) Send(msg message.Message, number contact.Contact, sendTime *time.Time) (*types.TwilioResult, error) {
|
// 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) {
|
||||||
if m.Config == nil {
|
if m.Config == nil {
|
||||||
return nil, fmt.Errorf("Config has not been initialized")
|
return nil, nil, fmt.Errorf("Config has not been initialized")
|
||||||
}
|
}
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
client := twilio.NewRestClientWithParams(twilio.ClientParams{
|
client := twilio.NewRestClientWithParams(twilio.ClientParams{
|
||||||
@@ -41,18 +44,23 @@ func (m *MessageSender) Send(msg message.Message, number contact.Contact, sendTi
|
|||||||
}
|
}
|
||||||
|
|
||||||
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, nil, fmt.Errorf("Error sending message: %v", err)
|
||||||
} else {
|
} else {
|
||||||
if _, err := json.Marshal(*resp); err != nil {
|
if twilioRespMarshaled, err := json.Marshal(*resp); err != nil {
|
||||||
return nil, fmt.Errorf("Error parsing result: %v", err)
|
return nil, nil, fmt.Errorf("Error parsing result: %v", err)
|
||||||
} else {
|
} else {
|
||||||
return resp, nil
|
var rawObject map[string]any
|
||||||
|
if err := json.Unmarshal(twilioRespMarshaled, &rawObject); err != nil {
|
||||||
|
return resp, nil, err
|
||||||
|
} else {
|
||||||
|
return resp, rawObject, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func isSchedulable(now *time.Time, scheduled *time.Time) bool {
|
func isSchedulable(now *time.Time, scheduled *time.Time) bool {
|
||||||
early := now.Add(300 * time.Second)
|
early := now.Add(Schedulable_Limit_In_Seconds * time.Second)
|
||||||
|
|
||||||
if scheduled.After(early) {
|
if scheduled.After(early) {
|
||||||
return true
|
return true
|
||||||
|
|||||||
Reference in New Issue
Block a user