Skip to content

Advanced Configuration#

Custom State Handling#

Since the library is built on green-api/whatsapp-chatbot-js-v2, you can use all the state features of the base library:

// Add custom state
bot.addState({
name: "collect_info",
async onEnter(message) {
await bot.sendText(message.chatId, "Please provide your name.");
},
async onMessage(message, data = {}) {
// Store name and handle with GPT
const openai = bot.getOpenAI();
const completion = await openai.chat.completions.create({
model: "gpt-3.5-turbo",
messages: [
{role: "system", content: "Generate a personalized greeting."},
{role: "user", content: `My name is ${message.text}`}
]
});

await bot.sendText(message.chatId, completion.choices[0]?.message.content || "Hello!");
return "main_chat"; // Enter the main chat state
}
});

Advanced message handling#

// Get the OpenAI client for custom API calls
const openai = bot.getOpenAI();

// Check if the current model supports images
if (bot.supportsImages()) {
// Process the image-based workflow
}