Skip to content

Commit dffe261

Browse files
committed
[Component]: hey: New components
1 parent 31906cf commit dffe261

File tree

10 files changed

+761
-10
lines changed

10 files changed

+761
-10
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import app from "../../heyy.app.mjs";
2+
3+
export default {
4+
key: "heyy-create-contact",
5+
name: "Create Contact",
6+
description: "Creates a new contact for the business. [See the documentation](https://documenter.getpostman.com/view/27408936/2sA2r3a6DW#a1249b8d-10cf-446a-be35-eb8793ffa967).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
phoneNumber: {
12+
propDefinition: [
13+
app,
14+
"phoneNumber",
15+
],
16+
},
17+
firstName: {
18+
propDefinition: [
19+
app,
20+
"firstName",
21+
],
22+
},
23+
lastName: {
24+
propDefinition: [
25+
app,
26+
"lastName",
27+
],
28+
},
29+
email: {
30+
propDefinition: [
31+
app,
32+
"email",
33+
],
34+
},
35+
labels: {
36+
propDefinition: [
37+
app,
38+
"labels",
39+
],
40+
},
41+
attributes: {
42+
propDefinition: [
43+
app,
44+
"attributes",
45+
],
46+
},
47+
},
48+
methods: {
49+
createContact(args = {}) {
50+
return this.app.post({
51+
path: "/contacts",
52+
...args,
53+
});
54+
},
55+
},
56+
async run({ $ }) {
57+
const {
58+
createContact,
59+
phoneNumber,
60+
firstName,
61+
lastName,
62+
email,
63+
labels,
64+
attributes,
65+
} = this;
66+
67+
const response = await createContact({
68+
$,
69+
data: {
70+
phoneNumber,
71+
firstName,
72+
lastName,
73+
email,
74+
...(labels?.length && {
75+
labels: labels.map((name) => ({
76+
name,
77+
})),
78+
}),
79+
attributes:
80+
attributes && Object.entries(attributes)
81+
.reduce((acc, [
82+
externalId,
83+
value,
84+
]) => ([
85+
...acc,
86+
{
87+
externalId,
88+
value,
89+
},
90+
]), []),
91+
},
92+
});
93+
$.export("$summary", `Successfully created contact with ID \`${response.data.id}\`.`);
94+
return response;
95+
},
96+
};
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
import app from "../../heyy.app.mjs";
2+
import constants from "../../common/constants.mjs";
3+
import utils from "../../common/utils.mjs";
4+
5+
export default {
6+
key: "heyy-send-whatsapp-message",
7+
name: "Send WhatsApp Message",
8+
description: "Sends a WhatsApp message to a contact. [See the documentation](https://documenter.getpostman.com/view/27408936/2sa2r3a6dw)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
app,
13+
channelId: {
14+
propDefinition: [
15+
app,
16+
"channelId",
17+
],
18+
},
19+
phoneNumber: {
20+
label: "Phone Number",
21+
description: "The phone number of the contact.",
22+
propDefinition: [
23+
app,
24+
"contactId",
25+
() => ({
26+
mapper: ({
27+
firstName, phoneNumber: value,
28+
}) => ({
29+
label: firstName || value,
30+
value,
31+
}),
32+
}),
33+
],
34+
},
35+
msgType: {
36+
type: "string",
37+
label: "Message Type",
38+
description: "The type of message to send.",
39+
options: Object.values(constants.MSG_TYPE),
40+
reloadProps: true,
41+
},
42+
},
43+
additionalProps() {
44+
const { msgType } = this;
45+
46+
const bodyText = {
47+
type: "string",
48+
label: "Body Text",
49+
description: "The text of the message to send.",
50+
};
51+
52+
if (msgType === constants.MSG_TYPE.TEXT) {
53+
return {
54+
bodyText,
55+
};
56+
}
57+
58+
if (msgType === constants.MSG_TYPE.IMAGE) {
59+
return {
60+
bodyText,
61+
fileId: {
62+
type: "string",
63+
label: "File ID",
64+
description: "The ID of the file to attach to the message.",
65+
},
66+
};
67+
}
68+
69+
if (msgType === constants.MSG_TYPE.TEMPLATE) {
70+
return {
71+
messageTemplateId: {
72+
type: "string",
73+
label: "Message Template ID",
74+
description: "The ID of the message template to use.",
75+
optional: true,
76+
options: async ({ page }) => {
77+
const { data: { messageTemplates } } = await this.app.getMessageTemplates({
78+
params: {
79+
page,
80+
sortBy: "updatedAt",
81+
order: "DESC",
82+
},
83+
});
84+
return messageTemplates.map(({
85+
id: value, name: label,
86+
}) => ({
87+
label,
88+
value,
89+
}));
90+
},
91+
},
92+
};
93+
}
94+
95+
if (msgType === constants.MSG_TYPE.INTERACTIVE) {
96+
return {
97+
bodyText,
98+
buttons: {
99+
type: "string[]",
100+
label: "Buttons",
101+
description: "The buttons to include in the message. Each row should have a JSON formated string. Eg. `{ \"id\": \"STRING\", \"title\": \"STRING\" }`.",
102+
},
103+
headerText: {
104+
type: "string",
105+
label: "Header Text",
106+
description: "The header text of the message to send.",
107+
optional: true,
108+
},
109+
footerText: {
110+
type: "string",
111+
label: "Footer Text",
112+
description: "The footer text of the message to send.",
113+
optional: true,
114+
},
115+
};
116+
}
117+
118+
return {};
119+
},
120+
methods: {
121+
sendWhatsappMessage({
122+
channelId, ...args
123+
} = {}) {
124+
return this.app.post({
125+
path: `/${channelId}/whatsapp_messages/send`,
126+
...args,
127+
});
128+
},
129+
},
130+
async run({ $ }) {
131+
const {
132+
sendWhatsappMessage,
133+
channelId,
134+
phoneNumber,
135+
msgType,
136+
bodyText,
137+
fileId,
138+
messageTemplateId,
139+
headerText,
140+
footerText,
141+
buttons,
142+
} = this;
143+
144+
const response = await sendWhatsappMessage({
145+
$,
146+
channelId,
147+
data: {
148+
phoneNumber,
149+
type: msgType,
150+
bodyText,
151+
fileId,
152+
messageTemplateId,
153+
headerText,
154+
footerText,
155+
buttons: utils.parseArray(buttons),
156+
},
157+
});
158+
$.export("$summary", "Succesfully sent WhatsApp message.");
159+
return response;
160+
},
161+
};
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import app from "../../heyy.app.mjs";
2+
3+
export default {
4+
key: "heyy-update-contact",
5+
name: "Update Contact",
6+
description: "Updates the details of a contact under your business.",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
contactId: {
12+
propDefinition: [
13+
app,
14+
"contactId",
15+
],
16+
},
17+
phoneNumber: {
18+
optional: true,
19+
propDefinition: [
20+
app,
21+
"phoneNumber",
22+
],
23+
},
24+
firstName: {
25+
optional: true,
26+
propDefinition: [
27+
app,
28+
"firstName",
29+
],
30+
},
31+
lastName: {
32+
propDefinition: [
33+
app,
34+
"lastName",
35+
],
36+
},
37+
email: {
38+
propDefinition: [
39+
app,
40+
"email",
41+
],
42+
},
43+
labels: {
44+
propDefinition: [
45+
app,
46+
"labels",
47+
],
48+
},
49+
attributes: {
50+
propDefinition: [
51+
app,
52+
"attributes",
53+
],
54+
},
55+
},
56+
methods: {
57+
updateContact({
58+
contactId, ...args
59+
} = {}) {
60+
return this.app.put({
61+
path: `/contacts/${contactId}`,
62+
...args,
63+
});
64+
},
65+
},
66+
async run({ $ }) {
67+
const {
68+
updateContact,
69+
contactId,
70+
phoneNumber,
71+
firstName,
72+
lastName,
73+
email,
74+
labels,
75+
attributes,
76+
} = this;
77+
78+
const response = await updateContact({
79+
$,
80+
contactId,
81+
data: {
82+
phoneNumber,
83+
firstName,
84+
lastName,
85+
email,
86+
...(labels?.length && {
87+
labels: labels.map((name) => ({
88+
name,
89+
})),
90+
}),
91+
attributes:
92+
attributes && Object.entries(attributes)
93+
.reduce((acc, [
94+
externalId,
95+
value,
96+
]) => ([
97+
...acc,
98+
{
99+
externalId,
100+
value,
101+
},
102+
]), []),
103+
},
104+
});
105+
106+
$.export("$summary", `Successfully updated contact with ID \`${response.data.id}\`.`);
107+
return response;
108+
},
109+
};

0 commit comments

Comments
 (0)