@pipedream/facebook_pages 0.0.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/facebook_pages.app.mjs +261 -0
- package/package.json +5 -5
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Overview
|
|
2
|
+
|
|
3
|
+
The Facebook Pages API on Pipedream allows you to automate interactions with your Facebook Page. Using Pipedream's serverless platform, you can create workflows that respond to events, publish new content, manage posts, and analyze Page performance data. This API enables seamless integration with other apps and services, allowing for complex automations and data-driven decision-making.
|
|
4
|
+
|
|
5
|
+
# Example Use Cases
|
|
6
|
+
|
|
7
|
+
- **Automate Content Posting**: Create a workflow that schedules and posts content to your Facebook Page. When you add new content to a Google Sheets spreadsheet, Pipedream triggers a workflow that automatically publishes the content to your Page at the scheduled time.
|
|
8
|
+
|
|
9
|
+
- **Audience Engagement Tracker**: Craft a workflow that monitors comments and messages on your Page. Leveraging Pipedream's built-in code steps, you can analyze sentiment, flag important items, and even respond automatically. Connect with Slack to send notifications when a user interaction requires personal attention.
|
|
10
|
+
|
|
11
|
+
- **Performance Reporting**: Set up a recurring workflow that gathers analytics from your Facebook Page and compiles them into a report. Integrate with email services like SendGrid to send weekly performance insights directly to your inbox or to your marketing team.
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { axios } from "@pipedream/platform";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
type: "app",
|
|
5
|
+
app: "facebook_pages",
|
|
6
|
+
propDefinitions: {
|
|
7
|
+
page: {
|
|
8
|
+
type: "string",
|
|
9
|
+
label: "Page",
|
|
10
|
+
description: "The identifier of a page",
|
|
11
|
+
async options({ prevContext }) {
|
|
12
|
+
const params = {};
|
|
13
|
+
if (prevContext?.after) {
|
|
14
|
+
params.after = prevContext.after;
|
|
15
|
+
}
|
|
16
|
+
const {
|
|
17
|
+
data, paging,
|
|
18
|
+
} = await this.listPages({
|
|
19
|
+
params,
|
|
20
|
+
});
|
|
21
|
+
const options = data?.map(({
|
|
22
|
+
id, name,
|
|
23
|
+
}) => ({
|
|
24
|
+
label: name,
|
|
25
|
+
value: id,
|
|
26
|
+
})) || [];
|
|
27
|
+
return {
|
|
28
|
+
options,
|
|
29
|
+
context: {
|
|
30
|
+
after: paging?.cursors?.after,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
post: {
|
|
36
|
+
type: "string",
|
|
37
|
+
label: "Post",
|
|
38
|
+
description: "The identifier of a post",
|
|
39
|
+
async options({
|
|
40
|
+
pageId, prevContext,
|
|
41
|
+
}) {
|
|
42
|
+
const params = {};
|
|
43
|
+
if (prevContext?.after) {
|
|
44
|
+
params.after = prevContext.after;
|
|
45
|
+
}
|
|
46
|
+
const {
|
|
47
|
+
data, paging,
|
|
48
|
+
} = await this.listPosts({
|
|
49
|
+
pageId,
|
|
50
|
+
params,
|
|
51
|
+
});
|
|
52
|
+
const options = data?.map(({
|
|
53
|
+
id, message,
|
|
54
|
+
}) => ({
|
|
55
|
+
label: message,
|
|
56
|
+
value: id,
|
|
57
|
+
})) || [];
|
|
58
|
+
return {
|
|
59
|
+
options,
|
|
60
|
+
context: {
|
|
61
|
+
after: paging?.cursors?.after,
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
comment: {
|
|
67
|
+
type: "string",
|
|
68
|
+
label: "Comment",
|
|
69
|
+
description: "The identifier of a comment",
|
|
70
|
+
async options({
|
|
71
|
+
pageId, postId, prevContext,
|
|
72
|
+
}) {
|
|
73
|
+
const params = {};
|
|
74
|
+
if (prevContext?.after) {
|
|
75
|
+
params.after = prevContext.after;
|
|
76
|
+
}
|
|
77
|
+
const {
|
|
78
|
+
data, paging,
|
|
79
|
+
} = await this.listComments({
|
|
80
|
+
pageId,
|
|
81
|
+
postId,
|
|
82
|
+
params,
|
|
83
|
+
});
|
|
84
|
+
const options = data?.map(({
|
|
85
|
+
id, message,
|
|
86
|
+
}) => ({
|
|
87
|
+
label: message,
|
|
88
|
+
value: id,
|
|
89
|
+
})) || [];
|
|
90
|
+
return {
|
|
91
|
+
options,
|
|
92
|
+
context: {
|
|
93
|
+
after: paging?.cursors?.after,
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
maxResults: {
|
|
99
|
+
type: "integer",
|
|
100
|
+
label: "Max Results",
|
|
101
|
+
description: "The maximum number of results to return",
|
|
102
|
+
optional: true,
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
methods: {
|
|
106
|
+
_baseUrl() {
|
|
107
|
+
return "https://graph.facebook.com";
|
|
108
|
+
},
|
|
109
|
+
_headers() {
|
|
110
|
+
return {
|
|
111
|
+
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
_userId() {
|
|
115
|
+
return this.$auth.oauth_uid;
|
|
116
|
+
},
|
|
117
|
+
async _makeRequest({
|
|
118
|
+
$ = this,
|
|
119
|
+
path,
|
|
120
|
+
pageId,
|
|
121
|
+
params,
|
|
122
|
+
...args
|
|
123
|
+
}) {
|
|
124
|
+
if (pageId) {
|
|
125
|
+
params = {
|
|
126
|
+
...params,
|
|
127
|
+
access_token: await this.getAccessToken(pageId),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
return axios($, {
|
|
131
|
+
url: `${this._baseUrl()}${path}`,
|
|
132
|
+
headers: this._headers(),
|
|
133
|
+
params,
|
|
134
|
+
...args,
|
|
135
|
+
});
|
|
136
|
+
},
|
|
137
|
+
async getAccessToken(pageId) {
|
|
138
|
+
const pages = await this.listAllPages();
|
|
139
|
+
const page = pages.find(({ id }) => id == pageId);
|
|
140
|
+
return page?.access_token;
|
|
141
|
+
},
|
|
142
|
+
async listAllPages(args = {}) {
|
|
143
|
+
const results = this.paginate({
|
|
144
|
+
fn: this.listPages,
|
|
145
|
+
args,
|
|
146
|
+
});
|
|
147
|
+
const pages = [];
|
|
148
|
+
for await (const page of results) {
|
|
149
|
+
pages.push(page);
|
|
150
|
+
}
|
|
151
|
+
return pages;
|
|
152
|
+
},
|
|
153
|
+
getPost({
|
|
154
|
+
pageId, postId, ...args
|
|
155
|
+
}) {
|
|
156
|
+
return this._makeRequest({
|
|
157
|
+
path: `/${postId}`,
|
|
158
|
+
pageId,
|
|
159
|
+
...args,
|
|
160
|
+
});
|
|
161
|
+
},
|
|
162
|
+
getComment({
|
|
163
|
+
pageId, commentId, ...args
|
|
164
|
+
}) {
|
|
165
|
+
return this._makeRequest({
|
|
166
|
+
path: `/${commentId}`,
|
|
167
|
+
pageId,
|
|
168
|
+
...args,
|
|
169
|
+
});
|
|
170
|
+
},
|
|
171
|
+
listPages(args = {}) {
|
|
172
|
+
return this._makeRequest({
|
|
173
|
+
path: `/${this._userId()}/accounts`,
|
|
174
|
+
...args,
|
|
175
|
+
});
|
|
176
|
+
},
|
|
177
|
+
listPosts({
|
|
178
|
+
pageId, ...args
|
|
179
|
+
}) {
|
|
180
|
+
return this._makeRequest({
|
|
181
|
+
path: `/${pageId}/feed`,
|
|
182
|
+
pageId,
|
|
183
|
+
...args,
|
|
184
|
+
});
|
|
185
|
+
},
|
|
186
|
+
listComments({
|
|
187
|
+
pageId, postId, ...args
|
|
188
|
+
}) {
|
|
189
|
+
return this._makeRequest({
|
|
190
|
+
path: `/${postId}/comments`,
|
|
191
|
+
pageId,
|
|
192
|
+
...args,
|
|
193
|
+
});
|
|
194
|
+
},
|
|
195
|
+
createPost({
|
|
196
|
+
pageId, ...args
|
|
197
|
+
}) {
|
|
198
|
+
return this._makeRequest({
|
|
199
|
+
path: `/${pageId}/feed`,
|
|
200
|
+
method: "POST",
|
|
201
|
+
pageId,
|
|
202
|
+
...args,
|
|
203
|
+
});
|
|
204
|
+
},
|
|
205
|
+
createComment({
|
|
206
|
+
pageId, postId, ...args
|
|
207
|
+
}) {
|
|
208
|
+
return this._makeRequest({
|
|
209
|
+
path: `/${postId}/comments`,
|
|
210
|
+
method: "POST",
|
|
211
|
+
pageId,
|
|
212
|
+
...args,
|
|
213
|
+
});
|
|
214
|
+
},
|
|
215
|
+
updatePost({
|
|
216
|
+
pageId, postId, ...args
|
|
217
|
+
}) {
|
|
218
|
+
return this._makeRequest({
|
|
219
|
+
path: `/${postId}`,
|
|
220
|
+
method: "POST",
|
|
221
|
+
pageId,
|
|
222
|
+
...args,
|
|
223
|
+
});
|
|
224
|
+
},
|
|
225
|
+
updateComment({
|
|
226
|
+
pageId, commentId, ...args
|
|
227
|
+
}) {
|
|
228
|
+
return this._makeRequest({
|
|
229
|
+
path: `/${commentId}`,
|
|
230
|
+
method: "POST",
|
|
231
|
+
pageId,
|
|
232
|
+
...args,
|
|
233
|
+
});
|
|
234
|
+
},
|
|
235
|
+
async *paginate({
|
|
236
|
+
fn, args = {},
|
|
237
|
+
}) {
|
|
238
|
+
do {
|
|
239
|
+
const {
|
|
240
|
+
data, paging,
|
|
241
|
+
} = await fn(args);
|
|
242
|
+
if (!data.length) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
for (const item of data) {
|
|
246
|
+
yield item;
|
|
247
|
+
}
|
|
248
|
+
if (!paging?.next) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
args = {
|
|
252
|
+
...args,
|
|
253
|
+
params: {
|
|
254
|
+
...args.params,
|
|
255
|
+
after: paging.cursors.after,
|
|
256
|
+
},
|
|
257
|
+
};
|
|
258
|
+
} while (true);
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
};
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pipedream/facebook_pages",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Pipedream Facebook Pages Components",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "facebook_pages.app.mjs",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"pipedream",
|
|
8
8
|
"facebook_pages"
|
|
9
9
|
],
|
|
10
|
-
"files": [
|
|
11
|
-
"dist"
|
|
12
|
-
],
|
|
13
10
|
"homepage": "https://pipedream.com/apps/facebook_pages",
|
|
14
11
|
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
|
|
15
12
|
"publishConfig": {
|
|
16
13
|
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@pipedream/platform": "^1.6.8"
|
|
17
17
|
}
|
|
18
18
|
}
|