@pipedream/facebook_pages 0.0.1 → 0.1.0

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.
@@ -0,0 +1,37 @@
1
+ import facebookPages from "../../facebook_pages.app.mjs";
2
+
3
+ export default {
4
+ props: {
5
+ facebookPages,
6
+ page: {
7
+ propDefinition: [
8
+ facebookPages,
9
+ "page",
10
+ ],
11
+ },
12
+ },
13
+ methods: {
14
+ async *paginate({
15
+ fn, args = {},
16
+ }) {
17
+ do {
18
+ const {
19
+ data, paging,
20
+ } = await fn(args);
21
+ if (!data.length) {
22
+ return;
23
+ }
24
+ for (const item of data) {
25
+ yield item;
26
+ }
27
+ args = {
28
+ ...args,
29
+ params: {
30
+ ...args.params,
31
+ after: paging.cursors.after,
32
+ },
33
+ };
34
+ } while (true);
35
+ },
36
+ },
37
+ };
@@ -0,0 +1,43 @@
1
+ import common from "../common/common.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "facebook_pages-create-comment",
6
+ name: "Create Comment",
7
+ description: "Create a new comment on a post on a Facebook Page. [See the documentation](https://developers.facebook.com/docs/graph-api/reference/object/comments/#publish)",
8
+ version: "0.0.1",
9
+ type: "action",
10
+ props: {
11
+ ...common.props,
12
+ post: {
13
+ propDefinition: [
14
+ common.props.facebookPages,
15
+ "post",
16
+ (c) => ({
17
+ pageId: c.page,
18
+ }),
19
+ ],
20
+ },
21
+ message: {
22
+ type: "string",
23
+ label: "Message",
24
+ description: "The comment text",
25
+ },
26
+ },
27
+ async run({ $ }) {
28
+ const response = await this.facebookPages.createComment({
29
+ pageId: this.page,
30
+ postId: this.post,
31
+ data: {
32
+ message: this.message,
33
+ },
34
+ $,
35
+ });
36
+
37
+ if (response) {
38
+ $.export("$summary", `Successfully created new comment with ID ${response.id}.`);
39
+ }
40
+
41
+ return response;
42
+ },
43
+ };
@@ -0,0 +1,46 @@
1
+ import common from "../common/common.mjs";
2
+ import { ConfigurationError } from "@pipedream/platform";
3
+
4
+ export default {
5
+ ...common,
6
+ key: "facebook_pages-create-post",
7
+ name: "Create Post",
8
+ description: "Create a new post on a Facebook Page. [See the documentation](https://developers.facebook.com/docs/graph-api/reference/page/feed#publish)",
9
+ version: "0.0.1",
10
+ type: "action",
11
+ props: {
12
+ ...common.props,
13
+ message: {
14
+ type: "string",
15
+ label: "Message",
16
+ description: "The main body of the post, otherwise called the status message. Either `link` or `message` must be supplied.",
17
+ optional: true,
18
+ },
19
+ link: {
20
+ type: "string",
21
+ label: "Link",
22
+ description: "The URL of a link to attach to the post. Either link or message must be supplied.",
23
+ optional: true,
24
+ },
25
+ },
26
+ async run({ $ }) {
27
+ if (!this.message && !this.link) {
28
+ throw new ConfigurationError("Either `link` or `message` must be supplied");
29
+ }
30
+
31
+ const response = await this.facebookPages.createPost({
32
+ pageId: this.page,
33
+ data: {
34
+ message: this.message,
35
+ link: this.link,
36
+ },
37
+ $,
38
+ });
39
+
40
+ if (response) {
41
+ $.export("$summary", `Successfully created new post with ID ${response.id}.`);
42
+ }
43
+
44
+ return response;
45
+ },
46
+ };
@@ -0,0 +1,43 @@
1
+ import common from "../common/common.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "facebook_pages-get-comment",
6
+ name: "Get Comment",
7
+ description: "Retrieves a comment on a post on a Facebook Page. [See the documentation](https://developers.facebook.com/docs/graph-api/reference/comment/#read)",
8
+ version: "0.0.1",
9
+ type: "action",
10
+ props: {
11
+ ...common.props,
12
+ post: {
13
+ propDefinition: [
14
+ common.props.facebookPages,
15
+ "post",
16
+ (c) => ({
17
+ pageId: c.page,
18
+ }),
19
+ ],
20
+ },
21
+ comment: {
22
+ propDefinition: [
23
+ common.props.facebookPages,
24
+ "comment",
25
+ (c) => ({
26
+ pageId: c.page,
27
+ postId: c.post,
28
+ }),
29
+ ],
30
+ },
31
+ },
32
+ async run({ $ }) {
33
+ const response = await this.facebookPages.getComment({
34
+ pageId: this.page,
35
+ commentId: this.comment,
36
+ $,
37
+ });
38
+
39
+ $.export("$summary", `Successfully retrieved comment with ID ${this.comment}`);
40
+
41
+ return response;
42
+ },
43
+ };
@@ -0,0 +1,20 @@
1
+ import common from "../common/common.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "facebook_pages-get-page",
6
+ name: "Get Page",
7
+ description: "Retrieves a Facebook Page. [See the documentation](https://developers.facebook.com/docs/graph-api/reference/page)",
8
+ version: "0.0.1",
9
+ type: "action",
10
+ async run({ $ }) {
11
+ const { data } = await this.facebookPages.listPages({
12
+ $,
13
+ });
14
+ const page = data.find(({ id }) => id == this.page);
15
+
16
+ $.export("$summary", `Successfully retrieved page with ID ${this.page}`);
17
+
18
+ return page;
19
+ },
20
+ };
@@ -0,0 +1,33 @@
1
+ import common from "../common/common.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "facebook_pages-get-post",
6
+ name: "Get Post",
7
+ description: "Retrieves a post on a Facebook Page. [See the documentation](https://developers.facebook.com/docs/graph-api/reference/pagepost)",
8
+ version: "0.0.1",
9
+ type: "action",
10
+ props: {
11
+ ...common.props,
12
+ post: {
13
+ propDefinition: [
14
+ common.props.facebookPages,
15
+ "post",
16
+ (c) => ({
17
+ pageId: c.page,
18
+ }),
19
+ ],
20
+ },
21
+ },
22
+ async run({ $ }) {
23
+ const response = await this.facebookPages.getPost({
24
+ pageId: this.page,
25
+ postId: this.post,
26
+ $,
27
+ });
28
+
29
+ $.export("$summary", `Successfully retrieved post with ID ${this.post}`);
30
+
31
+ return response;
32
+ },
33
+ };
@@ -0,0 +1,54 @@
1
+ import common from "../common/common.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "facebook_pages-list-comments",
6
+ name: "List Comments",
7
+ description: "Retrieves a list of comments on a post on a Facebook Page. [See the documentation](https://developers.facebook.com/docs/graph-api/reference/comment/#read)",
8
+ version: "0.0.1",
9
+ type: "action",
10
+ props: {
11
+ ...common.props,
12
+ post: {
13
+ propDefinition: [
14
+ common.props.facebookPages,
15
+ "post",
16
+ (c) => ({
17
+ pageId: c.page,
18
+ }),
19
+ ],
20
+ },
21
+ maxResults: {
22
+ propDefinition: [
23
+ common.props.facebookPages,
24
+ "maxResults",
25
+ ],
26
+ },
27
+ },
28
+ async run({ $ }) {
29
+ const response = this.paginate({
30
+ fn: this.facebookPages.listComments,
31
+ args: {
32
+ pageId: this.page,
33
+ postId: this.post,
34
+ $,
35
+ },
36
+ });
37
+
38
+ const comments = [];
39
+ let count = 0;
40
+ for await (const comment of response) {
41
+ comments.push(comment);
42
+
43
+ if (this.maxResults && ++count === this.maxResults) {
44
+ break;
45
+ }
46
+ }
47
+
48
+ $.export("$summary", `Successfully retrieved ${comments.length} comment${comments.length === 1
49
+ ? ""
50
+ : "s"}`);
51
+
52
+ return comments;
53
+ },
54
+ };
@@ -0,0 +1,44 @@
1
+ import common from "../common/common.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "facebook_pages-list-posts",
6
+ name: "List Posts",
7
+ description: "Retrieves a list of posts on a Facebook Page. [See the documentation](https://developers.facebook.com/docs/graph-api/reference/v17.0/page/feed)",
8
+ version: "0.0.1",
9
+ type: "action",
10
+ props: {
11
+ ...common.props,
12
+ maxResults: {
13
+ propDefinition: [
14
+ common.props.facebookPages,
15
+ "maxResults",
16
+ ],
17
+ },
18
+ },
19
+ async run({ $ }) {
20
+ const response = this.paginate({
21
+ fn: this.facebookPages.listPosts,
22
+ args: {
23
+ pageId: this.page,
24
+ $,
25
+ },
26
+ });
27
+
28
+ const posts = [];
29
+ let count = 0;
30
+ for await (const post of response) {
31
+ posts.push(post);
32
+
33
+ if (this.maxResults && ++count === this.maxResults) {
34
+ break;
35
+ }
36
+ }
37
+
38
+ $.export("$summary", `Successfully retrieved ${posts.length} post${posts.length === 1
39
+ ? ""
40
+ : "s"}`);
41
+
42
+ return posts;
43
+ },
44
+ };
@@ -0,0 +1,53 @@
1
+ import common from "../common/common.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "facebook_pages-update-comment",
6
+ name: "Update Comment",
7
+ description: "Updates an existing comment on a post on a Facebook Page. [See the documentation](https://developers.facebook.com/docs/graph-api/reference/comment/#updating)",
8
+ version: "0.0.1",
9
+ type: "action",
10
+ props: {
11
+ ...common.props,
12
+ post: {
13
+ propDefinition: [
14
+ common.props.facebookPages,
15
+ "post",
16
+ (c) => ({
17
+ pageId: c.page,
18
+ }),
19
+ ],
20
+ },
21
+ comment: {
22
+ propDefinition: [
23
+ common.props.facebookPages,
24
+ "comment",
25
+ (c) => ({
26
+ pageId: c.page,
27
+ postId: c.post,
28
+ }),
29
+ ],
30
+ },
31
+ message: {
32
+ type: "string",
33
+ label: "Message",
34
+ description: "The comment text",
35
+ },
36
+ },
37
+ async run({ $ }) {
38
+ const response = await this.facebookPages.updateComment({
39
+ pageId: this.page,
40
+ commentId: this.comment,
41
+ data: {
42
+ message: this.message,
43
+ },
44
+ $,
45
+ });
46
+
47
+ if (response) {
48
+ $.export("$summary", `Successfully updated comment with ID ${this.comment}.`);
49
+ }
50
+
51
+ return response;
52
+ },
53
+ };
@@ -0,0 +1,43 @@
1
+ import common from "../common/common.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "facebook_pages-update-post",
6
+ name: "Update Post",
7
+ description: "Update an existing post on a Facebook Page. [See the documentation](https://developers.facebook.com/docs/graph-api/reference/post#updating)",
8
+ version: "0.0.1",
9
+ type: "action",
10
+ props: {
11
+ ...common.props,
12
+ post: {
13
+ propDefinition: [
14
+ common.props.facebookPages,
15
+ "post",
16
+ (c) => ({
17
+ pageId: c.page,
18
+ }),
19
+ ],
20
+ },
21
+ message: {
22
+ type: "string",
23
+ label: "Message",
24
+ description: "The main body of the post, otherwise called the status message.",
25
+ },
26
+ },
27
+ async run({ $ }) {
28
+ const response = await this.facebookPages.updatePost({
29
+ pageId: this.page,
30
+ postId: this.post,
31
+ data: {
32
+ message: this.message,
33
+ },
34
+ $,
35
+ });
36
+
37
+ if (response) {
38
+ $.export("$summary", `Successfully updated post with ID ${this.post}.`);
39
+ }
40
+
41
+ return response;
42
+ },
43
+ };
@@ -0,0 +1,225 @@
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 { data } = await this.listPages();
139
+ const page = data.find(({ id }) => id == pageId);
140
+ return page.access_token;
141
+ },
142
+ getPost({
143
+ pageId, postId, ...args
144
+ }) {
145
+ return this._makeRequest({
146
+ path: `/${postId}`,
147
+ pageId,
148
+ ...args,
149
+ });
150
+ },
151
+ getComment({
152
+ pageId, commentId, ...args
153
+ }) {
154
+ return this._makeRequest({
155
+ path: `/${commentId}`,
156
+ pageId,
157
+ ...args,
158
+ });
159
+ },
160
+ listPages(args = {}) {
161
+ return this._makeRequest({
162
+ path: `/${this._userId()}/accounts`,
163
+ ...args,
164
+ });
165
+ },
166
+ listPosts({
167
+ pageId, ...args
168
+ }) {
169
+ return this._makeRequest({
170
+ path: `/${pageId}/feed`,
171
+ pageId,
172
+ ...args,
173
+ });
174
+ },
175
+ listComments({
176
+ pageId, postId, ...args
177
+ }) {
178
+ return this._makeRequest({
179
+ path: `/${postId}/comments`,
180
+ pageId,
181
+ ...args,
182
+ });
183
+ },
184
+ createPost({
185
+ pageId, ...args
186
+ }) {
187
+ return this._makeRequest({
188
+ path: `/${pageId}/feed`,
189
+ method: "POST",
190
+ pageId,
191
+ ...args,
192
+ });
193
+ },
194
+ createComment({
195
+ pageId, postId, ...args
196
+ }) {
197
+ return this._makeRequest({
198
+ path: `/${postId}/comments`,
199
+ method: "POST",
200
+ pageId,
201
+ ...args,
202
+ });
203
+ },
204
+ updatePost({
205
+ pageId, postId, ...args
206
+ }) {
207
+ return this._makeRequest({
208
+ path: `/${postId}`,
209
+ method: "POST",
210
+ pageId,
211
+ ...args,
212
+ });
213
+ },
214
+ updateComment({
215
+ pageId, commentId, ...args
216
+ }) {
217
+ return this._makeRequest({
218
+ path: `/${commentId}`,
219
+ method: "POST",
220
+ pageId,
221
+ ...args,
222
+ });
223
+ },
224
+ },
225
+ };
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@pipedream/facebook_pages",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "description": "Pipedream Facebook Pages Components",
5
- "main": "dist/app/facebook_pages.app.mjs",
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.5.1"
17
17
  }
18
18
  }