Compare commits

..
Author SHA1 Message Date
phoenix ae0df7ef0a tsk-9: Build fixes after package update 2025-12-31 18:35:20 -05:00
phoenix 0ec0b3dece tsk-9: textsender-models version bump 2025-12-31 18:34:58 -05:00
2 changed files with 8 additions and 16 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ jobs:
run: | run: |
echo "Creating version" echo "Creating version"
VERSION="0.1.0" VERSION="0.0.8"
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)
+7 -15
View File
@@ -15,17 +15,14 @@ import (
) )
const Schedule_Type = "fixed" const Schedule_Type = "fixed"
const Schedulable_Limit_In_Seconds = 300
type MessageSender struct { type MessageSender struct {
Config *auxcfg.TwilioConfig Config *auxcfg.TwilioConfig
} }
// Sends a message to a contact via Twilio func (m *MessageSender) Send(msg message.Message, number contact.Contact, sendTime *time.Time) (*types.TwilioResult, error) {
// 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, nil, fmt.Errorf("Config has not been initialized") 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{
@@ -44,23 +41,18 @@ 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, nil, fmt.Errorf("Error sending message: %v", err) return nil, fmt.Errorf("Error sending message: %v", err)
} else { } else {
if twilioRespMarshaled, err := json.Marshal(*resp); err != nil { if _, err := json.Marshal(*resp); err != nil {
return nil, nil, fmt.Errorf("Error parsing result: %v", err) return nil, fmt.Errorf("Error parsing result: %v", err)
} else { } else {
var rawObject map[string]any return resp, nil
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(Schedulable_Limit_In_Seconds * time.Second) early := now.Add(300 * time.Second)
if scheduled.After(early) { if scheduled.After(early) {
return true return true