Skip to content

Commit 419d1e0

Browse files
authored
Gupshup - new components (#19344)
* new components * gupshup * update templateId prop * updates
1 parent 6edbfe7 commit 419d1e0

File tree

5 files changed

+194
-6
lines changed

5 files changed

+194
-6
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import gupshup from "../../gupshup.app.mjs";
2+
3+
export default {
4+
key: "gupshup-send-template-message",
5+
name: "Send Template Message",
6+
description: "Send a template message. Requires a paid Gupshup account. [See the documentation](https://docs.gupshup.io/reference/sending-text-template)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: false,
13+
},
14+
props: {
15+
gupshup,
16+
info: {
17+
type: "alert",
18+
alertType: "info",
19+
content: "Note: This action requires a paid Gupshup account.",
20+
},
21+
source: {
22+
type: "string",
23+
label: "Source",
24+
description: "Sender Whatsapp Number",
25+
},
26+
destination: {
27+
type: "string",
28+
label: "Destination",
29+
description: "Receiver Whatsapp Number",
30+
},
31+
templateId: {
32+
propDefinition: [
33+
gupshup,
34+
"templateId",
35+
],
36+
},
37+
params: {
38+
type: "string[]",
39+
label: "Parameters",
40+
description: "List of template parameters",
41+
},
42+
},
43+
async run({ $ }) {
44+
const response = await this.gupshup.sendTemplateMessage({
45+
$,
46+
data: {
47+
source: this.source,
48+
destination: this.destination,
49+
template: {
50+
id: this.templateId,
51+
params: this.params,
52+
},
53+
},
54+
});
55+
if (response.status === "success") {
56+
$.export("$summary", `Successfully sent template message to ${this.destination}`);
57+
}
58+
return response;
59+
},
60+
};
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import gupshup from "../../gupshup.app.mjs";
2+
3+
export default {
4+
key: "gupshup-update-subscription",
5+
name: "Update Subscription",
6+
description: "Update a subscription. Requires a paid Gupshup account. [See the documentation](https://docs.gupshup.io/reference/updateanexisitngsubscription)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: true,
11+
openWorldHint: true,
12+
readOnlyHint: false,
13+
},
14+
props: {
15+
gupshup,
16+
info: {
17+
type: "alert",
18+
alertType: "info",
19+
content: "Note: This action requires a paid Gupshup account.",
20+
},
21+
subscriptionId: {
22+
type: "string",
23+
label: "Subscription ID",
24+
description: "The ID of the subscription to update",
25+
},
26+
modes: {
27+
type: "string",
28+
label: "Modes",
29+
description: "The modes of the subscription",
30+
},
31+
url: {
32+
type: "string",
33+
label: "URL",
34+
description: "The subscription URL",
35+
},
36+
version: {
37+
type: "integer",
38+
label: "Version",
39+
description: "The version of the subscription",
40+
},
41+
active: {
42+
type: "boolean",
43+
label: "Active",
44+
description: "Whether the subscription is active",
45+
},
46+
},
47+
async run({ $ }) {
48+
const response = await this.gupshup.updateSubscription({
49+
$,
50+
subscriptionId: this.subscriptionId,
51+
data: {
52+
modes: this.modes,
53+
url: this.url,
54+
version: this.version,
55+
active: this.active,
56+
},
57+
});
58+
if (response.status === "success") {
59+
$.export("$summary", `Successfully updated subscription ${this.subscriptionId}`);
60+
}
61+
return response;
62+
},
63+
};

components/gupshup/gupshup.app.mjs

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,69 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "gupshup",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
templateId: {
8+
type: "string",
9+
label: "Template ID",
10+
description: "The ID of the template to use",
11+
async options({ page }) {
12+
const { templates } = await this.listTemplates({
13+
params: {
14+
pageNo: page,
15+
},
16+
});
17+
return templates?.map(({ id }) => id) || [];
18+
},
19+
},
20+
},
521
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
22+
_baseUrl() {
23+
return "https://api.gupshup.io";
24+
},
25+
_appName() {
26+
return this.$auth.appname;
27+
},
28+
_makeRequest({
29+
$ = this, path, headers, ...opts
30+
}) {
31+
return axios($, {
32+
url: `${this._baseUrl()}${path}`,
33+
headers: {
34+
...headers,
35+
"apikey": `${this.$auth.apikey}`,
36+
},
37+
...opts,
38+
});
39+
},
40+
listTemplates(opts = {}) {
41+
return this._makeRequest({
42+
path: `/wa/app/${this._appName()}/template`,
43+
...opts,
44+
});
45+
},
46+
sendTemplateMessage(opts = {}) {
47+
return this._makeRequest({
48+
method: "POST",
49+
path: "/wa/api/v1/template/msg",
50+
headers: {
51+
"Content-Type": "application/x-www-form-urlencoded",
52+
},
53+
...opts,
54+
});
55+
},
56+
updateSubscription({
57+
subscriptionId, ...opts
58+
}) {
59+
return this._makeRequest({
60+
method: "PUT",
61+
path: `/wa/app/${this._appName()}/subscription/${subscriptionId}`,
62+
headers: {
63+
"Content-Type": "application/x-www-form-urlencoded",
64+
},
65+
...opts,
66+
});
967
},
1068
},
1169
};

components/gupshup/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/gupshup",
3-
"version": "0.0.3",
3+
"version": "0.1.0",
44
"description": "Pipedream Gupshup Components",
55
"main": "gupshup.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.1"
1417
}
1518
}

pnpm-lock.yaml

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)