Skip to content

Commit 9003f4a

Browse files
committed
feat(messages): replace {{greeting}} with time-based greeting in pt-BR
1 parent a3c0d5f commit 9003f4a

File tree

7 files changed

+32
-5
lines changed

7 files changed

+32
-5
lines changed

.changeset/grumpy-coats-float.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solufy/evolution-sdk": patch
3+
---
4+
5+
Replace `{{greeting}}` with with time-based greeting in pt-BR at all messages and captions.

src/modules/messages/schemas/document.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as z from "zod";
22

33
import { mediaSchema } from "@/schemas/common";
44
import { Jid, MessageId } from "@/types/tags";
5+
import { replaceWithGreeting } from "@/utils/greeting";
56
import { phoneNumberFromJid } from "@/utils/phone-numer-from-jid";
67

78
import { BaseMessageOptionsSchema } from "./base";
@@ -14,7 +15,7 @@ export const DocumentMessageOptionsSchema = BaseMessageOptionsSchema.extend({
1415
/**
1516
* Caption to send with document
1617
*/
17-
caption: z.string().optional(),
18+
caption: z.string().optional().overwrite(replaceWithGreeting),
1819
/**
1920
* Document mimetype
2021
*/

src/modules/messages/schemas/image.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as z from "zod";
22

33
import { mediaSchema } from "@/schemas/common";
44
import { Jid, MessageId } from "@/types/tags";
5+
import { replaceWithGreeting } from "@/utils/greeting";
56
import { phoneNumberFromJid } from "@/utils/phone-numer-from-jid";
67

78
import { BaseMessageOptionsSchema } from "./base";
@@ -14,7 +15,7 @@ export const ImageMessageOptionsSchema = BaseMessageOptionsSchema.extend({
1415
/**
1516
* Caption to send with image
1617
*/
17-
caption: z.string().optional(),
18+
caption: z.string().optional().overwrite(replaceWithGreeting),
1819
/**
1920
* Image mimetype
2021
*/

src/modules/messages/schemas/poll.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as z from "zod";
22

33
import { Jid, MessageId } from "@/types/tags";
4+
import { replaceWithGreeting } from "@/utils/greeting";
45
import { phoneNumberFromJid } from "@/utils/phone-numer-from-jid";
56

67
import { BaseMessageOptionsSchema } from "./base";
@@ -9,7 +10,7 @@ export const PollMessageOptionsSchema = BaseMessageOptionsSchema.extend({
910
/**
1011
* Name of the poll
1112
*/
12-
name: z.string(),
13+
name: z.string().overwrite(replaceWithGreeting),
1314
/**
1415
* Whether multiple options can be selected
1516
* @default false

src/modules/messages/schemas/text.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as z from "zod";
22

33
import { Jid, MessageId } from "@/types/tags";
4+
import { replaceWithGreeting } from "@/utils/greeting";
45
import { phoneNumberFromJid } from "@/utils/phone-numer-from-jid";
56

67
import { BaseMessageOptionsSchema } from "./base";
@@ -9,7 +10,7 @@ export const TextMessageOptionsSchema = BaseMessageOptionsSchema.extend({
910
/**
1011
* Message text content
1112
*/
12-
text: z.string(),
13+
text: z.string().overwrite(replaceWithGreeting),
1314
/**
1415
* Whether link preview should be shown
1516
*/

src/modules/messages/schemas/video.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as z from "zod";
22

33
import { mediaSchema } from "@/schemas/common";
44
import { Jid, MessageId } from "@/types/tags";
5+
import { replaceWithGreeting } from "@/utils/greeting";
56
import { phoneNumberFromJid } from "@/utils/phone-numer-from-jid";
67

78
import { BaseMessageOptionsSchema } from "./base";
@@ -14,7 +15,7 @@ export const VideoMessageOptionsSchema = BaseMessageOptionsSchema.extend({
1415
/**
1516
* Caption to send with video
1617
*/
17-
caption: z.string().optional(),
18+
caption: z.string().optional().overwrite(replaceWithGreeting),
1819
/**
1920
* Video mimetype
2021
*/

src/utils/greeting.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export function getGreeting(
2+
date: Date = new Date(),
3+
timeZone: string = "America/Sao_Paulo",
4+
): string {
5+
const timeInTimezone = new Date(date.toLocaleString("en-US", { timeZone }));
6+
const hours = timeInTimezone.getHours();
7+
8+
if (hours >= 5 && hours < 12) return "Bom dia"; // Good morning (5:00 - 11:59)
9+
if (hours >= 12 && hours < 18) return "Boa tarde"; // Good afternoon (12:00 - 17:59)
10+
return "Boa noite"; // Good evening/night (18:00 - 4:59)
11+
}
12+
13+
export function replaceWithGreeting(value: string): string;
14+
export function replaceWithGreeting(value?: string): string | undefined;
15+
export function replaceWithGreeting(value?: string): string | undefined {
16+
return value?.replaceAll("{{greeting}}", getGreeting());
17+
}

0 commit comments

Comments
 (0)