Skip to content

Commit 6596349

Browse files
authored
Merge branch 'master' into sdk/connect-workflow-invocation
2 parents a33b75f + 02197b3 commit 6596349

File tree

36 files changed

+462
-155
lines changed

36 files changed

+462
-155
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import app from "../../bippybox.app.mjs";
2+
3+
export default {
4+
key: "bippybox-activate-box",
5+
name: "Activate Box",
6+
description: "Triggers the BippyBox to play an audio file. [See the documentation](https://bippybox.io/docs/).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
device: {
12+
type: "string",
13+
label: "Device",
14+
description: "The device identifier. Eg. `DEVICE123`.",
15+
},
16+
url: {
17+
type: "string",
18+
label: "URL",
19+
description: "The URL of the audio file to play. Eg. `https://storage.example.com/users/exampleUserUID67890/audio/SampleAudioFile.wav?alt=media&token=exampleToken123456`.",
20+
},
21+
},
22+
async run({ $ }) {
23+
const {
24+
app,
25+
device,
26+
url,
27+
} = this;
28+
29+
const response = await app.activateBox({
30+
$,
31+
data: {
32+
device,
33+
URL: url,
34+
},
35+
});
36+
$.export("$summary", "Successfully activated BippyBox.");
37+
return response;
38+
},
39+
};
Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,46 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "bippybox",
4-
propDefinitions: {},
56
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
7+
getUrl(path) {
8+
return `https://websocket.bippybox.io${path}`;
9+
},
10+
getHeaders(headers) {
11+
return {
12+
...headers,
13+
"Content-Type": "application/json",
14+
"x-api-key": this.$auth.api_key,
15+
};
16+
},
17+
_makeRequest({
18+
$ = this, path, headers, ...args
19+
} = {}) {
20+
return axios($, {
21+
...args,
22+
url: this.getUrl(path),
23+
headers: this.getHeaders(headers),
24+
});
25+
},
26+
post(args = {}) {
27+
return this._makeRequest({
28+
method: "POST",
29+
...args,
30+
});
31+
},
32+
activateBox({
33+
data, ...args
34+
} = {}) {
35+
const { uid } = this.$auth;
36+
return this.post({
37+
path: "/send",
38+
data: {
39+
...data,
40+
uid,
41+
},
42+
...args,
43+
});
944
},
1045
},
11-
};
46+
};

components/bippybox/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/bippybox",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream BippyBox Components",
55
"main": "bippybox.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "3.0.3"
1417
}
15-
}
18+
}

components/intercom/actions/create-note/create-note.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "intercom-create-note",
55
name: "Create Note",
66
description: "Creates a note for a specific user. [See the docs here](https://developers.intercom.com/intercom-api-reference/reference/create-note-for-contact)",
7-
version: "0.0.3",
7+
version: "0.0.4",
88
type: "action",
99
props: {
1010
intercom,

components/intercom/actions/send-incoming-message/send-incoming-message.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "intercom-send-incoming-message",
55
name: "Send Incoming Message",
66
description: "Send a message from a user into your Intercom app. [See the docs here](https://developers.intercom.com/intercom-api-reference/reference/create-a-conversation)",
7-
version: "0.0.3",
7+
version: "0.0.4",
88
type: "action",
99
props: {
1010
intercom,
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
import { ROLE_OPTIONS } from "../../common/constants.mjs";
2+
import intercom from "../../intercom.app.mjs";
3+
4+
export default {
5+
key: "intercom-upsert-contact",
6+
name: "Upsert Contact",
7+
description: "Create a new contact. If there is already a contact with the email provided, the existing contact will be updated. [See the docs here](https://developers.intercom.com/docs/references/rest-api/api.intercom.io/contacts/createcontact)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
intercom,
12+
email: {
13+
type: "string",
14+
label: "Email",
15+
description: "The contact's email.",
16+
},
17+
role: {
18+
type: "string",
19+
label: "Role",
20+
description: "The role of the contact.",
21+
options: ROLE_OPTIONS,
22+
optional: true,
23+
},
24+
externalId: {
25+
type: "string",
26+
label: "External Id",
27+
description: "A unique identifier for the contact which is given to Intercom.",
28+
optional: true,
29+
},
30+
phone: {
31+
type: "string",
32+
label: "Phone",
33+
description: "The contact's phone number.",
34+
optional: true,
35+
},
36+
name: {
37+
type: "string",
38+
label: "Name",
39+
description: "The contact's name.",
40+
optional: true,
41+
},
42+
avatar: {
43+
type: "string",
44+
label: "Avatar",
45+
description: "An image URL containing the avatar of a contact.",
46+
optional: true,
47+
},
48+
unsubscribedFromEmails: {
49+
type: "boolean",
50+
label: "Unsubscribed From Emails",
51+
description: "Whether the contact is unsubscribed from emails.",
52+
optional: true,
53+
},
54+
customAttributes: {
55+
type: "object",
56+
label: "Custom Attributes",
57+
description: "The custom attributes which are set for the contact.",
58+
optional: true,
59+
},
60+
},
61+
async run({ $ }) {
62+
let response = {};
63+
let requestType = "created";
64+
let data = {
65+
email: this.email,
66+
role: this.role,
67+
externalId: this.externalId,
68+
phone: this.phone,
69+
name: this.name,
70+
avatar: this.avatar,
71+
unsubscribedFromEmails: this.unsubscribedFromEmails,
72+
customAttributes: this.customAttributes,
73+
};
74+
75+
data = Object.entries(data).filter(([
76+
,
77+
value,
78+
]) => (value != "" && value != undefined))
79+
.reduce((obj, [
80+
key,
81+
value,
82+
]) => Object.assign(obj, {
83+
[key]: value,
84+
}), {});
85+
86+
const {
87+
data: contact, total_count: total,
88+
} = await this.intercom.searchContact({
89+
data: {
90+
query: {
91+
operator: "AND",
92+
value: [
93+
{
94+
field: "email",
95+
operator: "=",
96+
value: this.email,
97+
},
98+
],
99+
},
100+
pagination: {
101+
per_page: 1,
102+
},
103+
},
104+
});
105+
106+
if (total) {
107+
const {
108+
id: contactId,
109+
// eslint-disable-next-line no-unused-vars
110+
owner_id,
111+
...contactInfos
112+
} = contact[0];
113+
response = await this.intercom.updateContact({
114+
$,
115+
contactId,
116+
data: {
117+
...contactInfos,
118+
...data,
119+
},
120+
});
121+
requestType = "updated";
122+
} else {
123+
response = await this.intercom.createContact({
124+
$,
125+
data,
126+
});
127+
}
128+
$.export("$summary", `Successfully ${requestType} contact with ID ${response.id}`);
129+
return response;
130+
},
131+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export const ROLE_OPTIONS = [
2+
{
3+
label: "User",
4+
value: "user",
5+
},
6+
{
7+
label: "Lead",
8+
value: "lead",
9+
},
10+
];

components/intercom/intercom.app.mjs

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,21 @@ export default {
4545
* @params {Object} [opts.data] - The request body
4646
* @returns {*} The response may vary depending on the specific API request.
4747
*/
48-
async makeRequest(opts) {
49-
const {
50-
method,
51-
url,
52-
endpoint,
53-
data,
54-
$,
55-
} = opts;
48+
async makeRequest({
49+
method,
50+
url,
51+
endpoint,
52+
$,
53+
...opts
54+
}) {
5655
const config = {
5756
method,
5857
url: url ?? `https://api.intercom.io/${endpoint}`,
5958
headers: {
6059
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
6160
Accept: "application/json",
6261
},
63-
data,
62+
...opts,
6463
};
6564
return axios($ || this, config);
6665
},
@@ -210,6 +209,29 @@ export default {
210209
$,
211210
});
212211
},
212+
searchContact(opts = {}) {
213+
return this.makeRequest({
214+
method: "POST",
215+
endpoint: "contacts/search",
216+
...opts,
217+
});
218+
},
219+
createContact(opts = {}) {
220+
return this.makeRequest({
221+
method: "POST",
222+
endpoint: "contacts",
223+
...opts,
224+
});
225+
},
226+
updateContact({
227+
contactId, ...opts
228+
}) {
229+
return this.makeRequest({
230+
method: "PUT",
231+
endpoint: `contacts/${contactId}`,
232+
...opts,
233+
});
234+
},
213235
/**
214236
* Create an incoming message from a user
215237
* @params {Object} data - The request body parameters including a `from` object and

components/intercom/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/intercom",
3-
"version": "0.4.0",
3+
"version": "0.5.0",
44
"description": "Pipedream Intercom Components",
55
"main": "intercom.app.mjs",
66
"keywords": [

components/intercom/sources/conversation-closed/conversation-closed.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "intercom-conversation-closed",
66
name: "New Closed Conversation",
77
description: "Emit new event each time a conversation is closed.",
8-
version: "0.0.5",
8+
version: "0.0.6",
99
type: "source",
1010
dedupe: "unique",
1111
methods: {

0 commit comments

Comments
 (0)