Skip to content

Commit 6e6631e

Browse files
authored
New Components - messagebird (#15247)
* new components * pnpm-lock.yaml * updates * update async options * new components * pnpm-lock.yaml * update * pnpm-lock.yaml * use $auth organization_id
1 parent edf01ea commit 6e6631e

File tree

16 files changed

+819
-24
lines changed

16 files changed

+819
-24
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import messagebird from "../../message_bird.app.mjs";
2+
3+
export default {
4+
key: "message_bird-create-contact",
5+
name: "Create Contact",
6+
description: "Creates a new contact. [See the documentation](https://developers.messagebird.com/api/contacts/#create-a-contact)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
messagebird,
11+
phone: {
12+
type: "string",
13+
label: "Phone",
14+
description: "The phone number of the contact. Example: `31612345678`",
15+
},
16+
firstName: {
17+
type: "string",
18+
label: "First Name",
19+
description: "First name of the contact",
20+
optional: true,
21+
},
22+
lastName: {
23+
type: "string",
24+
label: "Last Name",
25+
description: "Last name of the contact",
26+
optional: true,
27+
},
28+
},
29+
async run({ $ }) {
30+
const response = await this.messagebird.createContact({
31+
$,
32+
data: {
33+
msisdn: this.phone,
34+
firstName: this.firstName,
35+
lastName: this.lastName,
36+
},
37+
});
38+
$.export("$summary", `Successfully created contact with ID ${response.id}`);
39+
return response;
40+
},
41+
};
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import messagebird from "../../message_bird.app.mjs";
2+
3+
export default {
4+
key: "message_bird-send-sms",
5+
name: "Send SMS",
6+
description: "Sends an SMS message. [See the documentation](https://developers.messagebird.com/api/sms-messaging/#send-outbound-sms)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
messagebird,
11+
originator: {
12+
propDefinition: [
13+
messagebird,
14+
"originator",
15+
],
16+
},
17+
body: {
18+
propDefinition: [
19+
messagebird,
20+
"body",
21+
],
22+
},
23+
recipients: {
24+
propDefinition: [
25+
messagebird,
26+
"recipients",
27+
],
28+
},
29+
},
30+
async run({ $ }) {
31+
const response = await this.messagebird.sendSMS({
32+
$,
33+
data: {
34+
originator: this.originator,
35+
body: this.body,
36+
recipients: typeof this.recipients === "string"
37+
? JSON.parse(this.recipients)
38+
: this.recipients,
39+
type: "sms",
40+
},
41+
});
42+
$.export("$summary", `Successfully sent SMS with ID ${response.id}`);
43+
return response;
44+
},
45+
};
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import messagebird from "../../message_bird.app.mjs";
2+
3+
export default {
4+
key: "message_bird-send-voice-message",
5+
name: "Send Voice Message",
6+
description: "Sends a voice message. [See the documentation](https://developers.messagebird.com/api/voice-messaging/#send-a-voice-message)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
messagebird,
11+
body: {
12+
propDefinition: [
13+
messagebird,
14+
"body",
15+
],
16+
},
17+
recipients: {
18+
propDefinition: [
19+
messagebird,
20+
"recipients",
21+
],
22+
},
23+
originator: {
24+
propDefinition: [
25+
messagebird,
26+
"originator",
27+
],
28+
optional: true,
29+
},
30+
},
31+
async run({ $ }) {
32+
const response = await this.messagebird.sendVoiceMessage({
33+
$,
34+
data: {
35+
body: this.body,
36+
recipients: typeof this.recipients === "string"
37+
? JSON.parse(this.recipients)
38+
: this.recipients,
39+
originator: this.originator,
40+
},
41+
});
42+
$.export("$summary", `Successfully sent voice message with ID ${response.id}`);
43+
return response;
44+
},
45+
};
Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,68 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "message_bird",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
originator: {
8+
type: "string",
9+
label: "Originator",
10+
description: "The sender of the message. This can be a telephone number (including country code) or an alphanumeric string. In case of an alphanumeric string, the maximum length is 11 characters.",
11+
},
12+
body: {
13+
type: "string",
14+
label: "Body",
15+
description: "The body of the message",
16+
},
17+
recipients: {
18+
type: "string[]",
19+
label: "Recipients",
20+
description: "An array of recipients msisdns (phone numbers)",
21+
},
22+
},
523
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
24+
_baseUrl() {
25+
return "https://rest.messagebird.com";
26+
},
27+
_makeRequest({
28+
$ = this,
29+
path,
30+
...opts
31+
}) {
32+
return axios($, {
33+
url: `${this._baseUrl()}${path}`,
34+
headers: {
35+
"Authorization": `AccessKey ${this.$auth.access_key}`,
36+
},
37+
...opts,
38+
});
39+
},
40+
listSMSMessages(opts = {}) {
41+
return this._makeRequest({
42+
path: "/messages",
43+
...opts,
44+
});
45+
},
46+
createContact(opts = {}) {
47+
return this._makeRequest({
48+
method: "POST",
49+
path: "/contacts",
50+
...opts,
51+
});
52+
},
53+
sendSMS(opts = {}) {
54+
return this._makeRequest({
55+
method: "POST",
56+
path: "/messages",
57+
...opts,
58+
});
59+
},
60+
sendVoiceMessage(opts = {}) {
61+
return this._makeRequest({
62+
method: "POST",
63+
path: "/voicemessages",
64+
...opts,
65+
});
966
},
1067
},
1168
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "@pipedream/message_bird",
3+
"version": "0.0.1",
4+
"description": "Pipedream MessageBird Components",
5+
"main": "message_bird.app.mjs",
6+
"keywords": [
7+
"pipedream",
8+
"message_bird"
9+
],
10+
"homepage": "https://pipedream.com/apps/message_bird",
11+
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
12+
"publishConfig": {
13+
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
17+
}
18+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import messagebird from "../../message_bird.app.mjs";
2+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
3+
4+
export default {
5+
key: "message_bird-new-sms-message-received",
6+
name: "New SMS Message Received",
7+
description: "Emit new event when a new SMS message is received. [See the documentation](https://developers.messagebird.com/api/sms-messaging/#list-messages)",
8+
version: "0.0.1",
9+
dedupe: "unique",
10+
type: "source",
11+
props: {
12+
messagebird,
13+
db: "$.service.db",
14+
timer: {
15+
type: "$.interface.timer",
16+
default: {
17+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
18+
},
19+
},
20+
},
21+
methods: {
22+
_getLastTs() {
23+
return this.db.get("lastTs");
24+
},
25+
_setLastTs(lastTs) {
26+
this.db.set("lastTs", lastTs);
27+
},
28+
generateMeta(message) {
29+
return {
30+
id: message.id,
31+
summary: `New Message ID: ${message.id}`,
32+
ts: Date.parse(message.createdDatetime),
33+
};
34+
},
35+
},
36+
async run() {
37+
let lastTs = this._getLastTs();
38+
39+
const { items } = await this.messagebird.listSMSMessages({
40+
params: {
41+
direction: "mo", // mt = sent, mo = received
42+
type: "sms",
43+
from: lastTs,
44+
},
45+
});
46+
47+
if (!items?.length) {
48+
return;
49+
}
50+
51+
for (const message of items) {
52+
const meta = this.generateMeta(message);
53+
this.$emit(message, meta);
54+
55+
if (!lastTs || Date.parse(message.createdDatetime) > Date.parse(lastTs)) {
56+
lastTs = message.createdDatetime;
57+
}
58+
}
59+
60+
this._setLastTs(lastTs);
61+
},
62+
};

components/messagebird/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import messagebird from "../../messagebird.app.mjs";
2+
3+
export default {
4+
key: "messagebird-create-contact",
5+
name: "Create Contact",
6+
description: "Creates a new contact. [See the documentation](https://docs.bird.com/api/contacts-api/api-reference/manage-workspace-contacts/create-a-contact)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
messagebird,
11+
workspaceId: {
12+
propDefinition: [
13+
messagebird,
14+
"workspaceId",
15+
],
16+
},
17+
displayName: {
18+
type: "string",
19+
label: "Display Name",
20+
description: "The display name for the contact",
21+
},
22+
email: {
23+
type: "string",
24+
label: "Email",
25+
description: "The email address of the contact",
26+
optional: true,
27+
},
28+
listIds: {
29+
propDefinition: [
30+
messagebird,
31+
"listIds",
32+
(c) => ({
33+
workspaceId: c.workspaceId,
34+
}),
35+
],
36+
},
37+
},
38+
async run({ $ }) {
39+
const response = await this.messagebird.createContact({
40+
$,
41+
workspaceId: this.workspaceId,
42+
data: {
43+
displayName: this.displayName,
44+
identifiers: this.email && [
45+
{
46+
key: "emailaddress",
47+
value: this.email,
48+
},
49+
],
50+
listIds: this.listIds,
51+
},
52+
});
53+
$.export("$summary", `Successfully created contact with ID: ${response.id}`);
54+
return response;
55+
},
56+
};

0 commit comments

Comments
 (0)