Skip to content

Commit 617efda

Browse files
testing comment replies
1 parent b4809df commit 617efda

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/app/(protected)/api/webhook/instagram/route.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,15 @@ export async function POST(req: NextRequest) {
183183
automation.User?.integrations[0].token!
184184
);
185185

186+
if (automation.listener.commentReply) {
187+
await sendPrivateMessage(
188+
webhook_payload.entry[0].id,
189+
webhook_payload.entry[0].changes[0].value.id,
190+
automation.listener.commentReply,
191+
automation.User?.integrations[0].token!
192+
);
193+
}
194+
186195
console.log("DM SENT", direct_message.data);
187196
if (direct_message.status === 200) {
188197
const tracked = await trackResponses(automation.id, "COMMENT");

src/lib/fetch.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,27 @@ export const sendPrivateMessage = async (
6060
);
6161
};
6262

63+
export const sendCommentReply = async (
64+
userId: string,
65+
commentId: string,
66+
reply: string,
67+
token: string
68+
) => {
69+
console.log("sending comment reply");
70+
return await axios.post(
71+
`${process.env.INSTAGRAM_BASE_URL}/${userId}/media/${commentId}/replies`,
72+
{
73+
message: reply,
74+
},
75+
{
76+
headers: {
77+
Authorization: `Bearer ${token}`,
78+
"Content-Type": "application/json",
79+
},
80+
}
81+
);
82+
};
83+
6384
export const generateTokens = async (code: string) => {
6485
try {
6586
// Validate input

0 commit comments

Comments
 (0)