Skip to content

Commit 079c9b8

Browse files
committed
[Component]: hey: New components
1 parent 46e7530 commit 079c9b8

File tree

10 files changed

+779
-10
lines changed

10 files changed

+779
-10
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import app from "../../heyy.app.mjs";
3+
import utils from "../../common/utils.mjs";
4+
5+
export default {
6+
key: "heyy-create-contact",
7+
name: "Create Contact",
8+
description: "Creates a new contact for the business. [See the documentation](https://documenter.getpostman.com/view/27408936/2sA2r3a6DW#a1249b8d-10cf-446a-be35-eb8793ffa967).",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
app,
13+
phoneNumber: {
14+
propDefinition: [
15+
app,
16+
"phoneNumber",
17+
],
18+
},
19+
firstName: {
20+
propDefinition: [
21+
app,
22+
"firstName",
23+
],
24+
},
25+
lastName: {
26+
propDefinition: [
27+
app,
28+
"lastName",
29+
],
30+
},
31+
email: {
32+
propDefinition: [
33+
app,
34+
"email",
35+
],
36+
},
37+
labels: {
38+
propDefinition: [
39+
app,
40+
"labels",
41+
],
42+
},
43+
attributes: {
44+
propDefinition: [
45+
app,
46+
"attributes",
47+
],
48+
},
49+
},
50+
methods: {
51+
createContact(args = {}) {
52+
return this.app.post({
53+
path: "/contacts",
54+
...args,
55+
});
56+
},
57+
},
58+
async run({ $ }) {
59+
const {
60+
createContact,
61+
phoneNumber,
62+
firstName,
63+
lastName,
64+
email,
65+
labels,
66+
attributes,
67+
} = this;
68+
69+
if (!utils.isPhoneNumberValid(phoneNumber)) {
70+
throw new ConfigurationError(`The phone number \`${phoneNumber}\` is invalid. Please provide a valid phone number.`);
71+
}
72+
73+
const response = await createContact({
74+
$,
75+
data: {
76+
phoneNumber,
77+
firstName,
78+
lastName,
79+
email,
80+
...(labels?.length && {
81+
labels: labels.map((name) => ({
82+
name,
83+
})),
84+
}),
85+
attributes:
86+
attributes && Object.entries(attributes)
87+
.reduce((acc, [
88+
externalId,
89+
value,
90+
]) => ([
91+
...acc,
92+
{
93+
externalId,
94+
value,
95+
},
96+
]), []),
97+
},
98+
});
99+
$.export("$summary", `Successfully created contact with ID \`${response.data.id}\`.`);
100+
return response;
101+
},
102+
};
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: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import app from "../../heyy.app.mjs";
3+
import utils from "../../common/utils.mjs";
4+
5+
export default {
6+
key: "heyy-update-contact",
7+
name: "Update Contact",
8+
description: "Updates the details of a contact under your business. [See the documentation](https://documenter.getpostman.com/view/27408936/2sA2r3a6DW#5a5ee22b-c16e-4d46-ae5d-3844b6501a34).",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
app,
13+
contactId: {
14+
propDefinition: [
15+
app,
16+
"contactId",
17+
],
18+
},
19+
phoneNumber: {
20+
optional: true,
21+
propDefinition: [
22+
app,
23+
"phoneNumber",
24+
],
25+
},
26+
firstName: {
27+
optional: true,
28+
propDefinition: [
29+
app,
30+
"firstName",
31+
],
32+
},
33+
lastName: {
34+
propDefinition: [
35+
app,
36+
"lastName",
37+
],
38+
},
39+
email: {
40+
propDefinition: [
41+
app,
42+
"email",
43+
],
44+
},
45+
labels: {
46+
propDefinition: [
47+
app,
48+
"labels",
49+
],
50+
},
51+
attributes: {
52+
propDefinition: [
53+
app,
54+
"attributes",
55+
],
56+
},
57+
},
58+
methods: {
59+
updateContact({
60+
contactId, ...args
61+
} = {}) {
62+
return this.app.put({
63+
path: `/contacts/${contactId}`,
64+
...args,
65+
});
66+
},
67+
},
68+
async run({ $ }) {
69+
const {
70+
updateContact,
71+
contactId,
72+
phoneNumber,
73+
firstName,
74+
lastName,
75+
email,
76+
labels,
77+
attributes,
78+
} = this;
79+
80+
if (phoneNumber && !utils.isPhoneNumberValid(phoneNumber)) {
81+
throw new ConfigurationError(`The phone number \`${phoneNumber}\` is invalid. Please provide a valid phone number.`);
82+
}
83+
84+
const response = await updateContact({
85+
$,
86+
contactId,
87+
data: {
88+
phoneNumber,
89+
firstName,
90+
lastName,
91+
email,
92+
...(labels?.length && {
93+
labels: labels.map((name) => ({
94+
name,
95+
})),
96+
}),
97+
attributes:
98+
attributes && Object.entries(attributes)
99+
.reduce((acc, [
100+
externalId,
101+
value,
102+
]) => ([
103+
...acc,
104+
{
105+
externalId,
106+
value,
107+
},
108+
]), []),
109+
},
110+
});
111+
112+
$.export("$summary", `Successfully updated contact with ID \`${response.data.id}\`.`);
113+
return response;
114+
},
115+
};

0 commit comments

Comments
 (0)