-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/ClubCedille/hackqc2024
- Loading branch information
Showing
26 changed files
with
441 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package geometry | ||
|
||
import ( | ||
"strconv" | ||
"strings" | ||
|
||
mapobject "github.com/ClubCedille/hackqc2024/pkg/map_object" | ||
pip "github.com/JamesLMilner/pip-go" | ||
"github.com/twpayne/go-geom" | ||
"github.com/twpayne/go-geom/xy" | ||
) | ||
|
||
func IsInGeom(point []float64, geometry mapobject.Geometry) bool { | ||
if geometry.GeomType == "Point" { | ||
const distCutoff = 0.01 | ||
|
||
coord1 := geometry.AsGeomCoord() | ||
coord2 := geom.Coord(point[0:2]) | ||
|
||
distance := xy.Distance(coord1, coord2) | ||
|
||
return distance < distCutoff | ||
} else if geometry.GeomType == "Polygon" { | ||
pipPoint := pip.Point{X: point[0], Y: point[1]} | ||
polygon := *geometry.AsPipPolygon() | ||
|
||
return pip.PointInPolygon(pipPoint, polygon) | ||
} | ||
|
||
return false | ||
} | ||
|
||
func ParseCoordinatesString(coordinates string) ([]float64, error) { | ||
coordinatesArray := strings.Split(coordinates, ",") | ||
|
||
var coordinatesArrayFloat []float64 | ||
for i := len(coordinatesArray) - 1; i >= 0; i-- { | ||
coords, err := strconv.ParseFloat(strings.TrimSpace(coordinatesArray[i]), 64) | ||
if err != nil { | ||
return nil, err | ||
} | ||
coordinatesArrayFloat = append(coordinatesArrayFloat, coords) | ||
} | ||
|
||
return coordinatesArrayFloat, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,110 @@ | ||
package notifications | ||
|
||
import "fmt" | ||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"io" | ||
"net/http" | ||
"net/url" | ||
"os" | ||
|
||
"github.com/ClubCedille/hackqc2024/pkg/account" | ||
"github.com/ClubCedille/hackqc2024/pkg/geometry" | ||
mapobject "github.com/ClubCedille/hackqc2024/pkg/map_object" | ||
"github.com/ostafen/clover/v2" | ||
) | ||
|
||
type Notification struct { | ||
APIUsername string `json:"api_username"` | ||
APIPassword string `json:"api_password"` | ||
Message string `json:"message"` | ||
Dst string `json:"dst"` | ||
Did string `json:"did"` | ||
} | ||
|
||
// Send notification to all phone numbers | ||
func SendNotification(message string, recipients []string) { | ||
// TODO: Implement notification sending | ||
fmt.Println("Sending Notification, message: ", message, " recipients: ", recipients) | ||
|
||
for _, recipient := range recipients { | ||
fmt.Println("Sending notification to: ", recipient) | ||
|
||
// go SendNotificationToPhoneNumber(message, recipient) | ||
} | ||
} | ||
|
||
func SendNotificationToPhoneNumber(message string, recipient string) { | ||
|
||
api_username := os.Getenv("VOIPMS_API_USERNAME") | ||
api_password := os.Getenv("VOIPMS_API_PASSWORD") | ||
api_did := os.Getenv("VOIPMS_API_DID") | ||
|
||
params := url.Values{ | ||
"method": []string{"sendSMS"}, | ||
"message": []string{message}, | ||
"dst": []string{recipient}, | ||
"did": []string{api_did}, | ||
"api_username": []string{api_username}, | ||
"api_password": []string{api_password}, | ||
} | ||
|
||
u := &url.URL{ | ||
Scheme: "https", | ||
Host: "voip.ms", | ||
Path: "/api/v1/rest.php", | ||
RawQuery: params.Encode(), | ||
} | ||
req, err := http.NewRequest("GET", u.String(), nil) | ||
if err != nil { | ||
fmt.Println("Error creating request: ", err) | ||
} | ||
|
||
client := &http.Client{} | ||
result, err := client.Do(req) | ||
|
||
if err != nil || result.StatusCode != 200 { | ||
fmt.Println("Error sending notification to phone number: ", err) | ||
} | ||
defer result.Body.Close() | ||
|
||
body, err := io.ReadAll(result.Body) | ||
if err != nil { | ||
fmt.Println("Error reading response body: ", err) | ||
} | ||
|
||
fmt.Println("Result sending notification to phone number: ", string(body)) | ||
} | ||
|
||
func NotifyNearby(db *clover.DB, message string, geom mapobject.Geometry) error { | ||
accounts, err := account.GetAllAccounts(db) | ||
if err != nil { | ||
log.Println("Error getting accounts:", err) | ||
return err | ||
} | ||
|
||
accountIds := []string{} | ||
for _, account := range accounts { | ||
if geometry.IsInGeom(account.Coordinates, geom) { | ||
accountIds = append(accountIds, account.Id) | ||
} | ||
} | ||
|
||
if len(accountIds) > 0 { | ||
SendNotification( | ||
message, | ||
accountIds, | ||
) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// what am I even doing here? | ||
func NotifyEventSubscribers(db *clover.DB, message string, subscribers []string) { | ||
SendNotification( | ||
message, | ||
subscribers, | ||
) | ||
} |
Oops, something went wrong.