naystack 1.1.2 → 1.1.4
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/dist/socials/index.cjs.js +59 -14
- package/dist/socials/index.d.mts +63 -15
- package/dist/socials/index.d.ts +63 -15
- package/dist/socials/index.esm.js +57 -13
- package/package.json +1 -1
|
@@ -30,7 +30,8 @@ __export(socials_exports, {
|
|
|
30
30
|
getInstagramUser: () => getInstagramUser,
|
|
31
31
|
getThread: () => getThread,
|
|
32
32
|
getThreads: () => getThreads,
|
|
33
|
-
getThreadsReplies: () => getThreadsReplies
|
|
33
|
+
getThreadsReplies: () => getThreadsReplies,
|
|
34
|
+
setupInstagramWebhook: () => setupInstagramWebhook
|
|
34
35
|
});
|
|
35
36
|
module.exports = __toCommonJS(socials_exports);
|
|
36
37
|
|
|
@@ -38,32 +39,43 @@ module.exports = __toCommonJS(socials_exports);
|
|
|
38
39
|
function getInstagramURL(token, path, params) {
|
|
39
40
|
return `https://graph.instagram.com/v23.0/${path}?${Object.keys(params).map((key) => `${key}=${params[key]}`).join("&")}&access_token=${token}`;
|
|
40
41
|
}
|
|
41
|
-
function getInstagramData(token, path, params,
|
|
42
|
+
function getInstagramData(token, path, params = {}, postData) {
|
|
42
43
|
return fetch(getInstagramURL(token, path, params), {
|
|
43
|
-
method:
|
|
44
|
+
method: postData ? "POST" : "GET",
|
|
45
|
+
body: JSON.stringify(postData),
|
|
46
|
+
headers: {
|
|
47
|
+
Authorization: `Bearer ${token}`,
|
|
48
|
+
"Content-Type": "application/json"
|
|
49
|
+
}
|
|
44
50
|
}).then((res) => res.json());
|
|
45
51
|
}
|
|
46
52
|
|
|
47
53
|
// src/socials/instagram/getters.ts
|
|
48
|
-
var getInstagramUser = (token, fields) => {
|
|
49
|
-
return getInstagramData(token, "me", {
|
|
54
|
+
var getInstagramUser = (token, id, fields) => {
|
|
55
|
+
return getInstagramData(token, id || "me", {
|
|
50
56
|
fields: fields ? fields.join(",") : "username,followers_count,media_count"
|
|
51
57
|
});
|
|
52
58
|
};
|
|
53
|
-
var getInstagramMedia = (token, fields, limit) => {
|
|
59
|
+
var getInstagramMedia = (token, fields, limit = 12) => {
|
|
54
60
|
return getInstagramData(token, "me/media", {
|
|
55
61
|
fields: fields ? fields.join(",") : "like_count,comments_count,permalink",
|
|
56
|
-
limit: limit?.toString()
|
|
62
|
+
limit: limit?.toString()
|
|
57
63
|
});
|
|
58
64
|
};
|
|
59
|
-
var getInstagramConversations = async (token, cursor) => {
|
|
65
|
+
var getInstagramConversations = async (token, limit = 25, cursor) => {
|
|
60
66
|
const result = await getInstagramData(token, "me/conversations", {
|
|
61
67
|
platform: "instagram",
|
|
68
|
+
fields: "participants,messages,updated_time",
|
|
69
|
+
limit: limit.toString(),
|
|
62
70
|
...cursor ? { after: cursor } : {}
|
|
63
71
|
});
|
|
64
72
|
return {
|
|
65
|
-
data: result?.data
|
|
66
|
-
|
|
73
|
+
data: result?.data.map((item) => ({
|
|
74
|
+
...item,
|
|
75
|
+
messages: item.messages?.data,
|
|
76
|
+
participants: item.participants?.data
|
|
77
|
+
})),
|
|
78
|
+
fetchMore: result?.paging?.cursors?.after ? () => getInstagramConversations(token, limit, result.paging.cursors?.after) : void 0
|
|
67
79
|
};
|
|
68
80
|
};
|
|
69
81
|
var getInstagramConversationByUser = (token, userID) => {
|
|
@@ -71,17 +83,24 @@ var getInstagramConversationByUser = (token, userID) => {
|
|
|
71
83
|
token,
|
|
72
84
|
"me/conversations",
|
|
73
85
|
{
|
|
86
|
+
fields: "participants,messages,updated_time",
|
|
74
87
|
user_id: userID
|
|
75
88
|
}
|
|
76
89
|
);
|
|
77
90
|
};
|
|
78
91
|
var getInstagramConversation = async (token, id, cursor) => {
|
|
79
|
-
const result = await getInstagramData(token, id + "
|
|
92
|
+
const result = await getInstagramData(token, id + "", {
|
|
93
|
+
fields: "participants,messages,updated_time",
|
|
80
94
|
...cursor ? { after: cursor } : {}
|
|
81
95
|
});
|
|
82
96
|
return {
|
|
83
|
-
|
|
84
|
-
|
|
97
|
+
messages: result?.messages?.data,
|
|
98
|
+
participants: result?.participants?.data,
|
|
99
|
+
fetchMore: result?.messages?.paging.cursors?.after ? () => getInstagramConversation(
|
|
100
|
+
token,
|
|
101
|
+
id,
|
|
102
|
+
result?.messages?.paging?.cursors?.after
|
|
103
|
+
) : void 0
|
|
85
104
|
};
|
|
86
105
|
};
|
|
87
106
|
var getInstagramMessage = (token, id, fields) => {
|
|
@@ -90,6 +109,31 @@ var getInstagramMessage = (token, id, fields) => {
|
|
|
90
109
|
});
|
|
91
110
|
};
|
|
92
111
|
|
|
112
|
+
// src/socials/meta-webhook.ts
|
|
113
|
+
var import_server = require("next/server");
|
|
114
|
+
var verifyWebhook = (secret) => (req) => {
|
|
115
|
+
const params = req.nextUrl.searchParams;
|
|
116
|
+
if (params.get("hub.verify_token") === secret) {
|
|
117
|
+
return new import_server.NextResponse(params.get("hub.challenge"));
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// src/socials/instagram/webhook.ts
|
|
122
|
+
var setupInstagramWebhook = (options) => {
|
|
123
|
+
return {
|
|
124
|
+
GET: verifyWebhook(options.secret),
|
|
125
|
+
POST: async (req) => {
|
|
126
|
+
const payload = await req.json();
|
|
127
|
+
for (const entry of payload.entry) {
|
|
128
|
+
for (const change of entry.changes) {
|
|
129
|
+
await options.callback(change.field, change.value);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return new Response("OK");
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
|
|
93
137
|
// src/socials/threads/utils.ts
|
|
94
138
|
function getThreadsURL(token, path, params) {
|
|
95
139
|
return `https://graph.threads.net/v1.0/${path}?${Object.keys(params).map((key) => `${key}=${params[key]}`).join("&")}&access_token=${token}`;
|
|
@@ -169,5 +213,6 @@ var createThread = async (token, threads) => {
|
|
|
169
213
|
getInstagramUser,
|
|
170
214
|
getThread,
|
|
171
215
|
getThreads,
|
|
172
|
-
getThreadsReplies
|
|
216
|
+
getThreadsReplies,
|
|
217
|
+
setupInstagramWebhook
|
|
173
218
|
});
|
package/dist/socials/index.d.mts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import * as next_server from 'next/server';
|
|
2
|
+
import { NextRequest } from 'next/server';
|
|
3
|
+
|
|
1
4
|
type InstagramMessage = {
|
|
2
5
|
id: string;
|
|
3
6
|
created_time: string;
|
|
@@ -23,34 +26,79 @@ type InstagramMedia = {
|
|
|
23
26
|
comments_count: number;
|
|
24
27
|
permalink: string;
|
|
25
28
|
};
|
|
29
|
+
type InstagramConversation = {
|
|
30
|
+
id: string;
|
|
31
|
+
updated_time: string;
|
|
32
|
+
messages?: {
|
|
33
|
+
data: {
|
|
34
|
+
id: string;
|
|
35
|
+
updated_time: string;
|
|
36
|
+
}[];
|
|
37
|
+
paging: {
|
|
38
|
+
cursors?: {
|
|
39
|
+
after?: string;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
participants?: {
|
|
44
|
+
data: {
|
|
45
|
+
id: string;
|
|
46
|
+
username: string;
|
|
47
|
+
}[];
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
type InstagramError = {
|
|
51
|
+
error?: {
|
|
52
|
+
message: string;
|
|
53
|
+
type: string;
|
|
54
|
+
code: number;
|
|
55
|
+
error_subcode: number;
|
|
56
|
+
fbtrace_id: string;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
26
59
|
|
|
27
|
-
declare const getInstagramUser: <T = InstagramUser>(token: string, fields?: string[]) => Promise<(T &
|
|
28
|
-
|
|
29
|
-
}) | null>;
|
|
30
|
-
declare const getInstagramMedia: <T = InstagramMedia>(token: string, fields?: string[], limit?: number) => Promise<{
|
|
60
|
+
declare const getInstagramUser: <T = InstagramUser>(token: string, id?: string, fields?: string[]) => Promise<(T & InstagramError) | null>;
|
|
61
|
+
declare const getInstagramMedia: <T = InstagramMedia>(token: string, fields?: string[], limit?: number) => Promise<({
|
|
31
62
|
data: T[];
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
declare const getInstagramConversations: (token: string, cursor?: string) => Promise<{
|
|
63
|
+
} & InstagramError) | null>;
|
|
64
|
+
declare const getInstagramConversations: (token: string, limit?: number, cursor?: string) => Promise<{
|
|
35
65
|
data: {
|
|
66
|
+
messages: {
|
|
67
|
+
id: string;
|
|
68
|
+
updated_time: string;
|
|
69
|
+
}[] | undefined;
|
|
70
|
+
participants: {
|
|
71
|
+
id: string;
|
|
72
|
+
username: string;
|
|
73
|
+
}[] | undefined;
|
|
36
74
|
id: string;
|
|
37
75
|
updated_time: string;
|
|
38
76
|
}[] | undefined;
|
|
39
77
|
fetchMore: (() => Promise</*elided*/ any>) | undefined;
|
|
40
78
|
}>;
|
|
41
|
-
declare const getInstagramConversationByUser: (token: string, userID: string) => Promise<{
|
|
42
|
-
data:
|
|
43
|
-
|
|
44
|
-
}[];
|
|
45
|
-
} | null>;
|
|
79
|
+
declare const getInstagramConversationByUser: (token: string, userID: string) => Promise<({
|
|
80
|
+
data: InstagramConversation[];
|
|
81
|
+
} & InstagramError) | null>;
|
|
46
82
|
declare const getInstagramConversation: (token: string, id: string, cursor?: string) => Promise<{
|
|
47
|
-
|
|
83
|
+
messages: {
|
|
48
84
|
id: string;
|
|
49
85
|
updated_time: string;
|
|
50
86
|
}[] | undefined;
|
|
87
|
+
participants: {
|
|
88
|
+
id: string;
|
|
89
|
+
username: string;
|
|
90
|
+
}[] | undefined;
|
|
51
91
|
fetchMore: (() => Promise</*elided*/ any>) | undefined;
|
|
52
92
|
}>;
|
|
53
|
-
declare const getInstagramMessage: <T = InstagramMessage>(token: string, id: string, fields?: string[]) => Promise<T | null>;
|
|
93
|
+
declare const getInstagramMessage: <T = InstagramMessage>(token: string, id: string, fields?: string[]) => Promise<(T & InstagramError) | null>;
|
|
94
|
+
|
|
95
|
+
declare const setupInstagramWebhook: (options: {
|
|
96
|
+
secret: string;
|
|
97
|
+
callback: (type: string, value: unknown) => Promise<void>;
|
|
98
|
+
}) => {
|
|
99
|
+
GET: (req: NextRequest) => next_server.NextResponse<unknown> | undefined;
|
|
100
|
+
POST: (req: NextRequest) => Promise<Response>;
|
|
101
|
+
};
|
|
54
102
|
|
|
55
103
|
type ThreadsPost = {
|
|
56
104
|
text: string;
|
|
@@ -65,4 +113,4 @@ declare const getThreadsReplies: <T = ThreadsPost>(token: string, id: string, fi
|
|
|
65
113
|
declare const createThreadsPost: (token: string, text: string, reply_to_id?: string) => Promise<string | void | null>;
|
|
66
114
|
declare const createThread: (token: string, threads: string[]) => Promise<string | undefined>;
|
|
67
115
|
|
|
68
|
-
export { createThread, createThreadsPost, getInstagramConversation, getInstagramConversationByUser, getInstagramConversations, getInstagramMedia, getInstagramMessage, getInstagramUser, getThread, getThreads, getThreadsReplies };
|
|
116
|
+
export { createThread, createThreadsPost, getInstagramConversation, getInstagramConversationByUser, getInstagramConversations, getInstagramMedia, getInstagramMessage, getInstagramUser, getThread, getThreads, getThreadsReplies, setupInstagramWebhook };
|
package/dist/socials/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import * as next_server from 'next/server';
|
|
2
|
+
import { NextRequest } from 'next/server';
|
|
3
|
+
|
|
1
4
|
type InstagramMessage = {
|
|
2
5
|
id: string;
|
|
3
6
|
created_time: string;
|
|
@@ -23,34 +26,79 @@ type InstagramMedia = {
|
|
|
23
26
|
comments_count: number;
|
|
24
27
|
permalink: string;
|
|
25
28
|
};
|
|
29
|
+
type InstagramConversation = {
|
|
30
|
+
id: string;
|
|
31
|
+
updated_time: string;
|
|
32
|
+
messages?: {
|
|
33
|
+
data: {
|
|
34
|
+
id: string;
|
|
35
|
+
updated_time: string;
|
|
36
|
+
}[];
|
|
37
|
+
paging: {
|
|
38
|
+
cursors?: {
|
|
39
|
+
after?: string;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
participants?: {
|
|
44
|
+
data: {
|
|
45
|
+
id: string;
|
|
46
|
+
username: string;
|
|
47
|
+
}[];
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
type InstagramError = {
|
|
51
|
+
error?: {
|
|
52
|
+
message: string;
|
|
53
|
+
type: string;
|
|
54
|
+
code: number;
|
|
55
|
+
error_subcode: number;
|
|
56
|
+
fbtrace_id: string;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
26
59
|
|
|
27
|
-
declare const getInstagramUser: <T = InstagramUser>(token: string, fields?: string[]) => Promise<(T &
|
|
28
|
-
|
|
29
|
-
}) | null>;
|
|
30
|
-
declare const getInstagramMedia: <T = InstagramMedia>(token: string, fields?: string[], limit?: number) => Promise<{
|
|
60
|
+
declare const getInstagramUser: <T = InstagramUser>(token: string, id?: string, fields?: string[]) => Promise<(T & InstagramError) | null>;
|
|
61
|
+
declare const getInstagramMedia: <T = InstagramMedia>(token: string, fields?: string[], limit?: number) => Promise<({
|
|
31
62
|
data: T[];
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
declare const getInstagramConversations: (token: string, cursor?: string) => Promise<{
|
|
63
|
+
} & InstagramError) | null>;
|
|
64
|
+
declare const getInstagramConversations: (token: string, limit?: number, cursor?: string) => Promise<{
|
|
35
65
|
data: {
|
|
66
|
+
messages: {
|
|
67
|
+
id: string;
|
|
68
|
+
updated_time: string;
|
|
69
|
+
}[] | undefined;
|
|
70
|
+
participants: {
|
|
71
|
+
id: string;
|
|
72
|
+
username: string;
|
|
73
|
+
}[] | undefined;
|
|
36
74
|
id: string;
|
|
37
75
|
updated_time: string;
|
|
38
76
|
}[] | undefined;
|
|
39
77
|
fetchMore: (() => Promise</*elided*/ any>) | undefined;
|
|
40
78
|
}>;
|
|
41
|
-
declare const getInstagramConversationByUser: (token: string, userID: string) => Promise<{
|
|
42
|
-
data:
|
|
43
|
-
|
|
44
|
-
}[];
|
|
45
|
-
} | null>;
|
|
79
|
+
declare const getInstagramConversationByUser: (token: string, userID: string) => Promise<({
|
|
80
|
+
data: InstagramConversation[];
|
|
81
|
+
} & InstagramError) | null>;
|
|
46
82
|
declare const getInstagramConversation: (token: string, id: string, cursor?: string) => Promise<{
|
|
47
|
-
|
|
83
|
+
messages: {
|
|
48
84
|
id: string;
|
|
49
85
|
updated_time: string;
|
|
50
86
|
}[] | undefined;
|
|
87
|
+
participants: {
|
|
88
|
+
id: string;
|
|
89
|
+
username: string;
|
|
90
|
+
}[] | undefined;
|
|
51
91
|
fetchMore: (() => Promise</*elided*/ any>) | undefined;
|
|
52
92
|
}>;
|
|
53
|
-
declare const getInstagramMessage: <T = InstagramMessage>(token: string, id: string, fields?: string[]) => Promise<T | null>;
|
|
93
|
+
declare const getInstagramMessage: <T = InstagramMessage>(token: string, id: string, fields?: string[]) => Promise<(T & InstagramError) | null>;
|
|
94
|
+
|
|
95
|
+
declare const setupInstagramWebhook: (options: {
|
|
96
|
+
secret: string;
|
|
97
|
+
callback: (type: string, value: unknown) => Promise<void>;
|
|
98
|
+
}) => {
|
|
99
|
+
GET: (req: NextRequest) => next_server.NextResponse<unknown> | undefined;
|
|
100
|
+
POST: (req: NextRequest) => Promise<Response>;
|
|
101
|
+
};
|
|
54
102
|
|
|
55
103
|
type ThreadsPost = {
|
|
56
104
|
text: string;
|
|
@@ -65,4 +113,4 @@ declare const getThreadsReplies: <T = ThreadsPost>(token: string, id: string, fi
|
|
|
65
113
|
declare const createThreadsPost: (token: string, text: string, reply_to_id?: string) => Promise<string | void | null>;
|
|
66
114
|
declare const createThread: (token: string, threads: string[]) => Promise<string | undefined>;
|
|
67
115
|
|
|
68
|
-
export { createThread, createThreadsPost, getInstagramConversation, getInstagramConversationByUser, getInstagramConversations, getInstagramMedia, getInstagramMessage, getInstagramUser, getThread, getThreads, getThreadsReplies };
|
|
116
|
+
export { createThread, createThreadsPost, getInstagramConversation, getInstagramConversationByUser, getInstagramConversations, getInstagramMedia, getInstagramMessage, getInstagramUser, getThread, getThreads, getThreadsReplies, setupInstagramWebhook };
|
|
@@ -2,32 +2,43 @@
|
|
|
2
2
|
function getInstagramURL(token, path, params) {
|
|
3
3
|
return `https://graph.instagram.com/v23.0/${path}?${Object.keys(params).map((key) => `${key}=${params[key]}`).join("&")}&access_token=${token}`;
|
|
4
4
|
}
|
|
5
|
-
function getInstagramData(token, path, params,
|
|
5
|
+
function getInstagramData(token, path, params = {}, postData) {
|
|
6
6
|
return fetch(getInstagramURL(token, path, params), {
|
|
7
|
-
method:
|
|
7
|
+
method: postData ? "POST" : "GET",
|
|
8
|
+
body: JSON.stringify(postData),
|
|
9
|
+
headers: {
|
|
10
|
+
Authorization: `Bearer ${token}`,
|
|
11
|
+
"Content-Type": "application/json"
|
|
12
|
+
}
|
|
8
13
|
}).then((res) => res.json());
|
|
9
14
|
}
|
|
10
15
|
|
|
11
16
|
// src/socials/instagram/getters.ts
|
|
12
|
-
var getInstagramUser = (token, fields) => {
|
|
13
|
-
return getInstagramData(token, "me", {
|
|
17
|
+
var getInstagramUser = (token, id, fields) => {
|
|
18
|
+
return getInstagramData(token, id || "me", {
|
|
14
19
|
fields: fields ? fields.join(",") : "username,followers_count,media_count"
|
|
15
20
|
});
|
|
16
21
|
};
|
|
17
|
-
var getInstagramMedia = (token, fields, limit) => {
|
|
22
|
+
var getInstagramMedia = (token, fields, limit = 12) => {
|
|
18
23
|
return getInstagramData(token, "me/media", {
|
|
19
24
|
fields: fields ? fields.join(",") : "like_count,comments_count,permalink",
|
|
20
|
-
limit: limit?.toString()
|
|
25
|
+
limit: limit?.toString()
|
|
21
26
|
});
|
|
22
27
|
};
|
|
23
|
-
var getInstagramConversations = async (token, cursor) => {
|
|
28
|
+
var getInstagramConversations = async (token, limit = 25, cursor) => {
|
|
24
29
|
const result = await getInstagramData(token, "me/conversations", {
|
|
25
30
|
platform: "instagram",
|
|
31
|
+
fields: "participants,messages,updated_time",
|
|
32
|
+
limit: limit.toString(),
|
|
26
33
|
...cursor ? { after: cursor } : {}
|
|
27
34
|
});
|
|
28
35
|
return {
|
|
29
|
-
data: result?.data
|
|
30
|
-
|
|
36
|
+
data: result?.data.map((item) => ({
|
|
37
|
+
...item,
|
|
38
|
+
messages: item.messages?.data,
|
|
39
|
+
participants: item.participants?.data
|
|
40
|
+
})),
|
|
41
|
+
fetchMore: result?.paging?.cursors?.after ? () => getInstagramConversations(token, limit, result.paging.cursors?.after) : void 0
|
|
31
42
|
};
|
|
32
43
|
};
|
|
33
44
|
var getInstagramConversationByUser = (token, userID) => {
|
|
@@ -35,17 +46,24 @@ var getInstagramConversationByUser = (token, userID) => {
|
|
|
35
46
|
token,
|
|
36
47
|
"me/conversations",
|
|
37
48
|
{
|
|
49
|
+
fields: "participants,messages,updated_time",
|
|
38
50
|
user_id: userID
|
|
39
51
|
}
|
|
40
52
|
);
|
|
41
53
|
};
|
|
42
54
|
var getInstagramConversation = async (token, id, cursor) => {
|
|
43
|
-
const result = await getInstagramData(token, id + "
|
|
55
|
+
const result = await getInstagramData(token, id + "", {
|
|
56
|
+
fields: "participants,messages,updated_time",
|
|
44
57
|
...cursor ? { after: cursor } : {}
|
|
45
58
|
});
|
|
46
59
|
return {
|
|
47
|
-
|
|
48
|
-
|
|
60
|
+
messages: result?.messages?.data,
|
|
61
|
+
participants: result?.participants?.data,
|
|
62
|
+
fetchMore: result?.messages?.paging.cursors?.after ? () => getInstagramConversation(
|
|
63
|
+
token,
|
|
64
|
+
id,
|
|
65
|
+
result?.messages?.paging?.cursors?.after
|
|
66
|
+
) : void 0
|
|
49
67
|
};
|
|
50
68
|
};
|
|
51
69
|
var getInstagramMessage = (token, id, fields) => {
|
|
@@ -54,6 +72,31 @@ var getInstagramMessage = (token, id, fields) => {
|
|
|
54
72
|
});
|
|
55
73
|
};
|
|
56
74
|
|
|
75
|
+
// src/socials/meta-webhook.ts
|
|
76
|
+
import { NextResponse } from "next/server";
|
|
77
|
+
var verifyWebhook = (secret) => (req) => {
|
|
78
|
+
const params = req.nextUrl.searchParams;
|
|
79
|
+
if (params.get("hub.verify_token") === secret) {
|
|
80
|
+
return new NextResponse(params.get("hub.challenge"));
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// src/socials/instagram/webhook.ts
|
|
85
|
+
var setupInstagramWebhook = (options) => {
|
|
86
|
+
return {
|
|
87
|
+
GET: verifyWebhook(options.secret),
|
|
88
|
+
POST: async (req) => {
|
|
89
|
+
const payload = await req.json();
|
|
90
|
+
for (const entry of payload.entry) {
|
|
91
|
+
for (const change of entry.changes) {
|
|
92
|
+
await options.callback(change.field, change.value);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return new Response("OK");
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
|
|
57
100
|
// src/socials/threads/utils.ts
|
|
58
101
|
function getThreadsURL(token, path, params) {
|
|
59
102
|
return `https://graph.threads.net/v1.0/${path}?${Object.keys(params).map((key) => `${key}=${params[key]}`).join("&")}&access_token=${token}`;
|
|
@@ -132,5 +175,6 @@ export {
|
|
|
132
175
|
getInstagramUser,
|
|
133
176
|
getThread,
|
|
134
177
|
getThreads,
|
|
135
|
-
getThreadsReplies
|
|
178
|
+
getThreadsReplies,
|
|
179
|
+
setupInstagramWebhook
|
|
136
180
|
};
|