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): Promise { try { // Check each group for the user for (const groupJid of groupJids) { const response = await axios.get( `${API_URL}/group/participants/${INSTANCE_NAME}`, { params: { groupJid: groupJid }, headers: { apikey: API_KEY } } ); // Check if user is in this group's participants const participants = response.data?.participants || []; // Check both JID and phone number formats const userPhone = userJid.split('@')[0]; if (participants.includes(userJid) || participants.some(p => p.startsWith(userPhone))) { return true; } } return false; } catch (error) { console.error('Error checking community membership:', error); return false; } }