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
41 changes: 41 additions & 0 deletions components/message_bird/actions/create-contact/create-contact.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import messagebird from "../../message_bird.app.mjs";

export default {
key: "message_bird-create-contact",
name: "Create Contact",
description: "Creates a new contact. [See the documentation](https://developers.messagebird.com/api/contacts/#create-a-contact)",
version: "0.0.1",
type: "action",
props: {
messagebird,
phone: {
type: "string",
label: "Phone",
description: "The phone number of the contact. Example: `31612345678`",
},
firstName: {
type: "string",
label: "First Name",
description: "First name of the contact",
optional: true,
},
lastName: {
type: "string",
label: "Last Name",
description: "Last name of the contact",
optional: true,
},
},
async run({ $ }) {
const response = await this.messagebird.createContact({
$,
data: {
msisdn: this.phone,
firstName: this.firstName,
lastName: this.lastName,
},
});
$.export("$summary", `Successfully created contact with ID ${response.id}`);
return response;
},
};
45 changes: 45 additions & 0 deletions components/message_bird/actions/send-sms/send-sms.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import messagebird from "../../message_bird.app.mjs";

export default {
key: "message_bird-send-sms",
name: "Send SMS",
description: "Sends an SMS message. [See the documentation](https://developers.messagebird.com/api/sms-messaging/#send-outbound-sms)",
version: "0.0.1",
type: "action",
props: {
messagebird,
originator: {
propDefinition: [
messagebird,
"originator",
],
},
body: {
propDefinition: [
messagebird,
"body",
],
},
recipients: {
propDefinition: [
messagebird,
"recipients",
],
},
},
async run({ $ }) {
const response = await this.messagebird.sendSMS({
$,
data: {
originator: this.originator,
body: this.body,
recipients: typeof this.recipients === "string"
? JSON.parse(this.recipients)
: this.recipients,
type: "sms",
},
});
$.export("$summary", `Successfully sent SMS with ID ${response.id}`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import messagebird from "../../message_bird.app.mjs";

export default {
key: "message_bird-send-voice-message",
name: "Send Voice Message",
description: "Sends a voice message. [See the documentation](https://developers.messagebird.com/api/voice-messaging/#send-a-voice-message)",
version: "0.0.1",
type: "action",
props: {
messagebird,
body: {
propDefinition: [
messagebird,
"body",
],
},
recipients: {
propDefinition: [
messagebird,
"recipients",
],
},
originator: {
propDefinition: [
messagebird,
"originator",
],
optional: true,
},
},
async run({ $ }) {
const response = await this.messagebird.sendVoiceMessage({
$,
data: {
body: this.body,
recipients: typeof this.recipients === "string"
? JSON.parse(this.recipients)
: this.recipients,
originator: this.originator,
},
});
$.export("$summary", `Successfully sent voice message with ID ${response.id}`);
return response;
},
};
65 changes: 61 additions & 4 deletions components/message_bird/message_bird.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,68 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "message_bird",
propDefinitions: {},
propDefinitions: {
originator: {
type: "string",
label: "Originator",
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.",
},
body: {
type: "string",
label: "Body",
description: "The body of the message",
},
recipients: {
type: "string[]",
label: "Recipients",
description: "An array of recipients msisdns (phone numbers)",
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://rest.messagebird.com";
},
_makeRequest({
$ = this,
path,
...opts
}) {
return axios($, {
url: `${this._baseUrl()}${path}`,
headers: {
"Authorization": `AccessKey ${this.$auth.access_key}`,
},
...opts,
});
},
listSMSMessages(opts = {}) {
return this._makeRequest({
path: "/messages",
...opts,
});
},
createContact(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/contacts",
...opts,
});
},
sendSMS(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/messages",
...opts,
});
},
sendVoiceMessage(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/voicemessages",
...opts,
});
},
},
};
18 changes: 18 additions & 0 deletions components/message_bird/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "@pipedream/message_bird",
"version": "0.0.1",
"description": "Pipedream MessageBird Components",
"main": "message_bird.app.mjs",
"keywords": [
"pipedream",
"message_bird"
],
"homepage": "https://pipedream.com/apps/message_bird",
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import messagebird from "../../message_bird.app.mjs";
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";

export default {
key: "message_bird-new-sms-message-received",
name: "New SMS Message Received",
description: "Emit new event when a new SMS message is received. [See the documentation](https://developers.messagebird.com/api/sms-messaging/#list-messages)",
version: "0.0.1",
dedupe: "unique",
type: "source",
props: {
messagebird,
db: "$.service.db",
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
},
methods: {
_getLastTs() {
return this.db.get("lastTs");
},
_setLastTs(lastTs) {
this.db.set("lastTs", lastTs);
},
generateMeta(message) {
return {
id: message.id,
summary: `New Message ID: ${message.id}`,
ts: Date.parse(message.createdDatetime),
};
},
},
async run() {
let lastTs = this._getLastTs();

const { items } = await this.messagebird.listSMSMessages({
params: {
direction: "mo", // mt = sent, mo = received
type: "sms",
from: lastTs,
},
});

if (!items?.length) {
return;
}

for (const message of items) {
const meta = this.generateMeta(message);
this.$emit(message, meta);

if (!lastTs || Date.parse(message.createdDatetime) > Date.parse(lastTs)) {
lastTs = message.createdDatetime;
}
}

this._setLastTs(lastTs);
},
};
3 changes: 0 additions & 3 deletions components/messagebird/.gitignore

This file was deleted.

56 changes: 56 additions & 0 deletions components/messagebird/actions/create-contact/create-contact.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import messagebird from "../../messagebird.app.mjs";

export default {
key: "messagebird-create-contact",
name: "Create Contact",
description: "Creates a new contact. [See the documentation](https://docs.bird.com/api/contacts-api/api-reference/manage-workspace-contacts/create-a-contact)",
version: "0.0.1",
type: "action",
props: {
messagebird,
workspaceId: {
propDefinition: [
messagebird,
"workspaceId",
],
},
displayName: {
type: "string",
label: "Display Name",
description: "The display name for the contact",
},
email: {
type: "string",
label: "Email",
description: "The email address of the contact",
optional: true,
},
listIds: {
propDefinition: [
messagebird,
"listIds",
(c) => ({
workspaceId: c.workspaceId,
}),
],
},
},
async run({ $ }) {
const response = await this.messagebird.createContact({
$,
workspaceId: this.workspaceId,
data: {
displayName: this.displayName,
identifiers: this.email && [
{
key: "emailaddress",
value: this.email,
},
],
listIds: this.listIds,
},
});
$.export("$summary", `Successfully created contact with ID: ${response.id}`);
return response;
},
};
Loading
Loading