-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #136 from flickmatch/hvs-flick-patch-1
Add functionality to format message
- Loading branch information
Showing
12 changed files
with
103 additions
and
13 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
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ import qrcode from "qrcode-terminal"; | |
import pkg from "whatsapp-web.js"; | ||
const { Client, LocalAuth } = pkg; | ||
import { processGroup } from "./src/inputParser.js"; | ||
import { createMessage } from "./src/notificationRequestParser.js"; | ||
|
||
export const isProd = | ||
process.platform !== "win32" && process.platform !== "darwin"; | ||
|
@@ -12,19 +13,16 @@ export const groupName = isProd ? "Online Queue Update" : "Test group "; | |
|
||
import express from "express"; | ||
const app = express(); | ||
app.use(express.json()); | ||
const port = 3000; | ||
const ggnSouthCityChatId = "[email protected]"; | ||
const hydChatId = "[email protected]"; | ||
|
||
app.post("/", (req, res) => { | ||
app.post("/notification", (req, res) => { | ||
const testGroupChatId = "[email protected]"; | ||
client.sendMessage(testGroupChatId, "Post Endpoint hit"); | ||
res.send("Hello World!"); | ||
}); | ||
|
||
app.get("/", (req, res) => { | ||
const testGroupChatId = "[email protected]"; | ||
client.sendMessage(testGroupChatId, "Get Endpoint hit"); | ||
const jsonData = req.body; | ||
//console.log('Received JSON data:', JSON.stringify(jsonData)); | ||
client.sendMessage(testGroupChatId, createMessage(jsonData)); | ||
res.send("Hello World!"); | ||
}); | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,52 @@ | ||
const daysOfWeek = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']; | ||
|
||
// Function to convert timestamps to timeslot | ||
function convertToTimeSlot(timestamp1, timestamp2) { | ||
// Convert timestamps to Date objects | ||
const date1 = new Date(timestamp1); | ||
const date2 = new Date(timestamp2); | ||
|
||
// Extract hours and minutes from the Date objects | ||
const hours1 = date1.getHours(); | ||
const minutes1 = date1.getMinutes(); | ||
const date = date1.getDate(); | ||
const month = date1.getMonth(); | ||
const year = date1.getFullYear(); | ||
const fullDate = `${date}-${month}-${year}` | ||
const day = date1.getDay(); | ||
|
||
const hours2 = date2.getHours(); | ||
const minutes2 = date2.getMinutes(); | ||
|
||
// Format the timeslots | ||
const timeSlot1 = `${padZero(hours1)}:${padZero(minutes1)}`; | ||
const timeSlot2 = `${padZero(hours2)}:${padZero(minutes2)}`; | ||
|
||
return `${timeSlot1} - ${timeSlot2} ${fullDate} (${daysOfWeek[day]})`; | ||
} | ||
|
||
// Function to pad zero for single-digit hours/minutes | ||
function padZero(value) { | ||
return value < 10 ? `0${value}` : `${value}`; | ||
} | ||
|
||
export const createMessage = (jsonData) => { | ||
//const jsonDataObject = JSON.parse(jsonData); | ||
const venueName = jsonData.venueName; | ||
const mapLink = jsonData.venueLocationLink; | ||
const format = jsonData.reservedPlayersCount/2; | ||
const charges = jsonData.charges; | ||
const dateTime = convertToTimeSlot(jsonData.startTime, jsonData.endTime); | ||
|
||
var message = `${venueName} (${mapLink}) | ||
${dateTime} | ||
${format}v${format} | ||
₹${charges}/- Per Person. | ||
Confirmed Players:`; | ||
for (const [index, value] of jsonData.playerNameList.entries()) { | ||
message = message + '\n' + `${index+1}. ${value}`; | ||
} | ||
message = message + '\n\nPlease pay at play.flickmatch.in to confirm your spot.'; | ||
return message; | ||
} |
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,22 @@ | ||
import { createMessage } from "../src/notificationRequestParser.js"; | ||
|
||
const jsonData = '{"startTime":1699715640000,"endTime":1699719240000,"venueName":"HotFut GachiBowli","reservedPlayersCount":10,"charges":200,"venueLocationLink":"https://goo.gl/maps/1QzakRkJPHxT8GjRA","localTimeZone":"GMT+5:30","playerNameList":["Player1","Player2","sam","nooo"]}'; | ||
const expected = `HotFut GachiBowli (https://goo.gl/maps/1QzakRkJPHxT8GjRA) | ||
20:44 - 21:44 11-10-2023 (Saturday) | ||
5v5 | ||
₹200/- Per Person. | ||
Confirmed Players: | ||
1. Player1 | ||
2. Player2 | ||
3. sam | ||
4. nooo | ||
Please pay at play.flickmatch.in to confirm your spot.`; | ||
|
||
function assertEqual(actual, expected, label) { | ||
const areEqual = JSON.stringify(actual) === JSON.stringify(expected); | ||
console.assert(areEqual, `Assertion failed for ${label}:`, actual); | ||
}; | ||
|
||
assertEqual(createMessage(JSON.parse(jsonData)), expected, 'createMessage test'); |