forked from NdoleStudio/httpsms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
110 lines (92 loc) · 2.66 KB
/
Copy pathmain.go
File metadata and controls
110 lines (92 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package main
import (
"context"
"fmt"
"log"
"os"
"strings"
"sync"
"time"
"github.com/palantir/stacktrace"
"github.com/NdoleStudio/httpsms/pkg/di"
"github.com/NdoleStudio/httpsms/pkg/entities"
"github.com/google/uuid"
"github.com/carlmjohnson/requests"
"github.com/joho/godotenv"
)
func main() {
err := godotenv.Load("../../.env")
if err != nil {
log.Fatal("Error loading .env file")
}
container := di.NewLiteContainer()
logger := container.Logger()
logger.Info("Starting experiments")
}
func chunkBy[T any](items []T, chunkSize int) (chunks [][]T) {
for chunkSize < len(items) {
items, chunks = items[chunkSize:], append(chunks, items[0:chunkSize:chunkSize])
}
return append(chunks, items)
}
func deleteContacts(container *di.Container) {
sendgrid := container.MarketingService()
logger := container.Logger()
b, err := os.ReadFile("28462979_cf6f5478-3e15-4666-95d7-59149df6f0fd.csv") // just pass the file name
if err != nil {
logger.Fatal(stacktrace.Propagate(err, "cannot read file"))
}
lines := strings.Split(string(b), "\n")[1:]
var contacts []string
for _, line := range lines {
contacts = append(contacts, strings.ReplaceAll(strings.Split(line, ",")[17], "\"", ""))
}
chunks := chunkBy(contacts, 100)
for _, chunk := range chunks {
err = sendgrid.DeleteContacts(context.Background(), chunk)
if err != nil {
logger.Fatal(err)
}
}
}
func text3CX() {
container := di.NewLiteContainer()
repo := container.Integration3CXRepository()
err := repo.Save(context.Background(), &entities.Integration3CX{
ID: uuid.MustParse("b0b1acdc-69dd-4aee-8277-ba4adc5d2e90"),
UserID: "XtABz6zdeFMoBLoltz6SREDvRSh2",
WebhookURL: "https://lagomtest.3cx.com.au/sms/generic/155e125bf7874f8fae5adbcaac49fdf8",
CreatedAt: time.Now().UTC(),
UpdatedAt: time.Now().UTC(),
})
if err != nil {
container.Logger().Fatal(err)
}
}
func loadTest() {
wg := sync.WaitGroup{}
for i := 0; i < 1; i++ {
wg.Add(1)
go func(count int) {
sendSMS(fmt.Sprintf("[%d] In the quiet of the night, the stars above whisper secrets of the universe. We, mere stardust, seek meaning in their cosmic dance, yearning to unlock the mysteries of existence that stretch far beyond our earthly bounds.", count))
wg.Done()
}(i)
}
wg.Wait()
}
func sendSMS(content string) {
var response string
err := requests.URL(os.Getenv("BASIC_URL")).
BodyJSON(map[string]any{
"content": content,
"from": os.Getenv("BASIC_FROM"),
"to": os.Getenv("BASIC_TO"),
}).
BasicAuth(os.Getenv("BASIC_USERNAME"), os.Getenv("BASIC_PASSWORD")).
ToString(&response).
Fetch(context.Background())
if err != nil {
log.Fatal(err)
}
log.Printf("%s\n", response)
}