Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { parseObject } from "../../common/utils.mjs";
import whautomate from "../../whautomate.app.mjs";

export default {
key: "whautomate-assign-tags-contact",
name: "Assign Tags to Contact",
description: "Assign one or more tags to an existing contact. [See the documentation](https://help.whautomate.com/product-guides/whautomate-rest-api/contacts#/v1-contacts-contactid-1)",
version: "0.0.1",
type: "action",
props: {
whautomate,
contactId: {
propDefinition: [
whautomate,
"contactId",
],
},
contactTags: {
propDefinition: [
whautomate,
"contactTags",
],
},
},
async run({ $ }) {
const contact = await this.whautomate.getContact(this.contactId);
const response = await this.whautomate.updateContact({
$,
contactId: this.contactId,
data: {
...contact,
tags: [
...new Set([
...(contact.tags
? contact.tags
: []),
...parseObject(this.contactTags),
]),
],
},
});
$.export("$summary", `Successfully assigned tags to contact ${this.contactId}`);
return response;
},
};
80 changes: 80 additions & 0 deletions components/whautomate/actions/create-contact/create-contact.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { STAGE_OPTIONS } from "../../common/constants.mjs";
import { parseObject } from "../../common/utils.mjs";
import whautomate from "../../whautomate.app.mjs";

export default {
key: "whautomate-create-contact",
name: "Create Contact",
description: "Create a new contact associated with a WhatsApp number. [See the documentation](https://help.whautomate.com/product-guides/whautomate-rest-api/contacts#/v1-contacts-1)",
version: "0.0.1",
type: "action",
props: {
whautomate,
name: {
type: "string",
label: "Name",
description: "The name of the contact",
},
phoneNumber: {
type: "string",
label: "Phone Number",
description: "The WhatsApp phone number of the contact. Format: +15555555555",
},
locationId: {
propDefinition: [
whautomate,
"locationId",
],
},
stage: {
type: "string",
label: "Stage",
description: "The Contact Stage",
optional: true,
options: STAGE_OPTIONS,
},
tags: {
propDefinition: [
whautomate,
"contactTags",
],
optional: true,
},
customFields: {
type: "object",
label: "Custom Fields",
description: "The contact custom fields.",
optional: true,
},
notes: {
type: "string",
label: "Notes",
description: "The contact notes.",
optional: true,
},
},
async run({ $ }) {
const {
whautomate,
locationId,
tags,
customFields,
...data
} = this;

const response = await whautomate.createContact({
$,
data: {
...data,
location: {
id: locationId,
},
tags: parseObject(tags),
customFields: parseObject(customFields),
},
});

$.export("$summary", `Successfully created contact with ID ${response.id}`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { ConfigurationError } from "@pipedream/platform";
import { parseObject } from "../../common/utils.mjs";
import whautomate from "../../whautomate.app.mjs";

export default {
key: "whautomate-send-whatsapp-template-message",
name: "Send WhatsApp Template Message",
description: "Send a pre-defined WhatsApp message template to a contact. [See the documentation](https://help.whautomate.com/product-guides/whautomate-rest-api/messages)",
version: "0.0.1",
type: "action",
props: {
whautomate,
contactId: {
propDefinition: [
whautomate,
"contactId",
],
},
templateName: {
type: "string",
label: "Template Name",
description: "The WhatsApp Template from your Whautomate Account.",
},
templateLanguage: {
type: "string",
label: "Template Language",
description: "The language of the WhatsApp Template.",
},
locationId: {
propDefinition: [
whautomate,
"locationId",
],
},
headerMediaUrl: {
type: "string",
label: "Header Media URL",
description: "The URL of the header media.",
optional: true,
},
headerTextParameters: {
type: "string[]",
label: "Header Text Parameters",
description: "The variables used in the header of your WhatsApp Template.",
optional: true,
},
bodyTextParameters: {
type: "string[]",
label: "Body Text Parameters",
description: "The variables used in the body of your WhatsApp Template.",
optional: true,
},
buttonUrlParameters: {
type: "string[]",
label: "Button URL Parameters",
description: "The placeholders used in the buttons of your WhatsApp Template.",
optional: true,
},
},
async run({ $ }) {
const response = await this.whautomate.sendWhatsAppMessageTemplate({
$,
data: {
contact: {
id: this.contactId,
},
template: {
name: this.templateName,
language: this.templateLanguage,
},
location: {
id: this.locationId,
},
headerMediaUrl: this.headerMediaUrl,
headerTextParameters: parseObject(this.headerTextParameters),
bodyTextParameters: parseObject(this.bodyTextParameters),
buttonUrlParameters: parseObject(this.buttonUrlParameters),
},
});

if (response.error) throw new ConfigurationError(response.error);

$.export("$summary", `Successfully sent template message to ${this.locationId}`);
return response;
},
};
10 changes: 10 additions & 0 deletions components/whautomate/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const STAGE_OPTIONS = [
"Subscriber",
"Lead",
"Marketing qualified lead (MQL)",
"Sales qualified lead (SQL)",
"Opportunity",
"Customer",
"Evangelist",
"Other",
];
24 changes: 24 additions & 0 deletions components/whautomate/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const parseObject = (obj) => {
if (!obj) return undefined;

if (Array.isArray(obj)) {
return obj.map((item) => {
if (typeof item === "string") {
try {
return JSON.parse(item);
} catch (e) {
return item;
}
}
return item;
});
}
if (typeof obj === "string") {
try {
return JSON.parse(obj);
} catch (e) {
return obj;
}
}
return obj;
};
8 changes: 6 additions & 2 deletions components/whautomate/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/whautomate",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Whautomate Components",
"main": "whautomate.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,9 @@
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.0"
}
}
}

58 changes: 58 additions & 0 deletions components/whautomate/sources/common/base.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import whautomate from "../../whautomate.app.mjs";

export default {
props: {
whautomate,
http: {
type: "$.interface.http",
customResponse: false,
},
db: "$.service.db",
name: {
type: "string",
label: "Name",
description: "The name of the webhook.",
},
},
methods: {
_setWehookId(webhookId) {
this.db.set("webhookId", webhookId);
},
_getWebhookId() {
return this.db.get("webhookId");
},
},
hooks: {
async activate() {
const data = await this.whautomate.createWebhook({
data: {
webhookHeaders: [
{
"key": "Content-Type",
"value": "application/json",
},
],
events: this.getEvent(),
name: this.name,
serverUrl: this.http.endpoint,
active: true,
},
});
this._setWehookId(data.id);
},
async deactivate() {
const webhookId = this._getWebhookId();
await this.whautomate.deleteWebhook(webhookId);
},
},
async run({ body }) {
if (body.event) {
const ts = Date.parse(body.event.timeStamp);
this.$emit(body, {
id: body.event.id,
summary: this.getSummary(body),
ts,
});
}
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import common from "../common/base.mjs";
import sampleEmit from "./test-event.mjs";

export default {
...common,
key: "whautomate-new-appointment-cancelled-instant",
name: "New Appointment Cancelled (Instant)",
description: "Emit new event when an appointment is cancelled in Whautomate.",
version: "0.0.1",
type: "source",
dedupe: "unique",
methods: {
...common.methods,
getEvent() {
return [
"appointment_cancelled",
];
},
getSummary(body) {
return `Appointment cancelled: ${body.appointment.id}`;
},
},
sampleEmit,
};
Loading