diff --git a/src/controllers/developments.ts b/src/controllers/developments.ts index ff9a1d1..dec026b 100644 --- a/src/controllers/developments.ts +++ b/src/controllers/developments.ts @@ -40,7 +40,8 @@ developmentsController.callbackQuery( } const developmentKeyboard = developerDetailMenuCreator(development); await ctx.reply(`*${developmentName}*`, { - reply_markup: developmentKeyboard + reply_markup: developmentKeyboard, + parse_mode: "MarkdownV2" }); } ); diff --git a/src/controllers/properties.ts b/src/controllers/properties.ts index 57a9cb4..6c4c76f 100644 --- a/src/controllers/properties.ts +++ b/src/controllers/properties.ts @@ -2,29 +2,36 @@ import { Composer } from "grammy"; import type { CustomContext } from "../types/context.js"; import type { PropertyFromDb } from "../types/database.js"; import { displayProperty } from "../services/Property/property.service.js"; +import isDevelopmentType from "../helpers/isDevelopmentType.js"; export const propertiesController = new Composer(); + let currentPropertyIndex = 0; -propertiesController.command("properties", async ctx => { - const properties = (await ctx.db.property - .find({}) - .toArray()) as PropertyFromDb[]; - await displayProperty(ctx, properties, currentPropertyIndex); +propertiesController.callbackQuery(/^view-properties \s*(.+)$/, async ctx => { + const chosenDevelopment = ctx.match[1]; + ctx.answerCallbackQuery(); + if (isDevelopmentType(chosenDevelopment)) { + const properties = (await ctx.db.property + .find({ development: chosenDevelopment }) + .toArray()) as PropertyFromDb[]; + await displayProperty(ctx, properties, currentPropertyIndex); - propertiesController.callbackQuery("next-property", async ctx => { - ctx.answerCallbackQuery(""); - if (currentPropertyIndex + 1 < properties.length) { - currentPropertyIndex++; - await displayProperty(ctx, properties, currentPropertyIndex); - } - }); + propertiesController.callbackQuery("next-property", async ctx => { + ctx.answerCallbackQuery(""); + if (currentPropertyIndex + 1 < properties.length) { + currentPropertyIndex++; + await displayProperty(ctx, properties, currentPropertyIndex); + } + }); - propertiesController.callbackQuery("previous-property", async ctx => { - ctx.answerCallbackQuery(""); - if (currentPropertyIndex + 1 > 0) { - currentPropertyIndex--; - await displayProperty(ctx, properties, currentPropertyIndex); - } - }); + propertiesController.callbackQuery("previous-property", async ctx => { + ctx.answerCallbackQuery(""); + if (currentPropertyIndex + 1 > 0) { + currentPropertyIndex--; + await displayProperty(ctx, properties, currentPropertyIndex); + } + }); + } + return; }); diff --git a/src/helpers/isDevelopmentType.ts b/src/helpers/isDevelopmentType.ts new file mode 100644 index 0000000..92a48c9 --- /dev/null +++ b/src/helpers/isDevelopmentType.ts @@ -0,0 +1,11 @@ +import { type DevelopmentType } from "../types/database"; + +const isDevelopmentType = ( + development: string +): development is DevelopmentType => { + return ["SaliSol Hills", "SaliSol Resort", "SaliSol Golf"].includes( + development + ); +}; + +export default isDevelopmentType; diff --git a/src/menus/propertyMenu.ts b/src/menus/propertyMenu.ts index c12b287..dca1f58 100644 --- a/src/menus/propertyMenu.ts +++ b/src/menus/propertyMenu.ts @@ -3,45 +3,37 @@ import { InlineKeyboard } from "grammy"; export const fullPropertyControlKeyboard = ( propertyId: string ): InlineKeyboard => { - const salisolHillsDropboxUrl = - "https://www.dropbox.com/sh/t6330gcog0lz7dh/AADqYOkfEnvIQ0RF6Lr0eRBja?dl=0"; - const keyboard = new InlineKeyboard() .text("ยซ Previous Property", "previous-property") .text("Next Property ยป ", "next-property") .row() .text("๐Ÿ“ž Contact me about this property", `contact_property_${propertyId}`) .row() - .url("๐Ÿ–ผ๏ธ Our Dropbox", salisolHillsDropboxUrl); + .text("๐Ÿ”™ Back", "view-developments"); + return keyboard; }; export const nextPropertyControlKeyboard = ( propertyId: string ): InlineKeyboard => { - const salisolHillsDropboxUrl = - "https://www.dropbox.com/sh/t6330gcog0lz7dh/AADqYOkfEnvIQ0RF6Lr0eRBja?dl=0"; - const keyboard = new InlineKeyboard() .text("Next Property ยป ", "next-property") .row() .text("๐Ÿ“ž Contact me about this property", `contact_property_${propertyId}`) .row() - .url("๐Ÿ–ผ๏ธ Our Dropbox", salisolHillsDropboxUrl); + .text("๐Ÿ”™ Back", "view-developments"); return keyboard; }; export const previousPropertyControlKeyboard = ( propertyId: string ): InlineKeyboard => { - const salisolHillsDropboxUrl = - "https://www.dropbox.com/sh/t6330gcog0lz7dh/AADqYOkfEnvIQ0RF6Lr0eRBja?dl=0"; - const keyboard = new InlineKeyboard() .text("ยซ Previous Property", "previous-property") .row() .text("๐Ÿ“ž Contact me about this property", `contact_property_${propertyId}`) .row() - .url("๐Ÿ–ผ๏ธ Our Dropbox", salisolHillsDropboxUrl); + .text("๐Ÿ”™ Back", "view-developments"); return keyboard; }; diff --git a/src/services/Notifications/notifySalesTeam.ts b/src/services/Notifications/notifySalesTeam.ts index aa691d2..e58e869 100644 --- a/src/services/Notifications/notifySalesTeam.ts +++ b/src/services/Notifications/notifySalesTeam.ts @@ -19,7 +19,7 @@ export const notifySalesTeam = async ( const formattedNotificationMessage = `A new client is requesting information:\nName: ${userName}\nUser: @${userClickable}\n${ propertyOfInterest - ? `Interested in ${propertyOfInterest.collection} ${propertyOfInterest.name}` + ? `Interested in ${propertyOfInterest.development} ${propertyOfInterest.name}` : "" }`; diff --git a/src/services/Property/property.service.ts b/src/services/Property/property.service.ts index fd1f8a1..ed573cb 100644 --- a/src/services/Property/property.service.ts +++ b/src/services/Property/property.service.ts @@ -13,7 +13,7 @@ export const generatePropertyDescription = ( ): string => { const { name, - collection, + development, availability, price, plotMetersSquared, @@ -21,7 +21,7 @@ export const generatePropertyDescription = ( } = property; // Property description uses Telegram's Markdown V2 - const propertyDescription = `*๐Ÿ  ${collection}: ${name}*\n\nPlot Size: ${plotMetersSquared}m2 \nBuilt Meters: ${builtMetersSquared}m2\nPrice: ${price + const propertyDescription = `*๐Ÿ  ${development}: ${name}*\n\nPlot Size: ${plotMetersSquared}m2 \nBuilt Meters: ${builtMetersSquared}m2\nPrice: ${price .toString() .replace(/\B(?=(\d{3})+(?!\d))/g, ",")}โ‚ฌ${ availability ? "" : "Reserved" @@ -54,7 +54,7 @@ export const displayProperty = async ( const currentPropertyId = currentProperty._id.toString(); let controlKeyboard; - if (currentPropertyIndex == 0) { + if (currentPropertyIndex == 0 && totalProperties > 1) { controlKeyboard = nextPropertyControlKeyboard(currentPropertyId); } else if (currentPropertyIndex + 1 < totalProperties) { controlKeyboard = fullPropertyControlKeyboard(currentPropertyId); @@ -72,6 +72,6 @@ export const displayProperty = async ( await ctx.replyWithVideo(videoFileId); await ctx.replyWithMediaGroup(propertyPhotoAlbum); await ctx.reply(`Property ${currentPropertyIndex + 1}/${totalProperties}`, { - reply_markup: controlKeyboard + reply_markup: controlKeyboard ?? undefined }); }; diff --git a/src/types/database.ts b/src/types/database.ts index 3d858a8..4877b87 100644 --- a/src/types/database.ts +++ b/src/types/database.ts @@ -30,9 +30,13 @@ export interface DevelopmentFromDb { phoneNumber: string; } +export type DevelopmentType = + | "SaliSol Hills" + | "SaliSol Resort" + | "SaliSol Golf"; export interface PropertyFromDb { _id: ObjectId; - collection: "SaliSol Hills" | "SaliSol Resort" | "SaliSol Golf"; + development: DevelopmentType; name: string; price: number; availability: boolean; @@ -45,6 +49,7 @@ export interface PropertyFromDb { telegramContactUrl: string; websiteUrl: string; } + export interface Chat { chatId: number; title: string;