Skip to content

Commit 1591b71

Browse files
committed
wati init
1 parent edd4923 commit 1591b71

File tree

8 files changed

+385
-2
lines changed

8 files changed

+385
-2
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import wati from "../../wati.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "wati-add-contact",
6+
name: "Add Contact",
7+
description: "Adds a new contact on the WATI platform. [See the documentation](https://docs.wati.io/reference/post_api-v1-addcontact-whatsappnumber)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
wati,
12+
contactDetails: {
13+
propDefinition: [
14+
wati,
15+
"contactDetails",
16+
],
17+
},
18+
},
19+
async run({ $ }) {
20+
const response = await this.wati.addContact(this.contactDetails);
21+
$.export("$summary", `Successfully added contact with name: ${this.contactDetails.name}`);
22+
return response;
23+
},
24+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import wati from "../../wati.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "wati-send-template-message",
6+
name: "Send WhatsApp Template Message",
7+
description: "Enables sending of WhatsApp messages using a pre-approved template. [See the documentation](https://docs.wati.io/reference/post_api-v2-sendtemplatemessage)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
wati,
12+
contactDetails: {
13+
propDefinition: [
14+
wati,
15+
"contactDetails",
16+
],
17+
},
18+
templateDetails: {
19+
propDefinition: [
20+
wati,
21+
"templateDetails",
22+
],
23+
},
24+
},
25+
async run({ $ }) {
26+
const response = await this.wati.sendTemplateMessage({
27+
contactDetails: this.contactDetails,
28+
templateDetails: this.templateDetails,
29+
});
30+
31+
$.export("$summary", `Successfully sent template message to ${this.contactDetails.name || this.contactDetails.number}`);
32+
return response;
33+
},
34+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import wati from "../../wati.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "wati-update-contact-attribute",
6+
name: "Update Contact Attribute",
7+
description: "Allows updating attributes/tags related to an existing contact. [See the documentation](https://docs.wati.io/reference/post_api-v1-updatecontactattributes-whatsappnumber)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
wati,
12+
contactDetails: {
13+
propDefinition: [
14+
wati,
15+
"contactDetails",
16+
],
17+
},
18+
attributeDetails: {
19+
propDefinition: [
20+
wati,
21+
"attributeDetails",
22+
],
23+
},
24+
},
25+
async run({ $ }) {
26+
const response = await this.wati.updateContactAttributes({
27+
contactDetails: this.contactDetails,
28+
attributeDetails: this.attributeDetails,
29+
});
30+
31+
$.export("$summary", `Successfully updated attributes for contact ${this.contactDetails.name}`);
32+
return response;
33+
},
34+
};

components/wati/app/wati.app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ export default defineApp({
1010
console.log(Object.keys(this.$auth));
1111
},
1212
},
13-
});
13+
});

components/wati/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
"publishConfig": {
1414
"access": "public"
1515
}
16-
}
16+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import wati from "../../wati.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "wati-new-contact-created-instant",
6+
name: "New Contact Created",
7+
description: "Emit new event when a contact is created from an incoming WhatsApp message. [See the documentation](https://docs.wati.io/reference/)",
8+
version: "0.0.{{ts}}",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
wati: {
13+
type: "app",
14+
app: "wati",
15+
},
16+
http: {
17+
type: "$.interface.http",
18+
customResponse: false,
19+
},
20+
db: "$.service.db",
21+
whatsappNumber: {
22+
propDefinition: [
23+
wati,
24+
"whatsappNumber",
25+
],
26+
},
27+
contactName: {
28+
propDefinition: [
29+
wati,
30+
"contactName",
31+
],
32+
optional: true,
33+
},
34+
messageContent: {
35+
propDefinition: [
36+
wati,
37+
"messageContent",
38+
],
39+
optional: true,
40+
},
41+
},
42+
async run(event) {
43+
const {
44+
whatsappNumber, contactName, messageContent,
45+
} = event.body;
46+
47+
await this.wati.emitContactCreatedEvent({
48+
whatsappNumber,
49+
contactName,
50+
messageContent,
51+
});
52+
53+
this.$emit(event.body, {
54+
id: Date.now(),
55+
summary: `New contact created: ${contactName || whatsappNumber}`,
56+
ts: Date.now(),
57+
});
58+
},
59+
};
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import wati from "../../wati.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "wati-new-incoming-message-instant",
6+
name: "New Incoming Message Instant",
7+
description: "Emit new event when there is an incoming message on your number. [See the documentation](https://docs.wati.io/reference/get_api-v1-getmessages-whatsappnumber)",
8+
version: "0.0.{{ts}}",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
wati: {
13+
type: "app",
14+
app: "wati",
15+
},
16+
http: {
17+
type: "$.interface.http",
18+
customResponse: false,
19+
},
20+
db: "$.service.db",
21+
whatsappNumber: {
22+
propDefinition: [
23+
wati,
24+
"whatsappNumber",
25+
],
26+
},
27+
messageContent: {
28+
propDefinition: [
29+
wati,
30+
"messageContent",
31+
{
32+
optional: true,
33+
},
34+
],
35+
},
36+
timestamp: {
37+
propDefinition: [
38+
wati,
39+
"timestamp",
40+
{
41+
optional: true,
42+
},
43+
],
44+
},
45+
},
46+
hooks: {
47+
async deploy() {
48+
const messages = await this.wati._makeRequest({
49+
path: `/getMessages/${this.whatsappNumber}`,
50+
params: {
51+
pageSize: 50,
52+
pageNumber: 1,
53+
},
54+
});
55+
if (messages && messages.messages && messages.messages.items) {
56+
const items = messages.messages.items.slice(-50).reverse();
57+
for (const item of items) {
58+
this.$emit(item, {
59+
id: item.id,
60+
summary: `New message: ${item.messageContent || "No content"}`,
61+
ts: new Date(item.created).getTime(),
62+
});
63+
}
64+
}
65+
},
66+
async activate() {
67+
this.http.endpointUrl();
68+
},
69+
async deactivate() {
70+
// No specific deactivation hook for this component
71+
},
72+
},
73+
async run(event) {
74+
const {
75+
whatsappNumber, messageContent, timestamp,
76+
} = event.body;
77+
78+
this.$emit(event.body, {
79+
id: event.body.id,
80+
summary: `New message from ${whatsappNumber}`,
81+
ts: timestamp
82+
? new Date(timestamp).getTime()
83+
: Date.now(),
84+
});
85+
},
86+
};

0 commit comments

Comments
 (0)