Skip to content

Commit

Permalink
Merge pull request askrella#262 from ClaytonCassi/master
Browse files Browse the repository at this point in the history
Implementation of IGNORE_LIST_ENABLED Configuration Option
  • Loading branch information
navopw authored Jul 25, 2023
2 parents 7ec50c4 + 4fca42e commit 82e3285
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ PROMPT_MODERATION_BLACKLISTED_CATEGORIES = ["hate", "hate/threatening", "self-ha

# Access control, only allow whatsapp-chatgpt to react to specific phone numbers, comma-separated
WHITELISTED_PHONE_NUMBERS=

WHITELISTED_ENABLED=false
# Speech API URL
# You can use host your own Speech API
# https://github.com/askrella/speech-rest-api
Expand Down
4 changes: 3 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dotenv.config();
interface IConfig {
// Access control
whitelistedPhoneNumbers: string[];

whitelistedEnabled: boolean;
// OpenAI
openAIModel: string;
openAIAPIKeys: string[];
Expand Down Expand Up @@ -58,6 +58,8 @@ interface IConfig {
// Config
export const config: IConfig = {
whitelistedPhoneNumbers: process.env.WHITELISTED_PHONE_NUMBERS?.split(",") || [],
whitelistedEnabled: getEnvBooleanWithDefault("WHITELISTED_ENABLED", false),


openAIAPIKeys: (process.env.OPENAI_API_KEYS || process.env.OPENAI_API_KEY || "").split(",").filter((key) => !!key), // Default: []
openAIModel: process.env.OPENAI_GPT_MODEL || "gpt-3.5-turbo", // Default: gpt-3.5-turbo
Expand Down
13 changes: 8 additions & 5 deletions src/handlers/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,16 @@ async function handleIncomingMessage(message: Message) {
if ((await message.getChat()).isGroup && !config.groupchatsEnabled) return;

const selfNotedMessage = message.fromMe && message.hasQuotedMsg === false && message.from === message.to;
const whitelistedPhoneNumbers = getConfig("general", "whitelist");


if (!selfNotedMessage && whitelistedPhoneNumbers.length > 0 && !whitelistedPhoneNumbers.includes(message.from)) {
cli.print(`Ignoring message from ${message.from} because it is not whitelisted.`);
return;
if (config.whitelistedEnabled) {
const whitelistedPhoneNumbers = getConfig("general", "whitelist");

if (!selfNotedMessage && whitelistedPhoneNumbers.length > 0 && !whitelistedPhoneNumbers.includes(message.from)) {
cli.print(`Ignoring message from ${message.from} because it is not whitelisted.`);
return;
}
}

// Transcribe audio
if (message.hasMedia) {
const media = await message.downloadMedia();
Expand Down

0 comments on commit 82e3285

Please sign in to comment.