Core Components#
Bot Configuration#
The bot inherits all configuration options from the GreenAPIBot
base class, including the ability to customize the GREEN-API instance's parameters.
Full configuration parameters for WhatsappGptBot:
bot = WhatsappGptBot(
# Mandatory parameters
id_instance="your-instance-id",
api_token_instance="your-api-token",
openai_api_key="your-openai-api-key",
# Optional GPT-specific parameters
model="gpt-4o", # Default model
max_history_length=10, # Maximum number of messages in conversation history
system_message="You are a helpful assistant.", # System message to set the behavior
temperature=0.5, # Temperature to generate responses
error_message="Sorry, I could not process your request. Please try again.",
session_timeout=1800, # Session timeout in seconds (30 minutes)
# Optional parameters from the base bot
bot_debug_mode=False, # Enable debug logs
debug_mode=False, # Enable API debug mode
raise_errors=True, # Whether to raise exceptions on API errors
settings={ # GREEN-API instance settings
"webhookUrl": "", # Custom URL for webhook
"webhookUrlToken": "", # Security token for webhook
"delaySendMessagesMilliseconds": 500, # Delay between messages
"markIncomingMessagesReaded": "yes", # Mark messages as read
"incomingWebhook": "yes", # Enable incoming webhooks
"keepOnlineStatus": "yes", # Maintain online status in WhatsApp
"pollMessageWebhook": "yes", # Enable webhooks for polls
}
)
WhatsappGptBot#
The main class for creating and managing your WhatsApp bot based on OpenAI:
from whatsapp_chatgpt_python import WhatsappGptBot
bot = WhatsappGptBot(
id_instance="your-instance-id",
api_token_instance="your-api-token",
openai_api_key="your-openai-api-key",
model="gpt-4o",
system_message="You are a helpful assistant specializing in customer support.",
max_history_length=15,
temperature=0.7,
settings={
"webhookUrl": "",
"markIncomingMessagesReaded": "yes",
"keepOnlineStatus": "yes",
"delaySendMessagesMilliseconds": 500,
}
)
# Start bot
bot.run_forever()