feat: add community membership verification and fix message mentions
parent
c27446934a
commit
2ab5605888
@ -0,0 +1,37 @@
|
||||
import axios from 'axios';
|
||||
import dotenv from 'dotenv';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const API_URL = process.env.API_URL;
|
||||
const INSTANCE_NAME = process.env.INSTANCE_NAME;
|
||||
const API_KEY = process.env.API_KEY;
|
||||
|
||||
export async function isUserInCommunity(userJid: string, groupJids: Set<string>): Promise<boolean> {
|
||||
try {
|
||||
// Check each group for the user
|
||||
for (const groupJid of groupJids) {
|
||||
const response = await axios.get(
|
||||
`${API_URL}/group/getParticipants/${INSTANCE_NAME}`,
|
||||
{
|
||||
params: {
|
||||
groupJid: groupJid
|
||||
},
|
||||
headers: {
|
||||
apikey: API_KEY
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Check if user is in this group's participants
|
||||
const participants = response.data?.participants || [];
|
||||
if (participants.includes(userJid)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} catch (error) {
|
||||
console.error('Error checking community membership:', error);
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue