-
Notifications
You must be signed in to change notification settings - Fork 4k
Develop debug #1861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Develop debug #1861
Conversation
Reviewer's GuideThis PR adds extensive debug logging across chatbot integration layers, wrapping key operations in log statements and try/catch blocks to trace execution flow and errors without altering business logic. Sequence diagram for enhanced logging in chatbot message processingsequenceDiagram
participant WhatsAppService as BaileysStartupService
participant ChatbotController
participant BotController as BaseChatbotController
participant BotService as OpenaiService
actor User
User->>WhatsAppService: Sends message
WhatsAppService->>WhatsAppService: Log MESSAGES.UPSERT STARTED
WhatsAppService->>WhatsAppService: Log Processing message details
WhatsAppService->>ChatbotController: emit({instance, remoteJid, msg, ...})
ChatbotController->>ChatbotController: Log EMIT STARTED
ChatbotController->>BotController: emit(emitData)
BotController->>BotController: Log EMIT STARTED
BotController->>BotController: Log Looking for settings
BotController->>BotController: Log Settings found
BotController->>BotController: Log Looking for session
BotController->>BotController: Log Session found
BotController->>BotController: Log Content
BotController->>BotController: Log Looking for bot trigger
BotController->>BotController: Log Bot found
BotController->>BotController: Log fallback if needed
BotController->>BotController: Log Fallback bot found or not
BotController->>BotController: Log Processing with/without debounce
BotController->>BotService: processBot(...)
BotService->>BotService: Log PROCESS STARTED
BotService->>BotService: Log Bot ID, enabled, Content, Session
BotService-->>BotController: processBot result
BotController-->>ChatbotController: emit result
ChatbotController-->>WhatsAppService: emit result
WhatsAppService->>WhatsAppService: Log chatbotController.emit completed
WhatsAppService->>User: Message processed
Class diagram for updated logging in chatbot integration classesclassDiagram
class BaileysStartupService {
+logger
+emit()
+sendDataWebhook()
+process message with logging
}
class ChatbotController {
+logger
+emit()
+processDebounce()
+logging for each bot emit
}
class BaseChatbotController {
+logger
+emit()
+findBotTrigger()
+getSession()
+processBot()
+logging at each step
}
class OpenaiService {
+logger
+processBot()
+logging for processBot
}
BaileysStartupService --> ChatbotController : calls emit
ChatbotController --> BaseChatbotController : calls emit
BaseChatbotController --> OpenaiService : calls processBot
Flow diagram for debug logging in bot trigger searchflowchart TD
A[findBotByTrigger called] --> B[Log: Searching for bot]
B --> C[Check for triggerType 'all' or 'none']
C --> D[Log: All/None trigger found]
D --> E{Trigger found?}
E -- Yes --> F[Log: Returning bot]
E -- No --> G[Continue with advancedOperatorsSearch]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- You’re adding many inline debug logs with emojis which could clutter production output—consider using structured logging with configurable levels and verbosity instead of raw console messages.
- There’s a lot of repeated logger.log calls for entry/exit and status checks—extracting a reusable logging decorator or helper would cut down boilerplate and improve maintainability.
- In findBotByTrigger you’re using console.log directly; please switch to the project’s logger instance for consistency and better control over log output.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- You’re adding many inline debug logs with emojis which could clutter production output—consider using structured logging with configurable levels and verbosity instead of raw console messages.
- There’s a lot of repeated logger.log calls for entry/exit and status checks—extracting a reusable logging decorator or helper would cut down boilerplate and improve maintainability.
- In findBotByTrigger you’re using console.log directly; please switch to the project’s logger instance for consistency and better control over log output.
## Individual Comments
### Comment 1
<location> `src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts:1049` </location>
<code_context>
settings: any,
) => {
try {
+ this.logger.log(`🚀 [Baileys] MESSAGES.UPSERT STARTED - type: ${type}, messages: ${messages.length}`);
+
</code_context>
<issue_to_address>
Error logging may omit stack trace information.
Log the full error object or stack trace to improve error reporting and facilitate debugging.
</issue_to_address>
### Comment 2
<location> `src/utils/findBotByTrigger.ts:4` </location>
<code_context>
import { advancedOperatorsSearch } from './advancedOperatorsSearch';
export const findBotByTrigger = async (botRepository: any, content: string, instanceId: string) => {
+ console.log(`🔍 [findBotByTrigger] Searching for bot - content: "${content}", instanceId: ${instanceId}`);
+
// Check for triggerType 'all' or 'none' (both should match any message)
</code_context>
<issue_to_address>
Use of console.log for logging may be inconsistent with other logger usage.
Replace console.log with the project's structured logger to ensure consistent logging and log level management.
Suggested implementation:
```typescript
import { advancedOperatorsSearch } from './advancedOperatorsSearch';
import { logger } from '../logger';
export const findBotByTrigger = async (botRepository: any, content: string, instanceId: string) => {
logger.info(`🔍 [findBotByTrigger] Searching for bot - content: "${content}", instanceId: ${instanceId}`);
// Check for triggerType 'all' or 'none' (both should match any message)
const findTriggerAllOrNone = await botRepository.findFirst({
where: {
},
});
logger.info(`🤖 [findBotByTrigger] All/None trigger found: ${findTriggerAllOrNone ? 'YES' : 'NO'} - ID: ${findTriggerAllOrNone?.id || 'NONE'}`);
if (findTriggerAllOrNone) {
logger.info(`✅ [findBotByTrigger] Returning bot with triggerType: ${findTriggerAllOrNone.triggerType}`);
return findTriggerAllOrNone;
```
If your logger uses a different import path or method (e.g., `import logger from ...` or `logger.log('info', ...)`), adjust the import and usage accordingly.
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
||
this.sendDataWebhook(Events.MESSAGES_UPSERT, messageRaw); | ||
|
||
await chatbotController.emit({ | ||
instance: { instanceName: this.instance.name, instanceId: this.instanceId }, | ||
remoteJid: messageRaw.key.remoteJid, | ||
msg: messageRaw, | ||
pushName: messageRaw.pushName, | ||
}); | ||
this.logger.log(`🤖 [Baileys] Calling chatbotController.emit for remoteJid: ${messageRaw.key.remoteJid}`); | ||
|
||
try { | ||
await chatbotController.emit({ | ||
instance: { instanceName: this.instance.name, instanceId: this.instanceId }, | ||
remoteJid: messageRaw.key.remoteJid, | ||
msg: messageRaw, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Error logging may omit stack trace information.
Log the full error object or stack trace to improve error reporting and facilitate debugging.
}, | ||
}); | ||
|
||
console.log(`🤖 [findBotByTrigger] All/None trigger found: ${findTriggerAllOrNone ? 'YES' : 'NO'} - ID: ${findTriggerAllOrNone?.id || 'NONE'}`); | ||
|
||
if (findTriggerAllOrNone) { | ||
console.log(`✅ [findBotByTrigger] Returning bot with triggerType: ${findTriggerAllOrNone.triggerType}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Use of console.log for logging may be inconsistent with other logger usage.
Replace console.log with the project's structured logger to ensure consistent logging and log level management.
Suggested implementation:
import { advancedOperatorsSearch } from './advancedOperatorsSearch';
import { logger } from '../logger';
export const findBotByTrigger = async (botRepository: any, content: string, instanceId: string) => {
logger.info(`🔍 [findBotByTrigger] Searching for bot - content: "${content}", instanceId: ${instanceId}`);
// Check for triggerType 'all' or 'none' (both should match any message)
const findTriggerAllOrNone = await botRepository.findFirst({
where: {
},
});
logger.info(`🤖 [findBotByTrigger] All/None trigger found: ${findTriggerAllOrNone ? 'YES' : 'NO'} - ID: ${findTriggerAllOrNone?.id || 'NONE'}`);
if (findTriggerAllOrNone) {
logger.info(`✅ [findBotByTrigger] Returning bot with triggerType: ${findTriggerAllOrNone.triggerType}`);
return findTriggerAllOrNone;
If your logger uses a different import path or method (e.g., import logger from ...
or logger.log('info', ...)
), adjust the import and usage accordingly.
4b11cfb
to
541a87f
Compare
Summary by Sourcery
Add comprehensive debug logging throughout the chatbot integration pipeline to trace message handling, bot resolution, and error flows.
Enhancements: