-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - messagebird #15247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
New Components - messagebird #15247
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b089d9a
new components
michelle0927 80c5b73
pnpm-lock.yaml
michelle0927 9765ed1
updates
michelle0927 aac32d3
update async options
michelle0927 4875d01
new components
michelle0927 8424040
pnpm-lock.yaml
michelle0927 800df0a
update
michelle0927 9a38ffd
Merge remote-tracking branch 'origin/master' into issue-15227
michelle0927 043f81c
pnpm-lock.yaml
michelle0927 9b44fb4
use $auth organization_id
michelle0927 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
components/message_bird/actions/create-contact/create-contact.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
type: "sms", | ||
}, | ||
}); | ||
$.export("$summary", `Successfully sent SMS with ID ${response.id}`); | ||
return response; | ||
}, | ||
}; |
45 changes: 45 additions & 0 deletions
45
components/message_bird/actions/send-voice-message/send-voice-message.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
originator: this.originator, | ||
}, | ||
}); | ||
$.export("$summary", `Successfully sent voice message with ID ${response.id}`); | ||
return response; | ||
}, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)", | ||
}, | ||
}, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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, | ||
}); | ||
}, | ||
}, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
components/message_bird/sources/new-sms-message-received/new-sms-message-received.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}); | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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); | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
components/messagebird/actions/create-contact/create-contact.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.