Hi everyone,
I’m currently working on a webhook listener that handles events from Amity Social Cloud. Whenever a new user is created (user.didCreate
event), the user is automatically added to a community. Here’s the code I’m using:
import axios from 'axios';
import { Request, Response } from 'express';
export const handleAmityEvents = async (req: Request, res: Response) => {
const event = req.body;
if (event.event === "user.didCreate") {
handleAddUserToCommunity(event.data.users[0].userId);
}
return res.json(event);
};
const handleAddUserToCommunity = async (userId: string) => {
const communityId = await getOneApiKeyAdmin({ keyName: "communityId" });
axios.post(`https://api.sg.amity.co/api/v3/communities/${communityId}/users`, {
userIds: [userId],
}, {
headers: {
'Authorization': `Bearer ${process.env.AMITY_ADMIN_KEY}`
}
}).then((res) => {
// Handle successful response
}).catch((err) => {
// Handle error
});
};
The new users are being added to the community without problems. However, I want to ask for user consent before adding them to the community. Specifically, I want to show them a pop-up to confirm if they want to join the community.
How can I do that?