Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
40d92ab7d3 | ||
|
|
7ec1f58f6a | ||
|
|
66c7fc261f | ||
|
|
a4fefd5bc6 | ||
|
|
c809815549 |
@@ -0,0 +1,6 @@
|
||||
vendor/
|
||||
|
||||
.git/
|
||||
.gitea/
|
||||
|
||||
.env
|
||||
@@ -0,0 +1,8 @@
|
||||
AUTH_URL=https://auth.txt.com
|
||||
API_URL=https://txt.com
|
||||
SERVICE_USERNAME=suave
|
||||
SERVICE_PASSPHRASE=9238urc9328nr329
|
||||
TWILIO_AUTH_SID=9M438C93R943U4329MCU43C34U
|
||||
TWILIO_SERVICE_SID=9M4J3X8439U398NUVT3342MC349C348T
|
||||
TWILIO_AUTH_TOKEN="f4a1f2b0b79ea3735078c2d8ee9684e1"
|
||||
TWILIO_PHONE_NUMBER=10123456789
|
||||
@@ -3,3 +3,4 @@ catapult
|
||||
|
||||
.env
|
||||
.env.local
|
||||
.env.docker
|
||||
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
FROM golang:1.25.4 AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
ca-certificates \
|
||||
openssh-client git
|
||||
|
||||
RUN mkdir -p -m 0700 ~/.ssh && \
|
||||
ssh-keyscan git.kundeng.us >> ~/.ssh/known_hosts
|
||||
|
||||
# Configure Git to use SSH for GitHub
|
||||
RUN git config --global url."ssh://git@git.kundeng.us".insteadOf "https://git.kundeng.us"
|
||||
|
||||
# Set up the Go environment for private modules
|
||||
ENV GOPRIVATE=git.kundeng.us
|
||||
|
||||
# Copy go mod and sum files
|
||||
COPY go.mod go.sum ./
|
||||
|
||||
RUN --mount=type=ssh mkdir src && \
|
||||
go mod download
|
||||
|
||||
# Copy source code
|
||||
COPY ./cmd ./cmd
|
||||
COPY ./internal ./internal
|
||||
COPY ./Makefile .
|
||||
COPY ./.env .
|
||||
|
||||
# Build the application
|
||||
RUN CGO_ENABLED=0 GOOS=linux make build
|
||||
|
||||
# Runtime stage
|
||||
FROM alpine:latest AS production
|
||||
|
||||
RUN apk --no-cache add ca-certificates
|
||||
|
||||
WORKDIR /root/
|
||||
|
||||
# Copy the pre-built binary file from the previous stage
|
||||
COPY --from=builder /app/catapult .
|
||||
COPY --from=builder /app/.env ./
|
||||
|
||||
# Command to run the executable
|
||||
CMD ["./catapult"]
|
||||
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
@@ -13,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println(app.App_Name)
|
||||
log.Println(app.App_Name)
|
||||
|
||||
versionFlag := config.CheckVersionFlag()
|
||||
if *versionFlag {
|
||||
@@ -23,7 +24,7 @@ func main() {
|
||||
|
||||
myApp, err := app.Load()
|
||||
if err != nil {
|
||||
fmt.Println("Error loading app: %w", err)
|
||||
log.Println("Error loading app: %w", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
version: '3.8' # Use a recent version
|
||||
|
||||
services:
|
||||
catapult_service:
|
||||
build: # Tells docker-compose to build the Dockerfile in the current directory
|
||||
context: .
|
||||
ssh: ["default"] # Uses host's SSH agent
|
||||
container_name: catapult # Optional: Give the container a specific name
|
||||
env_file:
|
||||
- .env
|
||||
restart: unless-stopped # Optional: Restart policy
|
||||
@@ -3,8 +3,8 @@ module git.kundeng.us/phoenix/catapult
|
||||
go 1.25.4
|
||||
|
||||
require (
|
||||
git.kundeng.us/phoenix/swoosh v0.0.5
|
||||
git.kundeng.us/phoenix/textsender-models v0.0.10
|
||||
git.kundeng.us/phoenix/swoosh v0.1.0
|
||||
git.kundeng.us/phoenix/textsender-models v0.1.6
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/joho/godotenv v1.5.1
|
||||
)
|
||||
@@ -13,5 +13,5 @@ require (
|
||||
github.com/golang-jwt/jwt/v5 v5.3.0 // indirect
|
||||
github.com/golang/mock v1.6.0 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/twilio/twilio-go v1.28.7 // indirect
|
||||
github.com/twilio/twilio-go v1.28.8 // indirect
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
git.kundeng.us/phoenix/swoosh v0.0.5 h1:++kc6xRlt01ToMeIOSzYtGnYjug6x0p0euZwJ+xHDs4=
|
||||
git.kundeng.us/phoenix/swoosh v0.0.5/go.mod h1:BTn6gDaHWTP/OpvDjOFZJwN9kJ1xd9Rl6yFJGy8xV1k=
|
||||
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=
|
||||
git.kundeng.us/phoenix/swoosh v0.1.0 h1:9P+wLuJsIZmVcRoG+W22l06hwp54eNrYbsBtGjucnjI=
|
||||
git.kundeng.us/phoenix/swoosh v0.1.0/go.mod h1:6/97/aS8KVdYqlczQ9ALvS3GVoce1UVl+D8VQK42Bd0=
|
||||
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=
|
||||
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=
|
||||
@@ -29,8 +29,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.7 h1:WzzQDR/rqmNkVs1TwtcHFPYGTdSdPnx/eAZf5UIXzr4=
|
||||
github.com/twilio/twilio-go v1.28.7/go.mod h1:FpgNWMoD8CFnmukpKq9RNpUSGXC0BwnbeKZj2YHlIkw=
|
||||
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/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=
|
||||
|
||||
+4
-4
@@ -5,7 +5,7 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"git.kundeng.us/phoenix/textsender-models/tx0/config"
|
||||
auxcfg "git.kundeng.us/phoenix/textsender-models/tx0/config/auxiliary"
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
@@ -16,7 +16,7 @@ type App struct {
|
||||
AuthUrl string
|
||||
ServiceUsername string
|
||||
ServicePassphrase string
|
||||
TwilioConfig *config.TwiloConfig
|
||||
TwilioConfig *auxcfg.TwilioConfig
|
||||
}
|
||||
|
||||
func Load() (*App, error) {
|
||||
@@ -56,7 +56,7 @@ func Load() (*App, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func loadTwilioConfig() (*config.TwiloConfig, error) {
|
||||
func loadTwilioConfig() (*auxcfg.TwilioConfig, error) {
|
||||
authSid := os.Getenv("TWILIO_AUTH_SID")
|
||||
serviceSid := os.Getenv("TWILIO_SERVICE_SID")
|
||||
authToken := os.Getenv("TWILIO_AUTH_TOKEN")
|
||||
@@ -71,7 +71,7 @@ func loadTwilioConfig() (*config.TwiloConfig, error) {
|
||||
} else if len(phoneNumber) == 0 {
|
||||
return nil, fmt.Errorf("Twilio config phone number not provided")
|
||||
} else {
|
||||
cfg := config.TwiloConfig{}
|
||||
cfg := auxcfg.TwilioConfig{}
|
||||
cfg.AccountSID = authSid
|
||||
cfg.AuthToken = authToken
|
||||
cfg.ServiceSID = serviceSid
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"git.kundeng.us/phoenix/textsender-models/tx0/token"
|
||||
|
||||
@@ -53,3 +54,45 @@ func (a *Auth) GetToken() (*token.Login, error) {
|
||||
|
||||
return r.Data[0], nil
|
||||
}
|
||||
|
||||
type refreshTokenRequest struct {
|
||||
AccessToken string `json:"access_token"`
|
||||
}
|
||||
|
||||
func (a *Auth) GetRefreshToken(tok *token.Login) (*token.Login, error) {
|
||||
req := refreshTokenRequest{AccessToken: tok.AccessToken}
|
||||
|
||||
jsonData, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := http.Post(fmt.Sprintf("%s/api/v1/token/refresh", a.Application.AuthUrl), "application/json", bytes.NewBuffer(jsonData))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
var r tokenResponse
|
||||
err = json.NewDecoder(resp.Body).Decode(&r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if len(r.Data) == 0 {
|
||||
return nil, nil
|
||||
} else {
|
||||
return r.Data[0], nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Auth) TokenExpired(tok *token.Login) bool {
|
||||
now := time.Now()
|
||||
expiredTime := time.Unix(tok.ExpiresIn, 0)
|
||||
|
||||
if now.After(expiredTime) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,15 +19,15 @@ type Contact struct {
|
||||
}
|
||||
|
||||
type getContactResponse struct {
|
||||
Message string `json:"message"`
|
||||
Data []*contact.Contact `json:"data"`
|
||||
Message string `json:"message"`
|
||||
Data []*contact.Contact `json:"data"`
|
||||
}
|
||||
|
||||
func (c *Contact) GetContact(id uuid.UUID) (*contact.Contact, error) {
|
||||
params := url.Values{}
|
||||
params.Add("id", id.String())
|
||||
pm := params.Encode()
|
||||
fullUrl := fmt.Sprintf("%s/api/v1/contact?%s", c.Application.ApiUrl, pm)
|
||||
fullUrl := fmt.Sprintf("%s/api/v1/contact?%s", c.Application.ApiUrl, pm)
|
||||
fmt.Println("Url:", fullUrl)
|
||||
req, err := http.NewRequest("GET", fullUrl, nil)
|
||||
if err != nil {
|
||||
|
||||
@@ -2,8 +2,6 @@ package core
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -57,56 +55,67 @@ func (s *Service) worker1() {
|
||||
// Do some work
|
||||
now := time.Now()
|
||||
log.Println("Worker 1: Processing...")
|
||||
catapultAuth := service.Auth{Application: s.App}
|
||||
if s.token == nil {
|
||||
catapultAuth := service.Auth{Application: s.App}
|
||||
log.Println("Token has not been fetched")
|
||||
log.Println("Fetching token")
|
||||
if token, err := catapultAuth.GetToken(); err != nil {
|
||||
fmt.Println("Error:", err)
|
||||
log.Println("Error:", err)
|
||||
} else {
|
||||
fmt.Println("Access token:", token.AccessToken)
|
||||
log.Println("Token fetched")
|
||||
s.token = token
|
||||
}
|
||||
} else if catapultAuth.TokenExpired(s.token) {
|
||||
// Get refresh token
|
||||
log.Println("Token expired")
|
||||
log.Println("Fetching refresh token")
|
||||
refreshToken, err := catapultAuth.GetRefreshToken(s.token)
|
||||
if err != nil {
|
||||
log.Println("Error getting refresh token:", err)
|
||||
} else {
|
||||
log.Println("Refresh token fetched")
|
||||
s.token = refreshToken
|
||||
}
|
||||
}
|
||||
|
||||
log.Println("Twilio config account sid:", s.App.TwilioConfig.AccountSID)
|
||||
log.Println("Twilio config auth token:", s.App.TwilioConfig.AuthToken)
|
||||
log.Println("Twilio config service sid:", s.App.TwilioConfig.ServiceSID)
|
||||
log.Println("Twilio config number:", s.App.TwilioConfig.Number)
|
||||
|
||||
queue := service.Queue{Application: s.App, Token: s.token}
|
||||
if item, exists, err := queue.GetQueue(); err != nil {
|
||||
fmt.Println("Error:", err)
|
||||
log.Println("Error:", err)
|
||||
} else {
|
||||
if *exists {
|
||||
fmt.Println("Scheduled message Id:", item.Id)
|
||||
fmt.Println("Created:", item.Created)
|
||||
fmt.Println("Scheduled:", item.Scheduled)
|
||||
fmt.Println("Status:", item.Status)
|
||||
log.Println("Scheduled message Id:", item.Id)
|
||||
log.Println("Created:", item.Created)
|
||||
log.Println("Scheduled:", item.Scheduled)
|
||||
log.Println("Status:", item.Status)
|
||||
log.Println("User Id:", item.UserId)
|
||||
if scheduledMessageValid(item, now) {
|
||||
fmt.Println("Scheduled Message can be sent")
|
||||
log.Println("Scheduled Message can be sent")
|
||||
scheduler := service.Scheduler{Application: s.App, Token: s.token}
|
||||
if events, err := scheduler.GetEvents(item.Id); err != nil {
|
||||
fmt.Println("Error getting event:", err)
|
||||
log.Println("Error getting event:", err)
|
||||
} else {
|
||||
for _, event := range events {
|
||||
if msg, err := scheduler.GetMessage(event.MessageId); err != nil {
|
||||
fmt.Println("Error getting message:", err)
|
||||
log.Println("Error getting message:", err)
|
||||
} else {
|
||||
if c, err := scheduler.GetContact(event.RecipientId); err != nil {
|
||||
fmt.Println("Error getting contact:", err)
|
||||
if c, err := scheduler.GetContact(event.ContactId); err != nil {
|
||||
log.Println("Error getting contact:", err)
|
||||
} else {
|
||||
fmt.Println("Message Id:", msg.Id)
|
||||
fmt.Println("Contact Id:", c.Id)
|
||||
if res, err := scheduler.ScheduleMessage(*item, *event, *c, *msg); err != nil {
|
||||
log.Println("Message Id:", msg.Id)
|
||||
log.Println("Contact Id:", c.Id)
|
||||
if res, resRaw, sent, err := scheduler.ScheduleMessage(*item, *event, *c, *msg); err != nil {
|
||||
log.Println("Failure with scheduling the message:", err)
|
||||
} else {
|
||||
if res != nil {
|
||||
bytes, err := json.Marshal(res)
|
||||
if err != nil {
|
||||
log.Println("Error parsing result:", err)
|
||||
if eventResponse, err := scheduler.RecordEventResponse(event, item.UserId, resRaw, sent); err != nil {
|
||||
log.Println("Failure recording event response:", err)
|
||||
} else {
|
||||
jsonValue := string(bytes)
|
||||
log.Println("Result:", jsonValue)
|
||||
if len(eventResponse) == 0 {
|
||||
log.Println("No event responses")
|
||||
} else {
|
||||
eventResponse := eventResponse[0]
|
||||
log.Println("Event response saved. Id:", eventResponse.Id)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.Println("Result should not be empty")
|
||||
@@ -117,10 +126,10 @@ func (s *Service) worker1() {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fmt.Println("Invalid scheduled message")
|
||||
log.Println("Invalid scheduled message")
|
||||
}
|
||||
} else {
|
||||
fmt.Println("Empty queue")
|
||||
log.Println("Empty queue")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,15 +19,15 @@ type Message struct {
|
||||
}
|
||||
|
||||
type getMessageResponse struct {
|
||||
Message string `json:"message"`
|
||||
Data []*message.Message `json:"data"`
|
||||
Message string `json:"message"`
|
||||
Data []*message.Message `json:"data"`
|
||||
}
|
||||
|
||||
func (m *Message) GetMessage(id uuid.UUID) (*message.Message, error) {
|
||||
params := url.Values{}
|
||||
params.Add("id", id.String())
|
||||
pm := params.Encode()
|
||||
fullUrl := fmt.Sprintf("%s/api/v1/message?%s", m.Application.ApiUrl, pm)
|
||||
fullUrl := fmt.Sprintf("%s/api/v1/message?%s", m.Application.ApiUrl, pm)
|
||||
fmt.Println("Url:", fullUrl)
|
||||
req, err := http.NewRequest("GET", fullUrl, nil)
|
||||
if err != nil {
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"git.kundeng.us/phoenix/textsender-models/tx0/message/event"
|
||||
"git.kundeng.us/phoenix/textsender-models/tx0/token"
|
||||
|
||||
"git.kundeng.us/phoenix/catapult/internal/app"
|
||||
)
|
||||
|
||||
type MessageEventResponse struct {
|
||||
Application *app.App
|
||||
Token *token.Login
|
||||
}
|
||||
|
||||
type recordMessageEventResponse struct {
|
||||
Message string `json:"message"`
|
||||
Data []*event.MessageEventResponse `json:"data"`
|
||||
}
|
||||
|
||||
func (m *MessageEventResponse) RecordEventResponse(mer *event.MessageEventResponse) ([]*event.MessageEventResponse, error) {
|
||||
fullUrl := fmt.Sprintf("%s/api/v1/schedule/message/event/response/record", m.Application.ApiUrl)
|
||||
jsonData, err := json.Marshal(mer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("POST", fullUrl, strings.NewReader(string(jsonData)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
token := m.Token.AccessToken
|
||||
req.Header.Set("Authorization", "Bearer "+token)
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
var r recordMessageEventResponse
|
||||
err = json.NewDecoder(resp.Body).Decode(&r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if len(r.Data) == 0 {
|
||||
return nil, nil
|
||||
} else {
|
||||
return r.Data, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,22 +6,21 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"git.kundeng.us/phoenix/textsender-models/tx0/message/scheduling"
|
||||
"git.kundeng.us/phoenix/textsender-models/tx0/token"
|
||||
"github.com/google/uuid"
|
||||
|
||||
"git.kundeng.us/phoenix/catapult/internal/app"
|
||||
)
|
||||
|
||||
|
||||
type ScheduledMessageEvent struct {
|
||||
Application *app.App
|
||||
Token *token.Login
|
||||
}
|
||||
|
||||
type getScheduledMessageEventResponse struct {
|
||||
Message string `json:"message"`
|
||||
Data []*scheduling.ScheduledMessageEvent `json:"data"`
|
||||
Message string `json:"message"`
|
||||
Data []*scheduling.ScheduledMessageEvent `json:"data"`
|
||||
}
|
||||
|
||||
func (s *ScheduledMessageEvent) GetEvents(scheduledMessageId uuid.UUID) ([]*scheduling.ScheduledMessageEvent, error) {
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.kundeng.us/phoenix/swoosh/swoop/send"
|
||||
"git.kundeng.us/phoenix/swoosh/swoop/types"
|
||||
"git.kundeng.us/phoenix/textsender-models/tx0/contact"
|
||||
"git.kundeng.us/phoenix/textsender-models/tx0/message"
|
||||
evnt "git.kundeng.us/phoenix/textsender-models/tx0/message/event"
|
||||
"git.kundeng.us/phoenix/textsender-models/tx0/message/scheduling"
|
||||
"git.kundeng.us/phoenix/textsender-models/tx0/token"
|
||||
"github.com/google/uuid"
|
||||
@@ -14,10 +15,9 @@ import (
|
||||
"git.kundeng.us/phoenix/catapult/internal/app"
|
||||
)
|
||||
|
||||
|
||||
type Scheduler struct {
|
||||
Application *app.App
|
||||
Token *token.Login
|
||||
Token *token.Login
|
||||
}
|
||||
|
||||
func (s *Scheduler) GetEvents(scheduledMessageId uuid.UUID) ([]*scheduling.ScheduledMessageEvent, error) {
|
||||
@@ -41,18 +41,29 @@ func (s *Scheduler) GetMessage(id uuid.UUID) (*message.Message, error) {
|
||||
func (s *Scheduler) GetContact(id uuid.UUID) (*contact.Contact, error) {
|
||||
ctct := Contact{Application: s.Application, Token: s.Token}
|
||||
if c, err := ctct.GetContact(id); err != nil {
|
||||
return nil ,err
|
||||
return nil, err
|
||||
} else {
|
||||
return c, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Scheduler) ScheduleMessage(schMsg scheduling.ScheduledMessage, event scheduling.ScheduledMessageEvent, c contact.Contact, msg message.Message) (*types.TwilioResult, error) {
|
||||
func (s *Scheduler) ScheduleMessage(schMsg scheduling.ScheduledMessage, event scheduling.ScheduledMessageEvent, c contact.Contact, msg message.Message) (*types.TwilioResult, map[string]any, *time.Time, error) {
|
||||
msgSender := send.MessageSender{Config: s.Application.TwilioConfig}
|
||||
if res, err := msgSender.Send(msg, c, &schMsg.Scheduled); err != nil {
|
||||
return nil, err
|
||||
if res, resRaw, err := msgSender.Send(msg, c, &schMsg.Scheduled); err != nil {
|
||||
return nil, nil, nil, err
|
||||
} else {
|
||||
fmt.Println(res.AccountSid)
|
||||
return res, nil
|
||||
sent := time.Now()
|
||||
return res, resRaw, &sent, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Scheduler) RecordEventResponse(schMsgEvent *scheduling.ScheduledMessageEvent, userId uuid.UUID, bytes map[string]any, sent *time.Time) ([]*evnt.MessageEventResponse, error) {
|
||||
mre := evnt.MessageEventResponse{ScheduledMessageEventId: schMsgEvent.Id, UserId: userId, Response: bytes, Sent: *sent, Status: evnt.Message_Event_Response_Status_Scheduled}
|
||||
|
||||
msgEventResponse := MessageEventResponse{Application: s.Application, Token: s.Token}
|
||||
if responses, err := msgEventResponse.RecordEventResponse(&mre); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return responses, nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user