-
-
Notifications
You must be signed in to change notification settings - Fork 86
Feature/contact name #100
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: main
Are you sure you want to change the base?
Feature/contact name #100
Conversation
WalkthroughThe changes update the documentation and core messaging services. The README now specifies that media messages require an authorization header and references an updated image link. In the code, the messaging history event now accepts and processes a contacts array, and the message metadata extraction fetches additional contact details. Multiple data store modules have been enhanced to support contact management through new Changes
Sequence Diagram(s)sequenceDiagram
participant MHE as Messaging History Event
participant Client as ClientBaileys
participant DS as DataStore/Redis
participant Trans as Transformer
participant Listener as ListenerBaileys
MHE->>Client: Trigger messaging-history.set (messages, contacts)
Client->>DS: Process contacts using setContact
DS-->>Client: Acknowledge contact storage
Client->>Client: Update message metadata via getContact
Listener->>Client: Invoke sendOne with validated key.id
Trans->>DS: Retrieve contact details for sender info
DS-->>Trans: Return contact information
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure. 🔧 ESLint
src/services/data_store.tsOops! Something went wrong! :( ESLint: 8.57.1 TypeError: prettier.resolveConfig.sync is not a function src/services/listener_baileys.tsOops! Something went wrong! :( ESLint: 8.57.1 TypeError: prettier.resolveConfig.sync is not a function src/services/data_store_file.tsOops! Something went wrong! :( ESLint: 8.57.1 TypeError: prettier.resolveConfig.sync is not a function
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (5)
src/services/listener_baileys.ts (1)
92-94: Use optional chaining for safer key access.The condition can be simplified using optional chaining, which is safer and more concise.
Apply this diff:
-if (i.key && i.key.id) { +if (i.key?.id) {🧰 Tools
🪛 Biome (1.9.4)
[error] 92-92: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
src/services/data_store_redis.ts (1)
71-85: Add error handling for contact operations.The contact management methods should handle potential errors when converting IDs or accessing undefined properties.
Apply this diff:
store.setContact = async (contact: Partial<Contact>) => { + if (!contact.id && !contact.lid) { + throw new Error('Contact ID or LID is required') + } const id = jidToPhoneNumber(contact.id || contact.lid) const newData: Partial<Contact> = {} if (contact.name) { newData.name = contact.name } if (contact.verifiedName) { newData.verifiedName = contact.verifiedName } return setContact(phone, id, newData) } store.getContact = async (id: string) => { + if (!id) { + throw new Error('Contact ID is required') + } const newId = jidToPhoneNumber(id) return getContact(phone, newId) }src/services/data_store_file.ts (2)
111-118: Add type safety to contacts event handler.The event handler could benefit from explicit type annotations and error handling.
Apply this diff:
-ev.on('contacts.upsert', async (contacts: Contact[]) => { +ev.on('contacts.upsert', async (contacts: readonly Contact[]) => { logger.debug('contacts.upsert %s', phone, JSON.stringify(contacts)) const { saveProfilePicture } = mediaStore - await Promise.all(contacts.map(async (c) => { + await Promise.all(contacts.map(async (c: Contact) => { + try { await dataStore.setContact(c) return saveProfilePicture(c) + } catch (error) { + logger.error('Failed to process contact:', error) + } }) ) })
129-143: Improve type safety in contact management methods.The contact management methods could benefit from stronger type checking and error handling.
Apply this diff:
dataStore.setContact = async (contact: Partial<Contact>) => { + if (!contact.id && !contact.lid) { + throw new Error('Contact ID or LID is required') + } const id = jidToPhoneNumber(contact.id || contact.lid) const newData: Partial<Contact> = {} if (contact.name) { newData.name = contact.name } if (contact.verifiedName) { newData.verifiedName = contact.verifiedName } + if (!dataStore.contacts) { + dataStore.contacts = {} + } dataStore.contacts[id] = { ...(dataStore.contacts[id] || {}), ...newData } } dataStore.getContact = async (id: string) => { + if (!id) { + throw new Error('Contact ID is required') + } const newId = jidToPhoneNumber(id) + if (!dataStore.contacts) { + return undefined + } return dataStore.contacts[newId] }src/services/redis.ts (1)
235-239: Consider adding TTL for contact data.The
setContactfunction correctly merges existing and new contact data. However, consider adding a TTL to prevent stale contact data from persisting indefinitely.Apply this diff to add TTL:
- await client.set(key, JSON.stringify({ ...currentContact, ...(contact || {} )})) + await client.set(key, JSON.stringify({ ...currentContact, ...(contact || {} )}), { EX: DATA_TTL })
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
README.md(1 hunks)src/services/client_baileys.ts(3 hunks)src/services/data_store.ts(2 hunks)src/services/data_store_file.ts(1 hunks)src/services/data_store_redis.ts(3 hunks)src/services/listener_baileys.ts(1 hunks)src/services/redis.ts(3 hunks)src/services/transformer.ts(1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/services/listener_baileys.ts
[error] 92-92: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
🔇 Additional comments (7)
src/services/data_store.ts (1)
1-1: LGTM! Contact management methods added.The addition of
setContactandgetContactmethods to theDataStoretype enhances contact management capabilities.Also applies to: 32-33
src/services/redis.ts (2)
142-144: LGTM! Key generation follows the established pattern.The
contactKeyfunction follows the same pattern as other key generation functions in the file, maintaining consistency.
229-233: LGTM! Contact retrieval with proper type safety.The
getContactfunction correctly handles type safety with theContacttype and properly handles undefined cases.src/services/client_baileys.ts (2)
308-324: LGTM! Enhanced messaging history with contact processing.The messaging history event handler now correctly processes contacts array and stores contact information. The implementation properly handles:
- Contact ID extraction with fallback
- Image URL storage
- Contact data storage
641-652: LGTM! Improved message metadata with contact information.The message metadata enhancement correctly adds contact name and business name information for outgoing messages.
src/services/transformer.ts (1)
467-467: LGTM! Improved sender name resolution.The sender name resolution now correctly prioritizes business name and contact name over the phone number, providing more meaningful identification.
README.md (1)
156-162: LGTM! Documentation improvements for media messages.The changes correctly:
- Add the required authorization header for media messages
- Update the example image link to a valid resource
Summary by CodeRabbit
Documentation
New Features