File tree Expand file tree Collapse file tree 7 files changed +32
-5
lines changed
Expand file tree Collapse file tree 7 files changed +32
-5
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @solufy/evolution-sdk " : patch
3+ ---
4+
5+ Replace ` {{greeting}} ` with with time-based greeting in pt-BR at all messages and captions.
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import * as z from "zod";
22
33import { mediaSchema } from "@/schemas/common" ;
44import { Jid , MessageId } from "@/types/tags" ;
5+ import { replaceWithGreeting } from "@/utils/greeting" ;
56import { phoneNumberFromJid } from "@/utils/phone-numer-from-jid" ;
67
78import { 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 */
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import * as z from "zod";
22
33import { mediaSchema } from "@/schemas/common" ;
44import { Jid , MessageId } from "@/types/tags" ;
5+ import { replaceWithGreeting } from "@/utils/greeting" ;
56import { phoneNumberFromJid } from "@/utils/phone-numer-from-jid" ;
67
78import { 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 */
Original file line number Diff line number Diff line change 11import * as z from "zod" ;
22
33import { Jid , MessageId } from "@/types/tags" ;
4+ import { replaceWithGreeting } from "@/utils/greeting" ;
45import { phoneNumberFromJid } from "@/utils/phone-numer-from-jid" ;
56
67import { 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
Original file line number Diff line number Diff line change 11import * as z from "zod" ;
22
33import { Jid , MessageId } from "@/types/tags" ;
4+ import { replaceWithGreeting } from "@/utils/greeting" ;
45import { phoneNumberFromJid } from "@/utils/phone-numer-from-jid" ;
56
67import { 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 */
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import * as z from "zod";
22
33import { mediaSchema } from "@/schemas/common" ;
44import { Jid , MessageId } from "@/types/tags" ;
5+ import { replaceWithGreeting } from "@/utils/greeting" ;
56import { phoneNumberFromJid } from "@/utils/phone-numer-from-jid" ;
67
78import { 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 */
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments