generated from QuantGeekDev/ts-tg-bot
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d38b4d4
commit f8f0f0b
Showing
8 changed files
with
2,502 additions
and
121 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
import { MongoClient } from "mongodb"; | ||
import type { Chat, Database, Property, User } from "../types/database.js"; | ||
import type { | ||
Chat, | ||
Database, | ||
PropertyFromDb, | ||
User | ||
} from "../types/database.js"; | ||
|
||
export async function connectToDb() { | ||
const client = new MongoClient(process.env.DB_CONNECTION_STRING); | ||
await client.connect(); | ||
const mongoDb = client.db(); | ||
const user = mongoDb.collection<User>("user"); | ||
const chat = mongoDb.collection<Chat>("chat"); | ||
const property = mongoDb.collection<Property>("properties"); | ||
const property = mongoDb.collection<PropertyFromDb>("properties"); | ||
const database: Database = { user, chat, property }; | ||
return database; | ||
} |
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,12 +1,19 @@ | ||
import { Composer } from "grammy"; | ||
import type { CustomContext } from "../types/context.js"; | ||
import { notifySalesTeam } from "../services/Admin/notifySalesTeam.js"; | ||
import { notifySalesTeam } from "../services/Notifications/notifySalesTeam.js"; | ||
|
||
export const contactSalesController = new Composer<CustomContext>(); | ||
contactSalesController.callbackQuery("contact-sales", async ctx => { | ||
|
||
contactSalesController.callbackQuery(/contact-sales/, async ctx => { | ||
ctx.answerCallbackQuery(""); | ||
ctx.reply( | ||
"Your request has been registered - an agent will contact you shortly" | ||
); | ||
notifySalesTeam(ctx); | ||
}); | ||
|
||
contactSalesController.callbackQuery(/^contact_property_(.+)$/, async ctx => { | ||
await ctx.answerCallbackQuery(); | ||
const propertyId = ctx.match[1]; | ||
notifySalesTeam(ctx, propertyId); | ||
}); |
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { ObjectId } from "mongodb"; | ||
import type { CustomContext } from "../../types/context"; | ||
import type { PropertyFromDb } from "../../types/database"; | ||
|
||
export const notifySalesTeam = async ( | ||
ctx: CustomContext, | ||
propertyId?: string | ||
) => { | ||
const adminGroupId = process.env.ADMIN_GROUP_ID; | ||
const userId = ctx.config.user.userId; | ||
const userName = ctx.config.user.name; | ||
|
||
const propertyMongoId = new ObjectId(propertyId); | ||
const propertyOfInterest = (await ctx.db.property.findOne({ | ||
_id: propertyMongoId | ||
})) as PropertyFromDb; | ||
|
||
const userClickable = `[${userName}](tg://user?id=${userId})`; | ||
|
||
const formattedNotificationMessage = `A new client is requesting information:\nName: ${userName}\nUser: @${userClickable}\n${ | ||
propertyOfInterest | ||
? `Interested in ${propertyOfInterest.collection} ${propertyOfInterest.name}` | ||
: "" | ||
}`; | ||
|
||
await ctx.api.sendMessage(adminGroupId, formattedNotificationMessage, { | ||
parse_mode: "MarkdownV2" | ||
}); | ||
}; |
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