Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

feat(bots): use api_keys_required decorators (#4135)

Jesse Urbano97685148d6c8
diff --git a/camel/bots/slack/slack_app.py b/camel/bots/slack/slack_app.py
index 2b4126336..3ba46dc53 100644
--- a/camel/bots/slack/slack_app.py
+++ b/camel/bots/slack/slack_app.py
@@ -26,7 +26,7 @@ from camel.bots.slack.models import (
SlackEventBody,
SlackEventProfile,
)
-from camel.utils import dependencies_required
+from camel.utils import api_keys_required, dependencies_required
if TYPE_CHECKING:
from slack_bolt.context.async_context import AsyncBoltContext
@@ -58,6 +58,13 @@ class SlackApp:
"""
@dependencies_required('slack_bolt')
+ @api_keys_required(
+ [
+ ("token", "SLACK_TOKEN"),
+ ("scopes", "SLACK_SCOPES"),
+ ("signing_secret", "SLACK_SIGNING_SECRET"),
+ ]
+ )
def __init__(
self,
token: Optional[str] = None,
@@ -101,13 +108,6 @@ class SlackApp:
"SLACK_CLIENT_SECRET"
)
- if not all([self.token, self.scopes, self.signing_secret]):
- raise ValueError(
- "`SLACK_TOKEN`, `SLACK_SCOPES`, and `SLACK_SIGNING_SECRET` "
- "environment variables must be set. Get it here: "
- "`https://api.slack.com/apps`."
- )
-
# Setup OAuth settings if client ID and secret are provided
if self.client_id and self.client_secret:
self._app = AsyncApp(
diff --git a/camel/bots/telegram_bot.py b/camel/bots/telegram_bot.py
index 646062d67..3454c75f1 100644
--- a/camel/bots/telegram_bot.py
+++ b/camel/bots/telegram_bot.py
@@ -15,7 +15,7 @@ import os
from typing import TYPE_CHECKING, Optional
from camel.agents import ChatAgent
-from camel.utils import dependencies_required
+from camel.utils import api_keys_required, dependencies_required
# Conditionally import telebot types only for type checking
if TYPE_CHECKING:
@@ -33,6 +33,11 @@ class TelegramBot:
"""
@dependencies_required('telebot')
+ @api_keys_required(
+ [
+ ("telegram_token", "TELEGRAM_TOKEN"),
+ ]
+ )
def __init__(
self,
chat_agent: ChatAgent,
@@ -40,15 +45,8 @@ class TelegramBot:
) -> None:
self.chat_agent = chat_agent
- if not telegram_token:
- self.token = os.getenv('TELEGRAM_TOKEN')
- if not self.token:
- raise ValueError(
- "`TELEGRAM_TOKEN` not found in environment variables. "
- "Get it from t.me/BotFather."
- )
- else:
- self.token = telegram_token
+ self.token = telegram_token or os.getenv('TELEGRAM_TOKEN')
+ assert self.token is not None
import telebot # type: ignore[import-untyped]
diff --git a/camel/utils/commons.py b/camel/utils/commons.py
index 17c5031ae..3e83d0961 100644
--- a/camel/utils/commons.py
+++ b/camel/utils/commons.py
@@ -343,6 +343,10 @@ def api_keys_required(
'ORCAROUTER_API_KEY': "https://www.orcarouter.ai/",
'QUERIT_API_KEY': "https://www.querit.ai/en/dashboard/home",
'PERPLEXITY_API_KEY': "https://www.perplexity.ai/account/api",
+ 'TELEGRAM_TOKEN': 'https://t.me/BotFather',
+ 'SLACK_TOKEN': "https://api.slack.com/apps",
+ 'SLACK_SCOPES': "https://api.slack.com/apps",
+ 'SLACK_SIGNING_SECRET': "https://api.slack.com/apps",
}
key_way = env_key_urls.get(
missing_keys[0], "the official website"