From abd17bea1f7a8ecccee5984a23b7c2b39bcbc266 Mon Sep 17 00:00:00 2001 From: Alex Andru Date: Fri, 5 Jan 2024 21:01:54 +0100 Subject: [PATCH 1/6] Rename developmentsMenu to ourDevelopmentsMenu --- src/controllers/developments.ts | 4 +-- ...lopmentsMenu.ts => ourDevelopmentsMenu.ts} | 2 +- src/menus/propertyMenu.ts | 30 +++++++++++-------- src/menus/salisolResortMenu.ts | 0 4 files changed, 21 insertions(+), 15 deletions(-) rename src/menus/{developmentsMenu.ts => ourDevelopmentsMenu.ts} (84%) create mode 100644 src/menus/salisolResortMenu.ts diff --git a/src/controllers/developments.ts b/src/controllers/developments.ts index 119c036..8e4cbfb 100644 --- a/src/controllers/developments.ts +++ b/src/controllers/developments.ts @@ -1,12 +1,12 @@ import { Composer } from "grammy"; import type { CustomContext } from "../types/context.js"; -import { developmentsMenu } from "../menus/developmentsMenu.js"; +import { ourDevelopmentsMenu } from "../menus/ourDevelopmentsMenu.js"; export const developmentsController = new Composer(); developmentsController.callbackQuery("view-developments", async ctx => { ctx.answerCallbackQuery(); await ctx.reply("Please select the development", { - reply_markup: developmentsMenu + reply_markup: ourDevelopmentsMenu }); }); diff --git a/src/menus/developmentsMenu.ts b/src/menus/ourDevelopmentsMenu.ts similarity index 84% rename from src/menus/developmentsMenu.ts rename to src/menus/ourDevelopmentsMenu.ts index 83e0b1d..53e40dd 100644 --- a/src/menus/developmentsMenu.ts +++ b/src/menus/ourDevelopmentsMenu.ts @@ -1,6 +1,6 @@ import { InlineKeyboard } from "grammy"; -export const developmentsMenu = new InlineKeyboard() +export const ourDevelopmentsMenu = new InlineKeyboard() .text( "🏠 SaliSol Resort - Guardamar, Spain", "view-development:salisol-resort" diff --git a/src/menus/propertyMenu.ts b/src/menus/propertyMenu.ts index 41d92c2..c12b287 100644 --- a/src/menus/propertyMenu.ts +++ b/src/menus/propertyMenu.ts @@ -3,39 +3,45 @@ 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}` - ); + .text("πŸ“ž Contact me about this property", `contact_property_${propertyId}`) + .row() + .url("πŸ–ΌοΈ Our Dropbox", salisolHillsDropboxUrl); 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}` - ); + .text("πŸ“ž Contact me about this property", `contact_property_${propertyId}`) + .row() + .url("πŸ–ΌοΈ Our Dropbox", salisolHillsDropboxUrl); 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}` - ); + .text("πŸ“ž Contact me about this property", `contact_property_${propertyId}`) + .row() + .url("πŸ–ΌοΈ Our Dropbox", salisolHillsDropboxUrl); return keyboard; }; diff --git a/src/menus/salisolResortMenu.ts b/src/menus/salisolResortMenu.ts new file mode 100644 index 0000000..e69de29 From 53c3f406458b6be514ce48132b8d04ec16d43365 Mon Sep 17 00:00:00 2001 From: Alex Andru Date: Sat, 6 Jan 2024 00:10:18 +0100 Subject: [PATCH 2/6] Add dynamic detail menu for developments --- src/menus/developmentDetailMenu.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/menus/developmentDetailMenu.ts diff --git a/src/menus/developmentDetailMenu.ts b/src/menus/developmentDetailMenu.ts new file mode 100644 index 0000000..bcd0667 --- /dev/null +++ b/src/menus/developmentDetailMenu.ts @@ -0,0 +1,20 @@ +import { InlineKeyboard } from "grammy"; +import type { DevelopmentFromDb } from "../types/database"; + +export const developerDetailMenuCreator = ( + development: DevelopmentFromDb +): InlineKeyboard => { + const { name, googleMapsUrl, dropboxUrl, phoneNumber } = development; + const developerDetailMenu = new InlineKeyboard() + .text("View Properties", `view-properties ${name}`) + .row() + .text("Request a showing", `request-showing ${name}`) + .row() + .url("πŸ“Œ View on Google Maps", googleMapsUrl) + .row() + .url("πŸ–ΌοΈ View Dropbox", dropboxUrl) + .row() + .url("πŸ“ž Call Sales Team", `tel:${phoneNumber}`); + + return developerDetailMenu; +}; From 7e81a2aac7bc16ac105dfb2c9d6f097716175d76 Mon Sep 17 00:00:00 2001 From: Alex Andru Date: Sat, 6 Jan 2024 00:13:47 +0100 Subject: [PATCH 3/6] Add callbackQuery for view-development to controller --- sampleData/developmentsSampleData.json | 23 ++++++++++++ .../propertiesSampleData.json | 0 src/config/database.ts | 14 ++++---- src/controllers/developments.ts | 35 ++++++++++--------- src/types/database.ts | 10 ++++++ 5 files changed, 60 insertions(+), 22 deletions(-) create mode 100644 sampleData/developmentsSampleData.json rename propertiesSampleData.json => sampleData/propertiesSampleData.json (100%) diff --git a/sampleData/developmentsSampleData.json b/sampleData/developmentsSampleData.json new file mode 100644 index 0000000..76feb65 --- /dev/null +++ b/sampleData/developmentsSampleData.json @@ -0,0 +1,23 @@ +[ + { + "name": "SaliSol Resort", + "dropboxUrl": "https://www.dropbox.com/sh/t49hfiy9nlc61vh/AACAPSVNxb7w8IM8QAUYyLNVa?dl=0A", + "googleMapsUrl": "https://maps.app.goo.gl/o22J9WNxTdUcdbHR6", + "presentationVideoFileId": "12345", + "phoneNumber": "+34607862954 " + }, + { + "name": "SaliSol Golf", + "dropboxUrl": "https://www.dropbox.com/sh/1jl3z0t28ia86xf/AABqTv8S39H7wpmfdpJS8aQWa?dl=0", + "googleMapsUrl": "https://maps.app.goo.gl/EvzDpeqqWr3ubYxk7", + "presentationVideoFileId": "12345", + "phoneNumber": "+34607862954" + }, + { + "name": "SaliSol Hills", + "dropboxUrl": "https://www.dropbox.com/sh/t6330gcog0lz7dh/AADqYOkfEnvIQ0RF6Lr0eRBja?dl=0", + "googleMapsUrl": "https://maps.app.goo.gl/FRF1Yo6D5cSDGbBGA", + "presentationVideoFileId": "12345", + "phoneNumber": "+34605632401" + } +] diff --git a/propertiesSampleData.json b/sampleData/propertiesSampleData.json similarity index 100% rename from propertiesSampleData.json rename to sampleData/propertiesSampleData.json diff --git a/src/config/database.ts b/src/config/database.ts index 7bbaf61..ce25894 100644 --- a/src/config/database.ts +++ b/src/config/database.ts @@ -1,9 +1,10 @@ import { MongoClient } from "mongodb"; -import type { - Chat, - Database, - PropertyFromDb, - User +import type { DevelopmentFromDb } from "../types/database.js"; +import { + type Chat, + type Database, + type PropertyFromDb, + type User } from "../types/database.js"; export async function connectToDb() { @@ -13,6 +14,7 @@ export async function connectToDb() { const user = mongoDb.collection("user"); const chat = mongoDb.collection("chat"); const property = mongoDb.collection("properties"); - const database: Database = { user, chat, property }; + const development = mongoDb.collection("developments"); + const database: Database = { user, chat, property, development }; return database; } diff --git a/src/controllers/developments.ts b/src/controllers/developments.ts index 8e4cbfb..b916577 100644 --- a/src/controllers/developments.ts +++ b/src/controllers/developments.ts @@ -11,25 +11,28 @@ developmentsController.callbackQuery("view-developments", async ctx => { }); developmentsController.callbackQuery( - "view-development:salisol-resort", + /^view-development:\s*(.+)$/, async ctx => { - ctx.answerCallbackQuery(); - await ctx.reply("SaliSol Resort Selected"); - } -); + const selectedDevelopment = ctx.match[1]; + let developmentName: string; + switch (selectedDevelopment) { + case "salisol-resort": + developmentName = "SaliSol Resort"; + break; + case "salisol-hills": + developmentName = "SaliSol Hills"; + break; + case "salisol-golf": + developmentName = "SaliSol Golf"; + break; + default: + throw new Error("Development not found"); + } -developmentsController.callbackQuery( - "view-development:salisol-hills", - async ctx => { ctx.answerCallbackQuery(); - await ctx.reply("SaliSol Hills Selected"); - } -); -developmentsController.callbackQuery( - "view-development:salisol-golf", - async ctx => { - ctx.answerCallbackQuery(); - await ctx.reply("SaliSol Golf Selected"); + await ctx.db.development.findOne({ name: developmentName }); + + await ctx.reply(`${developmentName} selected`); } ); diff --git a/src/types/database.ts b/src/types/database.ts index 5a6b2d4..3d858a8 100644 --- a/src/types/database.ts +++ b/src/types/database.ts @@ -21,6 +21,15 @@ export interface Property { websiteUrl: string; } +export interface DevelopmentFromDb { + _id: ObjectId; + name: string; + dropboxUrl: string; + googleMapsUrl: string; + presentationVideoFileId?: string; + phoneNumber: string; +} + export interface PropertyFromDb { _id: ObjectId; collection: "SaliSol Hills" | "SaliSol Resort" | "SaliSol Golf"; @@ -45,4 +54,5 @@ export interface Database { user: Collection; chat: Collection; property: Collection; + development: Collection; } From 5c8979661e90c57fbc45b6d51e0cf8fcedf80f97 Mon Sep 17 00:00:00 2001 From: Alex Andru Date: Sat, 6 Jan 2024 00:32:06 +0100 Subject: [PATCH 4/6] Add 'back' button to ourDevelopmentsMenu --- src/controllers/start.ts | 11 +++++++++++ src/menus/ourDevelopmentsMenu.ts | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/controllers/start.ts b/src/controllers/start.ts index 8b52740..1a79d66 100644 --- a/src/controllers/start.ts +++ b/src/controllers/start.ts @@ -12,3 +12,14 @@ startController.command("start", async ctx => { { reply_markup: startMenu } ); }); + +startController.callbackQuery("start", async ctx => { + ctx.answerCallbackQuery(); + const salisolLogoUrl = + "https://lh3.googleusercontent.com/u/0/drive-viewer/AEYmBYSo6VRezOEbJpP0wzkLbT9JQ_f_HbNJw_MgzN45az99ZU5qvOe3Ad5N7qWGlHg_5iIUrRO-2sb82LOgcd-cOuBt8vNLSg=w2560-h1204"; + await ctx.replyWithPhoto(salisolLogoUrl); + await ctx.reply( + `Hello ${ctx.config.user.name}, welcome to SaliSolβ˜€οΈπŸ  - 30 years developing properties on Spain's Costa Blanca.\nHow can we help you?`, + { reply_markup: startMenu } + ); +}); diff --git a/src/menus/ourDevelopmentsMenu.ts b/src/menus/ourDevelopmentsMenu.ts index 53e40dd..bbef0e2 100644 --- a/src/menus/ourDevelopmentsMenu.ts +++ b/src/menus/ourDevelopmentsMenu.ts @@ -8,4 +8,6 @@ export const ourDevelopmentsMenu = new InlineKeyboard() .row() .text("πŸ”οΈ SaliSol Hills - Benidorm, Spain", "view-development:salisol-hills") .row() - .text("β›³ SaliSol Golf - Benidorm, Spain", "view-development:salisol-golf"); + .text("β›³ SaliSol Golf - Benidorm, Spain", "view-development:salisol-golf") + .row() + .text("πŸ”™ Back", "start"); From 7adc0307fab6909cf845c2a0ac180875c0189a07 Mon Sep 17 00:00:00 2001 From: Alex Andru Date: Sat, 6 Jan 2024 00:42:38 +0100 Subject: [PATCH 5/6] Add 'back' button to developerDetailMenuCreator --- sampleData/developmentsSampleData.json | 6 +++--- src/controllers/developments.ts | 14 +++++++++++--- src/menus/developmentDetailMenu.ts | 4 ++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/sampleData/developmentsSampleData.json b/sampleData/developmentsSampleData.json index 76feb65..081a2f9 100644 --- a/sampleData/developmentsSampleData.json +++ b/sampleData/developmentsSampleData.json @@ -4,20 +4,20 @@ "dropboxUrl": "https://www.dropbox.com/sh/t49hfiy9nlc61vh/AACAPSVNxb7w8IM8QAUYyLNVa?dl=0A", "googleMapsUrl": "https://maps.app.goo.gl/o22J9WNxTdUcdbHR6", "presentationVideoFileId": "12345", - "phoneNumber": "+34607862954 " + "phoneNumber": "0034607862954" }, { "name": "SaliSol Golf", "dropboxUrl": "https://www.dropbox.com/sh/1jl3z0t28ia86xf/AABqTv8S39H7wpmfdpJS8aQWa?dl=0", "googleMapsUrl": "https://maps.app.goo.gl/EvzDpeqqWr3ubYxk7", "presentationVideoFileId": "12345", - "phoneNumber": "+34607862954" + "phoneNumber": "0034607862954" }, { "name": "SaliSol Hills", "dropboxUrl": "https://www.dropbox.com/sh/t6330gcog0lz7dh/AADqYOkfEnvIQ0RF6Lr0eRBja?dl=0", "googleMapsUrl": "https://maps.app.goo.gl/FRF1Yo6D5cSDGbBGA", "presentationVideoFileId": "12345", - "phoneNumber": "+34605632401" + "phoneNumber": "0034605632401" } ] diff --git a/src/controllers/developments.ts b/src/controllers/developments.ts index b916577..ff9a1d1 100644 --- a/src/controllers/developments.ts +++ b/src/controllers/developments.ts @@ -1,6 +1,7 @@ import { Composer } from "grammy"; import type { CustomContext } from "../types/context.js"; import { ourDevelopmentsMenu } from "../menus/ourDevelopmentsMenu.js"; +import { developerDetailMenuCreator } from "../menus/developmentDetailMenu.js"; export const developmentsController = new Composer(); developmentsController.callbackQuery("view-developments", async ctx => { @@ -31,8 +32,15 @@ developmentsController.callbackQuery( ctx.answerCallbackQuery(); - await ctx.db.development.findOne({ name: developmentName }); - - await ctx.reply(`${developmentName} selected`); + const development = await ctx.db.development.findOne({ + name: developmentName + }); + if (!development) { + return; + } + const developmentKeyboard = developerDetailMenuCreator(development); + await ctx.reply(`*${developmentName}*`, { + reply_markup: developmentKeyboard + }); } ); diff --git a/src/menus/developmentDetailMenu.ts b/src/menus/developmentDetailMenu.ts index bcd0667..c54d1c7 100644 --- a/src/menus/developmentDetailMenu.ts +++ b/src/menus/developmentDetailMenu.ts @@ -4,7 +4,7 @@ import type { DevelopmentFromDb } from "../types/database"; export const developerDetailMenuCreator = ( development: DevelopmentFromDb ): InlineKeyboard => { - const { name, googleMapsUrl, dropboxUrl, phoneNumber } = development; + const { name, googleMapsUrl, dropboxUrl } = development; const developerDetailMenu = new InlineKeyboard() .text("View Properties", `view-properties ${name}`) .row() @@ -14,7 +14,7 @@ export const developerDetailMenuCreator = ( .row() .url("πŸ–ΌοΈ View Dropbox", dropboxUrl) .row() - .url("πŸ“ž Call Sales Team", `tel:${phoneNumber}`); + .text("πŸ”™ Back", "view-developments"); return developerDetailMenu; }; From bca00eceec9067e87b852039e31ea206a5f2bf4c Mon Sep 17 00:00:00 2001 From: Alex Andru Date: Sat, 6 Jan 2024 01:39:13 +0100 Subject: [PATCH 6/6] Add view-properties callbackQuery to propertiesController --- src/controllers/developments.ts | 3 +- src/controllers/properties.ts | 45 +++++++++++-------- src/helpers/isDevelopmentType.ts | 11 +++++ src/menus/propertyMenu.ts | 16 ++----- src/services/Notifications/notifySalesTeam.ts | 2 +- src/services/Property/property.service.ts | 8 ++-- src/types/database.ts | 7 ++- 7 files changed, 54 insertions(+), 38 deletions(-) create mode 100644 src/helpers/isDevelopmentType.ts 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;