Skip to content

Commit 6e6eea1

Browse files
committed
message: fix send contact payload
1 parent dda5384 commit 6e6eea1

3 files changed

Lines changed: 85 additions & 78 deletions

File tree

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,12 @@ await client.messages.sendLocation({
303303
// Send contact
304304
await client.messages.sendContact({
305305
number: "5511999999999",
306-
contact: {
307-
fullName: "John Doe",
308-
phones: ["5511999999999"],
309-
},
306+
contact: [
307+
{
308+
fullName: "John Doe",
309+
phones: ["5511999999999"],
310+
},
311+
],
310312
});
311313

312314
// Send reaction

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "evolution-api-sdk",
33
"private": false,
4-
"version": "0.6.1",
4+
"version": "0.6.2",
55
"description": "Unofficial SDK for the Evolution Whatsapp API v2",
66
"main": "lib/index.js",
77
"types": "lib/index.d.ts",

src/modules/messages/schemas/contact.ts

Lines changed: 78 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -6,98 +6,103 @@ import { BaseMessageOptions } from "./base";
66

77
// Raw response interface from API
88
export interface ContactMessageResponseRaw {
9-
key: {
10-
remoteJid: string;
11-
id: string;
12-
};
13-
message: {
14-
contactMessage?: {
15-
displayName: string;
16-
vcard: string;
17-
};
18-
contactsArrayMessage?: {
19-
contacts: {
20-
displayName: string;
21-
vcard: string;
22-
}[];
23-
};
24-
};
25-
messageTimestamp: string | Date;
9+
key: {
10+
remoteJid: string;
11+
id: string;
12+
};
13+
message: {
14+
contactMessage?: {
15+
displayName: string;
16+
vcard: string;
17+
};
18+
contactsArrayMessage?: {
19+
contacts: {
20+
displayName: string;
21+
vcard: string;
22+
}[];
23+
};
24+
};
25+
messageTimestamp: string | Date;
2626
}
2727

2828
// Request interfaces
2929
export interface Contact {
30-
/**
31-
* Contact display name
32-
*/
33-
fullName: string;
34-
/**
35-
* Contact phone number
36-
*/
37-
phoneNumber: string;
38-
/**
39-
* Contact organization
40-
*/
41-
organization?: string;
42-
/**
43-
* Contact email
44-
*/
45-
email?: string;
46-
/**
47-
* Contact website url
48-
*/
49-
url?: string;
30+
/**
31+
* Contact display name
32+
*/
33+
fullName: string;
34+
/**
35+
* Contact phone number
36+
*/
37+
phoneNumber: string;
38+
/**
39+
* Contact organization
40+
*/
41+
organization?: string;
42+
/**
43+
* Contact email
44+
*/
45+
email?: string;
46+
/**
47+
* Contact website url
48+
*/
49+
url?: string;
5050
}
5151

5252
export interface ContactMessageOptions extends BaseMessageOptions {
53-
/**
54-
* Contact list
55-
*/
56-
contacts: Contact[];
53+
/**
54+
* Contact list
55+
*/
56+
contact: Contact[];
5757
}
5858

5959
export interface ContactMessageBody extends BaseMessageOptions {
60-
contact: (Contact & {
61-
wuid: string;
62-
})[];
60+
contact: (Contact & {
61+
wuid: string;
62+
})[];
6363
}
6464

6565
// Response interfaces
6666
export interface ContactMessageResponse {
67-
receiver: {
68-
phoneNumber: string;
69-
jid: Jid;
70-
};
71-
contacts: {
72-
displayName: string;
73-
vcard: string;
74-
}[];
75-
id: MessageId;
76-
timestamp: Date;
67+
receiver: {
68+
phoneNumber: string;
69+
jid: Jid;
70+
};
71+
contacts: {
72+
displayName: string;
73+
vcard: string;
74+
}[];
75+
id: MessageId;
76+
timestamp: Date;
7777
}
7878

7979
// Transform functions
80-
export const ContactMessageBodyTransform = (
81-
{ contacts, ...data }: ContactMessageOptions
82-
): ContactMessageBody => ({
83-
...data,
84-
contact: contacts.map((contact) => ({
85-
...contact,
86-
phoneNumber: parsePhoneNumber(contact.phoneNumber).formatInternational(),
87-
wuid: contact.phoneNumber.replace(/\D/g, ""),
88-
})),
80+
export const ContactMessageBodyTransform = ({
81+
contact,
82+
...data
83+
}: ContactMessageOptions): ContactMessageBody => ({
84+
...data,
85+
contact: contact.map((contactItem) => ({
86+
...contactItem,
87+
phoneNumber: parsePhoneNumber(
88+
contactItem.phoneNumber
89+
).formatInternational(),
90+
wuid: contactItem.phoneNumber.replace(/\D/g, ""),
91+
})),
8992
});
9093

91-
export const ContactMessageResponseTransform = (data: ContactMessageResponseRaw): ContactMessageResponse => ({
92-
receiver: {
93-
phoneNumber: phoneNumberFromJid(data.key.remoteJid),
94-
jid: Jid(data.key.remoteJid),
95-
},
96-
contacts: data.message.contactMessage
97-
? [data.message.contactMessage]
98-
: data.message.contactsArrayMessage?.contacts || [],
99-
id: MessageId(data.key.id),
100-
timestamp: new Date(data.messageTimestamp),
94+
export const ContactMessageResponseTransform = (
95+
data: ContactMessageResponseRaw
96+
): ContactMessageResponse => ({
97+
receiver: {
98+
phoneNumber: phoneNumberFromJid(data.key.remoteJid),
99+
jid: Jid(data.key.remoteJid),
100+
},
101+
contacts: data.message.contactMessage
102+
? [data.message.contactMessage]
103+
: data.message.contactsArrayMessage?.contacts || [],
104+
id: MessageId(data.key.id),
105+
timestamp: new Date(data.messageTimestamp),
101106
});
102107

103108
// Backward compatibility aliases

0 commit comments

Comments
 (0)